objective c - NSOutlineView Changing group row color -


in nsoutlineview using custom cell subclassed nstextfieldcell, need draw different color group row , normal row, when selected,

to so, have done following ,

-(id)_highlightcolorforcell:(nscell *)cell {     return [nscolor colorwithcalibratedwhite:0.5f alpha:0.7f]; } 

yep know private api, couldn't found other way, working normal row, no effect on group row, there way change group color,

kind regards rohan

you can without relying on private api's, @ least if willing require mac os x 10.4 or better.

put following in cell subclass:

- (nscolor *)highlightcolorwithframe:(nsrect)cellframe inview:(nsview *)controlview {   // returning nil circumvents standard row highlighting.   return nil; } 

and subclass nsoutlineview , re-implement method, - (void)highlightselectionincliprect:(nsrect)cliprect;

here's example draws 1 color non-group rows , group rows

- (void)highlightselectionincliprect:(nsrect)cliprect {   nsindexset *selectedrowindexes = [self selectedrowindexes];   nsrange visiblerows = [self rowsinrect:cliprect];    nsuinteger selectedrow = [selectedrowindexes firstindex];   while (selectedrow != nsnotfound)   {     if (selectedrow == -1 || !nslocationinrange(selectedrow, visiblerows))      {       selectedrow = [selectedrowindexes indexgreaterthanindex:selectedrow];       continue;     }         // determine if group row or not     id delegate = [self delegate];     bool isgrouprow = no;     if ([delegate respondstoselector:@selector(outlineview:isgroupitem:)])     {       id item = [self itematrow:selectedrow];       isgrouprow = [delegate outlineview:self isgroupitem:item];     }      if (isgrouprow)     {        [[nscolor alternateselectedcontrolcolor] set];     } else {       [[nscolor secondaryselectedcontrolcolor] set];     }      nsrectfill([self rectofrow:selectedrow]);     selectedrow = [selectedrowindexes indexgreaterthanindex:selectedrow];   } } 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -