mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-10 02:28:04 +02:00
CheckListBox: OnItemClick when using space bar to toggle the checkbox
git-svn-id: trunk@9689 -
This commit is contained in:
parent
e7c9877bac
commit
e4534f2a06
@ -56,6 +56,7 @@ type
|
||||
procedure ReadData(Stream: TStream);
|
||||
procedure WriteData(Stream: TStream);
|
||||
procedure ClickChecked;
|
||||
procedure ItemClick(const AIndex: Integer);
|
||||
public
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
property Checked[const AIndex: Integer]: Boolean read GetChecked write SetChecked;
|
||||
@ -146,7 +147,7 @@ procedure TCustomCheckListBox.DoChange(var Msg: TLMessage);
|
||||
begin
|
||||
//DebugLn(['TCustomCheckListBox.DoChange ',DbgSName(Self),' ',Msg.WParam]);
|
||||
ClickChecked;
|
||||
if Assigned(OnItemClick) then OnItemClick(Self,Msg.WParam);
|
||||
ItemClick(Msg.WParam);
|
||||
end;
|
||||
|
||||
function TCustomCheckListBox.GetCachedDataSize: Integer;
|
||||
@ -171,9 +172,13 @@ begin
|
||||
end;
|
||||
|
||||
procedure TCustomCheckListBox.KeyDown(var Key: Word; Shift: TShiftState);
|
||||
var
|
||||
Index: Integer;
|
||||
begin
|
||||
if (Key = VK_SPACE) and (Shift=[]) then begin
|
||||
Checked[ItemIndex]:=not Checked[ItemIndex];
|
||||
Index := ItemIndex;
|
||||
Checked[Index]:=not Checked[Index];
|
||||
ItemClick(Index);
|
||||
Key:=VK_UNKNOWN;
|
||||
end else
|
||||
inherited KeyDown(Key,Shift);
|
||||
@ -201,6 +206,11 @@ begin
|
||||
if Assigned(fOnClickChecked) then FOnClickChecked(self);
|
||||
end;
|
||||
|
||||
procedure TCustomCheckListBox.ItemClick(const AIndex: Integer);
|
||||
begin
|
||||
if Assigned(OnItemClick) then OnItemClick(Self, AIndex);
|
||||
end;
|
||||
|
||||
procedure TCustomCheckListBox.DefineProperties(Filer: TFiler);
|
||||
begin
|
||||
inherited DefineProperties(Filer);
|
||||
|
@ -482,10 +482,10 @@ Var
|
||||
begin
|
||||
// item clicked: toggle
|
||||
if I < TCheckListBox(lWinControl).Items.Count then begin
|
||||
TCheckListBox(lWinControl).Checked[I] := not TCheckListBox(lWinControl).Checked[I];
|
||||
Message.Msg := LM_CHANGED;
|
||||
Message.WParam := I;
|
||||
DeliverMessage(lWinControl, Message);
|
||||
TCheckListBox(lWinControl).Checked[I] := not TCheckListBox(lWinControl).Checked[I];
|
||||
end;
|
||||
// can only click one item
|
||||
exit;
|
||||
|
@ -428,6 +428,7 @@ Var
|
||||
I: Integer;
|
||||
ItemRect: Windows.Rect;
|
||||
MousePos: Windows.Point;
|
||||
Message: TLMessage;
|
||||
begin
|
||||
MousePos.X := LMMouse.Pos.X;
|
||||
MousePos.Y := LMMouse.Pos.Y;
|
||||
@ -438,8 +439,12 @@ Var
|
||||
if Windows.PtInRect(@ItemRect, MousePos) then
|
||||
begin
|
||||
// item clicked: toggle
|
||||
if I < TCheckListBox(lWinControl).Items.Count then
|
||||
if I < TCheckListBox(lWinControl).Items.Count then begin
|
||||
TCheckListBox(lWinControl).Checked[I] := not TCheckListBox(lWinControl).Checked[I];
|
||||
Message.Msg := LM_CHANGED;
|
||||
Message.WParam := I;
|
||||
DeliverMessage(lWinControl, Message);
|
||||
end;
|
||||
// can only click one item
|
||||
exit;
|
||||
end;
|
||||
|
Loading…
Reference in New Issue
Block a user