Difference between revisions of "LazControls"

From Free Pascal wiki
Jump to navigationJump to search
Line 41: Line 41:
 
== TTreeFilterEdit ==
 
== TTreeFilterEdit ==
  
This control can filter a ListBox. Important properties:
+
This control can filter a TreeView. Important properties:
  
 
* FilteredTreeview -- must be assigned to the desired TTreeview control either at design time ot run time.
 
* FilteredTreeview -- must be assigned to the desired TTreeview control either at design time ot run time.

Revision as of 21:44, 22 May 2012

LazControls is a set of controls that are often used in Lazarus IDE itself, but they can be used elsewhere, too.

FilterEdit controls

Controls inherited from TCustomControlFilterEdit provide a filtering edit box connected to a container control. Currently there are filters for TListBox and TTreeView implemented. When the container control is connected to the filter control, the filtering happens automatically as a user enters text. When the filter is empty and does not have focus, it shows a grey "(filter)" text.

There are some common properties that control the behavior:

  • property OnFilterItem -- a user can provide an event handler to give extra conditions for filtering, in addition to the default behavior. This feature has for example enabled filtering the Options windows in Lazarus IDE, based on captions of all controls on the options pages.
  • property OnCheckItem -- This has effect when items in the filtered container can be checked. ToDo: improve...
  • property UseFormActivate -- Sometimes the control's OnEnter and OnExit handlers are not called when focus is moved directly to/from another window.

Then the gray "(filter)" can remain visible even when the control gains focus. When UseFormActivate is True, it finds the parent form and registers handlers for its OnActivate and OnDeactivate events. They properly keep track when the control has focus. This setting is False by default to make sure no existing event handler is overwritten. (An improvent could be to save an existing handler before registering a new one.)

TListFilterEdit

This control can filter a ListBox. Properties:

  • FilteredListBox -- must be assigned to the desired TListBox control either at design time or run time.

Data should be added to TListFilterEdit.Items, not to the container ListBox.Items list. The filter works on its own internal data list and copies to the ListBox only the items that pass the filtering tests. The Items property is also a TStringList and works the same way as ListBox.Items.

You can also attach a filter to a ListBox with existing data. Then the existing items are copied to the filter's items initially.

Working with TCheckListBox

ToDo:

  • procedure RemoveItem(AItem: string);
  • procedure ItemWasClicked(AItem: string; IsChecked: Boolean);


TTreeFilterEdit

This control can filter a TreeView. Important properties:

  • FilteredTreeview -- must be assigned to the desired TTreeview control either at design time ot run time.

This control has 2 different operation modes. They are so different that there could be 2 separate controls as well. One mode maintains and filters sub-items of root-nodes in a tree, another mode filters a whole existing tree using TreeNode.Visible property.

Mode 1: Sub-branches under root nodes

Items for each branch are maintained in TTreeFilterBranch class instance.

  • function TTreeFilterEdit.GetBranch(ARootNode: TTreeNode): TTreeFilterBranch;

can be used to get a new or existing branch. All its items will show under ARootNode.

Items to a branch can be added with

  • procedure AddNodeData(ANodeText: string; AData: TObject; AFullFilename: string = );

ToDo: explain better

The branches can also show a directory hierarchy. This property controls it:

  • property ShowDirHierarchy

If enabled, it assumes the strings are directory names with separators and creates a multi-level tree structure imitating the directory structure.

  • ExpandAllInitially --