RE: NSTableView lost focus detection
RE: NSTableView lost focus detection
- Subject: RE: NSTableView lost focus detection
- From: Keith Blount <email@hidden>
- Date: Fri, 1 Apr 2005 02:04:55 -0800 (PST)
- Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys
Hello, I do exactly the same as you want to do in an
NSCell subclass that I use inside an outline view.
This is the override of NSCell's
drawInteriorWithFrame:controlView: method that does
what you want, changing the text to white if the cell
is selected and the view has focus, otherwise setting
it to black:
// Deal with drawing the text inside the cell
ourselves
- (void)drawInteriorWithFrame:(NSRect)cellFrame
inView:(NSView *)controlView
{
// First get the string and string attributes
NSString *string = [self stringValue];
NSMutableDictionary *attribs = [[[self
attributedStringValue] attributesAtIndex:0
effectiveRange:nil] mutableCopy];
// If the cell is selected and its control view is
the first responder, draw the text white
if ([self isHighlighted] && ([[controlView window]
firstResponder] == controlView) )
[attribs setObject:[NSColor whiteColor]
forKey:NSForegroundColorAttributeName];
// Then adjust the drawing rectangle and draw the
text so that it is centered vertically
NSSize stringSize = [string
sizeWithAttributes:attribs];
cellFrame.origin.x += 4.0;
cellFrame.size.width -= 4.0;
cellFrame.origin.y += (cellFrame.size.height -
stringSize.height)/2;
cellFrame.size.height = stringSize.height;
[string drawInRect:cellFrame withAttributes:attribs];
[attribs release];
}
Note that because I am using this cell in an outline
view that that emulates Mail's and therefore has
different cell heights, in the last part of the method
I center the text vertically. You may want to change
the cellFrame.origin to get default behaviour, though
I don't think you will tell the difference if your
cells are just the default 16/17 pixels high.
Hope that helps,
Keith
__________________________________
Yahoo! Messenger
Show us what our next emoticon should look like. Join the fun.
http://www.advision.webevents.yahoo.com/emoticontest
_______________________________________________
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