From 35e4b8de27a5347677a24a074c81c8f8ed0c320e Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Fri, 5 Nov 2021 22:22:36 +0000 Subject: [PATCH] ExCtrls: Fix CheckComboBoxEx not closing up when button is clicked in dropped-down state. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8145 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../exctrls/examples/CheckComboBoxEx/main.pas | 1 - components/exctrls/source/excheckcombo.pas | 32 +++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/components/exctrls/examples/CheckComboBoxEx/main.pas b/components/exctrls/examples/CheckComboBoxEx/main.pas index 275c9b623..56410356d 100644 --- a/components/exctrls/examples/CheckComboBoxEx/main.pas +++ b/components/exctrls/examples/CheckComboBoxEx/main.pas @@ -52,7 +52,6 @@ begin FCombo := TCheckComboBoxEx.Create(self); FCombo.Align := alTop; FCombo.BorderSpacing.Around := 6; - //FCombo.AutoDropDown := true; FCombo.Items.Add('Item 1'); FCombo.Items.Add('Item 2'); FCombo.Items.Add('Item 3'); diff --git a/components/exctrls/source/excheckcombo.pas b/components/exctrls/source/excheckcombo.pas index f13c28a9b..da984d027 100644 --- a/components/exctrls/source/excheckcombo.pas +++ b/components/exctrls/source/excheckcombo.pas @@ -66,6 +66,7 @@ type FAutoDropDown: Boolean; FButtonWidth: Integer; FCheckListBox: TCheckListBox; + FCloseUpTime: TDateTime; FDelimiter: Char; FDropDownCount: Integer; FDropDownImageIndex: TCheckComboBoxExImageIndex; @@ -82,6 +83,8 @@ type FOnDropDown: TNotifyEvent; FOnItemChange: TCheckItemChange; FOnItemClick: TCheckListClicked; + procedure ButtonMouseDownHandler(Sender: TObject; + AButton: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure CheckComboBoxFormCloseHandler(Sender: TObject; var CloseAction: TCloseAction); function GetButtonWidth: Integer; function GetChecked(AIndex: Integer): Boolean; @@ -108,6 +111,7 @@ type protected procedure ButtonClick; override; procedure CloseUp; + function CreateBuddy: TControl; override; procedure CreateHandle; override; procedure DoAutoAdjustLayout(const AMode: TLayoutAdjustmentPolicy; const AXProportion, AYProportion: Double); override; @@ -661,13 +665,24 @@ begin end; procedure TCheckComboBoxEx.ButtonClick; +begin + { + if DroppedDown then + CloseUp + else + ShowPopup; +} +end; + +procedure TCheckComboBoxEx.ButtonMouseDownHandler(Sender: TObject; + AButton: TMouseButton; Shift: TShiftState; X, Y: Integer); begin if DroppedDown then CloseUp else ShowPopup; end; - + procedure TCheckComboBoxEx.CheckAll(AState: TCheckBoxState; AAllowGrayed: Boolean = true; AAllowDisabled: Boolean = true); var @@ -720,6 +735,13 @@ begin InvalidateButton; UpdateCaption; DoCloseUp; + FCloseUpTime := Now(); +end; + +function TCheckComboBoxEx.CreateBuddy: TControl; +begin + Result := inherited; + TSpeedButton(Result).OnMouseDown := @ButtonMouseDownHandler; end; procedure TCheckComboBoxEx.CreateHandle; @@ -1041,6 +1063,9 @@ begin end; procedure TCheckComboBoxEx.ShowPopup; +const + MILLISECOND = 1.0/(24*60*60*100); + DELAY = 10*MILLISECOND; var PopupOrigin: TPoint; PopupWidth: Integer; @@ -1048,7 +1073,10 @@ var begin if FItems.Count = 0 then exit; - + + if Now() - FCloseUpTime < DELAY then + exit; + F := TCheckComboBoxForm.CreateNew(Application); F.FCaller := Self; F.BiDiMode := BiDiMode;