NSBrowserCell state and isHighlighted

  • Hello all,

    I'm trying to make a subclass of NSBrowserCell and I'm confused about
    using the 'state' and 'isHighlighted' methods of NSBrowserCell.

    When I override the drawing I use isHighlighted to know if I should
    draw the "current" (normally blue) color or the "clicked but no longer
    current" (normally gray) state. For some reason the cell highlights
    but then almost immediatly becomes "inactive." (Gray.) If I don't
    override any methods it works fine, of course. What am I *not* doing
    that Apple does? I hope it's trivial.

    - (void)_drawHighlightWithFrame:(NSRect)cellFrame inView:(NSView*)controlView
    {
    NSLog(@"Highlighting NSBrowserCell: %@", self);
    NSLog(@"State = %i and isHighlighted = %i of %@", [self state], [self
    isHighlighted], self);

    [self setTitle: [NSString stringWithFormat: @"%i : %i", [self state],
    [self isHighlighted]]];
    NSColor *color = nil;

    if ([self state] == NSOffState && [self isHighlighted] == YES)
    {
      color = [self activeColor];
    }
    else
    {
      color = [self inactiveColor];
    }

    if (color != nil)
    {
      if ([[color colorSpaceName] isEqualToString: @"NSPatternColorSpace"])
      {
      NSImage *image = [color patternImage];

      [image setFlipped: [controlView isFlipped]];
      [image fillHorizontalRect: cellFrame];
      }
      else
      {
      [color drawSwatchInRect: cellFrame];
      }
    }
    }

    I know I shouldn't override private methods but I'm going to do it
    this way until I get this working.

    Please help, I've been bashing my head for the last two days on this.
    Thanks in advance, Alan

    --
    // Quotes from yours truly -------------------------
    "You don't forget, you just don't remember."
    "Maturity resides in the mind."
    "Silence is the Universe's greatest gift."
    "When the World realizes that religion really is unnecessary, then it
    shall evolve."
previous month december 2006 next month
MTWTFSS
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Go to today