diff options
author | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2008-04-11 12:56:25 +0000 |
---|---|---|
committer | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2008-04-11 12:56:25 +0000 |
commit | 2bcdcddcfd88233bceb4838ee8c58ee991003cea (patch) | |
tree | 02e6336c6b8bceef30af50e00871cfa34eadd0ce | |
parent | 95b760d80613d0873a9ed92e4bf29f1ef9b27564 (diff) | |
download | fpGUI-2bcdcddcfd88233bceb4838ee8c58ee991003cea.tar.xz |
* Implemented OnClose event for TfpgPopupWindow
* Implemented OnDropDown and OnCloseUp for any combobox type component.
* TfpgCombobox.FocusItem can now be set via code without the OnChange event firing (default). This behaviour can be modified with the TfpgComboBox.Options property.
-rw-r--r-- | src/corelib/gfx_popupwindow.pas | 10 | ||||
-rw-r--r-- | src/gui/gui_combobox.pas | 45 | ||||
-rw-r--r-- | src/gui/gui_editcombo.pas | 7 | ||||
-rw-r--r-- | src/gui/gui_popupcalendar.pas | 11 |
4 files changed, 62 insertions, 11 deletions
diff --git a/src/corelib/gfx_popupwindow.pas b/src/corelib/gfx_popupwindow.pas index 33921bc9..2b5f6130 100644 --- a/src/corelib/gfx_popupwindow.pas +++ b/src/corelib/gfx_popupwindow.pas @@ -37,6 +37,7 @@ type TfpgPopupWindow = class(TfpgWidget) private FDontCloseWidget: TfpgWidget; + FOnClose: TNotifyEvent; FPopupFrame: boolean; procedure SetPopupFrame(const AValue: boolean); protected @@ -45,12 +46,14 @@ type procedure HandleClose; virtual; procedure ProcessPopupFrame; virtual; procedure DoPaintPopupFrame; virtual; + procedure DoOnClose; virtual; public constructor Create(AOwner: TComponent); override; procedure ShowAt(AWidget: TfpgWidget; x, y: TfpgCoord); procedure Close; virtual; property DontCloseWidget: TfpgWidget read FDontCloseWidget write FDontCloseWidget; property PopupFrame: boolean read FPopupFrame write SetPopupFrame; + property OnClose: TNotifyEvent read FOnClose write FOnClose; end; @@ -223,6 +226,7 @@ end; procedure TfpgPopupWindow.HandleClose; begin + DoOnClose; HandleHide; end; @@ -266,6 +270,12 @@ begin Canvas.SetColor(lColor); end; +procedure TfpgPopupWindow.DoOnClose; +begin + if Assigned(OnClose) then + OnClose(self); +end; + constructor TfpgPopupWindow.Create(AOwner: TComponent); begin inherited Create(AOwner); diff --git a/src/gui/gui_combobox.pas b/src/gui/gui_combobox.pas index 105f162e..044582b3 100644 --- a/src/gui/gui_combobox.pas +++ b/src/gui/gui_combobox.pas @@ -56,6 +56,9 @@ uses gfx_popupwindow; type + // widget options + TfpgComboOption = (wo_FocusItemTriggersOnChange); + TfpgComboOptions = set of TfpgComboOption; { TfpgBaseComboBox } @@ -64,6 +67,9 @@ type FDropDownCount: integer; FFont: TfpgFont; FOnChange: TNotifyEvent; + FOnCloseUp: TNotifyEvent; + FOnDropDown: TNotifyEvent; + FOptions: TfpgComboOptions; function GetFontDesc: string; procedure SetDropDownCount(const AValue: integer); procedure SetFocusItem(const AValue: integer); @@ -72,15 +78,20 @@ type FInternalBtnRect: TfpgRect; FFocusItem: integer; FItems: TStringList; + procedure InternalOnClose(Sender: TObject); procedure HandleKeyPress(var keycode: word; var shiftstate: TShiftState; var consumed: boolean); override; - procedure DoOnChange; + procedure DoOnChange; virtual; procedure DoDropDown; virtual; abstract; + procedure DoOnCloseUp; virtual; function GetDropDownPos(AParent, AComboBox, ADropDown: TfpgWidget): TfpgRect; virtual; property DropDownCount: integer read FDropDownCount write SetDropDownCount default 8; property FocusItem: integer read FFocusItem write SetFocusItem; property FontDesc: string read GetFontDesc write SetFontDesc; property Items: TStringList read FItems; {$Note Make this read/write } + property Options: TfpgComboOptions read FOptions write FOptions; property OnChange: TNotifyEvent read FOnChange write FOnChange; + property OnCloseUp: TNotifyEvent read FOnCloseUp write FOnCloseUp; + property OnDropDown: TNotifyEvent read FOnDropDown write FOnDropDown; public constructor Create(AOwner: TComponent); override; destructor Destroy; override; @@ -93,7 +104,6 @@ type TfpgAbstractComboBox = class(TfpgBaseComboBox) private procedure InternalBtnClick(Sender: TObject); - procedure SetFocusItem(const AValue: integer); procedure CalculateInternalButtonRect; protected FMargin: integer; @@ -128,11 +138,14 @@ type property FontDesc; property Height; property Items; + property Options; property TabOrder; property Text; property TextColor; property Width; property OnChange; + property OnCloseUp; + property OnDropDown; end; @@ -196,7 +209,8 @@ begin FFocusItem := FItems.Count; RePaint; - DoOnChange; + if wo_FocusItemTriggersOnChange in FOptions then + DoOnChange; end; procedure TfpgBaseComboBox.SetFontDesc(const AValue: string); @@ -208,6 +222,11 @@ begin RePaint; end; +procedure TfpgBaseComboBox.InternalOnClose(Sender: TObject); +begin + DoOnCloseUp; +end; + procedure TfpgBaseComboBox.HandleKeyPress(var keycode: word; var shiftstate: TShiftState; var consumed: boolean); begin @@ -241,6 +260,12 @@ begin FOnChange(self); end; +procedure TfpgBaseComboBox.DoOnCloseUp; +begin + if Assigned(OnCloseUp) then + OnCloseUp(self); +end; + function TfpgBaseComboBox.GetDropDownPos(AParent, AComboBox, ADropDown: TfpgWidget): TfpgRect; var pt: TPoint; @@ -279,6 +304,7 @@ begin FFocusItem := 0; // nothing is selected FItems := TStringList.Create; FFont := fpgGetFont('#List'); + FOptions := []; FOnChange := nil; end; @@ -310,6 +336,8 @@ end; procedure TComboboxDropdownWindow.ListBoxSelect(Sender: TObject); begin FCallerWidget.FocusItem := ListBox.FocusItem; + if not (wo_FocusItemTriggersOnChange in FCallerWidget.FOptions) then + FCallerWidget.DoOnChange; Close; end; @@ -413,6 +441,11 @@ begin ddw.DontCloseWidget := self; // now we can control when the popup window closes r := GetDropDownPos(Parent, self, ddw); // find suitable position ddw.Height := r.Height; // in case GetDropDownPos resized us + + if (FItems.Count > 0) and Assigned(OnDropDown) then + OnDropDown(self); + ddw.OnClose := @InternalOnClose; + ddw.ShowAt(Parent, r.Left, r.Top); end else @@ -432,11 +465,6 @@ begin DoDropDown; end; -procedure TfpgAbstractComboBox.SetFocusItem(const AValue: integer); -begin - -end; - procedure TfpgAbstractComboBox.SetText(const AValue: string); var i: integer; @@ -523,7 +551,6 @@ begin FocusItem := NewIndex; RePaint; end; - end; procedure TfpgAbstractComboBox.HandleResize(awidth, aheight: TfpgCoord); diff --git a/src/gui/gui_editcombo.pas b/src/gui/gui_editcombo.pas index dad8449f..fee9ec70 100644 --- a/src/gui/gui_editcombo.pas +++ b/src/gui/gui_editcombo.pas @@ -129,6 +129,8 @@ type property TextColor; property Width; property OnChange; + property OnCloseUp; + property OnDropDown; end; @@ -359,6 +361,11 @@ begin ddw.DontCloseWidget := self; // now we can control when the popup window closes r := GetDropDownPos(Parent, self, ddw); ddw.Height := r.Height; + + if (FItems.Count > 0) and Assigned(OnDropDown) then + OnDropDown(self); + ddw.OnClose := @InternalOnClose; + ddw.ShowAt(Parent, r.Left, r.Top); end else diff --git a/src/gui/gui_popupcalendar.pas b/src/gui/gui_popupcalendar.pas index a70d5a6f..1fcfb44b 100644 --- a/src/gui/gui_popupcalendar.pas +++ b/src/gui/gui_popupcalendar.pas @@ -148,6 +148,8 @@ type property CloseOnSelect: boolean read FCloseOnSelect write SetCloseOnSelect default True; property TabOrder; property OnChange; + property OnCloseUp; + property OnDropDown; end; {@VFD_NEWFORM_DECL} @@ -334,7 +336,7 @@ end; procedure TfpgPopupCalendar.SetCloseOnSelect(const AValue: boolean); begin if FCloseOnSelect = AValue then - exit; + Exit; FCloseOnSelect := AValue; end; @@ -755,7 +757,7 @@ begin on E: Exception do begin FDateFormat := OldFormat; - ShowMessage(E.Message); + fpgApplication.HandleException(self); end; end; end; @@ -772,6 +774,10 @@ begin { Set to false CloseOnSelect to leave opened popup calendar menu} ddw.CloseOnSelect := CloseOnSelect; ddw.CallerWidget := self; + + if Assigned(OnDropDown) then + OnDropDown(self); + ddw.MinDate := FMinDate; ddw.MaxDate := FMaxDate; ddw.DateValue := FDate; @@ -781,6 +787,7 @@ begin ddw.UpdateCalendar; //slapshot ddw.PopupFrame := True; ddw.OnValueSet := @InternalOnValueSet; + ddw.OnClose := @InternalOnClose; end else begin |