From 9f577dc5482422641419f105590452731717f2e3 Mon Sep 17 00:00:00 2001 From: Juha Date: Sun, 18 Sep 2022 21:17:56 +0300 Subject: [PATCH] LCL: Add an option to NOT call TCheckbox OnChange handler when clicked. Issue #39870, patch by Arioch The. --- lcl/include/buttoncontrol.inc | 3 ++- lcl/include/customcheckbox.inc | 23 ++++++++++++++--------- lcl/stdctrls.pp | 5 +++++ 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/lcl/include/buttoncontrol.inc b/lcl/include/buttoncontrol.inc index e6e3984e34..9c2adf2436 100644 --- a/lcl/include/buttoncontrol.inc +++ b/lcl/include/buttoncontrol.inc @@ -51,7 +51,8 @@ end; procedure TButtonControl.Click; begin - DoOnChange; + if not FSkipOnChangeOnClick then + DoOnChange; inherited Click; end; diff --git a/lcl/include/customcheckbox.inc b/lcl/include/customcheckbox.inc index 9bad674b64..8daac80965 100644 --- a/lcl/include/customcheckbox.inc +++ b/lcl/include/customcheckbox.inc @@ -115,7 +115,13 @@ end; procedure TCustomCheckBox.Click; begin - // skip clicks by WM_MOUSEUP + if VCL_OnClick_Emulation then Exit; + FSkipOnChangeOnClick := True; + try + inherited Click; + finally + FSkipOnChangeOnClick := False; + end; end; function TCustomCheckBox.RetrieveState: TCheckBoxState; @@ -130,13 +136,12 @@ begin end; end; -{------------------------------------------------------------------------------ - Method: TCustomCheckBox.Create - Params: TheOwner: the owner of the class - Returns: Nothing +class constructor TCustomCheckBox.CreateClass; +begin + VCL_OnClick_Emulation := True; + inherited; +end; - Constructor for custom checkbox. - ------------------------------------------------------------------------------} constructor TCustomCheckBox.Create(TheOwner: TComponent); begin inherited Create(TheOwner); @@ -276,8 +281,8 @@ end; procedure TCustomCheckBox.DoClickOnChange; begin Changed; - // emulate delphi OnClick behaviour (click will call OnChange) - if not ClicksDisabled then + // emulate delphi OnClick behaviour (inherited .Click will call DoOnChange) + if VCL_OnClick_Emulation and not ClicksDisabled then inherited Click else DoOnChange; diff --git a/lcl/stdctrls.pp b/lcl/stdctrls.pp index 63d3816ced..9c6a5da745 100644 --- a/lcl/stdctrls.pp +++ b/lcl/stdctrls.pp @@ -1181,6 +1181,8 @@ type function IsCheckedStored: boolean; procedure WMDefaultClicked(var Message: TLMessage); message LM_CLICKED; protected + // Do not call OnChange when clicked, required by TCustomCheckBox + FSkipOnChangeOnClick: boolean; class procedure WSRegisterClass; override; function GetActionLinkClass: TControlActionLinkClass; override; function GetChecked: Boolean; virtual; @@ -1353,6 +1355,9 @@ type procedure TextChanged; override; procedure CreateParams(var Params: TCreateParams); override; public + // VCL calls OnChange when clicked. This can be turned off for a more logical behavior. + class var VCL_OnClick_Emulation: boolean; + class constructor CreateClass; constructor Create(TheOwner: TComponent); override; public property Alignment: TLeftRight read GetAlignment write SetAlignment default taRightJustify;