diff --git a/examples/filteredits/filteredits.ex-meta b/examples/filteredits/filteredits.ex-meta new file mode 100644 index 0000000000..12e9d2a516 --- /dev/null +++ b/examples/filteredits/filteredits.ex-meta @@ -0,0 +1,5 @@ +{ "FilterEditsDemo" : { + "Category" : "General", + "Keywords" : ["ListBox", "ListView", "TreeView", "Filter", "Search Here"], + "Description" : "An Example project to demonstrate use of FilterEdit components, namely ListFilterEdit, ListViewFilterEdit and TreeFilterEdit. They provide a simple means to filter ListBox, ListView and TreeView contents respectively.\n\nSee also https://wiki.freepascal.org/TListFilterEdit, wiki.freepascal.org/TListViewFilterEdit, wiki.freepascal.org/TTreeFilterEdit"} +} diff --git a/examples/filteredits/filtereditsdemo.ico b/examples/filteredits/filtereditsdemo.ico new file mode 100644 index 0000000000..10c5fc1a3d Binary files /dev/null and b/examples/filteredits/filtereditsdemo.ico differ diff --git a/examples/filteredits/filtereditsdemo.lpi b/examples/filteredits/filtereditsdemo.lpi new file mode 100644 index 0000000000..3b38477542 --- /dev/null +++ b/examples/filteredits/filtereditsdemo.lpi @@ -0,0 +1,95 @@ + + + + + + + + <Scaled Value="True"/> + <ResourceType Value="res"/> + <UseXPManifest Value="True"/> + <XPManifest> + <DpiAware Value="True"/> + </XPManifest> + <Icon Value="0"/> + </General> + <BuildModes> + <Item Name="Default" Default="True"/> + </BuildModes> + <PublishOptions> + <Version Value="2"/> + <DestinationDirectory Value="$(ProjPath)/published/"/> + <UseFileFilters Value="True"/> + </PublishOptions> + <RunParams> + <FormatVersion Value="2"/> + </RunParams> + <RequiredPackages> + <Item> + <PackageName Value="LCL"/> + </Item> + <Item> + <PackageName Value="LazControls"/> + </Item> + <Item> + <PackageName Value="LazControlDsgn"/> + </Item> + </RequiredPackages> + <Units> + <Unit> + <Filename Value="filtereditsdemo.lpr"/> + <IsPartOfProject Value="True"/> + <UnitName Value="FilterEditsDemo"/> + </Unit> + <Unit> + <Filename Value="mainunit.pas"/> + <IsPartOfProject Value="True"/> + <ComponentName Value="MainForm"/> + <HasResources Value="True"/> + <ResourceBaseClass Value="Form"/> + <UnitName Value="MainUnit"/> + </Unit> + <Unit> + <Filename Value="listviewfilterunit.pas"/> + <IsPartOfProject Value="True"/> + <ComponentName Value="ListViewFilterForm"/> + <HasResources Value="True"/> + <ResourceBaseClass Value="Form"/> + <UnitName Value="ListViewFilterUnit"/> + </Unit> + <Unit> + <Filename Value="listfilterunit.pas"/> + <IsPartOfProject Value="True"/> + <ComponentName Value="ListFilterForm"/> + <HasResources Value="True"/> + <ResourceBaseClass Value="Form"/> + <UnitName Value="ListFilterUnit"/> + </Unit> + <Unit> + <Filename Value="treefilterunit.pas"/> + <IsPartOfProject Value="True"/> + <ComponentName Value="TreeFilterForm"/> + <HasResources Value="True"/> + <ResourceBaseClass Value="Form"/> + <UnitName Value="TreeFilterUnit"/> + </Unit> + </Units> + </ProjectOptions> + <CompilerOptions> + <Version Value="11"/> + <Target> + <Filename Value="filtereditsdemo"/> + </Target> + <SearchPaths> + <IncludeFiles Value="$(ProjOutDir)"/> + <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/> + </SearchPaths> + <Linking> + <Options> + <Win32> + <GraphicApplication Value="True"/> + </Win32> + </Options> + </Linking> + </CompilerOptions> +</CONFIG> diff --git a/examples/filteredits/filtereditsdemo.lpr b/examples/filteredits/filtereditsdemo.lpr new file mode 100644 index 0000000000..4003d0b569 --- /dev/null +++ b/examples/filteredits/filtereditsdemo.lpr @@ -0,0 +1,28 @@ +program FilterEditsDemo; + +{$mode objfpc}{$H+} + +uses + {$IFDEF UNIX} + cthreads, + {$ENDIF} + {$IFDEF HASAMIGA} + athreads, + {$ENDIF} + Interfaces, // this includes the LCL widgetset + Forms, LazControls, MainUnit, ListViewFilterUnit, ListFilterUnit, +TreeFilterUnit; + +{$R *.res} + +begin + RequireDerivedFormResource:=True; + Application.Scaled:=True; + Application.Initialize; + Application.CreateForm(TMainForm, MainForm); + Application.CreateForm(TListFilterForm, ListFilterForm); + Application.CreateForm(TListViewFilterForm, ListViewFilterForm); + Application.CreateForm(TTreeFilterForm, TreeFilterForm); + Application.Run; +end. + diff --git a/examples/filteredits/filtereditsdemo.res b/examples/filteredits/filtereditsdemo.res new file mode 100644 index 0000000000..bb86af9234 Binary files /dev/null and b/examples/filteredits/filtereditsdemo.res differ diff --git a/examples/filteredits/listfilterunit.lfm b/examples/filteredits/listfilterunit.lfm new file mode 100644 index 0000000000..b6b02fc6b1 --- /dev/null +++ b/examples/filteredits/listfilterunit.lfm @@ -0,0 +1,23 @@ +object ListFilterForm: TListFilterForm + Left = 141 + Height = 240 + Top = 206 + Width = 320 + Caption = 'ListFilterForm' + ClientHeight = 240 + ClientWidth = 320 + LCLVersion = '2.3.0.0' + object Label1: TLabel + AnchorSideLeft.Control = Owner + AnchorSideTop.Control = Owner + Left = 20 + Height = 19 + Top = 20 + Width = 193 + BorderSpacing.Left = 20 + BorderSpacing.Top = 20 + Caption = 'ListFilterEdit Example (ToDo)' + Font.Style = [fsBold] + ParentFont = False + end +end diff --git a/examples/filteredits/listfilterunit.pas b/examples/filteredits/listfilterunit.pas new file mode 100644 index 0000000000..4864569305 --- /dev/null +++ b/examples/filteredits/listfilterunit.pas @@ -0,0 +1,50 @@ +{ + *************************************************************************** + * * + * This source is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This code is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * General Public License for more details. * + * * + * A copy of the GNU General Public License is available on the World * + * Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also * + * obtain it by writing to the Free Software Foundation, * + * Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1335, USA. * + * * + *************************************************************************** +} +unit ListFilterUnit; + +{$mode ObjFPC}{$H+} + +interface + +uses + Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls; + +type + + { TListFilterForm } + + TListFilterForm = class(TForm) + Label1: TLabel; + private + + public + + end; + +var + ListFilterForm: TListFilterForm; + +implementation + +{$R *.lfm} + +end. + diff --git a/examples/filteredits/listviewfilterunit.lfm b/examples/filteredits/listviewfilterunit.lfm new file mode 100644 index 0000000000..2e062598a3 --- /dev/null +++ b/examples/filteredits/listviewfilterunit.lfm @@ -0,0 +1,124 @@ +object ListViewFilterForm: TListViewFilterForm + Left = 472 + Height = 408 + Top = 253 + Width = 469 + Caption = 'ListViewFilterForm' + ClientHeight = 408 + ClientWidth = 469 + OnCreate = FormCreate + LCLVersion = '2.3.0.0' + object ButtonProgram: TButton + AnchorSideLeft.Control = ListViewFilterEdit1 + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = ListViewFilterEdit1 + AnchorSideRight.Side = asrBottom + AnchorSideBottom.Control = CheckCaseSensitive + Left = 20 + Height = 25 + Top = 281 + Width = 429 + Anchors = [akLeft, akRight, akBottom] + BorderSpacing.Top = 20 + BorderSpacing.Bottom = 20 + Caption = 'programmatically x' + OnClick = ButtonProgramClick + TabOrder = 0 + end + object ListView1: TListView + AnchorSideLeft.Control = ListViewFilterEdit1 + AnchorSideTop.Control = ListViewFilterEdit1 + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = ListViewFilterEdit1 + AnchorSideRight.Side = asrBottom + AnchorSideBottom.Control = ButtonProgram + Left = 20 + Height = 151 + Top = 110 + Width = 429 + Anchors = [akTop, akLeft, akRight, akBottom] + BorderSpacing.Top = 20 + BorderSpacing.Bottom = 20 + Columns = < + item + AutoSize = True + Caption = 'Col 1' + Width = 42 + end + item + Caption = 'Col 2' + Width = 365 + end> + SortColumn = 0 + SortType = stText + TabOrder = 1 + ViewStyle = vsReport + end + object CheckCaseSensitive: TCheckBox + AnchorSideLeft.Control = ListViewFilterEdit1 + AnchorSideTop.Side = asrBottom + AnchorSideBottom.Control = CheckBothColumns + Left = 20 + Height = 21 + Top = 326 + Width = 112 + Anchors = [akLeft, akBottom] + BorderSpacing.Top = 20 + BorderSpacing.Bottom = 20 + Caption = 'Case Sensitive' + OnChange = CheckCaseSensitiveChange + TabOrder = 2 + end + object ListViewFilterEdit1: TListViewFilterEdit + AnchorSideLeft.Control = Owner + AnchorSideTop.Control = Label1 + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = Owner + AnchorSideRight.Side = asrBottom + Left = 20 + Height = 31 + Top = 59 + Width = 429 + CharCase = ecNormal + ButtonWidth = 23 + Anchors = [akTop, akLeft, akRight] + BorderSpacing.Left = 20 + BorderSpacing.Top = 20 + BorderSpacing.Right = 20 + NumGlyphs = 1 + MaxLength = 0 + TabOrder = 3 + Text = 'listviewfilteredit1' + TextHint = 'Search Here' + FilteredListview = ListView1 + end + object CheckBothColumns: TCheckBox + AnchorSideLeft.Control = ListViewFilterEdit1 + AnchorSideTop.Side = asrBottom + AnchorSideBottom.Control = Owner + AnchorSideBottom.Side = asrBottom + Left = 20 + Height = 21 + Top = 367 + Width = 110 + Anchors = [akLeft, akBottom] + BorderSpacing.Top = 20 + BorderSpacing.Bottom = 20 + Caption = 'Both Columns' + OnChange = CheckBothColumnsChange + TabOrder = 4 + end + object Label1: TLabel + AnchorSideLeft.Control = Owner + AnchorSideTop.Control = Owner + Left = 20 + Height = 19 + Top = 20 + Width = 179 + BorderSpacing.Left = 20 + BorderSpacing.Top = 20 + Caption = 'ListViewFilterEdit Example' + Font.Style = [fsBold] + ParentFont = False + end +end diff --git a/examples/filteredits/listviewfilterunit.pas b/examples/filteredits/listviewfilterunit.pas new file mode 100644 index 0000000000..a5dd8f2224 --- /dev/null +++ b/examples/filteredits/listviewfilterunit.pas @@ -0,0 +1,129 @@ +{ + *************************************************************************** + * * + * This source is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This code is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * General Public License for more details. * + * * + * A copy of the GNU General Public License is available on the World * + * Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also * + * obtain it by writing to the Free Software Foundation, * + * Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1335, USA. * + * * + *************************************************************************** +} +unit ListViewFilterUnit; + +{$mode objfpc}{$H+} + +{ An Example project to demonstrate use of the ListViewFilterEdit +component, a simple means to filter ListView contents. + + +Content to be displayed in the ListView must be loaded via the ListViewFilterEdit +control. Although not demonstrated here, its possible to include an object with +each row, much the same as can be done with ListView. + + +There does not appear to be a way to define an external search method. Therefore +you can search only the content actually loaded into the TListViewFilterEdit. + +Do not use a ListViewFilterEdit with a ListView in Owner Data mode. + +FilterOptions property should be used to make filtering case sensitive or not. + +Following changes were made in the Object Inspector - + ListView1.ViewStyle := vsReport; + ListViewFilterEdit1.FilteredListview := ListView1; + ListViewFilterEdit1.TextHint := 'Search Here'; + ListViewFilterEdit1.CharCase := ecNormal; + Create two columns in the ListView, set first one to be autowidth + + +David Bannon, 2022-12-07 + +} +interface + +uses + Forms, Controls, StdCtrls, ComCtrls, + ListViewFilterEdit, EditBtn; + +type + + { TListViewFilterForm } + + TListViewFilterForm = class(TForm) + ButtonProgram: TButton; + CheckBothColumns: TCheckBox; + CheckCaseSensitive: TCheckBox; + Label1: TLabel; + ListView1: TListView; + ListViewFilterEdit1: TListViewFilterEdit; + procedure ButtonProgramClick(Sender: TObject); + procedure CheckBothColumnsChange(Sender: TObject); + procedure CheckCaseSensitiveChange(Sender: TObject); + procedure FormCreate(Sender: TObject); + private + procedure AddLVItem(St1, St2: string); + public + + end; + +var + ListViewFilterForm: TListViewFilterForm; + +implementation + +{$R *.lfm} + +procedure TListViewFilterForm.AddLVItem(St1, St2 : string); +var + ListItem: TListViewDataItem; +begin + ListItem.Data := Nil; + SetLength(ListItem.StringArray, 2); + ListItem.StringArray[0] := St1; + ListItem.StringArray[1] := St2; + {%H-}ListViewFilterEdit1.Items.Add(ListItem); +end; + +procedure TListViewFilterForm.FormCreate(Sender: TObject); +begin + ListView1.BeginUpdate; + AddLVItem('String1', 'String2'); + AddLVItem('String3', 'String4'); + AddLVItem('A String', 'another String'); + AddLVItem('x string', 'Extra String'); + ListViewFilterEdit1.InvalidateFilter; + ListViewFilterEdit1.ResetFilter; + ListView1.EndUpdate; +end; + +procedure TListViewFilterForm.ButtonProgramClick(Sender: TObject); +begin + ListViewFilterEdit1.Filter := 'x'; // Filter for strings containing x +end; + +procedure TListViewFilterForm.CheckBothColumnsChange(Sender: TObject); +begin + ListViewFilterEdit1.ByAllFields := CheckBothColumns.Checked; +end; + +procedure TListViewFilterForm.CheckCaseSensitiveChange(Sender: TObject); +begin + with ListViewFilterEdit1 do + if CheckCaseSensitive.checked then + FilterOptions := FilterOptions + [fsoCaseSensitive] + else + FilterOptions := FilterOptions - [fsoCaseSensitive]; +end; + +end. + diff --git a/examples/filteredits/mainunit.lfm b/examples/filteredits/mainunit.lfm new file mode 100644 index 0000000000..d8180c3ef5 --- /dev/null +++ b/examples/filteredits/mainunit.lfm @@ -0,0 +1,51 @@ +object MainForm: TMainForm + Left = 514 + Height = 207 + Top = 51 + Width = 268 + Caption = 'MainForm' + ClientHeight = 207 + ClientWidth = 268 + OnCreate = FormCreate + LCLVersion = '2.3.0.0' + object Label1: TLabel + AnchorSideLeft.Control = Owner + AnchorSideTop.Control = Owner + Left = 20 + Height = 19 + Top = 20 + Width = 126 + BorderSpacing.Left = 20 + BorderSpacing.Top = 20 + Caption = 'FilterEdit Examples' + Font.Style = [fsBold] + ParentFont = False + end + object ListFilterEditButton: TButton + Left = 20 + Height = 25 + Top = 56 + Width = 220 + Caption = 'ListFilterEdit' + OnClick = ListFilterEditButtonClick + TabOrder = 0 + end + object ListViewFilterEditButton: TButton + Left = 20 + Height = 25 + Top = 96 + Width = 220 + Caption = 'ListViewFilterEdit' + OnClick = ListViewFilterEditButtonClick + TabOrder = 1 + end + object TreeFilterEditButton: TButton + Left = 20 + Height = 25 + Top = 136 + Width = 220 + Caption = 'TreeFilterEdit' + OnClick = TreeFilterEditButtonClick + TabOrder = 2 + end +end diff --git a/examples/filteredits/mainunit.pas b/examples/filteredits/mainunit.pas new file mode 100644 index 0000000000..cf8a69d81c --- /dev/null +++ b/examples/filteredits/mainunit.pas @@ -0,0 +1,85 @@ +{ + *************************************************************************** + * * + * This source is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This code is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * General Public License for more details. * + * * + * A copy of the GNU General Public License is available on the World * + * Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also * + * obtain it by writing to the Free Software Foundation, * + * Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1335, USA. * + * * + *************************************************************************** +} +unit MainUnit; + +{$mode objfpc}{$H+} + +{ +An Example project to demonstrate use of FilterEdit components. +They provide a simple means to filter ListBox, ListView and TreeView contents. + +David Bannon, Juha Manninen + +} +interface + +uses + Forms, Controls, StdCtrls, + ListFilterUnit, ListViewFilterUnit, TreeFilterUnit; + +type + + { TMainForm } + + TMainForm = class(TForm) + ListFilterEditButton: TButton; + ListViewFilterEditButton: TButton; + TreeFilterEditButton: TButton; + Label1: TLabel; + procedure FormCreate(Sender: TObject); + procedure ListFilterEditButtonClick(Sender: TObject); + procedure ListViewFilterEditButtonClick(Sender: TObject); + procedure TreeFilterEditButtonClick(Sender: TObject); + private + + public + + end; + +var + MainForm: TMainForm; + +implementation + +{$R *.lfm} + +procedure TMainForm.FormCreate(Sender: TObject); +begin + ; +end; + +procedure TMainForm.ListFilterEditButtonClick(Sender: TObject); +begin + ListFilterForm.Show; +end; + +procedure TMainForm.ListViewFilterEditButtonClick(Sender: TObject); +begin + ListViewFilterForm.Show; +end; + +procedure TMainForm.TreeFilterEditButtonClick(Sender: TObject); +begin + TreeFilterForm.Show; +end; + +end. + diff --git a/examples/filteredits/treefilterunit.lfm b/examples/filteredits/treefilterunit.lfm new file mode 100644 index 0000000000..49bab285f6 --- /dev/null +++ b/examples/filteredits/treefilterunit.lfm @@ -0,0 +1,23 @@ +object TreeFilterForm: TTreeFilterForm + Left = 969 + Height = 240 + Top = 209 + Width = 320 + Caption = 'TreeFilterForm' + ClientHeight = 240 + ClientWidth = 320 + LCLVersion = '2.3.0.0' + object Label1: TLabel + AnchorSideLeft.Control = Owner + AnchorSideTop.Control = Owner + Left = 20 + Height = 19 + Top = 20 + Width = 197 + BorderSpacing.Left = 20 + BorderSpacing.Top = 20 + Caption = 'TreeFilterEdit Example (ToDo)' + Font.Style = [fsBold] + ParentFont = False + end +end diff --git a/examples/filteredits/treefilterunit.pas b/examples/filteredits/treefilterunit.pas new file mode 100644 index 0000000000..4cef0201f7 --- /dev/null +++ b/examples/filteredits/treefilterunit.pas @@ -0,0 +1,50 @@ +{ + *************************************************************************** + * * + * This source is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This code is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * General Public License for more details. * + * * + * A copy of the GNU General Public License is available on the World * + * Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also * + * obtain it by writing to the Free Software Foundation, * + * Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1335, USA. * + * * + *************************************************************************** +} +unit TreeFilterUnit; + +{$mode ObjFPC}{$H+} + +interface + +uses + Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls; + +type + + { TTreeFilterForm } + + TTreeFilterForm = class(TForm) + Label1: TLabel; + private + + public + + end; + +var + TreeFilterForm: TTreeFilterForm; + +implementation + +{$R *.lfm} + +end. +