- 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
This commit is contained in:
Klaas Pieter Annema committed 2010-05-05 12:23:55 +02:00
1 parent 93afa11ef9
commit 006f7e0c15
2 files changed
+56 -28

No files matched your search

+29 -23
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;
@@ -272,6 +273,9 @@ var _CPTableColumnHeaderViewStringValueKey = @"_CPTableColumnHeaderViewStringVal
if (type === CPLeftMouseDown)
{
if (columnIndex === -1)
return;
_mouseDownLocation = currentLocation;
_activeColumn = columnIndex;
@@ -373,6 +377,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
@@ -405,7 +421,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
@@ -594,27 +616,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
@@ -640,5 +647,4 @@ var CPTableHeaderViewTableViewKey = @"CPTableHeaderViewTableViewKey";
[aCoder encodeObject:_tableView forKey:CPTableHeaderViewTableViewKey];
}
@end
@end
+27 -5
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];
}
/*!
@@ -1856,7 +1869,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];
@@ -1890,6 +1903,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];
@@ -2138,7 +2152,7 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
var column = columnArray[columnIndex],
tableColumn = _tableColumns[column];
if ([tableColumn isHidden])
if ([tableColumn isHidden] || columnIndex === _draggedColumnIndex)
continue;
var tableColumnUID = [tableColumn UID];
@@ -2294,6 +2308,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
@@ -2301,7 +2324,6 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
if (!_usesAlternatingRowBackgroundColors)
return;
var rowColors = [self alternatingRowBackgroundColors],
colorCount = [rowColors count];