Cocoa/ListView: add and fix macOS 10.11 APIs for NSCollectionView related

This commit is contained in:
rich2014 2024-07-15 22:36:06 +08:00
parent bf056effc4
commit ed64d28b68
2 changed files with 23 additions and 9 deletions

View File

@ -113,6 +113,14 @@ type
message 'setBackgroundColors:'; { available in 10_11 }
end;
NSCollectionViewLayoutAttributes = objcclass external (NSObject)
function frame: NSRect; message 'frame'; { available in 10_11 }
function size: NSSize; message 'size'; { available in 10_11 }
function alpha: CGFloat; message 'alpha'; { available in 10_11 }
function hidden: Boolean; message 'hidden'; { available in 10_11 }
function zIndex: NSInteger; message 'zIndex'; { available in 10_11 }
end;
NSCollectionViewDataSourceProtocol = objcprotocol external name 'NSCollectionViewDataSource'
function collectionView_numberOfItemsInSection(
collectionView: NSCollectionView; section: NSInteger ): NSInteger;
@ -186,6 +194,8 @@ type
function numberOfItemsInSection( section: NSInteger ): NSInteger;
message 'numberOfItemsInSection:'; { available in 10_11 }
function itemAtIndexPath( indexPath: NSIndexPath ): NSCollectionViewItem;
message 'itemAtIndexPath:'; { available in 10_11 }
function indexPathForItem( item:NSCollectionViewItem ): NSIndexPath;
message 'indexPathForItem:'; { available in 10_11 }
function indexPathForItemAtPoint( point: NSPoint ): NSIndexPath;
@ -200,6 +210,9 @@ type
message 'collectionViewLayout'; { available in 10_11 }
procedure setCollectionViewLayout( newValue: NSCollectionViewLayout );
message 'setCollectionViewLayout:'; { available in 10_11 }
function layoutAttributesForItemAtIndexPath(
indexPaht: NSIndexPath ): NSCollectionViewLayoutAttributes;
message 'layoutAttributesForItemAtIndexPath:'; { available in 10_11 }
function visibleItems: NSArray;
message 'visibleItems'; { available in 10_11 }
@ -216,6 +229,8 @@ type
function selectionIndexPaths: NSSet;
message 'selectionIndexPaths'; { available in 10_11 }
procedure setSelectionIndexPaths( newValue: NSSet );
message 'setSelectionIndexPaths:'; { available in 10_11 }
procedure selectItemsAtIndexPaths_scrollPosition(
indexPaths: NSSet; scrollPosition: NSCollectionViewScrollPosition );
message 'selectItemsAtIndexPaths:scrollPosition:'; { available in 10_11 }
@ -229,7 +244,10 @@ type
NSIndexPathFix = objccategory external (NSIndexPath)
function item: NSInteger; message 'item';
procedure setItem( newValue:NSInteger ); message 'setItem:';
function section: NSInteger; message 'section';
class function indexPathForItem_inSection(
item: NSInteger; section: NSInteger ): id;
message 'indexPathForItem:inSection:'; { available in 10_11 }
end;
const

View File

@ -124,11 +124,9 @@ end;
function indexPathsWithOneIndex( cv: NSCollectionView; AIndex: Integer ): NSSet;
var
item: NSCollectionViewItem;
indexPath: NSIndexPath;
begin
item:= cv.itemAtIndex( AIndex );
indexPath:= cv.indexPathForItem( item );
indexPath:= NSIndexPath.indexPathForItem_inSection( AIndex, 0 );
Result:= NSSet.setWithObject( indexPath );
end;
@ -283,12 +281,10 @@ end;
procedure TCocoaCollectionView.selectOneItemByIndex(
index: Integer; isSelected: Boolean );
var
item: NSCollectionViewItem;
indexPath: NSIndexPath;
indexPaths: NSSet;
begin
item:= self.itemAtIndex( index );
indexPath:= self.indexPathForItem( item );
indexPath:= NSIndexPath.indexPathForItem_inSection( index, 0 );
indexPaths:= NSSet.setWithObject( indexPath );
if isSelected then begin
@ -373,7 +369,7 @@ var
item: TCocoaCollectionItem;
begin
for indexPath in indexPaths do begin
item:= TCocoaCollectionItem( self.itemAtIndex(indexPath.item) );
item:= TCocoaCollectionItem( self.itemAtIndexPath(indexPath) );
item.setSelected( True );
item.textField.setToolTip( item.textField.stringValue );
item.view.setNeedsDisplay_(True);
@ -394,7 +390,7 @@ var
item: TCocoaCollectionItem;
begin
for indexPath in indexPaths do begin
item:= TCocoaCollectionItem( self.itemAtIndex(indexPath.item) );
item:= TCocoaCollectionItem( self.itemAtIndexPath(indexPath) );
item.setSelected( False );
item.textField.setToolTip( nil );
item.view.setNeedsDisplay_(True);