diff --git a/.gitattributes b/.gitattributes index e5233bdefe..cb2c7807db 100644 --- a/.gitattributes +++ b/.gitattributes @@ -229,6 +229,13 @@ examples/testallform.pp svneol=native#text/pascal examples/testtools.inc svneol=native#text/pascal examples/toolbar.pp svneol=native#text/pascal examples/trackbar.pp svneol=native#text/pascal +examples/treeview/TV_Add_Remove.dpr svneol=native#text/pascal +examples/treeview/TV_Add_Remove.res svneol=native#unset +examples/treeview/TV_Add_Remove_U1.dfm svneol=native#unset +examples/treeview/tv_add_remove.lpi svneol=native#text/plain +examples/treeview/tv_add_remove_u1.lfm svneol=native#text/plain +examples/treeview/tv_add_remove_u1.lrs svneol=native#text/pascal +examples/treeview/tv_add_remove_u1.pas svneol=native#text/pascal ide/aboutfrm.lfm svneol=native#text/plain ide/aboutfrm.lrs svneol=native#text/pascal ide/aboutfrm.pas svneol=native#text/pascal diff --git a/examples/treeview/README b/examples/treeview/README new file mode 100644 index 0000000000..28f2f9232b --- /dev/null +++ b/examples/treeview/README @@ -0,0 +1,8 @@ + +This demo was written by Andre .v.d. Merwe and marked public domain. +Quickly converted to Lazarus and FPC by Tom Lisjac + +The original source and an *excellent* tutorial on the TTreeview +component can be found here: + +http://users.iafrica.com/d/da/dart/Delphi/TTreeView/TreeView.html diff --git a/examples/treeview/TV_Add_Remove.dpr b/examples/treeview/TV_Add_Remove.dpr new file mode 100644 index 0000000000..da7a026a5a --- /dev/null +++ b/examples/treeview/TV_Add_Remove.dpr @@ -0,0 +1,15 @@ +program TV_Add_Remove; + +uses + Interfaces, + Forms, + TV_Add_Remove_U1; + //in 'TV_Add_Remove_U1.pas' {Form1}; + +//{$R *.RES} + +begin + Application.Initialize; + Application.CreateForm(TForm1, Form1); + Application.Run; +end. diff --git a/examples/treeview/TV_Add_Remove.res b/examples/treeview/TV_Add_Remove.res new file mode 100644 index 0000000000..9f9f89428d Binary files /dev/null and b/examples/treeview/TV_Add_Remove.res differ diff --git a/examples/treeview/TV_Add_Remove_U1.dfm b/examples/treeview/TV_Add_Remove_U1.dfm new file mode 100644 index 0000000000..a582f9df36 Binary files /dev/null and b/examples/treeview/TV_Add_Remove_U1.dfm differ diff --git a/examples/treeview/tv_add_remove.lpi b/examples/treeview/tv_add_remove.lpi new file mode 100644 index 0000000000..1b2e415936 --- /dev/null +++ b/examples/treeview/tv_add_remove.lpi @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + </General> + <Units Count="2"> + <Unit0> + <CursorPos X="1" Y="7"/> + <EditorIndex Value="0"/> + <Filename Value="TV_Add_Remove.dpr"/> + <IsPartOfProject Value="True"/> + <Loaded Value="True"/> + <TopLine Value="1"/> + <UsageCount Value="20"/> + </Unit0> + <Unit1> + <CursorPos X="19" Y="52"/> + <EditorIndex Value="1"/> + <Filename Value="tv_add_remove_u1.pas"/> + <ComponentName Value="Form1"/> + <IsPartOfProject Value="True"/> + <Loaded Value="True"/> + <ResourceFilename Value="tv_add_remove_u1.lrs"/> + <TopLine Value="38"/> + <UnitName Value="TV_Add_Remove_U1"/> + <UsageCount Value="20"/> + </Unit1> + </Units> + <PublishOptions> + <Version Value="2"/> + <IgnoreBinaries Value="False"/> + <IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/> + <ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/> + </PublishOptions> + <RunParams> + <local> + <FormatVersion Value="1"/> + <LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/> + </local> + </RunParams> + <RequiredPackages Count="1"> + <Item1> + <PackageName Value="LCL"/> + <MinVersion Major="1" Valid="True"/> + </Item1> + </RequiredPackages> + </ProjectOptions> + <CompilerOptions> + <SearchPaths> + <LCLWidgetType Value="gtk"/> + <SrcPath Value="$(LazarusDir)/lcl;$(LazarusDir)/lcl/interfaces/$(LCLWidgetType)"/> + </SearchPaths> + <Other> + <CompilerPath Value="$(CompPath)"/> + </Other> + </CompilerOptions> +</CONFIG> diff --git a/examples/treeview/tv_add_remove_u1.lfm b/examples/treeview/tv_add_remove_u1.lfm new file mode 100644 index 0000000000..e746cb8bd7 --- /dev/null +++ b/examples/treeview/tv_add_remove_u1.lfm @@ -0,0 +1,47 @@ +object Form1: TForm1 + CAPTION = 'TreeView Example 1' + CLIENTHEIGHT = 427 + CLIENTWIDTH = 455 + FONT.HEIGHT = -11 + FONT.NAME = 'MS Sans Serif' + TEXTHEIGHT = 13 + HORZSCROLLBAR.PAGE = 456 + VERTSCROLLBAR.PAGE = 428 + LEFT = 570 + HEIGHT = 427 + TOP = 249 + WIDTH = 455 + object tv_eg1: TTREEVIEW + ALIGN = alleft + BACKGROUNDCOLOR = 16777215 + BORDERWIDTH = 2 + DEFAULTITEMHEIGHT = 17 + DRAGCURSOR = 0 + HIDESELECTION = False + INDENT = 19 + PARENTCTL3D = False + SELECTIONCOLOR = -2147483635 + TABORDER = 0 + OPTIONS = [tvoautoitemheight, tvokeepcollapsednodes, tvoshowbuttons, tvoshowlines, tvoshowroot, tvotooltips] + HEIGHT = 427 + WIDTH = 196 + end + object but_Add: TBUTTON + CAPTION = 'Add' + TABORDER = 1 + ONCLICK = but_AddClick + LEFT = 208 + HEIGHT = 25 + TOP = 8 + WIDTH = 75 + end + object but_Remove: TBUTTON + CAPTION = 'Remove' + TABORDER = 2 + ONCLICK = but_RemoveClick + LEFT = 208 + HEIGHT = 25 + TOP = 40 + WIDTH = 75 + end +end diff --git a/examples/treeview/tv_add_remove_u1.lrs b/examples/treeview/tv_add_remove_u1.lrs new file mode 100644 index 0000000000..9051ac7889 --- /dev/null +++ b/examples/treeview/tv_add_remove_u1.lrs @@ -0,0 +1,18 @@ +{ This is an automatically generated lazarus resource file } + +LazarusResources.Add('TForm1','FORMDATA',[ + 'TPF0'#6'TForm1'#5'Form1'#7'CAPTION'#6#18'TreeView Example 1'#12'CLIENTHEIGHT' + +#3#171#1#11'CLIENTWIDTH'#3#199#1#11'FONT.HEIGHT'#2#245#9'FONT.NAME'#6#13'MS ' + +'Sans Serif'#10'TEXTHEIGHT'#2#13#18'HORZSCROLLBAR.PAGE'#3#200#1#18'VERTSCROL' + +'LBAR.PAGE'#3#172#1#4'LEFT'#3':'#2#6'HEIGHT'#3#171#1#3'TOP'#3#249#0#5'WIDTH' + +#3#199#1#0#9'TTREEVIEW'#6'tv_eg1'#5'ALIGN'#7#6'alleft'#15'BACKGROUNDCOLOR'#4 + +#255#255#255#0#11'BORDERWIDTH'#2#2#17'DEFAULTITEMHEIGHT'#2#17#10'DRAGCURSOR' + +#2#0#13'HIDESELECTION'#8#6'INDENT'#2#19#11'PARENTCTL3D'#8#14'SELECTIONCOLOR' + +#4#13#0#0#128#8'TABORDER'#2#0#7'OPTIONS'#11#17'tvoautoitemheight'#21'tvokeep' + +'collapsednodes'#14'tvoshowbuttons'#12'tvoshowlines'#11'tvoshowroot'#11'tvot' + +'ooltips'#0#6'HEIGHT'#3#171#1#5'WIDTH'#3#196#0#0#0#7'TBUTTON'#7'but_Add'#7'C' + +'APTION'#6#3'Add'#8'TABORDER'#2#1#7'ONCLICK'#7#12'but_AddClick'#4'LEFT'#3#208 + +#0#6'HEIGHT'#2#25#3'TOP'#2#8#5'WIDTH'#2'K'#0#0#7'TBUTTON'#10'but_Remove'#7'C' + +'APTION'#6#6'Remove'#8'TABORDER'#2#2#7'ONCLICK'#7#15'but_RemoveClick'#4'LEFT' + +#3#208#0#6'HEIGHT'#2#25#3'TOP'#2'('#5'WIDTH'#2'K'#0#0#0 +]); diff --git a/examples/treeview/tv_add_remove_u1.pas b/examples/treeview/tv_add_remove_u1.pas new file mode 100644 index 0000000000..306a6ff468 --- /dev/null +++ b/examples/treeview/tv_add_remove_u1.pas @@ -0,0 +1,102 @@ +unit TV_Add_Remove_U1; + +{ +This demo was written by Andre .v.d. Merwe and marked public domain. +Quickly converted to Lazarus and FPC by Tom Lisjac <vlx@users.sourceforge.net> + +The original source and an *excellent* tutorial on the TTreeview +component can be found here: + http://users.iafrica.com/d/da/dart/Delphi/TTreeView/TreeView.html +} + +interface + +uses + Messages, SysUtils, LResources, Classes, Graphics, Controls, Forms, Dialogs, + StdCtrls, ComCtrls, Buttons; + +type + TForm1 = class(TForm) + tv_eg1: TTreeView; + but_Add: TButton; + but_Remove: TButton; + procedure but_AddClick(Sender: TObject); + procedure but_RemoveClick(Sender: TObject); + private + { Private declarations } + public + { Public declarations } + end; + +var + Form1: TForm1; + +implementation + +//{$R *.DFM} + +procedure TForm1.but_AddClick(Sender: TObject); +var + sText : ansistring; +begin + {If nothing is selected} + if( tv_eg1.Selected = nil ) then + begin + {Does a root node already exist?} + if( tv_eg1.Items.Count = 0 ) then + begin + {Add the root node} + with tv_eg1.Items.AddFirst( nil, 'Root' ) do + begin + Selected := true; + end; + end + else begin + {There is a root, so user must first select a node} + //MessageBeep( -1 ); + ShowMessage( 'Select a parent node' ); + Exit; + end; + end + else begin + {Get a name for the new node} + InputQuery( 'New Node', 'Caption ?', sText ); + + {Add the node as a child of the selected node} + with tv_eg1.Items.AddChild( tv_eg1.Selected, sText ) do + begin + MakeVisible; + end; + end; +end; + + + +procedure TForm1.but_RemoveClick(Sender: TObject); +begin + {Make sure somthing is selected, before trying to + delete it} + if( tv_eg1.Selected = nil ) then + begin + //MessageBeep( -1 ); + ShowMessage( 'Nothing selected' ); + Exit; + end; + + {Dont allow user to delete the root node} + if( tv_eg1.Selected.Level = 0 ) then + begin + //MessageBeep( -1 ); + ShowMessage( 'Cant delete the root node' ); + Exit; + end; + + + {Delete the node} + tv_eg1.Selected.Delete; +end; + +Initialization +{$I tv_add_remove_u1.lrs} + +end.