NSOutlineView Control HighLight and indentation

1k views Asked by At

In my Outline view, i am using CustomCell, which is nothing but took the code from Cocoa ImageTextCell RefrenceCode with some modification,

Is it possible to change the highlight color for a cell ?

So far i have done following, - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {

if([self isHighlighted]){
    NSColor *evenColor = [NSColor colorWithCalibratedRed:.1 green:0.1 blue: 0.1   
         alpha:1.0];
    [evenColor set];
    NSRectFill(cellFrame);
    bSelected = YES;
}

}

This is working but what is happening, i could see, hightlight cell color first start from system default color, then, it will get override by evenColor, I feel the problem is cellFrame.origin.x, its not starting from 0,

output was as below after applying this piece of code

----- My Custom Cell ----------------
======================================
| blue |                             |
| color|    even Color               | 
|      |                             |
======================================

and what i was expecting

----- My Custom Cell ----------------
======================================
|                                    |
|    even Color                      | 
|                                    |
======================================
1

There are 1 answers

1
Alex On

The highlighting is handled by the NSOutlineView (well, actually, it's inherited behavior from NSTableView). Anyway, instead of focusing on the cell, you should take a look at subclassing NSOutlineView and overriding highlightSelectionInClipRect:. That's where you should do your custom highlight drawing.