LCL/TCheckListBox: Deprecate event OnItemClick (duplicate of Delphi-compatible event OnClickCheck) and related methods, issue #38933. Fix KeyDown method to result in the same order of events as in Delphi.

This commit is contained in:
wp_xyz 2023-09-11 23:42:32 +02:00
parent 6873e2646a
commit 144bdc06af
2 changed files with 9 additions and 9 deletions

View File

@ -66,7 +66,7 @@ type
procedure ReadData(Stream: TStream); procedure ReadData(Stream: TStream);
procedure WriteData(Stream: TStream); procedure WriteData(Stream: TStream);
procedure ClickCheck; virtual; procedure ClickCheck; virtual;
procedure ItemClick(const AIndex: Integer); virtual; procedure ItemClick(const AIndex: Integer); virtual; deprecated 'Use ClickCheck instead'; // to be removed in V4.99
procedure KeyDown(var Key: Word; Shift: TShiftState); override; procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure FontChanged(Sender: TObject); override; procedure FontChanged(Sender: TObject); override;
public public
@ -84,7 +84,7 @@ type
property ItemEnabled[AIndex: Integer]: Boolean read GetItemEnabled write SetItemEnabled; property ItemEnabled[AIndex: Integer]: Boolean read GetItemEnabled write SetItemEnabled;
property State[AIndex: Integer]: TCheckBoxState read GetState write SetState; property State[AIndex: Integer]: TCheckBoxState read GetState write SetState;
property OnClickCheck: TNotifyEvent read FOnClickCheck write FOnClickCheck; property OnClickCheck: TNotifyEvent read FOnClickCheck write FOnClickCheck;
property OnItemClick: TCheckListClicked read FOnItemClick write FOnItemClick; property OnItemClick: TCheckListClicked read FOnItemClick write FOnItemClick; deprecated 'Use OnClickCheck instead'; // to be removed in V4.99
end; end;
@ -137,7 +137,7 @@ type
property OnEndDrag; property OnEndDrag;
property OnEnter; property OnEnter;
property OnExit; property OnExit;
property OnItemClick; property OnItemClick; deprecated 'Use OnClickCheck instead'; // to be removed in V4.99
property OnKeyPress; property OnKeyPress;
property OnKeyDown; property OnKeyDown;
property OnKeyUp; property OnKeyUp;
@ -266,7 +266,7 @@ procedure TCustomCheckListBox.DoChange(var Msg: TLMessage);
begin begin
//DebugLn(['TCustomCheckListBox.DoChange ',DbgSName(Self),' ',Msg.WParam]); //DebugLn(['TCustomCheckListBox.DoChange ',DbgSName(Self),' ',Msg.WParam]);
ClickCheck; ClickCheck;
ItemClick(Msg.WParam); ItemClick(Msg.WParam); // deprecated; to be removed in V4.99
end; end;
function TCustomCheckListBox.GetCachedDataSize: Integer; function TCustomCheckListBox.GetCachedDataSize: Integer;
@ -323,6 +323,7 @@ procedure TCustomCheckListBox.KeyDown(var Key: Word; Shift: TShiftState);
var var
Index: Integer; Index: Integer;
begin begin
inherited KeyDown(Key,Shift);
if (Key = VK_SPACE) and (Shift=[]) then if (Key = VK_SPACE) and (Shift=[]) then
begin begin
//Delphi (7) sets ItemIndex to 0 in this case and fires OnClick //Delphi (7) sets ItemIndex to 0 in this case and fires OnClick
@ -337,11 +338,10 @@ begin
Checked[Index] := not Checked[Index]; Checked[Index] := not Checked[Index];
ClickCheck; ClickCheck;
//ToDo: does Delphi fire OnItemClick and in the same order? //ToDo: does Delphi fire OnItemClick and in the same order?
ItemClick(Index); //-- wp: Delphi fires: OnKeyDown - OnClickCheck - OnKeyPress - OnKeyUp
Key := VK_UNKNOWN; ItemClick(Index); // deprecated; to be removed in V4.99
end; end;
end else end;
inherited KeyDown(Key,Shift);
end; end;
procedure TCustomCheckListBox.SetItemEnabled(AIndex: Integer; procedure TCustomCheckListBox.SetItemEnabled(AIndex: Integer;

View File

@ -290,7 +290,7 @@ type
class function GetControlClassDefaultSize: TSize; override; class function GetControlClassDefaultSize: TSize; override;
procedure Click; override; procedure Click; override;
procedure CMShapeHitTest(var Message: TCMHittest); message CM_MASKHITTEST; procedure CMShapeHitTest(var Message: TCMHittest); message CM_MASKHITTEST;
procedure DrawToCanvas(ACanvas: TCanvas); procedure DrawToCanvas(ACanvas: TCanvas); virtual;
procedure UpdateMask; procedure UpdateMask;
public public
constructor Create(TheOwner: TComponent); override; constructor Create(TheOwner: TComponent); override;