First pass - alternating background colors - still needs some tweaks

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/branches/gnustep_testplant_branch@40318 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Marcian Lytwyn 2017-02-01 02:13:38 +00:00
parent 67fb2de57e
commit 6b65c7d2bb
2 changed files with 105 additions and 150 deletions

View file

@ -2956,8 +2956,8 @@ typedef enum {
width = [column width];
drawingRect.size.width = width;
cell = [column headerCell];
if ((column == highlightedTableColumn)
|| [tableView isColumnSelected: i])
if ((column == highlightedTableColumn) ||
[tableView isColumnSelected: i])
{
[cell setHighlighted: YES];
}
@ -3013,15 +3013,13 @@ typedef enum {
if ([tableView usesAlternatingRowBackgroundColors])
{
const CGFloat rowHeight = [tableView rowHeight];
NSInteger startingRow = [tableView rowAtPoint: NSMakePoint(0, NSMinY(aRect))];
NSInteger endingRow;
NSInteger i;
NSArray *rowColors = [NSColor controlAlternatingRowBackgroundColors];
const NSUInteger rowColorCount = [rowColors count];
NSRect rowRect;
NSArray *rowColors = [NSColor controlAlternatingRowBackgroundColors];
const NSUInteger rowColorCount = [rowColors count];
const CGFloat rowHeight = [tableView rowHeight];
NSInteger startingRow = [tableView rowAtPoint: NSMakePoint(0, NSMinY(aRect))];
NSInteger endingRow;
NSInteger i;
NSRect rowRect;
if (rowHeight <= 0
|| rowColorCount == 0
@ -3207,6 +3205,10 @@ typedef enum {
[selectionColor set];
}
#endif
NSColor *selectionColor = [NSColor colorWithCalibratedRed: 163 / 255.0
green: 205 / 255.0
blue: 254 / 255.0
alpha: 1.0];
if (selectingColumns == NO)
{
@ -3226,34 +3228,10 @@ typedef enum {
startingRow = 0;
if (endingRow == -1)
endingRow = numberOfRows - 1;
// FIXME: Take alternating row coloring into account...
NSArray *rowColors = [NSColor controlAlternatingRowBackgroundColors];
const NSUInteger rowColorCount = [rowColors count];
row = [selectedRows indexGreaterThanOrEqualToIndex: startingRow];
while ((row != NSNotFound) && (row <= endingRow))
{
NSColor *selectionColor = nil;
if ([tableView usesAlternatingRowBackgroundColors])
backgroundColor = [rowColors objectAtIndex: (row % rowColorCount)];
// Switch to the alternate color if the backgroundColor is white.
if([backgroundColor isEqual: [NSColor whiteColor]])
{
selectionColor = [NSColor colorWithCalibratedRed: 0.86
green: 0.92
blue: 0.99
alpha: 1.0];
}
else
{
selectionColor = [NSColor whiteColor];
}
//NSHighlightRect(NSIntersectionRect([tableView rectOfRow: row],
// clipRect));
[selectionColor set];
NSRectFill(NSIntersectionRect([tableView rectOfRow: row], clipRect));
row = [selectedRows indexGreaterThanIndex: row];
@ -3263,27 +3241,28 @@ typedef enum {
{
NSUInteger selectedColumnsCount;
NSUInteger column;
NSInteger startingColumn, endingColumn;
NSInteger startingColumn, endingColumn;
selectedColumnsCount = [selectedColumns count];
if (selectedColumnsCount == 0)
return;
return;
/* highlight selected columns */
startingColumn = [tableView columnAtPoint: NSMakePoint(NSMinX(clipRect), 0)];
endingColumn = [tableView columnAtPoint: NSMakePoint(NSMaxX(clipRect), 0)];
endingColumn = [tableView columnAtPoint: NSMakePoint(NSMaxX(clipRect), 0)];
if (startingColumn == -1)
startingColumn = 0;
startingColumn = 0;
if (endingColumn == -1)
endingColumn = numberOfColumns - 1;
endingColumn = numberOfColumns - 1;
column = [selectedColumns indexGreaterThanOrEqualToIndex: startingColumn];
while ((column != NSNotFound) && (column <= endingColumn))
{
NSHighlightRect(NSIntersectionRect([tableView rectOfColumn: column], clipRect));
column = [selectedColumns indexGreaterThanIndex: column];
[selectionColor set];
NSRectFill(NSIntersectionRect([tableView rectOfColumn: column], clipRect));
column = [selectedColumns indexGreaterThanIndex: column];
}
}
}

View file

@ -4619,7 +4619,7 @@ This method is deprecated, use -columnIndexesInRect:. */
// Group rows take up the entire row...
if ([self _isGroupRow: rowIndex])
{
frameRect.size.width = [self frame].size.width;
frameRect.size.width = _bounds.size.width;
}
else
{
@ -4661,27 +4661,6 @@ This method is deprecated, use -columnIndexesInRect:. */
_columnAutoresizingStyle = style;
}
- (void) sizeLastColumnToFit
{
if ((_super_view != nil) && (_numberOfColumns > 0))
{
CGFloat excess_width;
CGFloat last_column_width;
NSTableColumn *lastColumn;
lastColumn = [_tableColumns objectAtIndex: (_numberOfColumns - 1)];
if ([lastColumn isResizable] == NO)
{
return;
}
excess_width = NSMaxX([self convertRect: [_super_view bounds]
fromView: _super_view]) - NSMaxX(_bounds);
last_column_width = [lastColumn width] + excess_width;
// This will automatically retile the table
[lastColumn setWidth: last_column_width];
}
}
- (void) setFrame: (NSRect)frameRect
{
NSRect tmpRect = frameRect;
@ -4692,14 +4671,13 @@ This method is deprecated, use -columnIndexesInRect:. */
NSRect docRect = [(NSClipView *)_super_view documentVisibleRect];
if (rowsHeight < docRect.size.height)
{
tmpRect.size.height = docRect.size.height;
}
else
{
tmpRect.size.height = rowsHeight;
tmpRect.size.height = docRect.size.height;
}
else
{
tmpRect.size.height = rowsHeight;
}
// TODO width?
}
[super setFrame: tmpRect];
}
@ -4714,14 +4692,13 @@ This method is deprecated, use -columnIndexesInRect:. */
NSRect docRect = [(NSClipView *)_super_view documentVisibleRect];
if (rowsHeight < docRect.size.height)
{
tmpSize.height = docRect.size.height;
}
{
tmpSize.height = docRect.size.height;
}
else
{
tmpSize.height = rowsHeight;
}
// TODO width?
}
[super setFrameSize: tmpSize];
}
@ -4733,6 +4710,44 @@ This method is deprecated, use -columnIndexesInRect:. */
[self setFrame: _frame];
}
- (void) _resizeTableView
{
if (_columnAutoresizingStyle == NSTableViewUniformColumnAutoresizingStyle)
{
[self setAutoresizesAllColumnsToFit:YES];
[self sizeToFit];
}
else if (_columnAutoresizingStyle == NSTableViewLastColumnOnlyAutoresizingStyle)
{
[self sizeLastColumnToFit];
}
else if (_columnAutoresizingStyle != NSTableViewNoColumnAutoresizing)
{
NSLog(@"%s:unsupported column autoresizing style: %d", __PRETTY_FUNCTION__, _columnAutoresizingStyle);
}
}
- (void) sizeLastColumnToFit
{
if ((_super_view != nil) && (_numberOfColumns > 0))
{
CGFloat excess_width;
CGFloat last_column_width;
NSTableColumn *lastColumn;
lastColumn = [_tableColumns objectAtIndex: (_numberOfColumns - 1)];
if ([lastColumn isResizable] == NO)
{
return;
}
excess_width = NSMaxX([self convertRect: [_super_view bounds]
fromView: _super_view]) - NSMaxX(_bounds);
last_column_width = [lastColumn width] + excess_width;
// This will automatically retile the table
[lastColumn setWidth: last_column_width];
}
}
- (void) sizeToFit
{
NSTableColumn *tb;
@ -5206,9 +5221,6 @@ This method is deprecated, use -columnIndexesInRect:. */
- (void) drawRect: (NSRect)aRect
{
if ([[self autosaveName] isEqualToString:@"ConnectionList"])
NSLog(@"%s:%ld:aRect: %@ clipFrame: %@", __PRETTY_FUNCTION__, (long)__LINE__,
NSStringFromRect(aRect), NSStringFromRect([[self superview] frame]));
[[GSTheme theme] drawTableViewRect: aRect
inView: self];
}
@ -5927,23 +5939,9 @@ This method is deprecated, use -columnIndexesInRect:. */
if ([aDecoder containsValueForKey: @"NSColumnAutoresizingStyle"])
{
_columnAutoresizingStyle = [aDecoder decodeIntForKey: @"NSColumnAutoresizingStyle"];
if ([[self autosaveName] isEqualToString: @"ConnectionList"])
NSLog(@"%s:%ld: _columnAutoresizingStyle: %ld", __PRETTY_FUNCTION__, (long)__LINE__, _columnAutoresizingStyle);
if (_columnAutoresizingStyle == NSTableViewUniformColumnAutoresizingStyle)
{
[self setAutoresizesAllColumnsToFit:YES];
[self sizeToFit];
}
else if (_columnAutoresizingStyle == NSTableViewLastColumnOnlyAutoresizingStyle)
{
[self sizeLastColumnToFit];
}
else if (_columnAutoresizingStyle != NSTableViewNoColumnAutoresizing)
{
NSLog(@"%s:unsupported column autoresizing style: %d", __PRETTY_FUNCTION__, _columnAutoresizingStyle);
}
}
[self _resizeTableView];
[self tile]; /* Initialize _columnOrigins */
}
else
@ -6019,6 +6017,7 @@ This method is deprecated, use -columnIndexesInRect:. */
if (aCell == nil)
return;
// ??? Why PREMATURE RETURN ???
return;
for (i = 0; i < _numberOfColumns; i++)
@ -6064,6 +6063,7 @@ This method is deprecated, use -columnIndexesInRect:. */
width: (CGFloat)width
{
[[_tableColumns objectAtIndex: index] setWidth: width];
[self sizeLastColumnToFit];
}
- (CGFloat *) _columnOrigins
@ -6342,14 +6342,7 @@ This method is deprecated, use -columnIndexesInRect:. */
}
}
}
if (_columnAutoresizingStyle == NSTableViewUniformColumnAutoresizingStyle)
{
[self sizeToFit];
}
else if (_columnAutoresizingStyle == NSTableViewLastColumnOnlyAutoresizingStyle)
{
[self sizeLastColumnToFit];
}
[self _resizeTableView];
}
}
@ -6395,41 +6388,30 @@ This method is deprecated, use -columnIndexesInRect:. */
- (void) superviewFrameChanged: (NSNotification*)aNotification
{
CGFloat table_width = 0;
if (_numberOfColumns > 0)
{
table_width = (_columnOrigins[_numberOfColumns - 1] +
[[_tableColumns objectAtIndex: _numberOfColumns - 1] width]);
}
if (_autoresizesAllColumnsToFit == YES)
{
CGFloat visible_width = [self convertRect: [_super_view bounds]
fromView: _super_view].size.width;
CGFloat table_width = 0;
if (_numberOfColumns > 0)
{
table_width =
_columnOrigins[_numberOfColumns - 1] +
[[_tableColumns objectAtIndex: _numberOfColumns - 1] width];
}
/*
NSLog(@"columnOrigins[0] %f", _columnOrigins[0]);
NSLog(@"superview.bounds %@",
NSStringFromRect([_super_view bounds]));
NSLog(@"superview.frame %@",
NSStringFromRect([_super_view frame]));
NSLog(@"table_width %f", table_width);
NSLog(@"width %f", visible_width);
NSLog(@"_superview_width %f", _superview_width);
*/
CGFloat visible_width = [_super_view bounds].size.width;
#if 0 // Need to fix this...
if (table_width - _superview_width <= 0.001
&& table_width - _superview_width >= -0.001)
{
// the last column had been sized to fit
[self sizeToFit];
[self _resizeTableView];
}
else if (table_width <= _superview_width
&& table_width >= visible_width)
{
// the tableView was too small and is now too large
[self sizeToFit];
[self _resizeTableView];
}
else if (table_width >= _superview_width
&& table_width <= visible_width)
@ -6437,45 +6419,29 @@ This method is deprecated, use -columnIndexesInRect:. */
// the tableView was too large and is now too small
if (_numberOfColumns > 0)
[self scrollColumnToVisible: 0];
[self sizeToFit];
[self _resizeTableView];
}
#else
[self _resizeTableView];
#endif
_superview_width = visible_width;
}
else if (_columnAutoresizingStyle == NSTableViewLastColumnOnlyAutoresizingStyle)
{
CGFloat visible_width = [self convertRect: [_super_view bounds]
fromView: _super_view].size.width;
CGFloat table_width = 0;
if (_numberOfColumns > 0)
{
table_width =
_columnOrigins[_numberOfColumns - 1] +
[[_tableColumns objectAtIndex: _numberOfColumns - 1] width];
}
/*
NSLog(@"columnOrigins[0] %f", _columnOrigins[0]);
NSLog(@"superview.bounds %@",
NSStringFromRect([_super_view bounds]));
NSLog(@"superview.frame %@",
NSStringFromRect([_super_view frame]));
NSLog(@"table_width %f", table_width);
NSLog(@"width %f", visible_width);
NSLog(@"_superview_width %f", _superview_width);
*/
CGFloat visible_width = [_super_view bounds].size.width;
#if 0 // Need to fix this...
if (table_width - _superview_width <= 0.001
&& table_width - _superview_width >= -0.001)
{
// the last column had been sized to fit
[self sizeLastColumnToFit];
[self _resizeTableView];
}
else if (table_width <= _superview_width
&& table_width >= visible_width)
{
// the tableView was too small and is now too large
[self sizeLastColumnToFit];
[self _resizeTableView];
}
else if (table_width >= _superview_width
&& table_width <= visible_width)
@ -6483,11 +6449,21 @@ This method is deprecated, use -columnIndexesInRect:. */
// the tableView was too large and is now too small
if (_numberOfColumns > 0)
[self scrollColumnToVisible: 0];
[self sizeLastColumnToFit];
[self _resizeTableView];
}
#else
[self _resizeTableView];
#endif
_superview_width = visible_width;
}
[self setFrame:_frame];
else
{
_superview_width = [_super_view bounds].size.width;
}
NSRect frame = _frame;
frame.size.width = fmax(table_width, _superview_width);
[self setFrame: frame];
}