summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorGraeme Geldenhuys <graemeg@gmail.com>2010-05-07 01:00:47 +0200
committerGraeme Geldenhuys <graemeg@gmail.com>2010-05-07 01:00:47 +0200
commit99f194504f3306189d6658fc0ef10a757ea054e9 (patch)
tree192880e6364918980579d582886da6b48133a96a /examples
parentfdcf31f5c1a38dd4b10a53149bd708b037f6db96 (diff)
downloadfpGUI-99f194504f3306189d6658fc0ef10a757ea054e9.tar.xz
Updated MenuTest demo
* Reworked the code so the UI is managed by the UI Forms Designer * Added a new View menu with checkitem menus. * Added Toolbar and Statusbar to give basic visual effect when menu check items are toggled. * Added a Memo used as a Log output window.
Diffstat (limited to 'examples')
-rw-r--r--examples/gui/menutest/menutest.lpi10
-rw-r--r--examples/gui/menutest/menutest.lpr267
2 files changed, 241 insertions, 36 deletions
diff --git a/examples/gui/menutest/menutest.lpi b/examples/gui/menutest/menutest.lpi
index f3d307af..96e0dc63 100644
--- a/examples/gui/menutest/menutest.lpi
+++ b/examples/gui/menutest/menutest.lpi
@@ -1,15 +1,14 @@
<?xml version="1.0"?>
<CONFIG>
<ProjectOptions>
- <PathDelim Value="/"/>
- <Version Value="6"/>
+ <Version Value="7"/>
<General>
<Flags>
<SaveOnlyProjectUnits Value="True"/>
+ <LRSInOutputDirectory Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
- <IconPath Value="./"/>
<TargetFileExt Value=""/>
</General>
<VersionInfo>
@@ -45,6 +44,11 @@
<Debugging>
<GenerateDebugInfo Value="True"/>
</Debugging>
+ <Options>
+ <Win32>
+ <GraphicApplication Value="True"/>
+ </Win32>
+ </Options>
</Linking>
<Other>
<CustomOptions Value="-FUunits
diff --git a/examples/gui/menutest/menutest.lpr b/examples/gui/menutest/menutest.lpr
index 1db064fb..e4d40cf0 100644
--- a/examples/gui/menutest/menutest.lpr
+++ b/examples/gui/menutest/menutest.lpr
@@ -7,24 +7,44 @@ uses
cthreads,
{$ENDIF}{$ENDIF}
Classes,
+ fpg_base,
fpg_main,
fpg_form,
fpg_menu,
- fpg_edit;
+ fpg_edit,
+ fpg_panel,
+ fpg_button,
+ fpg_dialogs,
+ fpg_memo;
type
TMainForm = class(TfpgForm)
private
+ {@VFD_HEAD_BEGIN: MainForm}
FMenuBar: TfpgMenuBar;
+ StatusBar: TfpgPanel;
+ Toolbar: TfpgBevel;
+ btnQuit: TfpgButton;
+ btnSave: TfpgButton;
+ btnOpen: TfpgButton;
+ btnAbout: TfpgButton;
+ edit1: TfpgEdit;
+ Memo1: TfpgMemo;
FFileSubMenu: TfpgPopupMenu;
FEditSubMenu: TfpgPopupMenu;
FEditSelectSubMenu: TfpgPopupMenu;
+ FViewSubMenu: TfpgPopupMenu;
FHelpSubMenu: TfpgPopupMenu;
- edit1: TfpgEdit;
+ {@VFD_HEAD_END: MainForm}
procedure miExitClicked(Sender: TObject);
procedure miMenuItemSelected(Sender: TObject);
+ procedure miMenuItemChecked(Sender: TObject);
+ procedure miToolBarChecked(Sender: TObject);
+ procedure miStatusBarChecked(Sender: TObject);
+ procedure btnAboutClicked(Sender: TObject);
+ procedure Log(const AText: TfpgString);
public
- constructor Create(AOwner: TComponent); override;
+ procedure AfterCreate; override;
end;
@@ -38,52 +58,233 @@ end;
procedure TMainForm.miMenuItemSelected(Sender: TObject);
begin
if Sender is TfpgMenuItem then
- writeln('Menu clicked: ', TfpgMenuItem(Sender).Text);
+ Log('Menu clicked: ' + TfpgMenuItem(Sender).Text);
+end;
+
+procedure TMainForm.miMenuItemChecked(Sender: TObject);
+begin
+ TfpgMenuItem(Sender).Checked := not TfpgMenuItem(Sender).Checked;
+ Log('Check Menu item toggled');
+end;
+
+procedure TMainForm.miToolBarChecked(Sender: TObject);
+begin
+ TfpgMenuItem(Sender).Checked := not TfpgMenuItem(Sender).Checked;
+ ToolBar.Visible := not ToolBar.Visible;
+ Log('Check Menu for Toolbar toggled');
+end;
+
+procedure TMainForm.miStatusBarChecked(Sender: TObject);
+begin
+ TfpgMenuItem(Sender).Checked := not TfpgMenuItem(Sender).Checked;
+ StatusBar.Visible := not StatusBar.Visible;
+ Log('Check Menu for Statusbar toggled');
+end;
+
+procedure TMainForm.btnAboutClicked(Sender: TObject);
+begin
+ TfpgMessageDialog.AboutFPGui;
+end;
+
+procedure TMainForm.Log(const AText: TfpgString);
+begin
+ Memo1.Lines.Add(AText);
end;
-constructor TMainForm.Create(AOwner: TComponent);
+procedure TMainForm.AfterCreate;
begin
- inherited Create(AOwner);
+ {%region 'Auto-generated GUI code' -fold}
+ {@VFD_BODY_BEGIN: MainForm}
+ Name := 'MainForm';
+ SetPosition(316, 169, 400, 200);
WindowTitle := 'Menu Test';
- WindowPosition := wpUser;
- SetPosition(100, 100, 400, 200);
-
- // Create top level sub-menus
+ Hint := '';
+ WindowPosition := wpOneThirdDown;
+
+ FMenuBar := TfpgMenuBar.Create(self);
+ with FMenuBar do
+ begin
+ Name := 'FMenuBar';
+ SetPosition(0, 0, 400, 24);
+ Anchors := [anLeft,anRight,anTop];
+ end;
+
+ StatusBar := TfpgPanel.Create(self);
+ with StatusBar do
+ begin
+ Name := 'StatusBar';
+ SetPosition(0, 176, 400, 24);
+ Anchors := [anLeft,anRight,anBottom];
+ Alignment := taLeftJustify;
+ FontDesc := '#Label1';
+ Hint := '';
+ Style := bsLowered;
+ Text := 'This is the status bar...';
+ end;
+
+ Toolbar := TfpgBevel.Create(self);
+ with Toolbar do
+ begin
+ Name := 'Toolbar';
+ SetPosition(0, 24, 400, 29);
+ Anchors := [anLeft,anRight,anTop];
+ Hint := '';
+ Shape := bsBottomLine;
+ end;
+
+ btnQuit := TfpgButton.Create(Toolbar);
+ with btnQuit do
+ begin
+ Name := 'btnQuit';
+ SetPosition(4, 2, 24, 24);
+ Text := '';
+ Embedded := True;
+ FontDesc := '#Label1';
+ Hint := '';
+ ImageMargin := -1;
+ ImageName := 'stdimg.quit';
+ ImageSpacing := 0;
+ TabOrder := 1;
+ OnClick := @miExitClicked;
+ end;
+
+ btnSave := TfpgButton.Create(Toolbar);
+ with btnSave do
+ begin
+ Name := 'btnSave';
+ SetPosition(56, 2, 24, 24);
+ Text := '';
+ Embedded := True;
+ FontDesc := '#Label1';
+ Hint := '';
+ ImageMargin := -1;
+ ImageName := 'stdimg.save';
+ ImageSpacing := 0;
+ TabOrder := 2;
+ end;
+
+ btnOpen := TfpgButton.Create(Toolbar);
+ with btnOpen do
+ begin
+ Name := 'btnOpen';
+ SetPosition(32, 2, 24, 24);
+ Text := '';
+ Embedded := True;
+ FontDesc := '#Label1';
+ Hint := '';
+ ImageMargin := -1;
+ ImageName := 'stdimg.open';
+ ImageSpacing := 0;
+ TabOrder := 3;
+ end;
+
+ btnAbout := TfpgButton.Create(Toolbar);
+ with btnAbout do
+ begin
+ Name := 'btnAbout';
+ SetPosition(84, 2, 24, 24);
+ Text := '';
+ Embedded := True;
+ FontDesc := '#Label1';
+ Hint := '';
+ ImageMargin := -1;
+ ImageName := 'stdimg.help';
+ ImageSpacing := 0;
+ TabOrder := 4;
+ OnClick := @btnAboutClicked;
+ end;
+
+ edit1 := TfpgEdit.Create(self);
+ with edit1 do
+ begin
+ Name := 'edit1';
+ SetPosition(8, 62, 100, 24);
+ ExtraHint := '';
+ Hint := '';
+ TabOrder := 6;
+ Text := '';
+ FontDesc := '#Edit1';
+ end;
+
+ Memo1 := TfpgMemo.Create(self);
+ with Memo1 do
+ begin
+ Name := 'Memo1';
+ SetPosition(124, 60, 268, 108);
+ Anchors := [anLeft,anRight,anTop,anBottom];
+ Hint := '';
+ Lines.Add('<= Text Edit has a popup menu too.');
+ FontDesc := '#Edit1';
+ TabOrder := 10;
+ end;
+
FFileSubMenu := TfpgPopupMenu.Create(self);
- FFileSubMenu.AddMenuItem('&Open', 'Ctrl-O', @miMenuItemSelected);
- FFileSubMenu.AddMenuItem('&Save', 'Ctrl-S', @miMenuItemSelected);
- FFileSubMenu.AddMenuItem('S&ave As', 'Ctrl+Shift+S', @miMenuItemSelected);
- FFileSubMenu.AddMenuItem('-', '', nil);
- FFileSubMenu.AddMenuItem('Save && Reload', '', @miMenuItemSelected);
- FFileSubMenu.AddMenuItem('-', '', nil);
- FFileSubMenu.AddMenuItem('&Quit', 'Ctrl-Q', @miExitClicked);
+ with FFileSubMenu do
+ begin
+ Name := 'FFileSubMenu';
+ SetPosition(264, 60, 120, 20);
+ AddMenuItem('&Open', 'Ctrl-O', @miMenuItemSelected);
+ AddMenuItem('&Save', 'Ctrl-S', @miMenuItemSelected);
+ AddMenuItem('S&ave As', 'Ctrl+Shift+S', @miMenuItemSelected);
+ AddMenuItem('-', '', nil);
+ AddMenuItem('Save && Reload', '', @miMenuItemSelected);
+ AddMenuItem('-', '', nil);
+ AddMenuItem('&Quit', 'Ctrl-Q', @miExitClicked);
+ end;
FEditSubMenu := TfpgPopupMenu.Create(self);
- FEditSubMenu.AddMenuItem('&Cut', 'Ctrl-X', @miMenuItemSelected);
- FEditSubMenu.AddMenuItem('C&opy', 'Ctrl-C', @miMenuItemSelected);
- FEditSubMenu.AddMenuItem('&Paste', 'Ctrl-V', @miMenuItemSelected);
- FEditSubMenu.AddMenuItem('-', '', nil);
- FEditSubMenu.AddMenuItem('&Spell check', 'F4', @miMenuItemSelected).Enabled := False;
+ with FEditSubMenu do
+ begin
+ Name := 'FEditSubMenu';
+ SetPosition(264, 80, 120, 20);
+ AddMenuItem('&Cut', 'Ctrl-X', @miMenuItemSelected);
+ AddMenuItem('C&opy', 'Ctrl-C', @miMenuItemSelected);
+ AddMenuItem('&Paste', 'Ctrl-V', @miMenuItemSelected);
+ AddMenuItem('-', '', nil);
+ AddMenuItem('&Spell check', 'F4', @miMenuItemSelected).Enabled := False;
+ end;
+
FEditSelectSubMenu := TfpgPopupMenu.Create(self);
- FEditSubMenu.AddMenuItem('Selec&t', '', nil).SubMenu := FEditSelectSubMenu;
- FEditSelectSubMenu.AddMenuItem('Select All', '', @miMenuItemSelected);
- FEditSelectSubMenu.AddMenuItem('Select Word', '', @miMenuItemSelected);
- FEditSelectSubMenu.AddMenuItem('Select Line', '', @miMenuItemSelected);
+ with FEditSelectSubMenu do
+ begin
+ Name := 'FEditSelectSubMenu';
+ SetPosition(264, 100, 120, 20);
+ AddMenuItem('Select All', '', @miMenuItemSelected);
+ AddMenuItem('Select Word', '', @miMenuItemSelected);
+ AddMenuItem('Select Line', '', @miMenuItemSelected);
+ FEditSubMenu.AddMenuItem('Selec&t', '', nil).SubMenu := FEditSelectSubMenu;
+ end;
+
+ FViewSubMenu := TfpgPopupMenu.Create(self);
+ with FViewSubMenu do
+ begin
+ Name := 'FViewSubMenu';
+ SetPosition(264, 120, 120, 20);
+ AddMenuItem('Full Screen', '', @miMenuItemChecked);
+ AddMenuItem('Tool Bar', '', @miToolBarChecked).Checked := True;
+ AddMenuItem('Status Bar', '', @miStatusBarChecked).Checked := True;
+ AddMenuItem('Line Numbers', '', @miMenuItemChecked);
+ end;
FHelpSubMenu := TfpgPopupMenu.Create(self);
- FHelpSubMenu.AddMenuItem('&About', 'F12', @miMenuItemSelected);
- FHelpSubMenu.AddMenuItem('Test Russian text -> Òåñò', '', @miMenuItemSelected);
+ with FHelpSubMenu do
+ begin
+ Name := 'FHelpSubMenu';
+ SetPosition(264, 140, 120, 20);
+ AddMenuItem('&About', 'F12', @btnAboutClicked);
+ AddMenuItem('Test Russian text -> Òåñò', '', @miMenuItemSelected);
+ end;
+
+ {@VFD_BODY_END: MainForm}
+ {%endregion}
- // Create main menu bar
- FMenuBar := CreateMenuBar(self);
+ // Attach sub menus to main menu bar
FMenuBar.AddMenuItem('&File', nil).SubMenu := FFileSubMenu;
FMenuBar.AddMenuItem('&Edit', nil).SubMenu := FEditSubMenu;
+ FMenuBar.AddMenuItem('&View', nil).SubMenu := FViewSubMenu;
FMenuBar.AddMenuItem('&Windows', nil);
FMenuBar.AddMenuItem('&Disabled', nil).Enabled := False;
FMenuBar.AddMenuItem('&Help', nil).SubMenu := FHelpSubMenu;
-
- edit1 := TfpgEdit.Create(self);
- edit1.SetPosition(10, 70, 100, 24);
end;