From d3b8f3ae90d1f97baba9deeaa55924a6fd9c2a43 Mon Sep 17 00:00:00 2001 From: Frank Le Grand Date: Fri, 8 Mar 2013 22:59:40 +0000 Subject: [PATCH] Finalized drag&drop on NSCollectionView, fixed a bug in NSTabView where the nextKeyView was being set to a dealloc'd view after closing all tabs and reopening one. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/branches/gnustep_testplant_branch@36314 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 4 +++ Source/NSCell.m | 1 - Source/NSCollectionView.m | 65 +++++++++++++++++++---------------- Source/NSCollectionViewItem.m | 2 +- Source/NSTabView.m | 31 ++++++++++------- 5 files changed, 60 insertions(+), 43 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0b2da964e..f58918efc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2013-03-08 Frank Le Grand + * Source\NSCollectionView.m: Implemented drag & drop. + * Source\NSTabView.m: Fixed a bug where the nextKeyView was being set a dealloc'd view in some cases. + 2013-02-28 Frank Le Grand Continued work on Collection View: Applied more GNUstep coding standards (including the use of macros), implemented selection. diff --git a/Source/NSCell.m b/Source/NSCell.m index 776d85b08..66dae339e 100644 --- a/Source/NSCell.m +++ b/Source/NSCell.m @@ -2238,7 +2238,6 @@ static NSColor *dtxtCol; // there's something wrong about telling the view to come // back here and draw. [controlView setKeyboardFocusRingNeedsDisplayInRect:NSMakeRect (aRect.origin.x - 2.0, aRect.origin.y - 2.0, aRect.size.width + 4.0, aRect.size.height + 4.0)]; - NSLog(@"Edited Cell: %@", self); } /**

Ends any text editing. This method sets the text object's delegate diff --git a/Source/NSCollectionView.m b/Source/NSCollectionView.m index 1340d0f6a..89e958530 100644 --- a/Source/NSCollectionView.m +++ b/Source/NSCollectionView.m @@ -135,15 +135,25 @@ static NSString *placeholderItem = nil; placeholderItem = @"Placeholder"; } +- (id) initWithFrame: (NSRect)frame +{ + if ((self = [super initWithFrame:frame])) + { + [self _initDefaults]; + } + return self; +} + -(void) _initDefaults { - _draggingSourceOperationMaskForLocal = NSDragOperationCopy | NSDragOperationLink | NSDragOperationGeneric | NSDragOperationPrivate; -// _draggingSourceOperationMaskForRemote = NSDragOperationNone; - _draggingSourceOperationMaskForRemote = NSDragOperationCopy | NSDragOperationLink | NSDragOperationGeneric | NSDragOperationPrivate; +// _draggingSourceOperationMaskForLocal = NSDragOperationCopy | NSDragOperationLink | NSDragOperationGeneric | NSDragOperationPrivate; + _draggingSourceOperationMaskForLocal = NSDragOperationGeneric | NSDragOperationMove | NSDragOperationCopy; + _draggingSourceOperationMaskForRemote = NSDragOperationGeneric | NSDragOperationMove | NSDragOperationCopy; [self _resetItemSize]; _content = [[NSArray alloc] init]; _items = [[NSMutableArray alloc] init]; _selectionIndexes = [[NSIndexSet alloc] init]; + _draggingOnIndex = NSNotFound; } - (void) _resetItemSize @@ -197,7 +207,10 @@ static NSString *placeholderItem = nil; //[[NSNotificationCenter defaultCenter] removeObserver:self]; DESTROY (_content); - //DESTROY (itemPrototype); + + // FIXME: Not clear if we should destroy the top-level item "itemPrototype" loaded in the nib file. + DESTROY (itemPrototype); + DESTROY (_backgroundColors); DESTROY (_selectionIndexes); DESTROY (_items); @@ -503,7 +516,7 @@ static NSString *placeholderItem = nil; ASSIGN(collectionItem, [itemPrototype copy]); [collectionItem setRepresentedObject:object]; } - return collectionItem; + return AUTORELEASE (collectionItem); } - (void) _removeItemsViews @@ -1007,31 +1020,9 @@ static NSString *placeholderItem = nil; endedAt: (NSPoint)point operation: (NSDragOperation)operation { - NSLog(@"draggedImage:endedAt:operation:"); } -- (NSDragOperation) draggingEntered: (id)sender -{ - NSLog(@"draggingEntered:"); - if ([sender draggingSource] == self) - { - return NSDragOperationNone; - } - else - { - return NSDragOperationCopy; - } -} - -- (void) draggingExited: (id)sender -{ - _draggingOnIndex = NSNotFound; - NSPoint location = [self convertPoint: [sender draggingLocation] fromView: nil]; - int index = [self _indexAtPoint:location]; - [self setNeedsDisplayInRect:[self _frameForRowOfItemAtIndex:index]]; -} - -- (NSDragOperation) draggingUpdated: (id)sender +- (NSDragOperation) _draggingEnteredOrUpdated: (id)sender { NSDragOperation result = NSDragOperationNone; @@ -1039,9 +1030,9 @@ static NSString *placeholderItem = nil; { NSPoint location = [self convertPoint: [sender draggingLocation] fromView: nil]; int index = [self _indexAtPoint:location]; + index = (index > [_items count] - 1) ? [_items count] - 1 : index; _draggingOnIndex = index; [self setNeedsDisplayInRect:[self _frameForRowsAroundItemAtIndex:index]]; - //NSLog (@">>> DRAGGING OVER INDEX %d", index); NSInteger *proposedIndex = (NSInteger *)index; @@ -1054,6 +1045,22 @@ static NSString *placeholderItem = nil; return result; } +- (NSDragOperation) draggingEntered: (id)sender +{ + return [self _draggingEnteredOrUpdated:sender]; +} + +- (void) draggingExited: (id)sender +{ + [self setNeedsDisplayInRect:[self _frameForRowsAroundItemAtIndex:_draggingOnIndex]]; + _draggingOnIndex = NSNotFound; +} + +- (NSDragOperation) draggingUpdated: (id)sender +{ + return [self _draggingEnteredOrUpdated:sender]; +} + - (BOOL) prepareForDragOperation: (id)sender { _draggingOnIndex = NSNotFound; diff --git a/Source/NSCollectionViewItem.m b/Source/NSCollectionViewItem.m index 8ae91010f..52a3bea2d 100644 --- a/Source/NSCollectionViewItem.m +++ b/Source/NSCollectionViewItem.m @@ -109,7 +109,7 @@ - (void)setRepresentedObject:(id)anObject { [super setRepresentedObject:anObject]; - [textField setStringValue:[self representedObject]]; + //[textField setStringValue:[self representedObject]]; } - (NSTextField *)textField diff --git a/Source/NSTabView.m b/Source/NSTabView.m index a52e4317e..34385ae57 100644 --- a/Source/NSTabView.m +++ b/Source/NSTabView.m @@ -89,6 +89,7 @@ // Reset the _selected attribute to prevent crash when -dealloc calls // -setNextKeyView: _selected = nil; + _original_nextKeyView = nil; RELEASE(_items); RELEASE(_font); [super dealloc]; @@ -273,24 +274,30 @@ if (selectedView != nil) { - NSView *firstResponder; + NSView *firstResponder; [self addSubview: selectedView]; - // FIXME: We should not change this mask + + // FIXME: We should not change this mask [selectedView setAutoresizingMask: - NSViewWidthSizable | NSViewHeightSizable]; + NSViewWidthSizable | NSViewHeightSizable]; [selectedView setFrame: [self contentRect]]; - firstResponder = [_selected initialFirstResponder]; - if (firstResponder == nil) - { - firstResponder = [_selected view]; - [_selected setInitialFirstResponder: firstResponder]; - [firstResponder _setUpKeyViewLoopWithNextKeyView: - _original_nextKeyView]; - } - [self setNextKeyView: firstResponder]; + firstResponder = [_selected initialFirstResponder]; + + if (firstResponder == nil) + { + firstResponder = [_selected view]; + [_selected setInitialFirstResponder: firstResponder]; + [firstResponder _setUpKeyViewLoopWithNextKeyView:_original_nextKeyView]; + } + + [super setNextKeyView: firstResponder]; [_window makeFirstResponder: firstResponder]; } + else + { + [super setNextKeyView:_original_nextKeyView]; + } /* Will need to redraw tabs and content area. */ [self setNeedsDisplay: YES];