Skip to content

Commit

Permalink
Added: GridCell to Grid control and Added: Grid Example
Browse files Browse the repository at this point in the history
  • Loading branch information
XusinboyBekchanov committed Mar 23, 2022
1 parent eeb0265 commit d7300b4
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 4 deletions.
49 changes: 49 additions & 0 deletions examples/Grid/Grid Example.bas
@@ -0,0 +1,49 @@
#ifdef __FB_WIN32__
'#Compile "Form1.rc"
#endif
'#Region "Form"
#include once "mff/Form.bi"
#include once "mff/Grid.bi"

Using My.Sys.Forms

Type Form1Type Extends Form
Declare Constructor

Dim As Grid Grid1
End Type

Constructor Form1Type
' Form1
With This
.Name = "Form1"
.Text = "Form1"
.SetBounds 0, 0, 350, 300
End With
' Grid1
With Grid1
.Name = "Grid1"
.Text = "Grid1"
.TabIndex = 0
.Align = DockStyle.alClient
.SetBounds 0, 0, 334, 261
.Parent = @This
.Columns.Add "Column 1", , 150
.Columns.Add "Column 2", , 150
.Rows.Add "Row 1 Column 1"
.Rows.Add "Row 2 Column 1"
Grid1[0][1].Text = "Row 1 Column 2"
Grid1[1][1].Text = "Row 2 Column 2"
End With
End Constructor

Dim Shared Form1 As Form1Type

#ifndef _NOT_AUTORUN_FORMS_
#define _NOT_AUTORUN_FORMS_

Form1.Show

App.Run
#endif
'#End Region
45 changes: 45 additions & 0 deletions mff/Grid.bas
Expand Up @@ -18,6 +18,13 @@ Namespace My.Sys.Forms
End If
End Function

Private Sub GridCell.SelectItem
With *Cast(Grid Ptr, Parent)
.SelectedColumn = Column
.SelectedRow = Row
End With
End Sub

Private Sub GridRow.SelectItem
#ifdef __USE_GTK__
If Parent Then
Expand All @@ -37,6 +44,36 @@ Namespace My.Sys.Forms
#endif
End Sub

Private Function GridRow.Item(ColumnIndex As Integer) As GridCell Ptr
Dim ic As Integer = FColumns.Count
Dim cc As Integer = Cast(Grid Ptr, Parent)->Columns.Count
If ic < cc Then
For i As Integer = ic + 1 To cc
FColumns.Add ""
Next i
End If
If ColumnIndex < FColumns.Count Then
Dim As GridCell Ptr Cell = FColumns.Object(ColumnIndex)
If Cell = 0 Then
Cell = New GridCell
Cell->Column = Cast(Grid Ptr, Parent)->Columns.Column(ColumnIndex)
Cell->Row = Cast(Grid Ptr, Parent)->Rows.Item(Index)
Cell->Parent = Parent
End If
Return Cell
Else
Return 0
End If
End Function

Private Property GridCell.Text ByRef As WString
Return Row->Text(Column->Index)
End Property

Private Property GridCell.Text(ByRef Value As WString)
Row->Text(Column->Index) = Value
End Property

Private Property GridRow.Text(iColumn As Integer) ByRef As WString
#ifdef __USE_GTK__
If FColumns.Count > iColumn Then
Expand Down Expand Up @@ -254,6 +291,10 @@ Namespace My.Sys.Forms
End If
End Property

Private Operator GridRow.[](ColumnIndex As Integer) ByRef As GridCell
Return *Item(ColumnIndex)
End Operator

Private Operator GridRow.Cast As Any Ptr
Return @This
End Operator
Expand Down Expand Up @@ -1494,6 +1535,10 @@ Namespace My.Sys.Forms
End Function
#endif

Private Operator Grid.[](RowIndex As Integer) ByRef As GridRow
Return *Rows.Item(RowIndex)
End Operator

Private Operator Grid.Cast As Control Ptr
Return @This
End Operator
Expand Down
23 changes: 19 additions & 4 deletions mff/Grid.bi
Expand Up @@ -53,8 +53,24 @@ End Enum
Namespace My.Sys.Forms
#define QGrid(__Ptr__) *Cast(Grid Ptr,__Ptr__)
#define QGridRow(__Ptr__) *Cast(GridRow Ptr, __Ptr__)
#define QGridCell(__Ptr__) *Cast(GridCell Ptr, __Ptr__)
#define QGridColumn(__Ptr__) *Cast(GridColumn Ptr,__Ptr__)

Type PGridRow As GridRow Ptr
Type PGridColumn As GridColumn Ptr

Private Type GridCell Extends My.Sys.Object
Public:
Column As PGridColumn
Parent As Control Ptr
Row As PGridRow
Tag As Any Ptr
Declare Sub SelectItem
Declare Property Text ByRef As WString
Declare Property Text(ByRef Value As WString)
Declare Operator Cast As Any Ptr
End Type

Private Type GridRow Extends My.Sys.Object
Private:
FText As WString Ptr
Expand All @@ -80,10 +96,7 @@ Namespace My.Sys.Forms
Tag As Any Ptr
Declare Sub SelectItem
Declare Function Index As Integer
Declare Property TabIndex As Integer
Declare Property TabIndex(Value As Integer)
Declare Property TabStop As Boolean
Declare Property TabStop(Value As Boolean)
Declare Function Item(ColumnIndex As Integer) As GridCell Ptr
Declare Property Text(iColumn As Integer) ByRef As WString
Declare Property Text(iColumn As Integer, ByRef Value As WString)
Declare Property Hint ByRef As WString
Expand All @@ -106,6 +119,7 @@ Namespace My.Sys.Forms
Declare Property Indent(Value As Integer)
Declare Property Visible As Boolean
Declare Property Visible(Value As Boolean)
Declare Operator [](ColumnIndex As Integer) ByRef As GridCell
Declare Operator Cast As Any Ptr
Declare Constructor
Declare Destructor
Expand Down Expand Up @@ -244,6 +258,7 @@ Namespace My.Sys.Forms
GroupHeaderImages As ImageList Ptr
Declare Virtual Function ReadProperty(PropertyName As String) As Any Ptr
Declare Virtual Function WriteProperty(PropertyName As String, Value As Any Ptr) As Boolean
Declare Operator [](RowIndex As Integer) ByRef As GridRow
Declare Property AllowColumnReorder As Boolean
Declare Property AllowColumnReorder(Value As Boolean)
Declare Property ColumnHeaderHidden As Boolean
Expand Down

0 comments on commit d7300b4

Please sign in to comment.