From d7300b44a82be650cd513ce8f41133fd5b3684b4 Mon Sep 17 00:00:00 2001 From: Xusinboy Bekchanov Date: Wed, 23 Mar 2022 22:01:52 +0500 Subject: [PATCH] Added: GridCell to Grid control and Added: Grid Example --- examples/Grid/Grid Example.bas | 49 ++++++++++++++++++++++++++++++++++ mff/Grid.bas | 45 +++++++++++++++++++++++++++++++ mff/Grid.bi | 23 +++++++++++++--- 3 files changed, 113 insertions(+), 4 deletions(-) create mode 100644 examples/Grid/Grid Example.bas diff --git a/examples/Grid/Grid Example.bas b/examples/Grid/Grid Example.bas new file mode 100644 index 00000000..b417f8a9 --- /dev/null +++ b/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 diff --git a/mff/Grid.bas b/mff/Grid.bas index 2892c315..582a1c52 100644 --- a/mff/Grid.bas +++ b/mff/Grid.bas @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/mff/Grid.bi b/mff/Grid.bi index 767fb7cc..f7de04d9 100644 --- a/mff/Grid.bi +++ b/mff/Grid.bi @@ -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 @@ -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 @@ -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 @@ -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