Full support for intercell spacing (issue #797)

This commit is contained in:
Aparajita Fishman committed 2010-07-28 17:51:05 -04:00
1 parent ff4f22a8a4
commit 470fcaf13e
2 files changed
+37 -31

No files matched your search

+34 -29
View File
@@ -262,7 +262,7 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
_dirtyTableColumnRangeIndex = CPNotFound;
_numberOfHiddenColumns = 0;
_intercellSpacing = _CGSizeMake(0.0, 0.0);
_intercellSpacing = _CGSizeMake(3.0, 2.0);
_rowHeight = 23.0;
[self setGridColor:[CPColor colorWithHexString:@"dce0e2"]];
@@ -545,6 +545,9 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
return;
_intercellSpacing = _CGSizeMakeCopy(aSize);
_dirtyTableColumnRangeIndex = 0; // so that _recalculateTableColumnRanges will work
[self _recalculateTableColumnRanges];
[self setNeedsLayout];
}
@@ -1253,7 +1256,7 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
else
{
var width = [_tableColumns[index] width];
var width = [_tableColumns[index] width] + _intercellSpacing.width;
_tableColumnRanges[index] = CPMakeRange(x, width);
@@ -1285,11 +1288,9 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
- (CGRect)rectOfRow:(CPInteger)aRowIndex
{
if (NO)
return NULL;
var height = _rowHeight + _intercellSpacing.height;
// FIXME: WRONG: ASK TABLE COLUMN RANGE
return _CGRectMake(0.0, (aRowIndex * (_rowHeight + _intercellSpacing.height)), _CGRectGetWidth([self bounds]), _rowHeight);
return _CGRectMake(0.0, aRowIndex * height, _CGRectGetWidth([self bounds]), height);
}
// Complexity:
@@ -1406,9 +1407,8 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
- (CPInteger)rowAtPoint:(CGPoint)aPoint
{
var y = aPoint.y;
var row = FLOOR(y / (_rowHeight + _intercellSpacing.height));
var y = aPoint.y,
row = FLOOR(y / (_rowHeight + _intercellSpacing.height));
if (row >= _numberOfRows)
return -1;
@@ -1421,9 +1421,14 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
UPDATE_COLUMN_RANGES_IF_NECESSARY();
var tableColumnRange = _tableColumnRanges[aColumn],
rectOfRow = [self rectOfRow:aRow];
return _CGRectMake(tableColumnRange.location, _CGRectGetMinY(rectOfRow), tableColumnRange.length, _CGRectGetHeight(rectOfRow));
rectOfRow = [self rectOfRow:aRow],
leftInset = FLOOR(_intercellSpacing.width / 2.0),
topInset = FLOOR(_intercellSpacing.height / 2.0);
return _CGRectMake(tableColumnRange.location + leftInset,
_CGRectGetMinY(rectOfRow) + topInset,
tableColumnRange.length - _intercellSpacing.width,
_CGRectGetHeight(rectOfRow) - _intercellSpacing.height);
}
- (void)resizeWithOldSuperviewSize:(CGSize)aSize
@@ -1910,11 +1915,11 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
[newSortDescriptors insertObject:newMainSortDescriptor atIndex:0];
// Update indicator image & highlighted column before
var image = [newMainSortDescriptor ascending] ? [self _tableHeaderSortImage] : [self _tableHeaderReverseSortImage];
var image = [newMainSortDescriptor ascending] ? [self _tableHeaderSortImage] : [self _tableHeaderReverseSortImage];
[self setIndicatorImage:nil inTableColumn:_currentHighlightedTableColumn];
[self setIndicatorImage:image inTableColumn:tableColumn];
[self setHighlightedTableColumn:tableColumn];
[self setIndicatorImage:image inTableColumn:tableColumn];
[self setHighlightedTableColumn:tableColumn];
[self setSortDescriptors:newSortDescriptors];
}
@@ -2137,7 +2142,7 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
_sortDescriptors = newSortDescriptors;
[self _sendDataSourceSortDescriptorsDidChange:oldSortDescriptors];
[self _sendDataSourceSortDescriptorsDidChange:oldSortDescriptors];
}
- (CPArray)sortDescriptors
@@ -3095,11 +3100,11 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
// If there is no (the default) or to little inter cell spacing we create some room for the CPTableViewDropAbove indicator
// This probably doesn't work if the row height is smaller than or around 5.0
if ([self intercellSpacing].height < 5.0)
rowRect = CPRectInset(rowRect, 0.0, 5.0 - [self intercellSpacing].height);
rowRect = CPRectInset(rowRect, 0.0, 5.0 - [self intercellSpacing].height);
// If the altered row rect contains the drag point we show the drop on
// We don't show the drop on indicator if we are dragging below the last row
// in that case we always want to show the drop above indicator
// If the altered row rect contains the drag point we show the drop on
// We don't show the drop on indicator if we are dragging below the last row
// in that case we always want to show the drop above indicator
if (CGRectContainsPoint(rowRect, theDragPoint) && row < _numberOfRows)
return CPTableViewDropOn;
@@ -3111,23 +3116,23 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
*/
- (CPInteger)_proposedRowAtPoint:(CGPoint)dragPoint
{
// We don't use rowAtPoint here because the drag indicator can appear below the last row
// and rowAtPoint doesn't return rows that are larger than numberOfRows
// We don't use rowAtPoint here because the drag indicator can appear below the last row
// and rowAtPoint doesn't return rows that are larger than numberOfRows
// FIX ME: this is going to break when we implement variable row heights...
var row = FLOOR(dragPoint.y / ( _rowHeight + _intercellSpacing.height )),
// Determine if the mouse is currently closer to this row or the row below it
var row = FLOOR(dragPoint.y / ( _rowHeight + _intercellSpacing.height )),
// Determine if the mouse is currently closer to this row or the row below it
lowerRow = row + 1,
rect = [self rectOfRow:row],
rect = [self rectOfRow:row],
bottomPoint = CGRectGetMaxY(rect),
bottomThirty = bottomPoint - ((bottomPoint - CGRectGetMinY(rect)) * 0.3);
if (dragPoint.y > MAX(bottomThirty, bottomPoint - 6))
row = lowerRow;
row = lowerRow;
if (row >= [self numberOfRows])
row = [self numberOfRows];
return row;
return row;
}
- (void)_validateDrop:(id)info proposedRow:(CPInteger)row proposedDropOperation:(CPTableViewDropOperation)dropOperation
@@ -3151,7 +3156,7 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
if (theLowerRowIndex > [self numberOfRows])
theLowerRowIndex = [self numberOfRows];
return [self rectOfRow:theLowerRowIndex];
return [self rectOfRow:theLowerRowIndex];
}
- (CPDragOperation)draggingUpdated:(id)sender
@@ -3540,7 +3545,7 @@ var CPTableViewDataSourceKey = @"CPTableViewDataSourceKey",
else
_rowHeight = 23.0;
_intercellSpacing = [aCoder decodeSizeForKey:CPTableViewIntercellSpacingKey] || _CGSizeMake(0.0, 0.0);
_intercellSpacing = [aCoder decodeSizeForKey:CPTableViewIntercellSpacingKey] || _CGSizeMake(3.0, 2.0);
[self setGridColor:[aCoder decodeObjectForKey:CPTableViewGridColorKey] || [CPColor grayColor]];
_gridStyleMask = [aCoder decodeIntForKey:CPTableViewGridStyleMaskKey] || CPTableViewGridNone;
+3 -2
View File
@@ -48,7 +48,8 @@
_tableColumns = [aCoder decodeObjectForKey:@"NSTableColumns"];
[_tableColumns makeObjectsPerformSelector:@selector(setTableView:) withObject:self];
_intercellSpacing = CGSizeMake(0.0, 0.0);//CGSizeMake([aCoder decodeFloatForKey:"NSIntercellSpacingWidth"], [aCoder decodeFloatForKey:"NSIntercellSpacingHeight"]);
_intercellSpacing = CGSizeMake([aCoder decodeFloatForKey:@"NSIntercellSpacingWidth"],
[aCoder decodeFloatForKey:@"NSIntercellSpacingHeight"]);
var gridColor = [aCoder decodeObjectForKey:@"NSGridColor"];
@@ -56,7 +57,7 @@
if ([gridColor isEqual:[CPColor colorWithRed:127.0 / 255.0 green:127.0 / 255.0 blue:127.0 / 255.0 alpha:1.0]])
gridColor = [CPColor colorWithRed:229.0 / 255.0 green:229.0 / 255.0 blue:229.0 / 255.0 alpha:1.0];
[self setValue:gridColor forThemeAttribute:"grid-color"];
[self setValue:gridColor forThemeAttribute:@"grid-color"];
_gridStyleMask = [aCoder decodeIntForKey:@"NSGridStyleMask"];