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

View File

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