diff --git a/Source/NSOutlineView.m b/Source/NSOutlineView.m
index 8e515d711..47581a83a 100644
--- a/Source/NSOutlineView.m
+++ b/Source/NSOutlineView.m
@@ -1,35 +1,35 @@
/**
NSOutlineView
-
-
- This class is a subclass of NSTableView which provides the user with a way
- to display tree structured data in an outline format.
- It is particularly useful for show hierarchical data such as a
- class inheritance tree or any other set of relationships.
-
-
- Copyright (C) 2001 Free Software Foundation, Inc.
-
- Author: Gregory John Casamento
- Date: October 2001
-
- This file is part of the GNUstep GUI Library.
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; see the file COPYING.LIB.
- If not, see or write to the
- Free Software Foundation, 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA.
- */
+
+
+ This class is a subclass of NSTableView which provides the user with a way
+ to display tree structured data in an outline format.
+ It is particularly useful for show hierarchical data such as a
+ class inheritance tree or any other set of relationships.
+
+
+ Copyright (C) 2001 Free Software Foundation, Inc.
+
+ Author: Gregory John Casamento
+ Date: October 2001
+
+ This file is part of the GNUstep GUI Library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; see the file COPYING.LIB.
+ If not, see or write to the
+ Free Software Foundation, 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
#import
#import
@@ -139,23 +139,23 @@ static NSImage *unexpandable = nil;
// Initialize the class when it is loaded
+ (void) initialize
{
- if (self == [NSOutlineView class])
+ if (self == [NSOutlineView class])
{
- [self setVersion: current_version];
- nc = [NSNotificationCenter defaultCenter];
+ [self setVersion: current_version];
+ nc = [NSNotificationCenter defaultCenter];
#if 0
- /* Old Interface Builder style. */
- collapsed = [NSImage imageNamed: @"common_outlineCollapsed"];
- expanded = [NSImage imageNamed: @"common_outlineExpanded"];
- unexpandable = [NSImage imageNamed: @"common_outlineUnexpandable"];
+/* Old Interface Builder style. */
+ collapsed = [NSImage imageNamed: @"common_outlineCollapsed"];
+ expanded = [NSImage imageNamed: @"common_outlineExpanded"];
+ unexpandable = [NSImage imageNamed: @"common_outlineUnexpandable"];
#else
- /* Current OSX style images. */
- // FIXME ... better ones?
- collapsed = [NSImage imageNamed: @"common_ArrowRightH"];
- expanded = [NSImage imageNamed: @"common_ArrowDownH"];
- unexpandable = [[NSImage alloc] initWithSize: [expanded size]];
+/* Current OSX style images. */
+// FIXME ... better ones?
+ collapsed = [NSImage imageNamed: @"common_ArrowRightH"];
+ expanded = [NSImage imageNamed: @"common_ArrowDownH"];
+ unexpandable = [[NSImage alloc] initWithSize: [expanded size]];
#endif
- autoExpanded = [NSMutableSet new];
+ autoExpanded = [NSMutableSet new];
}
}
@@ -168,39 +168,39 @@ static NSImage *unexpandable = nil;
*/
- (id) initWithFrame: (NSRect)frame
{
- self = [super initWithFrame: frame];
-
- if (self != nil)
- {
- [self _initOutlineDefaults];
- //_outlineTableColumn = nil;
- }
-
- return self;
+ self = [super initWithFrame: frame];
+
+ if (self != nil)
+ {
+ [self _initOutlineDefaults];
+ //_outlineTableColumn = nil;
+ }
+
+ return self;
}
- (void) dealloc
{
- RELEASE(_items);
- RELEASE(_expandedItems);
-
- NSFreeMapTable(_itemDict);
- NSFreeMapTable(_levelOfItems);
-
- if (_autosaveExpandedItems)
+ RELEASE(_items);
+ RELEASE(_expandedItems);
+
+ NSFreeMapTable(_itemDict);
+ NSFreeMapTable(_levelOfItems);
+
+ if (_autosaveExpandedItems)
{
- // notify when an item expands...
- [nc removeObserver: self
- name: NSOutlineViewItemDidExpandNotification
- object: self];
-
- // notify when an item collapses...
- [nc removeObserver: self
- name: NSOutlineViewItemDidCollapseNotification
- object: self];
+ // notify when an item expands...
+ [nc removeObserver: self
+ name: NSOutlineViewItemDidExpandNotification
+ object: self];
+
+ // notify when an item collapses...
+ [nc removeObserver: self
+ name: NSOutlineViewItemDidCollapseNotification
+ object: self];
}
-
- [super dealloc];
+
+ [super dealloc];
}
/**
@@ -209,7 +209,7 @@ static NSImage *unexpandable = nil;
*/
- (BOOL)autoResizesOutlineColumn
{
- return _autoResizesOutlineColumn;
+ return _autoResizesOutlineColumn;
}
/**
@@ -218,7 +218,7 @@ static NSImage *unexpandable = nil;
*/
- (BOOL)autosaveExpandedItems
{
- return _autosaveExpandedItems;
+ return _autosaveExpandedItems;
}
/**
@@ -227,7 +227,7 @@ static NSImage *unexpandable = nil;
*/
- (void) collapseItem: (id)item
{
- [self collapseItem: item collapseChildren: NO];
+ [self collapseItem: item collapseChildren: NO];
}
/**
@@ -237,61 +237,61 @@ static NSImage *unexpandable = nil;
*/
- (void) collapseItem: (id)item collapseChildren: (BOOL)collapseChildren
{
- const SEL shouldSelector = @selector(outlineView:shouldCollapseItem:);
- BOOL canCollapse = YES;
-
- if ([_delegate respondsToSelector: shouldSelector])
+ const SEL shouldSelector = @selector(outlineView:shouldCollapseItem:);
+ BOOL canCollapse = YES;
+
+ if ([_delegate respondsToSelector: shouldSelector])
{
- canCollapse = [_delegate outlineView: self shouldCollapseItem: item];
+ canCollapse = [_delegate outlineView: self shouldCollapseItem: item];
}
-
- if ([self isExpandable: item] && [self isItemExpanded: item] && canCollapse)
+
+ if ([self isExpandable: item] && [self isItemExpanded: item] && canCollapse)
{
- NSMutableDictionary *infoDict = [NSMutableDictionary dictionary];
-
- [infoDict setObject: item forKey: @"NSObject"];
-
- // Send out the notification to let observers know that this is about
- // to occur.
- [nc postNotificationName: NSOutlineViewItemWillCollapseNotification
- object: self
- userInfo: infoDict];
-
- // recursively find all children and call this method to close them.
- // Note: The children must be collapsed before their parent item so
- // that the selected row indexes are properly updated (and in particular
- // are valid when we post our notifications).
- if (collapseChildren) // collapse all
+ NSMutableDictionary *infoDict = [NSMutableDictionary dictionary];
+
+ [infoDict setObject: item forKey: @"NSObject"];
+
+ // Send out the notification to let observers know that this is about
+ // to occur.
+ [nc postNotificationName: NSOutlineViewItemWillCollapseNotification
+ object: self
+ userInfo: infoDict];
+
+ // recursively find all children and call this method to close them.
+ // Note: The children must be collapsed before their parent item so
+ // that the selected row indexes are properly updated (and in particular
+ // are valid when we post our notifications).
+ if (collapseChildren) // collapse all
{
- int index, numChildren;
- NSMutableArray *allChildren;
- id sitem = (item == nil) ? (id)[NSNull null] : (id)item;
-
- allChildren = NSMapGet(_itemDict, sitem);
- numChildren = [allChildren count];
-
- for (index = 0; index < numChildren; index++)
+ int index, numChildren;
+ NSMutableArray *allChildren;
+ id sitem = (item == nil) ? (id)[NSNull null] : (id)item;
+
+ allChildren = NSMapGet(_itemDict, sitem);
+ numChildren = [allChildren count];
+
+ for (index = 0; index < numChildren; index++)
{
- id child = [allChildren objectAtIndex: index];
-
- if ([self isExpandable: child])
+ id child = [allChildren objectAtIndex: index];
+
+ if ([self isExpandable: child])
{
- [self collapseItem: child collapseChildren: collapseChildren];
+ [self collapseItem: child collapseChildren: collapseChildren];
}
}
}
-
- // collapse...
- [self _closeItem: item];
-
- // Send out the notification to let observers know that this has
- // occured.
- [nc postNotificationName: NSOutlineViewItemDidCollapseNotification
- object: self
- userInfo: infoDict];
-
- // Should only mark the rect below the closed item for redraw
- [self setNeedsDisplay: YES];
+
+ // collapse...
+ [self _closeItem: item];
+
+ // Send out the notification to let observers know that this has
+ // occured.
+ [nc postNotificationName: NSOutlineViewItemDidCollapseNotification
+ object: self
+ userInfo: infoDict];
+
+ // Should only mark the rect below the closed item for redraw
+ [self setNeedsDisplay: YES];
}
}
@@ -301,7 +301,7 @@ static NSImage *unexpandable = nil;
*/
- (void) expandItem: (id)item
{
- [self expandItem: item expandChildren: NO];
+ [self expandItem: item expandChildren: NO];
}
/**
@@ -311,83 +311,83 @@ static NSImage *unexpandable = nil;
*/
- (void) expandItem: (id)item expandChildren: (BOOL)expandChildren
{
- const SEL shouldExpandSelector = @selector(outlineView:shouldExpandItem:);
- BOOL canExpand = YES;
-
- if ([_delegate respondsToSelector: shouldExpandSelector])
+ const SEL shouldExpandSelector = @selector(outlineView:shouldExpandItem:);
+ BOOL canExpand = YES;
+
+ if ([_delegate respondsToSelector: shouldExpandSelector])
{
- canExpand = [_delegate outlineView: self shouldExpandItem: item];
+ canExpand = [_delegate outlineView: self shouldExpandItem: item];
}
-
- // if the item is expandable
- if ([self isExpandable: item])
+
+ // if the item is expandable
+ if ([self isExpandable: item])
{
- // if it is not already expanded and it can be expanded, then expand
- if (![self isItemExpanded: item] && canExpand)
+ // if it is not already expanded and it can be expanded, then expand
+ if (![self isItemExpanded: item] && canExpand)
{
- NSMutableDictionary *infoDict = [NSMutableDictionary dictionary];
-
- [infoDict setObject: item forKey: @"NSObject"];
-
- // Send out the notification to let observers know that this is about
- // to occur.
- [nc postNotificationName: NSOutlineViewItemWillExpandNotification
- object: self
- userInfo: infoDict];
-
- // insert the root element, if necessary otherwise insert the
- // actual object.
- [self _openItem: item];
-
- // Send out the notification to let observers know that this has
- // occured.
- [nc postNotificationName: NSOutlineViewItemDidExpandNotification
- object: self
- userInfo: infoDict];
+ NSMutableDictionary *infoDict = [NSMutableDictionary dictionary];
+
+ [infoDict setObject: item forKey: @"NSObject"];
+
+ // Send out the notification to let observers know that this is about
+ // to occur.
+ [nc postNotificationName: NSOutlineViewItemWillExpandNotification
+ object: self
+ userInfo: infoDict];
+
+ // insert the root element, if necessary otherwise insert the
+ // actual object.
+ [self _openItem: item];
+
+ // Send out the notification to let observers know that this has
+ // occured.
+ [nc postNotificationName: NSOutlineViewItemDidExpandNotification
+ object: self
+ userInfo: infoDict];
}
-
- // recursively find all children and call this method to open them.
- if (expandChildren) // expand all
+
+ // recursively find all children and call this method to open them.
+ if (expandChildren) // expand all
{
- int index, numChildren;
- NSMutableArray *allChildren;
- id sitem = (item == nil) ? (id)[NSNull null] : (id)item;
-
- allChildren = NSMapGet(_itemDict, sitem);
- numChildren = [allChildren count];
-
- for (index = 0; index < numChildren; index++)
+ int index, numChildren;
+ NSMutableArray *allChildren;
+ id sitem = (item == nil) ? (id)[NSNull null] : (id)item;
+
+ allChildren = NSMapGet(_itemDict, sitem);
+ numChildren = [allChildren count];
+
+ for (index = 0; index < numChildren; index++)
{
- id child = [allChildren objectAtIndex: index];
-
- if ([self isExpandable: child])
+ id child = [allChildren objectAtIndex: index];
+
+ if ([self isExpandable: child])
{
- [self expandItem: child expandChildren: expandChildren];
+ [self expandItem: child expandChildren: expandChildren];
}
}
}
-
- // Should only mark the rect below the expanded item for redraw
- [self setNeedsDisplay: YES];
+
+ // Should only mark the rect below the expanded item for redraw
+ [self setNeedsDisplay: YES];
}
}
- (NSRect) frameOfOutlineCellAtRow: (NSInteger)row
{
- NSRect frameRect;
-
- if (![self isExpandable: [self itemAtRow: row]])
- return NSZeroRect;
-
- frameRect = [self frameOfCellAtColumn: 0
- row: row];
-
- if (_indentationMarkerFollowsCell)
+ NSRect frameRect;
+
+ if (![self isExpandable: [self itemAtRow: row]])
+ return NSZeroRect;
+
+ frameRect = [self frameOfCellAtColumn: 0
+ row: row];
+
+ if (_indentationMarkerFollowsCell)
{
- frameRect.origin.x += _indentationPerLevel * [self levelForRow: row];
+ frameRect.origin.x += _indentationPerLevel * [self levelForRow: row];
}
-
- return frameRect;
+
+ return frameRect;
}
/**
@@ -396,7 +396,7 @@ static NSImage *unexpandable = nil;
*/
- (BOOL) indentationMarkerFollowsCell
{
- return _indentationMarkerFollowsCell;
+ return _indentationMarkerFollowsCell;
}
/**
@@ -405,7 +405,7 @@ static NSImage *unexpandable = nil;
*/
- (CGFloat) indentationPerLevel
{
- return _indentationPerLevel;
+ return _indentationPerLevel;
}
/**
@@ -415,11 +415,11 @@ static NSImage *unexpandable = nil;
*/
- (BOOL) isExpandable: (id)item
{
- if (item == nil)
+ if (item == nil)
{
- return NO;
+ return NO;
}
- return [_dataSource outlineView: self isItemExpandable: item];
+ return [_dataSource outlineView: self isItemExpandable: item];
}
/**
@@ -429,12 +429,12 @@ static NSImage *unexpandable = nil;
*/
- (BOOL) isItemExpanded: (id)item
{
- if (item == nil)
+ if (item == nil)
{
- return YES;
+ return YES;
}
- // Check the array to determine if it is expanded.
- return([_expandedItems containsObject: item]);
+ // Check the array to determine if it is expanded.
+ return([_expandedItems containsObject: item]);
}
/**
@@ -443,11 +443,11 @@ static NSImage *unexpandable = nil;
*/
- (id) itemAtRow: (NSInteger)row
{
- if ((row >= [_items count]) || (row < 0))
+ if ((row >= [_items count]) || (row < 0))
{
- return nil;
+ return nil;
}
- return [_items objectAtIndex: row];
+ return [_items objectAtIndex: row];
}
/**
@@ -455,13 +455,13 @@ static NSImage *unexpandable = nil;
*/
- (NSInteger) levelForItem: (id)item
{
- if (item != nil)
+ if (item != nil)
{
- id object = NSMapGet(_levelOfItems, item);
- return [object integerValue];
+ id object = NSMapGet(_levelOfItems, item);
+ return [object integerValue];
}
-
- return -1;
+
+ return -1;
}
/**
@@ -469,7 +469,7 @@ static NSImage *unexpandable = nil;
*/
- (NSInteger) levelForRow: (NSInteger)row
{
- return [self levelForItem: [self itemAtRow: row]];
+ return [self levelForItem: [self itemAtRow: row]];
}
/**
@@ -477,7 +477,7 @@ static NSImage *unexpandable = nil;
*/
- (NSTableColumn *) outlineTableColumn
{
- return _outlineTableColumn;
+ return _outlineTableColumn;
}
/**
@@ -485,22 +485,22 @@ static NSImage *unexpandable = nil;
*/
- (id) parentForItem: (id)item
{
- NSArray *allKeys = NSAllMapTableKeys(_itemDict);
- NSEnumerator *en = [allKeys objectEnumerator];
- NSInteger index;
- id parent;
-
- while ((parent = [en nextObject]))
+ NSArray *allKeys = NSAllMapTableKeys(_itemDict);
+ NSEnumerator *en = [allKeys objectEnumerator];
+ NSInteger index;
+ id parent;
+
+ while ((parent = [en nextObject]))
{
- NSMutableArray *childArray = NSMapGet(_itemDict, parent);
-
- if ((index = [childArray indexOfObject: item]) != NSNotFound)
+ NSMutableArray *childArray = NSMapGet(_itemDict, parent);
+
+ if ((index = [childArray indexOfObject: item]) != NSNotFound)
{
- return (parent == [NSNull null]) ? (id)nil : (id)parent;
+ return (parent == [NSNull null]) ? (id)nil : (id)parent;
}
}
-
- return nil;
+
+ return nil;
}
/**
@@ -509,7 +509,7 @@ static NSImage *unexpandable = nil;
*/
- (void) reloadItem: (id)item
{
- [self reloadItem: item reloadChildren: NO];
+ [self reloadItem: item reloadChildren: NO];
}
/**
@@ -519,50 +519,50 @@ static NSImage *unexpandable = nil;
*/
- (void) reloadItem: (id)item reloadChildren: (BOOL)reloadChildren
{
- NSInteger index;
- id parent;
- BOOL expanded;
- id dsobj = nil;
- id object = (item == nil) ? (id)[NSNull null] : (id)item;
- NSArray *allKeys = NSAllMapTableKeys(_itemDict);
- NSEnumerator *en = [allKeys objectEnumerator];
-
- expanded = [self isItemExpanded: item];
-
- // find the parent of the item
- while ((parent = [en nextObject]))
+ NSInteger index;
+ id parent;
+ BOOL expanded;
+ id dsobj = nil;
+ id object = (item == nil) ? (id)[NSNull null] : (id)item;
+ NSArray *allKeys = NSAllMapTableKeys(_itemDict);
+ NSEnumerator *en = [allKeys objectEnumerator];
+
+ expanded = [self isItemExpanded: item];
+
+ // find the parent of the item
+ while ((parent = [en nextObject]))
{
- NSMutableArray *childArray = NSMapGet(_itemDict, parent);
-
- if ((index = [childArray indexOfObject: object]) != NSNotFound)
+ NSMutableArray *childArray = NSMapGet(_itemDict, parent);
+
+ if ((index = [childArray indexOfObject: object]) != NSNotFound)
{
- parent = (parent == [NSNull null]) ? (id)nil : (id)parent;
- dsobj = [_dataSource outlineView: self
- child: index
- ofItem: parent];
-
- if (dsobj != item)
+ parent = (parent == [NSNull null]) ? (id)nil : (id)parent;
+ dsobj = [_dataSource outlineView: self
+ child: index
+ ofItem: parent];
+
+ if (dsobj != item)
{
- [childArray replaceObjectAtIndex: index withObject: dsobj];
- // FIXME We need to correct _items, _itemDict, _levelOfItems,
- // _expandedItems and _selectedItems
+ [childArray replaceObjectAtIndex: index withObject: dsobj];
+ // FIXME We need to correct _items, _itemDict, _levelOfItems,
+ // _expandedItems and _selectedItems
}
- break;
+ break;
}
}
-
- if (reloadChildren)
+
+ if (reloadChildren)
{
- [self _removeChildren: dsobj];
- [self _loadDictionaryStartingWith: dsobj
- atLevel: [self levelForItem: dsobj]];
-
- if (expanded)
+ [self _removeChildren: dsobj];
+ [self _loadDictionaryStartingWith: dsobj
+ atLevel: [self levelForItem: dsobj]];
+
+ if (expanded)
{
- [self _openItem: dsobj];
+ [self _openItem: dsobj];
}
}
- [self setNeedsDisplay: YES];
+ [self setNeedsDisplay: YES];
}
/**
@@ -571,12 +571,12 @@ static NSImage *unexpandable = nil;
*/
- (NSInteger) rowForItem: (id)item
{
- NSInteger row;
- if (item == nil)
- return -1;
-
- row = [_items indexOfObject: item];
- return (row == NSNotFound) ? -1 : row;
+ NSInteger row;
+ if (item == nil)
+ return -1;
+
+ row = [_items indexOfObject: item];
+ return (row == NSNotFound) ? -1 : row;
}
/**
@@ -586,7 +586,7 @@ static NSImage *unexpandable = nil;
*/
- (void) setAutoresizesOutlineColumn: (BOOL)resize
{
- _autoResizesOutlineColumn = resize;
+ _autoResizesOutlineColumn = resize;
}
/**
@@ -596,38 +596,38 @@ static NSImage *unexpandable = nil;
*/
- (void) setAutosaveExpandedItems: (BOOL)flag
{
- if (flag == _autosaveExpandedItems)
+ if (flag == _autosaveExpandedItems)
{
- return;
+ return;
}
-
- _autosaveExpandedItems = flag;
- if (flag)
+
+ _autosaveExpandedItems = flag;
+ if (flag)
{
- [self _autoloadExpandedItems];
- // notify when an item expands...
- [nc addObserver: self
- selector: @selector(_autosaveExpandedItems)
- name: NSOutlineViewItemDidExpandNotification
- object: self];
-
- // notify when an item collapses...
- [nc addObserver: self
- selector: @selector(_autosaveExpandedItems)
- name: NSOutlineViewItemDidCollapseNotification
- object: self];
+ [self _autoloadExpandedItems];
+ // notify when an item expands...
+ [nc addObserver: self
+ selector: @selector(_autosaveExpandedItems)
+ name: NSOutlineViewItemDidExpandNotification
+ object: self];
+
+ // notify when an item collapses...
+ [nc addObserver: self
+ selector: @selector(_autosaveExpandedItems)
+ name: NSOutlineViewItemDidCollapseNotification
+ object: self];
}
- else
+ else
{
- // notify when an item expands...
- [nc removeObserver: self
- name: NSOutlineViewItemDidExpandNotification
- object: self];
-
- // notify when an item collapses...
- [nc removeObserver: self
- name: NSOutlineViewItemDidCollapseNotification
- object: self];
+ // notify when an item expands...
+ [nc removeObserver: self
+ name: NSOutlineViewItemDidExpandNotification
+ object: self];
+
+ // notify when an item collapses...
+ [nc removeObserver: self
+ name: NSOutlineViewItemDidCollapseNotification
+ object: self];
}
}
@@ -638,7 +638,7 @@ static NSImage *unexpandable = nil;
*/
- (void) setIndentationMarkerFollowsCell: (BOOL)followsCell
{
- _indentationMarkerFollowsCell = followsCell;
+ _indentationMarkerFollowsCell = followsCell;
}
/**
@@ -646,7 +646,7 @@ static NSImage *unexpandable = nil;
*/
- (void)setIndentationPerLevel: (CGFloat)newIndentLevel
{
- _indentationPerLevel = newIndentLevel;
+ _indentationPerLevel = newIndentLevel;
}
/**
@@ -654,7 +654,7 @@ static NSImage *unexpandable = nil;
*/
- (void)setOutlineTableColumn: (NSTableColumn *)outlineTableColumn
{
- _outlineTableColumn = outlineTableColumn;
+ _outlineTableColumn = outlineTableColumn;
}
/**
@@ -663,7 +663,7 @@ static NSImage *unexpandable = nil;
*/
- (BOOL)shouldCollapseAutoExpandedItemsForDeposited: (BOOL)deposited
{
- return YES;
+ return YES;
}
/**
@@ -672,23 +672,23 @@ static NSImage *unexpandable = nil;
- (void) setDataSource: (id)anObject
{
#define CHECK_REQUIRED_METHOD(selector_name) \
-if (anObject && ![anObject respondsToSelector: @selector(selector_name)]) \
-[NSException raise: NSInternalInconsistencyException \
-format: @"data source does not respond to %@", @#selector_name]
-
- CHECK_REQUIRED_METHOD(outlineView:child:ofItem:);
- CHECK_REQUIRED_METHOD(outlineView:isItemExpandable:);
- CHECK_REQUIRED_METHOD(outlineView:numberOfChildrenOfItem:);
- CHECK_REQUIRED_METHOD(outlineView:objectValueForTableColumn:byItem:);
-
- // Is the data source editable?
- _dataSource_editable = [anObject respondsToSelector:
- @selector(outlineView:setObjectValue:forTableColumn:byItem:)];
-
- /* We do *not* retain the dataSource, it's like a delegate */
- _dataSource = anObject;
- [self tile];
- [self reloadData];
+ if (anObject && ![anObject respondsToSelector: @selector(selector_name)]) \
+ [NSException raise: NSInternalInconsistencyException \
+ format: @"data source does not respond to %@", @#selector_name]
+
+ CHECK_REQUIRED_METHOD(outlineView:child:ofItem:);
+ CHECK_REQUIRED_METHOD(outlineView:isItemExpandable:);
+ CHECK_REQUIRED_METHOD(outlineView:numberOfChildrenOfItem:);
+ CHECK_REQUIRED_METHOD(outlineView:objectValueForTableColumn:byItem:);
+
+ // Is the data source editable?
+ _dataSource_editable = [anObject respondsToSelector:
+ @selector(outlineView:setObjectValue:forTableColumn:byItem:)];
+
+ /* We do *not* retain the dataSource, it's like a delegate */
+ _dataSource = anObject;
+ [self tile];
+ [self reloadData];
}
/**
@@ -696,34 +696,34 @@ format: @"data source does not respond to %@", @#selector_name]
*/
- (void) reloadData
{
- // release the old array
- if (_items != nil)
+ // release the old array
+ if (_items != nil)
{
- RELEASE(_items);
+ RELEASE(_items);
}
-
- if (_itemDict != NULL)
+
+ if (_itemDict != NULL)
{
- NSFreeMapTable(_itemDict);
+ NSFreeMapTable(_itemDict);
}
-
- if (_levelOfItems != NULL)
+
+ if (_levelOfItems != NULL)
{
- NSFreeMapTable(_levelOfItems);
+ NSFreeMapTable(_levelOfItems);
}
-
- // create a new empty one
- _items = [[NSMutableArray alloc] init];
- _itemDict = NSCreateMapTable(NSObjectMapKeyCallBacks,
- NSObjectMapValueCallBacks,
- 64);
- _levelOfItems = NSCreateMapTable(NSObjectMapKeyCallBacks,
- NSObjectMapValueCallBacks,
- 64);
-
- // reload all the open items...
- [self _openItem: nil];
- [super reloadData];
+
+ // create a new empty one
+ _items = [[NSMutableArray alloc] init];
+ _itemDict = NSCreateMapTable(NSObjectMapKeyCallBacks,
+ NSObjectMapValueCallBacks,
+ 64);
+ _levelOfItems = NSCreateMapTable(NSObjectMapKeyCallBacks,
+ NSObjectMapValueCallBacks,
+ 64);
+
+ // reload all the open items...
+ [self _openItem: nil];
+ [super reloadData];
}
/**
@@ -731,181 +731,181 @@ format: @"data source does not respond to %@", @#selector_name]
*/
- (void) setDelegate: (id)anObject
{
- const SEL sel = @selector(outlineView:willDisplayCell:forTableColumn:item:);
-
- if (_delegate)
- [nc removeObserver: _delegate name: nil object: self];
- _delegate = anObject;
-
+ const SEL sel = @selector(outlineView:willDisplayCell:forTableColumn:item:);
+
+ if (_delegate)
+ [nc removeObserver: _delegate name: nil object: self];
+ _delegate = anObject;
+
#define SET_DELEGATE_NOTIFICATION(notif_name) \
-if ([_delegate respondsToSelector: @selector(outlineView##notif_name:)]) \
-[nc addObserver: _delegate \
-selector: @selector(outlineView##notif_name:) \
-name: NSOutlineView##notif_name##Notification object: self]
-
- SET_DELEGATE_NOTIFICATION(ColumnDidMove);
- SET_DELEGATE_NOTIFICATION(ColumnDidResize);
- SET_DELEGATE_NOTIFICATION(SelectionDidChange);
- SET_DELEGATE_NOTIFICATION(SelectionIsChanging);
- SET_DELEGATE_NOTIFICATION(ItemDidExpand);
- SET_DELEGATE_NOTIFICATION(ItemDidCollapse);
- SET_DELEGATE_NOTIFICATION(ItemWillExpand);
- SET_DELEGATE_NOTIFICATION(ItemWillCollapse);
-
- _del_responds = [_delegate respondsToSelector: sel];
+ if ([_delegate respondsToSelector: @selector(outlineView##notif_name:)]) \
+ [nc addObserver: _delegate \
+ selector: @selector(outlineView##notif_name:) \
+ name: NSOutlineView##notif_name##Notification object: self]
+
+ SET_DELEGATE_NOTIFICATION(ColumnDidMove);
+ SET_DELEGATE_NOTIFICATION(ColumnDidResize);
+ SET_DELEGATE_NOTIFICATION(SelectionDidChange);
+ SET_DELEGATE_NOTIFICATION(SelectionIsChanging);
+ SET_DELEGATE_NOTIFICATION(ItemDidExpand);
+ SET_DELEGATE_NOTIFICATION(ItemDidCollapse);
+ SET_DELEGATE_NOTIFICATION(ItemWillExpand);
+ SET_DELEGATE_NOTIFICATION(ItemWillCollapse);
+
+ _del_responds = [_delegate respondsToSelector: sel];
}
- (void) encodeWithCoder: (NSCoder*)aCoder
{
- [super encodeWithCoder: aCoder];
- if ([aCoder allowsKeyedCoding] == NO)
+ [super encodeWithCoder: aCoder];
+ if ([aCoder allowsKeyedCoding] == NO)
{
- float indentation = _indentationPerLevel;
- [aCoder encodeValueOfObjCType: @encode(BOOL)
- at: &_autoResizesOutlineColumn];
- [aCoder encodeValueOfObjCType: @encode(BOOL)
- at: &_indentationMarkerFollowsCell];
- [aCoder encodeValueOfObjCType: @encode(BOOL)
- at: &_autosaveExpandedItems];
- [aCoder encodeValueOfObjCType: @encode(float)
- at: &indentation];
- [aCoder encodeConditionalObject: _outlineTableColumn];
+ float indentation = _indentationPerLevel;
+ [aCoder encodeValueOfObjCType: @encode(BOOL)
+ at: &_autoResizesOutlineColumn];
+ [aCoder encodeValueOfObjCType: @encode(BOOL)
+ at: &_indentationMarkerFollowsCell];
+ [aCoder encodeValueOfObjCType: @encode(BOOL)
+ at: &_autosaveExpandedItems];
+ [aCoder encodeValueOfObjCType: @encode(float)
+ at: &indentation];
+ [aCoder encodeConditionalObject: _outlineTableColumn];
}
}
- (id) initWithCoder: (NSCoder *)aDecoder
{
- // Since we only have one version....
- self = [super initWithCoder: aDecoder];
- if (self == nil)
- return self;
-
- [self _initOutlineDefaults];
-
- if ([aDecoder allowsKeyedCoding])
+ // Since we only have one version....
+ self = [super initWithCoder: aDecoder];
+ if (self == nil)
+ return self;
+
+ [self _initOutlineDefaults];
+
+ if ([aDecoder allowsKeyedCoding])
{
- // init the table column... (this can't be chosen on IB either)...
- if ([_tableColumns count] > 0)
+ // init the table column... (this can't be chosen on IB either)...
+ if ([_tableColumns count] > 0)
{
- _outlineTableColumn = [_tableColumns objectAtIndex: 0];
+ _outlineTableColumn = [_tableColumns objectAtIndex: 0];
}
}
- else
+ else
{
- float indentation;
- // overrides outline defaults with archived values
- [aDecoder decodeValueOfObjCType: @encode(BOOL)
- at: &_autoResizesOutlineColumn];
- [aDecoder decodeValueOfObjCType: @encode(BOOL)
- at: &_indentationMarkerFollowsCell];
- [aDecoder decodeValueOfObjCType: @encode(BOOL)
- at: &_autosaveExpandedItems];
- [aDecoder decodeValueOfObjCType: @encode(float)
- at: &indentation];
- _indentationPerLevel = indentation;
- _outlineTableColumn = [aDecoder decodeObject];
+ float indentation;
+ // overrides outline defaults with archived values
+ [aDecoder decodeValueOfObjCType: @encode(BOOL)
+ at: &_autoResizesOutlineColumn];
+ [aDecoder decodeValueOfObjCType: @encode(BOOL)
+ at: &_indentationMarkerFollowsCell];
+ [aDecoder decodeValueOfObjCType: @encode(BOOL)
+ at: &_autosaveExpandedItems];
+ [aDecoder decodeValueOfObjCType: @encode(float)
+ at: &indentation];
+ _indentationPerLevel = indentation;
+ _outlineTableColumn = [aDecoder decodeObject];
}
- return self;
+ return self;
}
- (void) mouseDown: (NSEvent *)theEvent
{
- NSPoint location = [theEvent locationInWindow];
-
- location = [self convertPoint: location fromView: nil];
- _clickedRow = [self rowAtPoint: location];
- _clickedColumn = [self columnAtPoint: location];
-
- if (_clickedRow != -1
- && [_tableColumns objectAtIndex: _clickedColumn] == _outlineTableColumn)
+ NSPoint location = [theEvent locationInWindow];
+
+ location = [self convertPoint: location fromView: nil];
+ _clickedRow = [self rowAtPoint: location];
+ _clickedColumn = [self columnAtPoint: location];
+
+ if (_clickedRow != -1
+ && [_tableColumns objectAtIndex: _clickedColumn] == _outlineTableColumn)
{
- NSImage *image;
-
- id item = [self itemAtRow:_clickedRow];
- int level = [self levelForRow: _clickedRow];
- int position = 0;
-
- if ([self isItemExpanded: item])
+ NSImage *image;
+
+ id item = [self itemAtRow:_clickedRow];
+ int level = [self levelForRow: _clickedRow];
+ int position = 0;
+
+ if ([self isItemExpanded: item])
{
- image = expanded;
+ image = expanded;
}
- else
+ else
{
- image = collapsed;
+ image = collapsed;
}
-
- if (_indentationMarkerFollowsCell)
+
+ if (_indentationMarkerFollowsCell)
{
- position = _indentationPerLevel * level;
+ position = _indentationPerLevel * level;
}
-
- position += _columnOrigins[_clickedColumn];
-
- if ([self isExpandable:item]
- && location.x >= position
- && location.x <= position + [image size].width)
+
+ position += _columnOrigins[_clickedColumn];
+
+ if ([self isExpandable:item]
+ && location.x >= position
+ && location.x <= position + [image size].width)
{
- BOOL withChildren =
- ([theEvent modifierFlags] & NSAlternateKeyMask) ? YES : NO;
- if (![self isItemExpanded: item])
+ BOOL withChildren =
+ ([theEvent modifierFlags] & NSAlternateKeyMask) ? YES : NO;
+ if (![self isItemExpanded: item])
{
- [self expandItem: item expandChildren: withChildren];
+ [self expandItem: item expandChildren: withChildren];
}
- else
+ else
{
- [self collapseItem: item collapseChildren: withChildren];
+ [self collapseItem: item collapseChildren: withChildren];
}
- return;
+ return;
}
}
-
- [super mouseDown: theEvent];
+
+ [super mouseDown: theEvent];
}
- (void)keyDown: (NSEvent*)event
{
- NSString *characters = [event characters];
-
- if ([characters length] == 1)
- {
- unichar c = [characters characterAtIndex: 0];
-
- NSIndexSet *selected = [self selectedRowIndexes];
- NSInteger i;
- for (i = [selected firstIndex]; i != NSNotFound; i = [selected indexGreaterThanIndex: i])
- {
- id item = [self itemAtRow: i];
- switch (c)
- {
- case NSLeftArrowFunctionKey:
- {
- if ([self isItemExpanded: item])
- {
- [self collapseItem: item];
- }
- else
- {
- id parent = [self parentForItem: item];
- if (parent != nil)
- {
- NSInteger parentRow = [self rowForItem: parent];
- [self selectRow: parentRow
- byExtendingSelection: NO];
- [self scrollRowToVisible: parentRow];
- }
- }
- return;
- }
- case NSRightArrowFunctionKey:
- [self expandItem: item];
- return;
- default:
- break;
- }
- }
- }
-
- [super keyDown: event];
+ NSString *characters = [event characters];
+
+ if ([characters length] == 1)
+ {
+ unichar c = [characters characterAtIndex: 0];
+
+ NSIndexSet *selected = [self selectedRowIndexes];
+ NSInteger i;
+ for (i = [selected firstIndex]; i != NSNotFound; i = [selected indexGreaterThanIndex: i])
+ {
+ id item = [self itemAtRow: i];
+ switch (c)
+ {
+ case NSLeftArrowFunctionKey:
+ {
+ if ([self isItemExpanded: item])
+ {
+ [self collapseItem: item];
+ }
+ else
+ {
+ id parent = [self parentForItem: item];
+ if (parent != nil)
+ {
+ NSInteger parentRow = [self rowForItem: parent];
+ [self selectRow: parentRow
+ byExtendingSelection: NO];
+ [self scrollRowToVisible: parentRow];
+ }
+ }
+ return;
+ }
+ case NSRightArrowFunctionKey:
+ [self expandItem: item];
+ return;
+ default:
+ break;
+ }
+ }
+ }
+
+ [super keyDown: event];
}
/*
@@ -913,169 +913,169 @@ name: NSOutlineView##notif_name##Notification object: self]
*/
- (void) drawRow: (int)rowIndex clipRect: (NSRect)aRect
{
- int startingColumn;
- int endingColumn;
- NSTableColumn *tb;
- NSRect drawingRect;
- NSCell *cell;
- NSCell *imageCell = nil;
- NSRect imageRect;
- int i;
- float x_pos;
-
- if (_dataSource == nil)
+ int startingColumn;
+ int endingColumn;
+ NSTableColumn *tb;
+ NSRect drawingRect;
+ NSCell *cell;
+ NSCell *imageCell = nil;
+ NSRect imageRect;
+ int i;
+ float x_pos;
+
+ if (_dataSource == nil)
{
- return;
+ return;
}
-
- /* Using columnAtPoint: here would make it called twice per row per drawn
+
+ /* Using columnAtPoint: here would make it called twice per row per drawn
rect - so we avoid it and do it natively */
-
- if (rowIndex >= _numberOfRows)
+
+ if (rowIndex >= _numberOfRows)
{
- return;
+ return;
}
-
- /* Determine starting column as fast as possible */
- x_pos = NSMinX (aRect);
- i = 0;
- while ((i < _numberOfColumns) && (x_pos > _columnOrigins[i]))
+
+ /* Determine starting column as fast as possible */
+ x_pos = NSMinX (aRect);
+ i = 0;
+ while ((i < _numberOfColumns) && (x_pos > _columnOrigins[i]))
{
- i++;
+ i++;
}
- startingColumn = (i - 1);
-
- if (startingColumn == -1)
- startingColumn = 0;
-
- /* Determine ending column as fast as possible */
- x_pos = NSMaxX (aRect);
- // Nota Bene: we do *not* reset i
- while ((i < _numberOfColumns) && (x_pos > _columnOrigins[i]))
+ startingColumn = (i - 1);
+
+ if (startingColumn == -1)
+ startingColumn = 0;
+
+ /* Determine ending column as fast as possible */
+ x_pos = NSMaxX (aRect);
+ // Nota Bene: we do *not* reset i
+ while ((i < _numberOfColumns) && (x_pos > _columnOrigins[i]))
{
- i++;
+ i++;
}
- endingColumn = (i - 1);
-
- if (endingColumn == -1)
- endingColumn = _numberOfColumns - 1;
-
- /* Draw the row between startingColumn and endingColumn */
- for (i = startingColumn; i <= endingColumn; i++)
+ endingColumn = (i - 1);
+
+ if (endingColumn == -1)
+ endingColumn = _numberOfColumns - 1;
+
+ /* Draw the row between startingColumn and endingColumn */
+ for (i = startingColumn; i <= endingColumn; i++)
{
- id item = [self itemAtRow: rowIndex];
-
- tb = [_tableColumns objectAtIndex: i];
- cell = [self _dataCellForTableColumn: tb row: rowIndex];
- if (i == _editedColumn && rowIndex == _editedRow)
- [cell _setInEditing: YES];
- [self _willDisplayCell: cell
- forTableColumn: tb
- row: rowIndex];
- [cell setObjectValue: [_dataSource outlineView: self
- objectValueForTableColumn: tb
- byItem: item]];
- drawingRect = [self frameOfCellAtColumn: i
- row: rowIndex];
-
- if (tb == _outlineTableColumn)
+ id item = [self itemAtRow: rowIndex];
+
+ tb = [_tableColumns objectAtIndex: i];
+ cell = [self _dataCellForTableColumn: tb row: rowIndex];
+ if (i == _editedColumn && rowIndex == _editedRow)
+ [cell _setInEditing: YES];
+ [self _willDisplayCell: cell
+ forTableColumn: tb
+ row: rowIndex];
+ [cell setObjectValue: [_dataSource outlineView: self
+ objectValueForTableColumn: tb
+ byItem: item]];
+ drawingRect = [self frameOfCellAtColumn: i
+ row: rowIndex];
+
+ if (tb == _outlineTableColumn)
{
- NSImage *image = nil;
- NSInteger level = 0;
- CGFloat indentationFactor = 0.0;
- // float originalWidth = drawingRect.size.width;
-
- // display the correct arrow...
- if ([self isItemExpanded: item])
+ NSImage *image = nil;
+ NSInteger level = 0;
+ CGFloat indentationFactor = 0.0;
+ // float originalWidth = drawingRect.size.width;
+
+ // display the correct arrow...
+ if ([self isItemExpanded: item])
{
- image = expanded;
+ image = expanded;
}
- else
+ else
{
- image = collapsed;
+ image = collapsed;
}
-
- if (![self isExpandable: item])
+
+ if (![self isExpandable: item])
{
- image = unexpandable;
+ image = unexpandable;
}
-
- level = [self levelForItem: item];
- indentationFactor = _indentationPerLevel * level;
- imageCell = [[NSCell alloc] initImageCell: image];
- imageRect = [self frameOfOutlineCellAtRow: rowIndex];
-
- if ([_delegate respondsToSelector: @selector(outlineView:willDisplayOutlineCell:forTableColumn:item:)])
+
+ level = [self levelForItem: item];
+ indentationFactor = _indentationPerLevel * level;
+ imageCell = [[NSCell alloc] initImageCell: image];
+ imageRect = [self frameOfOutlineCellAtRow: rowIndex];
+
+ if ([_delegate respondsToSelector: @selector(outlineView:willDisplayOutlineCell:forTableColumn:item:)])
{
- [_delegate outlineView: self
- willDisplayOutlineCell: imageCell
- forTableColumn: tb
- item: item];
+ [_delegate outlineView: self
+ willDisplayOutlineCell: imageCell
+ forTableColumn: tb
+ item: item];
}
-
- /* Do not indent if the delegate set the image to nil. */
- if ([imageCell image])
+
+ /* Do not indent if the delegate set the image to nil. */
+ if ([imageCell image])
{
- imageRect.size.width = [image size].width;
- imageRect.size.height = [image size].height;
- [imageCell drawWithFrame: imageRect inView: self];
- drawingRect.origin.x
+ imageRect.size.width = [image size].width;
+ imageRect.size.height = [image size].height;
+ [imageCell drawWithFrame: imageRect inView: self];
+ drawingRect.origin.x
+= indentationFactor + imageRect.size.width + 5;
- drawingRect.size.width
+ drawingRect.size.width
-= indentationFactor + imageRect.size.width + 5;
}
- else
+ else
{
- drawingRect.origin.x += indentationFactor;
- drawingRect.size.width -= indentationFactor;
+ drawingRect.origin.x += indentationFactor;
+ drawingRect.size.width -= indentationFactor;
}
-
- RELEASE(imageCell);
+
+ RELEASE(imageCell);
}
-
- [cell drawWithFrame: drawingRect inView: self];
- if (i == _editedColumn && rowIndex == _editedRow)
- [cell _setInEditing: NO];
+
+ [cell drawWithFrame: drawingRect inView: self];
+ if (i == _editedColumn && rowIndex == _editedRow)
+ [cell _setInEditing: NO];
}
}
- (void) drawRect: (NSRect)aRect
{
- int index = 0;
-
- if (_autoResizesOutlineColumn)
+ int index = 0;
+
+ if (_autoResizesOutlineColumn)
{
- float widest = 0;
- for (index = 0; index < _numberOfRows; index++)
+ float widest = 0;
+ for (index = 0; index < _numberOfRows; index++)
{
- float offset = [self levelForRow: index] *
+ float offset = [self levelForRow: index] *
[self indentationPerLevel];
- NSRect drawingRect = [self frameOfCellAtColumn: 0
- row: index];
- float length = drawingRect.size.width + offset;
- if (widest < length) widest = length;
+ NSRect drawingRect = [self frameOfCellAtColumn: 0
+ row: index];
+ float length = drawingRect.size.width + offset;
+ if (widest < length) widest = length;
}
- // [_outlineTableColumn setWidth: widest];
+ // [_outlineTableColumn setWidth: widest];
}
-
- [super drawRect: aRect];
+
+ [super drawRect: aRect];
}
- (void) setDropItem: (id)item
dropChildIndex: (NSInteger)childIndex
{
-
- if (item != nil && [_items indexOfObject: item] == NSNotFound)
+
+ if (item != nil && [_items indexOfObject: item] == NSNotFound)
{
- /* FIXME raise an exception, or perhaps we should support
- * setting an item which is not visible (inside a collapsed
- * item presumably), or perhaps we should treat this as
- * cancelling the drop?
- */
- return;
+ /* FIXME raise an exception, or perhaps we should support
+ * setting an item which is not visible (inside a collapsed
+ * item presumably), or perhaps we should treat this as
+ * cancelling the drop?
+ */
+ return;
}
- currentDropItem = item;
- currentDropIndex = childIndex;
+ currentDropItem = item;
+ currentDropIndex = childIndex;
}
/*
@@ -1084,454 +1084,453 @@ name: NSOutlineView##notif_name##Notification object: self]
- (NSDragOperation) draggingEntered: (id ) sender
{
- //NSLog(@"draggingEntered");
- oldDropItem = currentDropItem = nil;
- oldDropIndex = currentDropIndex = -1;
- lastVerticalQuarterPosition = -1;
- dragOperation = NSDragOperationCopy;
- oldDraggingRect = NSMakeRect(0.,0., 0., 0.);
- return NSDragOperationCopy;
+ //NSLog(@"draggingEntered");
+ oldDropItem = currentDropItem = nil;
+ oldDropIndex = currentDropIndex = -1;
+ lastVerticalQuarterPosition = -1;
+ dragOperation = NSDragOperationCopy;
+ oldDraggingRect = NSMakeRect(0.,0., 0., 0.);
+ return NSDragOperationCopy;
}
- (void) draggingExited: (id ) sender
{
- [self setNeedsDisplayInRect: oldDraggingRect];
- [self _autoCollapse];
- [self displayIfNeeded];
- DESTROY(lastDragUpdate);
- DESTROY(lastDragChange);
+ [self setNeedsDisplayInRect: oldDraggingRect];
+ [self _autoCollapse];
+ [self displayIfNeeded];
+ DESTROY(lastDragUpdate);
+ DESTROY(lastDragChange);
}
// TODO: Move the part that starts at 'Compute the indicator rect area' to GSTheme
-- (void) drawDropAboveIndicatorWithDropItem: (id)currentDropItem
- atRow: (int)row
+- (void) drawDropAboveIndicatorWithDropItem: (id)currentDropItem
+ atRow: (int)row
childDropIndex: (int)currentDropIndex
{
- int level = 0;
- NSBezierPath *path = nil;
- NSRect newRect = NSZeroRect;
-
- /* Compute the indicator rect area */
- if (currentDropItem == nil && currentDropIndex == 0)
+ int level = 0;
+ NSBezierPath *path = nil;
+ NSRect newRect = NSZeroRect;
+
+ /* Compute the indicator rect area */
+ if (currentDropItem == nil && currentDropIndex == 0)
{
- newRect = NSMakeRect([self visibleRect].origin.x,
- 0,
- [self visibleRect].size.width,
- 2);
+ newRect = NSMakeRect([self visibleRect].origin.x,
+ 0,
+ [self visibleRect].size.width,
+ 2);
}
- else if (row == _numberOfRows)
+ else if (row == _numberOfRows)
{
- newRect = NSMakeRect([self visibleRect].origin.x,
- row * _rowHeight - 2,
- [self visibleRect].size.width,
- 2);
+ newRect = NSMakeRect([self visibleRect].origin.x,
+ row * _rowHeight - 2,
+ [self visibleRect].size.width,
+ 2);
}
- else
+ else
{
- newRect = NSMakeRect([self visibleRect].origin.x,
- row * _rowHeight - 1,
- [self visibleRect].size.width,
- 2);
+ newRect = NSMakeRect([self visibleRect].origin.x,
+ row * _rowHeight - 1,
+ [self visibleRect].size.width,
+ 2);
}
- level = [self levelForItem: currentDropItem] + 1;
- newRect.origin.x += level * _indentationPerLevel;
- newRect.size.width -= level * _indentationPerLevel;
-
- [[NSColor darkGrayColor] set];
-
- /* The rectangle is a line across the cell indicating the
- * insertion position. We adjust by enough pixels to allow for
- * a ring drawn on the left end.
- */
- newRect.size.width -= 7;
- newRect.origin.x += 7;
- NSRectFill(newRect);
-
- /* We make the redraw rectangle big enough to hold both the
- * line and the circle (8 pixels high).
- */
- newRect.size.width += 7;
- newRect.origin.x -= 7;
- newRect.size.height = 8;
- newRect.origin.y -= 3;
- oldDraggingRect = newRect;
- if (newRect.size.width < 8)
- oldDraggingRect.size.width = 8;
-
- /* We draw the circle at the left of the line, and make it
- * a little smaller than the redraw rectangle so that the
- * bezier path will draw entirely inside the redraw area
- * and we won't leave artifacts behind on the screen.
- */
- newRect.size.width = 7;
- newRect.size.height = 7;
- newRect.origin.x += 0.5;
- newRect.origin.y += 0.5;
- path = [NSBezierPath bezierPath];
- [path appendBezierPathWithOvalInRect: newRect];
- [path stroke];
+ level = [self levelForItem: currentDropItem] + 1;
+ newRect.origin.x += level * _indentationPerLevel;
+ newRect.size.width -= level * _indentationPerLevel;
+
+ [[NSColor darkGrayColor] set];
+
+ /* The rectangle is a line across the cell indicating the
+ * insertion position. We adjust by enough pixels to allow for
+ * a ring drawn on the left end.
+ */
+ newRect.size.width -= 7;
+ newRect.origin.x += 7;
+ NSRectFill(newRect);
+
+ /* We make the redraw rectangle big enough to hold both the
+ * line and the circle (8 pixels high).
+ */
+ newRect.size.width += 7;
+ newRect.origin.x -= 7;
+ newRect.size.height = 8;
+ newRect.origin.y -= 3;
+ oldDraggingRect = newRect;
+ if (newRect.size.width < 8)
+ oldDraggingRect.size.width = 8;
+
+ /* We draw the circle at the left of the line, and make it
+ * a little smaller than the redraw rectangle so that the
+ * bezier path will draw entirely inside the redraw area
+ * and we won't leave artifacts behind on the screen.
+ */
+ newRect.size.width = 7;
+ newRect.size.height = 7;
+ newRect.origin.x += 0.5;
+ newRect.origin.y += 0.5;
+ path = [NSBezierPath bezierPath];
+ [path appendBezierPathWithOvalInRect: newRect];
+ [path stroke];
}
/* When the drop item is nil and the drop child index is -1 */
- (void) drawDropOnRootIndicator
{
- NSRect indicatorRect = [self visibleRect];
-
- /* Remember indicator area to be redrawn next time */
- oldDraggingRect = indicatorRect;
-
- [[NSColor darkGrayColor] set];
- NSFrameRectWithWidth(indicatorRect, 2.0);
+ NSRect indicatorRect = [self visibleRect];
+
+ /* Remember indicator area to be redrawn next time */
+ oldDraggingRect = indicatorRect;
+
+ [[NSColor darkGrayColor] set];
+ NSFrameRectWithWidth(indicatorRect, 2.0);
}
// TODO: Move a method common to -drapOnRootIndicator and the one below to GSTheme
- (void) drawDropOnIndicatorWithDropItem: (id)currentDropItem
{
- int row = [_items indexOfObject: currentDropItem];
- int level = [self levelForItem: currentDropItem];
- NSRect newRect = [self frameOfCellAtColumn: 0
- row: row];
-
- newRect.origin.x = _bounds.origin.x;
- newRect.size.width = _bounds.size.width + 2;
- newRect.origin.x -= _intercellSpacing.height / 2;
- newRect.size.height += _intercellSpacing.height;
-
- /* Remember indicator area to be redrawn next time */
- oldDraggingRect = newRect;
- oldDraggingRect.origin.y -= 1;
- oldDraggingRect.size.height += 2;
-
- newRect.size.height -= 1;
- newRect.origin.x += 3;
- newRect.size.width -= 3;
-
- if (_drawsGrid)
+ int row = [_items indexOfObject: currentDropItem];
+ int level = [self levelForItem: currentDropItem];
+ NSRect newRect = [self frameOfCellAtColumn: 0
+ row: row];
+
+ newRect.origin.x = _bounds.origin.x;
+ newRect.size.width = _bounds.size.width + 2;
+ newRect.origin.x -= _intercellSpacing.height / 2;
+ newRect.size.height += _intercellSpacing.height;
+
+ /* Remember indicator area to be redrawn next time */
+ oldDraggingRect = newRect;
+ oldDraggingRect.origin.y -= 1;
+ oldDraggingRect.size.height += 2;
+
+ newRect.size.height -= 1;
+ newRect.origin.x += 3;
+ newRect.size.width -= 3;
+
+ if (_drawsGrid)
{
- //newRect.origin.y += 1;
- //newRect.origin.x += 1;
- //newRect.size.width -= 2;
- newRect.size.height += 1;
+ //newRect.origin.y += 1;
+ //newRect.origin.x += 1;
+ //newRect.size.width -= 2;
+ newRect.size.height += 1;
}
-
- newRect.origin.x += level * _indentationPerLevel;
- newRect.size.width -= level * _indentationPerLevel;
-
- [[NSColor darkGrayColor] set];
- NSFrameRectWithWidth(newRect, 2.0);
+
+ newRect.origin.x += level * _indentationPerLevel;
+ newRect.size.width -= level * _indentationPerLevel;
+
+ [[NSColor darkGrayColor] set];
+ NSFrameRectWithWidth(newRect, 2.0);
}
-/* Returns the row whose item is the parent that owns the child at the given row.
- Also returns the child index relative to this parent. */
-- (NSInteger) _parentRowForRow: (NSInteger)row
- atLevel: (NSInteger)level
+/* Returns the row whose item is the parent that owns the child at the given row.
+Also returns the child index relative to this parent. */
+- (NSInteger) _parentRowForRow: (NSInteger)row
+ atLevel: (NSInteger)level
andReturnChildIndex: (NSInteger *)childIndex
{
- NSInteger i;
- NSInteger lvl;
-
- *childIndex = 0;
-
- for (i = row - 1; i >= 0; i--)
+ NSInteger i;
+ NSInteger lvl;
+
+ *childIndex = 0;
+
+ for (i = row - 1; i >= 0; i--)
{
- BOOL foundParent;
- BOOL foundSibling;
-
- lvl = [self levelForRow: i];
-
- foundParent = (lvl == level - 1);
- foundSibling = (lvl == level);
-
- if (foundParent)
- {
- break;
- }
- else if (foundSibling)
- {
- (*childIndex)++;
- }
+ BOOL foundParent;
+ BOOL foundSibling;
+
+ lvl = [self levelForRow: i];
+
+ foundParent = (lvl == level - 1);
+ foundSibling = (lvl == level);
+
+ if (foundParent)
+ {
+ break;
+ }
+ else if (foundSibling)
+ {
+ (*childIndex)++;
+ }
}
-
- return i;
+
+ return i;
}
- (NSDragOperation) draggingUpdated: (id ) sender
{
- NSPoint p = [self convertPoint: [sender draggingLocation] fromView: nil];
- /* The insertion row.
- * The insertion row is identical to the hovered row, except when p is in
- * the hovered row bottom part (the last quarter).
- */
- NSInteger row;
- /* A row can be divided into 4 vertically stacked portions.
- * We call each portion a quarter.
- * verticalQuarterPosition is the number of quarters that exists between the
- * top left origin (NSOutlineView is flipped) and the hovered row (precisely
- * up to the quarter occupied by the pointer in this row).
- */
- NSInteger verticalQuarterPosition;
- /* An indentation unit can be divided into 2 portions (left and right).
- * We call each portion a half.
- * We use it to compute the insertion level. */
- NSInteger horizontalHalfPosition;
- /* The quarter (0, 1, 2 or 3) occupied by the pointer within the hovered row
- * (not in the insertion row). */
- NSInteger positionInRow;
- /* The previous row level (the row before the insertion row) */
- NSInteger levelBefore;
- /* The next row level (the row after the insertion row) */
- NSInteger levelAfter;
- /* The insertion level that may vary with the horizontal pointer position,
- * when the pointer is between two rows and the bottom row is a parent.
- */
- NSInteger level;
-
-
- ASSIGN(lastDragUpdate, [NSDate date]);
- //NSLog(@"draggingUpdated");
-
- /* _bounds.origin is (0, 0) when the outline view is not clipped.
- * When the view is scrolled, _bounds.origin.y returns the scrolled height. */
- verticalQuarterPosition =
+ NSPoint p = [self convertPoint: [sender draggingLocation] fromView: nil];
+ /* The insertion row.
+ * The insertion row is identical to the hovered row, except when p is in
+ * the hovered row bottom part (the last quarter).
+ */
+ NSInteger row;
+ /* A row can be divided into 4 vertically stacked portions.
+ * We call each portion a quarter.
+ * verticalQuarterPosition is the number of quarters that exists between the
+ * top left origin (NSOutlineView is flipped) and the hovered row (precisely
+ * up to the quarter occupied by the pointer in this row).
+ */
+ NSInteger verticalQuarterPosition;
+ /* An indentation unit can be divided into 2 portions (left and right).
+ * We call each portion a half.
+ * We use it to compute the insertion level. */
+ NSInteger horizontalHalfPosition;
+ /* The quarter (0, 1, 2 or 3) occupied by the pointer within the hovered row
+ * (not in the insertion row). */
+ NSInteger positionInRow;
+ /* The previous row level (the row before the insertion row) */
+ NSInteger levelBefore;
+ /* The next row level (the row after the insertion row) */
+ NSInteger levelAfter;
+ /* The insertion level that may vary with the horizontal pointer position,
+ * when the pointer is between two rows and the bottom row is a parent.
+ */
+ NSInteger level;
+
+
+ ASSIGN(lastDragUpdate, [NSDate date]);
+ //NSLog(@"draggingUpdated");
+
+ /* _bounds.origin is (0, 0) when the outline view is not clipped.
+ * When the view is scrolled, _bounds.origin.y returns the scrolled height. */
+ verticalQuarterPosition =
GSRoundTowardsInfinity(((p.y + _bounds.origin.y) / _rowHeight) * 4.);
- horizontalHalfPosition =
+ horizontalHalfPosition =
GSRoundTowardsInfinity(((p.x + _bounds.origin.y) / _indentationPerLevel) * 2.);
-
- /* We add an extra quarter to shift the insertion row below the hovered row. */
- row = (verticalQuarterPosition + 1) / 4;
- positionInRow = verticalQuarterPosition % 4;
- if (row > _numberOfRows)
+
+ /* We add an extra quarter to shift the insertion row below the hovered row. */
+ row = (verticalQuarterPosition + 1) / 4;
+ positionInRow = verticalQuarterPosition % 4;
+ if (row > _numberOfRows)
{
- row = _numberOfRows; // beyond the last real row
- positionInRow = 1; // inside the root item (we could also use 2)
+ row = _numberOfRows; // beyond the last real row
+ positionInRow = 1; // inside the root item (we could also use 2)
}
-
- //NSLog(@"horizontalHalfPosition = %d", horizontalHalfPosition);
- //NSLog(@"verticalQuarterPosition = %d", verticalQuarterPosition);
- //NSLog(@"insertion row = %d", row);
-
- if (row == 0)
+
+ //NSLog(@"horizontalHalfPosition = %d", horizontalHalfPosition);
+ //NSLog(@"verticalQuarterPosition = %d", verticalQuarterPosition);
+ //NSLog(@"insertion row = %d", row);
+
+ if (row == 0)
{
- levelBefore = 0;
+ levelBefore = 0;
}
- else
+ else
{
- levelBefore = [self levelForRow: (row - 1)];
+ levelBefore = [self levelForRow: (row - 1)];
}
- if (row == _numberOfRows)
+ if (row == _numberOfRows)
{
- levelAfter = 0;
+ levelAfter = 0;
}
- else
+ else
{
- levelAfter = [self levelForRow: row];
+ levelAfter = [self levelForRow: row];
}
- //NSLog(@"level before = %d", levelBefore);
- //NSLog(@"level after = %d", levelAfter);
-
- if ((lastVerticalQuarterPosition != verticalQuarterPosition)
- || (lastHorizontalHalfPosition != horizontalHalfPosition))
+ //NSLog(@"level before = %d", levelBefore);
+ //NSLog(@"level after = %d", levelAfter);
+
+ if ((lastVerticalQuarterPosition != verticalQuarterPosition)
+ || (lastHorizontalHalfPosition != horizontalHalfPosition))
{
- NSInteger minInsertionLevel = levelAfter;
- NSInteger maxInsertionLevel = levelBefore;
- NSInteger pointerInsertionLevel = GSRoundTowardsInfinity((float)horizontalHalfPosition / 2.);
-
- /* Save positions to avoid executing this code when the general
- * position of the mouse is unchanged.
- */
- lastVerticalQuarterPosition = verticalQuarterPosition;
- lastHorizontalHalfPosition = horizontalHalfPosition;
-
- /* When the row before is an empty parent, we allow to insert the dragged
- * item as its child.
- */
- if ([self isExpandable: [self itemAtRow: (row - 1)]])
+ NSInteger minInsertionLevel = levelAfter;
+ NSInteger maxInsertionLevel = levelBefore;
+ NSInteger pointerInsertionLevel = GSRoundTowardsInfinity((float)horizontalHalfPosition / 2.);
+
+ /* Save positions to avoid executing this code when the general
+ * position of the mouse is unchanged.
+ */
+ lastVerticalQuarterPosition = verticalQuarterPosition;
+ lastHorizontalHalfPosition = horizontalHalfPosition;
+
+ /* When the row before is an empty parent, we allow to insert the dragged
+ * item as its child.
+ */
+ if ([self isExpandable: [self itemAtRow: (row - 1)]])
{
- maxInsertionLevel++;
+ maxInsertionLevel++;
+ }
+
+ /* Find the insertion level to be used with a drop above
+ *
+ * In the outline below, when the pointer moves horizontally on
+ * the dashed line, it can insert at three levels: x level, C level or
+ * B/D level but not at A level.
+ *
+ * + A
+ * + B
+ * + C
+ * - x
+ * --- pointer ---
+ * + D
+ */
+ if (pointerInsertionLevel < minInsertionLevel)
+ {
+ level = minInsertionLevel;
}
-
- /* Find the insertion level to be used with a drop above
- *
- * In the outline below, when the pointer moves horizontally on
- * the dashed line, it can insert at three levels: x level, C level or
- * B/D level but not at A level.
- *
- * + A
- * + B
- * + C
- * - x
- * --- pointer ---
- * + D
- */
- if (pointerInsertionLevel < minInsertionLevel)
+ else if (pointerInsertionLevel > maxInsertionLevel)
{
- level = minInsertionLevel;
+ level = maxInsertionLevel;
}
- else if (pointerInsertionLevel > maxInsertionLevel)
+ else
{
- level = maxInsertionLevel;
+ level = pointerInsertionLevel;
}
- else
+
+ //NSLog(@"min insert level = %d", minInsertionLevel);
+ //NSLog(@"max insert level = %d", maxInsertionLevel);
+ //NSLog(@"insert level = %d", level);
+ //NSLog(@"row = %d and position in row = %d", row, positionInRow);
+
+ if (positionInRow > 0 && positionInRow < 3) /* Drop on */
+ {
+ /* We are directly over the middle of a row ... so the drop
+ * should be directory on the item in that row.
+ */
+ currentDropItem = [self itemAtRow: row];
+ currentDropIndex = NSOutlineViewDropOnItemIndex;
+ }
+ else /* Drop above */
+ {
+ NSInteger childIndex = 0;
+ NSInteger parentRow = [self _parentRowForRow: row
+ atLevel: level
+ andReturnChildIndex: &childIndex];
+
+ //NSLog(@"found %d (proposed childIndex = %d)", parentRow, childIndex);
+
+ currentDropItem = (parentRow == -1 ? nil : [self itemAtRow: parentRow]);
+ currentDropIndex = childIndex;
+ }
+
+ if ([_dataSource respondsToSelector:
+ @selector(outlineView:validateDrop:proposedItem:proposedChildIndex:)])
{
- level = pointerInsertionLevel;
+ dragOperation = [_dataSource outlineView: self
+ validateDrop: sender
+ proposedItem: currentDropItem
+ proposedChildIndex: currentDropIndex];
}
-
- //NSLog(@"min insert level = %d", minInsertionLevel);
- //NSLog(@"max insert level = %d", maxInsertionLevel);
- //NSLog(@"insert level = %d", level);
- //NSLog(@"row = %d and position in row = %d", row, positionInRow);
-
- if (positionInRow > 0 && positionInRow < 3) /* Drop on */
+
+ //NSLog(@"Drop on %@ %d", currentDropItem, currentDropIndex);
+
+ if ((currentDropItem != oldDropItem)
+ || (currentDropIndex != oldDropIndex))
{
- /* We are directly over the middle of a row ... so the drop
- * should be directory on the item in that row.
- */
- currentDropItem = [self itemAtRow: row];
- currentDropIndex = NSOutlineViewDropOnItemIndex;
- }
- else /* Drop above */
- {
- NSInteger childIndex = 0;
- NSInteger parentRow = [self _parentRowForRow: row
- atLevel: level
- andReturnChildIndex: &childIndex];
-
- //NSLog(@"found %d (proposed childIndex = %d)", parentRow, childIndex);
-
- currentDropItem = (parentRow == -1 ? nil : [self itemAtRow: parentRow]);
- currentDropIndex = childIndex;
- }
-
- if ([_dataSource respondsToSelector:
- @selector(outlineView:validateDrop:proposedItem:proposedChildIndex:)])
- {
- dragOperation = [_dataSource outlineView: self
- validateDrop: sender
- proposedItem: currentDropItem
- proposedChildIndex: currentDropIndex];
- }
-
- //NSLog(@"Drop on %@ %d", currentDropItem, currentDropIndex);
-
- if ((currentDropItem != oldDropItem)
- || (currentDropIndex != oldDropIndex))
- {
- oldDropItem = currentDropItem;
- oldDropIndex = currentDropIndex;
-
- ASSIGN(lastDragChange, lastDragUpdate);
- [self lockFocus];
-
- [self setNeedsDisplayInRect: oldDraggingRect];
- [self displayIfNeeded];
-
- if (dragOperation != NSDragOperationNone)
- {
- if (currentDropIndex != NSOutlineViewDropOnItemIndex && currentDropItem != nil)
- {
- [self drawDropAboveIndicatorWithDropItem: currentDropItem
- atRow: row
- childDropIndex: currentDropIndex];
- }
- else if (currentDropIndex == NSOutlineViewDropOnItemIndex && currentDropItem == nil)
- {
- [self drawDropOnRootIndicator];
- }
- else
- {
- [self drawDropOnIndicatorWithDropItem: currentDropItem];
- }
- }
-
- [_window flushWindow];
- [self unlockFocus];
-
+ oldDropItem = currentDropItem;
+ oldDropIndex = currentDropIndex;
+
+ ASSIGN(lastDragChange, lastDragUpdate);
+ [self lockFocus];
+
+ [self setNeedsDisplayInRect: oldDraggingRect];
+ [self displayIfNeeded];
+
+ if (dragOperation != NSDragOperationNone)
+ {
+ if (currentDropIndex != NSOutlineViewDropOnItemIndex && currentDropItem != nil)
+ {
+ [self drawDropAboveIndicatorWithDropItem: currentDropItem
+ atRow: row
+ childDropIndex: currentDropIndex];
+ }
+ else if (currentDropIndex == NSOutlineViewDropOnItemIndex && currentDropItem == nil)
+ {
+ [self drawDropOnRootIndicator];
+ }
+ else
+ {
+ [self drawDropOnIndicatorWithDropItem: currentDropItem];
+ }
+ }
+
+ [_window flushWindow];
+ [self unlockFocus];
+
}
}
- else if (row != _numberOfRows)
+ else if (row != _numberOfRows)
{
- /* If we have been hovering over an item for more than half a second,
- * we should expand it.
- */
- if (lastDragChange != nil && [lastDragUpdate timeIntervalSinceDate: lastDragChange] >= 0.5)
- {
- id item = [_items objectAtIndex: row];
- if ([self isExpandable: item] && ![self isItemExpanded: item])
- {
- [self expandItem: item expandChildren: NO];
- if ([self isItemExpanded: item])
- {
- [autoExpanded addObject: item];
- }
- }
- /* Set the change date even if we didn't actually expand ... so
- * we don't keep trying to expand the same item unnecessarily.
- */
- ASSIGN(lastDragChange, lastDragUpdate);
- }
+ /* If we have been hovering over an item for more than half a second,
+ * we should expand it.
+ */
+ if (lastDragChange != nil && [lastDragUpdate timeIntervalSinceDate: lastDragChange] >= 0.5)
+ {
+ id item = [_items objectAtIndex: row];
+ if ([self isExpandable: item] && ![self isItemExpanded: item])
+ {
+ [self expandItem: item expandChildren: NO];
+ if ([self isItemExpanded: item])
+ {
+ [autoExpanded addObject: item];
+ }
+ }
+ /* Set the change date even if we didn't actually expand ... so
+ * we don't keep trying to expand the same item unnecessarily.
+ */
+ ASSIGN(lastDragChange, lastDragUpdate);
+ }
}
-
- return dragOperation;
+
+ return dragOperation;
}
- (BOOL) performDragOperation: (id)sender
{
- BOOL result = NO;
-
- if ([_dataSource
- respondsToSelector:
- @selector(outlineView:acceptDrop:item:childIndex:)])
+ BOOL result = NO;
+
+ if ([_dataSource
+ respondsToSelector:
+ @selector(outlineView:acceptDrop:item:childIndex:)])
{
- result = [_dataSource outlineView: self
- acceptDrop: sender
- item: currentDropItem
- childIndex: currentDropIndex];
+ result = [_dataSource outlineView: self
+ acceptDrop: sender
+ item: currentDropItem
+ childIndex: currentDropIndex];
}
-
- [self _autoCollapse];
-
- return result;
+
+ [self _autoCollapse];
+
+ return result;
}
- (BOOL) prepareForDragOperation: (id)sender
{
- [self setNeedsDisplayInRect: oldDraggingRect];
- [self displayIfNeeded];
-
- return YES;
+ [self setNeedsDisplayInRect: oldDraggingRect];
+ [self displayIfNeeded];
+
+ return YES;
}
- (NSArray*) namesOfPromisedFilesDroppedAtDestination: (NSURL *)dropDestination
{
- if ([_dataSource respondsToSelector:
- @selector(outlineView:namesOfPromisedFilesDroppedAtDestination:forDraggedItems:)])
+ if ([_dataSource respondsToSelector:
+ @selector(outlineView:namesOfPromisedFilesDroppedAtDestination:forDraggedItems:)])
{
- NSUInteger count = [_selectedRows count];
- NSMutableArray *itemArray = [NSMutableArray arrayWithCapacity: count];
- NSUInteger index = [_selectedRows firstIndex];
-
- while (index != NSNotFound)
+ NSUInteger count = [_selectedRows count];
+ NSMutableArray *itemArray = [NSMutableArray arrayWithCapacity: count];
+ NSUInteger index = [_selectedRows firstIndex];
+
+ while (index != NSNotFound)
{
- [itemArray addObject: [self itemAtRow: index]];
- index = [_selectedRows indexGreaterThanIndex: index];
+ [itemArray addObject: [self itemAtRow: index]];
+ index = [_selectedRows indexGreaterThanIndex: index];
}
-
- return [_dataSource outlineView: self
-namesOfPromisedFilesDroppedAtDestination: dropDestination
- forDraggedItems: itemArray];
+
+ return [_dataSource outlineView: self
+ namesOfPromisedFilesDroppedAtDestination: dropDestination
+ forDraggedItems: itemArray];
}
- else
+ else
{
- return nil;
+ return nil;
}
}
-
// Autosave methods...
- (void) setAutosaveName: (NSString *)name
{
- [super setAutosaveName: name];
- [self _autoloadExpandedItems];
+ [super setAutosaveName: name];
+ [self _autoloadExpandedItems];
}
- (void) editColumn: (int) columnIndex
@@ -1539,66 +1538,66 @@ namesOfPromisedFilesDroppedAtDestination: dropDestination
withEvent: (NSEvent *) theEvent
select: (BOOL) flag
{
- NSText *t;
- NSTableColumn *tb;
- NSRect drawingRect;
- unsigned length = 0;
- int level = 0;
- float indentationFactor = 0.0;
-
- // We refuse to edit cells if the delegate can not accept results
- // of editing.
- if (_dataSource_editable == NO)
+ NSText *t;
+ NSTableColumn *tb;
+ NSRect drawingRect;
+ unsigned length = 0;
+ int level = 0;
+ float indentationFactor = 0.0;
+
+ // We refuse to edit cells if the delegate can not accept results
+ // of editing.
+ if (_dataSource_editable == NO)
{
- flag = YES;
+ flag = YES;
}
-
- [self scrollRowToVisible: rowIndex];
- [self scrollColumnToVisible: columnIndex];
-
- if (rowIndex < 0 || rowIndex >= _numberOfRows
- || columnIndex < 0 || columnIndex >= _numberOfColumns)
+
+ [self scrollRowToVisible: rowIndex];
+ [self scrollColumnToVisible: columnIndex];
+
+ if (rowIndex < 0 || rowIndex >= _numberOfRows
+ || columnIndex < 0 || columnIndex >= _numberOfColumns)
{
- [NSException raise: NSInvalidArgumentException
- format: @"Row/column out of index in edit"];
+ [NSException raise: NSInvalidArgumentException
+ format: @"Row/column out of index in edit"];
}
-
- if (_textObject != nil)
+
+ if (_textObject != nil)
{
- [self validateEditing];
- [self abortEditing];
+ [self validateEditing];
+ [self abortEditing];
}
-
- // Now (_textObject == nil)
-
- t = [_window fieldEditor: YES forObject: self];
-
- if ([t superview] != nil)
+
+ // Now (_textObject == nil)
+
+ t = [_window fieldEditor: YES forObject: self];
+
+ if ([t superview] != nil)
{
- if ([t resignFirstResponder] == NO)
+ if ([t resignFirstResponder] == NO)
{
- return;
+ return;
}
}
-
- _editedRow = rowIndex;
- _editedColumn = columnIndex;
-
- // Prepare the cell
- tb = [_tableColumns objectAtIndex: columnIndex];
- // NB: need to be released when no longer used
- _editedCell = [[self _dataCellForTableColumn: tb row: rowIndex] copy];
-
- [_editedCell setEditable: _dataSource_editable];
- [_editedCell setObjectValue: [self _objectValueForTableColumn: tb
- row: rowIndex]];
-
- // But of course the delegate can mess it up if it wants
- [self _willDisplayCell: _editedCell
- forTableColumn: tb
- row: rowIndex];
-
- /* Please note the important point - calling stringValue normally
+
+ _editedRow = rowIndex;
+ _editedColumn = columnIndex;
+
+ // Prepare the cell
+ tb = [_tableColumns objectAtIndex: columnIndex];
+ // NB: need to be released when no longer used
+ _editedCell = [[self _dataCellForTableColumn: tb row: rowIndex] copy];
+
+ [_editedCell setEditable: _dataSource_editable];
+ [_editedCell setObjectValue: [self _objectValueForTableColumn: tb
+ row: rowIndex]];
+
+ // But of course the delegate can mess it up if it wants
+ [self _willDisplayCell: _editedCell
+ forTableColumn: tb
+ row: rowIndex];
+
+ /* Please note the important point - calling stringValue normally
causes the _editedCell to call the validateEditing method of its
control view ... which happens to be this object :-)
but we don't want any spurious validateEditing to be performed
@@ -1608,100 +1607,100 @@ namesOfPromisedFilesDroppedAtDestination: dropDestination
edit somewhere else ... getting into the bug that when you TAB
from one cell to another one, the string is copied!), so we must
call stringValue when _textObject is still nil. */
- if (flag)
+ if (flag)
{
- length = [[_editedCell stringValue] length];
+ length = [[_editedCell stringValue] length];
}
-
- _textObject = [_editedCell setUpFieldEditorAttributes: t];
- // FIXME: Which background color do we want here?
- [_textObject setBackgroundColor: [NSColor selectedControlColor]];
- [_textObject setDrawsBackground: YES];
-
- drawingRect = [self frameOfCellAtColumn: columnIndex row: rowIndex];
-
- if (tb == [self outlineTableColumn])
+
+ _textObject = [_editedCell setUpFieldEditorAttributes: t];
+ // FIXME: Which background color do we want here?
+ [_textObject setBackgroundColor: [NSColor selectedControlColor]];
+ [_textObject setDrawsBackground: YES];
+
+ drawingRect = [self frameOfCellAtColumn: columnIndex row: rowIndex];
+
+ if (tb == [self outlineTableColumn])
{
- id item = nil;
- NSImage *image = nil;
- NSCell *imageCell = nil;
- NSRect imageRect;
-
- item = [self itemAtRow: rowIndex];
- // determine which image to use...
- if ([self isItemExpanded: item])
+ id item = nil;
+ NSImage *image = nil;
+ NSCell *imageCell = nil;
+ NSRect imageRect;
+
+ item = [self itemAtRow: rowIndex];
+ // determine which image to use...
+ if ([self isItemExpanded: item])
{
- image = expanded;
+ image = expanded;
}
- else
+ else
{
- image = collapsed;
+ image = collapsed;
}
-
- if (![self isExpandable: item])
+
+ if (![self isExpandable: item])
{
- image = unexpandable;
+ image = unexpandable;
}
-
- level = [self levelForItem: item];
- indentationFactor = _indentationPerLevel * level;
- // create the image cell..
- imageCell = [[NSCell alloc] initImageCell: image];
- imageRect = [self frameOfOutlineCellAtRow: rowIndex];
-
- if ([_delegate respondsToSelector: @selector(outlineView:willDisplayOutlineCell:forTableColumn:item:)])
+
+ level = [self levelForItem: item];
+ indentationFactor = _indentationPerLevel * level;
+ // create the image cell..
+ imageCell = [[NSCell alloc] initImageCell: image];
+ imageRect = [self frameOfOutlineCellAtRow: rowIndex];
+
+ if ([_delegate respondsToSelector: @selector(outlineView:willDisplayOutlineCell:forTableColumn:item:)])
{
- [_delegate outlineView: self
- willDisplayOutlineCell: imageCell
- forTableColumn: tb
- item: item];
+ [_delegate outlineView: self
+ willDisplayOutlineCell: imageCell
+ forTableColumn: tb
+ item: item];
}
-
-
- if ([imageCell image])
+
+
+ if ([imageCell image])
{
-
- imageRect.size.width = [image size].width;
- imageRect.size.height = [image size].height;
-
- // draw...
- [self lockFocus];
- [imageCell drawWithFrame: imageRect inView: self];
- [self unlockFocus];
-
- // move the drawing rect over like in the drawRow routine...
- drawingRect.origin.x += indentationFactor + 5 + imageRect.size.width;
- drawingRect.size.width -= indentationFactor + 5 + imageRect.size.width;
+
+ imageRect.size.width = [image size].width;
+ imageRect.size.height = [image size].height;
+
+ // draw...
+ [self lockFocus];
+ [imageCell drawWithFrame: imageRect inView: self];
+ [self unlockFocus];
+
+ // move the drawing rect over like in the drawRow routine...
+ drawingRect.origin.x += indentationFactor + 5 + imageRect.size.width;
+ drawingRect.size.width -= indentationFactor + 5 + imageRect.size.width;
}
- else
+ else
{
- // move the drawing rect over like in the drawRow routine...
- drawingRect.origin.x += indentationFactor;
- drawingRect.size.width -= indentationFactor;
+ // move the drawing rect over like in the drawRow routine...
+ drawingRect.origin.x += indentationFactor;
+ drawingRect.size.width -= indentationFactor;
}
-
- RELEASE(imageCell);
+
+ RELEASE(imageCell);
}
-
- if (flag)
+
+ if (flag)
{
- [_editedCell selectWithFrame: drawingRect
- inView: self
- editor: _textObject
- delegate: self
- start: 0
- length: length];
+ [_editedCell selectWithFrame: drawingRect
+ inView: self
+ editor: _textObject
+ delegate: self
+ start: 0
+ length: length];
}
- else
+ else
{
- [_editedCell editWithFrame: drawingRect
- inView: self
- editor: _textObject
- delegate: self
- event: theEvent];
+ [_editedCell editWithFrame: drawingRect
+ inView: self
+ editor: _textObject
+ delegate: self
+ event: theEvent];
}
-
- return;
+
+ return;
}
@end /* implementation of NSOutlineView */
@@ -1712,205 +1711,205 @@ namesOfPromisedFilesDroppedAtDestination: dropDestination
*/
- (void) _postSelectionIsChangingNotification
{
- [nc postNotificationName:
- NSOutlineViewSelectionIsChangingNotification
- object: self];
+ [nc postNotificationName:
+ NSOutlineViewSelectionIsChangingNotification
+ object: self];
}
- (void) _postSelectionDidChangeNotification
{
- [nc postNotificationName:
- NSOutlineViewSelectionDidChangeNotification
- object: self];
+ [nc postNotificationName:
+ NSOutlineViewSelectionDidChangeNotification
+ object: self];
}
- (void) _postColumnDidMoveNotificationWithOldIndex: (int) oldIndex
newIndex: (int) newIndex
{
- [nc postNotificationName:
- NSOutlineViewColumnDidMoveNotification
- object: self
- userInfo: [NSDictionary
- dictionaryWithObjectsAndKeys:
- [NSNumber numberWithInt: newIndex],
- @"NSNewColumn",
- [NSNumber numberWithInt: oldIndex],
- @"NSOldColumn",
- nil]];
+ [nc postNotificationName:
+ NSOutlineViewColumnDidMoveNotification
+ object: self
+ userInfo: [NSDictionary
+ dictionaryWithObjectsAndKeys:
+ [NSNumber numberWithInt: newIndex],
+ @"NSNewColumn",
+ [NSNumber numberWithInt: oldIndex],
+ @"NSOldColumn",
+ nil]];
}
- (void) _postColumnDidResizeNotificationWithOldWidth: (float) oldWidth
{
- [nc postNotificationName:
- NSOutlineViewColumnDidResizeNotification
- object: self
- userInfo: [NSDictionary
- dictionaryWithObjectsAndKeys:
- [NSNumber numberWithFloat: oldWidth],
- @"NSOldWidth",
- nil]];
+ [nc postNotificationName:
+ NSOutlineViewColumnDidResizeNotification
+ object: self
+ userInfo: [NSDictionary
+ dictionaryWithObjectsAndKeys:
+ [NSNumber numberWithFloat: oldWidth],
+ @"NSOldWidth",
+ nil]];
}
- (BOOL) _shouldSelectTableColumn: (NSTableColumn *)tableColumn
{
- if ([_delegate respondsToSelector:
- @selector (outlineView:shouldSelectTableColumn:)] == YES)
+ if ([_delegate respondsToSelector:
+ @selector (outlineView:shouldSelectTableColumn:)] == YES)
{
- if ([_delegate outlineView: self shouldSelectTableColumn: tableColumn]
- == NO)
+ if ([_delegate outlineView: self shouldSelectTableColumn: tableColumn]
+ == NO)
{
- return NO;
+ return NO;
}
}
-
- return YES;
+
+ return YES;
}
- (BOOL) _shouldSelectRow: (int)rowIndex
{
- id item = [self itemAtRow: rowIndex];
-
- if ([_delegate respondsToSelector:
- @selector (outlineView:shouldSelectItem:)] == YES)
+ id item = [self itemAtRow: rowIndex];
+
+ if ([_delegate respondsToSelector:
+ @selector (outlineView:shouldSelectItem:)] == YES)
{
- if ([_delegate outlineView: self shouldSelectItem: item] == NO)
+ if ([_delegate outlineView: self shouldSelectItem: item] == NO)
{
- return NO;
+ return NO;
}
}
-
- return YES;
+
+ return YES;
}
- (BOOL) _shouldSelectionChange
{
- if ([_delegate respondsToSelector:
- @selector (selectionShouldChangeInTableView:)] == YES)
+ if ([_delegate respondsToSelector:
+ @selector (selectionShouldChangeInTableView:)] == YES)
{
- if ([_delegate selectionShouldChangeInTableView: self] == NO)
+ if ([_delegate selectionShouldChangeInTableView: self] == NO)
{
- return NO;
+ return NO;
}
}
-
- return YES;
+
+ return YES;
}
- (void) _didChangeSortDescriptors: (NSArray *)oldSortDescriptors
{
- if ([_dataSource
- respondsToSelector: @selector(outlineView:sortDescriptorsDidChange:)])
+ if ([_dataSource
+ respondsToSelector: @selector(outlineView:sortDescriptorsDidChange:)])
{
- [_dataSource outlineView: self sortDescriptorsDidChange: oldSortDescriptors];
+ [_dataSource outlineView: self sortDescriptorsDidChange: oldSortDescriptors];
}
}
- (void) _didClickTableColumn: (NSTableColumn *)tc
{
- if ([_delegate
- respondsToSelector: @selector(outlineView:didClickTableColumn:)])
+ if ([_delegate
+ respondsToSelector: @selector(outlineView:didClickTableColumn:)])
{
- [_delegate outlineView: self didClickTableColumn: tc];
+ [_delegate outlineView: self didClickTableColumn: tc];
}
}
- (BOOL) _shouldEditTableColumn: (NSTableColumn *)tableColumn
row: (int) rowIndex
{
- if ([_delegate respondsToSelector:
- @selector(outlineView:shouldEditTableColumn:item:)])
+ if ([_delegate respondsToSelector:
+ @selector(outlineView:shouldEditTableColumn:item:)])
{
- id item = [self itemAtRow: rowIndex];
-
- if ([_delegate outlineView: self shouldEditTableColumn: tableColumn
- item: item] == NO)
+ id item = [self itemAtRow: rowIndex];
+
+ if ([_delegate outlineView: self shouldEditTableColumn: tableColumn
+ item: item] == NO)
{
- return NO;
+ return NO;
}
}
-
- return YES;
+
+ return YES;
}
- (void) _willDisplayCell: (NSCell*)cell
forTableColumn: (NSTableColumn *)tb
row: (int)index
{
- if (_del_responds)
+ if (_del_responds)
{
- id item = [self itemAtRow: index];
-
- [_delegate outlineView: self
- willDisplayCell: cell
- forTableColumn: tb
- item: item];
+ id item = [self itemAtRow: index];
+
+ [_delegate outlineView: self
+ willDisplayCell: cell
+ forTableColumn: tb
+ item: item];
}
}
- (BOOL) _writeRows: (NSIndexSet *)rows
toPasteboard: (NSPasteboard *)pboard
{
- NSUInteger count = [rows count];
- NSMutableArray *itemArray = [NSMutableArray arrayWithCapacity: count];
- NSUInteger index = [rows firstIndex];
-
- while (index != NSNotFound)
+ NSUInteger count = [rows count];
+ NSMutableArray *itemArray = [NSMutableArray arrayWithCapacity: count];
+ NSUInteger index = [rows firstIndex];
+
+ while (index != NSNotFound)
{
- [itemArray addObject: [self itemAtRow: index]];
- index = [rows indexGreaterThanIndex: index];
+ [itemArray addObject: [self itemAtRow: index]];
+ index = [rows indexGreaterThanIndex: index];
}
-
- if ([_dataSource respondsToSelector:
- @selector(outlineView:writeItems:toPasteboard:)] == YES)
+
+ if ([_dataSource respondsToSelector:
+ @selector(outlineView:writeItems:toPasteboard:)] == YES)
{
- return [_dataSource outlineView: self
- writeItems: itemArray
- toPasteboard: pboard];
+ return [_dataSource outlineView: self
+ writeItems: itemArray
+ toPasteboard: pboard];
}
- return NO;
+ return NO;
}
- (BOOL) _isDraggingSource
{
- return [_dataSource respondsToSelector:
- @selector(outlineView:writeItems:toPasteboard:)];
+ return [_dataSource respondsToSelector:
+ @selector(outlineView:writeItems:toPasteboard:)];
}
- (id) _objectValueForTableColumn: (NSTableColumn *)tb
row: (int) index
{
- id result = nil;
-
- if ([_dataSource respondsToSelector:
- @selector(outlineView:objectValueForTableColumn:byItem:)])
+ id result = nil;
+
+ if ([_dataSource respondsToSelector:
+ @selector(outlineView:objectValueForTableColumn:byItem:)])
{
- id item = [self itemAtRow: index];
-
- result = [_dataSource outlineView: self
- objectValueForTableColumn: tb
- byItem: item];
+ id item = [self itemAtRow: index];
+
+ result = [_dataSource outlineView: self
+ objectValueForTableColumn: tb
+ byItem: item];
}
-
- return result;
+
+ return result;
}
- (void) _setObjectValue: (id)value
forTableColumn: (NSTableColumn *)tb
row: (int) index
{
- if ([_dataSource respondsToSelector:
- @selector(outlineView:setObjectValue:forTableColumn:byItem:)])
+ if ([_dataSource respondsToSelector:
+ @selector(outlineView:setObjectValue:forTableColumn:byItem:)])
{
- id item = [self itemAtRow: index];
-
- [_dataSource outlineView: self
- setObjectValue: value
- forTableColumn: tb
- byItem: item];
+ id item = [self itemAtRow: index];
+
+ [_dataSource outlineView: self
+ setObjectValue: value
+ forTableColumn: tb
+ byItem: item];
}
}
- (int) _numRows
{
- return [_items count];
+ return [_items count];
}
@end
@@ -1919,56 +1918,56 @@ namesOfPromisedFilesDroppedAtDestination: dropDestination
- (void) _initOutlineDefaults
{
- _itemDict = NSCreateMapTable(NSObjectMapKeyCallBacks,
- NSObjectMapValueCallBacks,
- 64);
- _items = [[NSMutableArray alloc] init];
- _expandedItems = [[NSMutableArray alloc] init];
- _levelOfItems = NSCreateMapTable(NSObjectMapKeyCallBacks,
- NSObjectMapValueCallBacks,
- 64);
-
- _indentationMarkerFollowsCell = YES;
- _autoResizesOutlineColumn = NO;
- _autosaveExpandedItems = NO;
- _indentationPerLevel = 10.0;
+ _itemDict = NSCreateMapTable(NSObjectMapKeyCallBacks,
+ NSObjectMapValueCallBacks,
+ 64);
+ _items = [[NSMutableArray alloc] init];
+ _expandedItems = [[NSMutableArray alloc] init];
+ _levelOfItems = NSCreateMapTable(NSObjectMapKeyCallBacks,
+ NSObjectMapValueCallBacks,
+ 64);
+
+ _indentationMarkerFollowsCell = YES;
+ _autoResizesOutlineColumn = NO;
+ _autosaveExpandedItems = NO;
+ _indentationPerLevel = 10.0;
}
- (void) _autosaveExpandedItems
{
- if (_autosaveExpandedItems && _autosaveName != nil)
+ if (_autosaveExpandedItems && _autosaveName != nil)
{
- NSUserDefaults *defaults;
- NSString *tableKey;
-
- defaults = [NSUserDefaults standardUserDefaults];
- tableKey = [NSString stringWithFormat: @"NSOutlineView Expanded Items %@",
- _autosaveName];
- [defaults setObject: _expandedItems forKey: tableKey];
- [defaults synchronize];
+ NSUserDefaults *defaults;
+ NSString *tableKey;
+
+ defaults = [NSUserDefaults standardUserDefaults];
+ tableKey = [NSString stringWithFormat: @"NSOutlineView Expanded Items %@",
+ _autosaveName];
+ [defaults setObject: _expandedItems forKey: tableKey];
+ [defaults synchronize];
}
}
- (void) _autoloadExpandedItems
{
- if (_autosaveExpandedItems && _autosaveName != nil)
+ if (_autosaveExpandedItems && _autosaveName != nil)
{
- NSUserDefaults *defaults;
- id config;
- NSString *tableKey;
-
- defaults = [NSUserDefaults standardUserDefaults];
- tableKey = [NSString stringWithFormat: @"NSOutlineView Expanded Items %@",
- _autosaveName];
- config = [defaults objectForKey: tableKey];
- if (config != nil)
+ NSUserDefaults *defaults;
+ id config;
+ NSString *tableKey;
+
+ defaults = [NSUserDefaults standardUserDefaults];
+ tableKey = [NSString stringWithFormat: @"NSOutlineView Expanded Items %@",
+ _autosaveName];
+ config = [defaults objectForKey: tableKey];
+ if (config != nil)
{
- NSEnumerator *en = [config objectEnumerator];
- id item = nil;
-
- while ((item = [en nextObject]) != nil)
+ NSEnumerator *en = [config objectEnumerator];
+ id item = nil;
+
+ while ((item = [en nextObject]) != nil)
{
- [self expandItem: item];
+ [self expandItem: item];
}
}
}
@@ -1978,311 +1977,292 @@ namesOfPromisedFilesDroppedAtDestination: dropDestination
- (void)_collectItemsStartingWith: (id)startitem
into: (NSMutableArray *)allChildren
{
- int num;
- int i;
- id sitem = (startitem == nil) ? (id)[NSNull null] : (id)startitem;
- NSMutableArray *anarray;
-
- anarray = NSMapGet(_itemDict, sitem);
- num = [anarray count];
- for (i = 0; i < num; i++)
+ int num;
+ int i;
+ id sitem = (startitem == nil) ? (id)[NSNull null] : (id)startitem;
+ NSMutableArray *anarray;
+
+ anarray = NSMapGet(_itemDict, sitem);
+ num = [anarray count];
+ for (i = 0; i < num; i++)
{
- id anitem = [anarray objectAtIndex: i];
-
- // Only collect the children if the item is expanded
- if ([self isItemExpanded: startitem])
+ id anitem = [anarray objectAtIndex: i];
+
+ // Only collect the children if the item is expanded
+ if ([self isItemExpanded: startitem])
{
- [allChildren addObject: anitem];
+ [allChildren addObject: anitem];
}
-
- [self _collectItemsStartingWith: anitem
- into: allChildren];
+
+ [self _collectItemsStartingWith: anitem
+ into: allChildren];
}
}
- (BOOL) _isItemLoaded: (id)item
{
- id sitem = (item == nil) ? (id)[NSNull null] : (id)item;
- id object = NSMapGet(_itemDict, sitem);
-
- // NOTE: We could store the loaded items in a map to ensure we only load
- // the children of item when it gets expanded for the first time. This would
- // allow to write: return (NSMapGet(_loadedItemDict, sitem) != nil);
- // The last line isn't truly correct because it implies an item without
- // children will get incorrectly reloaded automatically on each
- // expand/collapse.
- return ([object count] != 0);
+ id sitem = (item == nil) ? (id)[NSNull null] : (id)item;
+ id object = NSMapGet(_itemDict, sitem);
+
+ // NOTE: We could store the loaded items in a map to ensure we only load
+ // the children of item when it gets expanded for the first time. This would
+ // allow to write: return (NSMapGet(_loadedItemDict, sitem) != nil);
+ // The last line isn't truly correct because it implies an item without
+ // children will get incorrectly reloaded automatically on each
+ // expand/collapse.
+ return ([object count] != 0);
}
- (void) _loadDictionaryStartingWith: (id) startitem
atLevel: (int) level
{
- int num = 0;
- int i = 0;
- id sitem = (startitem == nil) ? (id)[NSNull null] : (id)startitem;
- NSMutableArray *anarray = nil;
-
- /* Check to see if item is expandable and expanded before getting the number
- * of items. For macos compatibility the topmost item (startitem==nil)
- * is always considered expandable and must not be checked.
- * We must load the item only if expanded, otherwise an outline view is not
- * usable with a big tree structure. For example, an outline view to browse
- * file system would try to traverse every file/directory on -reloadData.
- */
- if ((startitem == nil
- || [_dataSource outlineView: self isItemExpandable: startitem])
- && [self isItemExpanded: startitem])
+ int num = 0;
+ int i = 0;
+ id sitem = (startitem == nil) ? (id)[NSNull null] : (id)startitem;
+ NSMutableArray *anarray = nil;
+
+ /* Check to see if item is expandable and expanded before getting the number
+ * of items. For macos compatibility the topmost item (startitem==nil)
+ * is always considered expandable and must not be checked.
+ * We must load the item only if expanded, otherwise an outline view is not
+ * usable with a big tree structure. For example, an outline view to browse
+ * file system would try to traverse every file/directory on -reloadData.
+ */
+ if ((startitem == nil
+ || [_dataSource outlineView: self isItemExpandable: startitem])
+ && [self isItemExpanded: startitem])
{
- num = [_dataSource outlineView: self
- numberOfChildrenOfItem: startitem];
+ num = [_dataSource outlineView: self
+ numberOfChildrenOfItem: startitem];
}
-
- if (num > 0)
+
+ if (num > 0)
{
- anarray = [NSMutableArray array];
- NSMapInsert(_itemDict, sitem, anarray);
+ anarray = [NSMutableArray array];
+ NSMapInsert(_itemDict, sitem, anarray);
}
-
- NSMapInsert(_levelOfItems, sitem, [NSNumber numberWithInt: level]);
-
- for (i = 0; i < num; i++)
+
+ NSMapInsert(_levelOfItems, sitem, [NSNumber numberWithInt: level]);
+
+ for (i = 0; i < num; i++)
{
- id anitem = [_dataSource outlineView: self
- child: i
- ofItem: startitem];
-
- [anarray addObject: anitem];
- [self _loadDictionaryStartingWith: anitem
- atLevel: level + 1];
+ id anitem = [_dataSource outlineView: self
+ child: i
+ ofItem: startitem];
+
+ [anarray addObject: anitem];
+ [self _loadDictionaryStartingWith: anitem
+ atLevel: level + 1];
}
}
- (void)_closeItem: (id)item
{
- NSUInteger i, numChildren;
- NSMutableArray *removeAll = [NSMutableArray array];
-
- [self _collectItemsStartingWith: item into: removeAll];
- numChildren = [removeAll count];
-
- // close the item...
- if (item != nil)
+ NSUInteger i, numChildren;
+ NSMutableArray *removeAll = [NSMutableArray array];
+
+ [self _collectItemsStartingWith: item into: removeAll];
+ numChildren = [removeAll count];
+
+ // close the item...
+ if (item != nil)
{
- [_expandedItems removeObject: item];
+ [_expandedItems removeObject: item];
}
-
- // For the close method it doesn't matter what order they are
- // removed in.
- for (i = 0; i < numChildren; i++)
+
+ // For the close method it doesn't matter what order they are
+ // removed in.
+ for (i = 0; i < numChildren; i++)
{
- id child = [removeAll objectAtIndex: i];
- [_items removeObject: child];
+ id child = [removeAll objectAtIndex: i];
+ [_items removeObject: child];
}
- [self _noteNumberOfRowsChangedBelowItem: item by: -numChildren];
+ [self _noteNumberOfRowsChangedBelowItem: item by: -numChildren];
}
- (void)_openItem: (id)item
{
- NSUInteger insertionPoint, numChildren, numDescendants;
- NSInteger i;
- id object;
- id sitem = (item == nil) ? (id)[NSNull null] : (id)item;
-
- // open the item...
- if (item != nil)
+ NSUInteger insertionPoint, numChildren, numDescendants;
+ NSInteger i;
+ id object;
+ id sitem = (item == nil) ? (id)[NSNull null] : (id)item;
+
+ // open the item...
+ if (item != nil)
{
- [_expandedItems addObject: item];
+ [_expandedItems addObject: item];
}
-
- // Load the children of the item if needed
- if ([self _isItemLoaded: item] == NO)
+
+ // Load the children of the item if needed
+ if ([self _isItemLoaded: item] == NO)
{
- [self _loadDictionaryStartingWith: item atLevel: [self levelForItem: item]];
+ [self _loadDictionaryStartingWith: item atLevel: [self levelForItem: item]];
}
-
- object = NSMapGet(_itemDict, sitem);
- numChildren = numDescendants = [object count];
-
- insertionPoint = [_items indexOfObject: item];
- if (insertionPoint == NSNotFound)
+
+ object = NSMapGet(_itemDict, sitem);
+ numChildren = numDescendants = [object count];
+
+ insertionPoint = [_items indexOfObject: item];
+ if (insertionPoint == NSNotFound)
{
- insertionPoint = 0;
+ insertionPoint = 0;
}
- else
+ else
{
- insertionPoint++;
+ insertionPoint++;
}
-
- for (i = numChildren-1; i >= 0; i--)
+
+ for (i = numChildren-1; i >= 0; i--)
{
- id obj = NSMapGet(_itemDict, sitem);
- id child = [obj objectAtIndex: i];
-
- // Add all of the children...
- if ([self isItemExpanded: child])
+ id obj = NSMapGet(_itemDict, sitem);
+ id child = [obj objectAtIndex: i];
+
+ // Add all of the children...
+ if ([self isItemExpanded: child])
{
- NSUInteger numItems;
- NSInteger j;
- NSMutableArray *insertAll = [NSMutableArray array];
-
- [self _collectItemsStartingWith: child into: insertAll];
- numItems = [insertAll count];
- numDescendants += numItems;
- for (j = numItems-1; j >= 0; j--)
+ NSUInteger numItems;
+ NSInteger j;
+ NSMutableArray *insertAll = [NSMutableArray array];
+
+ [self _collectItemsStartingWith: child into: insertAll];
+ numItems = [insertAll count];
+ numDescendants += numItems;
+ for (j = numItems-1; j >= 0; j--)
{
- [_items insertObject: [insertAll objectAtIndex: j]
- atIndex: insertionPoint];
+ [_items insertObject: [insertAll objectAtIndex: j]
+ atIndex: insertionPoint];
}
}
-
- // Add the parent
- [_items insertObject: child atIndex: insertionPoint];
+
+ // Add the parent
+ [_items insertObject: child atIndex: insertionPoint];
}
-
- [self _noteNumberOfRowsChangedBelowItem: item by: numDescendants];
+
+ [self _noteNumberOfRowsChangedBelowItem: item by: numDescendants];
}
- (void) _removeChildren: (id)startitem
{
- NSUInteger i, numChildren;
- id sitem = (startitem == nil) ? (id)[NSNull null] : (id)startitem;
- NSMutableArray *anarray;
-
- anarray = NSMapGet(_itemDict, sitem);
- numChildren = [anarray count];
- for (i = 0; i < numChildren; i++)
+ NSUInteger i, numChildren;
+ id sitem = (startitem == nil) ? (id)[NSNull null] : (id)startitem;
+ NSMutableArray *anarray;
+
+ anarray = NSMapGet(_itemDict, sitem);
+ numChildren = [anarray count];
+ for (i = 0; i < numChildren; i++)
{
- id child = [anarray objectAtIndex: i];
-
- [self _removeChildren: child];
- NSMapRemove(_itemDict, child);
- [_items removeObject: child];
- [_expandedItems removeObject: child];
+ id child = [anarray objectAtIndex: i];
+
+ [self _removeChildren: child];
+ NSMapRemove(_itemDict, child);
+ [_items removeObject: child];
+ [_expandedItems removeObject: child];
}
- [anarray removeAllObjects];
- [self _noteNumberOfRowsChangedBelowItem: startitem by: -numChildren];
+ [anarray removeAllObjects];
+ [self _noteNumberOfRowsChangedBelowItem: startitem by: -numChildren];
}
- (void) _noteNumberOfRowsChangedBelowItem: (id)item by: (int)numItems
{
- BOOL selectionDidChange = NO;
- NSUInteger rowIndex, nextIndex;
-
- // check for trivial case
- if (numItems == 0)
- return;
-
- // if a row below item is selected, update the selected row indexes
- /* Note: We update the selected row indexes directly instead of calling
- * -selectRowIndexes:extendingSelection: to avoid posting bogus selection
- * did change notifications. */
- rowIndex = [_items indexOfObject: item];
- rowIndex = (rowIndex == NSNotFound) ? 0 : rowIndex + 1;
- nextIndex = [_selectedRows indexGreaterThanOrEqualToIndex: rowIndex];
- if (nextIndex != NSNotFound)
+ BOOL selectionDidChange = NO;
+ NSUInteger rowIndex, nextIndex;
+
+ // check for trivial case
+ if (numItems == 0)
+ return;
+
+ // if a row below item is selected, update the selected row indexes
+ /* Note: We update the selected row indexes directly instead of calling
+ * -selectRowIndexes:extendingSelection: to avoid posting bogus selection
+ * did change notifications. */
+ rowIndex = [_items indexOfObject: item];
+ rowIndex = (rowIndex == NSNotFound) ? 0 : rowIndex + 1;
+ nextIndex = [_selectedRows indexGreaterThanOrEqualToIndex: rowIndex];
+ if (nextIndex != NSNotFound)
{
- if (numItems > 0)
+ if (numItems > 0)
+ {
+ [_selectedRows shiftIndexesStartingAtIndex: rowIndex by: numItems];
+ if (_selectedRow >= rowIndex)
+ {
+ _selectedRow += numItems;
+ }
+ }
+ else
{
- [_selectedRows shiftIndexesStartingAtIndex: rowIndex by: numItems];
- if (_selectedRow >= rowIndex)
+ numItems = -numItems;
+ [_selectedRows shiftIndexesStartingAtIndex: rowIndex + numItems
+ by: -numItems];
+ if (nextIndex < rowIndex + numItems)
+ {
+ /* Don't post the notification here, as the table view is in
+ * an inconsistent state. */
+ selectionDidChange = YES;
+ }
+
+ /* If the selection becomes empty after removing items and the
+ * receiver does not allow empty selections, select the root item. */
+ if ([_selectedRows firstIndex] == NSNotFound &&
+ [self allowsEmptySelection] == NO)
{
- _selectedRow += numItems;
- }
- }
- else
- {
- numItems = -numItems;
- [_selectedRows shiftIndexesStartingAtIndex: rowIndex + numItems
- by: -numItems];
- if (nextIndex < rowIndex + numItems)
- {
- /* Don't post the notification here, as the table view is in
- * an inconsistent state. */
- selectionDidChange = YES;
- }
-
- /* If the selection becomes empty after removing items and the
- * receiver does not allow empty selections, select the root item. */
- if ([_selectedRows firstIndex] == NSNotFound &&
- [self allowsEmptySelection] == NO)
- {
- [_selectedRows addIndex: 0];
- }
-
- if (_selectedRow >= rowIndex + numItems)
- {
- _selectedRow -= numItems;
- }
- else if (_selectedRow >= rowIndex)
- {
- /* If the item at _selectedRow was removed, we arbitrarily choose
- * another selected item (if there is still any). The policy
- * implemented below chooses the index most close to item. */
- NSUInteger r1 = [_selectedRows indexLessThanIndex: rowIndex];
- NSUInteger r2 = [_selectedRows indexGreaterThanOrEqualToIndex: rowIndex];
- if (r1 != NSNotFound && r2 != NSNotFound)
- {
- _selectedRow = (rowIndex - r1) <= (r2 - rowIndex) ? r1 : r2;
- }
- else if (r1 != NSNotFound)
- {
- _selectedRow = r1;
- }
- else if (r2 != NSNotFound)
- {
- _selectedRow = r2;
- }
- else
- {
- _selectedRow = -1;
- }
+ [_selectedRows addIndex: 0];
}
+
+ if (_selectedRow >= rowIndex + numItems)
+ {
+ _selectedRow -= numItems;
+ }
+ else if (_selectedRow >= rowIndex)
+ {
+ /* If the item at _selectedRow was removed, we arbitrarily choose
+ * another selected item (if there is still any). The policy
+ * implemented below chooses the index most close to item. */
+ NSUInteger r1 = [_selectedRows indexLessThanIndex: rowIndex];
+ NSUInteger r2 = [_selectedRows indexGreaterThanOrEqualToIndex: rowIndex];
+ if (r1 != NSNotFound && r2 != NSNotFound)
+ {
+ _selectedRow = (rowIndex - r1) <= (r2 - rowIndex) ? r1 : r2;
+ }
+ else if (r1 != NSNotFound)
+ {
+ _selectedRow = r1;
+ }
+ else if (r2 != NSNotFound)
+ {
+ _selectedRow = r2;
+ }
+ else
+ {
+ _selectedRow = -1;
+ }
+ }
}
}
-
- [self noteNumberOfRowsChanged];
- if (selectionDidChange)
+
+ [self noteNumberOfRowsChanged];
+ if (selectionDidChange)
{
- [self _postSelectionDidChangeNotification];
+ [self _postSelectionDidChangeNotification];
}
}
- (NSCell *) _dataCellForTableColumn: (NSTableColumn *)tb
row: (int) rowIndex
{
- NSCell *cell = nil;
- if ([_delegate respondsToSelector:
- @selector(outlineView:dataCellForTableColumn:item:)])
+ NSCell *cell = nil;
+ if ([_delegate respondsToSelector:
+ @selector(outlineView:dataCellForTableColumn:item:)])
{
- id item = [self itemAtRow: rowIndex];
- cell = [_delegate outlineView: self
- dataCellForTableColumn: tb
- item: item];
+ id item = [self itemAtRow: rowIndex];
+ cell = [_delegate outlineView: self
+ dataCellForTableColumn: tb
+ item: item];
}
- if (cell == nil)
+ if (cell == nil)
{
- cell = [tb dataCellForRow: rowIndex];
+ cell = [tb dataCellForRow: rowIndex];
}
- return cell;
-}
-
-// This is used to build the drag image.
-- (NSString *) _objectStringForTableColum:(NSTableColumn *)column item:(int)row {
- NSString *draggedItemString = nil;
- if ([[self dataSource] respondsToSelector:@selector(outlineView:objectValueForTableColumn:byItem:)]) {
- id item = [self itemAtRow:row];
- id draggedObject = [[self dataSource] outlineView:self
- objectValueForTableColumn:column
- byItem:item];
-
- // Pad the string to match its indentation level:
- int level = [self levelForRow:row];
- NSString *pad = [@"" stringByPaddingToLength:(level*4)
- withString:@" "
- startingAtIndex:0];
- draggedItemString = [pad stringByAppendingString:[draggedObject description]];
- }
- return draggedItemString;
+ return cell;
}
@end
@@ -2292,15 +2272,14 @@ namesOfPromisedFilesDroppedAtDestination: dropDestination
*/
- (void) _autoCollapse
{
- NSEnumerator *e;
- id item;
-
- e = [autoExpanded objectEnumerator];
- while ((item = [e nextObject]) != nil)
- {
- [self collapseItem: item collapseChildren: YES];
- }
- [autoExpanded removeAllObjects];
-}
+ NSEnumerator *e;
+ id item;
+ e = [autoExpanded objectEnumerator];
+ while ((item = [e nextObject]) != nil)
+ {
+ [self collapseItem: item collapseChildren: YES];
+ }
+ [autoExpanded removeAllObjects];
+}
@end
diff --git a/Source/NSTableView.m b/Source/NSTableView.m
index ef17826ee..dfde36a76 100644
--- a/Source/NSTableView.m
+++ b/Source/NSTableView.m
@@ -1,34 +1,34 @@
/** NSTableView
-
- Copyright (C) 2000 Free Software Foundation, Inc.
-
- Author: Nicola Pero
- Date: March 2000, June 2000, August 2000, September 2000
-
- Author: Pierre-Yves Rivaille
- Date: August 2001, January 2002
-
- Author: Fred Kiefer
- Date: March 2004
-
- This file is part of the GNUstep GUI Library.
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; see the file COPYING.LIB.
- If not, see or write to the
- Free Software Foundation, 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA.
- */
+
+ Copyright (C) 2000 Free Software Foundation, Inc.
+
+ Author: Nicola Pero
+ Date: March 2000, June 2000, August 2000, September 2000
+
+ Author: Pierre-Yves Rivaille
+ Date: August 2001, January 2002
+
+ Author: Fred Kiefer
+ Date: March 2004
+
+ This file is part of the GNUstep GUI Library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; see the file COPYING.LIB.
+ If not, see or write to the
+ Free Software Foundation, 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
#import
#import
@@ -68,8 +68,6 @@
#import "AppKit/NSCustomImageRep.h"
#import "GNUstepGUI/GSTheme.h"
#import "GSBindingHelpers.h"
-#import "AppKit/NSAttributedString.h"
-#import "AppKit/NSStringDrawing.h"
#include
static NSNotificationCenter *nc = nil;
@@ -85,28 +83,28 @@ static int lastQuarterPosition;
static NSDragOperation currentDragOperation;
/*
- * Nib compatibility struct. This structure is used to
+ * Nib compatibility struct. This structure is used to
* pull the attributes out of the nib that we need to fill
* in the flags.
*/
typedef struct _tableViewFlags
{
#if GS_WORDS_BIGENDIAN == 1
- unsigned int columnOrdering:1;
- unsigned int columnResizing:1;
- unsigned int drawsGrid:1;
- unsigned int emptySelection:1;
- unsigned int multipleSelection:1;
- unsigned int columnSelection:1;
- unsigned int _unused:26;
+ unsigned int columnOrdering:1;
+ unsigned int columnResizing:1;
+ unsigned int drawsGrid:1;
+ unsigned int emptySelection:1;
+ unsigned int multipleSelection:1;
+ unsigned int columnSelection:1;
+ unsigned int _unused:26;
#else
- unsigned int _unused:26;
- unsigned int columnSelection:1;
- unsigned int multipleSelection:1;
- unsigned int emptySelection:1;
- unsigned int drawsGrid:1;
- unsigned int columnResizing:1;
- unsigned int columnOrdering:1;
+ unsigned int _unused:26;
+ unsigned int columnSelection:1;
+ unsigned int multipleSelection:1;
+ unsigned int emptySelection:1;
+ unsigned int drawsGrid:1;
+ unsigned int columnResizing:1;
+ unsigned int columnOrdering:1;
#endif
} GSTableViewFlags;
@@ -120,7 +118,7 @@ typedef struct _tableViewFlags
- (void) _postSelectionIsChangingNotification;
- (void) _postSelectionDidChangeNotification;
- (void) _postColumnDidMoveNotificationWithOldIndex: (int) oldIndex
- newIndex: (int) newIndex;
+ newIndex: (int) newIndex;
- (void) _postColumnDidResizeNotification;
- (BOOL) _shouldSelectTableColumn: (NSTableColumn *)tableColumn;
- (BOOL) _shouldSelectRow: (int)rowIndex;
@@ -129,22 +127,22 @@ typedef struct _tableViewFlags
- (void) _didChangeSortDescriptors: (NSArray *)oldSortDescriptors;
- (void) _didClickTableColumn: (NSTableColumn *)tc;
- (BOOL) _shouldEditTableColumn: (NSTableColumn *)tableColumn
- row: (int) rowIndex;
+ row: (int) rowIndex;
- (void) _willDisplayCell: (NSCell*)cell
- forTableColumn: (NSTableColumn *)tb
- row: (int)index;
+ forTableColumn: (NSTableColumn *)tb
+ row: (int)index;
- (BOOL) _writeRows: (NSIndexSet *)rows
toPasteboard: (NSPasteboard *)pboard;
- (BOOL) _isDraggingSource;
- (id)_objectValueForTableColumn: (NSTableColumn *)tb
- row: (int)index;
+ row: (int)index;
- (void)_setObjectValue: (id)value
- forTableColumn: (NSTableColumn *)tb
- row: (int)index;
+ forTableColumn: (NSTableColumn *)tb
+ row: (int)index;
- (BOOL) _isCellEditableColumn: (int) columnIndex
- row: (int) rowIndex;
+ row: (int) rowIndex;
- (int) _numRows;
@end
@@ -170,62 +168,62 @@ typedef struct _tableViewFlags
* This is used by the -sizeToFit method
*/
typedef struct {
- float width;
- BOOL isMax;
+ float width;
+ BOOL isMax;
} columnSorting;
static
void quick_sort_internal(columnSorting *data, int p, int r)
{
- if (p < r)
+ if (p < r)
{
- int q;
- {
- float x = data[p].width;
- BOOL y = data[p].isMax;
- int i = p - 1;
- int j = r + 1;
- columnSorting exchange;
- while (1)
- {
- j--;
- for (;
- (data[j].width > x)
- || ((data[j].width == x)
- && (data[j].isMax == YES)
- && (y == NO));
- j--)
- ;
-
- i++;
- for (;
- (data[i].width < x)
- || ((data[i].width == x)
- && (data[i].isMax == NO)
- && (y == YES));
- i++)
- ;
- if (i < j)
- {
- exchange = data[j];
- data[j] = data[i];
- data[i] = exchange;
- }
- else
- {
- q = j;
- break;
- }
- }
- }
- quick_sort_internal(data, p, q);
- quick_sort_internal(data, q + 1, r);
+ int q;
+ {
+ float x = data[p].width;
+ BOOL y = data[p].isMax;
+ int i = p - 1;
+ int j = r + 1;
+ columnSorting exchange;
+ while (1)
+ {
+ j--;
+ for (;
+ (data[j].width > x)
+ || ((data[j].width == x)
+ && (data[j].isMax == YES)
+ && (y == NO));
+ j--)
+ ;
+
+ i++;
+ for (;
+ (data[i].width < x)
+ || ((data[i].width == x)
+ && (data[i].isMax == NO)
+ && (y == YES));
+ i++)
+ ;
+ if (i < j)
+ {
+ exchange = data[j];
+ data[j] = data[i];
+ data[i] = exchange;
+ }
+ else
+ {
+ q = j;
+ break;
+ }
+ }
+ }
+ quick_sort_internal(data, p, q);
+ quick_sort_internal(data, q + 1, r);
}
}
-/*
- * Now some auxiliary functions used to manage real-time user selections.
+/*
+ * Now some auxiliary functions used to manage real-time user selections.
*
*/
@@ -239,1721 +237,1721 @@ static void computeNewSelection
int *_selectedRow,
unsigned selectionMode)
{
- if (!(selectionMode & ALLOWS_MULTIPLE))
+ if (!(selectionMode & ALLOWS_MULTIPLE))
{
- if ((selectionMode & SHIFT_DOWN) &&
- (selectionMode & ALLOWS_EMPTY) &&
- !(selectionMode & ADDING_ROW))
- // we will unselect the selected row
- // ic, sc : ok
+ if ((selectionMode & SHIFT_DOWN) &&
+ (selectionMode & ALLOWS_EMPTY) &&
+ !(selectionMode & ADDING_ROW))
+ // we will unselect the selected row
+ // ic, sc : ok
{
- int count = [_selectedRows count];
-
- if ((count == 0) && (_oldRow == -1))
- {
- NSLog(@"how did you get there ?");
- NSLog(@"you're supposed to have clicked on a selected row,");
- NSLog(@"but there's no selected row!");
- return;
- }
- else if (count > 1)
- {
- [tv _unselectAllRows];
- [tv _postSelectionIsChangingNotification];
- }
- else if (_currentRow != _originalRow)
- {
- if (*_selectedRow == _originalRow)
- {
- // we are already selected, don't do anything
- }
- else
- {
- //begin checking code
- if (count > 0)
- {
- NSLog(@"There should not be any row selected");
- }
- //end checking code
-
- if ([tv _selectRow: _originalRow])
- {
- [tv _postSelectionIsChangingNotification];
- }
- }
- }
- else if (_currentRow == _originalRow)
- {
- if (count == 0)
- {
- // the row is already deselected
- // nothing to do !
- }
- else
- {
- [tv _unselectRow: _originalRow];
- [tv _postSelectionIsChangingNotification];
- }
- }
- }
- else //(!(selectionMode & ALLOWS_MULTIPLE) &&
- //(!(selectionMode & SHIFT_DOWN) ||
- //!(selectionMode & ALLOWS_EMPTY) ||
- //(selectionMode & ADDING_ROW)))
- // we'll be selecting exactly one row
- // ic, sc : ok
+ int count = [_selectedRows count];
+
+ if ((count == 0) && (_oldRow == -1))
+ {
+ NSLog(@"how did you get there ?");
+ NSLog(@"you're supposed to have clicked on a selected row,");
+ NSLog(@"but there's no selected row!");
+ return;
+ }
+ else if (count > 1)
+ {
+ [tv _unselectAllRows];
+ [tv _postSelectionIsChangingNotification];
+ }
+ else if (_currentRow != _originalRow)
+ {
+ if (*_selectedRow == _originalRow)
+ {
+ // we are already selected, don't do anything
+ }
+ else
+ {
+ //begin checking code
+ if (count > 0)
+ {
+ NSLog(@"There should not be any row selected");
+ }
+ //end checking code
+
+ if ([tv _selectRow: _originalRow])
+ {
+ [tv _postSelectionIsChangingNotification];
+ }
+ }
+ }
+ else if (_currentRow == _originalRow)
+ {
+ if (count == 0)
+ {
+ // the row is already deselected
+ // nothing to do !
+ }
+ else
+ {
+ [tv _unselectRow: _originalRow];
+ [tv _postSelectionIsChangingNotification];
+ }
+ }
+ }
+ else //(!(selectionMode & ALLOWS_MULTIPLE) &&
+ //(!(selectionMode & SHIFT_DOWN) ||
+ //!(selectionMode & ALLOWS_EMPTY) ||
+ //(selectionMode & ADDING_ROW)))
+ // we'll be selecting exactly one row
+ // ic, sc : ok
{
- int count = [_selectedRows count];
-
- if ([tv _shouldSelectRow: _currentRow] == NO)
- {
- return;
- }
-
- if ((count != 1) || (_oldRow == -1))
- {
- // this is the first call that goes thru shouldSelectRow
- // Therefore we don't know anything about the selection
- BOOL notified = ![_selectedRows containsIndex: _currentRow];
- [tv _unselectAllRows];
- [_selectedRows addIndex: _currentRow];
- *_selectedRow = _currentRow;
-
- if (notified == YES)
- {
- [tv setNeedsDisplayInRect: [tv rectOfRow: _currentRow]];
- }
- else
- {
- if (count > 1)
- {
- notified = YES;
- }
- }
- if (notified == YES)
- {
- [tv _postSelectionIsChangingNotification];
- }
- }
- else
- {
- // we know there is only one column selected
- // this column is *_selectedRow
-
- //begin checking code
- if (![_selectedRows containsIndex: *_selectedRow])
- {
- NSLog(@"*_selectedRow is not the only selected row!");
- }
- //end checking code
-
- if (*_selectedRow == _currentRow)
- {
- // currentRow is already selecteed
- return;
- }
- else
- {
- [tv _unselectRow: *_selectedRow];
- // CHANGE: This does a check more
- [tv _selectRow: _currentRow];
- [tv _postSelectionIsChangingNotification];
- }
- }
- }
+ int count = [_selectedRows count];
+
+ if ([tv _shouldSelectRow: _currentRow] == NO)
+ {
+ return;
+ }
+
+ if ((count != 1) || (_oldRow == -1))
+ {
+ // this is the first call that goes thru shouldSelectRow
+ // Therefore we don't know anything about the selection
+ BOOL notified = ![_selectedRows containsIndex: _currentRow];
+ [tv _unselectAllRows];
+ [_selectedRows addIndex: _currentRow];
+ *_selectedRow = _currentRow;
+
+ if (notified == YES)
+ {
+ [tv setNeedsDisplayInRect: [tv rectOfRow: _currentRow]];
+ }
+ else
+ {
+ if (count > 1)
+ {
+ notified = YES;
+ }
+ }
+ if (notified == YES)
+ {
+ [tv _postSelectionIsChangingNotification];
+ }
+ }
+ else
+ {
+ // we know there is only one column selected
+ // this column is *_selectedRow
+
+ //begin checking code
+ if (![_selectedRows containsIndex: *_selectedRow])
+ {
+ NSLog(@"*_selectedRow is not the only selected row!");
+ }
+ //end checking code
+
+ if (*_selectedRow == _currentRow)
+ {
+ // currentRow is already selecteed
+ return;
+ }
+ else
+ {
+ [tv _unselectRow: *_selectedRow];
+ // CHANGE: This does a check more
+ [tv _selectRow: _currentRow];
+ [tv _postSelectionIsChangingNotification];
+ }
+ }
+ }
}
- else if ((selectionMode & ALLOWS_MULTIPLE)
- && (selectionMode & SHIFT_DOWN)
- && (selectionMode & ADDING_ROW))
- // we add new row to the current selection
+ else if ((selectionMode & ALLOWS_MULTIPLE)
+ && (selectionMode & SHIFT_DOWN)
+ && (selectionMode & ADDING_ROW))
+ // we add new row to the current selection
{
- if (_oldRow == -1)
- // this is the first pass
- {
- BOOL notified = NO;
- int i;
- int diff = _currentRow - _originalRow;
-
- if (diff >= 0)
- {
- for (i = _originalRow; i <= _currentRow; i++)
- {
- if ([_selectedRows containsIndex: i] ||
- [tv _selectRow: i])
- {
- *_selectedRow = i;
- notified = YES;
- }
- }
- }
- else
- {
- // this case does happen, (sometimes)
- for (i = _originalRow; i >= _currentRow; i--)
- {
- if ([_selectedRows containsIndex: i] ||
- [tv _selectRow: i])
- {
- *_selectedRow = i;
- notified = YES;
- }
- }
- }
-
- if (notified == YES)
- {
- [tv _postSelectionIsChangingNotification];
- }
- }
- else // new multiple selection, after first pass
- {
- int oldDiff, newDiff, i;
- oldDiff = _oldRow - _originalRow;
- newDiff = _currentRow - _originalRow;
- if (oldDiff >= 0 && newDiff >= 0)
- {
- if (newDiff >= oldDiff)
- // we're extending the selection
- {
- BOOL notified = NO;
-
- for (i = _oldRow + 1; i <= _currentRow; i++)
- {
- if ([_selectedRows containsIndex: i] ||
- [tv _selectRow: i])
- {
- *_selectedRow = i;
- notified = YES;
- }
- }
- if (notified == YES)
- {
- [tv _postSelectionIsChangingNotification];
- }
- }
- else
- // we're reducing the selection
- {
- BOOL notified = NO;
-
- for (i = _oldRow; i > _currentRow; i--)
- {
- if ([_oldSelectedRows containsIndex: i])
- {
- // this row was in the old selection
- // leave it selected
- continue;
- }
-
- if ([tv _unselectRow: i])
- {
- notified = YES;
- }
- }
- if (*_selectedRow == -1)
- {
- NSUInteger last = [_selectedRows lastIndex];
-
- if (last == NSNotFound)
- {
- *_selectedRow = -1;
- }
- else
- {
- *_selectedRow = last;
- }
- }
- if (notified)
- {
- [tv _postSelectionIsChangingNotification];
- }
- }
- }
- else if (oldDiff <= 0 && newDiff <= 0)
- {
- if (newDiff <= oldDiff)
- // we're extending the selection
- {
- BOOL notified = NO;
- for (i = _oldRow - 1; i >= _currentRow; i--)
- {
- if ([_selectedRows containsIndex: i] ||
- [tv _selectRow: i])
- {
- *_selectedRow = i;
- notified = YES;
- }
- }
- if (notified == YES)
- {
- [tv _postSelectionIsChangingNotification];
- }
- }
- else
- // we're reducing the selection
- {
- BOOL notified = NO;
-
- for (i = _oldRow; i < _currentRow; i++)
- {
- if ([_oldSelectedRows containsIndex: i])
- {
- // this row was in the old selection
- // leave it selected
- continue;
- }
-
- if ([tv _unselectRow: i])
- {
- notified = YES;
- }
- }
- if (*_selectedRow == -1)
- {
- NSUInteger first = [_selectedRows firstIndex];
-
- if (first == NSNotFound)
- {
- *_selectedRow = -1;
- }
- else
- {
- *_selectedRow = first;
- }
- }
- if (notified == YES)
- {
- [tv _postSelectionIsChangingNotification];
- }
- }
- }
- else if (oldDiff <= 0 && newDiff >= 0)
- {
- BOOL notified = NO;
-
- // we're reducing the selection
- {
- for (i = _oldRow; i < _originalRow; i++)
- {
- if ([_oldSelectedRows containsIndex: i])
- {
- // this row was in the old selection
- // leave it selected
- continue;
- }
-
- if ([tv _unselectRow: i])
- {
- notified = YES;
- }
- }
- }
- // then we're extending it
- for (i = _originalRow + 1; i <= _currentRow; i++)
- {
- if ([_selectedRows containsIndex: i] ||
- [tv _selectRow: i])
- {
- *_selectedRow = i;
- notified = YES;
- }
- }
-
- if (*_selectedRow == -1)
- {
- NSUInteger first = [_selectedRows firstIndex];
-
- if (first == NSNotFound)
- {
- *_selectedRow = -1;
- }
- else
- {
- *_selectedRow = first;
- }
- }
- if (notified == YES)
- {
- [tv _postSelectionIsChangingNotification];
- }
- }
- else if (oldDiff >= 0 && newDiff <= 0)
- {
- BOOL notified = NO;
-
- // we're reducing the selection
- for (i = _oldRow; i > _originalRow; i--)
- {
- if ([_oldSelectedRows containsIndex: i])
- {
- // this row was in the old selection
- // leave it selected
- continue;
- }
-
- if ([tv _unselectRow: i])
- {
- notified = YES;
- }
- }
- // then we're extending it
- for (i = _originalRow - 1; i >= _currentRow; i--)
- {
- if ([_selectedRows containsIndex: i] ||
- [tv _selectRow: i])
- {
- *_selectedRow = i;
- notified = YES;
- }
- }
-
- if (*_selectedRow == -1)
- {
- NSUInteger last = [_selectedRows lastIndex];
-
- if (last == NSNotFound)
- {
- *_selectedRow = -1;
- }
- else
- {
- *_selectedRow = last;
- }
- }
- if (notified == YES)
- {
- [tv _postSelectionIsChangingNotification];
- }
- }
-
- }
+ if (_oldRow == -1)
+ // this is the first pass
+ {
+ BOOL notified = NO;
+ int i;
+ int diff = _currentRow - _originalRow;
+
+ if (diff >= 0)
+ {
+ for (i = _originalRow; i <= _currentRow; i++)
+ {
+ if ([_selectedRows containsIndex: i] ||
+ [tv _selectRow: i])
+ {
+ *_selectedRow = i;
+ notified = YES;
+ }
+ }
+ }
+ else
+ {
+ // this case does happen, (sometimes)
+ for (i = _originalRow; i >= _currentRow; i--)
+ {
+ if ([_selectedRows containsIndex: i] ||
+ [tv _selectRow: i])
+ {
+ *_selectedRow = i;
+ notified = YES;
+ }
+ }
+ }
+
+ if (notified == YES)
+ {
+ [tv _postSelectionIsChangingNotification];
+ }
+ }
+ else // new multiple selection, after first pass
+ {
+ int oldDiff, newDiff, i;
+ oldDiff = _oldRow - _originalRow;
+ newDiff = _currentRow - _originalRow;
+ if (oldDiff >= 0 && newDiff >= 0)
+ {
+ if (newDiff >= oldDiff)
+ // we're extending the selection
+ {
+ BOOL notified = NO;
+
+ for (i = _oldRow + 1; i <= _currentRow; i++)
+ {
+ if ([_selectedRows containsIndex: i] ||
+ [tv _selectRow: i])
+ {
+ *_selectedRow = i;
+ notified = YES;
+ }
+ }
+ if (notified == YES)
+ {
+ [tv _postSelectionIsChangingNotification];
+ }
+ }
+ else
+ // we're reducing the selection
+ {
+ BOOL notified = NO;
+
+ for (i = _oldRow; i > _currentRow; i--)
+ {
+ if ([_oldSelectedRows containsIndex: i])
+ {
+ // this row was in the old selection
+ // leave it selected
+ continue;
+ }
+
+ if ([tv _unselectRow: i])
+ {
+ notified = YES;
+ }
+ }
+ if (*_selectedRow == -1)
+ {
+ NSUInteger last = [_selectedRows lastIndex];
+
+ if (last == NSNotFound)
+ {
+ *_selectedRow = -1;
+ }
+ else
+ {
+ *_selectedRow = last;
+ }
+ }
+ if (notified)
+ {
+ [tv _postSelectionIsChangingNotification];
+ }
+ }
+ }
+ else if (oldDiff <= 0 && newDiff <= 0)
+ {
+ if (newDiff <= oldDiff)
+ // we're extending the selection
+ {
+ BOOL notified = NO;
+ for (i = _oldRow - 1; i >= _currentRow; i--)
+ {
+ if ([_selectedRows containsIndex: i] ||
+ [tv _selectRow: i])
+ {
+ *_selectedRow = i;
+ notified = YES;
+ }
+ }
+ if (notified == YES)
+ {
+ [tv _postSelectionIsChangingNotification];
+ }
+ }
+ else
+ // we're reducing the selection
+ {
+ BOOL notified = NO;
+
+ for (i = _oldRow; i < _currentRow; i++)
+ {
+ if ([_oldSelectedRows containsIndex: i])
+ {
+ // this row was in the old selection
+ // leave it selected
+ continue;
+ }
+
+ if ([tv _unselectRow: i])
+ {
+ notified = YES;
+ }
+ }
+ if (*_selectedRow == -1)
+ {
+ NSUInteger first = [_selectedRows firstIndex];
+
+ if (first == NSNotFound)
+ {
+ *_selectedRow = -1;
+ }
+ else
+ {
+ *_selectedRow = first;
+ }
+ }
+ if (notified == YES)
+ {
+ [tv _postSelectionIsChangingNotification];
+ }
+ }
+ }
+ else if (oldDiff <= 0 && newDiff >= 0)
+ {
+ BOOL notified = NO;
+
+ // we're reducing the selection
+ {
+ for (i = _oldRow; i < _originalRow; i++)
+ {
+ if ([_oldSelectedRows containsIndex: i])
+ {
+ // this row was in the old selection
+ // leave it selected
+ continue;
+ }
+
+ if ([tv _unselectRow: i])
+ {
+ notified = YES;
+ }
+ }
+ }
+ // then we're extending it
+ for (i = _originalRow + 1; i <= _currentRow; i++)
+ {
+ if ([_selectedRows containsIndex: i] ||
+ [tv _selectRow: i])
+ {
+ *_selectedRow = i;
+ notified = YES;
+ }
+ }
+
+ if (*_selectedRow == -1)
+ {
+ NSUInteger first = [_selectedRows firstIndex];
+
+ if (first == NSNotFound)
+ {
+ *_selectedRow = -1;
+ }
+ else
+ {
+ *_selectedRow = first;
+ }
+ }
+ if (notified == YES)
+ {
+ [tv _postSelectionIsChangingNotification];
+ }
+ }
+ else if (oldDiff >= 0 && newDiff <= 0)
+ {
+ BOOL notified = NO;
+
+ // we're reducing the selection
+ for (i = _oldRow; i > _originalRow; i--)
+ {
+ if ([_oldSelectedRows containsIndex: i])
+ {
+ // this row was in the old selection
+ // leave it selected
+ continue;
+ }
+
+ if ([tv _unselectRow: i])
+ {
+ notified = YES;
+ }
+ }
+ // then we're extending it
+ for (i = _originalRow - 1; i >= _currentRow; i--)
+ {
+ if ([_selectedRows containsIndex: i] ||
+ [tv _selectRow: i])
+ {
+ *_selectedRow = i;
+ notified = YES;
+ }
+ }
+
+ if (*_selectedRow == -1)
+ {
+ NSUInteger last = [_selectedRows lastIndex];
+
+ if (last == NSNotFound)
+ {
+ *_selectedRow = -1;
+ }
+ else
+ {
+ *_selectedRow = last;
+ }
+ }
+ if (notified == YES)
+ {
+ [tv _postSelectionIsChangingNotification];
+ }
+ }
+
+ }
}
- else if ((selectionMode & ALLOWS_MULTIPLE)
- && ((selectionMode & SHIFT_DOWN) == 0)
- && (selectionMode & ALLOWS_EMPTY)
- )
- // ic, sr : ok
- // new multiple selection (empty possible)
+ else if ((selectionMode & ALLOWS_MULTIPLE)
+ && ((selectionMode & SHIFT_DOWN) == 0)
+ && (selectionMode & ALLOWS_EMPTY)
+ )
+ // ic, sr : ok
+ // new multiple selection (empty possible)
{
- if (_oldRow == -1)
- // this is the first pass
- // we'll clear the selection first
- {
- int diff, i;
- int count = [_selectedRows count];
- BOOL notified = NO;
- diff = _currentRow - _originalRow;
-
- if (count > 0)
- {
- notified = YES;
- }
-
- [tv _unselectAllRows];
-
- if (diff >= 0)
- {
- for (i = _originalRow; i <= _currentRow; i++)
- {
- if ([tv _selectRow: i])
- {
- notified = YES;
- }
- }
- }
- else
- {
- // this case does happen (sometimes)
- for (i = _originalRow; i >= _currentRow; i--)
- {
- if ([tv _selectRow: i])
- {
- notified = YES;
- }
- }
- }
- if (notified == YES)
- {
- [tv _postSelectionIsChangingNotification];
- }
- }
- else // new multiple selection, after first pass
- {
- int oldDiff, newDiff, i;
- oldDiff = _oldRow - _originalRow;
- newDiff = _currentRow - _originalRow;
- if (oldDiff >= 0 && newDiff >= 0)
- {
- if (newDiff >= oldDiff)
- {
- BOOL notified = NO;
- for (i = _oldRow + 1; i <= _currentRow; i++)
- {
- if ([tv _selectRow: i])
- {
- notified = YES;
- }
- }
- if (notified == YES)
- {
- [tv _postSelectionIsChangingNotification];
- }
- }
- else
- {
- BOOL notified = NO;
-
- for (i = _oldRow; i > _currentRow; i--)
- {
- if ([tv _unselectRow: i])
- {
- notified = YES;
- }
- }
- if (*_selectedRow == -1)
- {
- NSUInteger last = [_selectedRows lastIndex];
-
- if (last == NSNotFound)
- {
- *_selectedRow = -1;
- }
- else
- {
- *_selectedRow = last;
- }
- }
- if (notified == YES)
- {
- [tv _postSelectionIsChangingNotification];
- }
- }
- }
- else if (oldDiff <= 0 && newDiff <= 0)
- {
- if (newDiff <= oldDiff)
- // we're extending the selection
- {
- BOOL notified = NO;
-
- for (i = _oldRow - 1; i >= _currentRow; i--)
- {
- if ([tv _selectRow: i])
- {
- notified = YES;
- }
- }
- if (notified == YES)
- {
- [tv _postSelectionIsChangingNotification];
- }
- }
- else
- // we're reducing the selection
- {
- BOOL notified = NO;
-
- for (i = _oldRow; i < _currentRow; i++)
- {
- if ([tv _unselectRow: i])
- {
- notified = YES;
- }
- }
- if (*_selectedRow == -1)
- {
- NSUInteger first = [_selectedRows firstIndex];
-
- if (first == NSNotFound)
- {
- *_selectedRow = -1;
- }
- else
- {
- *_selectedRow = first;
- }
- }
- if (notified == YES)
- {
- [tv _postSelectionIsChangingNotification];
- }
- }
- }
- else if (oldDiff <= 0 && newDiff >= 0)
- {
- BOOL notified = NO;
-
- // we're reducing the selection
- for (i = _oldRow; i < _originalRow; i++)
- {
- if ([tv _unselectRow: i])
- {
- notified = YES;
- }
- }
- // then we're extending it
- for (i = _originalRow + 1; i <= _currentRow; i++)
- {
- if ([tv _selectRow: i])
- {
- notified = YES;
- }
- }
-
- if (*_selectedRow == -1)
- {
- NSUInteger first = [_selectedRows firstIndex];
-
- if (first == NSNotFound)
- {
- *_selectedRow = -1;
- }
- else
- {
- *_selectedRow = first;
- }
- }
- if (notified == YES)
- {
- [tv _postSelectionIsChangingNotification];
- }
- }
- else if (oldDiff >= 0 && newDiff <= 0)
- {
- BOOL notified = NO;
-
- // we're reducing the selection
- for (i = _oldRow; i > _originalRow; i--)
- {
- if ([tv _unselectRow: i])
- {
- notified = YES;
- }
- }
- // then we're extending it
- for (i = _originalRow - 1; i >= _currentRow; i--)
- {
- if ([tv _selectRow: i])
- {
- notified = YES;
- }
- }
-
- if (*_selectedRow == -1)
- {
- NSUInteger last = [_selectedRows lastIndex];
-
- if (last == NSNotFound)
- {
- *_selectedRow = -1;
- }
- else
- {
- *_selectedRow = last;
- }
- }
- if (notified == YES)
- {
- [tv _postSelectionIsChangingNotification];
- }
- }
- }
+ if (_oldRow == -1)
+ // this is the first pass
+ // we'll clear the selection first
+ {
+ int diff, i;
+ int count = [_selectedRows count];
+ BOOL notified = NO;
+ diff = _currentRow - _originalRow;
+
+ if (count > 0)
+ {
+ notified = YES;
+ }
+
+ [tv _unselectAllRows];
+
+ if (diff >= 0)
+ {
+ for (i = _originalRow; i <= _currentRow; i++)
+ {
+ if ([tv _selectRow: i])
+ {
+ notified = YES;
+ }
+ }
+ }
+ else
+ {
+ // this case does happen (sometimes)
+ for (i = _originalRow; i >= _currentRow; i--)
+ {
+ if ([tv _selectRow: i])
+ {
+ notified = YES;
+ }
+ }
+ }
+ if (notified == YES)
+ {
+ [tv _postSelectionIsChangingNotification];
+ }
+ }
+ else // new multiple selection, after first pass
+ {
+ int oldDiff, newDiff, i;
+ oldDiff = _oldRow - _originalRow;
+ newDiff = _currentRow - _originalRow;
+ if (oldDiff >= 0 && newDiff >= 0)
+ {
+ if (newDiff >= oldDiff)
+ {
+ BOOL notified = NO;
+ for (i = _oldRow + 1; i <= _currentRow; i++)
+ {
+ if ([tv _selectRow: i])
+ {
+ notified = YES;
+ }
+ }
+ if (notified == YES)
+ {
+ [tv _postSelectionIsChangingNotification];
+ }
+ }
+ else
+ {
+ BOOL notified = NO;
+
+ for (i = _oldRow; i > _currentRow; i--)
+ {
+ if ([tv _unselectRow: i])
+ {
+ notified = YES;
+ }
+ }
+ if (*_selectedRow == -1)
+ {
+ NSUInteger last = [_selectedRows lastIndex];
+
+ if (last == NSNotFound)
+ {
+ *_selectedRow = -1;
+ }
+ else
+ {
+ *_selectedRow = last;
+ }
+ }
+ if (notified == YES)
+ {
+ [tv _postSelectionIsChangingNotification];
+ }
+ }
+ }
+ else if (oldDiff <= 0 && newDiff <= 0)
+ {
+ if (newDiff <= oldDiff)
+ // we're extending the selection
+ {
+ BOOL notified = NO;
+
+ for (i = _oldRow - 1; i >= _currentRow; i--)
+ {
+ if ([tv _selectRow: i])
+ {
+ notified = YES;
+ }
+ }
+ if (notified == YES)
+ {
+ [tv _postSelectionIsChangingNotification];
+ }
+ }
+ else
+ // we're reducing the selection
+ {
+ BOOL notified = NO;
+
+ for (i = _oldRow; i < _currentRow; i++)
+ {
+ if ([tv _unselectRow: i])
+ {
+ notified = YES;
+ }
+ }
+ if (*_selectedRow == -1)
+ {
+ NSUInteger first = [_selectedRows firstIndex];
+
+ if (first == NSNotFound)
+ {
+ *_selectedRow = -1;
+ }
+ else
+ {
+ *_selectedRow = first;
+ }
+ }
+ if (notified == YES)
+ {
+ [tv _postSelectionIsChangingNotification];
+ }
+ }
+ }
+ else if (oldDiff <= 0 && newDiff >= 0)
+ {
+ BOOL notified = NO;
+
+ // we're reducing the selection
+ for (i = _oldRow; i < _originalRow; i++)
+ {
+ if ([tv _unselectRow: i])
+ {
+ notified = YES;
+ }
+ }
+ // then we're extending it
+ for (i = _originalRow + 1; i <= _currentRow; i++)
+ {
+ if ([tv _selectRow: i])
+ {
+ notified = YES;
+ }
+ }
+
+ if (*_selectedRow == -1)
+ {
+ NSUInteger first = [_selectedRows firstIndex];
+
+ if (first == NSNotFound)
+ {
+ *_selectedRow = -1;
+ }
+ else
+ {
+ *_selectedRow = first;
+ }
+ }
+ if (notified == YES)
+ {
+ [tv _postSelectionIsChangingNotification];
+ }
+ }
+ else if (oldDiff >= 0 && newDiff <= 0)
+ {
+ BOOL notified = NO;
+
+ // we're reducing the selection
+ for (i = _oldRow; i > _originalRow; i--)
+ {
+ if ([tv _unselectRow: i])
+ {
+ notified = YES;
+ }
+ }
+ // then we're extending it
+ for (i = _originalRow - 1; i >= _currentRow; i--)
+ {
+ if ([tv _selectRow: i])
+ {
+ notified = YES;
+ }
+ }
+
+ if (*_selectedRow == -1)
+ {
+ NSUInteger last = [_selectedRows lastIndex];
+
+ if (last == NSNotFound)
+ {
+ *_selectedRow = -1;
+ }
+ else
+ {
+ *_selectedRow = last;
+ }
+ }
+ if (notified == YES)
+ {
+ [tv _postSelectionIsChangingNotification];
+ }
+ }
+ }
}
- else if (((selectionMode & ALLOWS_MULTIPLE)
- && ((selectionMode & SHIFT_DOWN) == 0)
- && ((selectionMode & ALLOWS_EMPTY) == 0)
- && (selectionMode & ADDING_ROW))
- // the following case can be assimilated to the
- // one before, although it will lead to an
- // extra redraw
- // TODO: solve this issue
- ||
- ((selectionMode & ALLOWS_MULTIPLE)
- && ((selectionMode & SHIFT_DOWN) == 0)
- && ((selectionMode & ALLOWS_EMPTY) == 0)
- && ((selectionMode & ADDING_ROW) == 0))
- )
+ else if (((selectionMode & ALLOWS_MULTIPLE)
+ && ((selectionMode & SHIFT_DOWN) == 0)
+ && ((selectionMode & ALLOWS_EMPTY) == 0)
+ && (selectionMode & ADDING_ROW))
+ // the following case can be assimilated to the
+ // one before, although it will lead to an
+ // extra redraw
+ // TODO: solve this issue
+ ||
+ ((selectionMode & ALLOWS_MULTIPLE)
+ && ((selectionMode & SHIFT_DOWN) == 0)
+ && ((selectionMode & ALLOWS_EMPTY) == 0)
+ && ((selectionMode & ADDING_ROW) == 0))
+ )
{
- if (_oldRow == -1)
- {
- // if we can select the _originalRow, we'll clear the old selection
- // else we'll add to the old selection
- if ([tv _shouldSelectRow: _currentRow] == YES)
- {
- // let's clear the old selection
- // this code is copied from another case
- // (AM = 1, SD=0, AE=1, AR=*, first pass)
- int diff, i;
- int count = [_selectedRows count];
- BOOL notified = NO;
- diff = _currentRow - _originalRow;
-
- if (count > 0)
+ if (_oldRow == -1)
+ {
+ // if we can select the _originalRow, we'll clear the old selection
+ // else we'll add to the old selection
+ if ([tv _shouldSelectRow: _currentRow] == YES)
+ {
+ // let's clear the old selection
+ // this code is copied from another case
+ // (AM = 1, SD=0, AE=1, AR=*, first pass)
+ int diff, i;
+ int count = [_selectedRows count];
+ BOOL notified = NO;
+ diff = _currentRow - _originalRow;
+
+ if (count > 0)
+ {
+ notified = YES;
+ }
+
+ [tv _unselectAllRows];
+
+ if (diff >= 0)
+ {
+ for (i = _originalRow; i <= _currentRow; i++)
+ {
+ if ([tv _selectRow: i])
+ {
+ notified = YES;
+ }
+ }
+ }
+ else
+ {
+ for (i = _originalRow; i >= _currentRow; i--)
+ {
+ if ([tv _selectRow: i])
+ {
+ notified = YES;
+ }
+ }
+ }
+ if (notified == YES)
{
- notified = YES;
+ [tv _postSelectionIsChangingNotification];
}
-
- [tv _unselectAllRows];
-
- if (diff >= 0)
- {
- for (i = _originalRow; i <= _currentRow; i++)
- {
- if ([tv _selectRow: i])
- {
- notified = YES;
- }
- }
- }
- else
- {
- for (i = _originalRow; i >= _currentRow; i--)
- {
- if ([tv _selectRow: i])
- {
- notified = YES;
- }
- }
- }
- if (notified == YES)
- {
- [tv _postSelectionIsChangingNotification];
- }
- }
- else
- {
- // let's add to the old selection
- // this code is copied from another case
- // (AM=1, SD=1, AE=*, AR=1)
- int diff, i;
- BOOL notified = NO;
- diff = _currentRow - _originalRow;
-
- if (diff >= 0)
- {
- for (i = _originalRow; i <= _currentRow; i++)
- {
- if ([_selectedRows containsIndex: i] ||
- [tv _selectRow: i])
- {
- *_selectedRow = i;
- notified = YES;
- }
- }
- }
- else
- {
- // this case does happen (sometimes)
- for (i = _originalRow; i >= _currentRow; i--)
- {
- if ([_selectedRows containsIndex: i] ||
- [tv _selectRow: i])
- {
- *_selectedRow = i;
- notified = YES;
- }
- }
- }
- if (notified == YES)
- {
- [tv _postSelectionIsChangingNotification];
- }
- }
- }
- else if ([_selectedRows containsIndex: _originalRow])
- // as the originalRow is selected,
- // we are in a new selection
- {
- // this code is copied from another case
- // (AM=1, SD=0, AE=1, AR=*, after first pass)
- int oldDiff, newDiff, i;
- oldDiff = _oldRow - _originalRow;
- newDiff = _currentRow - _originalRow;
- if (oldDiff >= 0 && newDiff >= 0)
- {
- if (newDiff >= oldDiff)
- {
- BOOL notified = NO;
- for (i = _oldRow + 1; i <= _currentRow; i++)
- {
- if ([tv _selectRow: i])
- {
- notified = YES;
- }
- }
- if (notified == YES)
- {
- [tv _postSelectionIsChangingNotification];
- }
- }
- else
- {
- BOOL notified = NO;
-
- for (i = _oldRow; i > _currentRow; i--)
- {
- if ([tv _unselectRow: i])
- {
- notified = YES;
- }
- }
- if (*_selectedRow == -1)
- {
- NSUInteger last = [_selectedRows lastIndex];
-
- if (last == NSNotFound)
- {
- *_selectedRow = -1;
- }
- else
- {
- *_selectedRow = last;
- }
- }
- if (notified == YES)
- {
- [tv _postSelectionIsChangingNotification];
- }
- }
- }
- else if (oldDiff <= 0 && newDiff <= 0)
- {
- if (newDiff <= oldDiff)
- // we're extending the selection
- {
- BOOL notified = NO;
-
- for (i = _oldRow - 1; i >= _currentRow; i--)
- {
- if ([tv _selectRow: i])
- {
- notified = YES;
- }
- }
- if (notified == YES)
- {
- [tv _postSelectionIsChangingNotification];
- }
- }
- else
- // we're reducing the selection
- {
- BOOL notified = NO;
-
- for (i = _oldRow; i < _currentRow; i++)
- {
- if ([tv _unselectRow: i])
- {
- notified = YES;
- }
- }
-
- if (*_selectedRow == -1)
- {
- NSUInteger first = [_selectedRows firstIndex];
-
- if (first == NSNotFound)
- {
- *_selectedRow = -1;
- }
- else
- {
- *_selectedRow = first;
- }
- }
- if (notified == YES)
- {
- [tv _postSelectionIsChangingNotification];
- }
- }
- }
- else if (oldDiff <= 0 && newDiff >= 0)
- {
- BOOL notified = NO;
-
- // we're reducing the selection
- for (i = _oldRow; i < _originalRow; i++)
- {
- if ([tv _unselectRow: i])
- {
- notified = YES;
- }
- }
- // then we're extending it
- for (i = _originalRow + 1; i <= _currentRow; i++)
- {
- if ([tv _selectRow: i])
- {
- notified = YES;
- }
- }
-
- if (*_selectedRow == -1)
- {
- NSUInteger first = [_selectedRows firstIndex];
-
- if (first == NSNotFound)
- {
- *_selectedRow = -1;
- }
- else
- {
- *_selectedRow = first;
- }
- }
- if (notified == YES)
- {
- [tv _postSelectionIsChangingNotification];
- }
- }
- else if (oldDiff >= 0 && newDiff <= 0)
- {
- BOOL notified = NO;
-
- // we're reducing the selection
- for (i = _oldRow; i > _originalRow; i--)
- {
- if ([tv _unselectRow: i])
- {
- notified = YES;
- }
- }
- // then we're extending it
- for (i = _originalRow - 1; i >= _currentRow; i--)
- {
- if ([tv _selectRow: i])
- {
- notified = YES;
- }
- }
-
- if (*_selectedRow == -1)
- {
- NSUInteger last = [_selectedRows lastIndex];
-
- if (last == NSNotFound)
- {
- *_selectedRow = -1;
- }
- else
- {
- *_selectedRow = last;
- }
- }
- if (notified == YES)
- {
- [tv _postSelectionIsChangingNotification];
- }
- }
- }
- else
- // as the originalRow is not selection,
- // we are adding to the old selection
- {
- // this code is copied from another case
- // (AM=1, SD=1, AE=*, AR=1, after first pass)
- int oldDiff, newDiff, i;
- oldDiff = _oldRow - _originalRow;
- newDiff = _currentRow - _originalRow;
-
- if (oldDiff >= 0 && newDiff >= 0)
- {
- if (newDiff >= oldDiff)
- // we're extending the selection
- {
- BOOL notified = NO;
- for (i = _oldRow + 1; i <= _currentRow; i++)
- {
- if ([_selectedRows containsIndex: i] ||
- [tv _selectRow: i])
- {
- *_selectedRow = i;
- notified = YES;
- }
- }
- if (notified == YES)
- {
- [tv _postSelectionIsChangingNotification];
- }
- }
- else
- // we're reducing the selection
- {
- BOOL notified = NO;
-
- for (i = _oldRow; i > _currentRow; i--)
- {
- if ([_oldSelectedRows containsIndex: i])
- {
- // this row was in the old selection
- // leave it selected
- continue;
- }
-
- if ([tv _unselectRow: i])
- {
- notified = YES;
- }
- }
-
- if (*_selectedRow == -1)
- {
- NSUInteger last = [_selectedRows lastIndex];
-
- if (last == NSNotFound)
- {
- *_selectedRow = -1;
- }
- else
- {
- *_selectedRow = last;
- }
- }
- if (notified == YES)
- {
- [tv _postSelectionIsChangingNotification];
- }
- }
- }
- else if (oldDiff <= 0 && newDiff <= 0)
- {
- if (newDiff <= oldDiff)
- // we're extending the selection
- {
- BOOL notified = NO;
- for (i = _oldRow - 1; i >= _currentRow; i--)
- {
- if ([_selectedRows containsIndex: i] ||
- [tv _selectRow: i])
- {
- *_selectedRow = i;
- notified = YES;
- }
- }
-
- if (notified == YES)
- {
- [tv _postSelectionIsChangingNotification];
- }
- }
- else
- // we're reducing the selection
- {
- BOOL notified = NO;
-
- for (i = _oldRow; i < _currentRow; i++)
- {
- if ([_oldSelectedRows containsIndex: i])
- {
- // this row was in the old selection
- // leave it selected
- continue;
- }
- if ([tv _unselectRow: i])
- {
- notified = YES;
- }
- }
- if (*_selectedRow == -1)
- {
- NSUInteger first = [_selectedRows firstIndex];
-
- if (first == NSNotFound)
- {
- *_selectedRow = -1;
- }
- else
- {
- *_selectedRow = first;
- }
- }
- if (notified == YES)
- {
- [tv _postSelectionIsChangingNotification];
- }
- }
- }
- else if (oldDiff <= 0 && newDiff >= 0)
- {
- BOOL notified = NO;
-
- // we're reducing the selection
- for (i = _oldRow; i < _originalRow; i++)
- {
- if ([_oldSelectedRows containsIndex: i])
- {
- // this row was in the old selection
- // leave it selected
- continue;
- }
- if ([tv _unselectRow: i])
- {
- notified = YES;
- }
- }
- // then we're extending it
- for (i = _originalRow + 1; i <= _currentRow; i++)
- {
- if ([_selectedRows containsIndex: i] ||
- [tv _selectRow: i])
- {
- *_selectedRow = i;
- notified = YES;
- }
- }
-
- if (*_selectedRow == -1)
- {
- NSUInteger first = [_selectedRows firstIndex];
-
- if (first == NSNotFound)
- {
- *_selectedRow = -1;
- }
- else
- {
- *_selectedRow = first;
- }
- }
- if (notified == YES)
- {
- [tv _postSelectionIsChangingNotification];
- }
- }
- else if (oldDiff >= 0 && newDiff <= 0)
- {
- BOOL notified = NO;
-
- // we're reducing the selection
- for (i = _oldRow; i > _originalRow; i--)
- {
- if ([_oldSelectedRows containsIndex: i])
- {
- // this row was in the old selection
- // leave it selected
- continue;
- }
-
- if ([tv _unselectRow: i])
- {
- notified = YES;
- }
- }
-
- // then we're extending it
- for (i = _originalRow - 1; i >= _currentRow; i--)
- {
- if ([_selectedRows containsIndex: i] ||
- [tv _selectRow: i])
- {
- *_selectedRow = i;
- notified = YES;
- }
- }
-
- if (*_selectedRow == -1)
- {
- NSUInteger last = [_selectedRows lastIndex];
-
- if (last == NSNotFound)
- {
- *_selectedRow = -1;
- }
- else
- {
- *_selectedRow = last;
- }
- }
- if (notified == YES)
- {
- [tv _postSelectionIsChangingNotification];
- }
- }
- }
+ }
+ else
+ {
+ // let's add to the old selection
+ // this code is copied from another case
+ // (AM=1, SD=1, AE=*, AR=1)
+ int diff, i;
+ BOOL notified = NO;
+ diff = _currentRow - _originalRow;
+
+ if (diff >= 0)
+ {
+ for (i = _originalRow; i <= _currentRow; i++)
+ {
+ if ([_selectedRows containsIndex: i] ||
+ [tv _selectRow: i])
+ {
+ *_selectedRow = i;
+ notified = YES;
+ }
+ }
+ }
+ else
+ {
+ // this case does happen (sometimes)
+ for (i = _originalRow; i >= _currentRow; i--)
+ {
+ if ([_selectedRows containsIndex: i] ||
+ [tv _selectRow: i])
+ {
+ *_selectedRow = i;
+ notified = YES;
+ }
+ }
+ }
+ if (notified == YES)
+ {
+ [tv _postSelectionIsChangingNotification];
+ }
+ }
+ }
+ else if ([_selectedRows containsIndex: _originalRow])
+ // as the originalRow is selected,
+ // we are in a new selection
+ {
+ // this code is copied from another case
+ // (AM=1, SD=0, AE=1, AR=*, after first pass)
+ int oldDiff, newDiff, i;
+ oldDiff = _oldRow - _originalRow;
+ newDiff = _currentRow - _originalRow;
+ if (oldDiff >= 0 && newDiff >= 0)
+ {
+ if (newDiff >= oldDiff)
+ {
+ BOOL notified = NO;
+ for (i = _oldRow + 1; i <= _currentRow; i++)
+ {
+ if ([tv _selectRow: i])
+ {
+ notified = YES;
+ }
+ }
+ if (notified == YES)
+ {
+ [tv _postSelectionIsChangingNotification];
+ }
+ }
+ else
+ {
+ BOOL notified = NO;
+
+ for (i = _oldRow; i > _currentRow; i--)
+ {
+ if ([tv _unselectRow: i])
+ {
+ notified = YES;
+ }
+ }
+ if (*_selectedRow == -1)
+ {
+ NSUInteger last = [_selectedRows lastIndex];
+
+ if (last == NSNotFound)
+ {
+ *_selectedRow = -1;
+ }
+ else
+ {
+ *_selectedRow = last;
+ }
+ }
+ if (notified == YES)
+ {
+ [tv _postSelectionIsChangingNotification];
+ }
+ }
+ }
+ else if (oldDiff <= 0 && newDiff <= 0)
+ {
+ if (newDiff <= oldDiff)
+ // we're extending the selection
+ {
+ BOOL notified = NO;
+
+ for (i = _oldRow - 1; i >= _currentRow; i--)
+ {
+ if ([tv _selectRow: i])
+ {
+ notified = YES;
+ }
+ }
+ if (notified == YES)
+ {
+ [tv _postSelectionIsChangingNotification];
+ }
+ }
+ else
+ // we're reducing the selection
+ {
+ BOOL notified = NO;
+
+ for (i = _oldRow; i < _currentRow; i++)
+ {
+ if ([tv _unselectRow: i])
+ {
+ notified = YES;
+ }
+ }
+
+ if (*_selectedRow == -1)
+ {
+ NSUInteger first = [_selectedRows firstIndex];
+
+ if (first == NSNotFound)
+ {
+ *_selectedRow = -1;
+ }
+ else
+ {
+ *_selectedRow = first;
+ }
+ }
+ if (notified == YES)
+ {
+ [tv _postSelectionIsChangingNotification];
+ }
+ }
+ }
+ else if (oldDiff <= 0 && newDiff >= 0)
+ {
+ BOOL notified = NO;
+
+ // we're reducing the selection
+ for (i = _oldRow; i < _originalRow; i++)
+ {
+ if ([tv _unselectRow: i])
+ {
+ notified = YES;
+ }
+ }
+ // then we're extending it
+ for (i = _originalRow + 1; i <= _currentRow; i++)
+ {
+ if ([tv _selectRow: i])
+ {
+ notified = YES;
+ }
+ }
+
+ if (*_selectedRow == -1)
+ {
+ NSUInteger first = [_selectedRows firstIndex];
+
+ if (first == NSNotFound)
+ {
+ *_selectedRow = -1;
+ }
+ else
+ {
+ *_selectedRow = first;
+ }
+ }
+ if (notified == YES)
+ {
+ [tv _postSelectionIsChangingNotification];
+ }
+ }
+ else if (oldDiff >= 0 && newDiff <= 0)
+ {
+ BOOL notified = NO;
+
+ // we're reducing the selection
+ for (i = _oldRow; i > _originalRow; i--)
+ {
+ if ([tv _unselectRow: i])
+ {
+ notified = YES;
+ }
+ }
+ // then we're extending it
+ for (i = _originalRow - 1; i >= _currentRow; i--)
+ {
+ if ([tv _selectRow: i])
+ {
+ notified = YES;
+ }
+ }
+
+ if (*_selectedRow == -1)
+ {
+ NSUInteger last = [_selectedRows lastIndex];
+
+ if (last == NSNotFound)
+ {
+ *_selectedRow = -1;
+ }
+ else
+ {
+ *_selectedRow = last;
+ }
+ }
+ if (notified == YES)
+ {
+ [tv _postSelectionIsChangingNotification];
+ }
+ }
+ }
+ else
+ // as the originalRow is not selection,
+ // we are adding to the old selection
+ {
+ // this code is copied from another case
+ // (AM=1, SD=1, AE=*, AR=1, after first pass)
+ int oldDiff, newDiff, i;
+ oldDiff = _oldRow - _originalRow;
+ newDiff = _currentRow - _originalRow;
+
+ if (oldDiff >= 0 && newDiff >= 0)
+ {
+ if (newDiff >= oldDiff)
+ // we're extending the selection
+ {
+ BOOL notified = NO;
+ for (i = _oldRow + 1; i <= _currentRow; i++)
+ {
+ if ([_selectedRows containsIndex: i] ||
+ [tv _selectRow: i])
+ {
+ *_selectedRow = i;
+ notified = YES;
+ }
+ }
+ if (notified == YES)
+ {
+ [tv _postSelectionIsChangingNotification];
+ }
+ }
+ else
+ // we're reducing the selection
+ {
+ BOOL notified = NO;
+
+ for (i = _oldRow; i > _currentRow; i--)
+ {
+ if ([_oldSelectedRows containsIndex: i])
+ {
+ // this row was in the old selection
+ // leave it selected
+ continue;
+ }
+
+ if ([tv _unselectRow: i])
+ {
+ notified = YES;
+ }
+ }
+
+ if (*_selectedRow == -1)
+ {
+ NSUInteger last = [_selectedRows lastIndex];
+
+ if (last == NSNotFound)
+ {
+ *_selectedRow = -1;
+ }
+ else
+ {
+ *_selectedRow = last;
+ }
+ }
+ if (notified == YES)
+ {
+ [tv _postSelectionIsChangingNotification];
+ }
+ }
+ }
+ else if (oldDiff <= 0 && newDiff <= 0)
+ {
+ if (newDiff <= oldDiff)
+ // we're extending the selection
+ {
+ BOOL notified = NO;
+ for (i = _oldRow - 1; i >= _currentRow; i--)
+ {
+ if ([_selectedRows containsIndex: i] ||
+ [tv _selectRow: i])
+ {
+ *_selectedRow = i;
+ notified = YES;
+ }
+ }
+
+ if (notified == YES)
+ {
+ [tv _postSelectionIsChangingNotification];
+ }
+ }
+ else
+ // we're reducing the selection
+ {
+ BOOL notified = NO;
+
+ for (i = _oldRow; i < _currentRow; i++)
+ {
+ if ([_oldSelectedRows containsIndex: i])
+ {
+ // this row was in the old selection
+ // leave it selected
+ continue;
+ }
+ if ([tv _unselectRow: i])
+ {
+ notified = YES;
+ }
+ }
+ if (*_selectedRow == -1)
+ {
+ NSUInteger first = [_selectedRows firstIndex];
+
+ if (first == NSNotFound)
+ {
+ *_selectedRow = -1;
+ }
+ else
+ {
+ *_selectedRow = first;
+ }
+ }
+ if (notified == YES)
+ {
+ [tv _postSelectionIsChangingNotification];
+ }
+ }
+ }
+ else if (oldDiff <= 0 && newDiff >= 0)
+ {
+ BOOL notified = NO;
+
+ // we're reducing the selection
+ for (i = _oldRow; i < _originalRow; i++)
+ {
+ if ([_oldSelectedRows containsIndex: i])
+ {
+ // this row was in the old selection
+ // leave it selected
+ continue;
+ }
+ if ([tv _unselectRow: i])
+ {
+ notified = YES;
+ }
+ }
+ // then we're extending it
+ for (i = _originalRow + 1; i <= _currentRow; i++)
+ {
+ if ([_selectedRows containsIndex: i] ||
+ [tv _selectRow: i])
+ {
+ *_selectedRow = i;
+ notified = YES;
+ }
+ }
+
+ if (*_selectedRow == -1)
+ {
+ NSUInteger first = [_selectedRows firstIndex];
+
+ if (first == NSNotFound)
+ {
+ *_selectedRow = -1;
+ }
+ else
+ {
+ *_selectedRow = first;
+ }
+ }
+ if (notified == YES)
+ {
+ [tv _postSelectionIsChangingNotification];
+ }
+ }
+ else if (oldDiff >= 0 && newDiff <= 0)
+ {
+ BOOL notified = NO;
+
+ // we're reducing the selection
+ for (i = _oldRow; i > _originalRow; i--)
+ {
+ if ([_oldSelectedRows containsIndex: i])
+ {
+ // this row was in the old selection
+ // leave it selected
+ continue;
+ }
+
+ if ([tv _unselectRow: i])
+ {
+ notified = YES;
+ }
+ }
+
+ // then we're extending it
+ for (i = _originalRow - 1; i >= _currentRow; i--)
+ {
+ if ([_selectedRows containsIndex: i] ||
+ [tv _selectRow: i])
+ {
+ *_selectedRow = i;
+ notified = YES;
+ }
+ }
+
+ if (*_selectedRow == -1)
+ {
+ NSUInteger last = [_selectedRows lastIndex];
+
+ if (last == NSNotFound)
+ {
+ *_selectedRow = -1;
+ }
+ else
+ {
+ *_selectedRow = last;
+ }
+ }
+ if (notified == YES)
+ {
+ [tv _postSelectionIsChangingNotification];
+ }
+ }
+ }
}
- else if ((selectionMode & ALLOWS_MULTIPLE)
- && (selectionMode & SHIFT_DOWN)
- && (selectionMode & ALLOWS_EMPTY)
- && ((selectionMode & ADDING_ROW) == 0))
+ else if ((selectionMode & ALLOWS_MULTIPLE)
+ && (selectionMode & SHIFT_DOWN)
+ && (selectionMode & ALLOWS_EMPTY)
+ && ((selectionMode & ADDING_ROW) == 0))
{
- if (_oldRow == -1)
- // this is the first pass
- {
- int diff, i;
- BOOL notified = NO;
-
- diff = _currentRow - _originalRow;
-
- if (diff >= 0)
- {
- for (i = _originalRow; i <= _currentRow; i++)
- {
- if ([tv _unselectRow: i])
- {
- notified = YES;
- }
- }
- if (*_selectedRow == -1)
- {
- NSUInteger first = [_selectedRows firstIndex];
-
- if (first == NSNotFound)
- {
- *_selectedRow = -1;
- }
- else
- {
- *_selectedRow = first;
- }
- }
- }
- else
- {
- // this case does happen (sometimes)
- for (i = _originalRow; i >= _currentRow; i--)
- {
- if ([tv _unselectRow: i])
- {
- notified = YES;
- }
- }
- if (*_selectedRow == -1)
- {
- NSUInteger first = [_selectedRows firstIndex];
-
- if (first == NSNotFound)
- {
- *_selectedRow = -1;
- }
- else
- {
- *_selectedRow = first;
- }
- }
- }
- if (notified == YES)
- {
- [tv _postSelectionIsChangingNotification];
- }
- }
- else // new multiple antiselection, after first pass
- {
- int oldDiff, newDiff, i;
-
- oldDiff = _oldRow - _originalRow;
- newDiff = _currentRow - _originalRow;
- if (oldDiff >= 0 && newDiff >= 0)
- {
- if (newDiff >= oldDiff)
- // we're extending the antiselection
- {
- BOOL notified = NO;
- for (i = _oldRow + 1; i <= _currentRow; i++)
- {
- if ([tv _unselectRow: i])
- {
- notified = YES;
- }
- }
-
- if (*_selectedRow == -1)
- {
- NSUInteger first = [_selectedRows firstIndex];
-
- if (first == NSNotFound)
- {
- *_selectedRow = -1;
- }
- else
- {
- *_selectedRow = first;
- }
- }
-
- if (notified == YES)
- {
- [tv _postSelectionIsChangingNotification];
- }
- }
- else
- // we're reducing the selection
- {
- BOOL notified = NO;
-
- for (i = _oldRow; i > _currentRow; i--)
- {
- if ([_oldSelectedRows containsIndex: i])
- {
- // this row was in the old selection
- // select it
- [tv setNeedsDisplayInRect: [tv rectOfRow: i]];
- [_selectedRows addIndex: i];
- *_selectedRow = i;
- notified = YES;
- }
- }
- if (notified == YES)
- {
- [tv _postSelectionIsChangingNotification];
- }
- }
- }
- else if (oldDiff <= 0 && newDiff <= 0)
- {
- if (newDiff <= oldDiff)
- // we're extending the selection
- {
- BOOL notified = NO;
- for (i = _oldRow - 1; i >= _currentRow; i--)
- {
- if ([tv _unselectRow: i])
- {
- notified = YES;
- }
- }
-
- if (*_selectedRow == -1)
- {
- NSUInteger first = [_selectedRows firstIndex];
-
- if (first == NSNotFound)
- {
- *_selectedRow = -1;
- }
- else
- {
- *_selectedRow = first;
- }
- }
-
- if (notified == YES)
- {
- [tv _postSelectionIsChangingNotification];
- }
- }
- else
- // we're reducing the selection
- {
- BOOL notified = NO;
-
- for (i = _oldRow; i < _currentRow; i++)
- {
- if ([_oldSelectedRows containsIndex: i])
- {
- // this row was in the old selection
- // select it
- [tv setNeedsDisplayInRect:
- [tv rectOfRow: i]];
- [_selectedRows addIndex: i];
- *_selectedRow = i;
- notified = YES;
- }
- }
-
- if (notified == YES)
- {
- [tv _postSelectionIsChangingNotification];
- }
- }
- }
- else if (oldDiff <= 0 && newDiff >= 0)
- {
- BOOL notified = NO;
-
- // we're reducing the selection
- {
- for (i = _oldRow; i < _originalRow; i++)
- {
- if ([_oldSelectedRows containsIndex: i])
- {
- // this row was in the old selection
- // select it
- [tv setNeedsDisplayInRect:
- [tv rectOfRow: i]];
- [_selectedRows addIndex: i];
- *_selectedRow = i;
- notified = YES;
- }
- }
- }
- // then we're extending it
- {
- for (i = _originalRow + 1; i <= _currentRow; i++)
- {
- if ([tv _unselectRow: i])
- {
- notified = YES;
- }
- }
- }
-
- if (*_selectedRow == -1)
- {
- NSUInteger first = [_selectedRows firstIndex];
-
- if (first == NSNotFound)
- {
- *_selectedRow = -1;
- }
- else
- {
- *_selectedRow = first;
- }
- }
-
- if (notified == YES)
- {
- [tv _postSelectionIsChangingNotification];
- }
- }
- else if (oldDiff >= 0 && newDiff <= 0)
- {
- BOOL notified = NO;
-
- // we're reducing the selection
- {
- for (i = _oldRow; i > _originalRow; i--)
- {
- if ([_oldSelectedRows containsIndex: i])
- {
- // this row was in the old selection
- // select it
- [tv setNeedsDisplayInRect:
- [tv rectOfRow: i]];
- [_selectedRows addIndex: i];
- *_selectedRow = i;
- notified = YES;
- }
- }
- }
- // then we're extending it
- {
- for (i = _originalRow - 1; i >= _currentRow; i--)
- {
- if ([tv _unselectRow: i])
- {
- notified = YES;
- }
- }
- }
-
- if (*_selectedRow == -1)
- {
- NSUInteger first = [_selectedRows firstIndex];
-
- if (first == NSNotFound)
- {
- *_selectedRow = -1;
- }
- else
- {
- *_selectedRow = first;
- }
- }
-
- if (notified == YES)
- {
- [tv _postSelectionIsChangingNotification];
- }
- }
- }
+ if (_oldRow == -1)
+ // this is the first pass
+ {
+ int diff, i;
+ BOOL notified = NO;
+
+ diff = _currentRow - _originalRow;
+
+ if (diff >= 0)
+ {
+ for (i = _originalRow; i <= _currentRow; i++)
+ {
+ if ([tv _unselectRow: i])
+ {
+ notified = YES;
+ }
+ }
+ if (*_selectedRow == -1)
+ {
+ NSUInteger first = [_selectedRows firstIndex];
+
+ if (first == NSNotFound)
+ {
+ *_selectedRow = -1;
+ }
+ else
+ {
+ *_selectedRow = first;
+ }
+ }
+ }
+ else
+ {
+ // this case does happen (sometimes)
+ for (i = _originalRow; i >= _currentRow; i--)
+ {
+ if ([tv _unselectRow: i])
+ {
+ notified = YES;
+ }
+ }
+ if (*_selectedRow == -1)
+ {
+ NSUInteger first = [_selectedRows firstIndex];
+
+ if (first == NSNotFound)
+ {
+ *_selectedRow = -1;
+ }
+ else
+ {
+ *_selectedRow = first;
+ }
+ }
+ }
+ if (notified == YES)
+ {
+ [tv _postSelectionIsChangingNotification];
+ }
+ }
+ else // new multiple antiselection, after first pass
+ {
+ int oldDiff, newDiff, i;
+
+ oldDiff = _oldRow - _originalRow;
+ newDiff = _currentRow - _originalRow;
+ if (oldDiff >= 0 && newDiff >= 0)
+ {
+ if (newDiff >= oldDiff)
+ // we're extending the antiselection
+ {
+ BOOL notified = NO;
+ for (i = _oldRow + 1; i <= _currentRow; i++)
+ {
+ if ([tv _unselectRow: i])
+ {
+ notified = YES;
+ }
+ }
+
+ if (*_selectedRow == -1)
+ {
+ NSUInteger first = [_selectedRows firstIndex];
+
+ if (first == NSNotFound)
+ {
+ *_selectedRow = -1;
+ }
+ else
+ {
+ *_selectedRow = first;
+ }
+ }
+
+ if (notified == YES)
+ {
+ [tv _postSelectionIsChangingNotification];
+ }
+ }
+ else
+ // we're reducing the selection
+ {
+ BOOL notified = NO;
+
+ for (i = _oldRow; i > _currentRow; i--)
+ {
+ if ([_oldSelectedRows containsIndex: i])
+ {
+ // this row was in the old selection
+ // select it
+ [tv setNeedsDisplayInRect: [tv rectOfRow: i]];
+ [_selectedRows addIndex: i];
+ *_selectedRow = i;
+ notified = YES;
+ }
+ }
+ if (notified == YES)
+ {
+ [tv _postSelectionIsChangingNotification];
+ }
+ }
+ }
+ else if (oldDiff <= 0 && newDiff <= 0)
+ {
+ if (newDiff <= oldDiff)
+ // we're extending the selection
+ {
+ BOOL notified = NO;
+ for (i = _oldRow - 1; i >= _currentRow; i--)
+ {
+ if ([tv _unselectRow: i])
+ {
+ notified = YES;
+ }
+ }
+
+ if (*_selectedRow == -1)
+ {
+ NSUInteger first = [_selectedRows firstIndex];
+
+ if (first == NSNotFound)
+ {
+ *_selectedRow = -1;
+ }
+ else
+ {
+ *_selectedRow = first;
+ }
+ }
+
+ if (notified == YES)
+ {
+ [tv _postSelectionIsChangingNotification];
+ }
+ }
+ else
+ // we're reducing the selection
+ {
+ BOOL notified = NO;
+
+ for (i = _oldRow; i < _currentRow; i++)
+ {
+ if ([_oldSelectedRows containsIndex: i])
+ {
+ // this row was in the old selection
+ // select it
+ [tv setNeedsDisplayInRect:
+ [tv rectOfRow: i]];
+ [_selectedRows addIndex: i];
+ *_selectedRow = i;
+ notified = YES;
+ }
+ }
+
+ if (notified == YES)
+ {
+ [tv _postSelectionIsChangingNotification];
+ }
+ }
+ }
+ else if (oldDiff <= 0 && newDiff >= 0)
+ {
+ BOOL notified = NO;
+
+ // we're reducing the selection
+ {
+ for (i = _oldRow; i < _originalRow; i++)
+ {
+ if ([_oldSelectedRows containsIndex: i])
+ {
+ // this row was in the old selection
+ // select it
+ [tv setNeedsDisplayInRect:
+ [tv rectOfRow: i]];
+ [_selectedRows addIndex: i];
+ *_selectedRow = i;
+ notified = YES;
+ }
+ }
+ }
+ // then we're extending it
+ {
+ for (i = _originalRow + 1; i <= _currentRow; i++)
+ {
+ if ([tv _unselectRow: i])
+ {
+ notified = YES;
+ }
+ }
+ }
+
+ if (*_selectedRow == -1)
+ {
+ NSUInteger first = [_selectedRows firstIndex];
+
+ if (first == NSNotFound)
+ {
+ *_selectedRow = -1;
+ }
+ else
+ {
+ *_selectedRow = first;
+ }
+ }
+
+ if (notified == YES)
+ {
+ [tv _postSelectionIsChangingNotification];
+ }
+ }
+ else if (oldDiff >= 0 && newDiff <= 0)
+ {
+ BOOL notified = NO;
+
+ // we're reducing the selection
+ {
+ for (i = _oldRow; i > _originalRow; i--)
+ {
+ if ([_oldSelectedRows containsIndex: i])
+ {
+ // this row was in the old selection
+ // select it
+ [tv setNeedsDisplayInRect:
+ [tv rectOfRow: i]];
+ [_selectedRows addIndex: i];
+ *_selectedRow = i;
+ notified = YES;
+ }
+ }
+ }
+ // then we're extending it
+ {
+ for (i = _originalRow - 1; i >= _currentRow; i--)
+ {
+ if ([tv _unselectRow: i])
+ {
+ notified = YES;
+ }
+ }
+ }
+
+ if (*_selectedRow == -1)
+ {
+ NSUInteger first = [_selectedRows firstIndex];
+
+ if (first == NSNotFound)
+ {
+ *_selectedRow = -1;
+ }
+ else
+ {
+ *_selectedRow = first;
+ }
+ }
+
+ if (notified == YES)
+ {
+ [tv _postSelectionIsChangingNotification];
+ }
+ }
+ }
}
- else if ((selectionMode & ALLOWS_MULTIPLE)
- && (selectionMode & SHIFT_DOWN)
- && ((selectionMode & ALLOWS_EMPTY) == 0)
- && ((selectionMode & ADDING_ROW) == 0))
+ else if ((selectionMode & ALLOWS_MULTIPLE)
+ && (selectionMode & SHIFT_DOWN)
+ && ((selectionMode & ALLOWS_EMPTY) == 0)
+ && ((selectionMode & ADDING_ROW) == 0))
{
- if (_oldRow == -1)
- // this is the first pass
- {
- int diff, i;
- int count = [_selectedRows count];
- BOOL notified = NO;
- diff = _currentRow - _originalRow;
-
- if (diff >= 0)
- {
- for (i = _originalRow; i <= _currentRow; i++)
- {
- if ((count > 1) && [tv _unselectRow: i])
- {
- notified = YES;
- count--;
- }
- }
- if (*_selectedRow == -1)
- {
- NSUInteger first = [_selectedRows firstIndex];
-
- if (first == NSNotFound)
- {
- NSLog(@"error!");
- *_selectedRow = -1;
- }
- else
- {
- *_selectedRow = first;
- }
- }
- }
- else
- {
- // this case does happen (sometimes)
- for (i = _originalRow; i >= _currentRow; i--)
- {
- if ((count > 1) && [tv _unselectRow: i])
- {
- notified = YES;
- count--;
- }
- }
- if (*_selectedRow == -1)
- {
- NSUInteger first = [_selectedRows firstIndex];
-
- if (first == NSNotFound)
- {
- NSLog(@"error!");
- *_selectedRow = -1;
- }
- else
- {
- *_selectedRow = first;
- }
- }
- }
- if (notified == YES)
- {
- [tv _postSelectionIsChangingNotification];
- }
- }
- else // new multiple antiselection, after first pass
- {
- int oldDiff, newDiff, i;
- int count = [_selectedRows count];
- oldDiff = _oldRow - _originalRow;
- newDiff = _currentRow - _originalRow;
- if (oldDiff >= 0 && newDiff >= 0)
- {
- if (newDiff >= oldDiff)
- // we're extending the antiselection
- {
- BOOL notified = NO;
- for (i = _oldRow + 1; i <= _currentRow; i++)
- {
- if ((count > 1) && [tv _unselectRow: i])
- {
- notified = YES;
- count--;
- }
- }
-
- if (*_selectedRow == -1)
- {
- NSUInteger first = [_selectedRows firstIndex];
-
- if (first == NSNotFound)
- {
- NSLog(@"error!");
- *_selectedRow = -1;
- }
- else
- {
- *_selectedRow = first;
- }
- }
-
- if (notified == YES)
- {
- [tv _postSelectionIsChangingNotification];
- }
- }
- else
- // we're reducing the selection
- {
- BOOL notified = NO;
-
- for (i = _oldRow; i > _currentRow; i--)
- {
- if (([_oldSelectedRows containsIndex: i]))
- {
- // this row was in the old selection
- // select it
- if ([tv _selectUnselectedRow: i])
- {
- notified = YES;
- }
- }
- }
- if (notified == YES)
- {
- [tv _postSelectionIsChangingNotification];
- }
- }
- }
- else if (oldDiff <= 0 && newDiff <= 0)
- {
- if (newDiff <= oldDiff)
- // we're extending the selection
- {
- BOOL notified = NO;
- for (i = _oldRow - 1; i >= _currentRow; i--)
- {
- if ((count > 1) && [tv _unselectRow: i])
- {
- notified = YES;
- count--;
- }
- }
-
- if (*_selectedRow == -1)
- {
- NSUInteger first = [_selectedRows firstIndex];
-
- if (first == NSNotFound)
- {
- NSLog(@"error!");
- *_selectedRow = -1;
- }
- else
- {
- *_selectedRow = first;
- }
- }
-
- if (notified == YES)
- {
- [tv _postSelectionIsChangingNotification];
- }
- }
- else
- // we're reducing the selection
- {
- BOOL notified = NO;
-
- for (i = _oldRow; i < _currentRow; i++)
- {
- if ([_oldSelectedRows containsIndex: i])
- {
- // this row was in the old selection
- // select it
- if ([tv _selectUnselectedRow: i])
- {
- notified = YES;
- }
- count++;
- }
- }
-
- if (notified == YES)
- {
- [tv _postSelectionIsChangingNotification];
- }
- }
- }
- else if (oldDiff <= 0 && newDiff >= 0)
- {
- BOOL notified = NO;
-
- // we're reducing the selection
- {
- for (i = _oldRow; i < _originalRow; i++)
- {
- if ([_oldSelectedRows containsIndex: i])
- {
- // this row was in the old selection
- // select it
- if ([tv _selectUnselectedRow: i])
- {
- notified = YES;
- }
- }
- }
- }
- // then we're extending it
- {
- for (i = _originalRow + 1; i <= _currentRow; i++)
- {
- if ((count > 1) && [tv _unselectRow: i])
- {
- notified = YES;
- count--;
- }
- }
- }
-
- if (*_selectedRow == -1)
- {
- NSUInteger first = [_selectedRows firstIndex];
-
- if (first == NSNotFound)
- {
- NSLog(@"error!");
- *_selectedRow = -1;
- }
- else
- {
- *_selectedRow = first;
- }
- }
-
- if (notified == YES)
- {
- [tv _postSelectionIsChangingNotification];
- }
- }
- else if (oldDiff >= 0 && newDiff <= 0)
- {
- BOOL notified = NO;
-
- // we're reducing the selection
- {
- for (i = _oldRow; i > _originalRow; i--)
- {
- if ([_oldSelectedRows containsIndex: i])
- {
- // this row was in the old selection
- // select it
- if ([tv _selectUnselectedRow: i])
- {
- notified = YES;
- }
- }
- }
- }
- // then we're extending it
- {
- for (i = _originalRow - 1; i >= _currentRow; i--)
- {
- if ((count > 1) && [tv _unselectRow: i])
- {
- notified = YES;
- count--;
- }
- }
- }
-
- if (*_selectedRow == -1)
- {
- NSUInteger first = [_selectedRows firstIndex];
-
- if (first == NSNotFound)
- {
- NSLog(@"error!");
- *_selectedRow = -1;
- }
- else
- {
- *_selectedRow = first;
- }
- }
-
- if (notified == YES)
- {
- [tv _postSelectionIsChangingNotification];
- }
- }
- }
+ if (_oldRow == -1)
+ // this is the first pass
+ {
+ int diff, i;
+ int count = [_selectedRows count];
+ BOOL notified = NO;
+ diff = _currentRow - _originalRow;
+
+ if (diff >= 0)
+ {
+ for (i = _originalRow; i <= _currentRow; i++)
+ {
+ if ((count > 1) && [tv _unselectRow: i])
+ {
+ notified = YES;
+ count--;
+ }
+ }
+ if (*_selectedRow == -1)
+ {
+ NSUInteger first = [_selectedRows firstIndex];
+
+ if (first == NSNotFound)
+ {
+ NSLog(@"error!");
+ *_selectedRow = -1;
+ }
+ else
+ {
+ *_selectedRow = first;
+ }
+ }
+ }
+ else
+ {
+ // this case does happen (sometimes)
+ for (i = _originalRow; i >= _currentRow; i--)
+ {
+ if ((count > 1) && [tv _unselectRow: i])
+ {
+ notified = YES;
+ count--;
+ }
+ }
+ if (*_selectedRow == -1)
+ {
+ NSUInteger first = [_selectedRows firstIndex];
+
+ if (first == NSNotFound)
+ {
+ NSLog(@"error!");
+ *_selectedRow = -1;
+ }
+ else
+ {
+ *_selectedRow = first;
+ }
+ }
+ }
+ if (notified == YES)
+ {
+ [tv _postSelectionIsChangingNotification];
+ }
+ }
+ else // new multiple antiselection, after first pass
+ {
+ int oldDiff, newDiff, i;
+ int count = [_selectedRows count];
+ oldDiff = _oldRow - _originalRow;
+ newDiff = _currentRow - _originalRow;
+ if (oldDiff >= 0 && newDiff >= 0)
+ {
+ if (newDiff >= oldDiff)
+ // we're extending the antiselection
+ {
+ BOOL notified = NO;
+ for (i = _oldRow + 1; i <= _currentRow; i++)
+ {
+ if ((count > 1) && [tv _unselectRow: i])
+ {
+ notified = YES;
+ count--;
+ }
+ }
+
+ if (*_selectedRow == -1)
+ {
+ NSUInteger first = [_selectedRows firstIndex];
+
+ if (first == NSNotFound)
+ {
+ NSLog(@"error!");
+ *_selectedRow = -1;
+ }
+ else
+ {
+ *_selectedRow = first;
+ }
+ }
+
+ if (notified == YES)
+ {
+ [tv _postSelectionIsChangingNotification];
+ }
+ }
+ else
+ // we're reducing the selection
+ {
+ BOOL notified = NO;
+
+ for (i = _oldRow; i > _currentRow; i--)
+ {
+ if (([_oldSelectedRows containsIndex: i]))
+ {
+ // this row was in the old selection
+ // select it
+ if ([tv _selectUnselectedRow: i])
+ {
+ notified = YES;
+ }
+ }
+ }
+ if (notified == YES)
+ {
+ [tv _postSelectionIsChangingNotification];
+ }
+ }
+ }
+ else if (oldDiff <= 0 && newDiff <= 0)
+ {
+ if (newDiff <= oldDiff)
+ // we're extending the selection
+ {
+ BOOL notified = NO;
+ for (i = _oldRow - 1; i >= _currentRow; i--)
+ {
+ if ((count > 1) && [tv _unselectRow: i])
+ {
+ notified = YES;
+ count--;
+ }
+ }
+
+ if (*_selectedRow == -1)
+ {
+ NSUInteger first = [_selectedRows firstIndex];
+
+ if (first == NSNotFound)
+ {
+ NSLog(@"error!");
+ *_selectedRow = -1;
+ }
+ else
+ {
+ *_selectedRow = first;
+ }
+ }
+
+ if (notified == YES)
+ {
+ [tv _postSelectionIsChangingNotification];
+ }
+ }
+ else
+ // we're reducing the selection
+ {
+ BOOL notified = NO;
+
+ for (i = _oldRow; i < _currentRow; i++)
+ {
+ if ([_oldSelectedRows containsIndex: i])
+ {
+ // this row was in the old selection
+ // select it
+ if ([tv _selectUnselectedRow: i])
+ {
+ notified = YES;
+ }
+ count++;
+ }
+ }
+
+ if (notified == YES)
+ {
+ [tv _postSelectionIsChangingNotification];
+ }
+ }
+ }
+ else if (oldDiff <= 0 && newDiff >= 0)
+ {
+ BOOL notified = NO;
+
+ // we're reducing the selection
+ {
+ for (i = _oldRow; i < _originalRow; i++)
+ {
+ if ([_oldSelectedRows containsIndex: i])
+ {
+ // this row was in the old selection
+ // select it
+ if ([tv _selectUnselectedRow: i])
+ {
+ notified = YES;
+ }
+ }
+ }
+ }
+ // then we're extending it
+ {
+ for (i = _originalRow + 1; i <= _currentRow; i++)
+ {
+ if ((count > 1) && [tv _unselectRow: i])
+ {
+ notified = YES;
+ count--;
+ }
+ }
+ }
+
+ if (*_selectedRow == -1)
+ {
+ NSUInteger first = [_selectedRows firstIndex];
+
+ if (first == NSNotFound)
+ {
+ NSLog(@"error!");
+ *_selectedRow = -1;
+ }
+ else
+ {
+ *_selectedRow = first;
+ }
+ }
+
+ if (notified == YES)
+ {
+ [tv _postSelectionIsChangingNotification];
+ }
+ }
+ else if (oldDiff >= 0 && newDiff <= 0)
+ {
+ BOOL notified = NO;
+
+ // we're reducing the selection
+ {
+ for (i = _oldRow; i > _originalRow; i--)
+ {
+ if ([_oldSelectedRows containsIndex: i])
+ {
+ // this row was in the old selection
+ // select it
+ if ([tv _selectUnselectedRow: i])
+ {
+ notified = YES;
+ }
+ }
+ }
+ }
+ // then we're extending it
+ {
+ for (i = _originalRow - 1; i >= _currentRow; i--)
+ {
+ if ((count > 1) && [tv _unselectRow: i])
+ {
+ notified = YES;
+ count--;
+ }
+ }
+ }
+
+ if (*_selectedRow == -1)
+ {
+ NSUInteger first = [_selectedRows firstIndex];
+
+ if (first == NSNotFound)
+ {
+ NSLog(@"error!");
+ *_selectedRow = -1;
+ }
+ else
+ {
+ *_selectedRow = first;
+ }
+ }
+
+ if (notified == YES)
+ {
+ [tv _postSelectionIsChangingNotification];
+ }
+ }
+ }
}
}
@@ -1965,12 +1963,12 @@ static void computeNewSelection
- (BOOL) isFlipped
{
- return YES;
+ return YES;
}
- (void) drawRect: (NSRect)aRect
{
- [[GSTheme theme] drawTableCornerView: self withClip: aRect];
+ [[GSTheme theme] drawTableCornerView: self withClip: aRect];
}
@end
@@ -1978,421 +1976,419 @@ static void computeNewSelection
@interface NSTableView (TableViewInternalPrivate)
- (void) _setSelectingColumns: (BOOL)flag;
- (BOOL) _editNextEditableCellAfterRow: (int)row
- column: (int)column;
+ column: (int)column;
- (BOOL) _editPreviousEditableCellBeforeRow: (int)row
- column: (int)column;
+ column: (int)column;
- (void) _editNextCellAfterRow:(int)row inColumn:(int)column;
- (void) _autosaveTableColumns;
- (void) _autoloadTableColumns;
- (NSCell *) _dataCellForTableColumn: (NSTableColumn *)tb
row: (int) rowIndex;
-- (NSString *) _objectStringForTableColum:(NSTableColumn *)column item:(int)row;
-
@end
-@implementation NSTableView
+@implementation NSTableView
+ (void) initialize
{
- if (self == [NSTableView class])
+ if (self == [NSTableView class])
{
- [self setVersion: currentVersion];
- nc = [NSNotificationCenter defaultCenter];
- // FIXME
- [self exposeBinding: NSContentBinding];
- [self exposeBinding: NSSelectionIndexesBinding];
+ [self setVersion: currentVersion];
+ nc = [NSNotificationCenter defaultCenter];
+ // FIXME
+ [self exposeBinding: NSContentBinding];
+ [self exposeBinding: NSSelectionIndexesBinding];
}
}
/*
- * Initializing/Releasing
+ * Initializing/Releasing
*/
- (void) _initDefaults
{
- _isValidating = NO;
- _drawsGrid = YES;
- _rowHeight = 16.0;
- _intercellSpacing = NSMakeSize (5.0, 2.0);
- ASSIGN(_selectedColumns, [NSMutableIndexSet indexSet]);
- ASSIGN(_selectedRows, [NSMutableIndexSet indexSet]);
- _allowsEmptySelection = YES;
- _allowsMultipleSelection = NO;
- _allowsColumnSelection = YES;
- _allowsColumnResizing = YES;
- _allowsColumnReordering = YES;
- _autoresizesAllColumnsToFit = NO;
- _selectingColumns = NO;
- _verticalMotionDrag = NO;
- _editedColumn = -1;
- _editedRow = -1;
- _clickedRow = -1;
- _clickedColumn = -1;
- _selectedColumn = -1;
- _selectedRow = -1;
- _highlightedTableColumn = nil;
- _draggingSourceOperationMaskForLocal = NSDragOperationCopy
- | NSDragOperationLink | NSDragOperationGeneric | NSDragOperationPrivate;
- _draggingSourceOperationMaskForRemote = NSDragOperationNone;
- ASSIGN(_sortDescriptors, [NSArray array]);
+ _isValidating = NO;
+ _drawsGrid = YES;
+ _rowHeight = 16.0;
+ _intercellSpacing = NSMakeSize (5.0, 2.0);
+ ASSIGN(_selectedColumns, [NSMutableIndexSet indexSet]);
+ ASSIGN(_selectedRows, [NSMutableIndexSet indexSet]);
+ _allowsEmptySelection = YES;
+ _allowsMultipleSelection = NO;
+ _allowsColumnSelection = YES;
+ _allowsColumnResizing = YES;
+ _allowsColumnReordering = YES;
+ _autoresizesAllColumnsToFit = NO;
+ _selectingColumns = NO;
+ _verticalMotionDrag = NO;
+ _editedColumn = -1;
+ _editedRow = -1;
+ _clickedRow = -1;
+ _clickedColumn = -1;
+ _selectedColumn = -1;
+ _selectedRow = -1;
+ _highlightedTableColumn = nil;
+ _draggingSourceOperationMaskForLocal = NSDragOperationCopy
+ | NSDragOperationLink | NSDragOperationGeneric | NSDragOperationPrivate;
+ _draggingSourceOperationMaskForRemote = NSDragOperationNone;
+ ASSIGN(_sortDescriptors, [NSArray array]);
}
- (id) initWithFrame: (NSRect)frameRect
{
- self = [super initWithFrame: frameRect];
- if (!self)
- return self;
-
- [self _initDefaults];
- ASSIGN(_gridColor, [NSColor gridColor]);
- ASSIGN(_backgroundColor, [NSColor controlBackgroundColor]);
- ASSIGN(_tableColumns, [NSMutableArray array]);
-
- _headerView = [NSTableHeaderView new];
- [_headerView setFrameSize: NSMakeSize (frameRect.size.width, 22.0)];
- [_headerView setTableView: self];
- _cornerView = [GSTableCornerView new];
- [self tile];
+ self = [super initWithFrame: frameRect];
+ if (!self)
return self;
+
+ [self _initDefaults];
+ ASSIGN(_gridColor, [NSColor gridColor]);
+ ASSIGN(_backgroundColor, [NSColor controlBackgroundColor]);
+ ASSIGN(_tableColumns, [NSMutableArray array]);
+
+ _headerView = [NSTableHeaderView new];
+ [_headerView setFrameSize: NSMakeSize (frameRect.size.width, 22.0)];
+ [_headerView setTableView: self];
+ _cornerView = [GSTableCornerView new];
+ [self tile];
+ return self;
}
- (void) dealloc
{
- [self abortEditing];
-
- RELEASE (_gridColor);
- RELEASE (_backgroundColor);
- RELEASE (_tableColumns);
- RELEASE (_selectedColumns);
- RELEASE (_selectedRows);
- RELEASE (_sortDescriptors);
- TEST_RELEASE (_headerView);
- TEST_RELEASE (_cornerView);
- if (_autosaveTableColumns == YES)
+ [self abortEditing];
+
+ RELEASE (_gridColor);
+ RELEASE (_backgroundColor);
+ RELEASE (_tableColumns);
+ RELEASE (_selectedColumns);
+ RELEASE (_selectedRows);
+ RELEASE (_sortDescriptors);
+ TEST_RELEASE (_headerView);
+ TEST_RELEASE (_cornerView);
+ if (_autosaveTableColumns == YES)
{
- [nc removeObserver: self
- name: NSTableViewColumnDidResizeNotification
- object: self];
+ [nc removeObserver: self
+ name: NSTableViewColumnDidResizeNotification
+ object: self];
}
- TEST_RELEASE (_autosaveName);
- if (_numberOfColumns > 0)
+ TEST_RELEASE (_autosaveName);
+ if (_numberOfColumns > 0)
{
- NSZoneFree (NSDefaultMallocZone (), _columnOrigins);
+ NSZoneFree (NSDefaultMallocZone (), _columnOrigins);
}
- if (_delegate != nil)
+ if (_delegate != nil)
{
- [nc removeObserver: _delegate name: nil object: self];
- _delegate = nil;
+ [nc removeObserver: _delegate name: nil object: self];
+ _delegate = nil;
}
- [super dealloc];
+ [super dealloc];
}
- (BOOL) isFlipped
{
- return YES;
+ return YES;
}
/*
- * Table Dimensions
+ * Table Dimensions
*/
- (int) numberOfColumns
{
- return _numberOfColumns;
+ return _numberOfColumns;
}
- (int) numberOfRows
{
- return _numberOfRows;
+ return _numberOfRows;
}
-/*
- * Columns
+/*
+ * Columns
*/
- (void) addTableColumn: (NSTableColumn *)aColumn
{
- [aColumn setTableView: self];
- [_tableColumns addObject: aColumn];
- _numberOfColumns++;
- if (_numberOfColumns > 1)
+ [aColumn setTableView: self];
+ [_tableColumns addObject: aColumn];
+ _numberOfColumns++;
+ if (_numberOfColumns > 1)
{
- _columnOrigins = NSZoneRealloc (NSDefaultMallocZone (), _columnOrigins,
- (sizeof (float)) * _numberOfColumns);
+ _columnOrigins = NSZoneRealloc (NSDefaultMallocZone (), _columnOrigins,
+ (sizeof (float)) * _numberOfColumns);
}
- else
+ else
{
- _columnOrigins = NSZoneMalloc (NSDefaultMallocZone (), sizeof (float));
- }
- [self tile];
+ _columnOrigins = NSZoneMalloc (NSDefaultMallocZone (), sizeof (float));
+ }
+ [self tile];
}
- (void) removeTableColumn: (NSTableColumn *)aColumn
{
- int columnIndex = [self columnWithIdentifier: [aColumn identifier]];
-
- if (columnIndex == -1)
+ int columnIndex = [self columnWithIdentifier: [aColumn identifier]];
+
+ if (columnIndex == -1)
{
- NSLog (@"Warning: Tried to remove not-existent column from table");
- return;
+ NSLog (@"Warning: Tried to remove not-existent column from table");
+ return;
}
-
- /* Remove selection on this column */
- [self deselectColumn: columnIndex];
- /* Shift column indexes on the right by one */
- if (_selectedColumn > columnIndex)
+
+ /* Remove selection on this column */
+ [self deselectColumn: columnIndex];
+ /* Shift column indexes on the right by one */
+ if (_selectedColumn > columnIndex)
{
- _selectedColumn--;
+ _selectedColumn--;
}
-
- [_selectedColumns removeIndex: columnIndex];
-
- /* Now really remove the column */
-
- /* NB: Set table view to nil before removing the column from the
+
+ [_selectedColumns removeIndex: columnIndex];
+
+ /* Now really remove the column */
+
+ /* NB: Set table view to nil before removing the column from the
array, because removing it from the array could deallocate it ! */
- [aColumn setTableView: nil];
- [_tableColumns removeObject: aColumn];
- _numberOfColumns--;
- if (_numberOfColumns > 0)
+ [aColumn setTableView: nil];
+ [_tableColumns removeObject: aColumn];
+ _numberOfColumns--;
+ if (_numberOfColumns > 0)
{
- _columnOrigins = NSZoneRealloc (NSDefaultMallocZone (), _columnOrigins,
- (sizeof (float)) * _numberOfColumns);
+ _columnOrigins = NSZoneRealloc (NSDefaultMallocZone (), _columnOrigins,
+ (sizeof (float)) * _numberOfColumns);
}
- else
+ else
{
- NSZoneFree (NSDefaultMallocZone (), _columnOrigins);
- }
- [self tile];
+ NSZoneFree (NSDefaultMallocZone (), _columnOrigins);
+ }
+ [self tile];
}
- (void) moveColumn: (int)columnIndex toColumn: (int)newIndex
{
- /* The range of columns which need to be shifted,
+ /* The range of columns which need to be shifted,
extremes included */
- int minRange, maxRange;
- /* Amount of shift for these columns */
- int shift;
- BOOL selected = NO;
-
- if ((columnIndex < 0) || (columnIndex > (_numberOfColumns - 1)))
+ int minRange, maxRange;
+ /* Amount of shift for these columns */
+ int shift;
+ BOOL selected = NO;
+
+ if ((columnIndex < 0) || (columnIndex > (_numberOfColumns - 1)))
{
- NSLog (@"Attempt to move column outside table");
- return;
+ NSLog (@"Attempt to move column outside table");
+ return;
}
- if ((newIndex < 0) || (newIndex > (_numberOfColumns - 1)))
+ if ((newIndex < 0) || (newIndex > (_numberOfColumns - 1)))
{
- NSLog (@"Attempt to move column to outside table");
- return;
+ NSLog (@"Attempt to move column to outside table");
+ return;
}
-
- if (columnIndex == newIndex)
- return;
-
- if (columnIndex > newIndex)
+
+ if (columnIndex == newIndex)
+ return;
+
+ if (columnIndex > newIndex)
{
- minRange = newIndex;
- maxRange = columnIndex - 1;
- shift = +1;
+ minRange = newIndex;
+ maxRange = columnIndex - 1;
+ shift = +1;
}
- else // columnIndex < newIndex
+ else // columnIndex < newIndex
{
- minRange = columnIndex + 1;
- maxRange = newIndex;
- shift = -1;
+ minRange = columnIndex + 1;
+ maxRange = newIndex;
+ shift = -1;
}
-
- /* Rearrange selection */
- if (_selectedColumn == columnIndex)
+
+ /* Rearrange selection */
+ if (_selectedColumn == columnIndex)
{
- _selectedColumn = newIndex;
+ _selectedColumn = newIndex;
}
- else if ((_selectedColumn >= minRange) && (_selectedColumn <= maxRange))
+ else if ((_selectedColumn >= minRange) && (_selectedColumn <= maxRange))
{
- _selectedColumn += shift;
+ _selectedColumn += shift;
}
-
- if ([_selectedColumns containsIndex: columnIndex])
+
+ if ([_selectedColumns containsIndex: columnIndex])
{
- selected = YES;
+ selected = YES;
}
- [_selectedColumns shiftIndexesStartingAtIndex: columnIndex + 1 by: -1];
- [_selectedColumns shiftIndexesStartingAtIndex: newIndex by: 1];
- if (selected)
+ [_selectedColumns shiftIndexesStartingAtIndex: columnIndex + 1 by: -1];
+ [_selectedColumns shiftIndexesStartingAtIndex: newIndex by: 1];
+ if (selected)
{
- [_selectedColumns addIndex: newIndex];
+ [_selectedColumns addIndex: newIndex];
}
-
- /* Update edited cell */
- if (_editedColumn == columnIndex)
+
+ /* Update edited cell */
+ if (_editedColumn == columnIndex)
{
- _editedColumn = newIndex;
+ _editedColumn = newIndex;
}
- else if ((_editedColumn >= minRange) && (_editedColumn <= maxRange))
+ else if ((_editedColumn >= minRange) && (_editedColumn <= maxRange))
{
- _editedColumn += shift;
+ _editedColumn += shift;
}
-
- /* Now really move the column */
- if (columnIndex < newIndex)
+
+ /* Now really move the column */
+ if (columnIndex < newIndex)
{
- [_tableColumns insertObject: [_tableColumns objectAtIndex: columnIndex]
- atIndex: newIndex + 1];
- [_tableColumns removeObjectAtIndex: columnIndex];
+ [_tableColumns insertObject: [_tableColumns objectAtIndex: columnIndex]
+ atIndex: newIndex + 1];
+ [_tableColumns removeObjectAtIndex: columnIndex];
}
- else
+ else
{
- [_tableColumns insertObject: [_tableColumns objectAtIndex: columnIndex]
- atIndex: newIndex];
- [_tableColumns removeObjectAtIndex: columnIndex + 1];
+ [_tableColumns insertObject: [_tableColumns objectAtIndex: columnIndex]
+ atIndex: newIndex];
+ [_tableColumns removeObjectAtIndex: columnIndex + 1];
}
- /* Tile */
- [self tile];
-
- /* Post notification */
-
- [self _postColumnDidMoveNotificationWithOldIndex: columnIndex
- newIndex: newIndex];
-
- [self _autosaveTableColumns];
+ /* Tile */
+ [self tile];
+
+ /* Post notification */
+
+ [self _postColumnDidMoveNotificationWithOldIndex: columnIndex
+ newIndex: newIndex];
+
+ [self _autosaveTableColumns];
}
- (NSArray *) tableColumns
{
- return AUTORELEASE ([_tableColumns mutableCopyWithZone:
- NSDefaultMallocZone ()]);
+ return AUTORELEASE ([_tableColumns mutableCopyWithZone:
+ NSDefaultMallocZone ()]);
}
- (int) columnWithIdentifier: (id)identifier
{
- NSEnumerator *enumerator = [_tableColumns objectEnumerator];
- NSTableColumn *tb;
- int return_value = 0;
-
- while ((tb = [enumerator nextObject]) != nil)
+ NSEnumerator *enumerator = [_tableColumns objectEnumerator];
+ NSTableColumn *tb;
+ int return_value = 0;
+
+ while ((tb = [enumerator nextObject]) != nil)
{
- // Also handle a nil identifier.
- if ((identifier == [tb identifier]) ||
- [[tb identifier] isEqual: identifier])
- return return_value;
- else
- return_value++;
+ // Also handle a nil identifier.
+ if ((identifier == [tb identifier]) ||
+ [[tb identifier] isEqual: identifier])
+ return return_value;
+ else
+ return_value++;
}
- return -1;
+ return -1;
}
- (NSTableColumn *) tableColumnWithIdentifier:(id)anObject
{
- int indexOfColumn = [self columnWithIdentifier: anObject];
-
- if (indexOfColumn == -1)
- return nil;
- else
- return [_tableColumns objectAtIndex: indexOfColumn];
+ int indexOfColumn = [self columnWithIdentifier: anObject];
+
+ if (indexOfColumn == -1)
+ return nil;
+ else
+ return [_tableColumns objectAtIndex: indexOfColumn];
}
-/*
- * Data Source
+/*
+ * Data Source
*/
- (id) dataSource
{
- return _dataSource;
+ return _dataSource;
}
- (void) setDataSource: (id)anObject
{
- /* Used only for readability */
- const SEL sel_a = @selector (numberOfRowsInTableView:);
- const SEL sel_b = @selector (tableView:objectValueForTableColumn:row:);
- const SEL sel_c = @selector(tableView:setObjectValue:forTableColumn:row:);
- GSKeyValueBinding *theBinding;
-
- // If we have content binding the data source is used only
- // like a delegate
- theBinding = [GSKeyValueBinding getBinding: NSContentBinding
- forObject: self];
- if (theBinding == nil)
- {
- if (anObject && [anObject respondsToSelector: sel_a] == NO)
+ /* Used only for readability */
+ const SEL sel_a = @selector (numberOfRowsInTableView:);
+ const SEL sel_b = @selector (tableView:objectValueForTableColumn:row:);
+ const SEL sel_c = @selector(tableView:setObjectValue:forTableColumn:row:);
+ GSKeyValueBinding *theBinding;
+
+ // If we have content binding the data source is used only
+ // like a delegate
+ theBinding = [GSKeyValueBinding getBinding: NSContentBinding
+ forObject: self];
+ if (theBinding == nil)
+ {
+ if (anObject && [anObject respondsToSelector: sel_a] == NO)
{
- [NSException
- raise: NSInternalInconsistencyException
- format: @"Data Source doesn't respond to numberOfRowsInTableView:"];
+ [NSException
+ raise: NSInternalInconsistencyException
+ format: @"Data Source doesn't respond to numberOfRowsInTableView:"];
}
-
- if (anObject && [anObject respondsToSelector: sel_b] == NO)
+
+ if (anObject && [anObject respondsToSelector: sel_b] == NO)
{
- /* This method isn't required.
- [NSException raise: NSInternalInconsistencyException
+ /* This method isn't required.
+ [NSException raise: NSInternalInconsistencyException
format: @"Data Source doesn't respond to "
@"tableView:objectValueForTableColumn:row:"];
- */
+ */
}
}
-
- _dataSource_editable = [anObject respondsToSelector: sel_c];
-
- /* We do *not* retain the dataSource, it's like a delegate */
- _dataSource = anObject;
-
- [self tile];
- [self reloadData];
+
+ _dataSource_editable = [anObject respondsToSelector: sel_c];
+
+ /* We do *not* retain the dataSource, it's like a delegate */
+ _dataSource = anObject;
+
+ [self tile];
+ [self reloadData];
}
-/*
- * Loading data
+/*
+ * Loading data
*/
- (void) reloadData
{
- [self noteNumberOfRowsChanged];
- [self setNeedsDisplay: YES];
+ [self noteNumberOfRowsChanged];
+ [self setNeedsDisplay: YES];
}
-/*
- * Target-action
+/*
+ * Target-action
*/
- (void) setAction: (SEL)aSelector
{
- _action = aSelector;
+ _action = aSelector;
}
- (SEL) action
{
- return _action;
+ return _action;
}
- (void) setDoubleAction: (SEL)aSelector
{
- _doubleAction = aSelector;
+ _doubleAction = aSelector;
}
- (SEL) doubleAction
{
- return _doubleAction;
+ return _doubleAction;
}
- (void) setTarget:(id)anObject
{
- _target = anObject;
+ _target = anObject;
}
- (id) target
{
- return _target;
+ return _target;
}
- (int) clickedColumn
{
- return _clickedColumn;
+ return _clickedColumn;
}
- (int) clickedRow
{
- return _clickedRow;
+ return _clickedRow;
}
/*
@@ -2401,960 +2397,960 @@ static void computeNewSelection
- (void) _sendDoubleActionForColumn: (int)columnIndex
{
- _clickedColumn = columnIndex;
- _clickedRow = -1;
- [self sendAction: _doubleAction to: _target];
+ _clickedColumn = columnIndex;
+ _clickedRow = -1;
+ [self sendAction: _doubleAction to: _target];
}
/*
- * And this when it gets a simple click which turns out to be for
+ * And this when it gets a simple click which turns out to be for
* selecting/deselecting a column.
- * We don't support subtracting a column from the selection (Cocoa doesn't
+ * We don't support subtracting a column from the selection (Cocoa doesn't
* either).
- * However we support adding a distinct column with the control key (unlike
+ * However we support adding a distinct column with the control key (unlike
* Cocoa where the user can only make column range selection).
*/
- (void) _selectColumn: (int)columnIndex
- modifiers: (unsigned int)modifiers
+ modifiers: (unsigned int)modifiers
{
- NSIndexSet *oldIndexes = [self selectedColumnIndexes];
- BOOL addRange = ((modifiers & NSShiftKeyMask)
- && _allowsMultipleSelection && [oldIndexes count] > 0);
- BOOL addSingle = ((modifiers & NSControlKeyMask)
- && _allowsMultipleSelection);
- BOOL shouldSelect = ([self _shouldSelectionChange]
- && [self _shouldSelectTableColumn: [_tableColumns objectAtIndex: columnIndex]]);
- NSIndexSet *newIndexes = [NSIndexSet indexSetWithIndex: columnIndex];
-
- if (_allowsColumnSelection == NO || shouldSelect == NO)
+ NSIndexSet *oldIndexes = [self selectedColumnIndexes];
+ BOOL addRange = ((modifiers & NSShiftKeyMask)
+ && _allowsMultipleSelection && [oldIndexes count] > 0);
+ BOOL addSingle = ((modifiers & NSControlKeyMask)
+ && _allowsMultipleSelection);
+ BOOL shouldSelect = ([self _shouldSelectionChange]
+ && [self _shouldSelectTableColumn: [_tableColumns objectAtIndex: columnIndex]]);
+ NSIndexSet *newIndexes = [NSIndexSet indexSetWithIndex: columnIndex];
+
+ if (_allowsColumnSelection == NO || shouldSelect == NO)
{
- return;
+ return;
}
-
- if (_selectingColumns == NO)
+
+ if (_selectingColumns == NO)
{
- [self _setSelectingColumns: YES];
+ [self _setSelectingColumns: YES];
}
-
- /* Single select has priority over range select when both modifiers are pressed */
- if (addSingle)
- {
- [self selectColumnIndexes: newIndexes byExtendingSelection: YES];
+
+ /* Single select has priority over range select when both modifiers are pressed */
+ if (addSingle)
+ {
+ [self selectColumnIndexes: newIndexes byExtendingSelection: YES];
}
- else if (addRange)
+ else if (addRange)
{
- NSUInteger firstIndex = [oldIndexes firstIndex];
- NSUInteger lastIndex = [oldIndexes lastIndex];
- NSRange range;
-
- /* We extend the selection to the left or the right of the last selected
+ NSUInteger firstIndex = [oldIndexes firstIndex];
+ NSUInteger lastIndex = [oldIndexes lastIndex];
+ NSRange range;
+
+ /* We extend the selection to the left or the right of the last selected
column. */
- if (columnIndex > [self selectedColumn])
+ if (columnIndex > [self selectedColumn])
{
- lastIndex = columnIndex;
+ lastIndex = columnIndex;
}
- else
+ else
{
- firstIndex = columnIndex;
+ firstIndex = columnIndex;
}
-
- range = NSMakeRange(firstIndex, lastIndex - firstIndex + 1);
- newIndexes = [NSIndexSet indexSetWithIndexesInRange: range];
- [self selectColumnIndexes: newIndexes byExtendingSelection: YES];
+
+ range = NSMakeRange(firstIndex, lastIndex - firstIndex + 1);
+ newIndexes = [NSIndexSet indexSetWithIndexesInRange: range];
+ [self selectColumnIndexes: newIndexes byExtendingSelection: YES];
}
- else
+ else
{
- [self selectColumnIndexes: newIndexes byExtendingSelection: NO];
+ [self selectColumnIndexes: newIndexes byExtendingSelection: NO];
}
}
/*
- *Configuration
- */
+ *Configuration
+ */
- (void) setAllowsColumnReordering: (BOOL)flag
{
- _allowsColumnReordering = flag;
+ _allowsColumnReordering = flag;
}
- (BOOL) allowsColumnReordering
{
- return _allowsColumnReordering;
+ return _allowsColumnReordering;
}
- (void) setAllowsColumnResizing: (BOOL)flag
{
- _allowsColumnResizing = flag;
+ _allowsColumnResizing = flag;
}
- (BOOL) allowsColumnResizing
{
- return _allowsColumnResizing;
+ return _allowsColumnResizing;
}
- (void) setAllowsMultipleSelection: (BOOL)flag
{
- _allowsMultipleSelection = flag;
+ _allowsMultipleSelection = flag;
}
- (BOOL) allowsMultipleSelection
{
- return _allowsMultipleSelection;
+ return _allowsMultipleSelection;
}
- (void) setAllowsEmptySelection: (BOOL)flag
{
- _allowsEmptySelection = flag;
+ _allowsEmptySelection = flag;
}
- (BOOL) allowsEmptySelection
{
- return _allowsEmptySelection;
+ return _allowsEmptySelection;
}
- (void) setAllowsColumnSelection: (BOOL)flag
{
- _allowsColumnSelection = flag;
+ _allowsColumnSelection = flag;
}
- (BOOL) allowsColumnSelection
{
- return _allowsColumnSelection;
+ return _allowsColumnSelection;
}
-/*
- * Drawing Attributes
+/*
+ * Drawing Attributes
*/
- (void) setIntercellSpacing: (NSSize)aSize
{
- _intercellSpacing = aSize;
- [self setNeedsDisplay: YES];
+ _intercellSpacing = aSize;
+ [self setNeedsDisplay: YES];
}
- (NSSize) intercellSpacing
{
- return _intercellSpacing;
+ return _intercellSpacing;
}
- (void) setRowHeight: (float)rowHeight
{
- _rowHeight = rowHeight;
- [self tile];
+ _rowHeight = rowHeight;
+ [self tile];
}
- (float) rowHeight
{
- return _rowHeight;
+ return _rowHeight;
}
- (void) setBackgroundColor: (NSColor *)aColor
{
- ASSIGN (_backgroundColor, aColor);
+ ASSIGN (_backgroundColor, aColor);
}
- (NSColor *) backgroundColor
{
- return _backgroundColor;
+ return _backgroundColor;
}
- (void) setUsesAlternatingRowBackgroundColors: (BOOL)useAlternatingRowColors
{
- // FIXME
+ // FIXME
}
- (BOOL) usesAlternatingRowBackgroundColors
{
- // FIXME
- return NO;
+ // FIXME
+ return NO;
}
/*
* Selecting Columns and Rows
*/
-- (void) selectColumn: (int)columnIndex
+- (void) selectColumn: (int)columnIndex
byExtendingSelection: (BOOL)flag
{
- if (columnIndex < 0 || columnIndex > _numberOfColumns)
+ if (columnIndex < 0 || columnIndex > _numberOfColumns)
{
- NSDebugLLog(@"NSTableView", @"Column index %d out of table in selectColumn", columnIndex);
- return;
+ NSDebugLLog(@"NSTableView", @"Column index %d out of table in selectColumn", columnIndex);
+ return;
}
-
- _selectingColumns = YES;
-
- if (flag == NO)
+
+ _selectingColumns = YES;
+
+ if (flag == NO)
{
- /* If the current selection is the one we want, just ends editing
- * This is not just a speed up, it prevents us from sending
- * a NSTableViewSelectionDidChangeNotification.
- * This behaviour is required by the specifications */
- if ([_selectedColumns count] == 1
- && [_selectedColumns containsIndex: columnIndex] == YES)
- {
- /* Stop editing if any */
- if (_textObject != nil)
- {
- [self validateEditing];
- [self abortEditing];
- }
- return;
- }
-
- /* If _numberOfColumns == 1, we can skip trying to deselect the
- only column - because we have been called to select it. */
- if (_numberOfColumns > 1)
- {
- [self _unselectAllColumns];
- }
+ /* If the current selection is the one we want, just ends editing
+ * This is not just a speed up, it prevents us from sending
+ * a NSTableViewSelectionDidChangeNotification.
+ * This behaviour is required by the specifications */
+ if ([_selectedColumns count] == 1
+ && [_selectedColumns containsIndex: columnIndex] == YES)
+ {
+ /* Stop editing if any */
+ if (_textObject != nil)
+ {
+ [self validateEditing];
+ [self abortEditing];
+ }
+ return;
+ }
+
+ /* If _numberOfColumns == 1, we can skip trying to deselect the
+ only column - because we have been called to select it. */
+ if (_numberOfColumns > 1)
+ {
+ [self _unselectAllColumns];
+ }
}
- else // flag == YES
+ else // flag == YES
{
- if (_allowsMultipleSelection == NO)
- {
- [NSException raise: NSInternalInconsistencyException
- format: @"Can not extend selection in table view when multiple selection is disabled"];
- }
+ if (_allowsMultipleSelection == NO)
+ {
+ [NSException raise: NSInternalInconsistencyException
+ format: @"Can not extend selection in table view when multiple selection is disabled"];
+ }
}
-
- /* Stop editing if any */
- if (_textObject != nil)
+
+ /* Stop editing if any */
+ if (_textObject != nil)
{
- [self validateEditing];
- [self abortEditing];
+ [self validateEditing];
+ [self abortEditing];
}
-
- /* Now select the column and post notification only if needed */
- if ([_selectedColumns containsIndex: columnIndex] == NO)
+
+ /* Now select the column and post notification only if needed */
+ if ([_selectedColumns containsIndex: columnIndex] == NO)
{
- [_selectedColumns addIndex: columnIndex];
- _selectedColumn = columnIndex;
-
- [self setNeedsDisplayInRect: [self rectOfColumn: columnIndex]];
- if (_headerView)
- {
- [_headerView setNeedsDisplayInRect:
+ [_selectedColumns addIndex: columnIndex];
+ _selectedColumn = columnIndex;
+
+ [self setNeedsDisplayInRect: [self rectOfColumn: columnIndex]];
+ if (_headerView)
+ {
+ [_headerView setNeedsDisplayInRect:
[_headerView headerRectOfColumn: columnIndex]];
- }
- [self _postSelectionDidChangeNotification];
+ }
+ [self _postSelectionDidChangeNotification];
}
- else /* Otherwise simply change the last selected column */
+ else /* Otherwise simply change the last selected column */
{
- _selectedColumn = columnIndex;
+ _selectedColumn = columnIndex;
}
}
- (void) selectRow: (int)rowIndex
byExtendingSelection: (BOOL)flag
{
- if (rowIndex < 0 || rowIndex >= _numberOfRows)
+ if (rowIndex < 0 || rowIndex >= _numberOfRows)
{
- NSDebugLLog(@"NSTableView", @"Row index %d out of table in selectRow", rowIndex);
- return;
+ NSDebugLLog(@"NSTableView", @"Row index %d out of table in selectRow", rowIndex);
+ return;
}
-
- if (_selectingColumns)
+
+ if (_selectingColumns)
{
- _selectingColumns = NO;
- if (_headerView)
- {
- [_headerView setNeedsDisplay: YES];
- }
+ _selectingColumns = NO;
+ if (_headerView)
+ {
+ [_headerView setNeedsDisplay: YES];
+ }
}
-
- if (flag == NO)
+
+ if (flag == NO)
{
- /* If the current selection is the one we want, just ends editing
- * This is not just a speed up, it prevents us from sending
- * a NSTableViewSelectionDidChangeNotification.
- * This behaviour is required by the specifications */
- if ([_selectedRows count] == 1
- && [_selectedRows containsIndex: rowIndex] == YES)
- {
- /* Stop editing if any */
- if (_textObject != nil)
- {
- [self validateEditing];
- [self abortEditing];
- }
-
- /* reset the _clickedRow for keyboard navigation */
- _clickedRow = rowIndex;
- return;
- }
-
- /* If _numberOfRows == 1, we can skip trying to deselect the
- only row - because we have been called to select it. */
- if (_numberOfRows > 1)
- {
- [self _unselectAllRows];
- }
+ /* If the current selection is the one we want, just ends editing
+ * This is not just a speed up, it prevents us from sending
+ * a NSTableViewSelectionDidChangeNotification.
+ * This behaviour is required by the specifications */
+ if ([_selectedRows count] == 1
+ && [_selectedRows containsIndex: rowIndex] == YES)
+ {
+ /* Stop editing if any */
+ if (_textObject != nil)
+ {
+ [self validateEditing];
+ [self abortEditing];
+ }
+
+ /* reset the _clickedRow for keyboard navigation */
+ _clickedRow = rowIndex;
+ return;
+ }
+
+ /* If _numberOfRows == 1, we can skip trying to deselect the
+ only row - because we have been called to select it. */
+ if (_numberOfRows > 1)
+ {
+ [self _unselectAllRows];
+ }
}
- else // flag == YES
+ else // flag == YES
{
- if (_allowsMultipleSelection == NO)
- {
- [NSException raise: NSInternalInconsistencyException
- format: @"Can not extend selection in table view when multiple selection is disabled"];
- }
+ if (_allowsMultipleSelection == NO)
+ {
+ [NSException raise: NSInternalInconsistencyException
+ format: @"Can not extend selection in table view when multiple selection is disabled"];
+ }
}
-
- /* Stop editing if any */
- if (_textObject != nil)
+
+ /* Stop editing if any */
+ if (_textObject != nil)
{
- [self validateEditing];
- [self abortEditing];
+ [self validateEditing];
+ [self abortEditing];
+ }
+
+ /*
+ * Now select the row and post notification only if needed
+ * also update the _clickedRow for keyboard navigation.
+ */
+ if ([self _selectUnselectedRow: rowIndex])
+ {
+ _clickedRow = rowIndex;
+ [self _postSelectionDidChangeNotification];
}
-
- /*
- * Now select the row and post notification only if needed
- * also update the _clickedRow for keyboard navigation.
- */
- if ([self _selectUnselectedRow: rowIndex])
+ else /* Otherwise simply change the last selected row */
{
- _clickedRow = rowIndex;
- [self _postSelectionDidChangeNotification];
- }
- else /* Otherwise simply change the last selected row */
- {
- _selectedRow = rowIndex;
- _clickedRow = rowIndex;
+ _selectedRow = rowIndex;
+ _clickedRow = rowIndex;
}
}
- (void) selectColumnIndexes: (NSIndexSet *)indexes byExtendingSelection: (BOOL)extend
{
- BOOL empty = ([indexes firstIndex] == NSNotFound);
- BOOL changed = NO;
- NSUInteger col;
-
- if (!_selectingColumns)
+ BOOL empty = ([indexes firstIndex] == NSNotFound);
+ BOOL changed = NO;
+ NSUInteger col;
+
+ if (!_selectingColumns)
{
- _selectingColumns = YES;
- if (_headerView)
- {
- [_headerView setNeedsDisplay: YES];
- }
+ _selectingColumns = YES;
+ if (_headerView)
+ {
+ [_headerView setNeedsDisplay: YES];
+ }
}
-
- /* Stop editing if any */
- if (_textObject != nil)
+
+ /* Stop editing if any */
+ if (_textObject != nil)
{
- [self validateEditing];
- [self abortEditing];
+ [self validateEditing];
+ [self abortEditing];
}
-
- if (extend == NO)
+
+ if (extend == NO)
{
- /* If the current selection is the one we want, just ends editing
- * This is not just a speed up, it prevents us from sending
- * a NSTableViewSelectionDidChangeNotification.
- * This behaviour is required by the specifications */
- if ([_selectedColumns isEqual: indexes])
+ /* If the current selection is the one we want, just ends editing
+ * This is not just a speed up, it prevents us from sending
+ * a NSTableViewSelectionDidChangeNotification.
+ * This behaviour is required by the specifications */
+ if ([_selectedColumns isEqual: indexes])
{
- if (!empty)
- {
- _selectedColumn = [indexes lastIndex];
- }
- return;
- }
-
- [self _unselectAllColumns];
- changed = YES;
+ if (!empty)
+ {
+ _selectedColumn = [indexes lastIndex];
+ }
+ return;
+ }
+
+ [self _unselectAllColumns];
+ changed = YES;
}
-
- if (!empty)
+
+ if (!empty)
{
- if ([indexes lastIndex] >= _numberOfColumns)
+ if ([indexes lastIndex] >= _numberOfColumns)
{
- [NSException raise: NSInvalidArgumentException
- format: @"Column index out of table in selectColumn"];
- }
-
- /* This check is not fully correct, as both sets may contain just
- the same entry, but works according to the old specification. */
- if (_allowsMultipleSelection == NO &&
- [_selectedColumns count] + [indexes count] > 1)
+ [NSException raise: NSInvalidArgumentException
+ format: @"Column index out of table in selectColumn"];
+ }
+
+ /* This check is not fully correct, as both sets may contain just
+ the same entry, but works according to the old specification. */
+ if (_allowsMultipleSelection == NO &&
+ [_selectedColumns count] + [indexes count] > 1)
{
- [NSException raise: NSInternalInconsistencyException
- format: @"Can not set multiple selection in table view when multiple selection is disabled"];
- }
-
- col = [indexes firstIndex];
- while (col != NSNotFound)
+ [NSException raise: NSInternalInconsistencyException
+ format: @"Can not set multiple selection in table view when multiple selection is disabled"];
+ }
+
+ col = [indexes firstIndex];
+ while (col != NSNotFound)
{
- if (![_selectedColumns containsIndex: col])
- {
- [self setNeedsDisplayInRect: [self rectOfColumn: col]];
- if (_headerView)
- {
- [_headerView setNeedsDisplayInRect:
- [_headerView headerRectOfColumn: col]];
- }
- changed = YES;
- }
- col = [indexes indexGreaterThanIndex: col];
- }
- [_selectedColumns addIndexes: indexes];
- _selectedColumn = [indexes lastIndex];
+ if (![_selectedColumns containsIndex: col])
+ {
+ [self setNeedsDisplayInRect: [self rectOfColumn: col]];
+ if (_headerView)
+ {
+ [_headerView setNeedsDisplayInRect:
+ [_headerView headerRectOfColumn: col]];
+ }
+ changed = YES;
+ }
+ col = [indexes indexGreaterThanIndex: col];
+ }
+ [_selectedColumns addIndexes: indexes];
+ _selectedColumn = [indexes lastIndex];
}
-
- if (changed)
+
+ if (changed)
{
- [self _postSelectionDidChangeNotification];
+ [self _postSelectionDidChangeNotification];
}
}
- (void) selectRowIndexes: (NSIndexSet *)indexes byExtendingSelection: (BOOL)extend
{
- BOOL empty = ([indexes firstIndex] == NSNotFound);
- BOOL changed = NO;
- NSUInteger row;
-
- if (_selectingColumns)
+ BOOL empty = ([indexes firstIndex] == NSNotFound);
+ BOOL changed = NO;
+ NSUInteger row;
+
+ if (_selectingColumns)
{
- _selectingColumns = NO;
- if (_headerView)
- {
- [_headerView setNeedsDisplay: YES];
- }
+ _selectingColumns = NO;
+ if (_headerView)
+ {
+ [_headerView setNeedsDisplay: YES];
+ }
}
-
- /* Stop editing if any */
- if (_textObject != nil)
+
+ /* Stop editing if any */
+ if (_textObject != nil)
{
- [self validateEditing];
- [self abortEditing];
+ [self validateEditing];
+ [self abortEditing];
}
-
- if (extend == NO)
+
+ if (extend == NO)
{
- /* If the current selection is the one we want, just ends editing
- * This is not just a speed up, it prevents us from sending
- * a NSTableViewSelectionDidChangeNotification.
- * This behaviour is required by the specifications */
- if ([_selectedRows isEqual: indexes])
+ /* If the current selection is the one we want, just ends editing
+ * This is not just a speed up, it prevents us from sending
+ * a NSTableViewSelectionDidChangeNotification.
+ * This behaviour is required by the specifications */
+ if ([_selectedRows isEqual: indexes])
{
- if (!empty)
- {
- _selectedRow = [indexes lastIndex];
- }
- return;
- }
-
- [self _unselectAllRows];
- changed = YES;
+ if (!empty)
+ {
+ _selectedRow = [indexes lastIndex];
+ }
+ return;
+ }
+
+ [self _unselectAllRows];
+ changed = YES;
}
-
- if (!empty)
+
+ if (!empty)
{
- if ([indexes lastIndex] >= _numberOfRows)
+ if ([indexes lastIndex] >= _numberOfRows)
{
- [NSException raise: NSInvalidArgumentException
- format: @"Row index out of table in selectRow"];
- }
-
- /* This check is not fully correct, as both sets may contain just
- the same entry, but works according to the old specification. */
- if (_allowsMultipleSelection == NO &&
- [_selectedRows count] + [indexes count] > 1)
+ [NSException raise: NSInvalidArgumentException
+ format: @"Row index out of table in selectRow"];
+ }
+
+ /* This check is not fully correct, as both sets may contain just
+ the same entry, but works according to the old specification. */
+ if (_allowsMultipleSelection == NO &&
+ [_selectedRows count] + [indexes count] > 1)
{
- [NSException raise: NSInternalInconsistencyException
- format: @"Can not set multiple selection in table view when multiple selection is disabled"];
- }
-
- row = [indexes firstIndex];
- while (row != NSNotFound)
+ [NSException raise: NSInternalInconsistencyException
+ format: @"Can not set multiple selection in table view when multiple selection is disabled"];
+ }
+
+ row = [indexes firstIndex];
+ while (row != NSNotFound)
{
- if (![_selectedRows containsIndex: row])
- {
- [self setNeedsDisplayInRect: [self rectOfRow: row]];
- }
- row = [indexes indexGreaterThanIndex: row];
- }
- [_selectedRows addIndexes: indexes];
- _selectedRow = [indexes lastIndex];
- changed = YES;
+ if (![_selectedRows containsIndex: row])
+ {
+ [self setNeedsDisplayInRect: [self rectOfRow: row]];
+ }
+ row = [indexes indexGreaterThanIndex: row];
+ }
+ [_selectedRows addIndexes: indexes];
+ _selectedRow = [indexes lastIndex];
+ changed = YES;
}
-
- if (changed)
+
+ if (changed)
{
- [self _postSelectionDidChangeNotification];
+ [self _postSelectionDidChangeNotification];
}
}
- (NSIndexSet *) selectedColumnIndexes
{
- return _selectedColumns;
+ return _selectedColumns;
}
- (NSIndexSet *) selectedRowIndexes
{
- return _selectedRows;
+ return _selectedRows;
}
- (void) deselectColumn: (int)columnIndex
{
- if ([_selectedColumns containsIndex: columnIndex] == NO)
+ if ([_selectedColumns containsIndex: columnIndex] == NO)
{
- return;
+ return;
}
-
- /* Now by internal consistency we assume columnIndex is in fact a
+
+ /* Now by internal consistency we assume columnIndex is in fact a
valid column index, since it was the index of a selected column */
-
- if (_textObject != nil)
+
+ if (_textObject != nil)
{
- [self validateEditing];
- [self abortEditing];
+ [self validateEditing];
+ [self abortEditing];
}
-
- _selectingColumns = YES;
-
- [_selectedColumns removeIndex: columnIndex];
-
- if (_selectedColumn == columnIndex)
+
+ _selectingColumns = YES;
+
+ [_selectedColumns removeIndex: columnIndex];
+
+ if (_selectedColumn == columnIndex)
{
- NSUInteger less = [_selectedColumns indexLessThanIndex: columnIndex];
- NSUInteger greater = [_selectedColumns indexGreaterThanIndex: columnIndex];
-
- if (less == NSNotFound)
+ NSUInteger less = [_selectedColumns indexLessThanIndex: columnIndex];
+ NSUInteger greater = [_selectedColumns indexGreaterThanIndex: columnIndex];
+
+ if (less == NSNotFound)
{
- if (greater == NSNotFound)
- {
- _selectedColumn = -1;
- }
- else
- {
- _selectedColumn = greater;
- }
- }
- else if (greater == NSNotFound)
+ if (greater == NSNotFound)
+ {
+ _selectedColumn = -1;
+ }
+ else
+ {
+ _selectedColumn = greater;
+ }
+ }
+ else if (greater == NSNotFound)
{
- _selectedColumn = less;
- }
- else if (columnIndex - less > greater - columnIndex)
+ _selectedColumn = less;
+ }
+ else if (columnIndex - less > greater - columnIndex)
{
- _selectedColumn = greater;
- }
- else
+ _selectedColumn = greater;
+ }
+ else
{
- _selectedColumn = less;
- }
+ _selectedColumn = less;
+ }
}
-
- [self setNeedsDisplayInRect: [self rectOfColumn: columnIndex]];
- if (_headerView)
+
+ [self setNeedsDisplayInRect: [self rectOfColumn: columnIndex]];
+ if (_headerView)
{
- [_headerView setNeedsDisplayInRect:
- [_headerView headerRectOfColumn: columnIndex]];
+ [_headerView setNeedsDisplayInRect:
+ [_headerView headerRectOfColumn: columnIndex]];
}
-
- [self _postSelectionDidChangeNotification];
+
+ [self _postSelectionDidChangeNotification];
}
- (void) deselectRow: (int)rowIndex
{
- if ([_selectedRows containsIndex: rowIndex] == NO)
+ if ([_selectedRows containsIndex: rowIndex] == NO)
{
- return;
+ return;
}
-
- if (_textObject != nil)
+
+ if (_textObject != nil)
{
- [self validateEditing];
- [self abortEditing];
+ [self validateEditing];
+ [self abortEditing];
}
-
- _selectingColumns = NO;
-
- [_selectedRows removeIndex: rowIndex];
-
- if (_selectedRow == rowIndex)
+
+ _selectingColumns = NO;
+
+ [_selectedRows removeIndex: rowIndex];
+
+ if (_selectedRow == rowIndex)
{
- NSUInteger less = [_selectedRows indexLessThanIndex: rowIndex];
- NSUInteger greater = [_selectedRows indexGreaterThanIndex: rowIndex];
-
- if (less == NSNotFound)
+ NSUInteger less = [_selectedRows indexLessThanIndex: rowIndex];
+ NSUInteger greater = [_selectedRows indexGreaterThanIndex: rowIndex];
+
+ if (less == NSNotFound)
{
- if (greater == NSNotFound)
- {
- _selectedRow = -1;
- }
- else
- {
- _selectedRow = greater;
- }
- }
- else if (greater == NSNotFound)
+ if (greater == NSNotFound)
+ {
+ _selectedRow = -1;
+ }
+ else
+ {
+ _selectedRow = greater;
+ }
+ }
+ else if (greater == NSNotFound)
{
- _selectedRow = less;
- }
- else if (rowIndex - less > greater - rowIndex)
+ _selectedRow = less;
+ }
+ else if (rowIndex - less > greater - rowIndex)
{
- _selectedRow = greater;
- }
- else
+ _selectedRow = greater;
+ }
+ else
{
- _selectedRow = less;
- }
+ _selectedRow = less;
+ }
}
-
- [self _postSelectionDidChangeNotification];
+
+ [self _postSelectionDidChangeNotification];
}
- (int) numberOfSelectedColumns
{
- return [_selectedColumns count];
+ return [_selectedColumns count];
}
- (int) numberOfSelectedRows
{
- return [_selectedRows count];
+ return [_selectedRows count];
}
- (int) selectedColumn
{
- return _selectedColumn;
+ return _selectedColumn;
}
- (int) selectedRow
{
- return _selectedRow;
+ return _selectedRow;
}
- (BOOL) isColumnSelected: (int)columnIndex
{
- return [_selectedColumns containsIndex: columnIndex];
+ return [_selectedColumns containsIndex: columnIndex];
}
- (BOOL) isRowSelected: (int)rowIndex
{
- return [_selectedRows containsIndex: rowIndex];
+ return [_selectedRows containsIndex: rowIndex];
}
- (NSEnumerator *) selectedColumnEnumerator
{
- return [[self _selectedColumArray] objectEnumerator];
+ return [[self _selectedColumArray] objectEnumerator];
}
- (NSEnumerator *) selectedRowEnumerator
{
- return [[self _selectedRowArray] objectEnumerator];
+ return [[self _selectedRowArray] objectEnumerator];
}
- (void) selectAll: (id) sender
{
- if (_allowsMultipleSelection == NO)
- return;
-
- /* Ask the delegate if we can select all columns or rows */
- if (_selectingColumns == YES)
+ if (_allowsMultipleSelection == NO)
+ return;
+
+ /* Ask the delegate if we can select all columns or rows */
+ if (_selectingColumns == YES)
{
- if ([_selectedColumns count] == (unsigned)_numberOfColumns)
- {
- // Nothing to do !
- return;
- }
-
- {
- NSEnumerator *enumerator = [_tableColumns objectEnumerator];
- NSTableColumn *tb;
- while ((tb = [enumerator nextObject]) != nil)
- {
- if ([self _shouldSelectTableColumn: tb] == NO)
- {
- return;
- }
- }
- }
+ if ([_selectedColumns count] == (unsigned)_numberOfColumns)
+ {
+ // Nothing to do !
+ return;
+ }
+
+ {
+ NSEnumerator *enumerator = [_tableColumns objectEnumerator];
+ NSTableColumn *tb;
+ while ((tb = [enumerator nextObject]) != nil)
+ {
+ if ([self _shouldSelectTableColumn: tb] == NO)
+ {
+ return;
+ }
+ }
+ }
}
- else // selecting rows
+ else // selecting rows
{
- if ([_selectedRows count] == (unsigned)_numberOfRows)
- {
- // Nothing to do !
- return;
- }
-
- {
- int row;
-
- for (row = 0; row < _numberOfRows; row++)
- {
- if ([self _shouldSelectRow: row] == NO)
- return;
- }
- }
+ if ([_selectedRows count] == (unsigned)_numberOfRows)
+ {
+ // Nothing to do !
+ return;
+ }
+
+ {
+ int row;
+
+ for (row = 0; row < _numberOfRows; row++)
+ {
+ if ([self _shouldSelectRow: row] == NO)
+ return;
+ }
+ }
}
-
- /* Stop editing if any */
- if (_textObject != nil)
+
+ /* Stop editing if any */
+ if (_textObject != nil)
{
- [self validateEditing];
- [self abortEditing];
- }
-
- /* Do the real selection */
- if (_selectingColumns == YES)
+ [self validateEditing];
+ [self abortEditing];
+ }
+
+ /* Do the real selection */
+ if (_selectingColumns == YES)
{
- [_selectedColumns removeAllIndexes];
- [_selectedColumns addIndexesInRange: NSMakeRange(0, _numberOfColumns)];
+ [_selectedColumns removeAllIndexes];
+ [_selectedColumns addIndexesInRange: NSMakeRange(0, _numberOfColumns)];
}
- else // selecting rows
+ else // selecting rows
{
- [_selectedRows removeAllIndexes];
- [_selectedRows addIndexesInRange: NSMakeRange(0, _numberOfRows)];
+ [_selectedRows removeAllIndexes];
+ [_selectedRows addIndexesInRange: NSMakeRange(0, _numberOfRows)];
}
-
- [self setNeedsDisplay: YES];
- [self _postSelectionDidChangeNotification];
+
+ [self setNeedsDisplay: YES];
+ [self _postSelectionDidChangeNotification];
}
- (void) deselectAll: (id) sender
{
- if (_allowsEmptySelection == NO)
- return;
-
- if ([self _shouldSelectionChange] == NO)
+ if (_allowsEmptySelection == NO)
+ return;
+
+ if ([self _shouldSelectionChange] == NO)
{
- return;
+ return;
}
-
- if (_textObject != nil)
+
+ if (_textObject != nil)
{
- [self validateEditing];
- [self abortEditing];
+ [self validateEditing];
+ [self abortEditing];
}
-
- if (([_selectedColumns count] > 0) || ([_selectedRows count] > 0))
+
+ if (([_selectedColumns count] > 0) || ([_selectedRows count] > 0))
{
- [_selectedColumns removeAllIndexes];
- [_selectedRows removeAllIndexes];
- _selectedColumn = -1;
- _selectedRow = -1;
- _selectingColumns = NO;
- [self setNeedsDisplay: YES];
- [self _postSelectionDidChangeNotification];
+ [_selectedColumns removeAllIndexes];
+ [_selectedRows removeAllIndexes];
+ _selectedColumn = -1;
+ _selectedRow = -1;
+ _selectingColumns = NO;
+ [self setNeedsDisplay: YES];
+ [self _postSelectionDidChangeNotification];
}
- else
+ else
{
- _selectedColumn = -1;
- _selectedRow = -1;
- _selectingColumns = NO;
+ _selectedColumn = -1;
+ _selectedRow = -1;
+ _selectingColumns = NO;
}
}
-/*
- * Grid Drawing attributes
+/*
+ * Grid Drawing attributes
*/
- (void) setDrawsGrid: (BOOL)flag
{
- _drawsGrid = flag;
+ _drawsGrid = flag;
}
- (BOOL) drawsGrid
{
- return _drawsGrid;
+ return _drawsGrid;
}
- (void) setGridColor: (NSColor *)aColor
{
- ASSIGN (_gridColor, aColor);
+ ASSIGN (_gridColor, aColor);
}
- (NSColor *) gridColor
{
- return _gridColor;
+ return _gridColor;
}
- (void) setGridStyleMask: (unsigned int)gridType
{
- // FIXME
+ // FIXME
}
- (unsigned int) gridStyleMask
{
- // FIXME
- return 0;
+ // FIXME
+ return 0;
}
-/*
- * Editing Cells
+/*
+ * Editing Cells
*/
- (BOOL) abortEditing
-{
- if (_textObject)
+{
+ if (_textObject)
{
- [_editedCell endEditing: _textObject];
- DESTROY(_editedCell);
- [self setNeedsDisplayInRect:
- [self frameOfCellAtColumn: _editedColumn row: _editedRow]];
- _editedRow = -1;
- _editedColumn = -1;
- _textObject = nil;
- return YES;
+ [_editedCell endEditing: _textObject];
+ DESTROY(_editedCell);
+ [self setNeedsDisplayInRect:
+ [self frameOfCellAtColumn: _editedColumn row: _editedRow]];
+ _editedRow = -1;
+ _editedColumn = -1;
+ _textObject = nil;
+ return YES;
}
- else
- return NO;
+ else
+ return NO;
}
- (NSText *) currentEditor
{
- if (_textObject && ([_window firstResponder] == _textObject))
- return _textObject;
- else
- return nil;
+ if (_textObject && ([_window firstResponder] == _textObject))
+ return _textObject;
+ else
+ return nil;
}
- (void) validateEditing
{
- if (_textObject && (_isValidating == NO))
+ if (_textObject && (_isValidating == NO))
{
- NSFormatter *formatter;
- NSString *string;
- id newObjectValue = nil;
- BOOL validatedOK = YES;
-
- // Avoid potential recursive sequences...
- _isValidating = YES;
-
- formatter = [_editedCell formatter];
- string = AUTORELEASE([[_textObject text] copy]);
-
- if (formatter != nil)
+ NSFormatter *formatter;
+ NSString *string;
+ id newObjectValue = nil;
+ BOOL validatedOK = YES;
+
+ // Avoid potential recursive sequences...
+ _isValidating = YES;
+
+ formatter = [_editedCell formatter];
+ string = AUTORELEASE([[_textObject text] copy]);
+
+ if (formatter != nil)
{
- NSString *error;
-
- if ([formatter getObjectValue: &newObjectValue
- forString: string
+ NSString *error;
+
+ if ([formatter getObjectValue: &newObjectValue
+ forString: string
errorDescription: &error] == YES)
{
- [_editedCell setObjectValue: newObjectValue];
-
- if (_dataSource_editable)
+ [_editedCell setObjectValue: newObjectValue];
+
+ if (_dataSource_editable)
{
- NSTableColumn *tb;
-
- tb = [_tableColumns objectAtIndex: _editedColumn];
-
- [self _setObjectValue: newObjectValue
- forTableColumn: tb
- row: _editedRow];
+ NSTableColumn *tb;
+
+ tb = [_tableColumns objectAtIndex: _editedColumn];
+
+ [self _setObjectValue: newObjectValue
+ forTableColumn: tb
+ row: _editedRow];
}
- return;
+ return;
}
- else
+ else
{
- SEL sel = @selector(control:didFailToFormatString:errorDescription:);
-
- if ([_delegate respondsToSelector: sel])
+ SEL sel = @selector(control:didFailToFormatString:errorDescription:);
+
+ if ([_delegate respondsToSelector: sel])
{
- validatedOK = [_delegate control: self
- didFailToFormatString: string
- errorDescription: error];
+ validatedOK = [_delegate control: self
+ didFailToFormatString: string
+ errorDescription: error];
}
- // Allow an empty string to fall through
- else if (![string isEqualToString: @""])
+ // Allow an empty string to fall through
+ else if (![string isEqualToString: @""])
{
- validatedOK = NO;
+ validatedOK = NO;
}
}
}
-
- if (validatedOK)
+
+ if (validatedOK)
{
- [_editedCell setStringValue: string];
-
- if (_dataSource_editable)
+ [_editedCell setStringValue: string];
+
+ if (_dataSource_editable)
{
- NSTableColumn *tb;
-
- tb = [_tableColumns objectAtIndex: _editedColumn];
-
- [self _setObjectValue: string // newObjectValue
- forTableColumn: tb
- row: _editedRow];
+ NSTableColumn *tb;
+
+ tb = [_tableColumns objectAtIndex: _editedColumn];
+
+ [self _setObjectValue: string // newObjectValue
+ forTableColumn: tb
+ row: _editedRow];
}
}
-
- // Avoid potential recursive sequences...
- _isValidating = NO;
+
+ // Avoid potential recursive sequences...
+ _isValidating = NO;
}
}
-- (void) editColumn: (int) columnIndex
- row: (int) rowIndex
- withEvent: (NSEvent *) theEvent
+- (void) editColumn: (int) columnIndex
+ row: (int) rowIndex
+ withEvent: (NSEvent *) theEvent
select: (BOOL) flag
{
- NSText *t;
- NSTableColumn *tb;
- NSRect drawingRect;
- unsigned length = 0;
-
- // We refuse to edit cells if the delegate can not accept results
- // of editing.
- if (_dataSource_editable == NO)
+ NSText *t;
+ NSTableColumn *tb;
+ NSRect drawingRect;
+ unsigned length = 0;
+
+ // We refuse to edit cells if the delegate can not accept results
+ // of editing.
+ if (_dataSource_editable == NO)
{
- flag = YES;
+ flag = YES;
}
-
- if (rowIndex != _selectedRow)
+
+ if (rowIndex != _selectedRow)
{
- [NSException raise:NSInvalidArgumentException
- format:@"Attempted to edit unselected row"];
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempted to edit unselected row"];
}
-
- if (rowIndex < 0 || rowIndex >= _numberOfRows
- || columnIndex < 0 || columnIndex >= _numberOfColumns)
+
+ if (rowIndex < 0 || rowIndex >= _numberOfRows
+ || columnIndex < 0 || columnIndex >= _numberOfColumns)
{
- [NSException raise: NSInvalidArgumentException
- format: @"Row/column out of index in edit"];
+ [NSException raise: NSInvalidArgumentException
+ format: @"Row/column out of index in edit"];
}
-
- [self scrollRowToVisible: rowIndex];
- [self scrollColumnToVisible: columnIndex];
-
- if (_textObject != nil)
+
+ [self scrollRowToVisible: rowIndex];
+ [self scrollColumnToVisible: columnIndex];
+
+ if (_textObject != nil)
{
- [self validateEditing];
- [self abortEditing];
+ [self validateEditing];
+ [self abortEditing];
}
-
- // Now (_textObject == nil)
-
- t = [_window fieldEditor: YES forObject: self];
-
- if ([t superview] != nil)
+
+ // Now (_textObject == nil)
+
+ t = [_window fieldEditor: YES forObject: self];
+
+ if ([t superview] != nil)
{
- if ([t resignFirstResponder] == NO)
- {
- return;
- }
+ if ([t resignFirstResponder] == NO)
+ {
+ return;
+ }
}
-
- _editedRow = rowIndex;
- _editedColumn = columnIndex;
-
- // Prepare the cell
- tb = [_tableColumns objectAtIndex: columnIndex];
- // NB: need to be released when no longer used
- _editedCell = [[self _dataCellForTableColumn: tb row: rowIndex] copy];
-
- [_editedCell setEditable: _dataSource_editable];
- [_editedCell setObjectValue: [self _objectValueForTableColumn: tb
- row: rowIndex]];
-
- // But of course the delegate can mess it up if it wants
- [self _willDisplayCell: _editedCell
- forTableColumn: tb
- row: rowIndex];
-
- /* Please note the important point - calling stringValue normally
+
+ _editedRow = rowIndex;
+ _editedColumn = columnIndex;
+
+ // Prepare the cell
+ tb = [_tableColumns objectAtIndex: columnIndex];
+ // NB: need to be released when no longer used
+ _editedCell = [[self _dataCellForTableColumn: tb row: rowIndex] copy];
+
+ [_editedCell setEditable: _dataSource_editable];
+ [_editedCell setObjectValue: [self _objectValueForTableColumn: tb
+ row: rowIndex]];
+
+ // But of course the delegate can mess it up if it wants
+ [self _willDisplayCell: _editedCell
+ forTableColumn: tb
+ row: rowIndex];
+
+ /* Please note the important point - calling stringValue normally
causes the _editedCell to call the validateEditing method of its
control view ... which happens to be this NSTableView object :-)
but we don't want any spurious validateEditing to be performed
@@ -3364,1964 +3360,1964 @@ byExtendingSelection: (BOOL)flag
edit somewhere else ... getting into the bug that when you TAB
from one cell to another one, the string is copied!), so we must
call stringValue when _textObject is still nil. */
- if (flag)
+ if (flag)
{
- length = [[_editedCell stringValue] length];
+ length = [[_editedCell stringValue] length];
}
-
- _textObject = [_editedCell setUpFieldEditorAttributes: t];
- // FIXME: Which background color do we want here?
- [_textObject setBackgroundColor: [NSColor selectedControlColor]];
- [_textObject setDrawsBackground: YES];
-
- drawingRect = [self frameOfCellAtColumn: columnIndex row: rowIndex];
- if (flag)
+
+ _textObject = [_editedCell setUpFieldEditorAttributes: t];
+ // FIXME: Which background color do we want here?
+ [_textObject setBackgroundColor: [NSColor selectedControlColor]];
+ [_textObject setDrawsBackground: YES];
+
+ drawingRect = [self frameOfCellAtColumn: columnIndex row: rowIndex];
+ if (flag)
{
- [_editedCell selectWithFrame: drawingRect
- inView: self
- editor: _textObject
- delegate: self
- start: 0
- length: length];
+ [_editedCell selectWithFrame: drawingRect
+ inView: self
+ editor: _textObject
+ delegate: self
+ start: 0
+ length: length];
}
- else
+ else
{
- [_editedCell editWithFrame: drawingRect
- inView: self
- editor: _textObject
- delegate: self
- event: theEvent];
+ [_editedCell editWithFrame: drawingRect
+ inView: self
+ editor: _textObject
+ delegate: self
+ event: theEvent];
}
- return;
+ return;
}
- (int) editedRow
{
- return _editedRow;
+ return _editedRow;
}
- (int) editedColumn
{
- return _editedColumn;
+ return _editedColumn;
}
static inline float computePeriod(NSPoint mouseLocationWin,
- float minYVisible,
- float maxYVisible)
+ float minYVisible,
+ float maxYVisible)
{
- /* We have three zones of speed.
- 0 - 50 pixels: period 0.2
- 50 - 100 pixels: period 0.1
- 100 - 150 pixels: period 0.01 */
+ /* We have three zones of speed.
+ 0 - 50 pixels: period 0.2
+ 50 - 100 pixels: period 0.1
+ 100 - 150 pixels: period 0.01 */
float distance = 0;
- if (mouseLocationWin.y < minYVisible)
- {
- distance = minYVisible - mouseLocationWin.y;
- }
+ if (mouseLocationWin.y < minYVisible)
+ {
+ distance = minYVisible - mouseLocationWin.y;
+ }
else if (mouseLocationWin.y > maxYVisible)
- {
- distance = mouseLocationWin.y - maxYVisible;
- }
+ {
+ distance = mouseLocationWin.y - maxYVisible;
+ }
if (distance < 50)
- return 0.2;
+ return 0.2;
else if (distance < 100)
- return 0.1;
- else
- return 0.01;
+ return 0.1;
+ else
+ return 0.01;
}
- (void) _trackCellAtColumn: (int) columnIndex
- row: (int) rowIndex
- withEvent: (NSEvent *) theEvent
+ row: (int) rowIndex
+ withEvent: (NSEvent *) theEvent
{
- NSTableColumn *tb;
- NSCell *cell;
- NSRect cellFrame;
- id originalValue;
-
- if (rowIndex == -1 || columnIndex == -1)
+ NSTableColumn *tb;
+ NSCell *cell;
+ NSRect cellFrame;
+ id originalValue;
+
+ if (rowIndex == -1 || columnIndex == -1)
{
- return;
+ return;
}
-
- tb = [_tableColumns objectAtIndex: columnIndex];
- /* we should copy the cell here, as we do on editing.
+
+ tb = [_tableColumns objectAtIndex: columnIndex];
+ /* we should copy the cell here, as we do on editing.
otherwise validation on a cell being edited could
cause the cell we are selecting to get it's objectValue */
- cell = [[self _dataCellForTableColumn: tb row: rowIndex] copy];
- originalValue = RETAIN([self _objectValueForTableColumn: tb
- row: rowIndex]);
- [cell setObjectValue: originalValue];
- cellFrame = [self frameOfCellAtColumn: columnIndex
- row: rowIndex];
- [cell setHighlighted: YES];
- [self setNeedsDisplayInRect: cellFrame];
- /* give delegate a chance to i.e set target */
- [self _willDisplayCell: cell
- forTableColumn: tb
- row: rowIndex];
-
- if ([cell trackMouse: theEvent
- inRect: cellFrame
- ofView: self
- untilMouseUp: [[cell class]
- prefersTrackingUntilMouseUp]])
+ cell = [[self _dataCellForTableColumn: tb row: rowIndex] copy];
+ originalValue = RETAIN([self _objectValueForTableColumn: tb
+ row: rowIndex]);
+ [cell setObjectValue: originalValue];
+ cellFrame = [self frameOfCellAtColumn: columnIndex
+ row: rowIndex];
+ [cell setHighlighted: YES];
+ [self setNeedsDisplayInRect: cellFrame];
+ /* give delegate a chance to i.e set target */
+ [self _willDisplayCell: cell
+ forTableColumn: tb
+ row: rowIndex];
+
+ if ([cell trackMouse: theEvent
+ inRect: cellFrame
+ ofView: self
+ untilMouseUp: [[cell class]
+ prefersTrackingUntilMouseUp]])
{
- id newValue = [cell objectValue];
-
- /* don't check editability that only pertains to editColumn:... */
- if (originalValue != newValue
- && ![originalValue isEqual: newValue])
+ id newValue = [cell objectValue];
+
+ /* don't check editability that only pertains to editColumn:... */
+ if (originalValue != newValue
+ && ![originalValue isEqual: newValue])
{
- [self _setObjectValue: newValue
- forTableColumn: tb
- row: rowIndex];
- }
+ [self _setObjectValue: newValue
+ forTableColumn: tb
+ row: rowIndex];
+ }
}
- RELEASE(originalValue);
- [cell setHighlighted: NO];
- [self setNeedsDisplayInRect: cellFrame];
- RELEASE(cell);
+ RELEASE(originalValue);
+ [cell setHighlighted: NO];
+ [self setNeedsDisplayInRect: cellFrame];
+ RELEASE(cell);
}
- (BOOL) _startDragOperationWithEvent: (NSEvent *) theEvent
{
- NSPasteboard *pboard = [NSPasteboard pasteboardWithName: NSDragPboard];
- NSPoint startPoint = [self convertPoint: [theEvent locationInWindow]
- fromView: nil];
-
- if ([self canDragRowsWithIndexes: _selectedRows atPoint: startPoint]
- && [self _writeRows: _selectedRows toPasteboard: pboard])
+ NSPasteboard *pboard = [NSPasteboard pasteboardWithName: NSDragPboard];
+ NSPoint startPoint = [self convertPoint: [theEvent locationInWindow]
+ fromView: nil];
+
+ if ([self canDragRowsWithIndexes: _selectedRows atPoint: startPoint]
+ && [self _writeRows: _selectedRows toPasteboard: pboard])
{
- NSPoint p = NSZeroPoint;
- NSImage *dragImage;
- NSSize s;
- // FIXME
- NSArray *cols = nil;
-
- dragImage = [self dragImageForRowsWithIndexes: _selectedRows
- tableColumns: cols
- event: theEvent
- offset: &p];
-
- /*
- * Store image offset in s ... the returned
- * value is the position of the center of
- * the image, so we adjust to the bottom left
- * corner.
- */
- s = [dragImage size];
- s.width = p.x - s.width/2;
- s.height = p.y + s.height/2; // View is flipped
-
- /*
- * Reuse the current mouse location and adjust
- * it to determine the location of the bottom
- * left corner of the image in this view's
- * coordinate system.
- */
- p = startPoint;
- p.x += s.width;
- p.y += s.height;
-
-
- [self dragImage: dragImage
- at: p
- offset: NSMakeSize(0, 0)
- event: theEvent
- pasteboard: pboard
- source: self
- slideBack: YES];
- return YES;
+ NSPoint p = NSZeroPoint;
+ NSImage *dragImage;
+ NSSize s;
+ // FIXME
+ NSArray *cols = nil;
+
+ dragImage = [self dragImageForRowsWithIndexes: _selectedRows
+ tableColumns: cols
+ event: theEvent
+ offset: &p];
+
+ /*
+ * Store image offset in s ... the returned
+ * value is the position of the center of
+ * the image, so we adjust to the bottom left
+ * corner.
+ */
+ s = [dragImage size];
+ s.width = p.x - s.width/2;
+ s.height = p.y + s.height/2; // View is flipped
+
+ /*
+ * Reuse the current mouse location and adjust
+ * it to determine the location of the bottom
+ * left corner of the image in this view's
+ * coordinate system.
+ */
+ p = startPoint;
+ p.x += s.width;
+ p.y += s.height;
+
+
+ [self dragImage: dragImage
+ at: p
+ offset: NSMakeSize(0, 0)
+ event: theEvent
+ pasteboard: pboard
+ source: self
+ slideBack: YES];
+ return YES;
}
- return NO;
+ return NO;
}
- (void) mouseDown: (NSEvent *)theEvent
{
- NSPoint initialLocation = [theEvent locationInWindow];
- NSPoint location;
- int clickCount = [theEvent clickCount];
-
- // Pathological case -- ignore mouse down
- if ((_numberOfRows == 0) || (_numberOfColumns == 0))
+ NSPoint initialLocation = [theEvent locationInWindow];
+ NSPoint location;
+ int clickCount = [theEvent clickCount];
+
+ // Pathological case -- ignore mouse down
+ if ((_numberOfRows == 0) || (_numberOfColumns == 0))
{
- return;
+ return;
}
-
- /* Stop editing if any */
- if (_textObject != nil)
+
+ /* Stop editing if any */
+ if (_textObject != nil)
{
- if (_editedCell != nil
- && [_editedCell isEntryAcceptable:[_textObject text]] == NO)
+ if (_editedCell != nil
+ && [_editedCell isEntryAcceptable:[_textObject text]] == NO)
{
- NSBeep();
- return;
+ NSBeep();
+ return;
}
- [self validateEditing];
- [self abortEditing];
- }
-
- // Determine row and column which were clicked
- location = [self convertPoint: initialLocation fromView: nil];
- _clickedRow = [self rowAtPoint: location];
- _clickedColumn = [self columnAtPoint: location];
-
- if ([theEvent type] == NSLeftMouseDown
- && clickCount > 1)
+ [self validateEditing];
+ [self abortEditing];
+ }
+
+ // Determine row and column which were clicked
+ location = [self convertPoint: initialLocation fromView: nil];
+ _clickedRow = [self rowAtPoint: location];
+ _clickedColumn = [self columnAtPoint: location];
+
+ if ([theEvent type] == NSLeftMouseDown
+ && clickCount > 1)
{
- // Double-click event
-
- if (![self isRowSelected: _clickedRow])
+ // Double-click event
+
+ if (![self isRowSelected: _clickedRow])
{
- return;
- }
-
- if (![self _isCellEditableColumn: _clickedColumn row: _clickedRow ])
+ return;
+ }
+
+ if (![self _isCellEditableColumn: _clickedColumn row: _clickedRow ])
{
- // Send double-action but don't edit
- [self _trackCellAtColumn: _clickedColumn
- row: _clickedRow
- withEvent: theEvent];
- if (_clickedRow != -1)
- [self sendAction: _doubleAction to: _target];
- }
- else if (clickCount == 2) // if < 2, dont want to abort editing
+ // Send double-action but don't edit
+ [self _trackCellAtColumn: _clickedColumn
+ row: _clickedRow
+ withEvent: theEvent];
+ if (_clickedRow != -1)
+ [self sendAction: _doubleAction to: _target];
+ }
+ else if (clickCount == 2) // if < 2, dont want to abort editing
{
- // It is OK to edit column. Go on, do it.
- [self editColumn: _clickedColumn
- row: _clickedRow
- withEvent: theEvent
- select: YES];
- }
+ // It is OK to edit column. Go on, do it.
+ [self editColumn: _clickedColumn
+ row: _clickedRow
+ withEvent: theEvent
+ select: YES];
+ }
}
- else
+ else
{
#define COMPUTE_NEW_SELECTION do { \
if (originalRow == -1) \
-{ \
-originalRow = currentRow; \
-} \
+ { \
+ originalRow = currentRow; \
+ } \
if (currentRow >= 0 && currentRow < _numberOfRows) \
-{ \
-computeNewSelection(self, \
-oldSelectedRows, \
-_selectedRows, \
-originalRow, \
-oldRow, \
-currentRow, \
-&_selectedRow, \
-selectionMode); \
-[self displayIfNeeded]; \
-} \
+ { \
+ computeNewSelection(self, \
+ oldSelectedRows, \
+ _selectedRows, \
+ originalRow, \
+ oldRow, \
+ currentRow, \
+ &_selectedRow, \
+ selectionMode); \
+ [self displayIfNeeded]; \
+ } \
} while (0);
-
- // Selection
- unsigned int modifiers = [theEvent modifierFlags];
- unsigned int eventMask = (NSLeftMouseUpMask
- | NSLeftMouseDownMask
- | NSLeftMouseDraggedMask
- | NSPeriodicMask);
- unsigned selectionMode = 0;
- NSPoint mouseLocationWin;
- NSPoint mouseLocationView;
- NSDate *distantFuture = [NSDate distantFuture];
- NSEvent *lastEvent;
- NSIndexSet *oldSelectedRows;
- BOOL startedPeriodicEvents = NO;
- BOOL mouseBelowView = NO;
- BOOL done = NO;
- BOOL mouseMoved = NO;
- BOOL didTrackCell = NO;
- BOOL dragOperationPossible = [self _isDraggingSource];
- NSRect visibleRect = [self convertRect: [self visibleRect]
- toView: nil];
- float minYVisible = NSMinY (visibleRect);
- float maxYVisible = NSMaxY (visibleRect);
- float oldPeriod = 0;
- int originalRow = _clickedRow;
- int oldRow = -1;
- int currentRow = -1;
- BOOL getNextEvent = YES;
- BOOL sendAction = NO;
-
- if (_allowsMultipleSelection == YES)
- {
- selectionMode |= ALLOWS_MULTIPLE;
- }
-
- if (_allowsEmptySelection == YES)
- {
- selectionMode |= ALLOWS_EMPTY;
- }
-
- if (modifiers & NSShiftKeyMask)
- {
- selectionMode |= SHIFT_DOWN;
- }
-
- if (![_selectedRows containsIndex: _clickedRow])
- {
- selectionMode |= ADDING_ROW;
- }
-
- if (modifiers & NSControlKeyMask)
- {
- selectionMode |= CONTROL_DOWN;
- if (_allowsMultipleSelection == YES && _selectedRow != -1)
- {
- originalRow = _selectedRow;
- selectionMode |= SHIFT_DOWN;
- selectionMode |= ADDING_ROW;
- }
- }
-
- // is the delegate ok for a new selection ?
- if ([self _shouldSelectionChange] == NO)
- {
- return;
- }
-
- // if we are in column selection mode, stop it
- [self _setSelectingColumns: NO];
-
- // let's sort the _selectedRows
- oldSelectedRows = [_selectedRows copy];
- lastEvent = theEvent;
-
- while (done != YES)
- {
- /*
- Wrap each iteration in an autorelease pool. Otherwise, we end
- up allocating huge amounts of objects if the button is held
- down for a long time.
- */
- CREATE_AUTORELEASE_POOL(arp);
- NSEventType eventType = [lastEvent type];
-
- mouseLocationWin = [lastEvent locationInWindow];
- mouseLocationView = [self convertPoint: mouseLocationWin
- fromView: nil];
-
- switch (eventType)
- {
- case NSLeftMouseUp:
- if ((mouseLocationWin.y > minYVisible)
- && (mouseLocationWin.y < maxYVisible))
- {
- // mouse up within table
- if (startedPeriodicEvents == YES)
- {
- [NSEvent stopPeriodicEvents];
- startedPeriodicEvents = NO;
- }
- mouseLocationView.x = _bounds.origin.x;
- oldRow = currentRow;
- currentRow = [self rowAtPoint: mouseLocationView];
-
- if (oldRow != currentRow)
- {
- COMPUTE_NEW_SELECTION;
- }
-
- if (!didTrackCell && currentRow == _clickedRow)
- {
- /*
- * a dragging operation is still possible so
- * selections were never dragged,
- * and a drag operation was never attempted.
- * the cell was clicked,
- * track the cell with the old mouseDown event
- * then it will get the current event mouseUp.
- */
- [self _trackCellAtColumn: _clickedColumn
- row: _clickedRow
- withEvent: theEvent];
- }
- }
- else
- {
- // Mouse dragged out of the table
- // we don't care
- }
- done = YES;
- break;
-
- case NSLeftMouseDown:
- case NSLeftMouseDragged:
- if (fabs(mouseLocationWin.x - initialLocation.x) > 1
- || fabs(mouseLocationWin.y - initialLocation.y) > 1)
- {
- mouseMoved = YES;
- }
-
- if (dragOperationPossible == YES)
- {
- if ([_selectedRows containsIndex:_clickedRow] == NO
- || (_verticalMotionDrag == NO
- && fabs(mouseLocationWin.y - initialLocation.y) > 2))
- {
- dragOperationPossible = NO;
- }
- else if ((fabs(mouseLocationWin.x - initialLocation.x) >= 4)
- || (_verticalMotionDrag
- && fabs(mouseLocationWin.y - initialLocation.y) >= 4))
- {
- if ([self _startDragOperationWithEvent: theEvent])
- {
- RELEASE(oldSelectedRows);
- IF_NO_GC(DESTROY(arp));
- return;
- }
- else
- {
- dragOperationPossible = NO;
- }
- }
- }
- else if ((mouseLocationWin.y > minYVisible)
- && (mouseLocationWin.y < maxYVisible))
- {
- // mouse dragged within table
- if (startedPeriodicEvents == YES)
- {
- [NSEvent stopPeriodicEvents];
- startedPeriodicEvents = NO;
- }
-
- mouseLocationView.x = _bounds.origin.x;
- oldRow = currentRow;
- currentRow = [self rowAtPoint: mouseLocationView];
- if (oldRow != currentRow)
- {
- COMPUTE_NEW_SELECTION;
- }
-
- if (eventType == NSLeftMouseDown)
- {
- /*
- * Can never get here from a dragging source
- * so they need to track in mouse up.
- */
- NSTableColumn *tb;
- NSCell *cell;
-
- tb = [_tableColumns objectAtIndex: _clickedColumn];
- cell = [self _dataCellForTableColumn: tb row: _clickedRow];
-
- [self _trackCellAtColumn: _clickedColumn
- row: _clickedRow
- withEvent: theEvent];
- didTrackCell = YES;
-
- if ([[cell class] prefersTrackingUntilMouseUp])
- {
- /* the mouse could have gone up outside of the cell
- * avoid selecting the row under mouse cursor */
- sendAction = YES;
- done = YES;
- }
- }
- /*
- * Since we may have tracked a cell which may have caused
- * a change to the currentEvent we may need to loop over
- * the current event
- */
- getNextEvent = (lastEvent == [NSApp currentEvent]);
- }
- else
- {
- // Mouse dragged out of the table
- float period = computePeriod(mouseLocationWin,
- minYVisible,
- maxYVisible);
-
- if (startedPeriodicEvents == YES)
- {
- /* Check - if the mouse did not change zone,
- we do nothing */
- if (period == oldPeriod)
- break;
-
- [NSEvent stopPeriodicEvents];
- }
- /* Start periodic events */
- oldPeriod = period;
- [NSEvent startPeriodicEventsAfterDelay: 0
- withPeriod: oldPeriod];
- startedPeriodicEvents = YES;
- if (mouseLocationWin.y <= minYVisible)
- mouseBelowView = YES;
- else
- mouseBelowView = NO;
- }
- break;
- case NSPeriodic:
- if (mouseBelowView == YES)
- {
- if (currentRow == -1 && oldRow != -1)
- currentRow = oldRow + 1;
-
- if (currentRow != -1 && currentRow < _numberOfRows - 1)
- {
- oldRow = currentRow;
- currentRow++;
- [self scrollRowToVisible: currentRow];
- if (dragOperationPossible == NO)
- COMPUTE_NEW_SELECTION;
- }
- }
- else
- {
- if (currentRow == -1 && oldRow != -1)
- currentRow = oldRow - 1;
-
- if (currentRow > 0)
- {
- oldRow = currentRow;
- currentRow--;
- [self scrollRowToVisible: currentRow];
- if (dragOperationPossible == NO)
- COMPUTE_NEW_SELECTION;
- }
- }
- break;
- default:
- break;
- }
-
- if (done == NO)
- {
- /* in certain cases we are working with events that have already
- * occured and been dequeued by NSCell classes, in these cases
- * getNextEvent is set to NO, use the current event.
- */
- if (getNextEvent == YES)
- {
- lastEvent = [NSApp nextEventMatchingMask: eventMask
- untilDate: distantFuture
- inMode: NSEventTrackingRunLoopMode
- dequeue: YES];
- }
- else
- {
- lastEvent = [NSApp currentEvent];
- getNextEvent = YES;
- }
- }
- IF_NO_GC(DESTROY(arp));
- }
-
- if (startedPeriodicEvents == YES)
- [NSEvent stopPeriodicEvents];
-
- if (![_selectedRows isEqual: oldSelectedRows])
- {
- [self _postSelectionDidChangeNotification];
- }
-
- RELEASE(oldSelectedRows);
-
- if (!mouseMoved)
- sendAction = YES;
-
- /* If this was a simple click (ie. no dragging), we send our action. */
- if (sendAction)
- {
- /*
- _clickedRow and _clickedColumn are already set at the start of
- this function.
-
- TODO: should we ask the data source/column for the cell for this
- row/column and check whether it has its own action/target?
- */
- if (_clickedRow != -1)
- [self sendAction: _action to: _target];
- }
+
+ // Selection
+ unsigned int modifiers = [theEvent modifierFlags];
+ unsigned int eventMask = (NSLeftMouseUpMask
+ | NSLeftMouseDownMask
+ | NSLeftMouseDraggedMask
+ | NSPeriodicMask);
+ unsigned selectionMode = 0;
+ NSPoint mouseLocationWin;
+ NSPoint mouseLocationView;
+ NSDate *distantFuture = [NSDate distantFuture];
+ NSEvent *lastEvent;
+ NSIndexSet *oldSelectedRows;
+ BOOL startedPeriodicEvents = NO;
+ BOOL mouseBelowView = NO;
+ BOOL done = NO;
+ BOOL mouseMoved = NO;
+ BOOL didTrackCell = NO;
+ BOOL dragOperationPossible = [self _isDraggingSource];
+ NSRect visibleRect = [self convertRect: [self visibleRect]
+ toView: nil];
+ float minYVisible = NSMinY (visibleRect);
+ float maxYVisible = NSMaxY (visibleRect);
+ float oldPeriod = 0;
+ int originalRow = _clickedRow;
+ int oldRow = -1;
+ int currentRow = -1;
+ BOOL getNextEvent = YES;
+ BOOL sendAction = NO;
+
+ if (_allowsMultipleSelection == YES)
+ {
+ selectionMode |= ALLOWS_MULTIPLE;
+ }
+
+ if (_allowsEmptySelection == YES)
+ {
+ selectionMode |= ALLOWS_EMPTY;
+ }
+
+ if (modifiers & NSShiftKeyMask)
+ {
+ selectionMode |= SHIFT_DOWN;
+ }
+
+ if (![_selectedRows containsIndex: _clickedRow])
+ {
+ selectionMode |= ADDING_ROW;
+ }
+
+ if (modifiers & NSControlKeyMask)
+ {
+ selectionMode |= CONTROL_DOWN;
+ if (_allowsMultipleSelection == YES && _selectedRow != -1)
+ {
+ originalRow = _selectedRow;
+ selectionMode |= SHIFT_DOWN;
+ selectionMode |= ADDING_ROW;
+ }
+ }
+
+ // is the delegate ok for a new selection ?
+ if ([self _shouldSelectionChange] == NO)
+ {
+ return;
+ }
+
+ // if we are in column selection mode, stop it
+ [self _setSelectingColumns: NO];
+
+ // let's sort the _selectedRows
+ oldSelectedRows = [_selectedRows copy];
+ lastEvent = theEvent;
+
+ while (done != YES)
+ {
+ /*
+ Wrap each iteration in an autorelease pool. Otherwise, we end
+ up allocating huge amounts of objects if the button is held
+ down for a long time.
+ */
+ CREATE_AUTORELEASE_POOL(arp);
+ NSEventType eventType = [lastEvent type];
+
+ mouseLocationWin = [lastEvent locationInWindow];
+ mouseLocationView = [self convertPoint: mouseLocationWin
+ fromView: nil];
+
+ switch (eventType)
+ {
+ case NSLeftMouseUp:
+ if ((mouseLocationWin.y > minYVisible)
+ && (mouseLocationWin.y < maxYVisible))
+ {
+ // mouse up within table
+ if (startedPeriodicEvents == YES)
+ {
+ [NSEvent stopPeriodicEvents];
+ startedPeriodicEvents = NO;
+ }
+ mouseLocationView.x = _bounds.origin.x;
+ oldRow = currentRow;
+ currentRow = [self rowAtPoint: mouseLocationView];
+
+ if (oldRow != currentRow)
+ {
+ COMPUTE_NEW_SELECTION;
+ }
+
+ if (!didTrackCell && currentRow == _clickedRow)
+ {
+ /*
+ * a dragging operation is still possible so
+ * selections were never dragged,
+ * and a drag operation was never attempted.
+ * the cell was clicked,
+ * track the cell with the old mouseDown event
+ * then it will get the current event mouseUp.
+ */
+ [self _trackCellAtColumn: _clickedColumn
+ row: _clickedRow
+ withEvent: theEvent];
+ }
+ }
+ else
+ {
+ // Mouse dragged out of the table
+ // we don't care
+ }
+ done = YES;
+ break;
+
+ case NSLeftMouseDown:
+ case NSLeftMouseDragged:
+ if (fabs(mouseLocationWin.x - initialLocation.x) > 1
+ || fabs(mouseLocationWin.y - initialLocation.y) > 1)
+ {
+ mouseMoved = YES;
+ }
+
+ if (dragOperationPossible == YES)
+ {
+ if ([_selectedRows containsIndex:_clickedRow] == NO
+ || (_verticalMotionDrag == NO
+ && fabs(mouseLocationWin.y - initialLocation.y) > 2))
+ {
+ dragOperationPossible = NO;
+ }
+ else if ((fabs(mouseLocationWin.x - initialLocation.x) >= 4)
+ || (_verticalMotionDrag
+ && fabs(mouseLocationWin.y - initialLocation.y) >= 4))
+ {
+ if ([self _startDragOperationWithEvent: theEvent])
+ {
+ RELEASE(oldSelectedRows);
+ IF_NO_GC(DESTROY(arp));
+ return;
+ }
+ else
+ {
+ dragOperationPossible = NO;
+ }
+ }
+ }
+ else if ((mouseLocationWin.y > minYVisible)
+ && (mouseLocationWin.y < maxYVisible))
+ {
+ // mouse dragged within table
+ if (startedPeriodicEvents == YES)
+ {
+ [NSEvent stopPeriodicEvents];
+ startedPeriodicEvents = NO;
+ }
+
+ mouseLocationView.x = _bounds.origin.x;
+ oldRow = currentRow;
+ currentRow = [self rowAtPoint: mouseLocationView];
+ if (oldRow != currentRow)
+ {
+ COMPUTE_NEW_SELECTION;
+ }
+
+ if (eventType == NSLeftMouseDown)
+ {
+ /*
+ * Can never get here from a dragging source
+ * so they need to track in mouse up.
+ */
+ NSTableColumn *tb;
+ NSCell *cell;
+
+ tb = [_tableColumns objectAtIndex: _clickedColumn];
+ cell = [self _dataCellForTableColumn: tb row: _clickedRow];
+
+ [self _trackCellAtColumn: _clickedColumn
+ row: _clickedRow
+ withEvent: theEvent];
+ didTrackCell = YES;
+
+ if ([[cell class] prefersTrackingUntilMouseUp])
+ {
+ /* the mouse could have gone up outside of the cell
+ * avoid selecting the row under mouse cursor */
+ sendAction = YES;
+ done = YES;
+ }
+ }
+ /*
+ * Since we may have tracked a cell which may have caused
+ * a change to the currentEvent we may need to loop over
+ * the current event
+ */
+ getNextEvent = (lastEvent == [NSApp currentEvent]);
+ }
+ else
+ {
+ // Mouse dragged out of the table
+ float period = computePeriod(mouseLocationWin,
+ minYVisible,
+ maxYVisible);
+
+ if (startedPeriodicEvents == YES)
+ {
+ /* Check - if the mouse did not change zone,
+ we do nothing */
+ if (period == oldPeriod)
+ break;
+
+ [NSEvent stopPeriodicEvents];
+ }
+ /* Start periodic events */
+ oldPeriod = period;
+ [NSEvent startPeriodicEventsAfterDelay: 0
+ withPeriod: oldPeriod];
+ startedPeriodicEvents = YES;
+ if (mouseLocationWin.y <= minYVisible)
+ mouseBelowView = YES;
+ else
+ mouseBelowView = NO;
+ }
+ break;
+ case NSPeriodic:
+ if (mouseBelowView == YES)
+ {
+ if (currentRow == -1 && oldRow != -1)
+ currentRow = oldRow + 1;
+
+ if (currentRow != -1 && currentRow < _numberOfRows - 1)
+ {
+ oldRow = currentRow;
+ currentRow++;
+ [self scrollRowToVisible: currentRow];
+ if (dragOperationPossible == NO)
+ COMPUTE_NEW_SELECTION;
+ }
+ }
+ else
+ {
+ if (currentRow == -1 && oldRow != -1)
+ currentRow = oldRow - 1;
+
+ if (currentRow > 0)
+ {
+ oldRow = currentRow;
+ currentRow--;
+ [self scrollRowToVisible: currentRow];
+ if (dragOperationPossible == NO)
+ COMPUTE_NEW_SELECTION;
+ }
+ }
+ break;
+ default:
+ break;
+ }
+
+ if (done == NO)
+ {
+ /* in certain cases we are working with events that have already
+ * occured and been dequeued by NSCell classes, in these cases
+ * getNextEvent is set to NO, use the current event.
+ */
+ if (getNextEvent == YES)
+ {
+ lastEvent = [NSApp nextEventMatchingMask: eventMask
+ untilDate: distantFuture
+ inMode: NSEventTrackingRunLoopMode
+ dequeue: YES];
+ }
+ else
+ {
+ lastEvent = [NSApp currentEvent];
+ getNextEvent = YES;
+ }
+ }
+ IF_NO_GC(DESTROY(arp));
+ }
+
+ if (startedPeriodicEvents == YES)
+ [NSEvent stopPeriodicEvents];
+
+ if (![_selectedRows isEqual: oldSelectedRows])
+ {
+ [self _postSelectionDidChangeNotification];
+ }
+
+ RELEASE(oldSelectedRows);
+
+ if (!mouseMoved)
+ sendAction = YES;
+
+ /* If this was a simple click (ie. no dragging), we send our action. */
+ if (sendAction)
+ {
+ /*
+ _clickedRow and _clickedColumn are already set at the start of
+ this function.
+
+ TODO: should we ask the data source/column for the cell for this
+ row/column and check whether it has its own action/target?
+ */
+ if (_clickedRow != -1)
+ [self sendAction: _action to: _target];
+ }
}
-
- _clickedRow = _selectedRow;
+
+ _clickedRow = _selectedRow;
}
/* helpers for keyboard selection */
#define CHECK_CHANGING(x) { \
if (!x) \
-{ \
-[self _postSelectionIsChangingNotification]; \
-x = YES; \
-} \
+ { \
+ [self _postSelectionIsChangingNotification]; \
+ x = YES; \
+ } \
}
static BOOL selectContiguousRegion(NSTableView *self,
- NSIndexSet *_selectedRows,
- int originalRow,
- int oldRow,
- int currentRow)
+ NSIndexSet *_selectedRows,
+ int originalRow,
+ int oldRow,
+ int currentRow)
{
- int first = (oldRow < currentRow) ? oldRow : currentRow;
- int last = (oldRow < currentRow) ? currentRow : oldRow;
- int row;
- BOOL notified = NO;
-
- if (![_selectedRows containsIndex: currentRow])
+ int first = (oldRow < currentRow) ? oldRow : currentRow;
+ int last = (oldRow < currentRow) ? currentRow : oldRow;
+ int row;
+ BOOL notified = NO;
+
+ if (![_selectedRows containsIndex: currentRow])
{
- CHECK_CHANGING(notified);
- [self _selectRow: currentRow];
+ CHECK_CHANGING(notified);
+ [self _selectRow: currentRow];
}
-
- /*
- * check if the old row is not between the current row and the original row
- * and not the original or current rows
- */
- if (((!((oldRow < currentRow
- && currentRow > originalRow
- && oldRow > originalRow)
- || (oldRow > currentRow
- && currentRow < originalRow
- && oldRow < originalRow)))
- && (!(oldRow == currentRow
- || oldRow == originalRow))))
+
+ /*
+ * check if the old row is not between the current row and the original row
+ * and not the original or current rows
+ */
+ if (((!((oldRow < currentRow
+ && currentRow > originalRow
+ && oldRow > originalRow)
+ || (oldRow > currentRow
+ && currentRow < originalRow
+ && oldRow < originalRow)))
+ && (!(oldRow == currentRow
+ || oldRow == originalRow))))
{
- CHECK_CHANGING(notified);
- [self _unselectRow: oldRow];
+ CHECK_CHANGING(notified);
+ [self _unselectRow: oldRow];
}
-
- /*
- * there is an off by one here it could be on either end of the loop
- * but its either oldRow or currentRow so above we select the currentRow
- * and possibly unselect the oldRow, one of the two will then
- * be selected or deselected again in in this loop
- */
- for (row = first; row < last; row++)
+
+ /*
+ * there is an off by one here it could be on either end of the loop
+ * but its either oldRow or currentRow so above we select the currentRow
+ * and possibly unselect the oldRow, one of the two will then
+ * be selected or deselected again in in this loop
+ */
+ for (row = first; row < last; row++)
{
-
- /* check if the old row is between the current row and the original row */
- if ((row < currentRow
- && row > originalRow
- && currentRow > oldRow)
- || (row > currentRow
- && row < originalRow
- && currentRow < oldRow))
- {
- if (![_selectedRows containsIndex: row])
- {
- CHECK_CHANGING(notified);
- [self _selectRow: row];
- }
- }
- else if (row == currentRow || row == originalRow)
- {
- if (![_selectedRows containsIndex: row])
- {
- CHECK_CHANGING(notified);
- [self _selectRow: row];
- }
- }
- else
- {
- if ([_selectedRows containsIndex: row])
- {
- CHECK_CHANGING(notified);
- [self _unselectRow: row];
- }
- }
+
+ /* check if the old row is between the current row and the original row */
+ if ((row < currentRow
+ && row > originalRow
+ && currentRow > oldRow)
+ || (row > currentRow
+ && row < originalRow
+ && currentRow < oldRow))
+ {
+ if (![_selectedRows containsIndex: row])
+ {
+ CHECK_CHANGING(notified);
+ [self _selectRow: row];
+ }
+ }
+ else if (row == currentRow || row == originalRow)
+ {
+ if (![_selectedRows containsIndex: row])
+ {
+ CHECK_CHANGING(notified);
+ [self _selectRow: row];
+ }
+ }
+ else
+ {
+ if ([_selectedRows containsIndex: row])
+ {
+ CHECK_CHANGING(notified);
+ [self _unselectRow: row];
+ }
+ }
}
- return notified;
-}
+ return notified;
+}
- (void) keyDown:(NSEvent *)theEvent
{
- int oldRow = -1;
- int currentRow = _selectedRow;
- int originalRow = -1;
- NSString *characters = [theEvent characters];
- unsigned int len = [characters length];
- unsigned int modifiers = [theEvent modifierFlags];
- int rowHeight = [self rowHeight];
- NSRect visRect = [self visibleRect];
- BOOL modifySelection = YES;
- NSPoint noModPoint = NSZeroPoint;
- int visRows;
- unsigned int i;
- BOOL gotMovementKey = NO;
-
- // will not contain partial rows.
- visRows = visRect.size.height / [self rowHeight];
-
- // _clickedRow is stored between calls as the first selected row
- // when doing multiple selection, so the selection may grow and shrink.
-
- /*
- * do a contiguous selection on shift
- */
- if (modifiers & NSShiftKeyMask)
- {
- originalRow = _clickedRow;
- if (_allowsMultipleSelection == YES)
- {
- oldRow = _selectedRow;
+ int oldRow = -1;
+ int currentRow = _selectedRow;
+ int originalRow = -1;
+ NSString *characters = [theEvent characters];
+ unsigned int len = [characters length];
+ unsigned int modifiers = [theEvent modifierFlags];
+ int rowHeight = [self rowHeight];
+ NSRect visRect = [self visibleRect];
+ BOOL modifySelection = YES;
+ NSPoint noModPoint = NSZeroPoint;
+ int visRows;
+ unsigned int i;
+ BOOL gotMovementKey = NO;
+
+ // will not contain partial rows.
+ visRows = visRect.size.height / [self rowHeight];
+
+ // _clickedRow is stored between calls as the first selected row
+ // when doing multiple selection, so the selection may grow and shrink.
+
+ /*
+ * do a contiguous selection on shift
+ */
+ if (modifiers & NSShiftKeyMask)
+ {
+ originalRow = _clickedRow;
+ if (_allowsMultipleSelection == YES)
+ {
+ oldRow = _selectedRow;
+ }
+ }
+
+ /* just scroll don't modify any selection */
+ if (modifiers & NSControlKeyMask)
+ {
+ modifySelection = NO;
+ }
+
+ for (i = 0; i < len; i++)
+ {
+ unichar c = [characters characterAtIndex: i];
+
+ switch (c)
+ {
+ case NSUpArrowFunctionKey:
+ gotMovementKey = YES;
+ if (modifySelection == NO)
+ {
+ noModPoint.x = visRect.origin.x;
+ noModPoint.y = NSMinY(visRect) - rowHeight;
+ }
+ else
+ {
+ currentRow--;
+ }
+ break;
+ case NSDownArrowFunctionKey:
+ gotMovementKey = YES;
+ if (modifySelection == NO)
+ {
+ noModPoint.x = visRect.origin.x;
+ noModPoint.y = NSMinY(visRect) + rowHeight;
+ }
+ else
+ {
+ currentRow++;
+ }
+ break;
+ case NSPageDownFunctionKey:
+ gotMovementKey = YES;
+ if (modifySelection == NO)
+ {
+ noModPoint.x = visRect.origin.x;
+ noModPoint.y = NSMinY(visRect) + (rowHeight * visRows) - rowHeight;
+ }
+ else
+ {
+ currentRow += visRows;
+ }
+ break;
+ case NSPageUpFunctionKey:
+ gotMovementKey = YES;
+ if (modifySelection == NO)
+ {
+ noModPoint.x = visRect.origin.x;
+ noModPoint.y = NSMinY(visRect) - (rowHeight * visRows) + rowHeight;
+ }
+ else
+ {
+ currentRow -= visRows;
+ }
+ break;
+ case NSHomeFunctionKey:
+ gotMovementKey = YES;
+ if (modifySelection == NO)
+ {
+ noModPoint.x = visRect.origin.x;
+ noModPoint.y = NSMinY(_bounds);
+ }
+ else
+ {
+ currentRow = 0;
+ }
+ break;
+ case NSEndFunctionKey:
+ gotMovementKey = YES;
+ if (modifySelection == NO)
+ {
+ noModPoint.x = visRect.origin.x;
+ noModPoint.y = NSMaxY(_bounds);
+ }
+ else
+ {
+ currentRow = _numberOfRows - 1;
+ }
+ break;
+ default:
+ break;
}
- }
-
- /* just scroll don't modify any selection */
- if (modifiers & NSControlKeyMask)
+ }
+
+ /*
+ * if scrolled off the bottom or top the selection.
+ * the modifiers might have changed so recompute the selection.
+ */
+ if (gotMovementKey == NO)
{
- modifySelection = NO;
+ /* no handled keys. */
+ [super keyDown: theEvent];
+ return;
}
-
- for (i = 0; i < len; i++)
+ else if (currentRow < 0)
{
- unichar c = [characters characterAtIndex: i];
-
- switch (c)
+ currentRow = 0;
+ }
+ else if (currentRow >= _numberOfRows)
+ {
+ currentRow = _numberOfRows - 1;
+ }
+
+ if (_numberOfRows)
+ {
+ if (modifySelection)
{
- case NSUpArrowFunctionKey:
- gotMovementKey = YES;
- if (modifySelection == NO)
- {
- noModPoint.x = visRect.origin.x;
- noModPoint.y = NSMinY(visRect) - rowHeight;
- }
- else
- {
- currentRow--;
- }
- break;
- case NSDownArrowFunctionKey:
- gotMovementKey = YES;
- if (modifySelection == NO)
- {
- noModPoint.x = visRect.origin.x;
- noModPoint.y = NSMinY(visRect) + rowHeight;
- }
- else
- {
- currentRow++;
- }
- break;
- case NSPageDownFunctionKey:
- gotMovementKey = YES;
- if (modifySelection == NO)
- {
- noModPoint.x = visRect.origin.x;
- noModPoint.y = NSMinY(visRect) + (rowHeight * visRows) - rowHeight;
- }
- else
- {
- currentRow += visRows;
- }
- break;
- case NSPageUpFunctionKey:
- gotMovementKey = YES;
- if (modifySelection == NO)
- {
- noModPoint.x = visRect.origin.x;
- noModPoint.y = NSMinY(visRect) - (rowHeight * visRows) + rowHeight;
- }
- else
- {
- currentRow -= visRows;
- }
- break;
- case NSHomeFunctionKey:
- gotMovementKey = YES;
- if (modifySelection == NO)
- {
- noModPoint.x = visRect.origin.x;
- noModPoint.y = NSMinY(_bounds);
- }
- else
- {
- currentRow = 0;
- }
- break;
- case NSEndFunctionKey:
- gotMovementKey = YES;
- if (modifySelection == NO)
- {
- noModPoint.x = visRect.origin.x;
- noModPoint.y = NSMaxY(_bounds);
- }
- else
- {
- currentRow = _numberOfRows - 1;
- }
- break;
- default:
- break;
+ BOOL notified = NO;
+
+ [self _setSelectingColumns: NO];
+
+ if (originalRow == -1)
+ {
+ /* we're not extending any selection */
+ originalRow = currentRow;
+ _clickedRow = currentRow;
+ }
+
+ if (_clickedRow == -1)
+ {
+ /* user must have hit a key with no selected rows */
+ _clickedRow = currentRow;
+ }
+
+ if ((!(modifiers & NSShiftKeyMask && _allowsMultipleSelection)))
+ {
+ int first = [_selectedRows firstIndex];
+ int last = [_selectedRows lastIndex];
+
+ if ((first == last && first == currentRow) == 0)
+ {
+ CHECK_CHANGING(notified)
+ [self _unselectAllRows];
+ [self _selectRow: currentRow];
+ _selectedRow = currentRow;
+ }
+ }
+ else
+ {
+ notified = selectContiguousRegion(self, _selectedRows,
+ originalRow, oldRow, currentRow);
+ _selectedRow = currentRow;
+ }
+
+ if (notified)
+ {
+ [self _postSelectionDidChangeNotification];
+ }
+
+ [self scrollRowToVisible: currentRow];
+ [self displayIfNeeded];
}
- }
-
- /*
- * if scrolled off the bottom or top the selection.
- * the modifiers might have changed so recompute the selection.
- */
- if (gotMovementKey == NO)
- {
- /* no handled keys. */
- [super keyDown: theEvent];
- return;
- }
- else if (currentRow < 0)
- {
- currentRow = 0;
- }
- else if (currentRow >= _numberOfRows)
- {
- currentRow = _numberOfRows - 1;
- }
-
- if (_numberOfRows)
- {
- if (modifySelection)
+ else
{
- BOOL notified = NO;
-
- [self _setSelectingColumns: NO];
-
- if (originalRow == -1)
- {
- /* we're not extending any selection */
- originalRow = currentRow;
- _clickedRow = currentRow;
- }
-
- if (_clickedRow == -1)
- {
- /* user must have hit a key with no selected rows */
- _clickedRow = currentRow;
- }
-
- if ((!(modifiers & NSShiftKeyMask && _allowsMultipleSelection)))
- {
- int first = [_selectedRows firstIndex];
- int last = [_selectedRows lastIndex];
-
- if ((first == last && first == currentRow) == 0)
- {
- CHECK_CHANGING(notified)
- [self _unselectAllRows];
- [self _selectRow: currentRow];
- _selectedRow = currentRow;
- }
- }
- else
- {
- notified = selectContiguousRegion(self, _selectedRows,
- originalRow, oldRow, currentRow);
- _selectedRow = currentRow;
- }
-
- if (notified)
- {
- [self _postSelectionDidChangeNotification];
- }
-
- [self scrollRowToVisible: currentRow];
- [self displayIfNeeded];
- }
- else
- {
- noModPoint = [self convertPoint: noModPoint
- toView: _super_view];
- noModPoint =
- [(NSClipView *)_super_view constrainScrollPoint: noModPoint];
- [(NSClipView *)_super_view scrollToPoint: noModPoint];
- }
+ noModPoint = [self convertPoint: noModPoint
+ toView: _super_view];
+ noModPoint =
+ [(NSClipView *)_super_view constrainScrollPoint: noModPoint];
+ [(NSClipView *)_super_view scrollToPoint: noModPoint];
+ }
}
}
-/*
- * Auxiliary Components
+/*
+ * Auxiliary Components
*/
- (void) setHeaderView: (NSTableHeaderView*)aHeaderView
{
-
- if ([_headerView respondsToSelector:@selector(setTableView:)])
- [_headerView setTableView: nil];
-
- ASSIGN (_headerView, aHeaderView);
-
- if ([_headerView respondsToSelector:@selector(setTableView:)])
- [_headerView setTableView: self];
-
- [self tile]; // resizes corner and header views, then displays
-
- if (_super_view != nil)
+
+ if ([_headerView respondsToSelector:@selector(setTableView:)])
+ [_headerView setTableView: nil];
+
+ ASSIGN (_headerView, aHeaderView);
+
+ if ([_headerView respondsToSelector:@selector(setTableView:)])
+ [_headerView setTableView: self];
+
+ [self tile]; // resizes corner and header views, then displays
+
+ if (_super_view != nil)
{
- id ssv = [_super_view superview];
- if ([ssv isKindOfClass: [NSScrollView class]])
- [ssv tile]; // draws any border type over corner and header views
- }
+ id ssv = [_super_view superview];
+ if ([ssv isKindOfClass: [NSScrollView class]])
+ [ssv tile]; // draws any border type over corner and header views
+ }
}
- (NSTableHeaderView*) headerView
{
- return _headerView;
+ return _headerView;
}
- (void) setCornerView: (NSView*)aView
{
- ASSIGN (_cornerView, aView);
- [self tile]; // resizes corner and header views, then displays
- if (_super_view)
+ ASSIGN (_cornerView, aView);
+ [self tile]; // resizes corner and header views, then displays
+ if (_super_view)
{
- id ssv = [_super_view superview];
- if ([ssv isKindOfClass: [NSScrollView class]])
- [ssv tile]; // draws any border type over corner and header views
+ id ssv = [_super_view superview];
+ if ([ssv isKindOfClass: [NSScrollView class]])
+ [ssv tile]; // draws any border type over corner and header views
}
}
- (NSView*) cornerView
{
- return _cornerView;
+ return _cornerView;
}
-/*
- * Layout
+/*
+ * Layout
*/
- (NSRect) rectOfColumn: (int)columnIndex
{
- NSRect rect;
-
- if (columnIndex < 0 || columnIndex > _numberOfColumns)
+ NSRect rect;
+
+ if (columnIndex < 0 || columnIndex > _numberOfColumns)
{
- NSDebugLLog(@"NSTableView", @"Column index %d out of table in rectOfColumn", columnIndex);
- return NSZeroRect;
+ NSDebugLLog(@"NSTableView", @"Column index %d out of table in rectOfColumn", columnIndex);
+ return NSZeroRect;
}
-
- rect.origin.x = _columnOrigins[columnIndex];
- rect.origin.y = _bounds.origin.y;
- rect.size.width = [[_tableColumns objectAtIndex: columnIndex] width];
- rect.size.height = _numberOfRows * _rowHeight;
- return rect;
+
+ rect.origin.x = _columnOrigins[columnIndex];
+ rect.origin.y = _bounds.origin.y;
+ rect.size.width = [[_tableColumns objectAtIndex: columnIndex] width];
+ rect.size.height = _numberOfRows * _rowHeight;
+ return rect;
}
- (NSRect) rectOfRow: (int)rowIndex
{
- NSRect rect;
-
- if (rowIndex < 0 || rowIndex >= _numberOfRows)
+ NSRect rect;
+
+ if (rowIndex < 0 || rowIndex >= _numberOfRows)
{
- NSDebugLLog(@"NSTableView", @"Row index %d out of table in rectOfRow", rowIndex);
- return NSZeroRect;
+ NSDebugLLog(@"NSTableView", @"Row index %d out of table in rectOfRow", rowIndex);
+ return NSZeroRect;
}
-
- rect.origin.x = _bounds.origin.x;
- rect.origin.y = _bounds.origin.y + (_rowHeight * rowIndex);
- rect.size.width = _bounds.size.width;
- rect.size.height = _rowHeight;
- return rect;
+
+ rect.origin.x = _bounds.origin.x;
+ rect.origin.y = _bounds.origin.y + (_rowHeight * rowIndex);
+ rect.size.width = _bounds.size.width;
+ rect.size.height = _rowHeight;
+ return rect;
}
/** Returns the indexes of the table columns which intersects the given rect.
-
- The rect is expressed in the receiver coordinate space.
-
- Hidden table columns are never tested. */
+
+The rect is expressed in the receiver coordinate space.
+
+Hidden table columns are never tested. */
- (NSIndexSet *) columnIndexesInRect: (NSRect)aRect
{
- NSRange range = [self columnsInRect: aRect];
- NSMutableIndexSet *indexes = [NSMutableIndexSet indexSetWithIndexesInRange: range];
- int i;
-
- for (i = range.location; i < range.length; i++)
+ NSRange range = [self columnsInRect: aRect];
+ NSMutableIndexSet *indexes = [NSMutableIndexSet indexSetWithIndexesInRange: range];
+ int i;
+
+ for (i = range.location; i < range.length; i++)
{
- NSTableColumn *tableColumn = [_tableColumns objectAtIndex: i];
-
- if ([tableColumn isHidden])
- [indexes removeIndex: i];
+ NSTableColumn *tableColumn = [_tableColumns objectAtIndex: i];
+
+ if ([tableColumn isHidden])
+ [indexes removeIndex: i];
}
-
- return indexes;
-}
+
+ return indexes;
+}
/** Returns the index range of the table columns which intersects the given rect.
-
- The rect is expressed in the receiver coordinate space.
-
- The returned range can include hidden table column indexes.
-
- This method is deprecated, use -columnIndexesInRect:. */
+
+The rect is expressed in the receiver coordinate space.
+
+The returned range can include hidden table column indexes.
+
+This method is deprecated, use -columnIndexesInRect:. */
- (NSRange) columnsInRect: (NSRect)aRect
{
- NSRange range;
-
- range.location = [self columnAtPoint: aRect.origin];
- range.length = [self columnAtPoint:
- NSMakePoint (NSMaxX (aRect), _bounds.origin.y)];
- range.length -= range.location;
- range.length += 1;
- return range;
+ NSRange range;
+
+ range.location = [self columnAtPoint: aRect.origin];
+ range.length = [self columnAtPoint:
+ NSMakePoint (NSMaxX (aRect), _bounds.origin.y)];
+ range.length -= range.location;
+ range.length += 1;
+ return range;
}
- (NSRange) rowsInRect: (NSRect)aRect
{
- NSRange range;
- int lastRowInRect;
-
- range.location = [self rowAtPoint: aRect.origin];
- lastRowInRect = [self rowAtPoint:
- NSMakePoint (_bounds.origin.x, NSMaxY (aRect))];
-
- if (lastRowInRect == -1)
+ NSRange range;
+ int lastRowInRect;
+
+ range.location = [self rowAtPoint: aRect.origin];
+ lastRowInRect = [self rowAtPoint:
+ NSMakePoint (_bounds.origin.x, NSMaxY (aRect))];
+
+ if (lastRowInRect == -1)
{
- lastRowInRect = _numberOfRows - 1;
+ lastRowInRect = _numberOfRows - 1;
}
-
- range.length = lastRowInRect;
- range.length -= range.location;
- range.length += 1;
- return range;
+
+ range.length = lastRowInRect;
+ range.length -= range.location;
+ range.length += 1;
+ return range;
}
- (int) columnAtPoint: (NSPoint)aPoint
{
- if ((NSMouseInRect (aPoint, _bounds, YES)) == NO)
+ if ((NSMouseInRect (aPoint, _bounds, YES)) == NO)
{
- return -1;
+ return -1;
}
- else
+ else
{
- int i = 0;
-
- while ((i < _numberOfColumns) && (aPoint.x >= _columnOrigins[i]))
- {
- i++;
- }
- return i - 1;
+ int i = 0;
+
+ while ((i < _numberOfColumns) && (aPoint.x >= _columnOrigins[i]))
+ {
+ i++;
+ }
+ return i - 1;
}
}
- (int) rowAtPoint: (NSPoint)aPoint
{
- /* NB: Y coordinate system is flipped in NSTableView */
- if ((NSMouseInRect (aPoint, _bounds, YES)) == NO)
+ /* NB: Y coordinate system is flipped in NSTableView */
+ if ((NSMouseInRect (aPoint, _bounds, YES)) == NO)
{
- return -1;
+ return -1;
}
- else
+ else
{
- int return_value;
-
- aPoint.y -= _bounds.origin.y;
- return_value = (int) (aPoint.y / _rowHeight);
- /* This could happen if point lies on the grid line or below the last row */
- if (return_value >= _numberOfRows)
- {
- return_value = -1;
- }
- return return_value;
+ int return_value;
+
+ aPoint.y -= _bounds.origin.y;
+ return_value = (int) (aPoint.y / _rowHeight);
+ /* This could happen if point lies on the grid line or below the last row */
+ if (return_value >= _numberOfRows)
+ {
+ return_value = -1;
+ }
+ return return_value;
}
}
-- (NSRect) frameOfCellAtColumn: (int)columnIndex
- row: (int)rowIndex
+- (NSRect) frameOfCellAtColumn: (int)columnIndex
+ row: (int)rowIndex
{
- NSRect frameRect;
-
- if ((columnIndex < 0)
- || (rowIndex < 0)
- || (columnIndex > (_numberOfColumns - 1))
- || (rowIndex > (_numberOfRows - 1)))
- return NSZeroRect;
-
- frameRect.origin.y = _bounds.origin.y + (rowIndex * _rowHeight);
- frameRect.origin.y += _intercellSpacing.height / 2;
- frameRect.size.height = _rowHeight - _intercellSpacing.height;
-
- frameRect.origin.x = _columnOrigins[columnIndex];
- frameRect.origin.x += _intercellSpacing.width / 2;
- frameRect.size.width = [[_tableColumns objectAtIndex: columnIndex] width];
- frameRect.size.width -= _intercellSpacing.width;
-
- // We add some space to separate the cell from the grid
- if (_drawsGrid)
+ NSRect frameRect;
+
+ if ((columnIndex < 0)
+ || (rowIndex < 0)
+ || (columnIndex > (_numberOfColumns - 1))
+ || (rowIndex > (_numberOfRows - 1)))
+ return NSZeroRect;
+
+ frameRect.origin.y = _bounds.origin.y + (rowIndex * _rowHeight);
+ frameRect.origin.y += _intercellSpacing.height / 2;
+ frameRect.size.height = _rowHeight - _intercellSpacing.height;
+
+ frameRect.origin.x = _columnOrigins[columnIndex];
+ frameRect.origin.x += _intercellSpacing.width / 2;
+ frameRect.size.width = [[_tableColumns objectAtIndex: columnIndex] width];
+ frameRect.size.width -= _intercellSpacing.width;
+
+ // We add some space to separate the cell from the grid
+ if (_drawsGrid)
{
- frameRect.size.width -= 4;
- frameRect.origin.x += 2;
+ frameRect.size.width -= 4;
+ frameRect.origin.x += 2;
}
-
- // Safety check
- if (frameRect.size.width < 0)
- frameRect.size.width = 0;
-
- return frameRect;
+
+ // Safety check
+ if (frameRect.size.width < 0)
+ frameRect.size.width = 0;
+
+ return frameRect;
}
- (void) setAutoresizesAllColumnsToFit: (BOOL)flag
{
- _autoresizesAllColumnsToFit = flag;
+ _autoresizesAllColumnsToFit = flag;
}
- (BOOL) autoresizesAllColumnsToFit
{
- return _autoresizesAllColumnsToFit;
+ return _autoresizesAllColumnsToFit;
}
- (NSTableViewColumnAutoresizingStyle) columnAutoresizingStyle
{
- // FIXME
- return NSTableViewNoColumnAutoresizing;
+ // FIXME
+ return NSTableViewNoColumnAutoresizing;
}
- (void) setColumnAutoresizingStyle: (NSTableViewColumnAutoresizingStyle)style
{
- // FIXME
+ // FIXME
}
- (void) sizeLastColumnToFit
{
- if ((_super_view != nil) && (_numberOfColumns > 0))
+ if ((_super_view != nil) && (_numberOfColumns > 0))
{
- float excess_width;
- float last_column_width;
- NSTableColumn *lastColumn;
-
- lastColumn = [_tableColumns objectAtIndex: (_numberOfColumns - 1)];
- if ([lastColumn isResizable] == NO)
- return;
- excess_width = NSMaxX([self convertRect: [_super_view bounds]
- fromView: _super_view]) - NSMaxX(_bounds);
- last_column_width = [lastColumn width] + excess_width;
- // This will automatically retile the table
- [lastColumn setWidth: last_column_width];
+ float excess_width;
+ float last_column_width;
+ NSTableColumn *lastColumn;
+
+ lastColumn = [_tableColumns objectAtIndex: (_numberOfColumns - 1)];
+ if ([lastColumn isResizable] == NO)
+ return;
+ excess_width = NSMaxX([self convertRect: [_super_view bounds]
+ fromView: _super_view]) - NSMaxX(_bounds);
+ last_column_width = [lastColumn width] + excess_width;
+ // This will automatically retile the table
+ [lastColumn setWidth: last_column_width];
}
}
- (void) setFrame: (NSRect)frameRect
{
- NSRect tmpRect = frameRect;
-
- if ([_super_view respondsToSelector: @selector(documentVisibleRect)])
+ NSRect tmpRect = frameRect;
+
+ if ([_super_view respondsToSelector: @selector(documentVisibleRect)])
{
- float rowsHeight = ((_numberOfRows * _rowHeight) + 1);
- NSRect docRect = [(NSClipView *)_super_view documentVisibleRect];
-
- if (rowsHeight < docRect.size.height)
+ float rowsHeight = ((_numberOfRows * _rowHeight) + 1);
+ NSRect docRect = [(NSClipView *)_super_view documentVisibleRect];
+
+ if (rowsHeight < docRect.size.height)
+ {
+ tmpRect.size.height = docRect.size.height;
+ }
+ else
{
- tmpRect.size.height = docRect.size.height;
+ tmpRect.size.height = rowsHeight;
}
- else
- {
- tmpRect.size.height = rowsHeight;
- }
- // TODO width?
+ // TODO width?
}
- [super setFrame: tmpRect];
+ [super setFrame: tmpRect];
}
- (void) setFrameSize: (NSSize)frameSize
{
- NSSize tmpSize = frameSize;
-
- if ([_super_view respondsToSelector: @selector(documentVisibleRect)])
+ NSSize tmpSize = frameSize;
+
+ if ([_super_view respondsToSelector: @selector(documentVisibleRect)])
{
- float rowsHeight = ((_numberOfRows * _rowHeight) + 1);
- NSRect docRect = [(NSClipView *)_super_view documentVisibleRect];
-
- if (rowsHeight < docRect.size.height)
+ float rowsHeight = ((_numberOfRows * _rowHeight) + 1);
+ NSRect docRect = [(NSClipView *)_super_view documentVisibleRect];
+
+ if (rowsHeight < docRect.size.height)
+ {
+ tmpSize.height = docRect.size.height;
+ }
+ else
{
- tmpSize.height = docRect.size.height;
+ tmpSize.height = rowsHeight;
}
- else
- {
- tmpSize.height = rowsHeight;
- }
- // TODO width?
+ // TODO width?
}
- [super setFrameSize: tmpSize];
+ [super setFrameSize: tmpSize];
}
- (void) viewWillMoveToSuperview:(NSView *)newSuper
{
- [super viewWillMoveToSuperview: newSuper];
- /* need to potentially enlarge to fill the documentRect of the clip view */
- [self setFrame: _frame];
+ [super viewWillMoveToSuperview: newSuper];
+ /* need to potentially enlarge to fill the documentRect of the clip view */
+ [self setFrame: _frame];
}
- (void) sizeToFit
{
- NSTableColumn *tb;
- int i, j;
- float remainingWidth;
- columnSorting *columnInfo;
- float *currentWidth;
- float *maxWidth;
- float *minWidth;
- BOOL *isResizable;
- int numberOfCurrentColumns = 0;
- float previousPoint;
- float nextPoint;
- float toAddToCurrentColumns;
-
- if ((_super_view == nil) || (_numberOfColumns == 0))
- return;
-
- columnInfo = NSZoneMalloc(NSDefaultMallocZone(),
- sizeof(columnSorting) * 2
- * _numberOfColumns);
- currentWidth = NSZoneMalloc(NSDefaultMallocZone(),
- sizeof(float) * _numberOfColumns);
- maxWidth = NSZoneMalloc(NSDefaultMallocZone(),
- sizeof(float) * _numberOfColumns);
- minWidth = NSZoneMalloc(NSDefaultMallocZone(),
- sizeof(float) * _numberOfColumns);
- isResizable = NSZoneMalloc(NSDefaultMallocZone(),
- sizeof(BOOL) * _numberOfColumns);
-
- remainingWidth = NSMaxX([self convertRect: [_super_view bounds]
- fromView: _super_view]);
-
- /*
- * We store the minWidth and the maxWidth of every column
- * because we'll use those values *a lot*
- * At the same time we set every column to its mininum width
- */
- for (i = 0; i < _numberOfColumns; i++)
+ NSTableColumn *tb;
+ int i, j;
+ float remainingWidth;
+ columnSorting *columnInfo;
+ float *currentWidth;
+ float *maxWidth;
+ float *minWidth;
+ BOOL *isResizable;
+ int numberOfCurrentColumns = 0;
+ float previousPoint;
+ float nextPoint;
+ float toAddToCurrentColumns;
+
+ if ((_super_view == nil) || (_numberOfColumns == 0))
+ return;
+
+ columnInfo = NSZoneMalloc(NSDefaultMallocZone(),
+ sizeof(columnSorting) * 2
+ * _numberOfColumns);
+ currentWidth = NSZoneMalloc(NSDefaultMallocZone(),
+ sizeof(float) * _numberOfColumns);
+ maxWidth = NSZoneMalloc(NSDefaultMallocZone(),
+ sizeof(float) * _numberOfColumns);
+ minWidth = NSZoneMalloc(NSDefaultMallocZone(),
+ sizeof(float) * _numberOfColumns);
+ isResizable = NSZoneMalloc(NSDefaultMallocZone(),
+ sizeof(BOOL) * _numberOfColumns);
+
+ remainingWidth = NSMaxX([self convertRect: [_super_view bounds]
+ fromView: _super_view]);
+
+ /*
+ * We store the minWidth and the maxWidth of every column
+ * because we'll use those values *a lot*
+ * At the same time we set every column to its mininum width
+ */
+ for (i = 0; i < _numberOfColumns; i++)
{
- tb = [_tableColumns objectAtIndex: i];
- isResizable[i] = [tb isResizable];
- if (isResizable[i] == YES)
- {
- minWidth[i] = [tb minWidth];
- maxWidth[i] = [tb maxWidth];
-
- if (minWidth[i] < 0)
- minWidth[i] = 0;
- if (minWidth[i] > maxWidth[i])
- {
- minWidth[i] = [tb width];
- maxWidth[i] = minWidth[i];
- }
- columnInfo[i * 2].width = minWidth[i];
- columnInfo[i * 2].isMax = 0;
- currentWidth[i] = minWidth[i];
- remainingWidth -= minWidth[i];
-
- columnInfo[i * 2 + 1].width = maxWidth[i];
- columnInfo[i * 2 + 1].isMax = 1;
- }
- else
- {
- minWidth[i] = [tb width];
- columnInfo[i * 2].width = minWidth[i];
- columnInfo[i * 2].isMax = 0;
- currentWidth[i] = minWidth[i];
- remainingWidth -= minWidth[i];
-
- maxWidth[i] = minWidth[i];
- columnInfo[i * 2 + 1].width = maxWidth[i];
- columnInfo[i * 2 + 1].isMax = 1;
- }
- }
-
- // sort the info we have
- quick_sort_internal(columnInfo, 0, 2 * _numberOfColumns - 1);
-
- previousPoint = columnInfo[0].width;
- numberOfCurrentColumns = 1;
-
- if (remainingWidth >= 0.)
+ tb = [_tableColumns objectAtIndex: i];
+ isResizable[i] = [tb isResizable];
+ if (isResizable[i] == YES)
+ {
+ minWidth[i] = [tb minWidth];
+ maxWidth[i] = [tb maxWidth];
+
+ if (minWidth[i] < 0)
+ minWidth[i] = 0;
+ if (minWidth[i] > maxWidth[i])
+ {
+ minWidth[i] = [tb width];
+ maxWidth[i] = minWidth[i];
+ }
+ columnInfo[i * 2].width = minWidth[i];
+ columnInfo[i * 2].isMax = 0;
+ currentWidth[i] = minWidth[i];
+ remainingWidth -= minWidth[i];
+
+ columnInfo[i * 2 + 1].width = maxWidth[i];
+ columnInfo[i * 2 + 1].isMax = 1;
+ }
+ else
+ {
+ minWidth[i] = [tb width];
+ columnInfo[i * 2].width = minWidth[i];
+ columnInfo[i * 2].isMax = 0;
+ currentWidth[i] = minWidth[i];
+ remainingWidth -= minWidth[i];
+
+ maxWidth[i] = minWidth[i];
+ columnInfo[i * 2 + 1].width = maxWidth[i];
+ columnInfo[i * 2 + 1].isMax = 1;
+ }
+ }
+
+ // sort the info we have
+ quick_sort_internal(columnInfo, 0, 2 * _numberOfColumns - 1);
+
+ previousPoint = columnInfo[0].width;
+ numberOfCurrentColumns = 1;
+
+ if (remainingWidth >= 0.)
{
- for (i = 1; i < 2 * _numberOfColumns; i++)
- {
- nextPoint = columnInfo[i].width;
-
- if (numberOfCurrentColumns > 0 &&
- (nextPoint - previousPoint) > 0.)
- {
- int verification = 0;
-
- if ((nextPoint - previousPoint) * numberOfCurrentColumns
- <= remainingWidth)
- {
- toAddToCurrentColumns = nextPoint - previousPoint;
- remainingWidth -=
- (nextPoint - previousPoint) * numberOfCurrentColumns;
-
- for (j = 0; j < _numberOfColumns; j++)
- {
- if (minWidth[j] <= previousPoint
- && maxWidth[j] >= nextPoint)
- {
- verification++;
- currentWidth[j] += toAddToCurrentColumns;
- }
- }
- if (verification != numberOfCurrentColumns)
- {
- NSLog(@"[NSTableView sizeToFit]: unexpected error");
- }
- }
- else
- {
- int remainingInt = floor(remainingWidth);
- int quotient = remainingInt / numberOfCurrentColumns;
- int remainder = remainingInt - quotient * numberOfCurrentColumns;
- int oldRemainder = remainder;
-
- for (j = _numberOfColumns - 1; j >= 0; j--)
- {
- if (minWidth[j] <= previousPoint
- && maxWidth[j] >= nextPoint)
- {
- currentWidth[j] += quotient;
- if (remainder > 0
- && maxWidth[j] >= currentWidth[j] + 1)
- {
- remainder--;
- currentWidth[j]++;
- }
- }
- }
- while (oldRemainder > remainder && remainder > 0)
- {
- oldRemainder = remainder;
- for (j = 0; j < _numberOfColumns; j++)
- {
- if (minWidth[j] <= previousPoint
- && maxWidth[j] >= nextPoint)
- {
- if (remainder > 0
- && maxWidth[j] >= currentWidth[j] + 1)
- {
- remainder--;
- currentWidth[j]++;
- }
- }
-
- }
- }
- if (remainder > 0)
- NSLog(@"There is still free space to fill.\
- However it seems better to use integer width for the columns");
- else
- remainingWidth = 0.;
- }
-
-
- }
- else if (numberOfCurrentColumns < 0)
- {
- NSLog(@"[NSTableView sizeToFit]: unexpected error");
- }
-
- if (columnInfo[i].isMax)
- numberOfCurrentColumns--;
- else
- numberOfCurrentColumns++;
- previousPoint = nextPoint;
-
- if (remainingWidth == 0.)
- {
- break;
- }
- }
+ for (i = 1; i < 2 * _numberOfColumns; i++)
+ {
+ nextPoint = columnInfo[i].width;
+
+ if (numberOfCurrentColumns > 0 &&
+ (nextPoint - previousPoint) > 0.)
+ {
+ int verification = 0;
+
+ if ((nextPoint - previousPoint) * numberOfCurrentColumns
+ <= remainingWidth)
+ {
+ toAddToCurrentColumns = nextPoint - previousPoint;
+ remainingWidth -=
+ (nextPoint - previousPoint) * numberOfCurrentColumns;
+
+ for (j = 0; j < _numberOfColumns; j++)
+ {
+ if (minWidth[j] <= previousPoint
+ && maxWidth[j] >= nextPoint)
+ {
+ verification++;
+ currentWidth[j] += toAddToCurrentColumns;
+ }
+ }
+ if (verification != numberOfCurrentColumns)
+ {
+ NSLog(@"[NSTableView sizeToFit]: unexpected error");
+ }
+ }
+ else
+ {
+ int remainingInt = floor(remainingWidth);
+ int quotient = remainingInt / numberOfCurrentColumns;
+ int remainder = remainingInt - quotient * numberOfCurrentColumns;
+ int oldRemainder = remainder;
+
+ for (j = _numberOfColumns - 1; j >= 0; j--)
+ {
+ if (minWidth[j] <= previousPoint
+ && maxWidth[j] >= nextPoint)
+ {
+ currentWidth[j] += quotient;
+ if (remainder > 0
+ && maxWidth[j] >= currentWidth[j] + 1)
+ {
+ remainder--;
+ currentWidth[j]++;
+ }
+ }
+ }
+ while (oldRemainder > remainder && remainder > 0)
+ {
+ oldRemainder = remainder;
+ for (j = 0; j < _numberOfColumns; j++)
+ {
+ if (minWidth[j] <= previousPoint
+ && maxWidth[j] >= nextPoint)
+ {
+ if (remainder > 0
+ && maxWidth[j] >= currentWidth[j] + 1)
+ {
+ remainder--;
+ currentWidth[j]++;
+ }
+ }
+
+ }
+ }
+ if (remainder > 0)
+ NSLog(@"There is still free space to fill.\
+ However it seems better to use integer width for the columns");
+ else
+ remainingWidth = 0.;
+ }
+
+
+ }
+ else if (numberOfCurrentColumns < 0)
+ {
+ NSLog(@"[NSTableView sizeToFit]: unexpected error");
+ }
+
+ if (columnInfo[i].isMax)
+ numberOfCurrentColumns--;
+ else
+ numberOfCurrentColumns++;
+ previousPoint = nextPoint;
+
+ if (remainingWidth == 0.)
+ {
+ break;
+ }
+ }
}
-
- _tilingDisabled = YES;
-
- remainingWidth = 0.;
- for (i = 0; i < _numberOfColumns; i++)
+
+ _tilingDisabled = YES;
+
+ remainingWidth = 0.;
+ for (i = 0; i < _numberOfColumns; i++)
{
- if (isResizable[i] == YES)
- {
- tb = [_tableColumns objectAtIndex: i];
- remainingWidth += currentWidth[i];
- [tb setWidth: currentWidth[i]];
- }
- else
- {
- remainingWidth += minWidth[i];
- }
+ if (isResizable[i] == YES)
+ {
+ tb = [_tableColumns objectAtIndex: i];
+ remainingWidth += currentWidth[i];
+ [tb setWidth: currentWidth[i]];
+ }
+ else
+ {
+ remainingWidth += minWidth[i];
+ }
}
-
- _tilingDisabled = NO;
- NSZoneFree(NSDefaultMallocZone(), columnInfo);
- NSZoneFree(NSDefaultMallocZone(), currentWidth);
- NSZoneFree(NSDefaultMallocZone(), maxWidth);
- NSZoneFree(NSDefaultMallocZone(), minWidth);
- NSZoneFree(NSDefaultMallocZone(), isResizable);
-
- [self tile];
+
+ _tilingDisabled = NO;
+ NSZoneFree(NSDefaultMallocZone(), columnInfo);
+ NSZoneFree(NSDefaultMallocZone(), currentWidth);
+ NSZoneFree(NSDefaultMallocZone(), maxWidth);
+ NSZoneFree(NSDefaultMallocZone(), minWidth);
+ NSZoneFree(NSDefaultMallocZone(), isResizable);
+
+ [self tile];
}
/*
- - (void) sizeToFit
- {
- NSCell *cell;
- NSEnumerator *enumerator;
- NSTableColumn *tb;
- float table_width;
- float width;
- float candidate_width;
- int row;
-
- _tilingDisabled = YES;
-
- // First Step
- // Resize Each Column to its Minimum Width
- table_width = _bounds.origin.x;
- enumerator = [_tableColumns objectEnumerator];
- while ((tb = [enumerator nextObject]) != nil)
- {
- // Compute min width of column
- width = [[tb headerCell] cellSize].width;
- for (row = 0; row < _numberOfRows; row++)
- {
- cell = [self _dataCellForTableColumn: tb row: row];
- [cell setObjectValue: [_dataSource tableView: self
- objectValueForTableColumn: tb
- row: row]];
- [self _willDisplayCell: cell
- forTableColumn: tb
- row: row];
- candidate_width = [cell cellSize].width;
-
- if (_drawsGrid)
- candidate_width += 4;
-
- if (candidate_width > width)
- {
- width = candidate_width;
- }
- }
- width += _intercellSpacing.width;
- [tb setWidth: width];
- // It is necessary to ask the column for the width, since it might have
- // been changed by the column to constrain it to a min or max width
- table_width += [tb width];
- }
-
- // Second Step
- // If superview (clipview) is bigger than that, divide remaining space
- // between all columns
- if ((_super_view != nil) && (_numberOfColumns > 0))
- {
- float excess_width;
-
- excess_width = NSMaxX ([self convertRect: [_super_view bounds]
- fromView: _super_view]);
- excess_width -= table_width;
- // Since we resized each column at its minimum width,
- // it's useless to try shrinking more: we can't
- if (excess_width <= 0)
- {
- _tilingDisabled = NO;
- [self tile];
- NSLog(@"exiting sizeToFit");
- return;
- }
- excess_width = excess_width / _numberOfColumns;
-
- enumerator = [_tableColumns objectEnumerator];
- while ((tb = [enumerator nextObject]) != nil)
- {
- [tb setWidth: ([tb width] + excess_width)];
- }
- }
-
- _tilingDisabled = NO;
- [self tile];
- NSLog(@"exiting sizeToFit");
- }
- */
+- (void) sizeToFit
+{
+ NSCell *cell;
+ NSEnumerator *enumerator;
+ NSTableColumn *tb;
+ float table_width;
+ float width;
+ float candidate_width;
+ int row;
+
+ _tilingDisabled = YES;
+
+ // First Step
+ // Resize Each Column to its Minimum Width
+ table_width = _bounds.origin.x;
+ enumerator = [_tableColumns objectEnumerator];
+ while ((tb = [enumerator nextObject]) != nil)
+ {
+ // Compute min width of column
+ width = [[tb headerCell] cellSize].width;
+ for (row = 0; row < _numberOfRows; row++)
+ {
+ cell = [self _dataCellForTableColumn: tb row: row];
+ [cell setObjectValue: [_dataSource tableView: self
+ objectValueForTableColumn: tb
+ row: row]];
+ [self _willDisplayCell: cell
+ forTableColumn: tb
+ row: row];
+ candidate_width = [cell cellSize].width;
+
+ if (_drawsGrid)
+ candidate_width += 4;
+
+ if (candidate_width > width)
+ {
+ width = candidate_width;
+ }
+ }
+ width += _intercellSpacing.width;
+ [tb setWidth: width];
+ // It is necessary to ask the column for the width, since it might have
+ // been changed by the column to constrain it to a min or max width
+ table_width += [tb width];
+ }
+
+ // Second Step
+ // If superview (clipview) is bigger than that, divide remaining space
+ // between all columns
+ if ((_super_view != nil) && (_numberOfColumns > 0))
+ {
+ float excess_width;
+
+ excess_width = NSMaxX ([self convertRect: [_super_view bounds]
+ fromView: _super_view]);
+ excess_width -= table_width;
+ // Since we resized each column at its minimum width,
+ // it's useless to try shrinking more: we can't
+ if (excess_width <= 0)
+ {
+ _tilingDisabled = NO;
+ [self tile];
+ NSLog(@"exiting sizeToFit");
+ return;
+ }
+ excess_width = excess_width / _numberOfColumns;
+
+ enumerator = [_tableColumns objectEnumerator];
+ while ((tb = [enumerator nextObject]) != nil)
+ {
+ [tb setWidth: ([tb width] + excess_width)];
+ }
+ }
+
+ _tilingDisabled = NO;
+ [self tile];
+ NSLog(@"exiting sizeToFit");
+}
+*/
- (void) noteNumberOfRowsChanged
{
- NSRect newFrame;
-
- _numberOfRows = [self _numRows];
-
- /* If we are selecting rows, we have to check that we have no
+ NSRect newFrame;
+
+ _numberOfRows = [self _numRows];
+
+ /* If we are selecting rows, we have to check that we have no
selected rows below the new end of the table */
- if (!_selectingColumns)
+ if (!_selectingColumns)
{
- NSUInteger row = [_selectedRows lastIndex];
-
- if (row == NSNotFound)
+ NSUInteger row = [_selectedRows lastIndex];
+
+ if (row == NSNotFound)
{
- if (!_allowsEmptySelection)
+ if (!_allowsEmptySelection)
{
- /* We shouldn't allow empty selection - try
+ /* We shouldn't allow empty selection - try
selecting the last row */
- NSInteger lastRow = _numberOfRows - 1;
-
- if (lastRow > -1)
+ NSInteger lastRow = _numberOfRows - 1;
+
+ if (lastRow > -1)
{
- [self _postSelectionIsChangingNotification];
- [_selectedRows addIndex: lastRow];
- _selectedRow = lastRow;
- [self _postSelectionDidChangeNotification];
+ [self _postSelectionIsChangingNotification];
+ [_selectedRows addIndex: lastRow];
+ _selectedRow = lastRow;
+ [self _postSelectionDidChangeNotification];
}
- else
+ else
{
- /* problem - there are no rows at all */
- _selectedRow = -1;
+ /* problem - there are no rows at all */
+ _selectedRow = -1;
}
}
}
- /* Check that all selected rows are in the new range of rows */
- else if (row >= _numberOfRows)
+ /* Check that all selected rows are in the new range of rows */
+ else if (row >= _numberOfRows)
{
- [_selectedRows removeIndexesInRange:
+ [_selectedRows removeIndexesInRange:
NSMakeRange(_numberOfRows, row + 1 - _numberOfRows)];
- if (_selectedRow >= _numberOfRows)
+ if (_selectedRow >= _numberOfRows)
{
- row = [_selectedRows lastIndex];
- [self _postSelectionIsChangingNotification];
-
- if (row != NSNotFound)
+ row = [_selectedRows lastIndex];
+ [self _postSelectionIsChangingNotification];
+
+ if (row != NSNotFound)
{
- _selectedRow = row;
+ _selectedRow = row;
}
- else
+ else
{
- /* Argh - all selected rows were outside the table */
- if (_allowsEmptySelection)
+ /* Argh - all selected rows were outside the table */
+ if (_allowsEmptySelection)
{
- _selectedRow = -1;
+ _selectedRow = -1;
}
- else
+ else
{
- /* We shouldn't allow empty selection - try
+ /* We shouldn't allow empty selection - try
selecting the last row */
- int lastRow = _numberOfRows - 1;
-
- if (lastRow > -1)
+ int lastRow = _numberOfRows - 1;
+
+ if (lastRow > -1)
{
- [_selectedRows addIndex: lastRow];
- _selectedRow = lastRow;
+ [_selectedRows addIndex: lastRow];
+ _selectedRow = lastRow;
}
- else
+ else
{
- /* problem - there are no rows at all */
- _selectedRow = -1;
+ /* problem - there are no rows at all */
+ _selectedRow = -1;
}
}
}
- [self _postSelectionDidChangeNotification];
+ [self _postSelectionDidChangeNotification];
}
}
}
-
- newFrame = _frame;
- newFrame.size.height = (_numberOfRows * _rowHeight) + 1;
- if (NO == NSEqualRects(newFrame, NSUnionRect(newFrame, _frame)))
+
+ newFrame = _frame;
+ newFrame.size.height = (_numberOfRows * _rowHeight) + 1;
+ if (NO == NSEqualRects(newFrame, NSUnionRect(newFrame, _frame)))
{
- [_super_view setNeedsDisplayInRect: _frame];
+ [_super_view setNeedsDisplayInRect: _frame];
}
- [self setFrame: newFrame];
-
- /* If we are shorter in height than the enclosing clipview, we
+ [self setFrame: newFrame];
+
+ /* If we are shorter in height than the enclosing clipview, we
should redraw us now. */
- if (_super_view != nil)
+ if (_super_view != nil)
{
- NSRect superviewBounds; // Get this *after* [self setFrame:]
- superviewBounds = [_super_view bounds];
- if ((superviewBounds.origin.x <= _frame.origin.x)
- && (NSMaxY(superviewBounds) >= NSMaxY(_frame)))
+ NSRect superviewBounds; // Get this *after* [self setFrame:]
+ superviewBounds = [_super_view bounds];
+ if ((superviewBounds.origin.x <= _frame.origin.x)
+ && (NSMaxY(superviewBounds) >= NSMaxY(_frame)))
{
- [self setNeedsDisplay: YES];
+ [self setNeedsDisplay: YES];
}
}
}
- (void) tile
{
- float table_width = 0;
- float table_height;
-
- if (_tilingDisabled == YES)
- return;
-
- if (_numberOfColumns > 0)
+ float table_width = 0;
+ float table_height;
+
+ if (_tilingDisabled == YES)
+ return;
+
+ if (_numberOfColumns > 0)
{
- int i;
- float width;
-
- _columnOrigins[0] = _bounds.origin.x;
- width = [[_tableColumns objectAtIndex: 0] width];
- table_width += width;
- for (i = 1; i < _numberOfColumns; i++)
- {
- _columnOrigins[i] = _columnOrigins[i - 1] + width;
- width = [[_tableColumns objectAtIndex: i] width];
- table_width += width;
- }
+ int i;
+ float width;
+
+ _columnOrigins[0] = _bounds.origin.x;
+ width = [[_tableColumns objectAtIndex: 0] width];
+ table_width += width;
+ for (i = 1; i < _numberOfColumns; i++)
+ {
+ _columnOrigins[i] = _columnOrigins[i - 1] + width;
+ width = [[_tableColumns objectAtIndex: i] width];
+ table_width += width;
+ }
}
- /* + 1 for the last grid line */
- table_height = (_numberOfRows * _rowHeight) + 1;
- [self setFrameSize: NSMakeSize (table_width, table_height)];
- [self setNeedsDisplay: YES];
-
- if (_headerView != nil)
+ /* + 1 for the last grid line */
+ table_height = (_numberOfRows * _rowHeight) + 1;
+ [self setFrameSize: NSMakeSize (table_width, table_height)];
+ [self setNeedsDisplay: YES];
+
+ if (_headerView != nil)
{
- [_headerView setFrameSize:
- NSMakeSize (_frame.size.width,
- [_headerView frame].size.height)];
- [_cornerView setFrameSize:
- NSMakeSize ([NSScroller scrollerWidth] + 1,
- [_headerView frame].size.height)];
- [_headerView setNeedsDisplay: YES];
- [_cornerView setNeedsDisplay: YES];
- }
+ [_headerView setFrameSize:
+ NSMakeSize (_frame.size.width,
+ [_headerView frame].size.height)];
+ [_cornerView setFrameSize:
+ NSMakeSize ([NSScroller scrollerWidth] + 1,
+ [_headerView frame].size.height)];
+ [_headerView setNeedsDisplay: YES];
+ [_cornerView setNeedsDisplay: YES];
+ }
}
-/*
- * Drawing
+/*
+ * Drawing
*/
- (void) drawRow: (int)rowIndex clipRect: (NSRect)clipRect
{
- [[GSTheme theme] drawTableViewRow: rowIndex
- clipRect: clipRect
- inView: self];
+ [[GSTheme theme] drawTableViewRow: rowIndex
+ clipRect: clipRect
+ inView: self];
}
- (void) noteHeightOfRowsWithIndexesChanged: (NSIndexSet*)indexes
{
- // FIXME
+ // FIXME
}
- (void) drawGridInClipRect: (NSRect)aRect
{
- [[GSTheme theme] drawTableViewGridInClipRect: aRect
- inView: self];
+ [[GSTheme theme] drawTableViewGridInClipRect: aRect
+ inView: self];
}
- (void) highlightSelectionInClipRect: (NSRect)clipRect
{
- [[GSTheme theme] highlightTableViewSelectionInClipRect: clipRect
- inView: self
- selectingColumns: _selectingColumns];
+ [[GSTheme theme] highlightTableViewSelectionInClipRect: clipRect
+ inView: self
+ selectingColumns: _selectingColumns];
}
- (void) drawBackgroundInClipRect: (NSRect)clipRect
{
- [[GSTheme theme] drawTableViewBackgroundInClipRect: clipRect
- inView: self
- withBackgroundColor: _backgroundColor];
+ [[GSTheme theme] drawTableViewBackgroundInClipRect: clipRect
+ inView: self
+ withBackgroundColor: _backgroundColor];
}
- (void) drawRect: (NSRect)aRect
{
- [[GSTheme theme] drawTableViewRect: aRect
- inView: self];
+ [[GSTheme theme] drawTableViewRect: aRect
+ inView: self];
}
- (BOOL) isOpaque
{
- return YES;
+ return YES;
}
-/*
- * Scrolling
+/*
+ * Scrolling
*/
- (void) scrollRowToVisible: (int)rowIndex
{
- if (_super_view != nil)
+ if (_super_view != nil)
{
- NSRect rowRect = [self rectOfRow: rowIndex];
- NSRect visibleRect = [self visibleRect];
-
- // If the row is over the top, or it is partially visible
- // on top,
- if ((rowRect.origin.y < visibleRect.origin.y))
- {
- // Then make it visible on top
- NSPoint newOrigin;
-
- newOrigin.x = visibleRect.origin.x;
- newOrigin.y = rowRect.origin.y;
- newOrigin = [self convertPoint: newOrigin toView: _super_view];
- [(NSClipView *)_super_view scrollToPoint: newOrigin];
- return;
- }
- // If the row is under the bottom, or it is partially visible on
- // the bottom,
- if (NSMaxY (rowRect) > NSMaxY (visibleRect))
- {
- // Then make it visible on bottom
- NSPoint newOrigin;
-
- newOrigin.x = visibleRect.origin.x;
- newOrigin.y = visibleRect.origin.y;
- newOrigin.y += NSMaxY (rowRect) - NSMaxY (visibleRect);
- newOrigin = [self convertPoint: newOrigin toView: _super_view];
- [(NSClipView *)_super_view scrollToPoint: newOrigin];
- return;
- }
+ NSRect rowRect = [self rectOfRow: rowIndex];
+ NSRect visibleRect = [self visibleRect];
+
+ // If the row is over the top, or it is partially visible
+ // on top,
+ if ((rowRect.origin.y < visibleRect.origin.y))
+ {
+ // Then make it visible on top
+ NSPoint newOrigin;
+
+ newOrigin.x = visibleRect.origin.x;
+ newOrigin.y = rowRect.origin.y;
+ newOrigin = [self convertPoint: newOrigin toView: _super_view];
+ [(NSClipView *)_super_view scrollToPoint: newOrigin];
+ return;
+ }
+ // If the row is under the bottom, or it is partially visible on
+ // the bottom,
+ if (NSMaxY (rowRect) > NSMaxY (visibleRect))
+ {
+ // Then make it visible on bottom
+ NSPoint newOrigin;
+
+ newOrigin.x = visibleRect.origin.x;
+ newOrigin.y = visibleRect.origin.y;
+ newOrigin.y += NSMaxY (rowRect) - NSMaxY (visibleRect);
+ newOrigin = [self convertPoint: newOrigin toView: _super_view];
+ [(NSClipView *)_super_view scrollToPoint: newOrigin];
+ return;
+ }
}
}
- (void) scrollColumnToVisible: (int)columnIndex
{
- if (_super_view != nil)
+ if (_super_view != nil)
{
- NSRect columnRect = [self rectOfColumn: columnIndex];
- NSRect visibleRect = [self visibleRect];
- float diff;
-
- // If the row is out on the left, or it is partially visible
- // on the left
- if ((columnRect.origin.x < visibleRect.origin.x))
- {
- // Then make it visible on the left
- NSPoint newOrigin;
-
- newOrigin.x = columnRect.origin.x;
- newOrigin.y = visibleRect.origin.y;
- newOrigin = [self convertPoint: newOrigin toView: _super_view];
- [(NSClipView *)_super_view scrollToPoint: newOrigin];
- return;
- }
- diff = NSMaxX (columnRect) - NSMaxX (visibleRect);
- // If the row is out on the right, or it is partially visible on
- // the right,
- if (diff > 0)
- {
- // Then make it visible on the right
- NSPoint newOrigin;
-
- newOrigin.x = visibleRect.origin.x;
- newOrigin.y = visibleRect.origin.y;
- newOrigin.x += diff;
- newOrigin = [self convertPoint: newOrigin toView: _super_view];
- [(NSClipView *)_super_view scrollToPoint: newOrigin];
- return;
- }
+ NSRect columnRect = [self rectOfColumn: columnIndex];
+ NSRect visibleRect = [self visibleRect];
+ float diff;
+
+ // If the row is out on the left, or it is partially visible
+ // on the left
+ if ((columnRect.origin.x < visibleRect.origin.x))
+ {
+ // Then make it visible on the left
+ NSPoint newOrigin;
+
+ newOrigin.x = columnRect.origin.x;
+ newOrigin.y = visibleRect.origin.y;
+ newOrigin = [self convertPoint: newOrigin toView: _super_view];
+ [(NSClipView *)_super_view scrollToPoint: newOrigin];
+ return;
+ }
+ diff = NSMaxX (columnRect) - NSMaxX (visibleRect);
+ // If the row is out on the right, or it is partially visible on
+ // the right,
+ if (diff > 0)
+ {
+ // Then make it visible on the right
+ NSPoint newOrigin;
+
+ newOrigin.x = visibleRect.origin.x;
+ newOrigin.y = visibleRect.origin.y;
+ newOrigin.x += diff;
+ newOrigin = [self convertPoint: newOrigin toView: _super_view];
+ [(NSClipView *)_super_view scrollToPoint: newOrigin];
+ return;
+ }
}
}
-/*
- * Text delegate methods
+/*
+ * Text delegate methods
*/
- (void) textDidBeginEditing: (NSNotification *)aNotification
{
- [super textDidBeginEditing: aNotification];
+ [super textDidBeginEditing: aNotification];
}
- (void) textDidChange: (NSNotification *)aNotification
{
- // MacOS-X asks us to inform the cell if possible.
- if ((_editedCell != nil) && [_editedCell respondsToSelector:
- @selector(textDidChange:)])
- [_editedCell textDidChange: aNotification];
-
- [super textDidChange: aNotification];
+ // MacOS-X asks us to inform the cell if possible.
+ if ((_editedCell != nil) && [_editedCell respondsToSelector:
+ @selector(textDidChange:)])
+ [_editedCell textDidChange: aNotification];
+
+ [super textDidChange: aNotification];
}
- (void) textDidEndEditing: (NSNotification *)aNotification
{
- id textMovement;
- int row, column;
-
- /* Save values */
- row = _editedRow;
- column = _editedColumn;
-
- [super textDidEndEditing: aNotification];
-
- textMovement = [[aNotification userInfo] objectForKey: @"NSTextMovement"];
- if (textMovement)
+ id textMovement;
+ int row, column;
+
+ /* Save values */
+ row = _editedRow;
+ column = _editedColumn;
+
+ [super textDidEndEditing: aNotification];
+
+ textMovement = [[aNotification userInfo] objectForKey: @"NSTextMovement"];
+ if (textMovement)
{
- switch ([(NSNumber *)textMovement intValue])
- {
- case NSReturnTextMovement:
- [self _editNextCellAfterRow: row inColumn: column];
- // Send action ?
- break;
- case NSTabTextMovement:
- if ([self _editNextEditableCellAfterRow: row column: column] == YES)
- {
- break;
- }
- [_window selectKeyViewFollowingView: self];
- break;
- case NSBacktabTextMovement:
- if ([self _editPreviousEditableCellBeforeRow: row column: column] == YES)
- {
- break;
- }
- [_window selectKeyViewPrecedingView: self];
- break;
- }
+ switch ([(NSNumber *)textMovement intValue])
+ {
+ case NSReturnTextMovement:
+ [self _editNextCellAfterRow: row inColumn: column];
+ // Send action ?
+ break;
+ case NSTabTextMovement:
+ if ([self _editNextEditableCellAfterRow: row column: column] == YES)
+ {
+ break;
+ }
+ [_window selectKeyViewFollowingView: self];
+ break;
+ case NSBacktabTextMovement:
+ if ([self _editPreviousEditableCellBeforeRow: row column: column] == YES)
+ {
+ break;
+ }
+ [_window selectKeyViewPrecedingView: self];
+ break;
+ }
}
}
- (BOOL) textShouldBeginEditing: (NSText *)textObject
{
- if (_delegate && [_delegate respondsToSelector:
- @selector(control:textShouldBeginEditing:)])
- return [_delegate control: self
- textShouldBeginEditing: textObject];
- else
- return YES;
+ if (_delegate && [_delegate respondsToSelector:
+ @selector(control:textShouldBeginEditing:)])
+ return [_delegate control: self
+ textShouldBeginEditing: textObject];
+ else
+ return YES;
}
- (BOOL) textShouldEndEditing: (NSText*)textObject
{
- if ([_delegate respondsToSelector:
- @selector(control:textShouldEndEditing:)])
+ if ([_delegate respondsToSelector:
+ @selector(control:textShouldEndEditing:)])
{
- if ([_delegate control: self
- textShouldEndEditing: textObject] == NO)
- {
- NSBeep ();
- return NO;
- }
-
- return YES;
+ if ([_delegate control: self
+ textShouldEndEditing: textObject] == NO)
+ {
+ NSBeep ();
+ return NO;
+ }
+
+ return YES;
}
-
- if ([_delegate respondsToSelector:
- @selector(control:isValidObject:)] == YES)
+
+ if ([_delegate respondsToSelector:
+ @selector(control:isValidObject:)] == YES)
{
- NSFormatter *formatter;
- id newObjectValue;
-
- formatter = [_editedCell formatter];
-
- if ([formatter getObjectValue: &newObjectValue
- forString: [_textObject text]
- errorDescription: NULL] == YES)
- {
- if ([_delegate control: self
- isValidObject: newObjectValue] == NO)
- return NO;
- }
+ NSFormatter *formatter;
+ id newObjectValue;
+
+ formatter = [_editedCell formatter];
+
+ if ([formatter getObjectValue: &newObjectValue
+ forString: [_textObject text]
+ errorDescription: NULL] == YES)
+ {
+ if ([_delegate control: self
+ isValidObject: newObjectValue] == NO)
+ return NO;
+ }
}
-
- return [_editedCell isEntryAcceptable: [textObject text]];
+
+ return [_editedCell isEntryAcceptable: [textObject text]];
}
-/*
- * Persistence
+/*
+ * Persistence
*/
- (NSString *) autosaveName
{
- return _autosaveName;
+ return _autosaveName;
}
- (BOOL) autosaveTableColumns
{
- return _autosaveTableColumns;
+ return _autosaveTableColumns;
}
- (void) setAutosaveName: (NSString *)name
{
- ASSIGN (_autosaveName, name);
- [self _autoloadTableColumns];
+ ASSIGN (_autosaveName, name);
+ [self _autoloadTableColumns];
}
- (void) setAutosaveTableColumns: (BOOL)flag
{
- if (flag == _autosaveTableColumns)
+ if (flag == _autosaveTableColumns)
{
- return;
+ return;
}
-
- _autosaveTableColumns = flag;
- if (flag)
+
+ _autosaveTableColumns = flag;
+ if (flag)
{
- [self _autoloadTableColumns];
- [nc addObserver: self
- selector: @selector(_autosaveTableColumns)
- name: NSTableViewColumnDidResizeNotification
- object: self];
+ [self _autoloadTableColumns];
+ [nc addObserver: self
+ selector: @selector(_autosaveTableColumns)
+ name: NSTableViewColumnDidResizeNotification
+ object: self];
}
- else
+ else
{
- [nc removeObserver: self
- name: NSTableViewColumnDidResizeNotification
- object: self];
+ [nc removeObserver: self
+ name: NSTableViewColumnDidResizeNotification
+ object: self];
}
}
-/*
- * Delegate
+/*
+ * Delegate
*/
- (void) setDelegate: (id)anObject
{
- const SEL sel = @selector(tableView:willDisplayCell:forTableColumn:row:);
-
- if (_delegate)
- [nc removeObserver: _delegate name: nil object: self];
- _delegate = anObject;
-
+ const SEL sel = @selector(tableView:willDisplayCell:forTableColumn:row:);
+
+ if (_delegate)
+ [nc removeObserver: _delegate name: nil object: self];
+ _delegate = anObject;
+
#define SET_DELEGATE_NOTIFICATION(notif_name) \
-if ([_delegate respondsToSelector: @selector(tableView##notif_name:)]) \
-[nc addObserver: _delegate \
-selector: @selector(tableView##notif_name:) \
-name: NSTableView##notif_name##Notification object: self]
-
- SET_DELEGATE_NOTIFICATION(ColumnDidMove);
- SET_DELEGATE_NOTIFICATION(ColumnDidResize);
- SET_DELEGATE_NOTIFICATION(SelectionDidChange);
- SET_DELEGATE_NOTIFICATION(SelectionIsChanging);
-
- /* Cache */
- _del_responds = [_delegate respondsToSelector: sel];
+ if ([_delegate respondsToSelector: @selector(tableView##notif_name:)]) \
+ [nc addObserver: _delegate \
+ selector: @selector(tableView##notif_name:) \
+ name: NSTableView##notif_name##Notification object: self]
+
+ SET_DELEGATE_NOTIFICATION(ColumnDidMove);
+ SET_DELEGATE_NOTIFICATION(ColumnDidResize);
+ SET_DELEGATE_NOTIFICATION(SelectionDidChange);
+ SET_DELEGATE_NOTIFICATION(SelectionIsChanging);
+
+ /* Cache */
+ _del_responds = [_delegate respondsToSelector: sel];
}
- (id) delegate
{
- return _delegate;
+ return _delegate;
}
/* indicator image */
- (NSImage *) indicatorImageInTableColumn: (NSTableColumn *)aTableColumn
{
- // TODO
- NSLog(@"Method %s is not implemented for class %s",
- "indicatorImageInTableColumn:", "NSTableView");
- return nil;
+ // TODO
+ NSLog(@"Method %s is not implemented for class %s",
+ "indicatorImageInTableColumn:", "NSTableView");
+ return nil;
}
- (void) setIndicatorImage: (NSImage *)anImage
- inTableColumn: (NSTableColumn *)aTableColumn
+ inTableColumn: (NSTableColumn *)aTableColumn
{
- // TODO
- NSLog(@"Method %s is not implemented for class %s",
- "setIndicatorImage:inTableColumn:", "NSTableView");
+ // TODO
+ NSLog(@"Method %s is not implemented for class %s",
+ "setIndicatorImage:inTableColumn:", "NSTableView");
}
/* highlighting columns */
- (NSTableColumn *) highlightedTableColumn
{
- return _highlightedTableColumn;
+ return _highlightedTableColumn;
}
- (void) setHighlightedTableColumn: (NSTableColumn *)aTableColumn
{
- NSUInteger tableColumnIndex;
-
- tableColumnIndex = [_tableColumns indexOfObject: aTableColumn];
-
- if (tableColumnIndex == NSNotFound)
+ NSUInteger tableColumnIndex;
+
+ tableColumnIndex = [_tableColumns indexOfObject: aTableColumn];
+
+ if (tableColumnIndex == NSNotFound)
{
- NSLog(@"setHighlightedTableColumn received an invalid\
- NSTableColumn object");
- return;
+ NSLog(@"setHighlightedTableColumn received an invalid\
+ NSTableColumn object");
+ return;
}
-
- // we do not need to retain aTableColumn as it is already in
- // _tableColumns array
- _highlightedTableColumn = aTableColumn;
-
- [_headerView setNeedsDisplay: YES];
+
+ // we do not need to retain aTableColumn as it is already in
+ // _tableColumns array
+ _highlightedTableColumn = aTableColumn;
+
+ [_headerView setNeedsDisplay: YES];
}
/* dragging rows */
@@ -5329,11 +5325,11 @@ name: NSTableView##notif_name##Notification object: self]
event: (NSEvent*)dragEvent
dragImageOffset: (NSPoint*)dragImageOffset
{
- // FIXME
- NSImage *dragImage = [[NSImage alloc]
- initWithSize: NSMakeSize(8, 8)];
-
- return AUTORELEASE(dragImage);
+ // FIXME
+ NSImage *dragImage = [[NSImage alloc]
+ initWithSize: NSMakeSize(8, 8)];
+
+ return AUTORELEASE(dragImage);
}
- (NSImage *) dragImageForRowsWithIndexes: (NSIndexSet*)rows
@@ -5341,97 +5337,53 @@ name: NSTableView##notif_name##Notification object: self]
event: (NSEvent*)event
offset: (NSPoint*)offset
{
- if (!cols && ([self tableColumns]) && ([[self tableColumns] count] > 0)) {
- cols = [NSArray arrayWithObject:[[self tableColumns] objectAtIndex:0]];
- }
- if (!rows || [rows count] < 1 || !cols || [cols count] < 1) {
- // FIXME
- NSArray *rowArray;
-
- rowArray = [self _indexSetToArray: rows];
- return [self dragImageForRows: rowArray
- event: event
- dragImageOffset: offset];
- }
-
- // Build a string of texts, each representing a line from the tableView,
- // separated by "\n":
- NSString *descriptionsList = nil;
- unsigned int index = [rows firstIndex];
- while (index != NSNotFound) {
- NSString *draggedItemString = [self _objectStringForTableColum:[cols objectAtIndex:0]
- item:index];
- if (!descriptionsList) {
- descriptionsList = [NSMutableString stringWithString:draggedItemString];
- }
- else {
- descriptionsList = [descriptionsList stringByAppendingFormat:@"\n%@", draggedItemString];
- }
- index = [rows indexGreaterThanIndex:index];
- }
-
-
- NSAttributedString *attributedString = [[[NSAttributedString alloc] initWithString:descriptionsList] autorelease];
-
- NSSize boxSize = [attributedString size];
- NSRect rect = NSMakeRect(0.0, 0.0, boxSize.width, boxSize.height);
- NSImage *image = [[NSImage alloc] initWithSize:boxSize];
- NSColor *bg = [NSColor whiteColor];
-
-
- [image lockFocus];
- // Filling with white color for now, transparent is showing as blackColor.
- [bg set];
- NSRectFill(rect);
- [attributedString drawInRect:rect];
- [image unlockFocus];
-
- // Offset the image so it sits neatly next to the mouse cursor.
- // Note: Cocoa actually offsets the image to position of the mouse down.
- offset->x = (boxSize.width / 2) + 5;
- offset->y = (boxSize.height / -2) + 5;
-
- return [image autorelease];
+ // FIXME
+ NSArray *rowArray;
+
+ rowArray = [self _indexSetToArray: rows];
+ return [self dragImageForRows: rowArray
+ event: event
+ dragImageOffset: offset];
}
- (void) setDropRow: (int)row
dropOperation: (NSTableViewDropOperation)operation
{
- if (row < -1 || row > _numberOfRows
- || (operation == NSTableViewDropOn && row == _numberOfRows))
+ if (row < -1 || row > _numberOfRows
+ || (operation == NSTableViewDropOn && row == _numberOfRows))
{
- currentDropRow = -1;
- currentDropOperation = NSTableViewDropOn;
+ currentDropRow = -1;
+ currentDropOperation = NSTableViewDropOn;
}
- else
+ else
{
- currentDropRow = row;
- currentDropOperation = operation;
+ currentDropRow = row;
+ currentDropOperation = operation;
}
}
- (void) setVerticalMotionCanBeginDrag: (BOOL)flag
{
- _verticalMotionDrag = flag;
+ _verticalMotionDrag = flag;
}
- (BOOL) verticalMotionCanBeginDrag
{
- return _verticalMotionDrag;
+ return _verticalMotionDrag;
}
- (NSArray*) namesOfPromisedFilesDroppedAtDestination: (NSURL *)dropDestination
{
- if ([_dataSource respondsToSelector:
- @selector(tableView:namesOfPromisedFilesDroppedAtDestination:forDraggedRowsWithIndexes:)])
+ if ([_dataSource respondsToSelector:
+ @selector(tableView:namesOfPromisedFilesDroppedAtDestination:forDraggedRowsWithIndexes:)])
{
- return [_dataSource tableView: self
-namesOfPromisedFilesDroppedAtDestination: dropDestination
- forDraggedRowsWithIndexes: _selectedRows];
+ return [_dataSource tableView: self
+ namesOfPromisedFilesDroppedAtDestination: dropDestination
+ forDraggedRowsWithIndexes: _selectedRows];
}
- else
+ else
{
- return nil;
+ return nil;
}
}
@@ -5441,438 +5393,438 @@ namesOfPromisedFilesDroppedAtDestination: dropDestination
- (void) encodeWithCoder: (NSCoder*)aCoder
{
- if ([aCoder allowsKeyedCoding])
+ if ([aCoder allowsKeyedCoding])
{
- unsigned long vFlags = 0;
- NSSize intercellSpacing = [self intercellSpacing];
- GSTableViewFlags tableViewFlags;
-
- // make sure the corner view is properly encoded...
- [super encodeWithCoder: aCoder];
-
- if ([self dataSource])
+ unsigned long vFlags = 0;
+ NSSize intercellSpacing = [self intercellSpacing];
+ GSTableViewFlags tableViewFlags;
+
+ // make sure the corner view is properly encoded...
+ [super encodeWithCoder: aCoder];
+
+ if ([self dataSource])
+ {
+ [aCoder encodeObject: [self dataSource] forKey: @"NSDataSource"];
+ }
+ if ([self delegate])
+ {
+ [aCoder encodeObject: [self delegate] forKey: @"NSDelegate"];
+ }
+ if ([self target])
+ {
+ [aCoder encodeObject: [self target] forKey: @"NSTarget"];
+ }
+ if ([self action])
+ {
+ [aCoder encodeObject: NSStringFromSelector([self action]) forKey: @"NSAction"];
+ }
+ if ([self doubleAction] != NULL)
+ {
+ [aCoder encodeObject: NSStringFromSelector([self doubleAction]) forKey: @"NSDoubleAction"];
+ }
+
+ [aCoder encodeObject: [self backgroundColor] forKey: @"NSBackgroundColor"];
+ [aCoder encodeObject: [self gridColor] forKey: @"NSGridColor"];
+ [aCoder encodeFloat: intercellSpacing.height forKey: @"NSIntercellSpacingHeight"];
+ [aCoder encodeFloat: intercellSpacing.width forKey: @"NSIntercellSpacingWidth"];
+ [aCoder encodeFloat: [self rowHeight] forKey: @"NSRowHeight"];
+ [aCoder encodeObject: [self tableColumns] forKey: @"NSTableColumns"];
+
+ if (_headerView)
{
- [aCoder encodeObject: [self dataSource] forKey: @"NSDataSource"];
+ [aCoder encodeObject: _headerView forKey: @"NSHeaderView"];
}
- if ([self delegate])
+ if (_cornerView)
{
- [aCoder encodeObject: [self delegate] forKey: @"NSDelegate"];
+ [aCoder encodeObject: _cornerView forKey: @"NSCornerView"];
}
- if ([self target])
+
+ if ([[self sortDescriptors] count] > 0)
{
- [aCoder encodeObject: [self target] forKey: @"NSTarget"];
+ [aCoder encodeObject: _sortDescriptors forKey: @"NSSortDescriptors"];
}
- if ([self action])
- {
- [aCoder encodeObject: NSStringFromSelector([self action]) forKey: @"NSAction"];
- }
- if ([self doubleAction] != NULL)
- {
- [aCoder encodeObject: NSStringFromSelector([self doubleAction]) forKey: @"NSDoubleAction"];
- }
-
- [aCoder encodeObject: [self backgroundColor] forKey: @"NSBackgroundColor"];
- [aCoder encodeObject: [self gridColor] forKey: @"NSGridColor"];
- [aCoder encodeFloat: intercellSpacing.height forKey: @"NSIntercellSpacingHeight"];
- [aCoder encodeFloat: intercellSpacing.width forKey: @"NSIntercellSpacingWidth"];
- [aCoder encodeFloat: [self rowHeight] forKey: @"NSRowHeight"];
- [aCoder encodeObject: [self tableColumns] forKey: @"NSTableColumns"];
-
- if (_headerView)
- {
- [aCoder encodeObject: _headerView forKey: @"NSHeaderView"];
- }
- if (_cornerView)
- {
- [aCoder encodeObject: _cornerView forKey: @"NSCornerView"];
- }
-
- if ([[self sortDescriptors] count] > 0)
- {
- [aCoder encodeObject: _sortDescriptors forKey: @"NSSortDescriptors"];
- }
-
- tableViewFlags.columnSelection = [self allowsColumnSelection];
- tableViewFlags.multipleSelection = [self allowsMultipleSelection];
- tableViewFlags.emptySelection = [self allowsEmptySelection];
- tableViewFlags.drawsGrid = [self drawsGrid];
- tableViewFlags.columnResizing = [self allowsColumnResizing];
- tableViewFlags.columnOrdering = [self allowsColumnReordering];
-
- memcpy((void *)&vFlags,(void *)&tableViewFlags,sizeof(unsigned long));
-
- // encode..
- [aCoder encodeInt: vFlags forKey: @"NSTvFlags"];
+
+ tableViewFlags.columnSelection = [self allowsColumnSelection];
+ tableViewFlags.multipleSelection = [self allowsMultipleSelection];
+ tableViewFlags.emptySelection = [self allowsEmptySelection];
+ tableViewFlags.drawsGrid = [self drawsGrid];
+ tableViewFlags.columnResizing = [self allowsColumnResizing];
+ tableViewFlags.columnOrdering = [self allowsColumnReordering];
+
+ memcpy((void *)&vFlags,(void *)&tableViewFlags,sizeof(unsigned long));
+
+ // encode..
+ [aCoder encodeInt: vFlags forKey: @"NSTvFlags"];
}
- else
+ else
{
- [super encodeWithCoder: aCoder];
- [aCoder encodeConditionalObject: _dataSource];
- [aCoder encodeObject: _tableColumns];
- [aCoder encodeObject: _gridColor];
- [aCoder encodeObject: _backgroundColor];
- [aCoder encodeObject: _headerView];
- [aCoder encodeObject: _cornerView];
- [aCoder encodeConditionalObject: _delegate];
- [aCoder encodeConditionalObject: _target];
-
- [aCoder encodeValueOfObjCType: @encode(int) at: &_numberOfRows];
- [aCoder encodeValueOfObjCType: @encode(int) at: &_numberOfColumns];
-
- [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_drawsGrid];
- [aCoder encodeValueOfObjCType: @encode(float) at: &_rowHeight];
- [aCoder encodeValueOfObjCType: @encode(SEL) at: &_doubleAction];
- [aCoder encodeSize: _intercellSpacing];
-
- [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_allowsMultipleSelection];
- [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_allowsEmptySelection];
- [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_allowsColumnSelection];
- [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_allowsColumnResizing];
- [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_allowsColumnReordering];
- [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_autoresizesAllColumnsToFit];
- [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_verticalMotionDrag];
- [aCoder encodeObject: _sortDescriptors];
+ [super encodeWithCoder: aCoder];
+ [aCoder encodeConditionalObject: _dataSource];
+ [aCoder encodeObject: _tableColumns];
+ [aCoder encodeObject: _gridColor];
+ [aCoder encodeObject: _backgroundColor];
+ [aCoder encodeObject: _headerView];
+ [aCoder encodeObject: _cornerView];
+ [aCoder encodeConditionalObject: _delegate];
+ [aCoder encodeConditionalObject: _target];
+
+ [aCoder encodeValueOfObjCType: @encode(int) at: &_numberOfRows];
+ [aCoder encodeValueOfObjCType: @encode(int) at: &_numberOfColumns];
+
+ [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_drawsGrid];
+ [aCoder encodeValueOfObjCType: @encode(float) at: &_rowHeight];
+ [aCoder encodeValueOfObjCType: @encode(SEL) at: &_doubleAction];
+ [aCoder encodeSize: _intercellSpacing];
+
+ [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_allowsMultipleSelection];
+ [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_allowsEmptySelection];
+ [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_allowsColumnSelection];
+ [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_allowsColumnResizing];
+ [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_allowsColumnReordering];
+ [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_autoresizesAllColumnsToFit];
+ [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_verticalMotionDrag];
+ [aCoder encodeObject: _sortDescriptors];
}
}
- (id) initWithCoder: (NSCoder*)aDecoder
{
- self = [super initWithCoder: aDecoder];
- if (!self)
- return self;
-
- if ([aDecoder allowsKeyedCoding])
- {
- NSSize intercellSpacing;
- NSArray *columns;
- NSEnumerator *e;
- NSTableColumn *col;
-
- // assign defaults, so that there's color in case none is specified
- [self _initDefaults];
- ASSIGN(_gridColor, [NSColor gridColor]);
- ASSIGN(_backgroundColor, [NSColor controlBackgroundColor]);
- ASSIGN(_tableColumns, [NSMutableArray array]);
- ASSIGN(_sortDescriptors, [NSArray array]);
-
- //
- // Check for nil on some of these, since they are usually set
- // in NSIBOutletConnector objects we don't want to override
- // that setting unless they're directly encoded with the
- // object.
- //
- // I'm not sure why IB encodes nil values for these, but
- // the behaviour here should match that on Mac OS X.
- //
- if ([aDecoder containsValueForKey: @"NSDataSource"])
- {
- id obj = [aDecoder decodeObjectForKey: @"NSDataSource"];
- if(obj != nil)
- {
- [self setDataSource: obj];
- }
- }
- if ([aDecoder containsValueForKey: @"NSDelegate"])
- {
- id obj = [aDecoder decodeObjectForKey: @"NSDelegate"];
- if(obj != nil)
- {
- [self setDelegate: obj];
- }
- }
- if ([aDecoder containsValueForKey: @"NSTarget"])
- {
- id obj = [aDecoder decodeObjectForKey: @"NSTarget"];
- if(obj != nil)
- {
- [self setTarget: obj];
- }
- }
- if ([aDecoder containsValueForKey: @"NSAction"])
- {
- NSString *action = [aDecoder decodeObjectForKey: @"NSAction"];
- if(action != nil)
- {
- [self setAction: NSSelectorFromString(action)];
- }
- }
- if ([aDecoder containsValueForKey: @"NSDoubleAction"])
- {
- NSString *action = [aDecoder decodeObjectForKey: @"NSDoubleAction"];
- if(action != nil)
- {
- [self setDoubleAction: NSSelectorFromString(action)];
- }
- }
-
- if ([aDecoder containsValueForKey: @"NSBackgroundColor"])
- {
- [self setBackgroundColor: [aDecoder decodeObjectForKey: @"NSBackgroundColor"]];
- }
- if ([aDecoder containsValueForKey: @"NSGridColor"])
- {
- [self setGridColor: [aDecoder decodeObjectForKey: @"NSGridColor"]];
- }
-
- intercellSpacing = [self intercellSpacing];
- if ([aDecoder containsValueForKey: @"NSIntercellSpacingHeight"])
- {
- intercellSpacing.height = [aDecoder decodeFloatForKey: @"NSIntercellSpacingHeight"];
- }
- if ([aDecoder containsValueForKey: @"NSIntercellSpacingWidth"])
- {
- intercellSpacing.width = [aDecoder decodeFloatForKey: @"NSIntercellSpacingWidth"];
- }
- [self setIntercellSpacing: intercellSpacing];
-
- if ([aDecoder containsValueForKey: @"NSDraggingSourceMaskForLocal"])
- {
- [self setDraggingSourceOperationMask:
- [aDecoder decodeIntForKey: @"NSDraggingSourceMaskForLocal"]
- forLocal: YES];
- }
- if ([aDecoder containsValueForKey: @"NSDraggingSourceMaskForNonLocal"])
- {
- [self setDraggingSourceOperationMask:
- [aDecoder decodeIntForKey: @"NSDraggingSourceMaskForNonLocal"]
- forLocal: NO];
- }
-
- if ([aDecoder containsValueForKey: @"NSRowHeight"])
- {
- [self setRowHeight: [aDecoder decodeFloatForKey: @"NSRowHeight"]];
- }
-
- if ([aDecoder containsValueForKey: @"NSCornerView"])
- {
- NSView *aView = [aDecoder decodeObjectForKey: @"NSCornerView"];
- [self setCornerView: aView];
- [aView setHidden: NO];
- }
- else
- {
- _cornerView = [GSTableCornerView new];
- }
-
- if ([aDecoder containsValueForKey: @"NSHeaderView"])
- {
- [self setHeaderView: [aDecoder decodeObjectForKey: @"NSHeaderView"]];
- }
-
- if ([aDecoder containsValueForKey: @"NSSortDescriptors"])
- {
- ASSIGN(_sortDescriptors, [aDecoder decodeObjectForKey: @"NSSortDescriptors"]);
- }
-
- if ([aDecoder containsValueForKey: @"NSTvFlags"])
- {
- unsigned long flags = [aDecoder decodeIntForKey: @"NSTvFlags"];
- GSTableViewFlags tableViewFlags;
- memcpy((void *)&tableViewFlags,(void *)&flags,sizeof(struct _tableViewFlags));
-
- [self setAllowsColumnSelection: tableViewFlags.columnSelection];
- [self setAllowsMultipleSelection: tableViewFlags.multipleSelection];
- [self setAllowsEmptySelection: tableViewFlags.emptySelection];
- [self setDrawsGrid: tableViewFlags.drawsGrid];
- [self setAllowsColumnResizing: tableViewFlags.columnResizing];
- [self setAllowsColumnReordering: tableViewFlags.columnOrdering];
- }
-
- // get the table columns...
- columns = [aDecoder decodeObjectForKey: @"NSTableColumns"];
- e = [columns objectEnumerator];
- while ((col = [e nextObject]) != nil)
- {
- /* Will initialize -[NSTableColumn tableView], _numberOfColumns and
- allocate _columnsOrigins */
- [self addTableColumn: col];
- }
-
- [self tile]; /* Initialize _columnOrigins */
- }
- else
- {
- int version = [aDecoder versionForClassName:
- @"NSTableView"];
- id aDelegate;
-
- [self _initDefaults];
- _dataSource = [aDecoder decodeObject];
- _tableColumns = RETAIN([aDecoder decodeObject]);
- _gridColor = RETAIN([aDecoder decodeObject]);
- _backgroundColor = RETAIN([aDecoder decodeObject]);
- _headerView = RETAIN([aDecoder decodeObject]);
- _cornerView = RETAIN([aDecoder decodeObject]);
- aDelegate = [aDecoder decodeObject];
- _target = [aDecoder decodeObject];
-
- [self setDelegate: aDelegate];
- [_headerView setTableView: self];
- [_tableColumns makeObjectsPerformSelector: @selector(setTableView:)
- withObject: self];
-
- [aDecoder decodeValueOfObjCType: @encode(int) at: &_numberOfRows];
- [aDecoder decodeValueOfObjCType: @encode(int) at: &_numberOfColumns];
- [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_drawsGrid];
- [aDecoder decodeValueOfObjCType: @encode(float) at: &_rowHeight];
- [aDecoder decodeValueOfObjCType: @encode(SEL) at: &_doubleAction];
- _intercellSpacing = [aDecoder decodeSize];
-
- [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_allowsMultipleSelection];
- [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_allowsEmptySelection];
- [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_allowsColumnSelection];
- [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_allowsColumnResizing];
- if (version >= 3)
- {
- [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_allowsColumnReordering];
- }
- if (version >= 2)
- {
- [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_autoresizesAllColumnsToFit];
- }
-
- if (version >= 4)
- {
- [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_verticalMotionDrag];
- }
- if (version >= 5)
- {
- ASSIGN(_sortDescriptors, [aDecoder decodeObject]);
- }
-
- if (_numberOfColumns > 0)
- {
- _columnOrigins = NSZoneMalloc (NSDefaultMallocZone (),
- sizeof(float) * _numberOfColumns);
- }
- [self tile]; /* Initialize _columnOrigins */
- }
-
+ self = [super initWithCoder: aDecoder];
+ if (!self)
return self;
+
+ if ([aDecoder allowsKeyedCoding])
+ {
+ NSSize intercellSpacing;
+ NSArray *columns;
+ NSEnumerator *e;
+ NSTableColumn *col;
+
+ // assign defaults, so that there's color in case none is specified
+ [self _initDefaults];
+ ASSIGN(_gridColor, [NSColor gridColor]);
+ ASSIGN(_backgroundColor, [NSColor controlBackgroundColor]);
+ ASSIGN(_tableColumns, [NSMutableArray array]);
+ ASSIGN(_sortDescriptors, [NSArray array]);
+
+ //
+ // Check for nil on some of these, since they are usually set
+ // in NSIBOutletConnector objects we don't want to override
+ // that setting unless they're directly encoded with the
+ // object.
+ //
+ // I'm not sure why IB encodes nil values for these, but
+ // the behaviour here should match that on Mac OS X.
+ //
+ if ([aDecoder containsValueForKey: @"NSDataSource"])
+ {
+ id obj = [aDecoder decodeObjectForKey: @"NSDataSource"];
+ if(obj != nil)
+ {
+ [self setDataSource: obj];
+ }
+ }
+ if ([aDecoder containsValueForKey: @"NSDelegate"])
+ {
+ id obj = [aDecoder decodeObjectForKey: @"NSDelegate"];
+ if(obj != nil)
+ {
+ [self setDelegate: obj];
+ }
+ }
+ if ([aDecoder containsValueForKey: @"NSTarget"])
+ {
+ id obj = [aDecoder decodeObjectForKey: @"NSTarget"];
+ if(obj != nil)
+ {
+ [self setTarget: obj];
+ }
+ }
+ if ([aDecoder containsValueForKey: @"NSAction"])
+ {
+ NSString *action = [aDecoder decodeObjectForKey: @"NSAction"];
+ if(action != nil)
+ {
+ [self setAction: NSSelectorFromString(action)];
+ }
+ }
+ if ([aDecoder containsValueForKey: @"NSDoubleAction"])
+ {
+ NSString *action = [aDecoder decodeObjectForKey: @"NSDoubleAction"];
+ if(action != nil)
+ {
+ [self setDoubleAction: NSSelectorFromString(action)];
+ }
+ }
+
+ if ([aDecoder containsValueForKey: @"NSBackgroundColor"])
+ {
+ [self setBackgroundColor: [aDecoder decodeObjectForKey: @"NSBackgroundColor"]];
+ }
+ if ([aDecoder containsValueForKey: @"NSGridColor"])
+ {
+ [self setGridColor: [aDecoder decodeObjectForKey: @"NSGridColor"]];
+ }
+
+ intercellSpacing = [self intercellSpacing];
+ if ([aDecoder containsValueForKey: @"NSIntercellSpacingHeight"])
+ {
+ intercellSpacing.height = [aDecoder decodeFloatForKey: @"NSIntercellSpacingHeight"];
+ }
+ if ([aDecoder containsValueForKey: @"NSIntercellSpacingWidth"])
+ {
+ intercellSpacing.width = [aDecoder decodeFloatForKey: @"NSIntercellSpacingWidth"];
+ }
+ [self setIntercellSpacing: intercellSpacing];
+
+ if ([aDecoder containsValueForKey: @"NSDraggingSourceMaskForLocal"])
+ {
+ [self setDraggingSourceOperationMask:
+ [aDecoder decodeIntForKey: @"NSDraggingSourceMaskForLocal"]
+ forLocal: YES];
+ }
+ if ([aDecoder containsValueForKey: @"NSDraggingSourceMaskForNonLocal"])
+ {
+ [self setDraggingSourceOperationMask:
+ [aDecoder decodeIntForKey: @"NSDraggingSourceMaskForNonLocal"]
+ forLocal: NO];
+ }
+
+ if ([aDecoder containsValueForKey: @"NSRowHeight"])
+ {
+ [self setRowHeight: [aDecoder decodeFloatForKey: @"NSRowHeight"]];
+ }
+
+ if ([aDecoder containsValueForKey: @"NSCornerView"])
+ {
+ NSView *aView = [aDecoder decodeObjectForKey: @"NSCornerView"];
+ [self setCornerView: aView];
+ [aView setHidden: NO];
+ }
+ else
+ {
+ _cornerView = [GSTableCornerView new];
+ }
+
+ if ([aDecoder containsValueForKey: @"NSHeaderView"])
+ {
+ [self setHeaderView: [aDecoder decodeObjectForKey: @"NSHeaderView"]];
+ }
+
+ if ([aDecoder containsValueForKey: @"NSSortDescriptors"])
+ {
+ ASSIGN(_sortDescriptors, [aDecoder decodeObjectForKey: @"NSSortDescriptors"]);
+ }
+
+ if ([aDecoder containsValueForKey: @"NSTvFlags"])
+ {
+ unsigned long flags = [aDecoder decodeIntForKey: @"NSTvFlags"];
+ GSTableViewFlags tableViewFlags;
+ memcpy((void *)&tableViewFlags,(void *)&flags,sizeof(struct _tableViewFlags));
+
+ [self setAllowsColumnSelection: tableViewFlags.columnSelection];
+ [self setAllowsMultipleSelection: tableViewFlags.multipleSelection];
+ [self setAllowsEmptySelection: tableViewFlags.emptySelection];
+ [self setDrawsGrid: tableViewFlags.drawsGrid];
+ [self setAllowsColumnResizing: tableViewFlags.columnResizing];
+ [self setAllowsColumnReordering: tableViewFlags.columnOrdering];
+ }
+
+ // get the table columns...
+ columns = [aDecoder decodeObjectForKey: @"NSTableColumns"];
+ e = [columns objectEnumerator];
+ while ((col = [e nextObject]) != nil)
+ {
+ /* Will initialize -[NSTableColumn tableView], _numberOfColumns and
+ allocate _columnsOrigins */
+ [self addTableColumn: col];
+ }
+
+ [self tile]; /* Initialize _columnOrigins */
+ }
+ else
+ {
+ int version = [aDecoder versionForClassName:
+ @"NSTableView"];
+ id aDelegate;
+
+ [self _initDefaults];
+ _dataSource = [aDecoder decodeObject];
+ _tableColumns = RETAIN([aDecoder decodeObject]);
+ _gridColor = RETAIN([aDecoder decodeObject]);
+ _backgroundColor = RETAIN([aDecoder decodeObject]);
+ _headerView = RETAIN([aDecoder decodeObject]);
+ _cornerView = RETAIN([aDecoder decodeObject]);
+ aDelegate = [aDecoder decodeObject];
+ _target = [aDecoder decodeObject];
+
+ [self setDelegate: aDelegate];
+ [_headerView setTableView: self];
+ [_tableColumns makeObjectsPerformSelector: @selector(setTableView:)
+ withObject: self];
+
+ [aDecoder decodeValueOfObjCType: @encode(int) at: &_numberOfRows];
+ [aDecoder decodeValueOfObjCType: @encode(int) at: &_numberOfColumns];
+ [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_drawsGrid];
+ [aDecoder decodeValueOfObjCType: @encode(float) at: &_rowHeight];
+ [aDecoder decodeValueOfObjCType: @encode(SEL) at: &_doubleAction];
+ _intercellSpacing = [aDecoder decodeSize];
+
+ [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_allowsMultipleSelection];
+ [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_allowsEmptySelection];
+ [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_allowsColumnSelection];
+ [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_allowsColumnResizing];
+ if (version >= 3)
+ {
+ [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_allowsColumnReordering];
+ }
+ if (version >= 2)
+ {
+ [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_autoresizesAllColumnsToFit];
+ }
+
+ if (version >= 4)
+ {
+ [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_verticalMotionDrag];
+ }
+ if (version >= 5)
+ {
+ ASSIGN(_sortDescriptors, [aDecoder decodeObject]);
+ }
+
+ if (_numberOfColumns > 0)
+ {
+ _columnOrigins = NSZoneMalloc (NSDefaultMallocZone (),
+ sizeof(float) * _numberOfColumns);
+ }
+ [self tile]; /* Initialize _columnOrigins */
+ }
+
+ return self;
}
- (void) updateCell: (NSCell*)aCell
{
- int i, j;
- NSTableColumn *tb;
- if (aCell == nil)
- return;
+ int i, j;
+ NSTableColumn *tb;
+ if (aCell == nil)
return;
- for (i = 0; i < _numberOfColumns; i++)
+ return;
+ for (i = 0; i < _numberOfColumns; i++)
{
- tb = [_tableColumns objectAtIndex: i];
- if ([self _dataCellForTableColumn: tb row: -1] == aCell)
- {
- [self setNeedsDisplayInRect: [self rectOfColumn: i]];
- }
- else
- {
- NSRect columnRect = [self rectOfColumn: i];
- NSRect rowRect;
- NSRect visibleRect = [self convertRect: [_super_view bounds]
- toView: self];
- NSPoint top = NSMakePoint(NSMinX(visibleRect),
- NSMinY(visibleRect));
- NSPoint bottom = NSMakePoint(NSMinX(visibleRect),
- NSMaxY(visibleRect));
- int firstVisibleRow = [self rowAtPoint: top];
- int lastVisibleRow = [self rowAtPoint: bottom];
-
- if (firstVisibleRow == -1)
- firstVisibleRow = 0;
-
- if (lastVisibleRow == -1)
- lastVisibleRow = _numberOfColumns - 1;
-
- for (j = firstVisibleRow; j < lastVisibleRow; j++)
- {
- if ([self _dataCellForTableColumn: tb row: j] == aCell)
- {
- rowRect = [self rectOfRow: j];
- [self setNeedsDisplayInRect:
- NSIntersectionRect(columnRect, rowRect)];
- }
- }
- }
+ tb = [_tableColumns objectAtIndex: i];
+ if ([self _dataCellForTableColumn: tb row: -1] == aCell)
+ {
+ [self setNeedsDisplayInRect: [self rectOfColumn: i]];
+ }
+ else
+ {
+ NSRect columnRect = [self rectOfColumn: i];
+ NSRect rowRect;
+ NSRect visibleRect = [self convertRect: [_super_view bounds]
+ toView: self];
+ NSPoint top = NSMakePoint(NSMinX(visibleRect),
+ NSMinY(visibleRect));
+ NSPoint bottom = NSMakePoint(NSMinX(visibleRect),
+ NSMaxY(visibleRect));
+ int firstVisibleRow = [self rowAtPoint: top];
+ int lastVisibleRow = [self rowAtPoint: bottom];
+
+ if (firstVisibleRow == -1)
+ firstVisibleRow = 0;
+
+ if (lastVisibleRow == -1)
+ lastVisibleRow = _numberOfColumns - 1;
+
+ for (j = firstVisibleRow; j < lastVisibleRow; j++)
+ {
+ if ([self _dataCellForTableColumn: tb row: j] == aCell)
+ {
+ rowRect = [self rectOfRow: j];
+ [self setNeedsDisplayInRect:
+ NSIntersectionRect(columnRect, rowRect)];
+ }
+ }
+ }
}
}
- (void) _userResizedTableColumn: (int)index
- width: (float)width
+ width: (float)width
{
- [[_tableColumns objectAtIndex: index] setWidth: width];
+ [[_tableColumns objectAtIndex: index] setWidth: width];
}
- (float *) _columnOrigins
{
- return _columnOrigins;
+ return _columnOrigins;
}
- (void) _mouseDownInHeaderOfTableColumn: (NSTableColumn *)tc
{
- if ([_delegate
- respondsToSelector:
- @selector(tableView:mouseDownInHeaderOfTableColumn:)])
+ if ([_delegate
+ respondsToSelector:
+ @selector(tableView:mouseDownInHeaderOfTableColumn:)])
{
- [_delegate tableView: self
-mouseDownInHeaderOfTableColumn: tc];
+ [_delegate tableView: self
+ mouseDownInHeaderOfTableColumn: tc];
}
}
- (void) _clickTableColumn: (NSTableColumn *)tc
{
- NSSortDescriptor *oldMainSortDescriptor = nil;
- NSSortDescriptor *newMainSortDescriptor = [tc sortDescriptorPrototype];
- NSMutableArray *newSortDescriptors =
+ NSSortDescriptor *oldMainSortDescriptor = nil;
+ NSSortDescriptor *newMainSortDescriptor = [tc sortDescriptorPrototype];
+ NSMutableArray *newSortDescriptors =
[NSMutableArray arrayWithArray: [self sortDescriptors]];
- NSEnumerator *e = [newSortDescriptors objectEnumerator];
- NSSortDescriptor *descriptor = nil;
- NSMutableArray *outdatedDescriptors = [NSMutableArray array];
-
- if ([[self sortDescriptors] count] > 0)
+ NSEnumerator *e = [newSortDescriptors objectEnumerator];
+ NSSortDescriptor *descriptor = nil;
+ NSMutableArray *outdatedDescriptors = [NSMutableArray array];
+
+ if ([[self sortDescriptors] count] > 0)
{
- oldMainSortDescriptor = [[self sortDescriptors] objectAtIndex: 0];
+ oldMainSortDescriptor = [[self sortDescriptors] objectAtIndex: 0];
}
-
- /* Remove every main descriptor equivalents (normally only one) */
- while ((descriptor = [e nextObject]) != nil)
+
+ /* Remove every main descriptor equivalents (normally only one) */
+ while ((descriptor = [e nextObject]) != nil)
{
- if ([[descriptor key] isEqual: [newMainSortDescriptor key]])
- [outdatedDescriptors addObject: descriptor];
+ if ([[descriptor key] isEqual: [newMainSortDescriptor key]])
+ [outdatedDescriptors addObject: descriptor];
}
-
- /* Invert the sort direction when the same column header is clicked twice */
- if ([[newMainSortDescriptor key] isEqual: [oldMainSortDescriptor key]])
+
+ /* Invert the sort direction when the same column header is clicked twice */
+ if ([[newMainSortDescriptor key] isEqual: [oldMainSortDescriptor key]])
{
- newMainSortDescriptor = [oldMainSortDescriptor reversedSortDescriptor];
+ newMainSortDescriptor = [oldMainSortDescriptor reversedSortDescriptor];
}
-
- [newSortDescriptors removeObjectsInArray: outdatedDescriptors];
- if (newMainSortDescriptor != nil)
- [newSortDescriptors insertObject: newMainSortDescriptor atIndex: 0];
-
- [self setSortDescriptors: newSortDescriptors];
-
- [self _didClickTableColumn: tc];
+
+ [newSortDescriptors removeObjectsInArray: outdatedDescriptors];
+ if (newMainSortDescriptor != nil)
+ [newSortDescriptors insertObject: newMainSortDescriptor atIndex: 0];
+
+ [self setSortDescriptors: newSortDescriptors];
+
+ [self _didClickTableColumn: tc];
}
- (void) _editNextCellAfterRow: (int) row
- inColumn: (int) column
+ inColumn: (int) column
{
- if (++row >= _numberOfRows)
- row = 0;
-
- if ([self _shouldSelectRow: row])
+ if (++row >= _numberOfRows)
+ row = 0;
+
+ if ([self _shouldSelectRow: row])
{
- [self selectRowIndexes: [NSIndexSet indexSetWithIndex: row]
+ [self selectRowIndexes: [NSIndexSet indexSetWithIndex: row]
byExtendingSelection: NO];
-
- if ([self _isCellEditableColumn: column row:row])
+
+ if ([self _isCellEditableColumn: column row:row])
{
- [self editColumn: column
- row: row
- withEvent: nil
- select: YES];
+ [self editColumn: column
+ row: row
+ withEvent: nil
+ select: YES];
}
}
}
@@ -5880,558 +5832,545 @@ mouseDownInHeaderOfTableColumn: tc];
-(BOOL) _editNextEditableCellAfterRow: (int)row
column: (int)column
{
- int i, j;
-
- if (row > -1)
+ int i, j;
+
+ if (row > -1)
{
- // First look for cells in the same row
- for (j = column + 1; j < _numberOfColumns; j++)
+ // First look for cells in the same row
+ for (j = column + 1; j < _numberOfColumns; j++)
{
- if ([self _isCellEditableColumn: j row: row])
+ if ([self _isCellEditableColumn: j row: row])
{
- [self editColumn: j row: row withEvent: nil select: YES];
- return YES;
+ [self editColumn: j row: row withEvent: nil select: YES];
+ return YES;
}
}
}
-
- // Otherwise, make the big cycle.
- for (i = row + 1; i < _numberOfRows; i++)
+
+ // Otherwise, make the big cycle.
+ for (i = row + 1; i < _numberOfRows; i++)
{
- for (j = 0; j < _numberOfColumns; j++)
+ for (j = 0; j < _numberOfColumns; j++)
{
- if ([self _isCellEditableColumn: j row: i])
+ if ([self _isCellEditableColumn: j row: i])
{
- // Need to select row to be able to edit it.
- [self selectRow: i byExtendingSelection: NO];
- [self editColumn: j row: i withEvent: nil select: YES];
- return YES;
+ // Need to select row to be able to edit it.
+ [self selectRow: i byExtendingSelection: NO];
+ [self editColumn: j row: i withEvent: nil select: YES];
+ return YES;
}
}
}
-
- // Should we loop around or not?
+
+// Should we loop around or not?
#if 0
- // Nothing found? Search in the rows before the current
- for (i = 0; i < row; i++)
+ // Nothing found? Search in the rows before the current
+ for (i = 0; i < row; i++)
{
- for (j = 0; j < _numberOfColumns; j++)
+ for (j = 0; j < _numberOfColumns; j++)
{
- if ([self _isCellEditableColumn: j row: i])
+ if ([self _isCellEditableColumn: j row: i])
{
- // Need to select row to be able to edit it.
- [self selectRow: i byExtendingSelection: NO];
- [self editColumn: j row: i withEvent: nil select: YES];
- return YES;
+ // Need to select row to be able to edit it.
+ [self selectRow: i byExtendingSelection: NO];
+ [self editColumn: j row: i withEvent: nil select: YES];
+ return YES;
}
}
}
-
- // Still nothing? Look at the beginning of the current row
- if (row > -1)
+
+ // Still nothing? Look at the beginning of the current row
+ if (row > -1)
{
- // First look for cells in the same row
- for (j = 0; j < column; j++)
+ // First look for cells in the same row
+ for (j = 0; j < column; j++)
{
- if ([self _isCellEditableColumn: j row: row])
+ if ([self _isCellEditableColumn: j row: row])
{
- [self editColumn: j row: row withEvent: nil select: YES];
- return YES;
+ [self editColumn: j row: row withEvent: nil select: YES];
+ return YES;
}
}
}
#endif
-
- return NO;
+
+ return NO;
}
-(BOOL) _editPreviousEditableCellBeforeRow: (int)row
- column: (int)column
+ column: (int)column
{
- int i, j;
-
- if (row > -1)
+ int i, j;
+
+ if (row > -1)
{
- // First look for cells in the same row
- for (j = column - 1; j > -1; j--)
+ // First look for cells in the same row
+ for (j = column - 1; j > -1; j--)
{
- if ([self _isCellEditableColumn: j row: row])
+ if ([self _isCellEditableColumn: j row: row])
{
- [self editColumn: j row: row withEvent: nil select: YES];
- return YES;
+ [self editColumn: j row: row withEvent: nil select: YES];
+ return YES;
}
}
}
-
- // Otherwise, make the big cycle.
- for (i = row - 1; i > -1; i--)
+
+ // Otherwise, make the big cycle.
+ for (i = row - 1; i > -1; i--)
{
- for (j = _numberOfColumns - 1; j > -1; j--)
+ for (j = _numberOfColumns - 1; j > -1; j--)
{
- if ([self _isCellEditableColumn: j row: i])
+ if ([self _isCellEditableColumn: j row: i])
{
- // Need to select row to be able to edit it.
- [self selectRow: i byExtendingSelection: NO];
- [self editColumn: j row: i withEvent: nil select: YES];
- return YES;
+ // Need to select row to be able to edit it.
+ [self selectRow: i byExtendingSelection: NO];
+ [self editColumn: j row: i withEvent: nil select: YES];
+ return YES;
}
}
}
-
- // Should we loop around or not?
+
+// Should we loop around or not?
#if 0
- // Nothing found? Search in the rows after the current
- for (i = _numberOfRows - 1; i > row; i--)
+ // Nothing found? Search in the rows after the current
+ for (i = _numberOfRows - 1; i > row; i--)
{
- for (j = _numberOfColumns - 1; j > -1; j--)
+ for (j = _numberOfColumns - 1; j > -1; j--)
{
- if ([self _isCellEditableColumn: j row: i])
+ if ([self _isCellEditableColumn: j row: i])
{
- // Need to select row to be able to edit it.
- [self selectRow: i byExtendingSelection: NO];
- [self editColumn: j row: i withEvent: nil select: YES];
- return YES;
+ // Need to select row to be able to edit it.
+ [self selectRow: i byExtendingSelection: NO];
+ [self editColumn: j row: i withEvent: nil select: YES];
+ return YES;
}
}
}
-
- // Still nothing? Look at the end of the current row
- if (row > -1)
+
+ // Still nothing? Look at the end of the current row
+ if (row > -1)
{
- // First look for cells in the same row
- for (j = _numberOfColumns - 1; j > column; j++)
+ // First look for cells in the same row
+ for (j = _numberOfColumns - 1; j > column; j++)
{
- if ([self _isCellEditableColumn: j row: row])
+ if ([self _isCellEditableColumn: j row: row])
{
- [self editColumn: j row: row withEvent: nil select: YES];
- return YES;
+ [self editColumn: j row: row withEvent: nil select: YES];
+ return YES;
}
}
}
#endif
-
- return NO;
+
+ return NO;
}
- (void) _autosaveTableColumns
{
- if (_autosaveTableColumns && _autosaveName != nil)
+ if (_autosaveTableColumns && _autosaveName != nil)
{
- NSUserDefaults *defaults;
- NSString *tableKey;
- NSMutableDictionary *config;
- NSTableColumn *column;
- id en;
-
- defaults = [NSUserDefaults standardUserDefaults];
- tableKey = [NSString stringWithFormat: @"NSTableView Columns %@",
- _autosaveName];
- config = [NSMutableDictionary new];
-
- en = [[self tableColumns] objectEnumerator];
- while ((column = [en nextObject]) != nil)
- {
- NSArray *array;
- NSNumber *width, *identNum;
- NSObject *ident;
-
- width = [NSNumber numberWithInt: [column width]];
- ident = [column identifier];
- identNum = [NSNumber numberWithInt: [self columnWithIdentifier:
- ident]];
- array = [NSArray arrayWithObjects: width, identNum, nil];
- [config setObject: array forKey: ident];
- }
- [defaults setObject: config forKey: tableKey];
- [defaults synchronize];
- RELEASE (config);
+ NSUserDefaults *defaults;
+ NSString *tableKey;
+ NSMutableDictionary *config;
+ NSTableColumn *column;
+ id en;
+
+ defaults = [NSUserDefaults standardUserDefaults];
+ tableKey = [NSString stringWithFormat: @"NSTableView Columns %@",
+ _autosaveName];
+ config = [NSMutableDictionary new];
+
+ en = [[self tableColumns] objectEnumerator];
+ while ((column = [en nextObject]) != nil)
+ {
+ NSArray *array;
+ NSNumber *width, *identNum;
+ NSObject *ident;
+
+ width = [NSNumber numberWithInt: [column width]];
+ ident = [column identifier];
+ identNum = [NSNumber numberWithInt: [self columnWithIdentifier:
+ ident]];
+ array = [NSArray arrayWithObjects: width, identNum, nil];
+ [config setObject: array forKey: ident];
+ }
+ [defaults setObject: config forKey: tableKey];
+ [defaults synchronize];
+ RELEASE (config);
}
}
- (void) _autoloadTableColumns
{
- if (_autosaveTableColumns && _autosaveName != nil)
+ if (_autosaveTableColumns && _autosaveName != nil)
{
- NSUserDefaults *defaults;
- NSDictionary *config;
- NSString *tableKey;
-
- defaults = [NSUserDefaults standardUserDefaults];
- tableKey = [NSString stringWithFormat: @"NSTableView Columns %@",
- _autosaveName];
- config = [defaults objectForKey: tableKey];
- if (config != nil)
- {
- NSEnumerator *en = [[config allKeys] objectEnumerator];
- NSString *colKey;
- NSArray *colDesc;
- NSTableColumn *col;
-
- while ((colKey = [en nextObject]) != nil)
- {
- col = [self tableColumnWithIdentifier: colKey];
-
- if (col != nil)
- {
- colDesc = [config objectForKey: colKey];
- [col setWidth: [[colDesc objectAtIndex: 0] intValue]];
- [self moveColumn: [self columnWithIdentifier: colKey]
- toColumn: [[colDesc objectAtIndex: 1] intValue]];
- }
- }
- }
+ NSUserDefaults *defaults;
+ NSDictionary *config;
+ NSString *tableKey;
+
+ defaults = [NSUserDefaults standardUserDefaults];
+ tableKey = [NSString stringWithFormat: @"NSTableView Columns %@",
+ _autosaveName];
+ config = [defaults objectForKey: tableKey];
+ if (config != nil)
+ {
+ NSEnumerator *en = [[config allKeys] objectEnumerator];
+ NSString *colKey;
+ NSArray *colDesc;
+ NSTableColumn *col;
+
+ while ((colKey = [en nextObject]) != nil)
+ {
+ col = [self tableColumnWithIdentifier: colKey];
+
+ if (col != nil)
+ {
+ colDesc = [config objectForKey: colKey];
+ [col setWidth: [[colDesc objectAtIndex: 0] intValue]];
+ [self moveColumn: [self columnWithIdentifier: colKey]
+ toColumn: [[colDesc objectAtIndex: 1] intValue]];
+ }
+ }
+ }
}
}
- (NSCell *) _dataCellForTableColumn: (NSTableColumn *)tb
row: (int) rowIndex
{
- NSCell *cell = nil;
- if ([_delegate respondsToSelector:
- @selector(tableView:dataCellForTableColumn:row:)])
+ NSCell *cell = nil;
+ if ([_delegate respondsToSelector:
+ @selector(tableView:dataCellForTableColumn:row:)])
{
- cell = [_delegate tableView: self
- dataCellForTableColumn: tb
- row: rowIndex];
+ cell = [_delegate tableView: self
+ dataCellForTableColumn: tb
+ row: rowIndex];
}
- if (cell == nil)
+ if (cell == nil)
{
- cell = [tb dataCellForRow: rowIndex];
+ cell = [tb dataCellForRow: rowIndex];
}
- return cell;
-}
-
-- (NSString *) _objectStringForTableColum:(NSTableColumn *)column item:(int)row
-{
- NSString *draggedItemString = nil;
- if ([_dataSource respondsToSelector:@selector(tableView:objectValueForTableColumn:byItem:)]) {
- id draggedObject = [_dataSource tableView:self
- objectValueForTableColumn:column
- row:row];
-
- draggedItemString = [draggedObject description];
- }
- return draggedItemString;
+ return cell;
}
- (void) superviewFrameChanged: (NSNotification*)aNotification
{
- if (_autoresizesAllColumnsToFit == YES)
+ if (_autoresizesAllColumnsToFit == YES)
{
- float visible_width = [self convertRect: [_super_view bounds]
- fromView: _super_view].size.width;
- float table_width = 0;
-
- if (_numberOfColumns > 0)
+ float visible_width = [self convertRect: [_super_view bounds]
+ fromView: _super_view].size.width;
+ float table_width = 0;
+
+ if (_numberOfColumns > 0)
{
- table_width =
+ table_width =
_columnOrigins[_numberOfColumns - 1] +
[[_tableColumns objectAtIndex: _numberOfColumns - 1] width];
}
-
- /*
- NSLog(@"columnOrigins[0] %f", _columnOrigins[0]);
- NSLog(@"superview.bounds %@",
- NSStringFromRect([_super_view bounds]));
- NSLog(@"superview.frame %@",
- NSStringFromRect([_super_view frame]));
- NSLog(@"table_width %f", table_width);
- NSLog(@"width %f", visible_width);
- NSLog(@"_superview_width %f", _superview_width);
- */
-
- if (table_width - _superview_width <= 0.001
- && table_width - _superview_width >= -0.001)
- {
- // the last column had been sized to fit
- [self sizeToFit];
- }
- else if (table_width <= _superview_width
- && table_width >= visible_width)
- {
- // the tableView was too small and is now too large
- [self sizeToFit];
- }
- else if (table_width >= _superview_width
- && table_width <= visible_width)
- {
- // the tableView was too large and is now too small
- if (_numberOfColumns > 0)
- [self scrollColumnToVisible: 0];
- [self sizeToFit];
- }
- _superview_width = visible_width;
+
+ /*
+ NSLog(@"columnOrigins[0] %f", _columnOrigins[0]);
+ NSLog(@"superview.bounds %@",
+ NSStringFromRect([_super_view bounds]));
+ NSLog(@"superview.frame %@",
+ NSStringFromRect([_super_view frame]));
+ NSLog(@"table_width %f", table_width);
+ NSLog(@"width %f", visible_width);
+ NSLog(@"_superview_width %f", _superview_width);
+ */
+
+ if (table_width - _superview_width <= 0.001
+ && table_width - _superview_width >= -0.001)
+ {
+ // the last column had been sized to fit
+ [self sizeToFit];
+ }
+ else if (table_width <= _superview_width
+ && table_width >= visible_width)
+ {
+ // the tableView was too small and is now too large
+ [self sizeToFit];
+ }
+ else if (table_width >= _superview_width
+ && table_width <= visible_width)
+ {
+ // the tableView was too large and is now too small
+ if (_numberOfColumns > 0)
+ [self scrollColumnToVisible: 0];
+ [self sizeToFit];
+ }
+ _superview_width = visible_width;
}
- else
+ else
{
- float visible_width = [self convertRect: [_super_view bounds]
- fromView: _super_view].size.width;
- float table_width = 0;
-
- if (_numberOfColumns > 0)
+ float visible_width = [self convertRect: [_super_view bounds]
+ fromView: _super_view].size.width;
+ float table_width = 0;
+
+ if (_numberOfColumns > 0)
{
- table_width =
+ table_width =
_columnOrigins[_numberOfColumns - 1] +
[[_tableColumns objectAtIndex: _numberOfColumns - 1] width];
}
-
- /*
- NSLog(@"columnOrigins[0] %f", _columnOrigins[0]);
- NSLog(@"superview.bounds %@",
- NSStringFromRect([_super_view bounds]));
- NSLog(@"superview.frame %@",
- NSStringFromRect([_super_view frame]));
- NSLog(@"table_width %f", table_width);
- NSLog(@"width %f", visible_width);
- NSLog(@"_superview_width %f", _superview_width);
- */
-
- if (table_width - _superview_width <= 0.001
- && table_width - _superview_width >= -0.001)
- {
- // the last column had been sized to fit
- [self sizeLastColumnToFit];
- }
- else if (table_width <= _superview_width
- && table_width >= visible_width)
- {
- // the tableView was too small and is now too large
- [self sizeLastColumnToFit];
- }
- else if (table_width >= _superview_width
- && table_width <= visible_width)
- {
- // the tableView was too large and is now too small
- if (_numberOfColumns > 0)
- [self scrollColumnToVisible: 0];
- [self sizeLastColumnToFit];
- }
- _superview_width = visible_width;
+
+ /*
+ NSLog(@"columnOrigins[0] %f", _columnOrigins[0]);
+ NSLog(@"superview.bounds %@",
+ NSStringFromRect([_super_view bounds]));
+ NSLog(@"superview.frame %@",
+ NSStringFromRect([_super_view frame]));
+ NSLog(@"table_width %f", table_width);
+ NSLog(@"width %f", visible_width);
+ NSLog(@"_superview_width %f", _superview_width);
+ */
+
+ if (table_width - _superview_width <= 0.001
+ && table_width - _superview_width >= -0.001)
+ {
+ // the last column had been sized to fit
+ [self sizeLastColumnToFit];
+ }
+ else if (table_width <= _superview_width
+ && table_width >= visible_width)
+ {
+ // the tableView was too small and is now too large
+ [self sizeLastColumnToFit];
+ }
+ else if (table_width >= _superview_width
+ && table_width <= visible_width)
+ {
+ // the tableView was too large and is now too small
+ if (_numberOfColumns > 0)
+ [self scrollColumnToVisible: 0];
+ [self sizeLastColumnToFit];
+ }
+ _superview_width = visible_width;
}
- [self setFrame:_frame];
+ [self setFrame:_frame];
}
- (NSDragOperation) draggingSourceOperationMaskForLocal: (BOOL)isLocal
{
- if (isLocal)
+ if (isLocal)
{
- return _draggingSourceOperationMaskForLocal;
+ return _draggingSourceOperationMaskForLocal;
}
- else
+ else
{
- return _draggingSourceOperationMaskForRemote;
+ return _draggingSourceOperationMaskForRemote;
}
}
- (void) setDraggingSourceOperationMask: (NSDragOperation)mask
forLocal: (BOOL)isLocal
{
- if (isLocal)
+ if (isLocal)
{
- _draggingSourceOperationMaskForLocal = mask;
+ _draggingSourceOperationMaskForLocal = mask;
}
- else
+ else
{
- _draggingSourceOperationMaskForRemote = mask;
+ _draggingSourceOperationMaskForRemote = mask;
}
}
- (NSDragOperation) draggingEntered: (id ) sender
{
- currentDropRow = -1;
- currentDropOperation = -1;
- oldDropRow = -1;
- lastQuarterPosition = -1;
- oldDraggingRect = NSMakeRect(0.,0., 0., 0.);
- currentDragOperation = NSDragOperationEvery;
- return currentDragOperation;
+ currentDropRow = -1;
+ currentDropOperation = -1;
+ oldDropRow = -1;
+ lastQuarterPosition = -1;
+ oldDraggingRect = NSMakeRect(0.,0., 0., 0.);
+ currentDragOperation = NSDragOperationEvery;
+ return currentDragOperation;
}
- (void) draggingExited: (id ) sender
{
- [self setNeedsDisplayInRect: oldDraggingRect];
- [self displayIfNeeded];
+ [self setNeedsDisplayInRect: oldDraggingRect];
+ [self displayIfNeeded];
}
- (NSDragOperation) draggingUpdated: (id ) sender
{
- NSPoint p = [sender draggingLocation];
- NSRect newRect;
- int row;
- int quarterPosition, positionInRow;
- int currentRow;
- NSDragOperation dragOperation;
-
- p = [self convertPoint: p fromView: nil];
- /* This is a crude method of scrolling the view while dragging so
+ NSPoint p = [sender draggingLocation];
+ NSRect newRect;
+ int row;
+ int quarterPosition, positionInRow;
+ int currentRow;
+ NSDragOperation dragOperation;
+
+ p = [self convertPoint: p fromView: nil];
+ /* This is a crude method of scrolling the view while dragging so
the user can drag to any cell even if it's not
visible. Unfortunately we don't receive events when the drag is
outside the view, so the pointer must still be in the view to
drag.
- */
- if (p.y < NSMinY([self visibleRect])+3)
+ */
+ if (p.y < NSMinY([self visibleRect])+3)
{
- currentRow = [self rowAtPoint: p] - 1;
- if (currentRow > 0)
- [self scrollRowToVisible: currentRow];
+ currentRow = [self rowAtPoint: p] - 1;
+ if (currentRow > 0)
+ [self scrollRowToVisible: currentRow];
}
- else if (p.y > NSMaxY([self visibleRect])-3)
+ else if (p.y > NSMaxY([self visibleRect])-3)
{
- currentRow = [self rowAtPoint: p] + 1;
- if (currentRow < _numberOfRows)
- [self scrollRowToVisible: currentRow];
+ currentRow = [self rowAtPoint: p] + 1;
+ if (currentRow < _numberOfRows)
+ [self scrollRowToVisible: currentRow];
}
-
- positionInRow = (int)(p.y - _bounds.origin.y) % (int)_rowHeight;
- quarterPosition = (p.y - _bounds.origin.y) / _rowHeight * 4.;
-
- if ((quarterPosition - oldDropRow * 4 <= 2) &&
- (quarterPosition - oldDropRow * 4 >= -3))
+
+ positionInRow = (int)(p.y - _bounds.origin.y) % (int)_rowHeight;
+ quarterPosition = (p.y - _bounds.origin.y) / _rowHeight * 4.;
+
+ if ((quarterPosition - oldDropRow * 4 <= 2) &&
+ (quarterPosition - oldDropRow * 4 >= -3))
{
- row = oldDropRow;
+ row = oldDropRow;
}
- else
+ else
{
- row = (quarterPosition + 2) / 4;
+ row = (quarterPosition + 2) / 4;
}
-
- // Are we in the two middle quarters of the row? Use TableViewDropOn
- if ((positionInRow > _rowHeight / 4 && positionInRow <= (3 * _rowHeight) / 4)
- || row > _numberOfRows)
+
+ // Are we in the two middle quarters of the row? Use TableViewDropOn
+ if ((positionInRow > _rowHeight / 4 && positionInRow <= (3 * _rowHeight) / 4)
+ || row > _numberOfRows)
{
- currentDropRow = (int)(p.y - _bounds.origin.y) / (int)_rowHeight;
- currentDropOperation = NSTableViewDropOn;
- if (currentDropRow >= _numberOfRows)
- currentDropRow = -1;
+ currentDropRow = (int)(p.y - _bounds.origin.y) / (int)_rowHeight;
+ currentDropOperation = NSTableViewDropOn;
+ if (currentDropRow >= _numberOfRows)
+ currentDropRow = -1;
}
- else // drop above
+ else // drop above
{
- currentDropRow = row;
- currentDropOperation = NSTableViewDropAbove;
+ currentDropRow = row;
+ currentDropOperation = NSTableViewDropAbove;
}
-
- dragOperation = [sender draggingSourceOperationMask];
- if ((lastQuarterPosition != quarterPosition)
- || (currentDragOperation != dragOperation))
+
+ dragOperation = [sender draggingSourceOperationMask];
+ if ((lastQuarterPosition != quarterPosition)
+ || (currentDragOperation != dragOperation))
{
- currentDragOperation = dragOperation;
- if ([_dataSource respondsToSelector:
+ currentDragOperation = dragOperation;
+ if ([_dataSource respondsToSelector:
@selector(tableView:validateDrop:proposedRow:proposedDropOperation:)])
{
- currentDragOperation = [_dataSource tableView: self
- validateDrop: sender
+ currentDragOperation = [_dataSource tableView: self
+ validateDrop: sender
proposedRow: currentDropRow
- proposedDropOperation: currentDropOperation];
- }
-
- lastQuarterPosition = quarterPosition;
-
- if ((currentDropRow != oldDropRow) || (currentDropOperation != oldDropOperation))
- {
- [self lockFocus];
-
- [self setNeedsDisplayInRect: oldDraggingRect];
- [self displayIfNeeded];
-
- [[NSColor darkGrayColor] set];
-
- if (currentDropRow == -1)
- {
- newRect = [self bounds];
- NSFrameRectWithWidth(newRect, 2.0);
- oldDraggingRect = newRect;
- currentDropRow = _numberOfRows;
- }
- else if (currentDropOperation == NSTableViewDropAbove)
- {
- if (currentDropRow == 0)
- {
- newRect = NSMakeRect([self visibleRect].origin.x,
- currentDropRow * _rowHeight,
- [self visibleRect].size.width,
- 3);
- }
- else if (currentDropRow == _numberOfRows)
- {
- newRect = NSMakeRect([self visibleRect].origin.x,
- currentDropRow * _rowHeight - 2,
- [self visibleRect].size.width,
- 3);
- }
- else
- {
- newRect = NSMakeRect([self visibleRect].origin.x,
- currentDropRow * _rowHeight - 1,
- [self visibleRect].size.width,
- 3);
- }
- NSRectFill(newRect);
- oldDraggingRect = newRect;
- }
- else
- {
- newRect = [self frameOfCellAtColumn: 0
- row: currentDropRow];
- newRect.origin.x = _bounds.origin.x;
- newRect.size.width = _bounds.size.width + 2;
- newRect.origin.x -= _intercellSpacing.height / 2;
- newRect.size.height += _intercellSpacing.height;
- oldDraggingRect = newRect;
- oldDraggingRect.origin.y -= 1;
- oldDraggingRect.size.height += 2;
-
- newRect.size.height -= 1;
-
- newRect.origin.x += 3;
- newRect.size.width -= 3;
-
- if (_drawsGrid)
- {
- //newRect.origin.y += 1;
- //newRect.origin.x += 1;
- //newRect.size.width -= 2;
- newRect.size.height += 1;
- }
- else
- {
- }
-
- NSFrameRectWithWidth(newRect, 2.0);
- // NSRectFill(newRect);
-
- }
- [_window flushWindow];
-
- [self unlockFocus];
-
- oldDropRow = currentDropRow;
- oldDropOperation = currentDropOperation;
+ proposedDropOperation: currentDropOperation];
}
+
+ lastQuarterPosition = quarterPosition;
+
+ if ((currentDropRow != oldDropRow) || (currentDropOperation != oldDropOperation))
+ {
+ [self lockFocus];
+
+ [self setNeedsDisplayInRect: oldDraggingRect];
+ [self displayIfNeeded];
+
+ [[NSColor darkGrayColor] set];
+
+ if (currentDropRow == -1)
+ {
+ newRect = [self bounds];
+ NSFrameRectWithWidth(newRect, 2.0);
+ oldDraggingRect = newRect;
+ currentDropRow = _numberOfRows;
+ }
+ else if (currentDropOperation == NSTableViewDropAbove)
+ {
+ if (currentDropRow == 0)
+ {
+ newRect = NSMakeRect([self visibleRect].origin.x,
+ currentDropRow * _rowHeight,
+ [self visibleRect].size.width,
+ 3);
+ }
+ else if (currentDropRow == _numberOfRows)
+ {
+ newRect = NSMakeRect([self visibleRect].origin.x,
+ currentDropRow * _rowHeight - 2,
+ [self visibleRect].size.width,
+ 3);
+ }
+ else
+ {
+ newRect = NSMakeRect([self visibleRect].origin.x,
+ currentDropRow * _rowHeight - 1,
+ [self visibleRect].size.width,
+ 3);
+ }
+ NSRectFill(newRect);
+ oldDraggingRect = newRect;
+ }
+ else
+ {
+ newRect = [self frameOfCellAtColumn: 0
+ row: currentDropRow];
+ newRect.origin.x = _bounds.origin.x;
+ newRect.size.width = _bounds.size.width + 2;
+ newRect.origin.x -= _intercellSpacing.height / 2;
+ newRect.size.height += _intercellSpacing.height;
+ oldDraggingRect = newRect;
+ oldDraggingRect.origin.y -= 1;
+ oldDraggingRect.size.height += 2;
+
+ newRect.size.height -= 1;
+
+ newRect.origin.x += 3;
+ newRect.size.width -= 3;
+
+ if (_drawsGrid)
+ {
+ //newRect.origin.y += 1;
+ //newRect.origin.x += 1;
+ //newRect.size.width -= 2;
+ newRect.size.height += 1;
+ }
+ else
+ {
+ }
+
+ NSFrameRectWithWidth(newRect, 2.0);
+ // NSRectFill(newRect);
+
+ }
+ [_window flushWindow];
+
+ [self unlockFocus];
+
+ oldDropRow = currentDropRow;
+ oldDropOperation = currentDropOperation;
+ }
}
-
-
- return currentDragOperation;
+
+
+ return currentDragOperation;
}
- (BOOL) performDragOperation: (id)sender
{
- if ([_dataSource respondsToSelector: @selector(tableView:acceptDrop:row:dropOperation:)])
+ if ([_dataSource respondsToSelector: @selector(tableView:acceptDrop:row:dropOperation:)])
{
- return [_dataSource tableView: self
- acceptDrop: sender
- row: currentDropRow
- dropOperation: currentDropOperation];
+ return [_dataSource tableView: self
+ acceptDrop: sender
+ row: currentDropRow
+ dropOperation: currentDropOperation];
}
- else
- return NO;
+ else
+ return NO;
}
- (BOOL) prepareForDragOperation: (id)sender
{
- [self setNeedsDisplayInRect: oldDraggingRect];
- [self displayIfNeeded];
-
- return YES;
+ [self setNeedsDisplayInRect: oldDraggingRect];
+ [self displayIfNeeded];
+
+ return YES;
}
- (void) concludeDragOperation:(id )sender
@@ -6441,7 +6380,7 @@ mouseDownInHeaderOfTableColumn: tc];
- (BOOL) canDragRowsWithIndexes: (NSIndexSet *)indexes
atPoint: (NSPoint)point
{
- return YES;
+ return YES;
}
/*
@@ -6449,57 +6388,57 @@ mouseDownInHeaderOfTableColumn: tc];
*/
/** Sets the sort descriptors used to sort the rows and delegates the sorting
- to -tableView:didChangeSortDescriptors or -outlineView:didChangeSortDescriptors:
- in NSOutlineView.
+to -tableView:didChangeSortDescriptors or -outlineView:didChangeSortDescriptors:
+in NSOutlineView.
+
+The delegate methods can retrieve the new sort descriptors with
+-sortDescriptors and override them with -setSortDescriptors:.
+The first object in the new sort descriptor array is the sort descriptor
+prototype returned by the table column whose header was the last clicked.
+See -[NSTableColumn sortDescriptorPrototype].
- The delegate methods can retrieve the new sort descriptors with
- -sortDescriptors and override them with -setSortDescriptors:.
- The first object in the new sort descriptor array is the sort descriptor
- prototype returned by the table column whose header was the last clicked.
- See -[NSTableColumn sortDescriptorPrototype].
-
- This method is called automatically when you click on a table column header,
- so you shouldn't need to call it usually.
-
- Take note the sort descriptors are encoded by the keyed archiving (rarely used
- since neither IB or Gorm support to set these directly). */
+This method is called automatically when you click on a table column header,
+so you shouldn't need to call it usually.
+
+Take note the sort descriptors are encoded by the keyed archiving (rarely used
+since neither IB or Gorm support to set these directly). */
- (void) setSortDescriptors: (NSArray *)sortDescriptors
{
- NSArray *oldSortDescriptors = [self sortDescriptors];
- NSArray *newSortDescriptors = nil;
-
- /* To replicate precisely the Cocoa behavior */
- if (sortDescriptors == nil)
+ NSArray *oldSortDescriptors = [self sortDescriptors];
+ NSArray *newSortDescriptors = nil;
+
+ /* To replicate precisely the Cocoa behavior */
+ if (sortDescriptors == nil)
{
- newSortDescriptors = [NSArray array];
+ newSortDescriptors = [NSArray array];
}
- else
+ else
{
- /* _sortDescriptors must remain immutable since -sortDescriptors doesn't
+ /* _sortDescriptors must remain immutable since -sortDescriptors doesn't
return a defensive copy */
- newSortDescriptors = [NSArray arrayWithArray: sortDescriptors];
+ newSortDescriptors = [NSArray arrayWithArray: sortDescriptors];
}
-
- if ([newSortDescriptors isEqual: oldSortDescriptors])
- return;
-
- RETAIN(oldSortDescriptors);
-
- ASSIGN(_sortDescriptors, newSortDescriptors);
- [self _didChangeSortDescriptors: oldSortDescriptors];
-
- RELEASE(oldSortDescriptors);
+
+ if ([newSortDescriptors isEqual: oldSortDescriptors])
+ return;
+
+ RETAIN(oldSortDescriptors);
+
+ ASSIGN(_sortDescriptors, newSortDescriptors);
+ [self _didChangeSortDescriptors: oldSortDescriptors];
+
+ RELEASE(oldSortDescriptors);
}
/** Returns the current sort descriptors, usually updated every time a click
- happens on a table column header.
-
- By default, returns an empty array.
-
- For a more detailed explanation, -setSortDescriptors:. */
+happens on a table column header.
+
+By default, returns an empty array.
+
+For a more detailed explanation, -setSortDescriptors:. */
- (NSArray *)sortDescriptors
{
- return _sortDescriptors;
+ return _sortDescriptors;
}
/*
@@ -6507,8 +6446,8 @@ mouseDownInHeaderOfTableColumn: tc];
*/
- (BOOL) validateUserInterfaceItem: (id )anItem
{
- // FIXME
- return YES;
+ // FIXME
+ return YES;
}
/*
@@ -6516,180 +6455,180 @@ mouseDownInHeaderOfTableColumn: tc];
*/
- (void) _postSelectionIsChangingNotification
{
- [nc postNotificationName: NSTableViewSelectionIsChangingNotification
- object: self];
+ [nc postNotificationName: NSTableViewSelectionIsChangingNotification
+ object: self];
}
- (void) _postSelectionDidChangeNotification
{
- [nc postNotificationName: NSTableViewSelectionDidChangeNotification
- object: self];
+ [nc postNotificationName: NSTableViewSelectionDidChangeNotification
+ object: self];
}
- (void) _postColumnDidMoveNotificationWithOldIndex: (int) oldIndex
- newIndex: (int) newIndex
+ newIndex: (int) newIndex
{
- [nc postNotificationName: NSTableViewColumnDidMoveNotification
- object: self
- userInfo: [NSDictionary
- dictionaryWithObjectsAndKeys:
- [NSNumber numberWithInt: newIndex],
- @"NSNewColumn",
- [NSNumber numberWithInt: oldIndex],
- @"NSOldColumn",
- nil]];
+ [nc postNotificationName: NSTableViewColumnDidMoveNotification
+ object: self
+ userInfo: [NSDictionary
+ dictionaryWithObjectsAndKeys:
+ [NSNumber numberWithInt: newIndex],
+ @"NSNewColumn",
+ [NSNumber numberWithInt: oldIndex],
+ @"NSOldColumn",
+ nil]];
}
- (void) _postColumnDidResizeNotificationWithOldWidth: (float) oldWidth
{
- [nc postNotificationName:
- NSTableViewColumnDidResizeNotification
- object: self
- userInfo: [NSDictionary
- dictionaryWithObjectsAndKeys:
- [NSNumber numberWithFloat: oldWidth],
- @"NSOldWidth",
- nil]];
+ [nc postNotificationName:
+ NSTableViewColumnDidResizeNotification
+ object: self
+ userInfo: [NSDictionary
+ dictionaryWithObjectsAndKeys:
+ [NSNumber numberWithFloat: oldWidth],
+ @"NSOldWidth",
+ nil]];
}
- (BOOL) _shouldSelectTableColumn: (NSTableColumn *)tableColumn
{
- if ([_delegate respondsToSelector:
- @selector (tableView:shouldSelectTableColumn:)] == YES)
+ if ([_delegate respondsToSelector:
+ @selector (tableView:shouldSelectTableColumn:)] == YES)
{
- if ([_delegate tableView: self shouldSelectTableColumn: tableColumn] == NO)
- {
- return NO;
- }
+ if ([_delegate tableView: self shouldSelectTableColumn: tableColumn] == NO)
+ {
+ return NO;
+ }
}
-
- return YES;
+
+ return YES;
}
- (BOOL) _shouldSelectRow: (int)rowIndex
{
- if ([_delegate respondsToSelector:
- @selector (tableView:shouldSelectRow:)] == YES)
+ if ([_delegate respondsToSelector:
+ @selector (tableView:shouldSelectRow:)] == YES)
{
- if ([_delegate tableView: self shouldSelectRow: rowIndex] == NO)
- {
- return NO;
- }
+ if ([_delegate tableView: self shouldSelectRow: rowIndex] == NO)
+ {
+ return NO;
+ }
}
-
- return YES;
+
+ return YES;
}
- (BOOL) _shouldSelectionChange
{
- if ([_delegate respondsToSelector:
- @selector (selectionShouldChangeInTableView:)] == YES)
+ if ([_delegate respondsToSelector:
+ @selector (selectionShouldChangeInTableView:)] == YES)
{
- if ([_delegate selectionShouldChangeInTableView: self] == NO)
- {
- return NO;
- }
+ if ([_delegate selectionShouldChangeInTableView: self] == NO)
+ {
+ return NO;
+ }
}
-
- return YES;
+
+ return YES;
}
- (void) _didChangeSortDescriptors: (NSArray *)oldSortDescriptors
{
- if ([_dataSource
- respondsToSelector: @selector(tableView:sortDescriptorsDidChange:)])
+ if ([_dataSource
+ respondsToSelector: @selector(tableView:sortDescriptorsDidChange:)])
{
- [_dataSource tableView: self sortDescriptorsDidChange: oldSortDescriptors];
+ [_dataSource tableView: self sortDescriptorsDidChange: oldSortDescriptors];
}
}
- (void) _didClickTableColumn: (NSTableColumn *)tc
{
- if ([_delegate
- respondsToSelector:
- @selector(tableView:didClickTableColumn:)])
+ if ([_delegate
+ respondsToSelector:
+ @selector(tableView:didClickTableColumn:)])
{
- [_delegate tableView: self
+ [_delegate tableView: self
didClickTableColumn: tc];
}
}
- (BOOL) _shouldEditTableColumn: (NSTableColumn *)tableColumn
- row: (int) rowIndex
+ row: (int) rowIndex
{
- if ([_delegate respondsToSelector:
- @selector(tableView:shouldEditTableColumn:row:)])
+ if ([_delegate respondsToSelector:
+ @selector(tableView:shouldEditTableColumn:row:)])
{
- return [_delegate tableView: self shouldEditTableColumn: tableColumn
- row: rowIndex];
+ return [_delegate tableView: self shouldEditTableColumn: tableColumn
+ row: rowIndex];
}
-
- return YES;
+
+ return YES;
}
- (BOOL) _isCellEditableColumn: (int) columnIndex
- row: (int) rowIndex
-
+ row: (int) rowIndex
+
{
- NSTableColumn *tableColumn = [_tableColumns objectAtIndex: columnIndex];
- NSCell *cell = [self _dataCellForTableColumn: tableColumn row: rowIndex];
-
- BOOL cellIsEditable = [cell isEditable];
- BOOL columnIsEditable = [tableColumn isEditable];
- BOOL delegateAllowsEditing = [self _shouldEditTableColumn: tableColumn
- row: rowIndex];
-
- return cellIsEditable && columnIsEditable && delegateAllowsEditing;
+ NSTableColumn *tableColumn = [_tableColumns objectAtIndex: columnIndex];
+ NSCell *cell = [self _dataCellForTableColumn: tableColumn row: rowIndex];
+
+ BOOL cellIsEditable = [cell isEditable];
+ BOOL columnIsEditable = [tableColumn isEditable];
+ BOOL delegateAllowsEditing = [self _shouldEditTableColumn: tableColumn
+ row: rowIndex];
+
+ return cellIsEditable && columnIsEditable && delegateAllowsEditing;
}
- (void) _willDisplayCell: (NSCell*)cell
- forTableColumn: (NSTableColumn *)tb
- row: (int)index
+ forTableColumn: (NSTableColumn *)tb
+ row: (int)index
{
- if (_del_responds)
+ if (_del_responds)
{
- [_delegate tableView: self
- willDisplayCell: cell
- forTableColumn: tb
- row: index];
+ [_delegate tableView: self
+ willDisplayCell: cell
+ forTableColumn: tb
+ row: index];
}
}
- (id) _objectValueForTableColumn: (NSTableColumn *)tb
- row: (int) index
+ row: (int) index
{
- id result = nil;
- GSKeyValueBinding *theBinding;
-
- theBinding = [GSKeyValueBinding getBinding: NSValueBinding
- forObject: tb];
- if (theBinding != nil)
+ id result = nil;
+ GSKeyValueBinding *theBinding;
+
+ theBinding = [GSKeyValueBinding getBinding: NSValueBinding
+ forObject: tb];
+ if (theBinding != nil)
{
- return [(NSArray *)[theBinding sourceValueFor: NSValueBinding]
- objectAtIndex: index];
+ return [(NSArray *)[theBinding sourceValueFor: NSValueBinding]
+ objectAtIndex: index];
}
- else if ([_dataSource respondsToSelector:
- @selector(tableView:objectValueForTableColumn:row:)])
+ else if ([_dataSource respondsToSelector:
+ @selector(tableView:objectValueForTableColumn:row:)])
{
- result = [_dataSource tableView: self
- objectValueForTableColumn: tb
- row: index];
+ result = [_dataSource tableView: self
+ objectValueForTableColumn: tb
+ row: index];
}
-
- return result;
+
+ return result;
}
- (void) _setObjectValue: (id)value
- forTableColumn: (NSTableColumn *)tb
- row: (int) index
+ forTableColumn: (NSTableColumn *)tb
+ row: (int) index
{
- if ([_dataSource respondsToSelector:
- @selector(tableView:setObjectValue:forTableColumn:row:)])
+ if ([_dataSource respondsToSelector:
+ @selector(tableView:setObjectValue:forTableColumn:row:)])
{
- [_dataSource tableView: self
- setObjectValue: value
- forTableColumn: tb
- row: index];
+ [_dataSource tableView: self
+ setObjectValue: value
+ forTableColumn: tb
+ row: index];
}
}
@@ -6699,57 +6638,57 @@ mouseDownInHeaderOfTableColumn: tc];
*/
- (int) _numRows
{
- GSKeyValueBinding *theBinding;
-
- // If we have content binding the data source is used only
- // like a delegate
- theBinding = [GSKeyValueBinding getBinding: NSContentBinding
- forObject: self];
- if (theBinding != nil)
+ GSKeyValueBinding *theBinding;
+
+ // If we have content binding the data source is used only
+ // like a delegate
+ theBinding = [GSKeyValueBinding getBinding: NSContentBinding
+ forObject: self];
+ if (theBinding != nil)
{
- return [(NSArray *)[theBinding sourceValueFor: NSContentBinding] count];
+ return [(NSArray *)[theBinding sourceValueFor: NSContentBinding] count];
}
- else if ([_dataSource respondsToSelector:
- @selector(numberOfRowsInTableView:)])
+ else if ([_dataSource respondsToSelector:
+ @selector(numberOfRowsInTableView:)])
{
- return [_dataSource numberOfRowsInTableView:self];
+ return [_dataSource numberOfRowsInTableView:self];
}
- else
+ else
{
- // FIXME
- return 0;
+ // FIXME
+ return 0;
}
}
- (BOOL) _isDraggingSource
{
- return [_dataSource respondsToSelector:
+ return [_dataSource respondsToSelector:
@selector(tableView:writeRows:toPasteboard:)]
- || [_dataSource respondsToSelector:
- @selector(tableView:writeRowsWithIndexes:toPasteboard:)];
+ || [_dataSource respondsToSelector:
+ @selector(tableView:writeRowsWithIndexes:toPasteboard:)];
}
- (BOOL) _writeRows: (NSIndexSet *)rows
toPasteboard: (NSPasteboard *)pboard
{
- if ([_dataSource respondsToSelector:
- @selector(tableView:writeRowsWithIndexes:toPasteboard:)] == YES)
+ if ([_dataSource respondsToSelector:
+ @selector(tableView:writeRowsWithIndexes:toPasteboard:)] == YES)
{
- return [_dataSource tableView: self
- writeRowsWithIndexes: rows
- toPasteboard: pboard];
+ return [_dataSource tableView: self
+ writeRowsWithIndexes: rows
+ toPasteboard: pboard];
}
- else if ([_dataSource respondsToSelector:
- @selector(tableView:writeRows:toPasteboard:)] == YES)
+ else if ([_dataSource respondsToSelector:
+ @selector(tableView:writeRows:toPasteboard:)] == YES)
{
- NSArray *rowArray;
-
- rowArray = [self _indexSetToArray: rows];
- return [_dataSource tableView: self
- writeRows: rowArray
- toPasteboard: pboard];
+ NSArray *rowArray;
+
+ rowArray = [self _indexSetToArray: rows];
+ return [_dataSource tableView: self
+ writeRows: rowArray
+ toPasteboard: pboard];
}
- return NO;
+ return NO;
}
@end /* implementation of NSTableView */
@@ -6758,185 +6697,185 @@ mouseDownInHeaderOfTableColumn: tc];
- (void) _setSelectingColumns: (BOOL)flag
{
- if (flag == _selectingColumns)
- return;
-
- if (flag == NO)
+ if (flag == _selectingColumns)
+ return;
+
+ if (flag == NO)
{
- [self _unselectAllColumns];
- _selectingColumns = NO;
+ [self _unselectAllColumns];
+ _selectingColumns = NO;
}
- else
+ else
{
- [self _unselectAllRows];
- _selectingColumns = YES;
+ [self _unselectAllRows];
+ _selectingColumns = YES;
}
}
- (NSArray *) _indexSetToArray: (NSIndexSet*)indexSet
{
- NSMutableArray *array = [NSMutableArray array];
- NSUInteger index = [indexSet firstIndex];
-
- while (index != NSNotFound)
+ NSMutableArray *array = [NSMutableArray array];
+ NSUInteger index = [indexSet firstIndex];
+
+ while (index != NSNotFound)
{
- NSNumber *num = [NSNumber numberWithInt: index];
-
- [array addObject: num];
- index = [indexSet indexGreaterThanIndex: index];
+ NSNumber *num = [NSNumber numberWithInt: index];
+
+ [array addObject: num];
+ index = [indexSet indexGreaterThanIndex: index];
}
-
- return array;
+
+ return array;
}
- (NSArray *) _selectedRowArray
{
- return [self _indexSetToArray: _selectedRows];
+ return [self _indexSetToArray: _selectedRows];
}
- (BOOL) _selectRow: (int)rowIndex
{
- if (![self _shouldSelectRow: rowIndex])
+ if (![self _shouldSelectRow: rowIndex])
{
- return NO;
+ return NO;
}
-
- [self setNeedsDisplayInRect: [self rectOfRow: rowIndex]];
- [_selectedRows addIndex: rowIndex];
- _selectedRow = rowIndex;
- return YES;
+
+ [self setNeedsDisplayInRect: [self rectOfRow: rowIndex]];
+ [_selectedRows addIndex: rowIndex];
+ _selectedRow = rowIndex;
+ return YES;
}
- (BOOL) _selectUnselectedRow: (int)rowIndex
{
- if ([_selectedRows containsIndex: rowIndex])
+ if ([_selectedRows containsIndex: rowIndex])
{
- return NO;
+ return NO;
}
-
- [self setNeedsDisplayInRect: [self rectOfRow: rowIndex]];
- [_selectedRows addIndex: rowIndex];
- _selectedRow = rowIndex;
- return YES;
+
+ [self setNeedsDisplayInRect: [self rectOfRow: rowIndex]];
+ [_selectedRows addIndex: rowIndex];
+ _selectedRow = rowIndex;
+ return YES;
}
- (BOOL) _unselectRow: (int)rowIndex
{
- if (![_selectedRows containsIndex: rowIndex])
+ if (![_selectedRows containsIndex: rowIndex])
{
- return NO;
+ return NO;
}
-
- [self setNeedsDisplayInRect: [self rectOfRow: rowIndex]];
- [_selectedRows removeIndex: rowIndex];
-
- if (_selectedRow == rowIndex)
+
+ [self setNeedsDisplayInRect: [self rectOfRow: rowIndex]];
+ [_selectedRows removeIndex: rowIndex];
+
+ if (_selectedRow == rowIndex)
{
- _selectedRow = -1;
+ _selectedRow = -1;
}
-
- return YES;
+
+ return YES;
}
- (void) _unselectAllRows
{
- /* Compute rect to redraw to clear the old row selection */
- NSUInteger row = [_selectedRows firstIndex];
-
- while (row != NSNotFound)
+ /* Compute rect to redraw to clear the old row selection */
+ NSUInteger row = [_selectedRows firstIndex];
+
+ while (row != NSNotFound)
{
- [self setNeedsDisplayInRect: [self rectOfRow: row]];
- row = [_selectedRows indexGreaterThanIndex: row];
+ [self setNeedsDisplayInRect: [self rectOfRow: row]];
+ row = [_selectedRows indexGreaterThanIndex: row];
}
- [_selectedRows removeAllIndexes];
- _selectedRow = -1;
+ [_selectedRows removeAllIndexes];
+ _selectedRow = -1;
}
- (NSArray *) _selectedColumArray
{
- return [self _indexSetToArray: _selectedColumns];
+ return [self _indexSetToArray: _selectedColumns];
}
- (void) _unselectAllColumns
{
- /* Compute rect to redraw to clear the old column selection */
- NSUInteger column = [_selectedColumns firstIndex];
-
- while (column != NSNotFound)
+ /* Compute rect to redraw to clear the old column selection */
+ NSUInteger column = [_selectedColumns firstIndex];
+
+ while (column != NSNotFound)
{
- [self setNeedsDisplayInRect: [self rectOfColumn: column]];
- if (_headerView)
+ [self setNeedsDisplayInRect: [self rectOfColumn: column]];
+ if (_headerView)
{
- [_headerView setNeedsDisplayInRect:
- [_headerView headerRectOfColumn: column]];
- }
- column = [_selectedColumns indexGreaterThanIndex: column];
+ [_headerView setNeedsDisplayInRect:
+ [_headerView headerRectOfColumn: column]];
+ }
+ column = [_selectedColumns indexGreaterThanIndex: column];
}
- [_selectedColumns removeAllIndexes];
- _selectedColumn = -1;
+ [_selectedColumns removeAllIndexes];
+ _selectedColumn = -1;
}
- (void) setValue: (id)anObject forKey: (NSString*)aKey
{
- if ([aKey isEqual: NSContentBinding])
+ if ([aKey isEqual: NSContentBinding])
{
- // Reload data
- [self reloadData];
- NSLog(@"Setting TV content to %@", anObject);
+ // Reload data
+ [self reloadData];
+ NSLog(@"Setting TV content to %@", anObject);
}
- else if ([aKey isEqual: NSSelectionIndexesBinding])
+ else if ([aKey isEqual: NSSelectionIndexesBinding])
{
- if (_selectingColumns)
+ if (_selectingColumns)
{
- if (nil == anObject)
+ if (nil == anObject)
{
- [self _unselectAllColumns];
+ [self _unselectAllColumns];
}
- else
+ else
{
- return [self selectColumnIndexes: anObject
- byExtendingSelection: NO];
+ return [self selectColumnIndexes: anObject
+ byExtendingSelection: NO];
}
}
- else
+ else
{
- if (nil == anObject)
+ if (nil == anObject)
{
- [self _unselectAllRows];
+ [self _unselectAllRows];
}
- else
+ else
{
- return [self selectRowIndexes: anObject
- byExtendingSelection: NO];
+ return [self selectRowIndexes: anObject
+ byExtendingSelection: NO];
}
}
}
- else
+ else
{
- [super setValue: anObject forKey: aKey];
+ [super setValue: anObject forKey: aKey];
}
}
- (id) valueForKey: (NSString*)aKey
{
- if ([aKey isEqual: NSContentBinding])
+ if ([aKey isEqual: NSContentBinding])
{
- return nil;
+ return nil;
}
- else if ([aKey isEqual: NSSelectionIndexesBinding])
+ else if ([aKey isEqual: NSSelectionIndexesBinding])
{
- if (_selectingColumns)
+ if (_selectingColumns)
{
- return [self selectedColumnIndexes];
+ return [self selectedColumnIndexes];
}
- else
+ else
{
- return [self selectedRowIndexes];
+ return [self selectedRowIndexes];
}
}
- else
+ else
{
- return [super valueForKey: aKey];
+ return [super valueForKey: aKey];
}
}