summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--extras/tiopf/demos/Common/Model.pas21
-rw-r--r--extras/tiopf/demos/Demo_20_ListMediators/demo_listmediators.lpi85
-rw-r--r--extras/tiopf/demos/Demo_20_ListMediators/demo_listmediators.lpr29
-rw-r--r--extras/tiopf/demos/Demo_20_ListMediators/frmMain.pas235
-rw-r--r--extras/tiopf/demos/EditControlsDemo/editmediators.lpi5
5 files changed, 359 insertions, 16 deletions
diff --git a/extras/tiopf/demos/Common/Model.pas b/extras/tiopf/demos/Common/Model.pas
index 7c60f58e..8fe815cb 100644
--- a/extras/tiopf/demos/Common/Model.pas
+++ b/extras/tiopf/demos/Common/Model.pas
@@ -81,33 +81,30 @@ uses
function GeneratePersonList: TPersonList;
var
- lList: TPersonList;
lData: TPerson;
begin
- lList := TPersonList.Create;
+ Result := TPersonList.Create;
lData := TPerson.Create;
lData.Name := 'Graeme Geldenhuys';
lData.Age := 23;
- lList.Add(lData);
+ Result.Add(lData);
lData := TPerson.Create;
lData.Name := 'Peter Hinrichsen';
lData.Age := 34;
- lList.Add(lData);
+ Result.Add(lData);
- lData := TPerson.Create;
- lData.Name := 'Ian Krigsman';
- lData.Age := 45;
- lData.Deleted := True;
- lList.Add(lData);
+ //lData := TPerson.Create;
+ //lData.Name := 'Ian Krigsman';
+ //lData.Age := 45;
+ //lData.Deleted := True;
+ //Result.Add(lData);
lData := TPerson.Create;
lData.Name := 'John Guthrie';
lData.Age := 56;
- lList.Add(lData);
-
- Result := lList;
+ Result.Add(lData);
end;
diff --git a/extras/tiopf/demos/Demo_20_ListMediators/demo_listmediators.lpi b/extras/tiopf/demos/Demo_20_ListMediators/demo_listmediators.lpi
new file mode 100644
index 00000000..5cfa02ee
--- /dev/null
+++ b/extras/tiopf/demos/Demo_20_ListMediators/demo_listmediators.lpi
@@ -0,0 +1,85 @@
+<?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"/>
+ <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="tiOPFfpGUI"/>
+ </Item1>
+ </RequiredPackages>
+ <Units Count="5">
+ <Unit0>
+ <Filename Value="demo_listmediators.lpr"/>
+ <IsPartOfProject Value="True"/>
+ <UnitName Value="demo_listmediators"/>
+ </Unit0>
+ <Unit1>
+ <Filename Value="frmMain.pas"/>
+ <IsPartOfProject Value="True"/>
+ <UnitName Value="frmMain"/>
+ </Unit1>
+ <Unit2>
+ <Filename Value="../Common/Model.pas"/>
+ <IsPartOfProject Value="True"/>
+ <UnitName Value="Model"/>
+ </Unit2>
+ <Unit3>
+ <Filename Value="../Common/Model_View.pas"/>
+ <IsPartOfProject Value="True"/>
+ <UnitName Value="Model_View"/>
+ </Unit3>
+ <Unit4>
+ <Filename Value="../Common/Constants.pas"/>
+ <IsPartOfProject Value="True"/>
+ <UnitName Value="Constants"/>
+ </Unit4>
+ </Units>
+ </ProjectOptions>
+ <CompilerOptions>
+ <Version Value="8"/>
+ <SearchPaths>
+ <OtherUnitFiles Value="../Common/"/>
+ </SearchPaths>
+ <Parsing>
+ <SyntaxOptions>
+ <CStyleOperator Value="False"/>
+ </SyntaxOptions>
+ </Parsing>
+ <CodeGeneration>
+ <SmartLinkUnit Value="True"/>
+ </CodeGeneration>
+ <Linking>
+ <LinkSmart Value="True"/>
+ </Linking>
+ <Other>
+ <CustomOptions Value="-FUunits
+"/>
+ <CompilerPath Value="$(CompPath)"/>
+ </Other>
+ </CompilerOptions>
+</CONFIG>
diff --git a/extras/tiopf/demos/Demo_20_ListMediators/demo_listmediators.lpr b/extras/tiopf/demos/Demo_20_ListMediators/demo_listmediators.lpr
new file mode 100644
index 00000000..3b66ebde
--- /dev/null
+++ b/extras/tiopf/demos/Demo_20_ListMediators/demo_listmediators.lpr
@@ -0,0 +1,29 @@
+program demo_listmediators;
+
+{$mode objfpc}{$H+}
+
+uses
+ {$IFDEF UNIX}{$IFDEF UseCThreads}
+ cthreads,
+ {$ENDIF}{$ENDIF}
+ Classes, fpgfx, frmMain, Model, Constants, Model_View;
+
+
+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/extras/tiopf/demos/Demo_20_ListMediators/frmMain.pas b/extras/tiopf/demos/Demo_20_ListMediators/frmMain.pas
new file mode 100644
index 00000000..6a173d98
--- /dev/null
+++ b/extras/tiopf/demos/Demo_20_ListMediators/frmMain.pas
@@ -0,0 +1,235 @@
+unit frmMain;
+
+{$mode objfpc}{$H+}
+
+interface
+
+uses
+ SysUtils, Classes, gfxbase, fpgfx, gfx_widget, gui_form, gui_button,
+ gui_grid, gui_checkbox, gui_panel, gui_listview, Model, tiFormMediator;
+
+type
+
+ TMainForm = class(TfpgForm)
+ private
+ { The object we will be working with. }
+ FPersonList: TPersonList;
+ FMediator: TFormMediator;
+
+ procedure btnViaCodeChangeClick(Sender: TObject);
+ procedure btnQuitClicked(Sender: TObject);
+ procedure btnViaCodeAddClick(Sender: TObject);
+ procedure btnShowModelClick(Sender: TObject);
+ procedure SetupMediators;
+ public
+ {@VFD_HEAD_BEGIN: MainForm}
+ lvName1: TfpgListView;
+ grdName1: TfpgStringGrid;
+ pnlName1: TfpgPanel;
+ btnName1: TfpgButton;
+ btnName2: TfpgButton;
+ btnName3: TfpgButton;
+ btnName4: TfpgButton;
+ btnQuit: TfpgButton;
+ cbName1: TfpgCheckBox;
+ {@VFD_HEAD_END: MainForm}
+ constructor Create(AOwner: TComponent); override;
+ destructor Destroy; override;
+ procedure AfterConstruction; override;
+ procedure AfterCreate; override;
+ end;
+
+{@VFD_NEWFORM_DECL}
+
+implementation
+
+uses
+ tiBaseMediator, tiListMediators, tiObject, tiDialogs;
+
+{@VFD_NEWFORM_IMPL}
+
+procedure TMainForm.btnViaCodeChangeClick(Sender: TObject);
+begin
+ { The BeginUpdate/EndUpdate will let the Item notify its observers
+ only once, even though two change where made.
+ Note:
+ This is for observers to the Item, not the List that the Item belongs to! }
+ FPersonList.Items[1].BeginUpdate;
+ FPersonList.Items[1].Name := 'I have changed via code';
+ FPersonList.Items[1].Age := 99;
+ FPersonList.Items[1].EndUpdate;
+ { This notifies observers of the List, that something has changed. }
+ FPersonList.NotifyObservers;
+end;
+
+procedure TMainForm.btnQuitClicked(Sender: TObject);
+begin
+ Close;
+end;
+
+procedure TMainForm.btnViaCodeAddClick(Sender: TObject);
+var
+ lData: TPerson;
+begin
+ lData := TPerson.Create;
+ lData.Name := 'I am new';
+ lData.Age := 44;
+ FPersonList.Add(lData);
+end;
+
+procedure TMainForm.btnShowModelClick(Sender: TObject);
+begin
+ tiShowString(FPersonList.AsDebugString);
+end;
+
+procedure TMainForm.SetupMediators;
+begin
+ if not Assigned(FMediator) then
+ begin
+ FMediator := TFormMediator.Create(self);
+ FMediator.Name := 'DemoFormMediator';
+ FMediator.AddComposite('Name(150,"Name",<);Age(50,"Age",>);GenderGUI(80,"Gender",|)', grdName1);
+// FMediator.AddComposite('Name(150,"Name",<);Age(75,"Age",>);GenderGUI(50,"Gender",|)', lvName1);
+ end;
+ FMediator.Subject := FPersonList;
+ FMediator.Active := True;
+end;
+
+constructor TMainForm.Create(AOwner: TComponent);
+begin
+ inherited Create(AOwner);
+ FPersonList := GeneratePersonList;
+end;
+
+destructor TMainForm.Destroy;
+begin
+ FMediator.Active := False;
+ FPersonList.Free;
+ inherited Destroy;
+end;
+
+procedure TMainForm.AfterConstruction;
+begin
+ inherited AfterConstruction;
+ SetupMediators;
+ FPersonList.NotifyObservers;
+end;
+
+procedure TMainForm.AfterCreate;
+begin
+ {@VFD_BODY_BEGIN: MainForm}
+ Name := 'MainForm';
+ SetPosition(298, 184, 617, 358);
+ WindowTitle := 'Demo 20: ListMediators';
+ Sizeable := False;
+
+ lvName1 := TfpgListView.Create(self);
+ with lvName1 do
+ begin
+ Name := 'lvName1';
+ SetPosition(8, 52, 292, 220);
+ ShowHeaders := True;
+ end;
+
+ grdName1 := TfpgStringGrid.Create(self);
+ with grdName1 do
+ begin
+ Name := 'grdName1';
+ SetPosition(316, 52, 292, 220);
+ FontDesc := '#Grid';
+ HeaderFontDesc := '#GridHeader';
+ TabOrder := 1;
+ end;
+
+ pnlName1 := TfpgPanel.Create(self);
+ with pnlName1 do
+ begin
+ Name := 'pnlName1';
+ SetPosition(8, 12, 600, 28);
+ Anchors := [anLeft,anRight,anTop];
+ Alignment := taLeftJustify;
+ Margin := 8;
+ Text := 'ListMediator Demo';
+ FontDesc := '#Label2';
+ TextColor := clWhite;
+ BackGroundColor := clDarkBlue;
+ end;
+
+ btnName1 := TfpgButton.Create(self);
+ with btnName1 do
+ begin
+ Name := 'btnName1';
+ SetPosition(8, 296, 120, 24);
+ Text := 'Add via Code';
+ FontDesc := '#Label1';
+ ImageName := '';
+ TabOrder := 3;
+ OnClick := @btnViaCodeAddClick;
+ end;
+
+ btnName2 := TfpgButton.Create(self);
+ with btnName2 do
+ begin
+ Name := 'btnName2';
+ SetPosition(8, 324, 120, 24);
+ Text := 'Change via Code';
+ FontDesc := '#Label1';
+ ImageName := '';
+ TabOrder := 4;
+ OnClick := @btnViaCodeChangeClick;
+ end;
+
+ btnName3 := TfpgButton.Create(self);
+ with btnName3 do
+ begin
+ Name := 'btnName3';
+ SetPosition(132, 324, 96, 24);
+ Text := 'Show Model';
+ FontDesc := '#Label1';
+ ImageName := '';
+ TabOrder := 5;
+ OnClick := @btnShowModelClick;
+ end;
+
+ btnName4 := TfpgButton.Create(self);
+ with btnName4 do
+ begin
+ Name := 'btnName4';
+ SetPosition(232, 324, 80, 24);
+ Text := 'Delete';
+ FontDesc := '#Label1';
+ ImageName := '';
+ TabOrder := 6;
+ end;
+
+ btnQuit := TfpgButton.Create(self);
+ with btnQuit do
+ begin
+ Name := 'btnQuit';
+ SetPosition(528, 324, 80, 24);
+ Text := 'Quit';
+ FontDesc := '#Label1';
+ ImageName := '';
+ TabOrder := 7;
+ OnClick := @btnQuitClicked;
+ end;
+
+ cbName1 := TfpgCheckBox.Create(self);
+ with cbName1 do
+ begin
+ Name := 'cbName1';
+ SetPosition(148, 296, 120, 20);
+ FontDesc := '#Label1';
+ TabOrder := 8;
+ Text := 'Show Deleted';
+ end;
+
+ {@VFD_BODY_END: MainForm}
+end;
+
+
+initialization
+ gMediatorManager.RegisterMediator(TStringGridMediator, TtiObjectList);
+// gMediatorManager.RegisterMediator(TListViewMediator, TtiObjectList);
+
+end.
diff --git a/extras/tiopf/demos/EditControlsDemo/editmediators.lpi b/extras/tiopf/demos/EditControlsDemo/editmediators.lpi
index 4b63bdd7..bceed7e6 100644
--- a/extras/tiopf/demos/EditControlsDemo/editmediators.lpi
+++ b/extras/tiopf/demos/EditControlsDemo/editmediators.lpi
@@ -62,13 +62,10 @@
</Units>
</ProjectOptions>
<CompilerOptions>
- <Version Value="5"/>
+ <Version Value="8"/>
<SearchPaths>
<OtherUnitFiles Value="../Common/"/>
</SearchPaths>
- <CodeGeneration>
- <Generate Value="Faster"/>
- </CodeGeneration>
<Other>
<CustomOptions Value="-FUunits
"/>