* Source/NSTableView.m (-selectedColumnIndexes,

* -selectedRowIndexes): Return an
        autoreleased copy of the corresponding ivar. Returning a
reference to the ivar
        leads to issues (and behavior different from Cocoa) when
iterating thru the
        indexsets if at a time they would be being altered.
        Patch by Frank LeGrand (flegrand@testplant.com).
        * Source/GNUmakefile: Add NSCollectionViewItem.
        * Headers/AppKit/NSCollectionView.h,
        * Headers/AppKit/NSCollectionViewItem.h,
        * Source/NSCollectionViewItem.m,
        * Source/NSCollectionView.m: Bring closer to the GNUstep coding
        * standard.



git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@36551 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
fredkiefer 2013-04-21 13:28:47 +00:00
parent 06c706a7c8
commit ab56e573e7
7 changed files with 336 additions and 382 deletions

View file

@ -1,3 +1,16 @@
2013-04-21 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSTableView.m (-selectedColumnIndexes, -selectedRowIndexes): Return an
autoreleased copy of the corresponding ivar. Returning a reference to the ivar
leads to issues (and behavior different from Cocoa) when iterating thru the
indexsets if at a time they would be being altered.
Patch by Frank LeGrand (flegrand@testplant.com).
* Source/GNUmakefile: Add NSCollectionViewItem.
* Headers/AppKit/NSCollectionView.h,
* Headers/AppKit/NSCollectionViewItem.h,
* Source/NSCollectionViewItem.m,
* Source/NSCollectionView.m: Bring closer to the GNUstep coding standard.
2013-04-17 23:54-EDT Gregory John Casamento <greg.casamento@gmail.com> 2013-04-17 23:54-EDT Gregory John Casamento <greg.casamento@gmail.com>
* Headers/AppKit/NSCollectionView.h * Headers/AppKit/NSCollectionView.h

View file

@ -29,11 +29,11 @@
#ifndef _GNUstep_H_NSCollectionView #ifndef _GNUstep_H_NSCollectionView
#define _GNUstep_H_NSCollectionView #define _GNUstep_H_NSCollectionView
#import <AppKit/NSNibDeclarations.h>
#import <GNUstepBase/GSVersionMacros.h> #import <GNUstepBase/GSVersionMacros.h>
#import <AppKit/NSView.h>
#import <AppKit/NSDragging.h> #import <AppKit/NSDragging.h>
#import <AppKit/NSNibDeclarations.h>
#import <AppKit/NSView.h>
@class NSCollectionViewItem; @class NSCollectionViewItem;
@class NSCollectionView; @class NSCollectionView;
@ -47,17 +47,32 @@ typedef NSInteger NSCollectionViewDropOperation;
@protocol NSCollectionViewDelegate <NSObject> @protocol NSCollectionViewDelegate <NSObject>
- (NSImage *)collectionView:(NSCollectionView *)collectionView draggingImageForItemsAtIndexes:(NSIndexSet *)indexes withEvent:(NSEvent *)event offset:(NSPointPointer)dragImageOffset; - (NSImage *)collectionView:(NSCollectionView *)collectionView
- (BOOL)collectionView:(NSCollectionView *)collectionView writeItemsAtIndexes:(NSIndexSet *)indexes toPasteboard:(NSPasteboard *)pasteboard; draggingImageForItemsAtIndexes:(NSIndexSet *)indexes
- (BOOL)collectionView:(NSCollectionView *)collectionView canDragItemsAtIndexes:(NSIndexSet *)indexes withEvent:(NSEvent *)event; withEvent:(NSEvent *)event
- (NSDragOperation)collectionView:(NSCollectionView *)collectionView validateDrop:(id < NSDraggingInfo >)draggingInfo proposedIndex:(NSInteger *)proposedDropIndex dropOperation:(NSCollectionViewDropOperation *)proposedDropOperation; offset:(NSPointPointer)dragImageOffset;
- (BOOL)collectionView:(NSCollectionView *)collectionView acceptDrop:(id < NSDraggingInfo >)draggingInfo index:(NSInteger)index dropOperation:(NSCollectionViewDropOperation)dropOperation; - (BOOL)collectionView:(NSCollectionView *)collectionView
- (NSArray *)collectionView:(NSCollectionView *)collectionView namesOfPromisedFilesDroppedAtDestination:(NSURL *)dropURL forDraggedItemsAtIndexes:(NSIndexSet *)indexes; writeItemsAtIndexes:(NSIndexSet *)indexes
toPasteboard:(NSPasteboard *)pasteboard;
- (BOOL)collectionView:(NSCollectionView *)collectionView
canDragItemsAtIndexes:(NSIndexSet *)indexes
withEvent:(NSEvent *)event;
- (NSDragOperation)collectionView:(NSCollectionView *)collectionView
validateDrop:(id < NSDraggingInfo >)draggingInfo
proposedIndex:(NSInteger *)proposedDropIndex
dropOperation:(NSCollectionViewDropOperation *)proposedDropOperation;
- (BOOL)collectionView:(NSCollectionView *)collectionView
acceptDrop:(id < NSDraggingInfo >)draggingInfo
index:(NSInteger)index
dropOperation:(NSCollectionViewDropOperation)dropOperation;
- (NSArray *)collectionView:(NSCollectionView *)collectionView
namesOfPromisedFilesDroppedAtDestination:(NSURL *)dropURL
forDraggedItemsAtIndexes:(NSIndexSet *)indexes;
@end @end
@interface NSCollectionView : NSView @interface NSCollectionView : NSView //<NSDraggingDestination, NSDraggingSource>
{ {
NSArray *_content; NSArray *_content;
IBOutlet NSCollectionViewItem *itemPrototype; IBOutlet NSCollectionViewItem *itemPrototype;
@ -73,13 +88,13 @@ typedef NSInteger NSCollectionViewDropOperation;
NSSize _itemSize; NSSize _itemSize;
NSSize _maxItemSize; NSSize _maxItemSize;
NSSize _minItemSize; NSSize _minItemSize;
float _tileWidth; CGFloat _tileWidth;
float _verticalMargin; CGFloat _verticalMargin;
float _horizontalMargin; CGFloat _horizontalMargin;
NSUInteger _maxNumberOfColumns; NSUInteger _maxNumberOfColumns;
NSUInteger _maxNumberOfRows; NSUInteger _maxNumberOfRows;
long _numberOfColumns; NSUInteger _numberOfColumns;
NSDragOperation _draggingSourceOperationMaskForLocal; NSDragOperation _draggingSourceOperationMaskForLocal;
NSDragOperation _draggingSourceOperationMaskForRemote; NSDragOperation _draggingSourceOperationMaskForRemote;

View file

@ -29,14 +29,16 @@
#ifndef _GNUstep_H_NSCollectionViewItem #ifndef _GNUstep_H_NSCollectionViewItem
#define _GNUstep_H_NSCollectionViewItem #define _GNUstep_H_NSCollectionViewItem
#import <AppKit/NSNibDeclarations.h>
#import <GNUstepBase/GSVersionMacros.h> #import <GNUstepBase/GSVersionMacros.h>
#import <AppKit/NSTextField.h> #import <Foundation/NSArray.h>
#import <AppKit/NSImageView.h>
#import <AppKit/NSView.h>
#import <AppKit/NSViewController.h>
#import <AppKit/NSCollectionView.h> #import <AppKit/NSCollectionView.h>
#import <AppKit/NSDragging.h> #import <AppKit/NSDragging.h>
#import <AppKit/NSImageView.h>
#import <AppKit/NSNibDeclarations.h>
#import <AppKit/NSTextField.h>
#import <AppKit/NSView.h>
#import <AppKit/NSViewController.h>
@interface NSCollectionViewItem : NSViewController @interface NSCollectionViewItem : NSViewController
@ -47,13 +49,15 @@
} }
- (NSCollectionView *)collectionView; - (NSCollectionView *)collectionView;
- (NSArray *)draggingImageComponents;
- (void)setSelected:(BOOL)shouldBeSelected; - (void)setSelected:(BOOL)shouldBeSelected;
- (BOOL)isSelected; - (BOOL)isSelected;
- (NSTextField *)textField; - (NSTextField *)textField;
- (NSImageView *)imageView;
- (void)setTextField:(NSTextField *)aTextField; - (void)setTextField:(NSTextField *)aTextField;
- (NSImageView *)imageView;
- (void)setImageView:(NSImageView *)anImageView; - (void)setImageView:(NSImageView *)anImageView;
@end @end

View file

@ -68,6 +68,7 @@ NSCachedImageRep.m \
NSCell.m \ NSCell.m \
NSClipView.m \ NSClipView.m \
NSCollectionView.m \ NSCollectionView.m \
NSCollectionViewItem.m \
NSColor.m \ NSColor.m \
NSColorList.m \ NSColorList.m \
NSColorPanel.m \ NSColorPanel.m \
@ -280,6 +281,7 @@ NSCachedImageRep.h \
NSCell.h \ NSCell.h \
NSClipView.h \ NSClipView.h \
NSCollectionView.h \ NSCollectionView.h \
NSCollectionViewItem.h \
NSColor.h \ NSColor.h \
NSColorList.h \ NSColorList.h \
NSColorPanel.h \ NSColorPanel.h \

View file

@ -25,61 +25,23 @@
Boston, MA 02110-1301, USA. Boston, MA 02110-1301, USA.
*/ */
#import "AppKit/NSCollectionView.h"
#import "AppKit/NSCollectionViewItem.h"
#import "Foundation/NSKeyedArchiver.h" #import "Foundation/NSKeyedArchiver.h"
#import <Foundation/NSGeometry.h> #import <Foundation/NSGeometry.h>
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSDebug.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSEnumerator.h>
#import <Foundation/NSException.h>
#import <Foundation/NSFormatter.h>
#import <Foundation/NSIndexSet.h> #import <Foundation/NSIndexSet.h>
#import <Foundation/NSKeyValueCoding.h>
#import <Foundation/NSNotification.h>
#import <Foundation/NSSet.h>
#import <Foundation/NSSortDescriptor.h>
#import <Foundation/NSUserDefaults.h>
#import <Foundation/NSValue.h>
#import <Foundation/NSKeyedArchiver.h> #import <Foundation/NSKeyedArchiver.h>
#import <Foundation/NSTimer.h>
#import "AppKit/NSView.h"
#import "AppKit/NSAnimation.h"
#import "AppKit/NSNibLoading.h"
#import "AppKit/NSTableView.h"
#import "AppKit/NSApplication.h" #import "AppKit/NSApplication.h"
#import "AppKit/NSCell.h"
#import "AppKit/NSClipView.h" #import "AppKit/NSClipView.h"
#import "AppKit/NSColor.h" #import "AppKit/NSCollectionView.h"
#import "AppKit/NSCollectionViewItem.h"
#import "AppKit/NSEvent.h" #import "AppKit/NSEvent.h"
#import "AppKit/NSImage.h"
#import "AppKit/NSGraphics.h" #import "AppKit/NSGraphics.h"
#import "AppKit/NSKeyValueBinding.h" #import "AppKit/NSImage.h"
#import "AppKit/NSScroller.h"
#import "AppKit/NSScrollView.h"
#import "AppKit/NSTableColumn.h"
#import "AppKit/NSTableHeaderView.h"
#import "AppKit/NSText.h"
#import "AppKit/NSTextFieldCell.h"
#import "AppKit/NSWindow.h"
#import "AppKit/PSOperators.h"
#import "AppKit/NSCachedImageRep.h"
#import "AppKit/NSPasteboard.h" #import "AppKit/NSPasteboard.h"
#import "AppKit/NSDragging.h" #import "AppKit/NSWindow.h"
#import "AppKit/NSCustomImageRep.h"
#import "AppKit/NSAttributedString.h"
#import "AppKit/NSStringDrawing.h"
#import "GNUstepGUI/GSTheme.h"
#import "GSBindingHelpers.h"
#include <math.h> #include <math.h>
static NSString* NSCollectionViewMinItemSizeKey = @"NSMinGridSize"; static NSString* NSCollectionViewMinItemSizeKey = @"NSMinGridSize";
static NSString* NSCollectionViewMaxItemSizeKey = @"NSMaxGridSize"; static NSString* NSCollectionViewMaxItemSizeKey = @"NSMaxGridSize";
//static NSString* NSCollectionViewVerticalMarginKey = @"NSCollectionViewVerticalMarginKey"; //static NSString* NSCollectionViewVerticalMarginKey = @"NSCollectionViewVerticalMarginKey";
@ -104,7 +66,7 @@ static NSString *placeholderItem = nil;
- (NSRect) _frameForRowOfItemAtIndex: (NSUInteger)theIndex; - (NSRect) _frameForRowOfItemAtIndex: (NSUInteger)theIndex;
- (NSRect) _frameForRowsAroundItemAtIndex: (NSUInteger)theIndex; - (NSRect) _frameForRowsAroundItemAtIndex: (NSUInteger)theIndex;
- (void) _modifySelectionWithNewIndex: (int)anIndex - (void) _modifySelectionWithNewIndex: (NSUInteger)anIndex
direction: (int)aDirection direction: (int)aDirection
expand: (BOOL)shouldExpand; expand: (BOOL)shouldExpand;
@ -190,9 +152,9 @@ static NSString *placeholderItem = nil;
NSInteger firstIndexInRect = MAX(0, [self _indexAtPoint: origin]); NSInteger firstIndexInRect = MAX(0, [self _indexAtPoint: origin]);
NSInteger lastIndexInRect = MIN([_items count] - 1, [self _indexAtPoint: oppositeOrigin]); NSInteger lastIndexInRect = MIN([_items count] - 1, [self _indexAtPoint: oppositeOrigin]);
NSInteger index = firstIndexInRect; NSInteger index;
for (; index <= lastIndexInRect; index++) for (index = firstIndexInRect; index <= lastIndexInRect; index++)
{ {
// Calling itemAtIndex: will eventually instantiate the collection view item, // Calling itemAtIndex: will eventually instantiate the collection view item,
// if it hasn't been done already. // if it hasn't been done already.
@ -251,14 +213,14 @@ static NSString *placeholderItem = nil;
- (void) setContent: (NSArray *)content - (void) setContent: (NSArray *)content
{ {
RELEASE (_content); NSInteger i;
_content = [content retain];
ASSIGN(_content, content);
[self _removeItemsViews]; [self _removeItemsViews];
RELEASE (_items); RELEASE (_items);
_items = [[NSMutableArray alloc] initWithCapacity: [_content count]]; _items = [[NSMutableArray alloc] initWithCapacity: [_content count]];
NSInteger i;
for (i = 0; i < [_content count]; i++) for (i = 0; i < [_content count]; i++)
{ {
[_items addObject: placeholderItem]; [_items addObject: placeholderItem];
@ -272,7 +234,7 @@ static NSString *placeholderItem = nil;
{ {
// Force recalculation of each item's frame // Force recalculation of each item's frame
_itemSize = _minItemSize; _itemSize = _minItemSize;
_tileWidth = -1; _tileWidth = -1.0;
[self tile]; [self tile];
} }
} }
@ -294,11 +256,7 @@ static NSString *placeholderItem = nil;
- (void) setItemPrototype: (NSCollectionViewItem *)prototype - (void) setItemPrototype: (NSCollectionViewItem *)prototype
{ {
ASSIGN(itemPrototype, prototype); ASSIGN(itemPrototype, prototype);
// RELEASE (itemPrototype);
// itemPrototype = prototype;
// RETAIN (itemPrototype);
[self _resetItemSize]; [self _resetItemSize];
} }
@ -401,9 +359,6 @@ static NSString *placeholderItem = nil;
if (![_selectionIndexes isEqual: indexes]) if (![_selectionIndexes isEqual: indexes])
{ {
ASSIGN(_selectionIndexes, indexes); ASSIGN(_selectionIndexes, indexes);
// RELEASE(_selectionIndexes);
// _selectionIndexes = indexes;
// RETAIN(_selectionIndexes);
} }
NSUInteger index = 0; NSUInteger index = 0;
@ -432,16 +387,17 @@ static NSString *placeholderItem = nil;
- (NSRect) frameForItemAtIndex: (NSUInteger)theIndex - (NSRect) frameForItemAtIndex: (NSUInteger)theIndex
{ {
NSRect itemFrame = NSMakeRect (0,0,0,0); NSRect itemFrame = NSMakeRect (0,0,0,0);
NSInteger index = 0; NSInteger index;
long count = (long)[_items count]; NSUInteger count = [_items count];
if (_maxNumberOfColumns > 0 && _maxNumberOfRows > 0)
count = MIN(count, _maxNumberOfColumns * _maxNumberOfRows);
CGFloat x = _horizontalMargin; CGFloat x = _horizontalMargin;
CGFloat y = -_itemSize.height; CGFloat y = -_itemSize.height;
for (; index < count; ++index) if (_maxNumberOfColumns > 0 && _maxNumberOfRows > 0)
{
count = MIN(count, _maxNumberOfColumns * _maxNumberOfRows);
}
for (index = 0; index < count; ++index)
{ {
if (index % _numberOfColumns == 0) if (index % _numberOfColumns == 0)
{ {
@ -452,10 +408,12 @@ static NSString *placeholderItem = nil;
if (index == theIndex) if (index == theIndex)
{ {
NSInteger draggingOffset = 0; NSInteger draggingOffset = 0;
if (_draggingOnIndex != NSNotFound) if (_draggingOnIndex != NSNotFound)
{ {
NSInteger draggingOnRow = (_draggingOnIndex / _numberOfColumns); NSInteger draggingOnRow = (_draggingOnIndex / _numberOfColumns);
NSInteger currentIndexRow = (theIndex / _numberOfColumns); NSInteger currentIndexRow = (theIndex / _numberOfColumns);
if (draggingOnRow == currentIndexRow) if (draggingOnRow == currentIndexRow)
{ {
if (index < _draggingOnIndex) if (index < _draggingOnIndex)
@ -480,9 +438,8 @@ static NSString *placeholderItem = nil;
- (NSRect) _frameForRowOfItemAtIndex: (NSUInteger)theIndex - (NSRect) _frameForRowOfItemAtIndex: (NSUInteger)theIndex
{ {
NSRect itemFrame = [self frameForItemAtIndex: theIndex]; NSRect itemFrame = [self frameForItemAtIndex: theIndex];
NSPoint origin = NSMakePoint (0, itemFrame.origin.y);
NSSize size = NSMakeSize([self bounds].size.width, itemFrame.size.height); return NSMakeRect (0, itemFrame.origin.y, [self bounds].size.width, itemFrame.size.height);
return NSMakeRect (origin.x, origin.y, size.width, size.height);
} }
// Returns the frame of an item's row with the row above and the row below // Returns the frame of an item's row with the row above and the row below
@ -491,13 +448,14 @@ static NSString *placeholderItem = nil;
NSRect itemRowFrame = [self _frameForRowOfItemAtIndex: theIndex]; NSRect itemRowFrame = [self _frameForRowOfItemAtIndex: theIndex];
CGFloat y = MAX (0, itemRowFrame.origin.y - itemRowFrame.size.height); CGFloat y = MAX (0, itemRowFrame.origin.y - itemRowFrame.size.height);
CGFloat height = MIN (itemRowFrame.size.height * 3, [self bounds].size.height); CGFloat height = MIN (itemRowFrame.size.height * 3, [self bounds].size.height);
NSRect rowsRect = NSMakeRect(0, y, itemRowFrame.size.width, height);
return rowsRect; return NSMakeRect(0, y, itemRowFrame.size.width, height);
} }
- (NSCollectionViewItem *) itemAtIndex: (NSUInteger)index - (NSCollectionViewItem *) itemAtIndex: (NSUInteger)index
{ {
id item = [_items objectAtIndex: index]; id item = [_items objectAtIndex: index];
if (item == placeholderItem) if (item == placeholderItem)
{ {
item = [self newItemForRepresentedObject: [_content objectAtIndex: index]]; item = [self newItemForRepresentedObject: [_content objectAtIndex: index]];
@ -527,14 +485,16 @@ static NSString *placeholderItem = nil;
if (!_items) if (!_items)
return; return;
long count = [_items count]; NSUInteger count = [_items count];
while (count--) while (count--)
{ {
if ([[_items objectAtIndex:count] respondsToSelector:@selector(view)]) id item = [_items objectAtIndex: count];
if ([item respondsToSelector: @selector(view)])
{ {
[[[_items objectAtIndex:count] view] removeFromSuperview]; [[item view] removeFromSuperview];
[[_items objectAtIndex:count] setSelected:NO]; [item setSelected: NO];
} }
} }
} }
@ -561,7 +521,6 @@ static NSString *placeholderItem = nil;
} }
CGFloat remaining = width - _numberOfColumns * itemSize.width; CGFloat remaining = width - _numberOfColumns * itemSize.width;
BOOL itemsNeedSizeUpdate = NO;
if (remaining > 0 && itemSize.width < _maxItemSize.width) if (remaining > 0 && itemSize.width < _maxItemSize.width)
{ {
@ -578,11 +537,10 @@ static NSString *placeholderItem = nil;
if (!NSEqualSizes(_itemSize, itemSize)) if (!NSEqualSizes(_itemSize, itemSize))
{ {
_itemSize = itemSize; _itemSize = itemSize;
itemsNeedSizeUpdate = YES;
} }
NSInteger index = 0; NSInteger index;
long count = (long)[_items count]; NSUInteger count = [_items count];
if (_maxNumberOfColumns > 0 && _maxNumberOfRows > 0) if (_maxNumberOfColumns > 0 && _maxNumberOfRows > 0)
{ {
@ -593,7 +551,7 @@ static NSString *placeholderItem = nil;
(_numberOfColumns + 1)); (_numberOfColumns + 1));
CGFloat y = -itemSize.height; CGFloat y = -itemSize.height;
for (; index < count; ++index) for (index = 0; index < count; ++index)
{ {
if (index % _numberOfColumns == 0) if (index % _numberOfColumns == 0)
{ {
@ -631,10 +589,8 @@ static NSString *placeholderItem = nil;
{ {
if ([aCoder allowsKeyedCoding]) if ([aCoder allowsKeyedCoding])
{ {
_items = [NSMutableArray array];
_content = [NSArray array];
_itemSize = NSMakeSize(0, 0); _itemSize = NSMakeSize(0, 0);
_tileWidth = -1.0;
_minItemSize = [aCoder decodeSizeForKey: NSCollectionViewMinItemSizeKey]; _minItemSize = [aCoder decodeSizeForKey: NSCollectionViewMinItemSizeKey];
_maxItemSize = [aCoder decodeSizeForKey: NSCollectionViewMaxItemSizeKey]; _maxItemSize = [aCoder decodeSizeForKey: NSCollectionViewMaxItemSizeKey];
@ -648,10 +604,6 @@ static NSString *placeholderItem = nil;
_allowsMultipleSelection = [aCoder decodeBoolForKey: NSCollectionViewAllowsMultipleSelectionKey]; _allowsMultipleSelection = [aCoder decodeBoolForKey: NSCollectionViewAllowsMultipleSelectionKey];
[self setBackgroundColors: [aCoder decodeObjectForKey: NSCollectionViewBackgroundColorsKey]]; [self setBackgroundColors: [aCoder decodeObjectForKey: NSCollectionViewBackgroundColorsKey]];
_tileWidth = -1.0;
_selectionIndexes = [NSIndexSet indexSet];
} }
else else
{ {
@ -703,7 +655,6 @@ static NSString *placeholderItem = nil;
NSInteger index = [self _indexAtPoint: location]; NSInteger index = [self _indexAtPoint: location];
NSEvent *lastEvent = theEvent; NSEvent *lastEvent = theEvent;
BOOL done = NO; BOOL done = NO;
NSUInteger eventMask = (NSLeftMouseUpMask NSUInteger eventMask = (NSLeftMouseUpMask
| NSLeftMouseDownMask | NSLeftMouseDownMask
| NSLeftMouseDraggedMask | NSLeftMouseDraggedMask
@ -750,8 +701,8 @@ static NSString *placeholderItem = nil;
if (_isSelectable && (index < [_items count])) if (_isSelectable && (index < [_items count]))
{ {
if (_allowsMultipleSelection if (_allowsMultipleSelection
&& (([theEvent modifierFlags] & NSControlKeyMask) || ([theEvent modifierFlags] & NSShiftKeyMask))) && (([theEvent modifierFlags] & NSControlKeyMask)
|| ([theEvent modifierFlags] & NSShiftKeyMask)))
{ {
if ([theEvent modifierFlags] & NSControlKeyMask) if ([theEvent modifierFlags] & NSControlKeyMask)
{ {
@ -767,7 +718,7 @@ static NSString *placeholderItem = nil;
} }
else if ([theEvent modifierFlags] & NSShiftKeyMask) else if ([theEvent modifierFlags] & NSShiftKeyMask)
{ {
long firstSelectedIndex = [currentIndexSet firstIndex]; NSUInteger firstSelectedIndex = [currentIndexSet firstIndex];
NSRange selectedRange; NSRange selectedRange;
if (firstSelectedIndex == NSNotFound) if (firstSelectedIndex == NSNotFound)
@ -791,8 +742,6 @@ static NSString *placeholderItem = nil;
[self setSelectionIndexes: [NSIndexSet indexSetWithIndex: index]]; [self setSelectionIndexes: [NSIndexSet indexSetWithIndex: index]];
} }
[[self window] makeFirstResponder: self]; [[self window] makeFirstResponder: self];
} }
else else
{ {
@ -879,7 +828,7 @@ static NSString *placeholderItem = nil;
-(void) _moveLeftAndExpandSelection: (BOOL)shouldExpand -(void) _moveLeftAndExpandSelection: (BOOL)shouldExpand
{ {
NSInteger index = [[self selectionIndexes] firstIndex]; NSUInteger index = [[self selectionIndexes] firstIndex];
if (index != NSNotFound && index != 0) if (index != NSNotFound && index != 0)
{ {
[self _modifySelectionWithNewIndex: index - 1 direction: -1 expand: shouldExpand]; [self _modifySelectionWithNewIndex: index - 1 direction: -1 expand: shouldExpand];
@ -903,14 +852,14 @@ static NSString *placeholderItem = nil;
-(void) _moveRightAndExpandSelection: (BOOL)shouldExpand -(void) _moveRightAndExpandSelection: (BOOL)shouldExpand
{ {
NSInteger index = [[self selectionIndexes] lastIndex]; NSUInteger index = [[self selectionIndexes] lastIndex];
if (index != NSNotFound && index != ([_items count] - 1)) if (index != NSNotFound && index != ([_items count] - 1))
{ {
[self _modifySelectionWithNewIndex: index + 1 direction: 1 expand: shouldExpand]; [self _modifySelectionWithNewIndex: index + 1 direction: 1 expand: shouldExpand];
} }
} }
- (void) _modifySelectionWithNewIndex: (int)anIndex - (void) _modifySelectionWithNewIndex: (NSUInteger)anIndex
direction: (int)aDirection direction: (int)aDirection
expand: (BOOL)shouldExpand expand: (BOOL)shouldExpand
{ {
@ -919,8 +868,8 @@ static NSString *placeholderItem = nil;
if (_allowsMultipleSelection && shouldExpand) if (_allowsMultipleSelection && shouldExpand)
{ {
NSMutableIndexSet *newIndexSet = [[NSMutableIndexSet alloc] initWithIndexSet: _selectionIndexes]; NSMutableIndexSet *newIndexSet = [[NSMutableIndexSet alloc] initWithIndexSet: _selectionIndexes];
NSInteger firstIndex = [newIndexSet firstIndex]; NSUInteger firstIndex = [newIndexSet firstIndex];
NSInteger lastIndex = [newIndexSet lastIndex]; NSUInteger lastIndex = [newIndexSet lastIndex];
if (aDirection == -1) if (aDirection == -1)
{ {
[newIndexSet addIndexesInRange:NSMakeRange (anIndex, firstIndex - anIndex + 1)]; [newIndexSet addIndexesInRange:NSMakeRange (anIndex, firstIndex - anIndex + 1)];
@ -972,6 +921,7 @@ static NSString *placeholderItem = nil;
clickedIndex: (NSUInteger)index clickedIndex: (NSUInteger)index
{ {
NSIndexSet *dragIndexes = _selectionIndexes; NSIndexSet *dragIndexes = _selectionIndexes;
if (![dragIndexes containsIndex: index] if (![dragIndexes containsIndex: index]
&& (index < [_items count])) && (index < [_items count]))
{ {
@ -1105,9 +1055,10 @@ clickedIndex:(NSUInteger)index
- (BOOL) prepareForDragOperation: (id<NSDraggingInfo>)sender - (BOOL) prepareForDragOperation: (id<NSDraggingInfo>)sender
{ {
_draggingOnIndex = NSNotFound;
NSPoint location = [self convertPoint: [sender draggingLocation] fromView: nil]; NSPoint location = [self convertPoint: [sender draggingLocation] fromView: nil];
NSInteger index = [self _indexAtPoint: location]; NSInteger index = [self _indexAtPoint: location];
_draggingOnIndex = NSNotFound;
[self setNeedsDisplayInRect: [self _frameForRowsAroundItemAtIndex: index]]; [self setNeedsDisplayInRect: [self _frameForRowsAroundItemAtIndex: index]];
return YES; return YES;
} }

View file

@ -25,50 +25,13 @@
Boston, MA 02110-1301, USA. Boston, MA 02110-1301, USA.
*/ */
#import "AppKit/NSCollectionViewItem.h" #import <Foundation/NSArray.h>
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSDebug.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSEnumerator.h>
#import <Foundation/NSException.h>
#import <Foundation/NSFormatter.h>
#import <Foundation/NSIndexSet.h>
#import <Foundation/NSKeyValueCoding.h>
#import <Foundation/NSNotification.h>
#import <Foundation/NSSet.h>
#import <Foundation/NSSortDescriptor.h>
#import <Foundation/NSUserDefaults.h>
#import <Foundation/NSValue.h>
#import <Foundation/NSKeyedArchiver.h> #import <Foundation/NSKeyedArchiver.h>
#import "AppKit/NSTableView.h" #import "AppKit/NSCollectionView.h"
#import "AppKit/NSApplication.h" #import "AppKit/NSCollectionViewItem.h"
#import "AppKit/NSCell.h" #import "AppKit/NSImageView.h"
#import "AppKit/NSClipView.h" #import "AppKit/NSTextField.h"
#import "AppKit/NSColor.h"
#import "AppKit/NSEvent.h"
#import "AppKit/NSImage.h"
#import "AppKit/NSGraphics.h"
#import "AppKit/NSKeyValueBinding.h"
#import "AppKit/NSScroller.h"
#import "AppKit/NSScrollView.h"
#import "AppKit/NSTableColumn.h"
#import "AppKit/NSTableHeaderView.h"
#import "AppKit/NSText.h"
#import "AppKit/NSTextFieldCell.h"
#import "AppKit/NSWindow.h"
#import "AppKit/PSOperators.h"
#import "AppKit/NSCachedImageRep.h"
#import "AppKit/NSPasteboard.h"
#import "AppKit/NSDragging.h"
#import "AppKit/NSCustomImageRep.h"
#import "AppKit/NSAttributedString.h"
#import "AppKit/NSStringDrawing.h"
#import "GNUstepGUI/GSTheme.h"
#import "GSBindingHelpers.h"
#include <math.h>
@implementation NSCollectionViewItem @implementation NSCollectionViewItem
@ -93,6 +56,12 @@
return (NSCollectionView *)[[self view] superview]; return (NSCollectionView *)[[self view] superview];
} }
- (NSArray *) draggingImageComponents
{
// FIXME: We don't have NSDraggingImageComponent
return [NSArray array];
}
- (void) setSelected: (BOOL)flag - (void) setSelected: (BOOL)flag
{ {
if (_isSelected != flag) if (_isSelected != flag)
@ -168,7 +137,7 @@
else else
{ {
[aCoder encodeObject: textField]; [aCoder encodeObject: textField];
[aCoder encodeObject:imageView] [aCoder encodeObject: imageView];
} }
} }

View file

@ -2884,12 +2884,12 @@ byExtendingSelection: (BOOL)flag
- (NSIndexSet *) selectedColumnIndexes - (NSIndexSet *) selectedColumnIndexes
{ {
return _selectedColumns; return [[_selectedColumns copy] autorelease];
} }
- (NSIndexSet *) selectedRowIndexes - (NSIndexSet *) selectedRowIndexes
{ {
return _selectedRows; return [[_selectedRows copy] autorelease];
} }
- (void) deselectColumn: (NSInteger)columnIndex - (void) deselectColumn: (NSInteger)columnIndex