(fixes issue 395) implemented -[NSOutlineView parentForItem:]

This commit is contained in:
Christopher Lloyd 2009-10-19 20:03:14 +00:00
parent 9618f7c954
commit 7987b8e121
2 changed files with 11 additions and 0 deletions

View File

@ -27,6 +27,7 @@ APPKIT_EXPORT NSString *NSOutlineViewSelectionIsChangingNotification;
NSTableColumn *_outlineTableColumn;
NSMapTable *_rowToItem;
NSMapTable *_itemToRow;
NSMapTable *_itemToParent;
NSMapTable *_itemToLevel;
NSMapTable *_itemToExpansionState;
NSMapTable *_itemToNumberOfChildren;
@ -48,6 +49,7 @@ APPKIT_EXPORT NSString *NSOutlineViewSelectionIsChangingNotification;
-itemAtRow:(int)row;
-(int)rowForItem:item;
-parentForItem:item;
-(BOOL)isExpandable:item;
-(int)levelForItem:item;

View File

@ -106,6 +106,7 @@ static inline id childOfItemAtIndex(NSOutlineView *self,id item,int index){
_rowToItem=NSCreateMapTable(NSIntegerMapKeyCallBacks, NSNonOwnedPointerMapValueCallBacks, 0);
_itemToRow = NSCreateMapTable(NSNonOwnedPointerOrNullMapKeyCallBacks, NSIntegerMapValueCallBacks, 0);
_itemToParent=NSCreateMapTable(NSNonOwnedPointerOrNullMapKeyCallBacks, NSNonOwnedPointerMapValueCallBacks, 0);
_itemToLevel = NSCreateMapTable(NSNonOwnedPointerOrNullMapKeyCallBacks, NSIntegerMapValueCallBacks, 0);
_itemToExpansionState = NSCreateMapTable(NSNonOwnedPointerOrNullMapKeyCallBacks, NSIntegerMapValueCallBacks, 0);
_itemToNumberOfChildren = NSCreateMapTable(NSNonOwnedPointerOrNullMapKeyCallBacks, NSIntegerMapValueCallBacks, 0);
@ -134,6 +135,7 @@ static inline id childOfItemAtIndex(NSOutlineView *self,id item,int index){
[super initWithFrame:frame];
_rowToItem = NSCreateMapTable(NSIntegerMapKeyCallBacks, NSNonOwnedPointerMapValueCallBacks, 0);
_itemToRow = NSCreateMapTable(NSNonOwnedPointerOrNullMapKeyCallBacks, NSIntegerMapValueCallBacks, 0);
_itemToParent=NSCreateMapTable(NSNonOwnedPointerOrNullMapKeyCallBacks, NSNonOwnedPointerMapValueCallBacks, 0);
_itemToLevel = NSCreateMapTable(NSNonOwnedPointerOrNullMapKeyCallBacks, NSIntegerMapValueCallBacks, 0);
_itemToExpansionState = NSCreateMapTable(NSNonOwnedPointerOrNullMapKeyCallBacks, NSIntegerMapValueCallBacks, 0);
_itemToNumberOfChildren = NSCreateMapTable(NSNonOwnedPointerOrNullMapKeyCallBacks, NSIntegerMapValueCallBacks, 0);
@ -156,6 +158,7 @@ static inline id childOfItemAtIndex(NSOutlineView *self,id item,int index){
-(void)dealloc {
NSFreeMapTable(_rowToItem);
NSFreeMapTable(_itemToRow);
NSFreeMapTable(_itemToParent);
NSFreeMapTable(_itemToLevel);
NSFreeMapTable(_itemToExpansionState);
NSFreeMapTable(_itemToNumberOfChildren);
@ -179,6 +182,10 @@ static inline id childOfItemAtIndex(NSOutlineView *self,id item,int index){
return (int)NSMapGet(_itemToRow, item);
}
-parentForItem:item {
return NSMapGet(_itemToParent, item);
}
- (BOOL)isExpandable:(id)item
{
return [_dataSource outlineView:self isItemExpandable:item];
@ -382,6 +389,7 @@ static inline id childOfItemAtIndex(NSOutlineView *self,id item,int index){
-(void)_resetMapTables {
NSResetMapTable(_rowToItem);
NSResetMapTable(_itemToRow);
NSResetMapTable(_itemToParent);
NSResetMapTable(_itemToLevel);
// NSResetMapTable(_itemToExpansionState);
NSResetMapTable(_itemToNumberOfChildren);
@ -478,6 +486,7 @@ static void loadItemIntoMapTables(NSOutlineView *self,id item,unsigned *rowCount
NSMapInsert(self->_rowToItem, (void *)(*rowCountPtr), child);
NSMapInsert(self->_itemToRow, child, (void *)(*rowCountPtr));
NSMapInsert(self->_itemToParent, child, item);
NSMapInsert(self->_itemToLevel, child, (void *)recursionLevel);
(*rowCountPtr)++;