A followup on this particular problem that Jonathan reported for people to reference:

On Mar 12, 2009, at 3:51 AM, jonat...@mugginsoft.com wrote:

NSTableViewSelectionHighlightStyleSourceList.


The source list style attempts to add auto-formatting to the cell by setting the attributed string for you, if you give it a plain string. This is how the text automatically becomes bold. However, once the attributed string has been created, it will use the settings already set on the cell to format the value. -willDisplayCell: is the last thing that is called in -preparedCellAtColumn:row:, allowing the developer to change anything that the tableview automatically set.

- (void)tableView:(NSTableView *)aTableView willDisplayCell:(id) aCell forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger) rowIndex
{
// note that when the NSTableView Highlight mode is set to source list
        // setting the text color of NSTextFieldCell seems to misbehave.
        if ([aCell isKindOfClass:[NSTextFieldCell class]]) {
                if ([aCell isHighlighted]) {

Instead of using -isHighlighted, a more appropriate check would be:

if ([aCell backgroundStyle] == NSBackgroundStyleDark || [aCell backgroundStyle] == NSBackgroundStyleLowered) {


                        [aCell setTextColor: [NSColor lightGrayColor]];
                } else {
                        [aCell setTextColor: [NSColor darkGrayColor]];
                }

Based on my above information, one can work around the issue by letting the cell reformat its value. This looses the custom bold attributes applied, but fixes the problem and is a work around:

                [aCell setStringValue:[aCell stringValue]];

        }
}


Alternatively, you could hook into the process earlier. The earliest point is -tableView:dataCellForTableColumn:row:. You could solve this type of issue with the following code:

- (NSCell *)tableView:(NSTableView *)tableView dataCellForTableColumn: (NSTableColumn *)tableColumn row:(NSInteger)row { NSTextFieldCell *result = (NSTextFieldCell *)[tableColumn dataCell];
    if ([[tableView selectedRowIndexes] containsIndex:row]) {
// This ignores the fact that we use different colors in a table that has the first responder status
        [result setTextColor: [NSColor blueColor]];
    } else {
        [result setTextColor: [NSColor yellowColor]];
    }
    return result;
}

Either solution is perfectly acceptable, and we'll increase our documentation to help developers understand the process of displaying cells.

corbin



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to