summaryrefslogtreecommitdiff
path: root/examples/gui
diff options
context:
space:
mode:
authorGraeme Geldenhuys <graeme@mastermaths.co.za>2011-10-26 11:52:36 +0200
committerGraeme Geldenhuys <graeme@mastermaths.co.za>2011-10-26 11:52:36 +0200
commit964790b057d40d08caad6521b6bbc0071174b145 (patch)
tree206280c66b45372e638c2745150cc8dd3c25abd1 /examples/gui
parenta395588c4b27366e015189179e29f5fafad79c41 (diff)
downloadfpGUI-964790b057d40d08caad6521b6bbc0071174b145.tar.xz
treeview demo: reworked this demo to show the StateImageList support
The demo adds some checkboxes to the treeview, and shows how you can query the treeview for any checked nodes.
Diffstat (limited to 'examples/gui')
-rw-r--r--examples/gui/treeviewtest/stateimages.pas130
-rw-r--r--examples/gui/treeviewtest/treeviewtest.lpi26
-rw-r--r--examples/gui/treeviewtest/treeviewtest.lpr74
3 files changed, 217 insertions, 13 deletions
diff --git a/examples/gui/treeviewtest/stateimages.pas b/examples/gui/treeviewtest/stateimages.pas
new file mode 100644
index 00000000..3c3c5ee7
--- /dev/null
+++ b/examples/gui/treeviewtest/stateimages.pas
@@ -0,0 +1,130 @@
+unit stateimages;
+
+interface
+
+procedure InitializeCustomImages;
+
+implementation
+
+uses
+ fpg_main;
+
+Const
+ usr_state0 : Array[0..821] of byte = (
+ 66, 77, 54, 3, 0, 0, 0, 0, 0, 0, 54, 0, 0, 0, 40, 0, 0,
+ 0, 16, 0, 0, 0, 16, 0, 0, 0, 1, 0, 24, 0, 0, 0, 0, 0,
+ 0, 3, 0, 0,100, 0, 0, 0,100, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,
+ 255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255,
+ 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,
+ 255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,
+ 255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255,
+ 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,
+ 255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,
+ 255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255,
+ 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,
+ 132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,
+ 132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,255,
+ 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,132,132,132,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,132,132,132,255, 0,255,255,
+ 0,255,255, 0,255,255, 0,255,255, 0,255,132,132,132,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,132,132,132,255, 0,255,255, 0,255,255,
+ 0,255,255, 0,255,255, 0,255,132,132,132,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,132,132,132,255, 0,255,255, 0,255,255, 0,255,255,
+ 0,255,255, 0,255,132,132,132,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,132,132,132,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255,
+ 0,255,132,132,132,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,132,132,
+ 132,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,132,
+ 132,132,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,132,132,132,255, 0,
+ 255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,132,132,132,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,132,132,132,255, 0,255,255, 0,
+ 255,255, 0,255,255, 0,255,255, 0,255,132,132,132,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,132,132,132,255, 0,255,255, 0,255,255, 0,
+ 255,255, 0,255,255, 0,255,132,132,132,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,132,132,132,255, 0,255,255, 0,255,255, 0,255,255, 0,
+ 255,255, 0,255,132,132,132,132,132,132,132,132,132,132,132,132,132,
+ 132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,
+ 132,132,132,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,
+ 255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255,
+ 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,
+ 255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,
+ 255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255,
+ 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,
+ 255, 0,255,255, 0,255);
+
+Const
+ usr_state1 : Array[0..821] of byte = (
+ 66, 77, 54, 3, 0, 0, 0, 0, 0, 0, 54, 0, 0, 0, 40, 0, 0,
+ 0, 16, 0, 0, 0, 16, 0, 0, 0, 1, 0, 24, 0, 0, 0, 0, 0,
+ 0, 3, 0, 0,100, 0, 0, 0,100, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,
+ 255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255,
+ 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,
+ 255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,
+ 255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255,
+ 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,
+ 255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,
+ 255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255,
+ 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,
+ 132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,
+ 132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,255,
+ 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,132,132,132,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,132,132,132,255, 0,255,255,
+ 0,255,255, 0,255,255, 0,255,255, 0,255,132,132,132,255,255,255,
+ 255,255,255,255,255,255, 0, 0, 0,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,132,132,132,255, 0,255,255, 0,255,255,
+ 0,255,255, 0,255,255, 0,255,132,132,132,255,255,255,255,255,255,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0,255,255,255,255,255,255,255,255,
+ 255,255,255,255,132,132,132,255, 0,255,255, 0,255,255, 0,255,255,
+ 0,255,255, 0,255,132,132,132,255,255,255, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0,255,255,255,255,255,255,255,255,
+ 255,132,132,132,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255,
+ 0,255,132,132,132,255,255,255, 0, 0, 0, 0, 0, 0,255,255,255,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0,255,255,255,255,255,255,132,132,
+ 132,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,132,
+ 132,132,255,255,255, 0, 0, 0,255,255,255,255,255,255,255,255,255,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0,255,255,255,132,132,132,255, 0,
+ 255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,132,132,132,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 0, 0, 0, 0, 0, 0,255,255,255,132,132,132,255, 0,255,255, 0,
+ 255,255, 0,255,255, 0,255,255, 0,255,132,132,132,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 0, 0, 0,255,255,255,132,132,132,255, 0,255,255, 0,255,255, 0,
+ 255,255, 0,255,255, 0,255,132,132,132,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,132,132,132,255, 0,255,255, 0,255,255, 0,255,255, 0,
+ 255,255, 0,255,132,132,132,132,132,132,132,132,132,132,132,132,132,
+ 132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,
+ 132,132,132,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,
+ 255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255,
+ 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,
+ 255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,
+ 255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255,
+ 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,
+ 255, 0,255,255, 0,255);
+
+
+procedure InitializeCustomImages;
+begin
+ fpgImages.AddMaskedBMP(
+ 'usr.state0',
+ @usr_state0,
+ sizeof(usr_state0), 0,0);
+
+ fpgImages.AddMaskedBMP(
+ 'usr.state1',
+ @usr_state1,
+ sizeof(usr_state1), 0,0);
+end;
+
+end.
diff --git a/examples/gui/treeviewtest/treeviewtest.lpi b/examples/gui/treeviewtest/treeviewtest.lpi
index 5f459bb9..6c19a1a9 100644
--- a/examples/gui/treeviewtest/treeviewtest.lpi
+++ b/examples/gui/treeviewtest/treeviewtest.lpi
@@ -1,19 +1,21 @@
<?xml version="1.0"?>
<CONFIG>
<ProjectOptions>
- <PathDelim Value="/"/>
- <Version Value="6"/>
+ <Version Value="9"/>
<General>
<Flags>
<SaveOnlyProjectUnits Value="True"/>
+ <LRSInOutputDirectory Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
- <TargetFileExt Value=""/>
</General>
<VersionInfo>
- <ProjectVersion Value=""/>
+ <StringTable ProductVersion=""/>
</VersionInfo>
+ <BuildModes Count="1">
+ <Item1 Name="default" Default="True"/>
+ </BuildModes>
<PublishOptions>
<Version Value="2"/>
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
@@ -30,24 +32,32 @@
<PackageName Value="fpgui_toolkit"/>
</Item1>
</RequiredPackages>
- <Units Count="1">
+ <Units Count="2">
<Unit0>
<Filename Value="treeviewtest.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="treeviewtest"/>
</Unit0>
+ <Unit1>
+ <Filename Value="stateimages.pas"/>
+ <IsPartOfProject Value="True"/>
+ <UnitName Value="stateimages"/>
+ </Unit1>
</Units>
</ProjectOptions>
<CompilerOptions>
- <Version Value="8"/>
+ <Version Value="9"/>
<Parsing>
<SyntaxOptions>
<CStyleOperator Value="False"/>
+ <UseAnsiStrings Value="False"/>
</SyntaxOptions>
</Parsing>
<Other>
- <CustomOptions Value="-FUunits
-"/>
+ <CompilerMessages>
+ <UseMsgFile Value="True"/>
+ </CompilerMessages>
+ <CustomOptions Value="-FUunits"/>
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions>
diff --git a/examples/gui/treeviewtest/treeviewtest.lpr b/examples/gui/treeviewtest/treeviewtest.lpr
index bca0a91d..3e1ac6ff 100644
--- a/examples/gui/treeviewtest/treeviewtest.lpr
+++ b/examples/gui/treeviewtest/treeviewtest.lpr
@@ -18,7 +18,8 @@ uses
fpg_label,
fpg_dialogs,
fpg_combobox,
- fpg_utils;
+ fpg_utils,
+ stateimages;
type
@@ -45,8 +46,10 @@ type
Label8: TfpgLabel;
btnCollapseAll: TfpgButton;
btnExpandAll: TfpgButton;
+ btnShowChecked: TfpgButton;
{@VFD_HEAD_END: MainForm}
FImagelist: TfpgImageList;
+ FStateImagelist: TfpgImageList;
FSrcNode: TfpgTreeNode;
FDestnode: TfpgTreeNode;
procedure cbShowImagesChange(Sender: TObject);
@@ -59,6 +62,8 @@ type
procedure btnMoveToClicked(Sender: TObject);
procedure btnCollapseAllClicked(Sender: TObject);
procedure btnExpandAllClicked(Sender: TObject);
+ procedure StateImageClicked(Sender: TObject; ANode: TfpgTreeNode);
+ procedure btnShowCheckedClicked(Sender: TObject);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
@@ -122,8 +127,13 @@ begin
n := tree.RootNode.AppendText('Node 1');
n.ImageIndex := 0;
- n.AppendText('Node 1.1').ImageIndex := 1;
- n.AppendText('Node 1.2').ImageIndex := 1;
+ n.StateImageIndex := 1;
+ n2 := n.AppendText('Node 1.1');
+ n2.ImageIndex := 1;
+ n2.StateImageIndex := 1;
+ n2 := n.AppendText('Node 1.2');
+ n2.ImageIndex := 1;
+ n2.StateImageIndex := 0;
n := tree.RootNode.AppendText('Node 2');
n.ImageIndex := 0;
n.AppendText('Node 2.1').ImageIndex := 1;
@@ -137,7 +147,8 @@ begin
else
n.AppendText(s);
end;
- n.Parent.AppendText('Node 2.3');
+ n2 := n.Parent.AppendText('Node 2.3');
+ n2.StateImageIndex := 0;
tree.RootNode.FirstSubNode.Next.Collapse;
tree.RootNode.AppendText('Node 3').ImageIndex := 0;
tree.Selection := n;
@@ -198,6 +209,31 @@ begin
TreeNodeChanged(nil);
end;
+procedure TMainForm.StateImageClicked(Sender: TObject; ANode: TfpgTreeNode);
+begin
+ case ANode.StateImageIndex of
+ 0: ANode.StateImageIndex := 1;
+ 1: ANode.StateImageIndex := 0;
+ end;
+ tree.Invalidate;
+end;
+
+procedure TMainForm.btnShowCheckedClicked(Sender: TObject);
+var
+ n: TfpgTreeNode;
+ s: string;
+begin
+ s := 'These are all the nodes that have checkboxes and are checked:' + LineEnding;
+ n := tree.RootNode;
+ while n <> nil do
+ begin
+ if n.StateImageIndex = 1 then
+ s += LineEnding + n.Text;
+ n := Tree.NextNode(n);
+ end;
+ ShowMessage(s);
+end;
+
procedure TMainForm.cbShowImagesChange(Sender: TObject);
begin
tree.ShowImages := cbShowImages.Checked;
@@ -216,12 +252,24 @@ begin
FImagelist.Items[1].Image.CreateMaskFromSample(0, 0);
FImagelist.Items[1].Image.UpdateImage;
end;
+
+ InitializeCustomImages;
+ FStateImagelist := TfpgImageList.Create;
+ FStateImagelist.AddImage(fpgImages.GetImage('usr.state0'));
+ FStateImagelist.AddImage(fpgImages.GetImage('usr.state1'));
+
end;
destructor TMainForm.Destroy;
+var
+ i: integer;
begin
tree.ImageList := nil;
+ tree.StateImageList := nil;
FImagelist.Free;
+ for i := FStateImageList.Count-1 downto 0 do
+ FStateImageList[i].Image := nil;
+ FStateImageList.Free;
inherited Destroy;
end;
@@ -247,7 +295,9 @@ begin
ShowImages := True;
TabOrder := 0;
ImageList := FImagelist;
+ StateImageList := FStateImagelist;
OnChange := @TreeNodeChanged;
+ OnStateImageClicked := @StateImageClicked;
end;
cbShowImages := TfpgCheckBox.Create(self);
@@ -406,6 +456,7 @@ begin
begin
Name := 'cbMoveToTypes';
SetPosition(612, 172, 96, 22);
+ ExtraHint := '';
FontDesc := '#List';
Hint := '';
Items.Add('naAdd');
@@ -413,8 +464,8 @@ begin
Items.Add('naAddChild');
Items.Add('naAddChildFirst');
Items.Add('naInsert');
- TabOrder := 14;
FocusItem := 0;
+ TabOrder := 14;
end;
Label6 := TfpgLabel.Create(self);
@@ -473,6 +524,19 @@ begin
OnClick := @btnExpandAllClicked;
end;
+ btnShowChecked := TfpgButton.Create(self);
+ with btnShowChecked do
+ begin
+ Name := 'btnShowChecked';
+ SetPosition(160, 304, 100, 24);
+ Text := 'Show Checked';
+ FontDesc := '#Label1';
+ Hint := '';
+ ImageName := '';
+ TabOrder := 21;
+ OnClick := @btnShowCheckedClicked;
+ end;
+
{@VFD_BODY_END: MainForm}
PopulateTree;