diff options
author | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2009-02-13 10:11:31 +0000 |
---|---|---|
committer | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2009-02-13 10:11:31 +0000 |
commit | ecb24afe63133584d82974477923fe7c7e75032f (patch) | |
tree | d4a52923cf66b4792f17135b410010b6ac9b3e6a /extras/tiopf/gui | |
parent | d422a9e0c1a88d83c1d9883f846da6167e06c9b2 (diff) | |
download | fpGUI-ecb24afe63133584d82974477923fe7c7e75032f.tar.xz |
* new mediators for 3 numeric edit components. Thanks to Clemens for the patch.
Diffstat (limited to 'extras/tiopf/gui')
-rw-r--r-- | extras/tiopf/gui/tiMediators.pas | 277 |
1 files changed, 268 insertions, 9 deletions
diff --git a/extras/tiopf/gui/tiMediators.pas b/extras/tiopf/gui/tiMediators.pas index 6cfb87ff..79b637ad 100644 --- a/extras/tiopf/gui/tiMediators.pas +++ b/extras/tiopf/gui/tiMediators.pas @@ -40,13 +40,66 @@ type procedure SetObjectUpdateMoment (Const AValue : TObjectUpdateMoment); override; public constructor Create; override; - constructor CreateCustom(pEditControl: TfpgWidget; pSubject: TtiObject; pFieldName: string; pGuiFieldName: string = 'Text'); reintroduce; destructor Destroy; override; property EditControl: TfpgEdit read FEditControl write FEditControl; class function ComponentClass: TClass; override; end; + { TMediatorEditIntegerView } + TMediatorEditIntegerView = class(TMediatorView) + private + FEditControl: TfpgEditInteger; + protected + function GetGUIControl: TComponent; override; + procedure SetGUIControl(const AValue: TComponent); override; + procedure UpdateGuiValidStatus(pErrors: TtiObjectErrors); override; + procedure SetupGUIandObject; override; + procedure SetObjectUpdateMoment (Const AValue : TObjectUpdateMoment); override; + public + constructor Create; override; + destructor Destroy; override; + property EditControl: TfpgEditInteger read FEditControl write FEditControl; + class function ComponentClass: TClass; override; + end; + + + { TMediatorEditFloatView } + TMediatorEditFloatView = class(TMediatorView) + private + FEditControl: TfpgEditFloat; + protected + function GetGUIControl: TComponent; override; + procedure SetGUIControl(const AValue: TComponent); override; + procedure UpdateGuiValidStatus(pErrors: TtiObjectErrors); override; + procedure SetupGUIandObject; override; + procedure SetObjectUpdateMoment (Const AValue : TObjectUpdateMoment); override; + public + constructor Create; override; + destructor Destroy; override; + property EditControl: TfpgEditFloat read FEditControl write FEditControl; + class function ComponentClass: TClass; override; + end; + + + { TMediatorEditCurrencyView } + TMediatorEditCurrencyView = class(TMediatorView) + private + FEditControl: TfpgEditCurrency; + protected + function GetGUIControl: TComponent; override; + procedure SetGUIControl(const AValue: TComponent); override; + procedure UpdateGuiValidStatus(pErrors: TtiObjectErrors); override; + procedure SetupGUIandObject; override; + procedure SetObjectUpdateMoment (Const AValue : TObjectUpdateMoment); override; + public + constructor Create; override; + destructor Destroy; override; + property EditControl: TfpgEditCurrency read FEditControl write FEditControl; + class function ComponentClass: TClass; override; + end; + + { Base class to handle TfpgCheckBox controls } TMediatorCheckBoxView = class(TMediatorView) private @@ -211,7 +264,6 @@ implementation uses SysUtils ,TypInfo - ,tiExcept ,fpg_dialogs // for TfpgMessageDialog ,fpg_base // for predefined colors ,tiGUIConstants // for error color @@ -227,6 +279,9 @@ const procedure RegisterFallBackMediators; begin gMediatorManager.RegisterMediator(TMediatorEditView, TtiObject, [tkSString,tkAString,tkInteger,tkFloat]); + gMediatorManager.RegisterMediator(TMediatorEditIntegerView, TtiObject, [tkInteger]); + gMediatorManager.RegisterMediator(TMediatorEditFloatView, TtiObject, [tkFloat]); + gMediatorManager.RegisterMediator(TMediatorEditCurrencyView, TtiObject, [tkFloat]); gMediatorManager.RegisterMediator(TMediatorCheckBoxView, TtiObject, [tkBool]); gMediatorManager.RegisterMediator(TMediatorComboboxView, TtiObject, [tkSString,tkAString]); gMediatorManager.RegisterMediator(TMediatorItemComboBoxView, TtiObject, [tkInteger, tkEnumeration]); @@ -297,13 +352,7 @@ end; constructor TMediatorEditView.Create; begin inherited Create; - GuiFieldName:='Text'; -end; - -constructor TMediatorEditView.CreateCustom(pEditControl: TfpgWidget; - pSubject: TtiObject; pFieldName: string; pGuiFieldName: string); -begin - inherited; + GuiFieldName := 'Text'; end; destructor TMediatorEditView.Destroy; @@ -837,5 +886,215 @@ begin Result := TfpgSpinEditFloat; end; +{ TMediatorEditIntegerView } + +function TMediatorEditIntegerView.GetGUIControl: TComponent; +begin + Result:= FEditControl; +end; + +procedure TMediatorEditIntegerView.SetGUIControl(const AValue: TComponent); +begin + FEditControl := AValue as TfpgEditInteger; + //inherited SetGUIControl(AValue); +end; + +procedure TMediatorEditIntegerView.UpdateGuiValidStatus(pErrors: TtiObjectErrors); +var + oError: TtiObjectError; +begin + inherited UpdateGuiValidStatus(pErrors); + + oError := pErrors.FindByErrorProperty(FieldName); + if oError <> nil then + begin + EditControl.BackgroundColor := clError; + EditControl.Hint := oError.ErrorMessage; + end + else + begin + EditControl.BackgroundColor := clBoxColor; + EditControl.Hint := ''; + end; +end; + +procedure TMediatorEditIntegerView.SetupGUIandObject; +begin + inherited; + if ObjectUpdateMoment in [ouOnChange,ouCustom] then + FEditControl.OnChange := @DoOnChange + else + FEditControl.OnExit := @DoOnChange; +end; + +procedure TMediatorEditIntegerView.SetObjectUpdateMoment( + const AValue: TObjectUpdateMoment); +begin + inherited SetObjectUpdateMoment(AValue); + if Assigned(FEditControl) then + If ObjectUpdateMoment in [ouOnchange,ouCustom] then + FEditControl.OnChange := @DoOnChange + else + FEditControl.OnExit := @DoOnChange; +end; + +constructor TMediatorEditIntegerView.Create; +begin + inherited Create; + GUIFieldName := 'Value'; +end; + +destructor TMediatorEditIntegerView.Destroy; +begin + if Assigned(EditControl) and Assigned(EditControl.OnChange) then + EditControl.OnChange := nil; + inherited Destroy; +end; + +class function TMediatorEditIntegerView.ComponentClass: TClass; +begin + Result := TfpgEditInteger; +end; + + +{ TMediatorEditFloatView } +function TMediatorEditFloatView.GetGUIControl: TComponent; +begin + Result:= FEditControl; +end; + +procedure TMediatorEditFloatView.SetGUIControl(const AValue: TComponent); +begin + FEditControl := AValue as TfpgEditFloat; + //inherited SetGUIControl(AValue); +end; + +procedure TMediatorEditFloatView.UpdateGuiValidStatus(pErrors: TtiObjectErrors); +var + oError: TtiObjectError; +begin + inherited UpdateGuiValidStatus(pErrors); + + oError := pErrors.FindByErrorProperty(FieldName); + if oError <> nil then + begin + EditControl.BackgroundColor := clError; + EditControl.Hint := oError.ErrorMessage; + end + else + begin + EditControl.BackgroundColor := clBoxColor; + EditControl.Hint := ''; + end; +end; + +procedure TMediatorEditFloatView.SetupGUIandObject; +begin + inherited; + if ObjectUpdateMoment in [ouOnChange,ouCustom] then + FEditControl.OnChange := @DoOnChange + else + FEditControl.OnExit := @DoOnChange; +end; + +procedure TMediatorEditFloatView.SetObjectUpdateMoment( + const AValue: TObjectUpdateMoment); +begin + inherited SetObjectUpdateMoment(AValue); + if Assigned(FEditControl) then + If ObjectUpdateMoment in [ouOnchange,ouCustom] then + FEditControl.OnChange := @DoOnChange + else + FEditControl.OnExit := @DoOnChange; +end; + +constructor TMediatorEditFloatView.Create; +begin + inherited Create; + GUIFieldName := 'Value'; +end; + +destructor TMediatorEditFloatView.Destroy; +begin + if Assigned(EditControl) and Assigned(EditControl.OnChange) then + EditControl.OnChange := nil; + inherited Destroy; +end; + +class function TMediatorEditFloatView.ComponentClass: TClass; +begin + Result := TfpgEditFloat; +end; + +{ TMediatorEditCurrencyView } + +function TMediatorEditCurrencyView.GetGUIControl: TComponent; +begin + Result:= FEditControl; +end; + +procedure TMediatorEditCurrencyView.SetGUIControl(const AValue: TComponent); +begin + FEditControl := AValue as TfpgEditCurrency; + //inherited SetGUIControl(AValue); +end; + +procedure TMediatorEditCurrencyView.UpdateGuiValidStatus(pErrors: TtiObjectErrors); +var + oError: TtiObjectError; +begin + inherited UpdateGuiValidStatus(pErrors); + + oError := pErrors.FindByErrorProperty(FieldName); + if oError <> nil then + begin + EditControl.BackgroundColor := clError; + EditControl.Hint := oError.ErrorMessage; + end + else + begin + EditControl.BackgroundColor := clBoxColor; + EditControl.Hint := ''; + end; +end; + +procedure TMediatorEditCurrencyView.SetupGUIandObject; +begin + inherited; + if ObjectUpdateMoment in [ouOnChange,ouCustom] then + FEditControl.OnChange := @DoOnChange + else + FEditControl.OnExit := @DoOnChange; +end; + +procedure TMediatorEditCurrencyView.SetObjectUpdateMoment( + const AValue: TObjectUpdateMoment); +begin + inherited SetObjectUpdateMoment(AValue); + if Assigned(FEditControl) then + If ObjectUpdateMoment in [ouOnchange,ouCustom] then + FEditControl.OnChange := @DoOnChange + else + FEditControl.OnExit := @DoOnChange; +end; + +constructor TMediatorEditCurrencyView.Create; +begin + inherited Create; + GUIFieldName := 'Value'; +end; + +destructor TMediatorEditCurrencyView.Destroy; +begin + if Assigned(EditControl) and Assigned(EditControl.OnChange) then + EditControl.OnChange := nil; + inherited Destroy; +end; + +class function TMediatorEditCurrencyView.ComponentClass: TClass; +begin + Result := TfpgEditCurrency; +end; + end. |