mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-29 23:30:22 +02:00
LCL: TCustomListView: implemented OnItemChecked. fixes #17042
git-svn-id: trunk@27975 -
This commit is contained in:
parent
ca5d59ca59
commit
612440d648
@ -950,6 +950,7 @@ type
|
|||||||
TLVDeletedEvent = procedure(Sender: TObject; Item: TListItem) of object;
|
TLVDeletedEvent = procedure(Sender: TObject; Item: TListItem) of object;
|
||||||
TLVInsertEvent = TLVDeletedEvent;
|
TLVInsertEvent = TLVDeletedEvent;
|
||||||
TLVDataEvent = TLVDeletedEvent;
|
TLVDataEvent = TLVDeletedEvent;
|
||||||
|
TLVCheckedItemEvent = procedure (Sender: TObject; Item: TListItem) of object;
|
||||||
TLVSelectItemEvent = procedure(Sender: TObject; Item: TListItem;
|
TLVSelectItemEvent = procedure(Sender: TObject; Item: TListItem;
|
||||||
Selected: Boolean) of object;
|
Selected: Boolean) of object;
|
||||||
TLVCustomDrawEvent = procedure(Sender: TCustomListView; const ARect: TRect;
|
TLVCustomDrawEvent = procedure(Sender: TCustomListView; const ARect: TRect;
|
||||||
@ -1034,6 +1035,7 @@ type
|
|||||||
FOnData: TLVDataEvent;
|
FOnData: TLVDataEvent;
|
||||||
FOnDeletion: TLVDeletedEvent;
|
FOnDeletion: TLVDeletedEvent;
|
||||||
FOnInsert: TLVInsertEvent;
|
FOnInsert: TLVInsertEvent;
|
||||||
|
FOnItemChecked: TLVCheckedItemEvent;
|
||||||
FOnSelectItem: TLVSelectItemEvent;
|
FOnSelectItem: TLVSelectItemEvent;
|
||||||
FOnCustomDraw: TLVCustomDrawEvent;
|
FOnCustomDraw: TLVCustomDrawEvent;
|
||||||
FOnCustomDrawItem: TLVCustomDrawItemEvent;
|
FOnCustomDrawItem: TLVCustomDrawItemEvent;
|
||||||
@ -1100,6 +1102,7 @@ type
|
|||||||
procedure Delete(Item : TListItem);
|
procedure Delete(Item : TListItem);
|
||||||
procedure DoDeletion(AItem: TListItem); virtual;
|
procedure DoDeletion(AItem: TListItem); virtual;
|
||||||
procedure DoInsert(AItem: TListItem); virtual;
|
procedure DoInsert(AItem: TListItem); virtual;
|
||||||
|
procedure DoItemChecked(AItem: TListItem);
|
||||||
procedure DoSelectItem(AItem: TListItem; ASelected: Boolean); virtual;
|
procedure DoSelectItem(AItem: TListItem; ASelected: Boolean); virtual;
|
||||||
procedure InsertItem(Item : TListItem);
|
procedure InsertItem(Item : TListItem);
|
||||||
procedure ImageChanged(Sender : TObject);
|
procedure ImageChanged(Sender : TObject);
|
||||||
@ -1137,6 +1140,7 @@ type
|
|||||||
property OnData: TLVDataEvent read FOnData write FOnData;
|
property OnData: TLVDataEvent read FOnData write FOnData;
|
||||||
property OnDeletion: TLVDeletedEvent read FOnDeletion write FOnDeletion;
|
property OnDeletion: TLVDeletedEvent read FOnDeletion write FOnDeletion;
|
||||||
property OnInsert: TLVInsertEvent read FOnInsert write FOnInsert;
|
property OnInsert: TLVInsertEvent read FOnInsert write FOnInsert;
|
||||||
|
property OnItemChecked: TLVCheckedItemEvent read FOnItemChecked write FOnItemChecked;
|
||||||
property OnSelectItem: TLVSelectItemEvent read FOnSelectItem write FOnSelectItem;
|
property OnSelectItem: TLVSelectItemEvent read FOnSelectItem write FOnSelectItem;
|
||||||
property OnCustomDraw: TLVCustomDrawEvent read FOnCustomDraw write FOnCustomDraw;
|
property OnCustomDraw: TLVCustomDrawEvent read FOnCustomDraw write FOnCustomDraw;
|
||||||
property OnCustomDrawItem: TLVCustomDrawItemEvent read FOnCustomDrawItem write FOnCustomDrawItem;
|
property OnCustomDrawItem: TLVCustomDrawItemEvent read FOnCustomDrawItem write FOnCustomDrawItem;
|
||||||
@ -1260,6 +1264,7 @@ type
|
|||||||
property OnEndDrag;
|
property OnEndDrag;
|
||||||
property OnEnter;
|
property OnEnter;
|
||||||
property OnExit;
|
property OnExit;
|
||||||
|
property OnItemChecked;
|
||||||
property OnKeyDown;
|
property OnKeyDown;
|
||||||
property OnKeyPress;
|
property OnKeyPress;
|
||||||
property OnKeyUp;
|
property OnKeyUp;
|
||||||
|
@ -231,47 +231,57 @@ begin
|
|||||||
LVN_ITEMCHANGING: begin
|
LVN_ITEMCHANGING: begin
|
||||||
//Check
|
//Check
|
||||||
end;
|
end;
|
||||||
LVN_ITEMCHANGED: begin
|
LVN_ITEMCHANGED:
|
||||||
|
begin
|
||||||
Item := Items[nm^.iItem];
|
Item := Items[nm^.iItem];
|
||||||
//DebugLn('TCustomListView.CNNotify Count=',dbgs(Items.Count),' nm^.iItem=',dbgs(nm^.iItem),' destroying=',dbgs(lifDestroying in Item.FFlags));
|
//DebugLn('TCustomListView.CNNotify Count=',dbgs(Items.Count),' nm^.iItem=',dbgs(nm^.iItem),' destroying=',dbgs(lifDestroying in Item.FFlags));
|
||||||
if (Item <> nil) and (not OwnerData) and (lifDestroying in Item.FFlags) then begin
|
if (Item <> nil) and (not OwnerData) and (lifDestroying in Item.FFlags) then
|
||||||
|
begin
|
||||||
if Item=FFocused then
|
if Item=FFocused then
|
||||||
FFocused:=nil;
|
FFocused:=nil;
|
||||||
if Item=FSelected then
|
if Item=FSelected then
|
||||||
InvalidateSelected;
|
InvalidateSelected;
|
||||||
end else begin
|
end else
|
||||||
|
begin
|
||||||
// owner data
|
// owner data
|
||||||
Change(Item, nm^.uChanged);
|
Change(Item, nm^.uChanged);
|
||||||
if (nm^.uChanged = LVIF_STATE)
|
if (nm^.uChanged = LVIF_STATE) then
|
||||||
then begin
|
begin
|
||||||
|
// checkbox
|
||||||
|
if Checkboxes then
|
||||||
|
DoItemChecked(Item);
|
||||||
|
|
||||||
// focus
|
// focus
|
||||||
if (nm^.uOldState and LVIS_FOCUSED) <> (nm^.uNewState and LVIS_FOCUSED)
|
if (nm^.uOldState and LVIS_FOCUSED) <>
|
||||||
then begin
|
(nm^.uNewState and LVIS_FOCUSED) then
|
||||||
|
begin
|
||||||
// focus state changed
|
// focus state changed
|
||||||
if (nm^.uNewState and LVIS_FOCUSED) = 0
|
if (nm^.uNewState and LVIS_FOCUSED) = 0 then
|
||||||
then begin
|
begin
|
||||||
if FFocused = Item
|
if FFocused = Item then
|
||||||
then FFocused := nil;
|
FFocused := nil;
|
||||||
end
|
end else
|
||||||
else begin
|
begin
|
||||||
FFocused := Item;
|
FFocused := Item;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
// select
|
// select
|
||||||
if (nm^.uOldState and LVIS_SELECTED) <> (nm^.uNewState and LVIS_SELECTED)
|
if (nm^.uOldState and LVIS_SELECTED) <>
|
||||||
then begin
|
(nm^.uNewState and LVIS_SELECTED) then
|
||||||
|
begin
|
||||||
// select state changed
|
// select state changed
|
||||||
if (nm^.uNewState and LVIS_SELECTED) = 0
|
if (nm^.uNewState and LVIS_SELECTED) = 0 then
|
||||||
then begin
|
begin
|
||||||
if not OwnerData and (FSelected = Item) then
|
if not OwnerData and (FSelected = Item) then
|
||||||
InvalidateSelected
|
InvalidateSelected
|
||||||
else if OwnerData and (nm^.iItem=FSelectedIdx) then begin
|
else if OwnerData and (nm^.iItem=FSelectedIdx) then
|
||||||
|
begin
|
||||||
FSelectedIdx:=-1;
|
FSelectedIdx:=-1;
|
||||||
InvalidateSelected;
|
InvalidateSelected;
|
||||||
end;
|
end;
|
||||||
DoSelectItem(Item, False);
|
DoSelectItem(Item, False);
|
||||||
end
|
end else
|
||||||
else begin
|
begin
|
||||||
FSelected := Item;
|
FSelected := Item;
|
||||||
Include(FFlags,lffSelectedValid);
|
Include(FFlags,lffSelectedValid);
|
||||||
if OwnerData then FSelectedIdx:=nm^.iItem;
|
if OwnerData then FSelectedIdx:=nm^.iItem;
|
||||||
@ -391,6 +401,24 @@ begin
|
|||||||
if Assigned(FOnInsert) then FOnInsert(Self, AItem);
|
if Assigned(FOnInsert) then FOnInsert(Self, AItem);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{------------------------------------------------------------------------------}
|
||||||
|
{ TCustomListView DoItemChecked }
|
||||||
|
{------------------------------------------------------------------------------}
|
||||||
|
procedure TCustomListView.DoItemChecked(AItem: TListItem);
|
||||||
|
var
|
||||||
|
B: Boolean;
|
||||||
|
begin
|
||||||
|
if (not HandleAllocated) or (csLoading in ComponentState) then exit;
|
||||||
|
B := TWSCustomListViewClass(WidgetSetClass).ItemGetChecked(Self,
|
||||||
|
AItem.Index, AItem);
|
||||||
|
if B <> AItem.GetCheckedInternal then
|
||||||
|
begin
|
||||||
|
AItem.Checked := B;
|
||||||
|
if Assigned(FOnItemChecked) then
|
||||||
|
FOnItemChecked(Self, AItem);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
{------------------------------------------------------------------------------}
|
{------------------------------------------------------------------------------}
|
||||||
{ TCustomListView DoSelectItem }
|
{ TCustomListView DoSelectItem }
|
||||||
{------------------------------------------------------------------------------}
|
{------------------------------------------------------------------------------}
|
||||||
|
@ -648,8 +648,9 @@ var
|
|||||||
begin
|
begin
|
||||||
LV := FOwner.FOwner;
|
LV := FOwner.FOwner;
|
||||||
FChecked := AValue;
|
FChecked := AValue;
|
||||||
if LV.Checkboxes and WSUpdateAllowed
|
if LV.Checkboxes and WSUpdateAllowed then
|
||||||
then TWSCustomListViewClass(LV.WidgetSetClass).ItemSetChecked(LV, GetIndex, Self, AValue);
|
TWSCustomListViewClass(LV.WidgetSetClass).ItemSetChecked(LV, GetIndex,
|
||||||
|
Self, AValue);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{------------------------------------------------------------------------------}
|
{------------------------------------------------------------------------------}
|
||||||
|
Loading…
Reference in New Issue
Block a user