diff options
Diffstat (limited to 'examples/gui/embedded_form')
-rw-r--r-- | examples/gui/embedded_form/demo1.lpi | 62 | ||||
-rw-r--r-- | examples/gui/embedded_form/demo1.lpr | 29 | ||||
-rw-r--r-- | examples/gui/embedded_form/extrafpc.cfg | 5 | ||||
-rw-r--r-- | examples/gui/embedded_form/fra_test.pas | 145 | ||||
-rw-r--r-- | examples/gui/embedded_form/frm_main.pas | 198 | ||||
-rw-r--r-- | examples/gui/embedded_form/units/.gitignore | 1 |
6 files changed, 440 insertions, 0 deletions
diff --git a/examples/gui/embedded_form/demo1.lpi b/examples/gui/embedded_form/demo1.lpi new file mode 100644 index 00000000..f6200396 --- /dev/null +++ b/examples/gui/embedded_form/demo1.lpi @@ -0,0 +1,62 @@ +<?xml version="1.0"?> +<CONFIG> + <ProjectOptions> + <Version Value="7"/> + <General> + <Flags> + <SaveOnlyProjectUnits Value="True"/> + </Flags> + <SessionStorage Value="InProjectDir"/> + <MainUnit Value="0"/> + <TargetFileExt Value=""/> + <UseAppBundle Value="False"/> + </General> + <VersionInfo> + <ProjectVersion Value=""/> + </VersionInfo> + <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="fpgui_toolkit"/> + </Item1> + </RequiredPackages> + <Units Count="3"> + <Unit0> + <Filename Value="demo1.lpr"/> + <IsPartOfProject Value="True"/> + <UnitName Value="demo1"/> + </Unit0> + <Unit1> + <Filename Value="fra_test.pas"/> + <IsPartOfProject Value="True"/> + <UnitName Value="fra_test"/> + </Unit1> + <Unit2> + <Filename Value="frm_main.pas"/> + <IsPartOfProject Value="True"/> + <UnitName Value="frm_main"/> + </Unit2> + </Units> + </ProjectOptions> + <CompilerOptions> + <Version Value="8"/> + <SearchPaths> + <IncludeFiles Value="$(ProjOutDir)/"/> + </SearchPaths> + <Other> + <CustomOptions Value="-FUunits"/> + <CompilerPath Value="$(CompPath)"/> + </Other> + </CompilerOptions> +</CONFIG> diff --git a/examples/gui/embedded_form/demo1.lpr b/examples/gui/embedded_form/demo1.lpr new file mode 100644 index 00000000..c006d530 --- /dev/null +++ b/examples/gui/embedded_form/demo1.lpr @@ -0,0 +1,29 @@ +program demo1; + +{$mode objfpc}{$H+} + +uses + {$IFDEF UNIX}{$IFDEF UseCThreads} + cthreads, + {$ENDIF}{$ENDIF} + Classes, fpg_main, frm_main, fra_test; + + +procedure MainProc; +var + frm: TMainForm; +begin + fpgApplication.Initialize; + frm := TMainForm.Create(nil); + try + frm.Show; + fpgApplication.Run; + finally + frm.Free; + end; +end; + +begin + MainProc; +end. + diff --git a/examples/gui/embedded_form/extrafpc.cfg b/examples/gui/embedded_form/extrafpc.cfg new file mode 100644 index 00000000..775d592f --- /dev/null +++ b/examples/gui/embedded_form/extrafpc.cfg @@ -0,0 +1,5 @@ +-FUunits +-Fu../../../lib/$fpctarget +-Xs +-XX +-CX diff --git a/examples/gui/embedded_form/fra_test.pas b/examples/gui/embedded_form/fra_test.pas new file mode 100644 index 00000000..33c6a1c5 --- /dev/null +++ b/examples/gui/embedded_form/fra_test.pas @@ -0,0 +1,145 @@ +unit fra_test; + +{$mode objfpc}{$H+} + +interface + +uses + SysUtils, Classes, fpg_base, fpg_main, fpg_checkbox, fpg_button, + fpg_menu, fpg_memo, fpg_panel; + +type + + { Note the tags for the UI Designer. This allows use to visually design + our frame. } + TMyFrame = class(TfpgBevel) + private + {@VFD_HEAD_BEGIN: MyFrame} + fraCheckBox1: TfpgCheckBox; + fraMenu1: TfpgMenuBar; + Button1: TfpgButton; + Memo1: TfpgMemo; + {@VFD_HEAD_END: MyFrame} + framnuFile: TfpgPopupMenu; + framnuHelp: TfpgPopupMenu; + WindowTitle: TfpgString; + procedure miHelpAboutClicked(Sender: TObject); + public + constructor Create(AOwner: TComponent); override; + destructor Destroy; override; + procedure AfterCreate; + end; + +{@VFD_NEWFORM_DECL} + +implementation + +uses + fpg_dialogs; + +{@VFD_NEWFORM_IMPL} + +procedure TMyFrame.miHelpAboutClicked(Sender: TObject); +begin + TfpgMessageDialog.AboutFPGui(''); +end; + +constructor TMyFrame.Create(AOwner: TComponent); +begin + inherited Create(AOwner); + Shape := bsSpacer; + AfterCreate; +end; + +destructor TMyFrame.Destroy; +begin + framnuFile.Free; + framnuHelp.Free; + inherited Destroy; +end; + +procedure TMyFrame.AfterCreate; +var + miFile: TfpgMenuItem; + miHelp: TfpgMenuItem; +begin + {%region 'Auto-generated GUI code' -fold} + {@VFD_BODY_BEGIN: MyFrame} + Name := 'MyFrame'; + SetPosition(380, 237, 200, 199); + WindowTitle := 'MyFrame'; + + fraCheckBox1 := TfpgCheckBox.Create(self); + with fraCheckBox1 do + begin + Name := 'fraCheckBox1'; + SetPosition(8, 40, 120, 20); + FontDesc := '#Label1'; + TabOrder := 0; + Text := 'CheckBox'; + end; + + fraMenu1 := TfpgMenuBar.Create(self); + with fraMenu1 do + begin + Name := 'fraMenu1'; + SetPosition(0, 0, 200, 24); + Anchors := [anLeft,anRight,anTop]; + miFile := AddMenuItem('File', nil); + AddMenuItem('Edit', nil).Enabled := False; + miHelp := AddMenuItem('Help', nil); + end; + + Button1 := TfpgButton.Create(self); + with Button1 do + begin + Name := 'Button1'; + SetPosition(104, 152, 80, 24); + Anchors := [anRight,anBottom]; + Text := 'Button'; + FontDesc := '#Label1'; + Hint := ''; + ImageName := ''; + TabOrder := 2; + end; + + Memo1 := TfpgMemo.Create(self); + with Memo1 do + begin + Name := 'Memo1'; + SetPosition(12, 60, 172, 84); + Anchors := [anLeft,anRight,anTop,anBottom]; + Lines.Add(''); + FontDesc := '#Edit1'; + TabOrder := 3; + end; + + {@VFD_BODY_END: MyFrame} + {%endregion} + + { There still seems to be a minor issue with Popup Menus used in a frame. So + for now the work around is to manually maintain the life of the Popup + Menus - so Owner is set to nil. } + framnuFile := TfpgPopupMenu.Create(nil); + with framnuFile do + begin + Name := 'framnuFile'; + SetPosition(44, 64, 120, 20); + AddMenuItem('Open...', '', nil); + AddMenuItem('-', '', nil); + AddMenuItem('Save', '', nil); + end; + miFile.SubMenu := framnuFile; + + framnuHelp := TfpgPopupMenu.Create(nil); + with framnuHelp do + begin + Name := 'framnuHelp'; + SetPosition(44, 64, 120, 20); + AddMenuItem('About fpGUI...', '', @miHelpAboutClicked); + end; + miHelp.SubMenu := framnuHelp; +end; + + +end. diff --git a/examples/gui/embedded_form/frm_main.pas b/examples/gui/embedded_form/frm_main.pas new file mode 100644 index 00000000..7cb28f6c --- /dev/null +++ b/examples/gui/embedded_form/frm_main.pas @@ -0,0 +1,198 @@ +unit frm_main; + +{$mode objfpc}{$H+} + +interface + +uses + SysUtils, Classes, + fpg_base, fpg_main, fpg_form, fpg_panel, fpg_button, + fpg_checkbox, fra_test, fpg_menu; + +type + + TMainForm = class(TfpgForm) + private + {@VFD_HEAD_BEGIN: MainForm} + BorderBevel: TfpgBevel; + Container: TfpgBevel; + btnExternal: TfpgButton; + btnEmbedded: TfpgButton; + CheckBox1: TfpgCheckBox; + MainMenu: TfpgMenubar; + mnuFile: TfpgPopupMenu; + mnuHelp: TfpgPopupMenu; + {@VFD_HEAD_END: MainForm} + frame: TMyFrame; + procedure btnExternalClicked(Sender: TObject); + procedure btnEmbeddedClicked(Sender: TObject); + procedure CheckBoxChanged(Sender: TObject); + procedure miQuitClicked(Sender: TObject); + procedure miHelpAboutClicked(Sender: TObject); + public + procedure AfterCreate; override; + end; + +{@VFD_NEWFORM_DECL} + +implementation + +uses + fpg_widget, fpg_dialogs; + + +{@VFD_NEWFORM_IMPL} + +procedure TMainForm.CheckBoxChanged(Sender: TObject); +begin + frame.Visible := Checkbox1.Checked; +end; + +procedure TMainForm.miQuitClicked(Sender: TObject); +begin + Close; +end; + +procedure TMainForm.miHelpAboutClicked(Sender: TObject); +begin + TfpgMessageDialog.Information('Embedded Frame Demo', 'A simple demo showing how to embed frames') +end; + +procedure TMainForm.btnExternalClicked(Sender: TObject); +var + frm: TfpgForm; + fra: TMyFrame; +begin + { create a form at runtime that will hold our frame. } + frm := TfpgForm.Create(nil); + try + frm.WindowPosition := wpOneThirdDown; + frm.Width := 284; + frm.Height := 257; + + // embed the frame in the form + fra := TMyFrame.Create(frm); + fra.Align := alClient; + + frm.ShowModal; + finally + frm.Free; + end; +end; + +procedure TMainForm.btnEmbeddedClicked(Sender: TObject); +begin + if Assigned(frame) then + exit; + + frame := TMyFrame.Create(Container); + with frame do + begin + Name := 'frame'; + SetPosition(0, 0, 280, 196); + Shape := bsSpacer; + Align := alClient; + Visible := True; + end; + + CheckBox1.Enabled := True; + CheckBox1.Checked := True; +end; + +procedure TMainForm.AfterCreate; +begin + {%region 'Auto-generated GUI code' -fold} + {@VFD_BODY_BEGIN: MainForm} + Name := 'MainForm'; + SetPosition(387, 207, 300, 340); + WindowTitle := 'MainForm'; + + BorderBevel := TfpgBevel.Create(self); + with BorderBevel do + begin + Name := 'BorderBevel'; + SetPosition(0, 68, 300, 272); + Anchors := [anLeft,anRight,anTop,anBottom]; + Shape := bsSpacer; + end; + + Container := TfpgBevel.Create(BorderBevel); + with Container do + begin + Name := 'Container'; + SetPosition(8, 8, 284, 257); + Anchors := [anLeft,anRight,anTop,anBottom]; + Style := bsLowered; + Shape := bsSpacer; + end; + + btnExternal := TfpgButton.Create(self); + with btnExternal do + begin + Name := 'btnExternal'; + SetPosition(12, 40, 80, 24); + Text := 'External'; + FontDesc := '#Label1'; + Hint := ''; + ImageName := ''; + TabOrder := 1; + OnClick := @btnExternalClicked; + end; + + btnEmbedded := TfpgButton.Create(self); + with btnEmbedded do + begin + Name := 'btnEmbedded'; + SetPosition(100, 40, 80, 24); + Text := 'Embedded'; + FontDesc := '#Label1'; + Hint := ''; + ImageName := ''; + TabOrder := 2; + OnClick := @btnEmbeddedClicked; + end; + + CheckBox1 := TfpgCheckBox.Create(self); + with CheckBox1 do + begin + Name := 'CheckBox1'; + SetPosition(192, 40, 93, 20); + FontDesc := '#Label1'; + TabOrder := 4; + Text := 'Visible'; + Enabled := false; + OnChange := @CheckBoxChanged; + end; + + MainMenu := TfpgMenubar.Create(self); + with MainMenu do + begin + Name := 'MainMenu'; + SetPosition(0, 0, 300, 28); + Anchors := [anLeft,anRight,anTop]; + end; + + mnuFile := TfpgPopupMenu.Create(self); + with mnuFile do + begin + Name := 'mnuFile'; + SetPosition(156, 88, 120, 20); + AddMenuItem('Quit', '', @miQuitClicked); + end; + + mnuHelp := TfpgPopupMenu.Create(self); + with mnuHelp do + begin + Name := 'mnuHelp'; + SetPosition(156, 112, 120, 20); + AddMenuItem('About...', '', @miHelpAboutClicked); + end; + + {@VFD_BODY_END: MainForm} + {%endregion} + MainMenu.AddMenuItem('File', nil).SubMenu := mnuFile; + MainMenu.AddMenuItem('Help', nil).SubMenu := mnuHelp; +end; + + +end. diff --git a/examples/gui/embedded_form/units/.gitignore b/examples/gui/embedded_form/units/.gitignore new file mode 100644 index 00000000..72e8ffc0 --- /dev/null +++ b/examples/gui/embedded_form/units/.gitignore @@ -0,0 +1 @@ +* |