mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 03:11:18 +00:00
Switch to using maptables to track some metadata bout items so that we can match items up when we need to find them by indexPath or point. Remove uneeded ivar from layout. Add call to delegate when selecting item
This commit is contained in:
parent
bf3ddc8cad
commit
2bec53bf0f
4 changed files with 27 additions and 12 deletions
|
@ -443,12 +443,12 @@ APPKIT_EXPORT_CLASS
|
|||
NSMutableSet *_indexPathsForVisibleItems;
|
||||
NSMutableDictionary *_visibleSupplementaryViews;
|
||||
NSMutableSet *_indexPathsForSupplementaryElementsOfKind;
|
||||
NSMutableDictionary *_itemsToAttributes;
|
||||
|
||||
// Private
|
||||
// Map items -> indexPath
|
||||
NSMapTable *_itemsToIndexPaths;
|
||||
NSMapTable *_indexPathsToItems;
|
||||
NSMapTable *_itemsToAttributes;
|
||||
|
||||
// Registered class/nib for item identifier
|
||||
NSMapTable *_registeredNibs;
|
||||
|
|
|
@ -162,7 +162,6 @@ typedef NSInteger NSCollectionUpdateAction;
|
|||
{
|
||||
NSCollectionView *_collectionView; // weak
|
||||
BOOL _valid;
|
||||
NSMutableDictionary *_itemsToAttributes;
|
||||
|
||||
Class _layoutAttributesClass;
|
||||
Class _invalidationContextClass;
|
||||
|
|
|
@ -162,9 +162,9 @@ static NSString *placeholderItem = nil;
|
|||
_indexPathsForVisibleItems = [[NSMutableSet alloc] init];
|
||||
_visibleSupplementaryViews = [[NSMutableDictionary alloc] init];
|
||||
_indexPathsForSupplementaryElementsOfKind = [[NSMutableSet alloc] init];
|
||||
_itemsToAttributes = [[NSMutableDictionary alloc] init];
|
||||
_itemsToIndexPaths = RETAIN([NSMapTable weakToWeakObjectsMapTable]);
|
||||
_indexPathsToItems = RETAIN([NSMapTable weakToWeakObjectsMapTable]);
|
||||
_itemsToAttributes = RETAIN([NSMapTable strongToStrongObjectsMapTable]);
|
||||
_itemsToIndexPaths = RETAIN([NSMapTable strongToStrongObjectsMapTable]);
|
||||
_indexPathsToItems = RETAIN([NSMapTable strongToStrongObjectsMapTable]);
|
||||
|
||||
// Registered nib/class
|
||||
_registeredNibs = RETAIN([NSMapTable weakToStrongObjectsMapTable]);
|
||||
|
@ -1418,9 +1418,25 @@ static NSString *placeholderItem = nil;
|
|||
|
||||
- (NSIndexPath *) indexPathForItemAtPoint: (NSPoint)point
|
||||
{
|
||||
NSInteger row = floor(point.y / (_itemSize.height + _verticalMargin));
|
||||
NSInteger column = floor(point.x / (_itemSize.width + _horizontalMargin));
|
||||
NSIndexPath *p = [NSIndexPath indexPathForRow: row inSection: column];
|
||||
NSIndexPath *p = nil;
|
||||
NSEnumerator *ke = [_itemsToAttributes keyEnumerator];
|
||||
NSCollectionViewItem *item = nil;
|
||||
|
||||
while ((item = [ke nextObject]) != nil)
|
||||
{
|
||||
NSCollectionViewLayoutAttributes *attr = [_itemsToAttributes objectForKey: item];
|
||||
|
||||
if (attr != nil)
|
||||
{
|
||||
NSRect f = [attr frame];
|
||||
|
||||
if (NSPointInRect(point, f))
|
||||
{
|
||||
p = [self indexPathForItem: item];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
|
|
@ -28,11 +28,11 @@
|
|||
#import "GSFastEnumeration.h"
|
||||
|
||||
@interface NSCollectionView (__NSCollectionViewLayout__)
|
||||
- (NSDictionary *) itemsToAttributes;
|
||||
- (NSMapTable *) itemsToAttributes;
|
||||
@end
|
||||
|
||||
@implementation NSCollectionView (__NSCollectionViewLayout__)
|
||||
- (NSDictionary *) itemsToAttributes
|
||||
- (NSMapTable *) itemsToAttributes
|
||||
{
|
||||
return _itemsToAttributes;
|
||||
}
|
||||
|
@ -249,7 +249,7 @@
|
|||
// Initializers
|
||||
- (void) _initDefaults
|
||||
{
|
||||
_itemsToAttributes = [[NSMutableDictionary alloc] init];
|
||||
// _itemsToAttributes = [[NSMutableDictionary alloc] init];
|
||||
}
|
||||
|
||||
- (void)invalidateLayout
|
||||
|
@ -311,7 +311,7 @@
|
|||
{
|
||||
NSMutableArray *result = [NSMutableArray array];
|
||||
NSArray *items = [_collectionView visibleItems];
|
||||
NSDictionary *itemsToAttributes = [_collectionView itemsToAttributes];
|
||||
NSMapTable *itemsToAttributes = [_collectionView itemsToAttributes];
|
||||
|
||||
FOR_IN(NSCollectionViewItem*, i, items)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue