diff --git a/AppKit/CPOutlineView.j b/AppKit/CPOutlineView.j index f4d871b18..77f1b6b38 100644 --- a/AppKit/CPOutlineView.j +++ b/AppKit/CPOutlineView.j @@ -627,140 +627,147 @@ var CPOutlineViewDelegate_outlineView_dataViewForTableColumn_item_ = 1 < @end +// 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) return; - // Get the existing info if it exists. - var itemInfosForItems = anOutlineView._itemInfosForItems, - dataSource = anOutlineView._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]] : anOutlineView._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; - anOutlineView._itemsForRows[itemInfo.row] = newItem; - } - - itemInfo.isExpandable = [dataSource outlineView:anOutlineView isItemExpandable:newItem]; - itemInfo.isExpanded = itemInfo.isExpandable && itemInfo.isExpanded; -} - -var _loadItemInfoForItem = function(/*CPOutlineView*/ anOutlineView, /*id*/ anItem, /*BOOL*/ isIntermediate) -{ - var itemInfosForItems = anOutlineView._itemInfosForItems, - dataSource = [anOutlineView dataSource]; // Somehow accessing the property directly doesn't work when a delegate was set - - if (!anItem) - var itemInfo = anOutlineView._rootItemInfo; - - else + with(anOutlineView) { // Get the existing info if it exists. - var itemUID = [anItem UID], + var itemInfosForItems = _itemInfosForItems, + dataSource = _outlineViewDataSource, + 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) + + // 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) { - itemInfo.isExpanded = NO; + 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... +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) + { + itemInfo.isExpanded = NO; + 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 = []; - } - } - - // The root item does not count as a descendant. - var weight = itemInfo.weight, - descendants = anItem ? [anItem] : []; - - if (itemInfo.isExpanded && (!(anOutlineView._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) + + for (; index < count; ++index) { - childItemInfo = { isExpanded:NO, isExpandable:NO, children:[], weight:1 }; - itemInfosForItems[[childItem UID]] = childItemInfo; + 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.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 = anOutlineView._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) + + itemInfo.weight = descendants.length; + + if (!isIntermediate) { - var parent = itemInfo.parent; - - while (parent) + // 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 parentItemInfo = itemInfosForItems[[parent UID]]; - - parentItemInfo.weight += deltaWeight; - parent = parentItemInfo.parent; + var parent = itemInfo.parent; + + while (parent) + { + var parentItemInfo = itemInfosForItems[[parent UID]]; + + parentItemInfo.weight += deltaWeight; + parent = parentItemInfo.parent; + } + + if (anItem) + _rootItemInfo.weight += deltaWeight; } - - if (anItem) - anOutlineView._rootItemInfo.weight += deltaWeight; } - } - + }//end of with return descendants; } diff --git a/AppKit/CPTableView.j b/AppKit/CPTableView.j index 0491d67a9..d1f9805da 100644 --- a/AppKit/CPTableView.j +++ b/AppKit/CPTableView.j @@ -192,14 +192,14 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5; CPView _dropOperationFeedbackView; -// BOOL _verticalMotionCanDrag; -// unsigned _destinationDragStyle; -// BOOL _isSelectingSession; -// CPIndexSet _draggedRowIndexes; -// _dropOperationDrawingView _dropOperationFeedbackView; -// CPDragOperation _dragOperationDefaultMask; -// int _retargetedDropRow; -// CPDragOperation _retargetedDropOperation; + BOOL _verticalMotionCanDrag; + unsigned _destinationDragStyle; + BOOL _isSelectingSession; + CPIndexSet _draggedRowIndexes; + _dropOperationDrawingView _dropOperationFeedbackView; + CPDragOperation _dragOperationDefaultMask; + int _retargetedDropRow; + CPDragOperation _retargetedDropOperation; } - (id)initWithFrame:(CGRect)aFrame @@ -248,22 +248,20 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5; _cornerView = [[_CPCornerView alloc] initWithFrame:CGRectMake(0, 0, [CPScroller scrollerWidth], CGRectGetHeight([_headerView frame]))]; - _selectedColumnIndexes = [CPIndexSet indexSet]; _selectedRowIndexes = [CPIndexSet indexSet]; -window.setTimeout(function(){ - self._draggedRowIndexes = [CPIndexSet indexSet]; - self._verticalMotionCanDrag = YES; - self._isSelectingSession = NO; - self._retargetedDropRow = nil; - self._retargetedDropOperation = nil; - self._dragOperationDefaultMask = nil; - self._destinationDragStyle = CPTableViewDraggingDestinationFeedbackStyleRegular; - // self._dropOperationFeedbackView = [[_dropOperationDrawingView alloc] initWithFrame:_CGRectMakeZero()]; + + _draggedRowIndexes = [CPIndexSet indexSet]; + _verticalMotionCanDrag = YES; + _isSelectingSession = NO; + _retargetedDropRow = nil; + _retargetedDropOperation = nil; + _dragOperationDefaultMask = nil; + _destinationDragStyle = CPTableViewDraggingDestinationFeedbackStyleRegular; + // _dropOperationFeedbackView = [[_dropOperationDrawingView alloc] initWithFrame:_CGRectMakeZero()]; // [self addSubview:_dropOperationFeedbackView]; // [_dropOperationFeedbackView setHidden:YES]; // [_dropOperationFeedbackView setTableView:self]; -},0); _tableDrawView = [[_CPTableDrawView alloc] initWithTableView:self]; [_tableDrawView setBackgroundColor:[CPColor clearColor]]; @@ -1961,11 +1959,6 @@ window.setTimeout(function(){ [self highlightSelectionInClipRect:exposedRect]; } -- (void)drawRect:(CGRect)aRect -{ - [_tableDrawView display]; -} - - (void)drawBackgroundInClipRect:(CGRect)aRect { if (![self usesAlternatingRowBackgroundColors]) @@ -1989,20 +1982,21 @@ window.setTimeout(function(){ // CGContextFillRect(context, CGRectIntersection(aRect, fillRect)); // console.profile("row-paint"); var exposedRows = [self rowsInRect:aRect], - firstRow = exposedRows.location -1, + firstRow = exposedRows.location, lastRow = CPMaxRange(exposedRows) - 1, colorIndex = MIN(exposedRows.length, colorCount), heightFilled = 0.0; while (colorIndex--) { - var row = firstRow % colorCount + firstRow + colorIndex, + var row = firstRow - firstRow % colorCount + colorIndex, fillRect = nil; CGContextBeginPath(context); for (; row <= lastRow; row += colorCount) - CGContextAddRect(context, CGRectIntersection(aRect, fillRect = [self rectOfRow:row])); + if (row >= firstRow) + CGContextAddRect(context, CGRectIntersection(aRect, fillRect = [self rectOfRow:row])); if (row - colorCount === lastRow) heightFilled = _CGRectGetMaxY(fillRect); @@ -2408,9 +2402,9 @@ window.setTimeout(function(){ rowIndex = [self rowAtPoint:aPoint]; if (rowIndex !== -1) { - if(_draggedRowIndexes !== nil) + if ([_draggedRowIndexes count] > 0) { - _draggedRowIndexes = nil; + _draggedRowIndexes = [CPIndexSet indexSet]; return; } // if the table has drag support then we use mouseUp to select a single row. diff --git a/AppKit/Resources/tableview-headerview-highlighted-pressed.png b/AppKit/Resources/tableview-headerview-highlighted-pressed.png index cd4464d36..b0a0ff82a 100644 Binary files a/AppKit/Resources/tableview-headerview-highlighted-pressed.png and b/AppKit/Resources/tableview-headerview-highlighted-pressed.png differ diff --git a/AppKit/Resources/tableview-headerview-pressed.png b/AppKit/Resources/tableview-headerview-pressed.png index e79e72539..e032e53de 100644 Binary files a/AppKit/Resources/tableview-headerview-pressed.png and b/AppKit/Resources/tableview-headerview-pressed.png differ diff --git a/Tests/Manual/TableTest/AppController.j b/Tests/Manual/TableTest/AppController.j index eb4b7830a..98fb0d160 100644 --- a/Tests/Manual/TableTest/AppController.j +++ b/Tests/Manual/TableTest/AppController.j @@ -39,6 +39,7 @@ CPLogRegister(CPLogConsole); [tableView setAllowsMultipleSelection:YES]; [tableView setAllowsColumnSelection:YES]; [tableView setUsesAlternatingRowBackgroundColors:YES]; + [tableView setAlternatingRowBackgroundColors:[[CPColor whiteColor], [CPColor colorWithHexString:@"e4e7ff"], [CPColor colorWithHexString:@"f4e7ff"]]]; [tableView setGridStyleMask:CPTableViewSolidHorizontalGridLineMask | CPTableViewSolidVerticalGridLineMask]; // [tableView setBackgroundColor:[CPColor blueColor]];