summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/gui/splashscreen/commands.pas89
-rw-r--r--examples/gui/splashscreen/extrafpc.cfg5
-rw-r--r--examples/gui/splashscreen/frm_main.pas125
-rw-r--r--examples/gui/splashscreen/frm_splashscreen.pas111
-rw-r--r--examples/gui/splashscreen/test.lpi67
-rw-r--r--examples/gui/splashscreen/test.lpr41
-rw-r--r--src/corelib/gfxbase.pas2
7 files changed, 439 insertions, 1 deletions
diff --git a/examples/gui/splashscreen/commands.pas b/examples/gui/splashscreen/commands.pas
new file mode 100644
index 00000000..aa948220
--- /dev/null
+++ b/examples/gui/splashscreen/commands.pas
@@ -0,0 +1,89 @@
+{
+ Here we define some commands that can be reused throughout a application.
+ Command actions are kept separate from the UI code (Forms).
+}
+unit commands;
+
+{$mode objfpc}{$H+}
+
+interface
+
+uses
+ gfx_command_intf,
+ gui_memo;
+
+type
+ // non reference counted interface
+ TNullInterfacedObject = class(TObject)
+ protected
+ function QueryInterface(const IID: TGUID; out Obj): longint; stdcall;
+ function _AddRef: longint; stdcall;
+ function _Release: longint; stdcall;
+ end;
+
+
+ TAddCommand = class(TInterfacedObject, ICommand)
+ private
+ FMemo: TfpgMemo;
+ public
+ constructor Create(AMemo: TfpgMemo); reintroduce;
+ procedure Execute;
+ end;
+
+
+ TExitCommand = class(TInterfacedObject, ICommand)
+ public
+ procedure Execute;
+ end;
+
+
+implementation
+
+uses
+ fpgfx, SysUtils;
+
+{ TNullInterfacedObject }
+
+function TNullInterfacedObject.QueryInterface(const IID: TGUID; out Obj): longint; stdcall;
+begin
+ if GetInterface(IID, Obj) then
+ Result := 0
+ else
+ result := integer(e_nointerface);
+end;
+
+function TNullInterfacedObject._AddRef: longint; stdcall;
+begin
+ Result := -1;
+end;
+
+function TNullInterfacedObject._Release: longint; stdcall;
+begin
+ Result := -1;
+end;
+
+{ TAddCommand }
+
+constructor TAddCommand.Create(AMemo: TfpgMemo);
+begin
+ inherited Create;
+ FMemo := AMemo;
+end;
+
+procedure TAddCommand.Execute;
+begin
+ Writeln('>> TAddComand.Execute');
+ FMemo.Lines.Add('Hello ' + IntToStr(Random(500)));
+ FMemo.Invalidate;
+end;
+
+{ TExitCommand }
+
+procedure TExitCommand.Execute;
+begin
+ Writeln('>> TExitComand.Execute');
+ fpgApplication.Terminated := True;
+end;
+
+end.
+
diff --git a/examples/gui/splashscreen/extrafpc.cfg b/examples/gui/splashscreen/extrafpc.cfg
new file mode 100644
index 00000000..073dc4b6
--- /dev/null
+++ b/examples/gui/splashscreen/extrafpc.cfg
@@ -0,0 +1,5 @@
+-FUunits
+-Fu../../../lib
+-Xs
+-XX
+-CX
diff --git a/examples/gui/splashscreen/frm_main.pas b/examples/gui/splashscreen/frm_main.pas
new file mode 100644
index 00000000..1c2548dd
--- /dev/null
+++ b/examples/gui/splashscreen/frm_main.pas
@@ -0,0 +1,125 @@
+{
+ This demonstrates the usage of ICommand and ICommandHolder. They work
+ similar to Delphi's TAction classes
+}
+unit frm_main;
+
+{$mode objfpc}{$H+}
+
+interface
+
+uses
+ SysUtils, Classes, gfxbase, fpgfx, gui_edit,
+ gfx_widget, gui_form, gui_label, gui_button,
+ gui_listbox, gui_memo, gui_combobox, gui_grid,
+ gui_dialogs, gui_checkbox, gui_tree, gui_trackbar,
+ gui_progressbar, gui_radiobutton, gui_tab, gui_menu,
+ gui_bevel;
+
+type
+
+ TMainForm = class(TfpgForm)
+ private
+ procedure CommandHandler(Sender: TObject);
+ public
+ {@VFD_HEAD_BEGIN: MainForm}
+ btnAdd: TfpgButton;
+ memName1: TfpgMemo;
+ btnQuit: TfpgButton;
+ MainMenu: TfpgMenuBar;
+ mnuFile: TfpgPopupMenu;
+ {@VFD_HEAD_END: MainForm}
+ procedure AfterCreate; override;
+ end;
+
+{@VFD_NEWFORM_DECL}
+
+implementation
+
+uses
+ gfx_command_intf,
+ commands;
+
+{@VFD_NEWFORM_IMPL}
+
+{ A single event handler that handles all Command based events. }
+procedure TMainForm.CommandHandler(Sender: TObject);
+var
+ cmd: ICommand;
+ holder: ICommandHolder;
+begin
+ if Supports(Sender, ICommandHolder, holder) then
+ begin
+ cmd := holder.GetCommand;
+ cmd.Execute;
+ end;
+end;
+
+procedure TMainForm.AfterCreate;
+begin
+ {@VFD_BODY_BEGIN: MainForm}
+ Name := 'MainForm';
+ SetPosition(293, 236, 416, 273);
+ WindowTitle := 'Command Interface Test';
+ WindowPosition := wpScreenCenter;
+
+ btnAdd := TfpgButton.Create(self);
+ with btnAdd do
+ begin
+ Name := 'btnAdd';
+ SetPosition(332, 36, 75, 24);
+ Text := 'Add';
+ FontDesc := '#Label1';
+ ImageName := '';
+ OnClick := @CommandHandler;
+ end;
+
+ memName1 := TfpgMemo.Create(self);
+ with memName1 do
+ begin
+ Name := 'memName1';
+ SetPosition(8, 36, 316, 228);
+ Lines.Add('');
+ FontDesc := '#Edit1';
+ end;
+
+ btnQuit := TfpgButton.Create(self);
+ with btnQuit do
+ begin
+ Name := 'btnQuit';
+ SetPosition(332, 240, 75, 24);
+ Text := 'Quit';
+ FontDesc := '#Label1';
+ ImageName := '';
+ OnClick := @CommandHandler;
+ end;
+
+ MainMenu := TfpgMenuBar.Create(self);
+ with MainMenu do
+ begin
+ Name := 'MainMenu';
+ SetPosition(0, 0, 416, 24);
+ Anchors := [anLeft,anRight,anTop];
+ end;
+
+ mnuFile := TfpgPopupMenu.Create(self);
+ with mnuFile do
+ begin
+ Name := 'mnuFile';
+ SetPosition(44, 72, 120, 20);
+ AddMenuItem('Quit', '', @CommandHandler);
+ end;
+
+ {@VFD_BODY_END: MainForm}
+
+ MainMenu.AddMenuItem('File', nil).SubMenu := mnuFile;
+
+ // instantiate the Command classes
+ btnAdd.SetCommand(TAddCommand.Create(memName1));
+ btnQuit.SetCommand(TExitCommand.Create);
+ // The menu item File|Quit shares the command of btnQuit
+ mnuFile.MenuItemByName('Quit').SetCommand(btnQuit.GetCommand);
+end;
+
+
+end.
diff --git a/examples/gui/splashscreen/frm_splashscreen.pas b/examples/gui/splashscreen/frm_splashscreen.pas
new file mode 100644
index 00000000..14030f2d
--- /dev/null
+++ b/examples/gui/splashscreen/frm_splashscreen.pas
@@ -0,0 +1,111 @@
+unit frm_splashscreen;
+
+{$mode objfpc}{$H+}
+
+interface
+
+uses
+ SysUtils, Classes, gfxbase, fpgfx, gui_edit,
+ gfx_widget, gui_form, gui_label, gui_button,
+ gui_listbox, gui_memo, gui_combobox, gui_grid,
+ gui_dialogs, gui_checkbox, gui_tree, gui_trackbar,
+ gui_progressbar, gui_radiobutton, gui_tab, gui_menu,
+ gui_bevel, gui_popupcalendar, gui_gauge;
+
+type
+
+ TSplashForm = class(TfpgForm)
+ procedure SplashFormShow(Sender: TObject);
+ procedure TimerFired(Sender: TObject);
+ private
+ tmr: TfpgTimer;
+ protected
+ procedure HandleLMouseUp(x, y: integer; shiftstate: TShiftState); override;
+ public
+ {@VFD_HEAD_BEGIN: SplashForm}
+ pnlName1: TfpgBevel;
+ lblName2: TfpgLabel;
+ lblName1: TfpgLabel;
+ {@VFD_HEAD_END: SplashForm}
+ constructor Create(AOwner: TComponent); override;
+ procedure AfterCreate; override;
+ end;
+
+{@VFD_NEWFORM_DECL}
+
+var
+ frmSplash: TSplashForm;
+
+implementation
+
+{@VFD_NEWFORM_IMPL}
+
+procedure TSplashForm.SplashFormShow(Sender: TObject);
+begin
+ tmr.Enabled := True;
+end;
+
+procedure TSplashForm.TimerFired(Sender: TObject);
+begin
+ tmr.Enabled := False;
+ tmr.Free;
+// writeln('Timer fired');
+ Hide;
+end;
+
+procedure TSplashForm.HandleLMouseUp(x, y: integer; shiftstate: TShiftState);
+begin
+ inherited HandleLMouseUp(x, y, shiftstate);
+ TimerFired(nil);
+end;
+
+constructor TSplashForm.Create(AOwner: TComponent);
+begin
+ inherited Create(AOwner);
+ WindowType := wtPopup;
+
+ tmr := TfpgTimer.Create(3000);
+ tmr.OnTimer := @TimerFired;
+
+ OnShow := @SplashFormShow;
+end;
+
+procedure TSplashForm.AfterCreate;
+begin
+ {@VFD_BODY_BEGIN: SplashForm}
+ Name := 'SplashForm';
+ SetPosition(298, 261, 300, 64);
+ WindowTitle := 'SplashForm';
+ WindowPosition := wpScreenCenter;
+ Sizeable := False;
+
+ pnlName1 := TfpgBevel.Create(self);
+ with pnlName1 do
+ begin
+ Name := 'pnlName1';
+ SetPosition(0, 0, 300, 64);
+ end;
+
+ lblName2 := TfpgLabel.Create(pnlName1);
+ with lblName2 do
+ begin
+ Name := 'lblName2';
+ SetPosition(24, 8, 272, 31);
+ Text := 'Splash screen goes here!';
+ FontDesc := 'Arial-18';
+ end;
+
+ lblName1 := TfpgLabel.Create(pnlName1);
+ with lblName1 do
+ begin
+ Name := 'lblName1';
+ SetPosition(52, 42, 188, 15);
+ Text := 'Click me to make me disappear.';
+ FontDesc := '#Label1';
+ end;
+
+ {@VFD_BODY_END: SplashForm}
+end;
+
+
+end.
diff --git a/examples/gui/splashscreen/test.lpi b/examples/gui/splashscreen/test.lpi
new file mode 100644
index 00000000..2d4421c0
--- /dev/null
+++ b/examples/gui/splashscreen/test.lpi
@@ -0,0 +1,67 @@
+<?xml version="1.0"?>
+<CONFIG>
+ <ProjectOptions>
+ <PathDelim Value="/"/>
+ <Version Value="6"/>
+ <General>
+ <Flags>
+ <SaveOnlyProjectUnits Value="True"/>
+ </Flags>
+ <SessionStorage Value="InProjectDir"/>
+ <MainUnit Value="0"/>
+ <IconPath Value="./"/>
+ <TargetFileExt Value=""/>
+ </General>
+ <VersionInfo>
+ <ProjectVersion Value=""/>
+ </VersionInfo>
+ <PublishOptions>
+ <Version Value="2"/>
+ <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_package"/>
+ </Item1>
+ </RequiredPackages>
+ <Units Count="4">
+ <Unit0>
+ <Filename Value="test.lpr"/>
+ <IsPartOfProject Value="True"/>
+ <UnitName Value="test"/>
+ </Unit0>
+ <Unit1>
+ <Filename Value="frm_main.pas"/>
+ <IsPartOfProject Value="True"/>
+ <UnitName Value="frm_main"/>
+ </Unit1>
+ <Unit2>
+ <Filename Value="commands.pas"/>
+ <IsPartOfProject Value="True"/>
+ <UnitName Value="commands"/>
+ </Unit2>
+ <Unit3>
+ <Filename Value="frm_splashscreen.pas"/>
+ <IsPartOfProject Value="True"/>
+ <UnitName Value="frm_splashscreen"/>
+ </Unit3>
+ </Units>
+ </ProjectOptions>
+ <CompilerOptions>
+ <Version Value="5"/>
+ <CodeGeneration>
+ <Generate Value="Faster"/>
+ </CodeGeneration>
+ <Other>
+ <CustomOptions Value="-FUunits"/>
+ <CompilerPath Value="$(CompPath)"/>
+ </Other>
+ </CompilerOptions>
+</CONFIG>
diff --git a/examples/gui/splashscreen/test.lpr b/examples/gui/splashscreen/test.lpr
new file mode 100644
index 00000000..008d602b
--- /dev/null
+++ b/examples/gui/splashscreen/test.lpr
@@ -0,0 +1,41 @@
+program test;
+
+{$mode objfpc}{$H+}
+
+uses
+ {$IFDEF UNIX}{$IFDEF UseCThreads}
+ cthreads,
+ {$ENDIF}{$ENDIF}
+ Classes, fpgfx, gui_form, frm_main, commands, frm_splashscreen;
+
+
+procedure MainProc;
+var
+ frm: TMainForm;
+begin
+ fpgApplication.Initialize;
+ Randomize;
+ frm := TMainForm.Create(nil);
+
+ // This is needed otherwise Splashscreen becomes main form. Rules are, the
+ // first form displayed is the main form.
+ fpgApplication.MainForm := frm;
+
+ // Now create and show the splashscreen before the main form.
+ frmSplash := TSplashForm.Create(nil);
+ frmSplash.Show;
+
+ try
+ frm.Show;
+ fpgApplication.Run;
+ finally
+ frm.Free;
+ end;
+end;
+
+begin
+ MainProc;
+end.
+
+
+
diff --git a/src/corelib/gfxbase.pas b/src/corelib/gfxbase.pas
index 32cbe8f9..97438276 100644
--- a/src/corelib/gfxbase.pas
+++ b/src/corelib/gfxbase.pas
@@ -382,7 +382,7 @@ type
FModalFormStack: TList;
function DoGetFontFaceList: TStringList; virtual; abstract;
public
- constructor Create(const AParams: string); virtual; abstract;
+ constructor Create(const AParams: string); virtual; abstract; reintroduce;
function GetFontFaceList: TStringList;
procedure PushModalForm(AForm: TfpgWindowBase);
procedure PopModalForm;