From af9412b01999bc5918c04e3cdd0e661e23cb3ae6 Mon Sep 17 00:00:00 2001 From: Bart <9132501-flyingsheep@users.noreply.gitlab.com> Date: Fri, 5 Jan 2024 17:59:21 +0100 Subject: [PATCH] TCustomListView: trying to implement OnChanging (Win32): * according to Delph docs (https://docwiki.embarcadero.com/Libraries/Alexandria/en/Vcl.ComCtrls.TCustomListView.CanChange) the function CanClose calls the OnChanging event. It's result indicates wether changing will be allowed. --- lcl/comctrls.pp | 2 +- lcl/include/customlistview.inc | 16 +++++--------- .../win32/win32wscustomlistview.inc | 22 +++++++++---------- 3 files changed, 16 insertions(+), 24 deletions(-) diff --git a/lcl/comctrls.pp b/lcl/comctrls.pp index b6b7eac5d5..d843facbea 100644 --- a/lcl/comctrls.pp +++ b/lcl/comctrls.pp @@ -1525,7 +1525,7 @@ type function CreateListItems: TListItems; virtual; function CanEdit(Item: TListItem): Boolean; virtual; procedure Change(AItem: TListItem; AChange: Integer); virtual; - procedure DoChanging(AItem: TListItem; AChange: Integer; var AllowChange: Boolean); + function CanChange(AItem: TListItem; AChange: Integer): Boolean; procedure ColClick(AColumn: TListColumn); virtual; procedure Delete(AItem : TListItem); virtual; diff --git a/lcl/include/customlistview.inc b/lcl/include/customlistview.inc index aea7ae2f9c..a4d855f216 100644 --- a/lcl/include/customlistview.inc +++ b/lcl/include/customlistview.inc @@ -205,10 +205,11 @@ begin then FOnChange(Self, AItem, ItemChange); end; -procedure TCustomListView.DoChanging(AItem: TListItem; AChange: Integer; var AllowChange: Boolean); +function TCustomListView.CanChange(AItem: TListItem; AChange: Integer): Boolean; var ItemChange: TItemChange; begin + Result := True; case AChange of LVIF_TEXT: ItemChange := ctText; LVIF_IMAGE: ItemChange := ctImage; @@ -217,14 +218,7 @@ begin Exit; end; if Assigned(FOnChanging) then - begin - FOnChanging(Self, AItem, ItemChange, AllowChange); - if not AllowChange then - begin - //ToDo - end; - end; - + FOnChanging(Self, AItem, ItemChange, Result); end; {------------------------------------------------------------------------------} @@ -335,7 +329,7 @@ begin LVN_ITEMCHANGING: begin //Check debugln('TCustomListView.CNNotify: LVN_ITEMCHANGING'); - AMessage.Result:=1; + //AMessage.Result:=1; //1=disallow changing //if nm^.iItem < 0 then // Item := nil //else @@ -344,7 +338,7 @@ begin //if Assigned(Item) then //begin // AllowChange := True; - // DoChanging(Item, nm^.uChanged, AllowChange); + // CanChange(Item, nm^.uChanged, AllowChange); // if not AllowChange then // AMessage.Result := 1; //end; diff --git a/lcl/interfaces/win32/win32wscustomlistview.inc b/lcl/interfaces/win32/win32wscustomlistview.inc index 8053b447dc..a4c5dec818 100644 --- a/lcl/interfaces/win32/win32wscustomlistview.inc +++ b/lcl/interfaces/win32/win32wscustomlistview.inc @@ -300,11 +300,9 @@ var var nm: PNMListView; Item: TListItem; - AllowChange: Boolean; begin - debugln(['HandleListChanging: HandleAllocated=',ALV.HandleAllocated]); - MsgResult := LResult(1); - EXIT; + debugln(['HandleListChanging: HandleAllocated=',ALV.HandleAllocated,', (wcfInitializing in FWinControlFlags)=',Dbgs(wcfInitializing in ALV.FWinControlFlags)]); + if (wcfInitializing in ALV.FWinControlFlags) then Exit; nm := PNMListView(NMHdr); if nm^.iItem < 0 then Item := nil @@ -313,12 +311,11 @@ var if Assigned(Item) then begin - AllowChange := True; - ALV.DoChanging(Item, nm^.uChanged, AllowChange); - //if not AllowChange then - MsgResult := 0; + if ALV.CanChange(Item, nm^.uChanged) then + MsgResult := 0 + else + MsgResult := 1; end; - end; procedure HandleListViewOwnerDataHint(ALV: TCustomListViewAccess); @@ -350,10 +347,11 @@ begin HandleListViewFindItem(TCustomListViewAccess(AWinControl)); LVN_ITEMCHANGING: begin - debugln('ListViewParentMsgHandler: LVN_ITEMCHANGING'); - MsgResult := LResult(-1); - //HandleListChanging(TCustomListViewAccess(AWinControl)); + //debugln('ListViewParentMsgHandler: LVN_ITEMCHANGING'); + //MsgResult := LResult(-1); + HandleListChanging(TCustomListViewAccess(AWinControl)); end; + //LVN_ITEMCHANGED: debugln('ListViewParentMsgHandler: LVN_ITEMCHANGed'); LVN_ODCACHEHINT: HandleListViewOwnerDataHint(TCustomListViewAccess(AWinControl)); end;