diff --git a/AppKit/CPOutlineView.j b/AppKit/CPOutlineView.j index df90c688d..06812521a 100644 --- a/AppKit/CPOutlineView.j +++ b/AppKit/CPOutlineView.j @@ -50,12 +50,30 @@ var CPOutlineViewDataSource_outlineView_setObjectValue_forTableColumn_byItem_ CPOutlineViewDataSource_outlineView_sortDescriptorsDidChange_ = 1 << 10; - var CPOutlineViewDelegate_outlineView_dataViewForTableColumn_item_ = 1 << 1, - CPOutlineViewDelegate_outlineView_shouldSelectItem_ = 1 << 2, - CPOutlineViewDelegate_outlineView_heightOfRowByItem_ = 1 << 3, - CPOutlineViewDelegate_outlineView_willDisplayView_forTableColumn_item_ = 1 << 4, - CPOutlineViewDelegate_outlineView_isGroupItem_ = 1 << 5; + CPOutlineViewDelegate_outlineView_didClickTableColumn_ = 1 << 2, + CPOutlineViewDelegate_outlineView_didDragTableColumn_ = 1 << 3, + CPOutlineViewDelegate_outlineView_heightOfRowByItem_ = 1 << 4, + CPOutlineViewDelegate_outlineView_isGroupItem_ = 1 << 5, + CPOutlineViewDelegate_outlineView_mouseDownInHeaderOfTableColumn_ = 1 << 6, + CPOutlineViewDelegate_outlineView_nextTypeSelectMatchFromItem_toItem_forString_ = 1 << 7, + CPOutlineViewDelegate_outlineView_selectionIndexesForProposedSelection_ = 1 << 8, + CPOutlineViewDelegate_outlineView_shouldCollapseItem_ = 1 << 9, + CPOutlineViewDelegate_outlineView_shouldEditTableColumn_item_ = 1 << 10, + CPOutlineViewDelegate_outlineView_shouldExpandItem_ = 1 << 11, + CPOutlineViewDelegate_outlineView_shouldReorderColumn_toColumn_ = 1 << 12, + CPOutlineViewDelegate_outlineView_shouldSelectItem_ = 1 << 13, + CPOutlineViewDelegate_outlineView_shouldSelectTableColumn_ = 1 << 14, + CPOutlineViewDelegate_outlineView_shouldShowOutlineViewForItem_ = 1 << 15, + CPOutlineViewDelegate_outlineView_shouldShowViewExpansionForTableColumn_item_ = 1 << 16, + CPOutlineViewDelegate_outlineView_shouldTrackView_forTableColumn_item_ = 1 << 17, + CPOutlineViewDelegate_outlineView_shouldTypeSelectForEvent_withCurrentSearchString_ = 1 << 18, + CPOutlineViewDelegate_outlineView_sizeToFitWidthOfColumn_ = 1 << 19, + CPOutlineViewDelegate_outlineView_toolTipForView_rect_tableColumn_item_mouseLocation_ = 1 << 20, + CPOutlineViewDelegate_outlineView_typeSelectStringForTableColumn_item_ = 1 << 21, + CPOutlineViewDelegate_outlineView_willDisplayOutlineView_forTableColumn_item_ = 1 << 22, + CPOutlineViewDelegate_outlineView_willDisplayView_forTableColumn_item_ = 1 << 23, + CPOutlineViewDelegate_selectionShouldChangeInOutlineView_ = 1 << 24; CPOutlineViewDropOnItemIndex = -1; @@ -79,10 +97,10 @@ CPOutlineViewDropOnItemIndex = -1; CPArray _disclosureControlsForRows; CPData _disclosureControlData; CPArray _disclosureControlQueue; - + BOOL _shouldRetargetItem; id _retargetedItem; - + BOOL _shouldRetargetChildIndex; CPInteger _retargedChildIndex; CPTimer _dragHoverTimer; @@ -107,7 +125,7 @@ CPOutlineViewDropOnItemIndex = -1; _retargetedItem = nil; _shouldRetargetItem = NO; - + _retargedChildIndex = nil; _shouldRetargetChildIndex = NO; _startHoverTime = nil; @@ -238,7 +256,7 @@ CPOutlineViewDropOnItemIndex = -1; { var children = itemInfo.children, childIndex = children.length; - + while (childIndex--) [self expandItem:children[childIndex] expandChildren:YES]; } @@ -374,7 +392,7 @@ CPOutlineViewDropOnItemIndex = -1; return nil; var parent = itemInfo.parent; - + // Check if the parent is the root item because we never return the actual root item if (itemInfo[[parent UID]] === _rootItemInfo) parent = nil; @@ -396,10 +414,10 @@ CPOutlineViewDropOnItemIndex = -1; - (void)_performSelection:(BOOL)select forRow:(CPInteger)rowIndex context:(id)context { [super _performSelection:select forRow:rowIndex context:context]; - + var control = _disclosureControlsForRows[rowIndex], selector = select ? @"setThemeState:" : @"unsetThemeState:"; - + [control performSelector:CPSelectorFromString(selector) withObject:CPThemeStateSelected]; } @@ -469,20 +487,42 @@ CPOutlineViewDropOnItemIndex = -1; _outlineViewDelegate = aDelegate; _implementedOutlineViewDelegateMethods = 0; - if ([_outlineViewDelegate respondsToSelector:@selector(outlineView:dataViewForTableColumn:item:)]) - _implementedOutlineViewDelegateMethods |= CPOutlineViewDelegate_outlineView_dataViewForTableColumn_item_; - - if ([_outlineViewDelegate respondsToSelector:@selector(outlineView:shouldSelectItem:)]) - _implementedOutlineViewDelegateMethods |= CPOutlineViewDelegate_outlineView_shouldSelectItem_; - - if ([_outlineViewDelegate respondsToSelector:@selector(outlineView:heightOfRowByItem:)]) - _implementedOutlineViewDelegateMethods |= CPOutlineViewDelegate_outlineView_heightOfRowByItem_; + var delegateMethods = [ + CPOutlineViewDelegate_outlineView_dataViewForTableColumn_item_ , @selector(outlineView:dataViewForTableColumn:item:), + CPOutlineViewDelegate_outlineView_didClickTableColumn_ , @selector(outlineView:didClickTableColumn:), + CPOutlineViewDelegate_outlineView_didDragTableColumn_ , @selector(outlineView:didDragTableColumn:), + CPOutlineViewDelegate_outlineView_heightOfRowByItem_ , @selector(outlineView:heightOfRowByItem:), + CPOutlineViewDelegate_outlineView_isGroupItem_ , @selector(outlineView:isGroupItem:), + CPOutlineViewDelegate_outlineView_mouseDownInHeaderOfTableColumn_ , @selector(outlineView:mouseDownInHeaderOfTableColumn:), + CPOutlineViewDelegate_outlineView_nextTypeSelectMatchFromItem_toItem_forString_ , @selector(outlineView:nextTypeSelectMatchFromItem:toItem:forString:), + CPOutlineViewDelegate_outlineView_selectionIndexesForProposedSelection_ , @selector(outlineView:selectionIndexesForProposedSelection:), + CPOutlineViewDelegate_outlineView_shouldCollapseItem_ , @selector(outlineView:shouldCollapseItem:), + CPOutlineViewDelegate_outlineView_shouldEditTableColumn_item_ , @selector(outlineView:shouldEditTableColumn:item:), + CPOutlineViewDelegate_outlineView_shouldExpandItem_ , @selector(outlineView:shouldExpandItem:), + CPOutlineViewDelegate_outlineView_shouldReorderColumn_toColumn_ , @selector(outlineView:shouldReorderColumn:toColumn:), + CPOutlineViewDelegate_outlineView_shouldSelectItem_ , @selector(outlineView:shouldSelectItem:), + CPOutlineViewDelegate_outlineView_shouldSelectTableColumn_ , @selector(outlineView:shouldSelectTableColumn:), + CPOutlineViewDelegate_outlineView_shouldShowOutlineViewForItem_ , @selector(outlineView:shouldShowOutlineViewForItem:), + CPOutlineViewDelegate_outlineView_shouldShowViewExpansionForTableColumn_item_ , @selector(outlineView:shouldShowViewExpansionForTableColumn:item:), + CPOutlineViewDelegate_outlineView_shouldTrackView_forTableColumn_item_ , @selector(outlineView:shouldTrackView:forTableColumn:item:), + CPOutlineViewDelegate_outlineView_shouldTypeSelectForEvent_withCurrentSearchString_ , @selector(outlineView:shouldTypeSelectForEvent:withCurrentSearchString:), + CPOutlineViewDelegate_outlineView_sizeToFitWidthOfColumn_ , @selector(outlineView:sizeToFitWidthOfColumn:), + CPOutlineViewDelegate_outlineView_toolTipForView_rect_tableColumn_item_mouseLocation_, @selector(outlineView:toolTipForView:rect:tableColumn:item:mouseLocation:), + CPOutlineViewDelegate_outlineView_typeSelectStringForTableColumn_item_ , @selector(outlineView:typeSelectStringForTableColumn:item:), + CPOutlineViewDelegate_outlineView_willDisplayOutlineView_forTableColumn_item_ , @selector(outlineView:willDisplayOutlineView:forTableColumn:item:), + CPOutlineViewDelegate_outlineView_willDisplayView_forTableColumn_item_ , @selector(outlineView:willDisplayView:forTableColumn:item:), + CPOutlineViewDelegate_selectionShouldChangeInOutlineView_ , @selector(selectionShouldChangeInOutlineView:) + ], + delegateCount = [delegateMethods count]; - if ([_outlineViewDelegate respondsToSelector:@selector(outlineView:willDisplayView:forTableColumn:item:)]) - _implementedOutlineViewDelegateMethods |= CPOutlineViewDelegate_outlineView_willDisplayView_forTableColumn_item_; + for (var i=0; i < delegateCount; i += 2) + { + var bitMask = delegateMethods[i], + selector = delegateMethods[i+1]; - if ([_outlineViewDelegate respondsToSelector:@selector(outlineView:isGroupItem:)]) - _implementedOutlineViewDelegateMethods |= CPOutlineViewDelegate_outlineView_isGroupItem_; + if ([_outlineViewDelegate respondsToSelector:selector]) + _implementedOutlineViewDelegateMethods |= bitMask; + } if ([_outlineViewDelegate respondsToSelector:@selector(outlineViewColumnDidMove:)]) [defaultCenter @@ -600,10 +640,10 @@ CPOutlineViewDropOnItemIndex = -1; _dropItem = theItem; _retargetedItem = theItem; _shouldRetargetItem = YES; - + _retargedChildIndex = theIndex; _shouldRetargetChildIndex = YES; - + // set CPTableView's _retargetedDropRow based on retargetedItem and retargetedChildIndex var retargetedItemInfo = (_retargetedItem !== nil) ? _itemInfosForItems[[_retargetedItem UID]] : _rootItemInfo, retargetedChildItem = (_retargedChildIndex !== CPOutlineViewDropOnItemIndex) ? retargetedItemInfo.children[_retargedChildIndex] : _retargetedItem; @@ -623,7 +663,7 @@ CPOutlineViewDropOnItemIndex = -1; { if (_shouldRetargetItem) return _retargetedItem; - + var lowerLevel = [self levelForRow:theLowerRowIndex] upperItem = [self itemAtRow:theUpperRowIndex]; upperLevel = [self levelForItem:upperItem]; @@ -642,7 +682,7 @@ CPOutlineViewDropOnItemIndex = -1; // Check the next parent upperItem = [self parentForItem:upperItem]; } - + return [self parentForItem:[self itemAtRow:theLowerRowIndex]]; } @@ -652,10 +692,10 @@ CPOutlineViewDropOnItemIndex = -1; var rect = [super _rectForDropHighlightViewBetweenUpperRow:theUpperRowIndex andLowerRow:theLowerRowIndex offset:theOffset], parentItem = [self _parentItemForUpperRow:theUpperRowIndex andLowerRow:theLowerRowIndex atMouseOffset:theOffset], level = [self levelForItem:parentItem]; - - rect.origin.x = (level + 1) * [self indentationPerLevel]; + + rect.origin.x = (level + 1) * [self indentationPerLevel]; rect.size.width -= rect.origin.x; // This assumes that the x returned by super is zero - + return rect; } @@ -823,7 +863,7 @@ CPOutlineViewDropOnItemIndex = -1; @end -// FIX ME: We're using with() here because Safari fails if we use anOutlineView._itemInfosForItems or whatever... +// FIX ME: We're using with() here because Safari fails if we use anOutlineView._itemInfosForItems or whatever... var _reloadItem = function(/*CPOutlineView*/ anOutlineView, /*id*/ anItem) { if (!anItem) @@ -836,55 +876,55 @@ var _reloadItem = function(/*CPOutlineView*/ anOutlineView, /*id*/ anItem) dataSource = _outlineViewDataSource, itemUID = [anItem UID], itemInfo = itemInfosForItems[itemUID]; - + // If we're not in the tree, then just bail. if (!itemInfo) return []; - + // See if the item itself can be swapped out. var parent = itemInfo.parent, parentItemInfo = parent ? itemInfosForItems[[parent UID]] : _rootItemInfo, parentChildren = parentItemInfo.children, index = [parentChildren indexOfObjectIdenticalTo:anItem], newItem = [dataSource outlineView:anOutlineView child:index ofItem:parent]; - + if (anItem !== newItem) { itemInfosForItems[[anItem UID]] = nil; itemInfosForItems[[newItem UID]] = itemInfo; - + parentChildren[index] = newItem; _itemsForRows[itemInfo.row] = newItem; } - + itemInfo.isExpandable = [dataSource outlineView:anOutlineView isItemExpandable:newItem]; itemInfo.isExpanded = itemInfo.isExpandable && itemInfo.isExpanded; } } -// FIX ME: We're using with() here because Safari fails if we use anOutlineView._itemInfosForItems or whatever... +// FIX ME: We're using with() here because Safari fails if we use anOutlineView._itemInfosForItems or whatever... var _loadItemInfoForItem = function(/*CPOutlineView*/ anOutlineView, /*id*/ anItem, /*BOOL*/ isIntermediate) { with(anOutlineView) { var itemInfosForItems = _itemInfosForItems, dataSource = _outlineViewDataSource; - + if (!anItem) var itemInfo = _rootItemInfo; - + else { // Get the existing info if it exists. var itemUID = [anItem UID], itemInfo = itemInfosForItems[itemUID]; - + // If we're not in the tree, then just bail. if (!itemInfo) return []; - + itemInfo.isExpandable = [dataSource outlineView:anOutlineView isItemExpandable:anItem]; - + // If we were previously expanded, but now no longer expandable, "de-expand". // NOTE: we are *not* collapsing, thus no notification is posted. if (!itemInfo.isExpandable && itemInfo.isExpanded) @@ -893,72 +933,72 @@ var _loadItemInfoForItem = function(/*CPOutlineView*/ anOutlineView, /*id*/ anIt itemInfo.children = []; } } - + // The root item does not count as a descendant. var weight = itemInfo.weight, descendants = anItem ? [anItem] : []; - + if (itemInfo.isExpanded && (!(_implementedOutlineViewDataSourceMethods & CPOutlineViewDataSource_outlineView_shouldDeferDisplayingChildrenOfItem_) || ![dataSource outlineView:anOutlineView shouldDeferDisplayingChildrenOfItem:anItem])) { var index = 0, count = [dataSource outlineView:anOutlineView numberOfChildrenOfItem:anItem], level = itemInfo.level + 1; - + itemInfo.children = []; - + for (; index < count; ++index) { var childItem = [dataSource outlineView:anOutlineView child:index ofItem:anItem], childItemInfo = itemInfosForItems[[childItem UID]]; - + if (!childItemInfo) { childItemInfo = { isExpanded:NO, isExpandable:NO, children:[], weight:1 }; itemInfosForItems[[childItem UID]] = childItemInfo; } - + itemInfo.children[index] = childItem; - + var childDescendants = _loadItemInfoForItem(anOutlineView, childItem, YES); - + childItemInfo.parent = anItem; childItemInfo.level = level; descendants = descendants.concat(childDescendants); } } - + itemInfo.weight = descendants.length; - + if (!isIntermediate) { // row = -1 is the root item, so just go to row 0 since it is ignored. var index = MAX(itemInfo.row, 0), itemsForRows = _itemsForRows; - + descendants.unshift(index, weight); - + itemsForRows.splice.apply(itemsForRows, descendants); - + var count = itemsForRows.length; - + for (; index < count; ++index) itemInfosForItems[[itemsForRows[index] UID]].row = index; - + var deltaWeight = itemInfo.weight - weight; - + if (deltaWeight !== 0) { var parent = itemInfo.parent; - + while (parent) { var parentItemInfo = itemInfosForItems[[parent UID]]; - + parentItemInfo.weight += deltaWeight; parent = parentItemInfo.parent; } - + if (anItem) _rootItemInfo.weight += deltaWeight; } @@ -1003,16 +1043,16 @@ var _loadItemInfoForItem = function(/*CPOutlineView*/ anOutlineView, /*id*/ anIt { if (!(_outlineView._implementedOutlineViewDataSourceMethods & CPOutlineViewDataSource_outlineView_writeItems_toPasteboard_)) return NO; - + var rowIndexes = []; [theIndexes getIndexes:rowIndexes maxCount:[theIndexes count] inIndexRange:nil]; - + var rowIndex = [rowIndexes count], items = []; - + while (rowIndex--) [items addObject:[_outlineView itemAtRow:[rowIndexes objectAtIndex:rowIndex]]]; - + return [_outlineView._outlineViewDataSource outlineView:_outlineView writeItems:items toPasteboard:thePasteboard]; } @@ -1020,15 +1060,15 @@ var _loadItemInfoForItem = function(/*CPOutlineView*/ anOutlineView, /*id*/ anIt { if (_outlineView._shouldRetargetChildIndex) return _outlineView._retargedChildIndex; - + var childIndex = CPNotFound; - + if (theDropOperation === CPTableViewDropAbove) { var parentItem = [_outlineView _parentItemForUpperRow:theRow - 1 andLowerRow:theRow atMouseOffset:theOffset], itemInfo = (parentItem !== nil) ? _outlineView._itemInfosForItems[[parentItem UID]] : _outlineView._rootItemInfo, children = itemInfo.children; - + childIndex = [children indexOfObject:[_outlineView itemAtRow:theRow]]; if (childIndex === CPNotFound) @@ -1043,12 +1083,12 @@ var _loadItemInfoForItem = function(/*CPOutlineView*/ anOutlineView, /*id*/ anIt - (void)_parentItemForDropOperation:(CPTableViewDropOperation)theDropOperation row:(int)theRow offset:(CPPoint)theOffset { if (theDropOperation === CPTableViewDropAbove) - return [_outlineView _parentItemForUpperRow:theRow - 1 andLowerRow:theRow atMouseOffset:theOffset] - + return [_outlineView _parentItemForUpperRow:theRow - 1 andLowerRow:theRow atMouseOffset:theOffset] + return [_outlineView itemAtRow:theRow]; } -- (CPDragOperation)tableView:(CPTableView)aTableView validateDrop:(id < CPDraggingInfo >)theInfo +- (CPDragOperation)tableView:(CPTableView)aTableView validateDrop:(id < CPDraggingInfo >)theInfo proposedRow:(int)theRow proposedDropOperation:(CPTableViewDropOperation)theOperation { if (!(_outlineView._implementedOutlineViewDataSourceMethods & CPOutlineViewDataSource_outlineView_validateDrop_proposedItem_proposedChildIndex_)) @@ -1069,14 +1109,14 @@ var _loadItemInfoForItem = function(/*CPOutlineView*/ anOutlineView, /*id*/ anIt } - (BOOL)tableView:(CPTableView)aTableView acceptDrop:(id )theInfo row:(int)theRow dropOperation:(CPTableViewDropOperation)theOperation -{ +{ if (!(_outlineView._implementedOutlineViewDataSourceMethods & CPOutlineViewDataSource_outlineView_acceptDrop_item_childIndex_)) return NO; var location = [_outlineView convertPoint:[theInfo draggingLocation] fromView:nil], parentItem = [self _parentItemForDropOperation:theOperation row:theRow offset:location]; childIndex = [self _childIndexForDropOperation:theOperation row:theRow offset:location]; - + _outlineView._retargetedItem = nil; _outlineView._shouldRetargetItem = NO; @@ -1106,15 +1146,15 @@ var _loadItemInfoForItem = function(/*CPOutlineView*/ anOutlineView, /*id*/ anIt - (CPView)tableView:(CPTableView)theTableView dataViewForTableColumn:(CPTableColumn)theTableColumn row:(int)theRow { var dataView = nil; - + if ((_outlineView._implementedOutlineViewDelegateMethods & CPOutlineViewDelegate_outlineView_dataViewForTableColumn_item_)) - dataView = [_outlineView._outlineViewDelegate outlineView:_outlineView - dataViewForTableColumn:theTableColumn + dataView = [_outlineView._outlineViewDelegate outlineView:_outlineView + dataViewForTableColumn:theTableColumn item:[_outlineView itemAtRow:theRow]]; if (!dataView) - dataView = [theTableColumn dataViewForRow:theRow]; - + dataView = [theTableColumn dataViewForRow:theRow]; + return dataView; } @@ -1122,7 +1162,7 @@ var _loadItemInfoForItem = function(/*CPOutlineView*/ anOutlineView, /*id*/ anIt { if ((_outlineView._implementedOutlineViewDelegateMethods & CPOutlineViewDelegate_outlineView_shouldSelectItem_)) return [_outlineView._outlineViewDelegate outlineView:_outlineView shouldSelectItem:[_outlineView itemAtRow:theRow]]; - + return YES; } @@ -1209,7 +1249,7 @@ var _loadItemInfoForItem = function(/*CPOutlineView*/ anOutlineView, /*id*/ anIt CGContextClosePath(context); var isHighlighted = [self hasThemeState:CPThemeStateHighlighted]; var color = [self hasThemeState:CPThemeStateSelected] ? (isHighlighted ? [CPColor lightGrayColor] : [CPColor whiteColor]) : (isHighlighted ? [CPColor blackColor] : [CPColor grayColor]); - + CGContextSetFillColor(context, color); CGContextFillPath(context); }