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 ReadData(Stream: TStream);
procedure WriteData(Stream: TStream); procedure WriteData(Stream: TStream);
procedure ClickChecked; procedure ClickChecked;
procedure ItemClick(const AIndex: Integer);
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
property Checked[const AIndex: Integer]: Boolean read GetChecked write SetChecked; property Checked[const AIndex: Integer]: Boolean read GetChecked write SetChecked;
@ -146,7 +147,7 @@ procedure TCustomCheckListBox.DoChange(var Msg: TLMessage);
begin begin
//DebugLn(['TCustomCheckListBox.DoChange ',DbgSName(Self),' ',Msg.WParam]); //DebugLn(['TCustomCheckListBox.DoChange ',DbgSName(Self),' ',Msg.WParam]);
ClickChecked; ClickChecked;
if Assigned(OnItemClick) then OnItemClick(Self,Msg.WParam); ItemClick(Msg.WParam);
end; end;
function TCustomCheckListBox.GetCachedDataSize: Integer; function TCustomCheckListBox.GetCachedDataSize: Integer;
@ -171,9 +172,13 @@ begin
end; end;
procedure TCustomCheckListBox.KeyDown(var Key: Word; Shift: TShiftState); procedure TCustomCheckListBox.KeyDown(var Key: Word; Shift: TShiftState);
var
Index: Integer;
begin begin
if (Key = VK_SPACE) and (Shift=[]) then 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; Key:=VK_UNKNOWN;
end else end else
inherited KeyDown(Key,Shift); inherited KeyDown(Key,Shift);
@ -201,6 +206,11 @@ begin
if Assigned(fOnClickChecked) then FOnClickChecked(self); if Assigned(fOnClickChecked) then FOnClickChecked(self);
end; end;
procedure TCustomCheckListBox.ItemClick(const AIndex: Integer);
begin
if Assigned(OnItemClick) then OnItemClick(Self, AIndex);
end;
procedure TCustomCheckListBox.DefineProperties(Filer: TFiler); procedure TCustomCheckListBox.DefineProperties(Filer: TFiler);
begin begin
inherited DefineProperties(Filer); inherited DefineProperties(Filer);

View File

@ -482,10 +482,10 @@ Var
begin begin
// item clicked: toggle // item clicked: toggle
if I < TCheckListBox(lWinControl).Items.Count then begin if I < TCheckListBox(lWinControl).Items.Count then begin
TCheckListBox(lWinControl).Checked[I] := not TCheckListBox(lWinControl).Checked[I];
Message.Msg := LM_CHANGED; Message.Msg := LM_CHANGED;
Message.WParam := I; Message.WParam := I;
DeliverMessage(lWinControl, Message); DeliverMessage(lWinControl, Message);
TCheckListBox(lWinControl).Checked[I] := not TCheckListBox(lWinControl).Checked[I];
end; end;
// can only click one item // can only click one item
exit; exit;

View File

@ -428,6 +428,7 @@ Var
I: Integer; I: Integer;
ItemRect: Windows.Rect; ItemRect: Windows.Rect;
MousePos: Windows.Point; MousePos: Windows.Point;
Message: TLMessage;
begin begin
MousePos.X := LMMouse.Pos.X; MousePos.X := LMMouse.Pos.X;
MousePos.Y := LMMouse.Pos.Y; MousePos.Y := LMMouse.Pos.Y;
@ -438,8 +439,12 @@ Var
if Windows.PtInRect(@ItemRect, MousePos) then if Windows.PtInRect(@ItemRect, MousePos) then
begin begin
// item clicked: toggle // 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]; 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 // can only click one item
exit; exit;
end; end;