summaryrefslogtreecommitdiff
path: root/examples/gui
diff options
context:
space:
mode:
authorGraeme Geldenhuys <graemeg@gmail.com>2010-08-18 20:46:01 +0200
committerGraeme Geldenhuys <graeme@mastermaths.co.za>2010-08-19 10:34:32 +0200
commit526b997f1276750cdfda142a8e88a3a9e28b35c2 (patch)
treef9f291d9d6c6f8c117815ffd69fe12d434762113 /examples/gui
parentc5c2de472878256070b85e61d738ee1253c3352b (diff)
downloadfpGUI-526b997f1276750cdfda142a8e88a3a9e28b35c2.tar.xz
Treeview Demo: extended the demo to show Node values as user selects them.
This should give users a better understanding of what those properties mean and how they work. Also a nice test to see if the Treeview Nodes work correctly.
Diffstat (limited to 'examples/gui')
-rw-r--r--examples/gui/treeviewtest/treeviewtest.lpr266
1 files changed, 263 insertions, 3 deletions
diff --git a/examples/gui/treeviewtest/treeviewtest.lpr b/examples/gui/treeviewtest/treeviewtest.lpr
index 9c57d5f9..bedf0dd4 100644
--- a/examples/gui/treeviewtest/treeviewtest.lpr
+++ b/examples/gui/treeviewtest/treeviewtest.lpr
@@ -14,23 +14,47 @@ uses
fpg_tree,
fpg_checkbox,
fpg_button,
- fpg_imagelist;
+ fpg_imagelist,
+ fpg_label,
+ fpg_panel,
+ fpg_dialogs,
+ fpg_combobox;
type
TMainForm = class(TfpgForm)
+ procedure TestButtonClicked(Sender: TObject);
private
{@VFD_HEAD_BEGIN: MainForm}
tree: TfpgTreeView;
cbShowImages: TfpgCheckBox;
cbIndentNode: TfpgCheckBox;
btnClear: TfpgButton;
+ Label1: TfpgLabel;
+ Label2: TfpgLabel;
+ Label3: TfpgLabel;
+ Label4: TfpgLabel;
+ Label5: TfpgLabel;
+ Bevel1: TfpgBevel;
+ lblSource: TfpgLabel;
+ lblDestination: TfpgLabel;
+ btnSource: TfpgButton;
+ btnDest: TfpgButton;
+ btnMoveTo: TfpgButton;
+ cbMoveToTypes: TfpgComboBox;
+ Button1: TfpgButton;
{@VFD_HEAD_END: MainForm}
FImagelist: TfpgImageList;
+ FSrcNode: TfpgTreeNode;
+ FDestnode: TfpgTreeNode;
procedure cbShowImagesChange(Sender: TObject);
procedure cbIndentNodeChange(Sender: TObject);
procedure btnClearClicked(Sender: TObject);
+ procedure TreeNodeChanged(Sender: TObject);
procedure PopulateTree;
+ procedure btnSourceClicked(Sender: TObject);
+ procedure btnDestinationClicked(Sender: TObject);
+ procedure btnMoveToClicked(Sender: TObject);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
@@ -57,6 +81,33 @@ begin
end;
end;
+procedure TMainForm.TreeNodeChanged(Sender: TObject);
+const
+ cParent = 'Parent = %s';
+ cPrev = 'Prev = %s';
+ cNext = 'Next = %s';
+ cFirstSubNode = 'FirstSubnode = %s';
+ cLastSubNode = 'LastSubnode = %s';
+var
+ n: TfpgTreeNode;
+
+ procedure PrintNodeInfo(ALabel: TfpgLabel; AFormat: string; ANode: TfpgTreeNode);
+ begin
+ if ANode = nil then
+ ALabel.Text := Format(AFormat, ['nil'])
+ else
+ ALabel.Text := Format(AFormat, [ANode.Text]);
+ end;
+
+begin
+ n := Tree.Selection;
+ PrintNodeInfo(Label1, cParent, n.Parent);
+ PrintNodeInfo(Label2, cPrev, n.Prev);
+ PrintNodeInfo(Label3, cNext, n.Next);
+ PrintNodeInfo(Label4, cFirstSubNode, n.FirstSubNode);
+ PrintNodeInfo(Label5, cLastSubNode, n.LastSubNode);
+end;
+
procedure TMainForm.PopulateTree;
var
n: TfpgTreeNode;
@@ -92,6 +143,58 @@ begin
n2.AppendText('Child 1').AppendText('Child 2');
n2.Collapsed := False;
end;
+
+ TreeNodeChanged(nil);
+end;
+
+procedure TMainForm.btnSourceClicked(Sender: TObject);
+begin
+ FSrcNode := tree.Selection;
+ if Assigned(FSrcNode) then
+ lblSource.Text := FSrcNode.Text
+ else
+ lblSource.Text := '--';
+end;
+
+procedure TMainForm.btnDestinationClicked(Sender: TObject);
+begin
+ FDestNode := tree.Selection;
+ if Assigned(FDestNode) then
+ lblDestination.Text := FDestNode.Text
+ else
+ lblDestination.Text := '--';
+end;
+
+procedure TMainForm.btnMoveToClicked(Sender: TObject);
+var
+ i: integer;
+begin
+ if FSrcNode = FDestNode then
+ begin
+ ShowMessage('Source and Destination may not be the same');
+ exit;
+ end;
+ i := cbMoveToTypes.FocusItem;
+ FSrcNode.MoveTo(FDestnode, TfpgNodeAttachMode(i)); // This cast is a hack! Do not do this in real-world apps!!
+ tree.FullExpand;
+ tree.Invalidate;
+ // reset values
+ FSrcNode := nil;
+ FDestnode := nil;
+ lblSource.Text := '--';
+ lblDestination.Text := '--';
+
+ TreeNodeChanged(nil);
+end;
+
+procedure TMainForm.TestButtonClicked(Sender: TObject);
+var
+ n: TfpgTreeNode;
+begin
+ n := Tree.Selection;
+ n.Parent.Remove(n);
+ n.Free;
+ Tree.Invalidate;
end;
procedure TMainForm.cbShowImagesChange(Sender: TObject);
@@ -122,8 +225,9 @@ begin
inherited AfterCreate;
{@VFD_BODY_BEGIN: MainForm}
Name := 'MainForm';
- SetPosition(294, 174, 300, 250);
+ SetPosition(294, 174, 709, 250);
WindowTitle := 'Treeview Test';
+ Hint := '';
WindowPosition := wpScreenCenter;
tree := TfpgTreeView.Create(self);
@@ -131,11 +235,14 @@ begin
begin
Name := 'tree';
SetPosition(8, 8, 284, 184);
- Anchors := [anLeft,anRight,anTop,anBottom];
+ Anchors := [anLeft,anTop,anBottom];
FontDesc := '#Label1';
+ Hint := '';
ScrollWheelDelta := 30;
ShowImages := True;
+ TabOrder := 1;
ImageList := FImagelist;
+ OnChange := @TreeNodeChanged;
end;
cbShowImages := TfpgCheckBox.Create(self);
@@ -146,6 +253,7 @@ begin
Anchors := [anLeft,anBottom];
Checked := True;
FontDesc := '#Label1';
+ Hint := '';
TabOrder := 1;
Text := 'Show images';
OnChange := @cbShowImagesChange;
@@ -159,6 +267,7 @@ begin
Anchors := [anLeft,anBottom];
Checked := True;
FontDesc := '#Label1';
+ Hint := '';
TabOrder := 2;
Text := 'Indent node with no image';
OnChange := @cbIndentNodeChange;
@@ -169,6 +278,7 @@ begin
begin
Name := 'btnClear';
SetPosition(8, 222, 144, 23);
+ Anchors := [anLeft,anBottom];
Text := 'Clear Selected Node';
FontDesc := '#Label1';
Hint := '';
@@ -177,6 +287,156 @@ begin
OnClick := @btnClearClicked;
end;
+ Label1 := TfpgLabel.Create(self);
+ with Label1 do
+ begin
+ Name := 'Label1';
+ SetPosition(312, 12, 292, 16);
+ FontDesc := '#Label1';
+ Hint := '';
+ Text := 'Label';
+ end;
+
+ Label2 := TfpgLabel.Create(self);
+ with Label2 do
+ begin
+ Name := 'Label2';
+ SetPosition(312, 32, 288, 16);
+ FontDesc := '#Label1';
+ Hint := '';
+ Text := 'Label';
+ end;
+
+ Label3 := TfpgLabel.Create(self);
+ with Label3 do
+ begin
+ Name := 'Label3';
+ SetPosition(312, 52, 272, 16);
+ FontDesc := '#Label1';
+ Hint := '';
+ Text := 'Label';
+ end;
+
+ Label4 := TfpgLabel.Create(self);
+ with Label4 do
+ begin
+ Name := 'Label4';
+ SetPosition(312, 72, 300, 16);
+ FontDesc := '#Label1';
+ Hint := '';
+ Text := 'Label';
+ end;
+
+ Label5 := TfpgLabel.Create(self);
+ with Label5 do
+ begin
+ Name := 'Label5';
+ SetPosition(312, 92, 320, 16);
+ FontDesc := '#Label1';
+ Hint := '';
+ Text := 'Label';
+ end;
+
+ Bevel1 := TfpgBevel.Create(self);
+ with Bevel1 do
+ begin
+ Name := 'Bevel1';
+ SetPosition(312, 116, 388, 12);
+ Anchors := [anLeft,anRight,anTop];
+ BorderStyle := bsDouble;
+ Hint := '';
+ Style := bsLowered;
+ Shape := bsTopLine;
+ end;
+
+ lblSource := TfpgLabel.Create(self);
+ with lblSource do
+ begin
+ Name := 'lblSource';
+ SetPosition(312, 160, 140, 16);
+ FontDesc := '#Label1';
+ Hint := '';
+ Text := 'Label';
+ end;
+
+ lblDestination := TfpgLabel.Create(self);
+ with lblDestination do
+ begin
+ Name := 'lblDestination';
+ SetPosition(464, 160, 128, 16);
+ FontDesc := '#Label1';
+ Hint := '';
+ Text := 'Label';
+ end;
+
+ btnSource := TfpgButton.Create(self);
+ with btnSource do
+ begin
+ Name := 'btnSource';
+ SetPosition(312, 132, 80, 24);
+ Text := 'Source';
+ FontDesc := '#Label1';
+ Hint := '';
+ ImageName := '';
+ TabOrder := 13;
+ OnClick := @btnSourceClicked;
+ end;
+
+ btnDest := TfpgButton.Create(self);
+ with btnDest do
+ begin
+ Name := 'btnDest';
+ SetPosition(464, 132, 80, 24);
+ Text := 'Destination';
+ FontDesc := '#Label1';
+ Hint := '';
+ ImageName := '';
+ TabOrder := 14;
+ OnClick := @btnDestinationClicked;
+ end;
+
+ btnMoveTo := TfpgButton.Create(self);
+ with btnMoveTo do
+ begin
+ Name := 'btnMoveTo';
+ SetPosition(608, 132, 80, 24);
+ Text := 'MoveTo';
+ FontDesc := '#Label1';
+ Hint := '';
+ ImageName := '';
+ TabOrder := 15;
+ OnClick := @btnMoveToClicked;
+ end;
+
+ cbMoveToTypes := TfpgComboBox.Create(self);
+ with cbMoveToTypes do
+ begin
+ Name := 'cbMoveToTypes';
+ SetPosition(608, 164, 96, 22);
+ FontDesc := '#List';
+ Hint := '';
+ Items.Add('naAdd');
+ Items.Add('naAddFirst');
+ Items.Add('naAddChild');
+ Items.Add('naAddChildFirst');
+ Items.Add('naInsert');
+ TabOrder := 16;
+ FocusItem := 0;
+ end;
+
+ Button1 := TfpgButton.Create(self);
+ with Button1 do
+ begin
+ Name := 'Button1';
+ SetPosition(472, 208, 80, 24);
+ Text := 'Button';
+ FontDesc := '#Label1';
+ Hint := '';
+ ImageName := '';
+ TabOrder := 17;
+ OnClick := @TestButtonClicked;
+ end;
+
{@VFD_BODY_END: MainForm}
PopulateTree;