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
This commit is contained in:
wp_xxyyzz
2021-11-05 22:22:36 +00:00
parent 8f89ccc7f4
commit 35e4b8de27
2 changed files with 30 additions and 3 deletions

View File

@ -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');

View File

@ -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,6 +665,17 @@ 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
@ -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;
@ -1049,6 +1074,9 @@ begin
if FItems.Count = 0 then
exit;
if Now() - FCloseUpTime < DELAY then
exit;
F := TCheckComboBoxForm.CreateNew(Application);
F.FCaller := Self;
F.BiDiMode := BiDiMode;