• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: how do you change the highlight color for rows in an NSOutlineView?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how do you change the highlight color for rows in an NSOutlineView?


  • Subject: Re: how do you change the highlight color for rows in an NSOutlineView?
  • From: Mike Morton <email@hidden>
  • Date: Fri, 17 Jun 2005 08:23:24 -0400

All --

A few weeks ago, I asked for suggestions on how to change the highlight color for an outline (the default highlight for a non-key table is light, and the text in this table is white).

I tried overriding a NSCell’s highlightColorWithFrame:inView:, but when that’s invoked for other cells in the row, it can’t know to change the color.

Corbin Dunn suggested overriding NSTableView’s highlightSelectionInClipRect:, but I wasn't able to get that to work (I forget what went wrong).


FYI, I finally found a fix which worked for me, overriding NSTableView’s undocumented _highlightColorForCell: and having it ask the delegate what to do. Code is below, in case it's useful to anyone.

At one point during debugging, I changed _highlightColorForCell: to return a sequence of colors, a new one each time it’s invoked. It’s interesting to see which colors wound up where (sorry I didn't save a screen shot to post).

-- Mike


*** in a posing subclass of NSOutlineView

+@interface NSOutlineView (UndocumentedMethods)
// Assume we have an implementation in the superclass, since someone’s
// trying to send us this message.
- (NSColor *) _highlightColorForCell: (NSCell *) aCell;
@end




// Declare this method just to shut the compiler up.
@interface NSObject (NSTableView_Color_Delegate)
- (NSColor *) tableView: (NSTableView *) aTableView
willHighlightCell: (NSCell *) aCell
withColor: (NSColor *) proposedHighlightColor;
@end




#pragma mark PRIVATE CLASS METHODS -- NSTableView OVERRIDES


// Override to let the delegate choose the background color.
// (This method is private AppKit API, but Googling suggests it’s
// used regularly and with good results. If Apple stops using this
// method, we'll just lose the ability to intercept this. We'll
// assume they won't change the arg or return type for it.)
- (NSColor *) _highlightColorForCell: (NSCell *) aCell;
{
NSColor *result;


result = [super _highlightColorForCell: aCell];


if ([[self delegate] respondsToSelector: @selector(tableView:willHighlightCell:withColor:)])
{
result = [[self delegate] tableView: self
willHighlightCell: aCell
withColor: result];
}


return result;
}


*** in the delegate class, assuming all outline/tables which have this delegate use white text

#pragma mark PUBLIC INSTANCE METHODS -- NSTableView DELEGATE (our extensions)


- (NSColor *) tableView: (NSTableView *) aTableView
willHighlightCell: (NSCell *) aCell
withColor: (NSColor *) proposedHighlightColor;
{
// If the table is the selected view in the window, the highlight
// is fine to return as-is.
if ([[aTableView window] firstResponder] == aTableView)
return proposedHighlightColor;


// All of our text is white, so substitute something which looks nicer
// than the default highlight for a non-selected table.
return [NSColor darkGrayColor];
}
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: NSPersistentDocument, Core Data & Cryptation
  • Next by Date: inset/offset path algorithm
  • Previous by thread: Re: Hotkey in Cocoa (not using carbon).
  • Next by thread: inset/offset path algorithm
  • Index(es):
    • Date
    • Thread