- fixed a out of bounds error when clicking in the table header outside of any column

- made the dragged table column appear gray
- gave the tablecolumn drag view a white background

Conflicts:

	AppKit/CPTableView.j
This commit is contained in:
Randall Luecke committed 2010-05-11 00:25:19 -05:00
1 parent 256cc902eb
commit 983f0a92b2
2 files changed
+60 -28

No files matched your search

+28 -22
View File
@@ -26,7 +26,7 @@
@implementation _CPTableColumnHeaderView : CPView
{
_CPImageAndTextView _textField;
_CPImageAndTextView _textField;
}
- (void)initWithFrame:(CGRect)frame
@@ -153,6 +153,7 @@ var _CPTableColumnHeaderViewStringValueKey = @"_CPTableColumnHeaderViewStringVal
int _pressedColumn;
BOOL _isResizing;
BOOL _isDragging;
BOOL _isTrackingColumn;
// CPPoint _previousTrackingLocation;
@@ -280,6 +281,9 @@ var _CPTableColumnHeaderViewStringValueKey = @"_CPTableColumnHeaderViewStringVal
if (type === CPLeftMouseDown)
{
if (columnIndex === -1)
return;
_mouseDownLocation = currentLocation;
_activeColumn = columnIndex;
@@ -381,6 +385,18 @@ var _CPTableColumnHeaderViewStringValueKey = @"_CPTableColumnHeaderViewStringVal
[[self tableView] moveColumn:aFromIndex toColumn:aToIndex];
_activeColumn = aToIndex;
_pressedColumn = _activeColumn;
[[self tableView] _setDraggedColumn:_activeColumn];
}
- (void)draggedView:(CPView)aView beganAt:(CPPoint)aPoint
{
_isDragging = YES;
[[[[[self tableView] tableColumns] objectAtIndex:_activeColumn] headerView] setHidden:YES];
[[self tableView] _setDraggedColumn:_activeColumn];
[self setNeedsDisplay:YES];
}
- (void)draggedView:(CPView)aView movedTo:(CPPoint)aPoint
@@ -413,7 +429,13 @@ var _CPTableColumnHeaderViewStringValueKey = @"_CPTableColumnHeaderViewStringVal
- (void)draggedView:(CPImage)aView endedAt:(CGPoint)aLocation operation:(CPDragOperation)anOperation
{
_isDragging = NO;
[[self tableView] _setDraggedColumn:-1];
[[[[[self tableView] tableColumns] objectAtIndex:_activeColumn] headerView] setHidden:NO];
[self stopTrackingTableColumn:_activeColumn at:aLocation];
[self setNeedsDisplay:YES];
}
- (BOOL)shouldResizeTableColumn:(int)aColumnIndex at:(CPPoint)aPoint
@@ -602,27 +624,12 @@ var _CPTableColumnHeaderViewStringValueKey = @"_CPTableColumnHeaderViewStringVal
CGContextClosePath(context);
CGContextStrokePath(context);
/*
var maxY = CGRectGetMaxY([self bounds]);
// draw normal gradient for remaining space
if (supportsCanvasGradient)
if (_isDragging)
{
aRect.origin.x = columnMaxX - 0.5;
aRect.size.width -= columnMaxX;
CGContextBeginPath(context);
CGContextAddRect(context, CGRectMake(columnMaxX + 1, 0, CGRectGetMaxX([self bounds]) - columnMaxX, CGRectGetHeight([self bounds])));
CGContextClosePath(context);
CGContextDrawLinearGradient(context, [_CPTableColumnHeaderView headerGradient], CGPointMake(0,0), CGPointMake(0, maxY - 1),0);
}
// Draw bottom line
CGContextBeginPath(context);
CGContextMoveToPoint(context, 0, maxY - 0.5);
CGContextAddLineToPoint(context, CGRectGetMaxX([self bounds]), maxY - 0.5);
CGContextClosePath(context);
CGContextStrokePath(context);
*/
CGContextSetFillColor(context, [CPColor grayColor]);
CGContextFillRect(context, [self headerRectOfColumn:_activeColumn])
}
}
@end
@@ -649,4 +656,3 @@ var CPTableHeaderViewTableViewKey = @"CPTableHeaderViewTableViewKey";
}
@end
+32 -6
View File
@@ -212,6 +212,9 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
CPGradient _sourceListActiveGradient;
CPColor _sourceListActiveTopLineColor;
CPColor _sourceListActiveBottomLineColor;
int _draggedColumnIndex;
/*
CPGradient _sourceListInactiveGradient;
CPColor _sourceListInactiveTopLineColor;
@@ -309,7 +312,9 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
if (!_cornerView)
_cornerView = [[_CPCornerView alloc] initWithFrame:CGRectMake(0, 0, [CPScroller scrollerWidth], CGRectGetHeight([_headerView frame]))];
_draggedColumnIndex = -1;
// Gradients for the source list
_sourceListActiveGradient = CGGradientCreateWithColorComponents(CGColorSpaceCreateDeviceRGB(), [89.0/255.0, 153.0/255.0, 209.0/255.0,1.0, 33.0/255.0, 94.0/255.0, 208.0/255.0,1.0], [0,1], 2);
_sourceListActiveTopLineColor = [CPColor colorWithCalibratedRed:(61.0/255.0) green:(123.0/255.0) blue:(218.0/255.0) alpha:1.0];
@@ -672,6 +677,15 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
[self setNeedsLayout];
}
- (void)_setDraggedColumn:(int)aColumnIndex
{
if (_draggedColumnIndex === aColumnIndex)
return;
_draggedColumnIndex = aColumnIndex;
[self reloadDataForRowIndexes:_exposedRows columnIndexes:[CPIndexSet indexSetWithIndex:aColumnIndex]];
}
/*!
Moves the column and heading at a given index to a new given index.
@@ -703,7 +717,6 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
columnIndexes = [CPIndexSet indexSetWithIndexesInRange:CPMakeRange(fromIndex, toIndex)];
[self reloadDataForRowIndexes:rowIndexes columnIndexes:columnIndexes];
// [self setNeedsLayout];
}
/*!
@@ -1849,7 +1862,7 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
{
var dragView = [[CPView alloc] initWithFrame:CPRectMakeZero()];
tableColumn = [[self tableColumns] objectAtIndex:theColumnIndex],
bounds = CPRectMake(0.0, 0.0, [tableColumn width], CPRectGetHeight([self bounds]) + 23.0),
bounds = CPRectMake(0.0, 0.0, [tableColumn width], CPRectGetHeight([self _exposedRect]) + 23.0),
columnRect = [self rectOfColumn:theColumnIndex],
headerView = [tableColumn headerView];
@@ -1883,6 +1896,7 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
// being of when starting the drag, we compensate for this by offseting the drag window by the x coordinate of the column
// theDragViewOffset.x -= columnRect.origin.x;
[dragView setBackgroundColor:[CPColor whiteColor]];
[dragView setAlphaValue:0.7];
[dragView setFrame:bounds];
@@ -2129,8 +2143,12 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
for (; columnIndex < columnsCount; ++columnIndex)
{
var column = columnArray[columnIndex],
tableColumn = _tableColumns[column],
tableColumnUID = [tableColumn UID];
tableColumn = _tableColumns[column];
if ([tableColumn isHidden] || columnIndex === _draggedColumnIndex)
continue;
var tableColumnUID = [tableColumn UID];
if (!_dataViewsForTableColumns[tableColumnUID])
_dataViewsForTableColumns[tableColumnUID] = [];
@@ -2280,6 +2298,15 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
[self drawBackgroundInClipRect:exposedRect];
[self drawGridInClipRect:exposedRect];
[self highlightSelectionInClipRect:exposedRect];
if (_draggedColumnIndex === -1)
return;
var context = [[CPGraphicsContext currentContext] graphicsPort],
columnRect = [self rectOfColumn:_draggedColumnIndex];
CGContextSetFillColor(context, [CPColor grayColor]);
CGContextFillRect(context, columnRect);
}
- (void)drawBackgroundInClipRect:(CGRect)aRect
@@ -2287,7 +2314,6 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
if (!_usesAlternatingRowBackgroundColors)
return;
var rowColors = [self alternatingRowBackgroundColors],
colorCount = [rowColors count];