mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-28 11:29:18 +02:00
New files for ListFilterEdit control
git-svn-id: trunk@31441 -
This commit is contained in:
parent
fa4e60b3a6
commit
277c38e58a
3
.gitattributes
vendored
3
.gitattributes
vendored
@ -1482,10 +1482,13 @@ components/lazcontrols/dividerbevel.pas svneol=native#text/pascal
|
||||
components/lazcontrols/dividerbevel_icon.lrs svneol=native#text/pascal
|
||||
components/lazcontrols/extendednotebook.pas svneol=native#text/pascal
|
||||
components/lazcontrols/extendednotebook_icon.lrs svneol=native#text/pascal
|
||||
components/lazcontrols/images/listfilteredit.png -text
|
||||
components/lazcontrols/images/tdividerbevel.png -text
|
||||
components/lazcontrols/images/textnotebook.png -text
|
||||
components/lazcontrols/lazcontrols.lpk svneol=native#text/xml
|
||||
components/lazcontrols/lazcontrols.pas svneol=native#text/pascal
|
||||
components/lazcontrols/listfilteredit.pas svneol=native#text/plain
|
||||
components/lazcontrols/listfilteredit_icon.lrs svneol=native#text/plain
|
||||
components/lazreport/doc/contributors.txt svneol=native#text/plain
|
||||
components/lazreport/doc/firststeps.odt -text
|
||||
components/lazreport/doc/fr_eng.sxw -text
|
||||
|
BIN
components/lazcontrols/images/listfilteredit.png
Normal file
BIN
components/lazcontrols/images/listfilteredit.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 791 B |
279
components/lazcontrols/listfilteredit.pas
Normal file
279
components/lazcontrols/listfilteredit.pas
Normal file
@ -0,0 +1,279 @@
|
||||
unit ListFilterEdit;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, Forms, LResources, Graphics, StdCtrls, ComCtrls, EditBtn;
|
||||
|
||||
resourcestring
|
||||
lisCEFilter = '(Filter)';
|
||||
|
||||
type
|
||||
|
||||
TImageIndexEvent = function (Str: String; Data: TObject): Integer of object;
|
||||
|
||||
{ TListFilterEdit }
|
||||
|
||||
TListFilterEdit = class(TCustomEditButton)
|
||||
procedure FilterEditChange(Sender: TObject);
|
||||
procedure FilterEditEnter(Sender: TObject);
|
||||
procedure FilterEditExit(Sender: TObject);
|
||||
procedure OnIdle(Sender: TObject; var Done: Boolean);
|
||||
private
|
||||
fFilter: string;
|
||||
fNeedUpdate: boolean;
|
||||
fIdleConnected: boolean;
|
||||
// Data to be filtered. Objects property can contain data, too.
|
||||
fData: TStringList;
|
||||
fFilteredTreeview: TTreeview;
|
||||
fFilteredListbox: TListbox;
|
||||
fOnGetImageIndex: TImageIndexEvent;
|
||||
procedure SetFilter(const AValue: string);
|
||||
procedure SetFilteredTreeview(const AValue: TTreeview);
|
||||
procedure SetFilteredListbox(const AValue: TListBox);
|
||||
function PassesFilter(Entry: string): boolean;
|
||||
procedure ApplyFilterToListBox(AListBox: TListBox);
|
||||
procedure ApplyFilterToTreeview(ATreeView: TTreeView);
|
||||
procedure SetIdleConnected(const AValue: boolean);
|
||||
protected
|
||||
function GetDefaultGlyph: TBitmap; override;
|
||||
function GetDefaultGlyphName: String; override;
|
||||
procedure DoButtonClick (Sender: TObject); override;
|
||||
public
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
procedure ApplyFilter(Immediately: Boolean = False);
|
||||
procedure Invalidate;
|
||||
public
|
||||
property Filter: string read fFilter write SetFilter;
|
||||
property IdleConnected: boolean read fIdleConnected write SetIdleConnected;
|
||||
property Data: TStringList read fData;
|
||||
published
|
||||
// TListFilterEdit properties.
|
||||
property FilteredTreeview: TTreeview read fFilteredTreeview write SetFilteredTreeview;
|
||||
property FilteredListbox: TListBox read fFilteredListbox write SetFilteredListbox;
|
||||
property OnGetImageIndex: TImageIndexEvent read fOnGetImageIndex write fOnGetImageIndex;
|
||||
// TEditButton properties.
|
||||
property ButtonWidth;
|
||||
property DirectInput;
|
||||
property ButtonOnlyWhenFocused;
|
||||
// property Glyph;
|
||||
property NumGlyphs;
|
||||
property Flat;
|
||||
// Other properties
|
||||
property Align;
|
||||
property Anchors;
|
||||
property BidiMode;
|
||||
property BorderSpacing;
|
||||
property BorderStyle;
|
||||
property AutoSize;
|
||||
property AutoSelect;
|
||||
property Color;
|
||||
property DragCursor;
|
||||
property DragMode;
|
||||
property Enabled;
|
||||
property Font;
|
||||
property MaxLength;
|
||||
property ParentBidiMode;
|
||||
property ParentColor;
|
||||
property ParentFont;
|
||||
property ParentShowHint;
|
||||
property PopupMenu;
|
||||
property ReadOnly;
|
||||
property ShowHint;
|
||||
property TabOrder;
|
||||
property TabStop;
|
||||
property Visible;
|
||||
property OnChange;
|
||||
property OnClick;
|
||||
property OnDblClick;
|
||||
property OnDragDrop;
|
||||
property OnDragOver;
|
||||
property OnEditingDone;
|
||||
property OnEndDrag;
|
||||
property OnEnter;
|
||||
property OnExit;
|
||||
property OnKeyDown;
|
||||
property OnKeyPress;
|
||||
property OnKeyUp;
|
||||
property OnMouseDown;
|
||||
property OnMouseMove;
|
||||
property OnMouseUp;
|
||||
property OnStartDrag;
|
||||
property OnUTF8KeyPress;
|
||||
end;
|
||||
|
||||
var
|
||||
ListFilterGlyph: TBitmap;
|
||||
|
||||
const
|
||||
ResBtnListFilter = 'btnfiltercancel';
|
||||
|
||||
procedure Register;
|
||||
|
||||
implementation
|
||||
|
||||
procedure Register;
|
||||
begin
|
||||
{$I listfilteredit_icon.lrs}
|
||||
RegisterComponents('LazControls',[TListFilterEdit]);
|
||||
end;
|
||||
|
||||
{ TListBoxFilterEdit }
|
||||
|
||||
constructor TListFilterEdit.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
fData:=TStringList.Create;
|
||||
Button.Enabled:=False;
|
||||
Font.Color:=clBtnShadow;
|
||||
Text:=lisCEFilter;
|
||||
OnChange:=@FilterEditChange;
|
||||
OnEnter:=@FilterEditEnter;
|
||||
OnExit:=@FilterEditExit;
|
||||
end;
|
||||
|
||||
destructor TListFilterEdit.Destroy;
|
||||
begin
|
||||
fData.Free;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
procedure TListFilterEdit.FilterEditChange(Sender: TObject);
|
||||
begin
|
||||
Filter:=Text;
|
||||
end;
|
||||
|
||||
procedure TListFilterEdit.FilterEditEnter(Sender: TObject);
|
||||
begin
|
||||
if Text=lisCEFilter then
|
||||
Text:='';
|
||||
end;
|
||||
|
||||
procedure TListFilterEdit.FilterEditExit(Sender: TObject);
|
||||
begin
|
||||
Filter:=Text;
|
||||
end;
|
||||
|
||||
procedure TListFilterEdit.DoButtonClick(Sender: TObject);
|
||||
begin
|
||||
Filter:='';
|
||||
end;
|
||||
|
||||
procedure TListFilterEdit.SetFilter(const AValue: string);
|
||||
var
|
||||
NewValue: String;
|
||||
begin
|
||||
NewValue:=LowerCase(AValue);
|
||||
if AValue=lisCEFilter then
|
||||
NewValue:='';
|
||||
fFilter:=NewValue;
|
||||
Button.Enabled:=Filter<>'';
|
||||
if (Filter='') and not Focused then begin
|
||||
Text:=lisCEFilter;
|
||||
Font.Color:=clBtnShadow;
|
||||
end
|
||||
else begin
|
||||
Text:=Filter;
|
||||
Font.Color:=clDefault;
|
||||
end;
|
||||
ApplyFilter;
|
||||
end;
|
||||
|
||||
procedure TListFilterEdit.OnIdle(Sender: TObject; var Done: Boolean);
|
||||
begin
|
||||
if fNeedUpdate then
|
||||
ApplyFilter(true);
|
||||
IdleConnected:=false;
|
||||
end;
|
||||
|
||||
procedure TListFilterEdit.SetIdleConnected(const AValue: boolean);
|
||||
begin
|
||||
if fIdleConnected=AValue then exit;
|
||||
fIdleConnected:=AValue;
|
||||
if fIdleConnected then
|
||||
Application.AddOnIdleHandler(@OnIdle)
|
||||
else
|
||||
Application.RemoveOnIdleHandler(@OnIdle);
|
||||
end;
|
||||
|
||||
function TListFilterEdit.GetDefaultGlyph: TBitmap;
|
||||
begin
|
||||
Result := ListFilterGlyph;
|
||||
end;
|
||||
|
||||
function TListFilterEdit.GetDefaultGlyphName: String;
|
||||
begin
|
||||
Result := ResBtnListFilter;
|
||||
end;
|
||||
|
||||
procedure TListFilterEdit.SetFilteredTreeview(const AValue: TTreeview);
|
||||
begin
|
||||
if Assigned(fFilteredListbox) then
|
||||
raise Exception.Create('Sorry, both Treeview and ListBox should not be assigned.');
|
||||
fFilteredTreeview := AValue;
|
||||
end;
|
||||
|
||||
procedure TListFilterEdit.SetFilteredListbox(const AValue: TListBox);
|
||||
begin
|
||||
if Assigned(fFilteredTreeview) then
|
||||
raise Exception.Create('Sorry, both Treeview and ListBox should not be assigned.');
|
||||
fFilteredListbox := AValue;
|
||||
end;
|
||||
|
||||
function TListFilterEdit.PassesFilter(Entry: string): boolean;
|
||||
begin
|
||||
Result:=(Filter='') or (System.Pos(Filter,lowercase(Entry))>0);
|
||||
end;
|
||||
|
||||
procedure TListFilterEdit.ApplyFilterToListBox(AListBox: TListBox);
|
||||
begin
|
||||
raise Exception.Create('Under construction.');
|
||||
end;
|
||||
|
||||
procedure TListFilterEdit.ApplyFilterToTreeview(ATreeView: TTreeView);
|
||||
var
|
||||
TVNode: TTreeNode;
|
||||
ImgIndex, i: Integer;
|
||||
begin
|
||||
fNeedUpdate:=false;
|
||||
ImgIndex:=-1;
|
||||
fData.Sorted:=True;
|
||||
ATreeView.BeginUpdate;
|
||||
ATreeView.Items.Clear;
|
||||
for i:=0 to fData.Count-1 do
|
||||
if PassesFilter(fData[i]) then begin
|
||||
TVNode:=ATreeView.Items.Add(nil,fData[i]);
|
||||
if Assigned(OnGetImageIndex) then
|
||||
ImgIndex:=OnGetImageIndex(fData[i], fData.Objects[i]);
|
||||
TVNode.ImageIndex:=ImgIndex;
|
||||
TVNode.SelectedIndex:=ImgIndex;
|
||||
end;
|
||||
ATreeView.EndUpdate;
|
||||
end;
|
||||
|
||||
procedure TListFilterEdit.ApplyFilter(Immediately: Boolean);
|
||||
begin
|
||||
if Immediately then begin
|
||||
if Assigned(fFilteredTreeview) then
|
||||
ApplyFilterToTreeview(fFilteredTreeview)
|
||||
else
|
||||
ApplyFilterToListBox(fFilteredListbox);
|
||||
end
|
||||
else begin
|
||||
if csDestroying in ComponentState then exit;
|
||||
Invalidate;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TListFilterEdit.Invalidate;
|
||||
begin
|
||||
fNeedUpdate:=true;
|
||||
IdleConnected:=true;
|
||||
end;
|
||||
|
||||
|
||||
end.
|
||||
|
35
components/lazcontrols/listfilteredit_icon.lrs
Normal file
35
components/lazcontrols/listfilteredit_icon.lrs
Normal file
@ -0,0 +1,35 @@
|
||||
LazarusResources.Add('listfilteredit','PNG',[
|
||||
#137'PNG'#13#10#26#10#0#0#0#13'IHDR'#0#0#0#24#0#0#0#24#8#6#0#0#0#224'w='#248#0
|
||||
+#0#0#1'sRGB'#0#174#206#28#233#0#0#0#6'bKGD'#0#0#0#0#0#0#249'C'#187#127#0#0#0
|
||||
+#9'pHYs'#0#0#11#19#0#0#11#19#1#0#154#156#24#0#0#0#7'tIME'#7#219#6#28#11'8'#0
|
||||
+':h'#8#209#0#0#2#151'IDATH'#199#189#149#205'O'#19'A'#24#198#127#211#150'm'#3
|
||||
+'i'#26#17#141#30'P'#211#131#136#17#13#136'&'#4#2'acj'#224#194#31'`'#140#28
|
||||
+#140#137#7#19#19#15#212#255#160#18#140'&'#156'='#168#193#179'FS'#18#162'X>'
|
||||
+#12#23#229'3R'#163#166#225'C'#129#131#17#203'R'#211#150'v'#199'Cwki'#23'(*>'
|
||||
+#151#217#157#153#247'y'#222'y?f'#132#174#235#8'!'#216'+'#8')%{'#9#7#128#223
|
||||
+#223#251#207'T'#2#129#27#162'@ #r'#233#15#200#250'6'#217'MM'#207#226#247#247
|
||||
+#202'\'#17'G'#174#129#170#250#138'&'#31#28#28#200'~WTT'#144#214'%'#161#208#8
|
||||
+#0'C'#195#163#178#165#185'I'#20#8#228#26#237#6']]'#183#241'x<['#231#224'o05='
|
||||
+#139#239'b'#219#246'I'#190'za'#138'h'#248#219#174#201'/'#159#127#207#227'`'
|
||||
+#17'U'#180#17'['#162#242'H'#29'8VA'#249#2#202'"('#243'`['#1#214'H'#199'!'#165
|
||||
+#185#216#248#225'&'#165#185'I'#199#202'H'''#156#172'/h'#180#181#223#20#128#11
|
||||
+'8'#4#184#250#131#19#165#192#167#130#16'E'#194'/'#240#214'4'#2#224't'#219'A'
|
||||
+#1#236') IZ'#1';6'#236#233#20#235#154#4#1'K'#11#26#0'gN'#159'<'#0'D'#129'y'
|
||||
+#128#254#224#132#4#236'&'#175#13#160#186'#('#0'"3o'#0'Hh)'#176'h'#238#184#150
|
||||
+#241'g'#241'c'#18#128#235#143#20#161#170#190#152#170#250#146'l'#182#208#11'N'
|
||||
+'P'#221#17#20#225'g'#237'2'#242'n'#30'o'#131' '#17#5#231#190#223#22#9'M'#1'`'
|
||||
+'nR'#1#24#175#234#12#157#29#236#196#1#252'4'#29#5'd'#222#152']`'#211'I'#198
|
||||
+'2'#235#137'5'#135'1f'#200'?'#143#148#3'P'#213#25'j4<'#214'sF'#189#168'2}8'
|
||||
+#214'&'#174'4'#244#203#200'p%'#222#214#149',y'#248#249'Q'#0'b'#167#238#213
|
||||
+#143#191#157#136#231'{'#154#7#155')h'#213#7''''#150#203'n'#137#195#177#187'2'
|
||||
+#242#250#28#222#214'W'#204'<'#169#202#198#28#186','#175#222#158#238';'#185
|
||||
+#191'r'#187'F'#251#0#148#154'"'#153#237#146'X'#205'}'#209#211'M'#9#144#178
|
||||
+#176'q'#3#235'9'#196'N '#190'e'''#215#213#215#30#4#230#230#158'F'#205#169#241
|
||||
+#186#250'Z'#167'A'#158#31#22'/'#240#213#156#31'x9'#139'I^'#144#228#28#28#203
|
||||
+#215'4'#200#173#18#25#1#18#219'v'#178#5#153#150'?'#169#170'>'#177#195#237'*'
|
||||
+#172#146'n%0'#9#148#3'$V'#215#152'|p'#220'$P'#140#154'7'#161#0'I'#171#196#238
|
||||
+'$'#160#7#2'}'#223'3'#159#215'\FX<'#4#250#242#247#165#141#30#144#187'~'#147
|
||||
+#135#134'G'#205#170'p'#26#241#221#15#148#0#203#197#190#245'-'#205'M'#242#191
|
||||
+'<'#250'6'#246#24#191#0#136#230#242'w'#134#223#12'V'#0#0#0#0'IEND'#174'B`'
|
||||
+#130
|
||||
]);
|
Loading…
Reference in New Issue
Block a user