Table view and cell drawing updates

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/branches/gnustep_testplant_branch@37351 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Marcian Lytwyn 2013-11-01 23:20:18 +00:00
parent b951ff0d8b
commit e1498b311a
3 changed files with 91 additions and 9 deletions

View file

@ -70,6 +70,7 @@
- (float *)_columnOrigins;
- (void) _willDisplayCell: (NSCell*)cell forTableColumn: (NSTableColumn *)tb row: (int)index;
- (NSCell *) _dataCellForTableColumn: (NSTableColumn *)tb row: (int) rowIndex;
- (BOOL)_isGroupRow: (NSInteger)rowIndex;
@end
@interface NSCell (Private)
@ -2611,11 +2612,9 @@ static NSDictionary *titleTextAttributes[3] = {nil, nil, nil};
return;
}
BOOL respondsToIsGroupRow = [[tableView delegate] respondsToSelector:@selector(tableView:isGroupRow:)];
// First, determine whether the table view delegate wants this row
// to be a grouped cell row...
if (respondsToIsGroupRow && [[tableView delegate] tableView:tableView isGroupRow:rowIndex])
if ([tableView _isGroupRow:rowIndex])
{
cell = [tableView preparedCellAtColumn: -1 row:rowIndex];
if (cell)
@ -2631,7 +2630,6 @@ static NSDictionary *titleTextAttributes[3] = {nil, nil, nil};
[cell _setInEditing: NO];
[cell setShowsFirstResponder:NO];
[cell setFocusRingType:NSFocusRingTypeNone];
[cell setBackgroundStyle:NSBackgroundStyleDark];
// Get the drawing rectangle...
drawingRect = [tableView frameOfCellAtColumn: 0 row: rowIndex];

View file

@ -2870,10 +2870,10 @@ static NSColor *dtxtCol;
switch (_cell.background_style)
{
#if 0
case NSBackgroundStyleDark:
{
NSFont *font = [NSFont fontWithName:@"LucidaGrande-Bold" size:12.0];
NSColor *color = [NSColor colorWithCalibratedWhite:0.458824 alpha:1.0];
NSColor *color = [NSColor alternateSelectedControlTextColor];
/* Note: There are only a few possible paragraph styles for cells.
TODO: Cache them and reuse them for the whole app lifetime. */
@ -2883,7 +2883,7 @@ static NSColor *dtxtCol;
[paragraphStyle setAlignment: [self alignment]];
attr = [[NSDictionary alloc] initWithObjectsAndKeys:
font, NSFontAttributeName,
_font, NSFontAttributeName,
color, NSForegroundColorAttributeName,
paragraphStyle, NSParagraphStyleAttributeName,
nil];
@ -2891,11 +2891,49 @@ static NSColor *dtxtCol;
break;
}
// TODO: Add raised style settings...
case NSBackgroundStyleRaised:
{
NSColor *color = [NSColor colorWithCalibratedWhite: 0.0 alpha: 1.0];
/* Note: There are only a few possible paragraph styles for cells.
TODO: Cache them and reuse them for the whole app lifetime. */
NSMutableParagraphStyle *paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
[paragraphStyle setLineBreakMode: [self lineBreakMode]];
[paragraphStyle setBaseWritingDirection: [self baseWritingDirection]];
[paragraphStyle setAlignment: [self alignment]];
attr = [[NSDictionary alloc] initWithObjectsAndKeys:
_font, NSFontAttributeName,
color, NSForegroundColorAttributeName,
paragraphStyle, NSParagraphStyleAttributeName,
nil];
RELEASE (paragraphStyle);
break;
}
// TODO: Add lowered style settings...
case NSBackgroundStyleLowered:
{
NSColor *color = [NSColor colorWithCalibratedWhite: 1.0 alpha: 1.0];
/* Note: There are only a few possible paragraph styles for cells.
TODO: Cache them and reuse them for the whole app lifetime. */
NSMutableParagraphStyle *paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
[paragraphStyle setLineBreakMode: [self lineBreakMode]];
[paragraphStyle setBaseWritingDirection: [self baseWritingDirection]];
[paragraphStyle setAlignment: [self alignment]];
attr = [[NSDictionary alloc] initWithObjectsAndKeys:
_font, NSFontAttributeName,
color, NSForegroundColorAttributeName,
paragraphStyle, NSParagraphStyleAttributeName,
nil];
RELEASE (paragraphStyle);
break;
}
case NSBackgroundStyleLight:
#endif
default:
{
NSColor *color = [self textColor];

View file

@ -3189,6 +3189,35 @@ byExtendingSelection: (BOOL)flag
* Providing Cells
*/
- (void)_addGroupRowAttributesToCell:(NSCell*)cell withData:(id)objectValue highlighted:(BOOL)highlighted
{
if ([objectValue isKindOfClass:[NSString class]])
{
NSString *fontname = [NSString stringWithFormat:@"%@-Bold",[[cell font] fontName]];
CGFloat fontsize = [[cell font] pointSize];
NSFont *font = [NSFont fontWithName:fontname size:fontsize];
NSColor *color = [NSColor colorWithCalibratedWhite:0.458824 alpha:1.0];
/* Note: There are only a few possible paragraph styles for cells.
TODO: Cache them and reuse them for the whole app lifetime. */
NSMutableParagraphStyle *paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
[paragraphStyle setLineBreakMode: [cell lineBreakMode]];
[paragraphStyle setBaseWritingDirection: [cell baseWritingDirection]];
[paragraphStyle setAlignment: [cell alignment]];
NSDictionary *attributes = [[NSDictionary alloc] initWithObjectsAndKeys:
font, NSFontAttributeName,
color, NSForegroundColorAttributeName,
paragraphStyle, NSParagraphStyleAttributeName,
nil];
objectValue = [[NSAttributedString alloc] initWithString:objectValue attributes:attributes];
RELEASE(paragraphStyle);
// Replace the cell's object value...
[cell setObjectValue:objectValue];
}
}
- (NSCell *) preparedCellAtColumn: (NSInteger)columnIndex row: (NSInteger)rowIndex
{
NSCell *cell = nil;
@ -3210,7 +3239,24 @@ byExtendingSelection: (BOOL)flag
if (cell)
{
// Get the object value from the delegate or nil...
[cell setObjectValue:[self _objectValueForTableColumn:tb row:rowIndex]];
id objectValue = [self _objectValueForTableColumn:tb row:rowIndex];
// Set the cell's object value...
[cell setObjectValue:objectValue];
// If grouped row the add the necessary group row attributes...
if ([self _isGroupRow:rowIndex])
{
// Force reset from other attributes then set dark...
[cell setBackgroundStyle:NSBackgroundStyleLight];
[cell setBackgroundStyle:NSBackgroundStyleDark];
// If the object value is a NSString type...
// Cocoa uses the object value as is if it is a NSAttributedString already...
if ([cell isKindOfClass:[NSTextFieldCell class]] &&
[objectValue isKindOfClass:[NSString class]])
[self _addGroupRowAttributesToCell:cell withData:objectValue highlighted:YES];
}
// Inform delegate we are getting ready to display
[self _willDisplayCell: cell forTableColumn: tb row: rowIndex];