Skip navigation.
 
mlRe: - outlineView:willDisplayCell:forTableColumn:item: and selected item
FROM : Corbin Dunn
DATE : Thu Feb 28 21:09:12 2008

On Feb 26, 2008, at 10:21 PM, Seth Willits wrote:
> On Feb 26, 2008, at 3:13 PM, John Stiles wrote:
>

>> Trying to simulate the drawing behavior of NSCell seems error-prone 
>> to me. Since I don't have access to the original code, it would be 
>> hard to match its behavior. I'd much rather inherit as much as I 
>> can and only customize around the edges.

>
> You're not replicating a whole lot here, however. If you're already 
> setting the multi-colored text color in willDisplayCell: for every 
> cell, then the minimal amount of work you need should be to call 
> setTextColor before calling the super class's implementation of 
> drawInteriorWithFrame if the cell is highlighted and active.
>
>
> - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView 
> *)controlView;
> {
>     BOOL isWindowActive = [[[self controlView] window] isKeyWindow] && 
> [[NSApplication sharedApplication] isActive];
>     BOOL isControlActive = isWindowActive && ([[[self controlView] 
> window] firstResponder] == [self controlView]);    
>
>     if (isControlActive && [self isHighlighted]) {
>         [self setTextColor:[NSColor whiteColor]];
>     }
>     
>     [super drawInteriorWithFrame:cellFrame inView:controlView];
> }



I should mention a few things about this snippet of code. Under 
leopard, the "isKeyWindow/isActive" stuff isn't required; you can just 
use something like this:

BOOL isControlActive = [self interiorBackgroundStyle] == 
NSBackgroundStyleLight;
...
This will be correct in more places than the above example (which 
would be wrong for edited text).

Also, if you call setTextColor for one case, you should call 
setTextColor for the other 'else' clause too. Otherwise, any drawings 
with the same cell will use the last color set (white), unless your 
willDisplayCell resets it.

corbin