Cocoa/ListView: fix the issue that checkBox may be reset after sorting

This commit is contained in:
rich2014 2024-08-04 22:28:31 +08:00
parent 210f0fac8a
commit 9aee14430e
3 changed files with 31 additions and 29 deletions

View File

@ -1171,20 +1171,8 @@ end;
procedure TCocoaWSListView_CollectionViewHandler.ItemSetChecked(
const AIndex: Integer; const AItem: TListItem; const AChecked: Boolean);
var
lclcb: TLCLListViewCallback;
begin
lclcb:= getCallback;
if NOT Assigned(lclcb) then
Exit;
if AChecked and not lclcb.checkedIdx.containsIndex(AIndex) then begin
lclcb.checkedIdx.addIndex(AIndex);
_collectionView.reloadData;
end else if not AChecked and lclcb.checkedIdx.containsIndex(AIndex) then begin
lclcb.checkedIdx.removeIndex(AIndex);
_collectionView.reloadData;
end;
_collectionView.reloadData;
end;
procedure TCocoaWSListView_CollectionViewHandler.ItemSetImage(

View File

@ -1792,20 +1792,8 @@ end;
procedure TCocoaWSListView_TableViewHandler.ItemSetChecked(
const AIndex: Integer; const AItem: TListItem; const AChecked: Boolean);
var
lclcb: TLCLListViewCallback;
begin
lclcb:= getCallback;
if NOT Assigned(lclcb) then
Exit;
if AChecked and not lclcb.checkedIdx.containsIndex(AIndex) then begin
lclcb.checkedIdx.addIndex(AIndex);
_tableView.reloadDataForRow_column(AIndex, 0);
end else if not AChecked and lclcb.checkedIdx.containsIndex(AIndex) then begin
lclcb.checkedIdx.removeIndex(AIndex);
_tableView.reloadDataForRow_column(AIndex, 0);
end;
_tableView.reloadDataForRow_column(AIndex, 0);
end;
procedure TCocoaWSListView_TableViewHandler.ItemSetImage(

View File

@ -17,6 +17,8 @@ type
{ TCocoaWSCustomListView }
TCocoaWSCustomListView = class(TWSCustomListView)
private
class var _settingLCLDirectly: Boolean;
private
class function getWSHandler( const lclListView: TCustomListView ):
TCocoaWSListViewHandler;
@ -365,10 +367,34 @@ class procedure TCocoaWSCustomListView.ItemSetChecked(
const AChecked: Boolean);
var
WSHandler: TCocoaWSListViewHandler;
lclcb: TLCLListViewCallback;
cocoaListView: TCocoaListView;
needsUpdate: Boolean = False;
begin
WSHandler:= getWSHandler( ALV );
if Assigned(WSHandler) then
WSHandler.ItemSetChecked( AIndex, AItem, AChecked );
if _settingLCLDirectly then
Exit;
lclcb:= self.getCallback( ALV );
if NOT Assigned(lclcb) then
Exit;
if AChecked and not lclcb.checkedIdx.containsIndex(AIndex) then begin
lclcb.checkedIdx.addIndex(AIndex);
needsUpdate:= True;
end else if not AChecked and lclcb.checkedIdx.containsIndex(AIndex) then begin
lclcb.checkedIdx.removeIndex(AIndex);
needsUpdate:= True;
end;
if needsUpdate then begin
WSHandler:= getWSHandler( ALV );
if Assigned(WSHandler) then
WSHandler.ItemSetChecked( AIndex, AItem, AChecked );
end;
_settingLCLDirectly:= True;
AItem.Checked:= AChecked;
_settingLCLDirectly:= False;
end;
class procedure TCocoaWSCustomListView.ItemSetImage(const ALV: TCustomListView;