CheckListBox: OnItemClick when using space bar to toggle the checkbox

git-svn-id: trunk@9689 -
This commit is contained in:
vincents 2006-07-28 12:56:22 +00:00
parent e7c9877bac
commit e4534f2a06
3 changed files with 19 additions and 4 deletions

View File

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

View File

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

View File

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