Cocoa/ListView: refactor checkIndex

This commit is contained in:
rich2014 2024-08-03 22:10:42 +08:00
parent 1ba49f1940
commit 06c6e6acc6
4 changed files with 18 additions and 38 deletions

View File

@ -156,7 +156,6 @@ type
// Item
procedure ItemDelete( const AIndex: Integer); override;
function ItemDisplayRect( const AIndex, ASubItem: Integer; ACode: TDisplayCode): TRect; override;
function ItemGetChecked( const AIndex: Integer; const {%H-}AItem: TListItem): Boolean; override;
function ItemGetPosition( const AIndex: Integer): TPoint; override;
function ItemGetState( const AIndex: Integer; const {%H-}AItem: TListItem; const AState: TListItemState; out AIsSet: Boolean): Boolean; override; // returns True if supported
procedure ItemInsert( const AIndex: Integer; const {%H-}AItem: TListItem); override;
@ -929,12 +928,6 @@ begin
Result:= NSRectToRect( frame );
end;
function TCocoaWSListView_CollectionViewHandler.ItemGetChecked(
const AIndex: Integer; const AItem: TListItem): Boolean;
begin
Result:= False;
end;
function TCocoaWSListView_CollectionViewHandler.ItemGetPosition(
const AIndex: Integer): TPoint;
var

View File

@ -71,7 +71,6 @@ type
// Item
procedure ItemDelete( const AIndex: Integer); virtual; abstract;
function ItemDisplayRect( const AIndex, ASubItem: Integer; ACode: TDisplayCode): TRect; virtual; abstract;
function ItemGetChecked( const AIndex: Integer; const {%H-}AItem: TListItem): Boolean; virtual; abstract;
function ItemGetPosition( const AIndex: Integer): TPoint; virtual; abstract;
function ItemGetState( const AIndex: Integer; const {%H-}AItem: TListItem; const AState: TListItemState; out AIsSet: Boolean): Boolean; virtual; abstract; // returns True if supported
procedure ItemInsert( const AIndex: Integer; const {%H-}AItem: TListItem); virtual; abstract;

View File

@ -240,7 +240,6 @@ type
// Item
procedure ItemDelete( const AIndex: Integer); override;
function ItemDisplayRect( const AIndex, ASubItem: Integer; ACode: TDisplayCode): TRect; override;
function ItemGetChecked( const AIndex: Integer; const {%H-}AItem: TListItem): Boolean; override;
function ItemGetPosition( const AIndex: Integer): TPoint; override;
function ItemGetState( const AIndex: Integer; const {%H-}AItem: TListItem; const AState: TListItemState; out AIsSet: Boolean): Boolean; override; // returns True if supported
procedure ItemInsert( const AIndex: Integer; const {%H-}AItem: TListItem); override;
@ -1749,19 +1748,6 @@ begin
end;
end;
function TCocoaWSListView_TableViewHandler.ItemGetChecked(
const AIndex: Integer; const AItem: TListItem): Boolean;
var
lclcb : TLCLListViewCallback;
begin
Result:= False;
lclcb:= getCallback;
if NOT Assigned(lclcb) then
Exit;
Result := lclcb.checkedIdx.containsIndex(AIndex);
end;
function TCocoaWSListView_TableViewHandler.ItemGetPosition(
const AIndex: Integer): TPoint;
var
@ -2005,19 +1991,7 @@ end;
procedure TCocoaWSListView_TableViewHandler.SetSort(const AType: TSortType;
const AColumn: Integer; const ASortDirection: TSortDirection);
var
lclcb: TLCLListViewCallback;
begin
lclcb:= getCallback;
if NOT Assigned(lclcb) then
Exit;
if TCocoaListView(lclcb.Owner).initializing then
Exit;
if Assigned(lclcb.checkedIdx) then
lclcb.checkedIdx.removeAllIndexes;
lclcb.selectionIndexSet.removeAllIndexes;
_tableView.reloadData();
{ //todo:
lNSColumn.setSortDescriptorPrototype(

View File

@ -317,12 +317,14 @@ class function TCocoaWSCustomListView.ItemGetChecked(
const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem
): Boolean;
var
WSHandler: TCocoaWSListViewHandler;
lclcb : TLCLListViewCallback;
begin
Result:= False;
WSHandler:= getWSHandler( ALV );
if Assigned(WSHandler) then
Result:= WSHandler.ItemGetChecked( AIndex, AItem );
lclcb:= getCallback( ALV );
if NOT Assigned(lclcb) then
Exit;
Result := lclcb.checkedIdx.containsIndex(AIndex);
end;
class function TCocoaWSCustomListView.ItemGetPosition(
@ -553,7 +555,19 @@ class procedure TCocoaWSCustomListView.SetSort(const ALV: TCustomListView;
const ASortDirection: TSortDirection);
var
WSHandler: TCocoaWSListViewHandler;
lclcb: TLCLListViewCallback;
begin
lclcb:= getCallback( ALV );
if NOT Assigned(lclcb) then
Exit;
if TCocoaListView(lclcb.Owner).initializing then
Exit;
if Assigned(lclcb.checkedIdx) then
lclcb.checkedIdx.removeAllIndexes;
lclcb.selectionIndexSet.removeAllIndexes;
WSHandler:= getWSHandler( ALV );
if Assigned(WSHandler) then
WSHandler.SetSort( AType, AColumn, ASortDirection );