diff options
Diffstat (limited to 'extras')
-rw-r--r-- | extras/tiopf/demos/Common/Model.pas | 8 | ||||
-rw-r--r-- | extras/tiopf/demos/Common/Model_View.pas | 168 | ||||
-rw-r--r-- | extras/tiopf/demos/EditControlsDemo/editmediators.lpi | 8 | ||||
-rw-r--r-- | extras/tiopf/demos/EditControlsDemo/frmMain.pas | 75 | ||||
-rw-r--r-- | extras/tiopf/gui/tiMediators.pas | 70 |
5 files changed, 66 insertions, 263 deletions
diff --git a/extras/tiopf/demos/Common/Model.pas b/extras/tiopf/demos/Common/Model.pas index 9d5dea39..7c60f58e 100644 --- a/extras/tiopf/demos/Common/Model.pas +++ b/extras/tiopf/demos/Common/Model.pas @@ -170,21 +170,21 @@ procedure TPerson.DoGetFieldBounds(const AFieldName: String; var MinValue, begin if AFieldName = 'Name' then begin - writeln(' Name - DoGetFieldBounds'); +// writeln(' Name - DoGetFieldBounds'); HasBounds := True; MinValue := 1; MaxValue := 25; end else if AFieldName = 'Age' then begin - writeln(' Age - DoGetFieldBounds'); +// writeln(' Age - DoGetFieldBounds'); HasBounds := True; MinValue := 1; - MaxValue := 95; + MaxValue := 100; end else begin - writeln(' unknown property <', AFieldName, '> - DoGetFieldBounds'); +// writeln(' unknown property <', AFieldName, '> - DoGetFieldBounds'); inherited DoGetFieldBounds(AFieldName, MinValue, MaxValue, HasBounds); end; end; diff --git a/extras/tiopf/demos/Common/Model_View.pas b/extras/tiopf/demos/Common/Model_View.pas index d50762fd..ad027534 100644 --- a/extras/tiopf/demos/Common/Model_View.pas +++ b/extras/tiopf/demos/Common/Model_View.pas @@ -7,109 +7,31 @@ unit Model_View; interface uses - Classes, tiMediators -// , tiListMediators -// ,tiGenericEditMediators -// ,tiGenericListMediators + Classes + ,tiMediators ; type - { TfpgEdit - Name } - TPerson_Name_TextEdit_View = class(TMediatorEditView) - private - procedure OnTextChanged(Sender: TObject); - protected - procedure SetupGUIandObject; override; - end; - - { TfpgEdit - Age } - TPerson_Age_TextEdit_View = class(TMediatorEditView) - private - procedure OnTextChanged(Sender: TObject); - protected - procedure SetupGUIandObject; override; - procedure DoGuiToObject; override; - procedure DoObjectToGui; override; - end; - - - { TSpinEdit - Age } -{ - TPerson_Age_SpinEdit_View = class(TMediatorSpinEditView) - protected - procedure SetupGUIandObject; override; - end; -} - - { TTrackBar - Age } - TPerson_Age_TrackBar_Mediator = class(TMediatorTrackBarView) - protected - procedure SetupGUIandObject; override; - end; - - { TMemo - Name } TPerson_Name_Memo_Mediator = class(TMediatorMemoView) protected procedure SetupGUIandObject; override; end; - - { TCombobox - Gender } - TPerson_Gender_ComboBox_Mediator = class(TMediatorComboBoxView) - protected - procedure SetupGUIandObject; override; - end; - - - { TPersonList_ComboBox_Mediator } - - //TPersonList_ComboBox_Mediator = class(TComboBoxMediator) - //protected - //procedure SetupGUIandObject; override; - //end; - -(* - TPersonList_ListView_CompositeMediator = class(TCompositeListViewMediator) - protected - procedure SetupGUIandObject; override; - end; -*) implementation uses - Model, SysUtils, tiBaseMediator, TypInfo, tiObject; + Model, tiBaseMediator; procedure RegisterMediators; begin // Fallbacks (generic) - gMediatorManager.RegisterMediator(TMediatorEditView,TTiObject,[tkSstring,tkAstring,tkinteger,tkFloat]); - gMediatorManager.RegisterMediator(TMediatorCheckBoxView,TTiObject,[tkBool]); - gMediatorManager.RegisterMediator(TMediatorComboboxView,TTiObject,[tkSString,tkAString]); - gMediatorManager.RegisterMediator(TMediatorStaticTextView,TTiObject); - gMediatorManager.RegisterMediator(TMediatorTrackBarView,TTiObject,[tkInteger]); - gMediatorManager.RegisterMediator(TMediatorDynamicComboBoxView,TTiObject,[tkClass]); - gMediatorManager.RegisterMediator(TMediatorMemoView,TTiObject,[tksString,tkAString]); - // Specific -// gMediatorManager.RegisterMediator(TMediatorCalendarComboView,TLeerling,'DateOfBirth'); -// gMediatorManager.RegisterMediator(TMediatorComboboxView,TLeerling,'Gender'); -end; + RegisterFallBackMediators; -{ TPersonNameView } - -procedure TPerson_Name_TextEdit_View.OnTextChanged(Sender: TObject); -begin - GUIChanged; -end; - -procedure TPerson_Name_TextEdit_View.SetupGUIandObject; -begin - inherited; - { The Name field my only contain 25 characters max. } - EditControl.MaxLength := 25; - EditControl.OnChange := @OnTextChanged; + // Specific + gMediatorManager.RegisterMediator(TPerson_Name_Memo_Mediator, TPerson, 'Name'); end; @@ -118,83 +40,7 @@ end; procedure TPerson_Name_Memo_Mediator.SetupGUIandObject; begin inherited SetupGUIandObject; - { The Name field my only contain 25 characters max. } -// EditControl.ReadOnly := True; - EditControl.Enabled := False; -end; - - -{ TPerson_Gender_ComboBox_Mediator } - -procedure TPerson_Gender_ComboBox_Mediator.SetupGUIandObject; -begin - inherited SetupGUIandObject; -// EditControl.Style := csDropDownList; -// TComboBox(EditControl).ReadOnly := True; -end; - - -{ TPersonList_ComboBox_Mediator } - -//procedure TPersonList_ComboBox_Mediator.SetupGUIandObject; -//begin - //inherited SetupGUIandObject; -//// View.Style := csDropDownList; -//// View.ReadOnly := True; -//end; - - -{ TPersonList_ListView_CompositeMediator } -(* -procedure TPersonList_ListView_CompositeMediator.SetupGUIandObject; -begin - inherited SetupGUIandObject; -// View.OnCustomDrawItem := ListViewCustomDrawItem; -end; -*) - -{ TPerson_Age_SpinEdit_View } -{ -procedure TPerson_Age_SpinEdit_View.SetupGUIandObject; -begin - inherited SetupGUIandObject; - EditControl.MaxValue := 100; -end; -} -{ TPerson_Age_TrackBar_Mediator } - -procedure TPerson_Age_TrackBar_Mediator.SetupGUIandObject; -begin - inherited SetupGUIandObject; - EditControl.Max := 100; -end; - -{ TPerson_Age_TextEdit_View } - -procedure TPerson_Age_TextEdit_View.OnTextChanged(Sender: TObject); -begin - GUIChanged; -end; - -procedure TPerson_Age_TextEdit_View.SetupGUIandObject; -begin - inherited SetupGUIandObject; - EditControl.MaxLength := 3; - EditControl.OnChange := @OnTextChanged; -end; - -procedure TPerson_Age_TextEdit_View.DoGuiToObject; -begin - inherited DoGuiToObject; - // manual example without RTTI -// TPerson(Subject).Age := StrToInt(EditControl.Text); -end; - -procedure TPerson_Age_TextEdit_View.DoObjectToGui; -begin - inherited DoObjectToGui; - // manual example without RTTI -// EditControl.Text := IntToStr(TPerson(Subject).Age); + EditControl.Enabled := False; // fpGUI doesn't have a ReadOnly property yet end; diff --git a/extras/tiopf/demos/EditControlsDemo/editmediators.lpi b/extras/tiopf/demos/EditControlsDemo/editmediators.lpi index 55dc6b9c..4b63bdd7 100644 --- a/extras/tiopf/demos/EditControlsDemo/editmediators.lpi +++ b/extras/tiopf/demos/EditControlsDemo/editmediators.lpi @@ -27,15 +27,11 @@ <LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/> </local> </RunParams> - <RequiredPackages Count="2"> + <RequiredPackages Count="1"> <Item1> - <PackageName Value="fpgui_package"/> - <MinVersion Minor="5" Valid="True"/> - </Item1> - <Item2> <PackageName Value="tiOPFfpGUI"/> <MinVersion Major="2" Release="3" Valid="True"/> - </Item2> + </Item1> </RequiredPackages> <Units Count="5"> <Unit0> diff --git a/extras/tiopf/demos/EditControlsDemo/frmMain.pas b/extras/tiopf/demos/EditControlsDemo/frmMain.pas index d6e416de..7e85f4a2 100644 --- a/extras/tiopf/demos/EditControlsDemo/frmMain.pas +++ b/extras/tiopf/demos/EditControlsDemo/frmMain.pas @@ -17,7 +17,6 @@ type Label1: TfpgLabel; Label2: TfpgLabel; edtName: TfpgEdit; -// edtAge: TSpinEdit; AgeTrackBar: TfpgTrackBar; memMemo: TfpgMemo; cbGender: TfpgComboBox; @@ -27,23 +26,12 @@ type FPerson: TPerson; { Form Mediator } FMediator: TFormMediator; - { Edit mediators } -// FEditNameMediator: TMediatorEditView; -//// FSpinEditAgeMediator: TMediatorSpinEditView; -// FTrackBarAgeMediator: TMediatorTrackBarView; -// FMemoNameMediator: TMediatorMemoView; -// FComboBoxGenderMediator: TMediatorComboBoxView; procedure btnCloseClick(Sender: TObject); procedure btnShowModelClick(Sender: TObject); procedure btnViaCodeClick(Sender: TObject); - procedure edtNameChange(Sender: TObject); - procedure edtAgeChange(Sender: TObject); - procedure AgeTrackBarChange(Sender: TObject; APosition: integer); - procedure cbGenderChange(Sender: TObject); procedure InitializeComponents; procedure SetupMediators; - procedure SetupEventHandlers; public constructor Create(AOwner: TComponent); override; destructor Destroy; override; @@ -76,27 +64,6 @@ begin FPerson.Gender := genFemale; end; -procedure TMainForm.edtNameChange(Sender: TObject); -begin - //FEditNameMediator.GUIChanged; -end; - -procedure TMainForm.edtAgeChange(Sender: TObject); -begin -// FSpinEditAgeMediator.GUIChanged; -end; - -procedure TMainForm.AgeTrackBarChange(Sender: TObject; APosition: integer); -begin - //FTrackBarAgeMediator.GUIChanged; -end; - -procedure TMainForm.cbGenderChange(Sender: TObject); -begin - //writeln('cbGenderChange'); - //FComboBoxGenderMediator.GUIChanged; -end; - procedure TMainForm.InitializeComponents; begin Label1 := TfpgLabel.Create(self); @@ -177,17 +144,6 @@ begin TabOrder := 3; end; -{ - object edtAge: TSpinEdit - Left = 64 - Height = 22 - Top = 40 - Width = 100 - MaxValue = 0 - TabOrder = 4 - end -} - AgeTrackBar := TfpgTrackBar.Create(self); with AgeTrackBar do begin @@ -195,10 +151,7 @@ begin Height := 41; Top := 72; Width := 150; -// ScrollStep := 10; -// Frequency := 10; Max := 100; -// ScalePos := trTop; ShowPosition := True; TabOrder := 5; end; @@ -219,9 +172,6 @@ begin Left := 264; Height := 21; Top := 96; -// Width := 145; -// AutoCompleteText = [cbactEndOfLineComplete, cbactSearchAscending]; -// MaxLength := 0; TabOrder := 7; end; end; @@ -229,16 +179,12 @@ end; procedure TMainForm.SetupMediators; begin { - FEditNameMediator := TPerson_Name_TextEdit_View.CreateCustom(edtName, FPerson, 'Name', 'Text'); -// FSpinEditAgeMediator := TPerson_Age_SpinEdit_View.CreateCustom(edtAge, FPerson, 'Age', 'Value'); - FTrackBarAgeMediator := TPerson_Age_TrackBar_Mediator.CreateCustom(AgeTrackBar, FPerson, 'Age', 'Position'); - FMemoNameMediator := TPerson_Name_Memo_Mediator.CreateCustom(memMemo, FPerson, 'Name', ''); FComboBoxGenderMediator := TPerson_Gender_ComboBox_Mediator.CreateCustom(cbGender, FPerson, 'GenderGUI', 'Text'); } if not Assigned(FMediator) then begin FMediator := TFormMediator.Create(self); - FMediator.Name := 'DemoMediator'; + FMediator.Name := 'DemoFormMediator'; FMediator.AddProperty('Name', edtName); FMediator.AddProperty('Age', AgeTrackBar); FMediator.AddProperty('Name', memMemo); @@ -248,15 +194,6 @@ begin FMediator.Active := True; end; -procedure TMainForm.SetupEventHandlers; -begin - { Setup generic OnChange event for all GUI controls. } - edtName.OnChange := @edtNameChange; -// edtAge.OnChange := @edtAgeChange; - AgeTrackBar.OnChange := @AgeTrackBarChange; - cbGender.OnChange := @cbGenderChange; -end; - constructor TMainForm.Create(AOwner: TComponent); var i: TGender; @@ -279,13 +216,7 @@ end; destructor TMainForm.Destroy; begin - { free mediators - they will detach themselves } -// FEditNameMediator.Free; -//// FSpinEditAgeMediator.Free; -// FTrackBarAgeMediator.Free; -// FMemoNameMediator.Free; -// FComboBoxGenderMediator.Free; - + // TFormMediator (FMediator) get free'd automatically because it's a TComponent FPerson.Free; inherited Destroy; end; @@ -296,7 +227,7 @@ begin { The only trick here is to not let the OnChange events fire before the mediators are not set up!! } SetupMediators; - SetupEventHandlers; + // This will cause all components to update at once FPerson.NotifyObservers; end; diff --git a/extras/tiopf/gui/tiMediators.pas b/extras/tiopf/gui/tiMediators.pas index 5c7ccb3a..6881b58c 100644 --- a/extras/tiopf/gui/tiMediators.pas +++ b/extras/tiopf/gui/tiMediators.pas @@ -97,6 +97,7 @@ type end; } + { Base class to handle TfpgTrackBar controls } TMediatorTrackBarView = class(TMediatorView) private @@ -118,22 +119,25 @@ type private FEditControl: TfpgComboBox; function GetGUIControl: TComponent; override; - procedure SetGUIControl(const AValue: TComponent);override; + procedure SetGUIControl(const AValue: TComponent); override; protected + procedure SetupGUIandObject; override; procedure UpdateGuiValidStatus(pErrors: TtiObjectErrors); override; procedure DoObjectToGui; override; public - Constructor Create; override; + constructor Create; override; property EditControl: TfpgComboBox read FEditControl write FEditControl; class function ComponentClass: TClass; override; end; - // Sets ItemIndex based on integer property + { Sets ItemIndex based on integer property } TMediatorItemComboBoxView = class(TMediatorComboBoxView) - Protected - Procedure DoGUIToObject; override; - Procedure DoObjectToGUI; override; + protected + Procedure DoGUIToObject; override; + Procedure DoObjectToGUI; override; + public + constructor Create; override; end; @@ -182,6 +186,10 @@ type end; +// Registering generic mediators which can handle most cases by default. +procedure RegisterFallBackMediators; + + implementation uses SysUtils @@ -196,16 +204,27 @@ const cErrorListHasNotBeenAssigned = 'List has not been assigned'; +procedure RegisterFallBackMediators; +begin + gMediatorManager.RegisterMediator(TMediatorEditView, TtiObject, [tkSstring,tkAstring,tkinteger,tkFloat]); + gMediatorManager.RegisterMediator(TMediatorCheckBoxView, TtiObject, [tkBool]); + gMediatorManager.RegisterMediator(TMediatorComboboxView, TtiObject, [tkSString,tkAString]); + gMediatorManager.RegisterMediator(TMediatorStaticTextView, TtiObject); + gMediatorManager.RegisterMediator(TMediatorTrackBarView, TtiObject, [tkInteger]); + gMediatorManager.RegisterMediator(TMediatorDynamicComboBoxView, TtiObject, [tkClass]); + gMediatorManager.RegisterMediator(TMediatorMemoView, TtiObject, [tksString,tkAString]); +end; + { TMediatorEditView } function TMediatorEditView.GetGUIControl: TComponent; begin - Result:=FeditControl; + Result := FEditControl; end; procedure TMediatorEditView.SetGUIControl(const AValue: TComponent); begin - FEditControl:=AValue as TfpgEdit; + FEditControl := AValue as TfpgEdit; Inherited; end; @@ -347,18 +366,17 @@ end; function TMediatorTrackBarView.GetGUIControl: TComponent; begin - Result:=FEditControl; + Result := FEditControl; end; procedure TMediatorTrackBarView.SetGUIControl(const AValue: TComponent); begin - FEditControl:=AValue as TfpgTrackBar; - Inherited; + FEditControl := AValue as TfpgTrackBar; + inherited; end; procedure TMediatorTrackBarView.DoTrackBarChanged(Sender: TObject; APosition: integer); begin -// writeln(' executing - DoTrackBarChanged'); GUIChanged; end; @@ -373,12 +391,9 @@ begin FEditControl.Max := Ma; end; if ObjectUpdateMoment in [ouOnChange,ouCustom] then - begin -// writeln(' Trackbar: setting OnChange event handler'); - FEditControl.OnChange := @DoTrackBarChanged; - end; -// else -// FeditControl.OnExit := @DoOnChange; + FEditControl.OnChange := @DoTrackBarChanged + else + FeditControl.OnExit := @DoOnChange; end; constructor TMediatorTrackBarView.Create; @@ -411,6 +426,15 @@ begin inherited; end; +procedure TMediatorComboBoxView.SetupGUIandObject; +begin + inherited SetupGUIandObject; + if ObjectUpdateMoment in [ouOnChange,ouCustom] then + FEditControl.OnChange := @DoOnChange + else + FEditControl.OnExit := @DoOnChange; +end; + procedure TMediatorComboBoxView.UpdateGuiValidStatus(pErrors: TtiObjectErrors); var oError: TtiObjectError; @@ -433,7 +457,7 @@ end; constructor TMediatorComboBoxView.Create; begin inherited Create; - GuiFieldName:='FocusItem'; + GuiFieldName := 'Text'; //'FocusItem'; end; procedure TMediatorComboBoxView.DoObjectToGui; @@ -710,7 +734,13 @@ end; procedure TMediatorItemComboBoxView.DoObjectToGUI; begin - EditCOntrol.FocusItem:=GetOrdProp(Subject,FieldName); + EditCOntrol.FocusItem := GetOrdProp(Subject,FieldName); +end; + +constructor TMediatorItemComboBoxView.Create; +begin + inherited Create; + GuiFieldName := 'FocusItem'; end; end. |