Re: [NSTableview] can't make selected text stay black
Re: [NSTableview] can't make selected text stay black
- Subject: Re: [NSTableview] can't make selected text stay black
- From: Keith Blount <email@hidden>
- Date: Sun, 14 Mar 2010 15:58:30 -0700 (PDT)
Hi Kent,
You're absolutely right! Thanks for sharing this. For myself, I have tables and outline views that draw a custom highlight and need the text colour to stay black, but your solution works for that too. The key, as you say, is calling -setHighlighted: to NO on the cell in the delegate method, and that is what I had missed before (given that I want to draw a highlight in my table, it hadn't occurred to me that I needed to prevent the cell drawing a highlight - but of course, that is all the private method was doing anyway). This prevents the cell from changing its text colour but I can still draw my custom highlights in the table/outline view subclasses. I need to test on Tiger (which I support and where NSBackgroundStyleLight isn't supported) to check that the private method isn't necessary there, but I believe you have just obviated my need for the private method altogether, which is great as resorting to private methods is never good - thanks! It seems
you have definitely found the best way of doing this.
All the best,
Keith
________________________________
From: Kent Hauser <email@hidden>
To: Keith Blount <email@hidden>; Corbin Dunn <email@hidden>
Cc: email@hidden
Sent: Sun, March 14, 2010 8:09:27 PM
Subject: Re: [NSTableview] can't make selected text stay black
Now I'm all confused. Everything's working now where it wasn't before.
I'm having the desired result (selected cell not appearing selected) by following Corbin's original advice:
override NSTable's -hightlightSelectionInClipRect: to do nothing & having the delegate method
- tableView:willDisplayCell:forTableColumn:row: perform setHighlighted:NO & setBackgroundStyle:NSBackgroundStyleLight on the cell.
I'm getting backColor text as desired.
Also, if I send [cell setHighlighted:NO], the cell's -highlightColorWithFrame:controlView: is not called, shao wholesale subclassing of cells does not appear to be needed.
My guess as to what I had wrong before was that I had set hightlight style to "source list" in IB when exploring & had not set it back to normal. I'm testing now with a programmaticly generated NSTableView.
Thanks for all your help.
Kent
On Fri, Mar 12, 2010 at 3:48 PM, Keith Blount <email@hidden> wrote:
Actually, after testing this, does overriding NSCell's -highlightColorWithFrame:controlView: really have the same effect as overriding the _highlightColorForCell: private message? I assume the latter just calls the former, but I must be doing something wrong because overriding -highlightColorWithFrame: didn't have the desired effect for me. Please see the following demo project:
>
>http://www.literatureandlatte.com/misc/BlackSelectedTableText.zip
>
>>Note that in that simple project, MyTextFieldCell overrides -highlightColorWithFrame:controlView: to return nil (and there is an NSLog in there to ensure it is getting called), but although doing so prevents the highlight colour from getting drawn, the text still gets drawn in white (even though the -willDisplayCell: delegate method in MyDocument is setting it to black). Contrast this with uncommenting the _highlightColorForCell: method that returns nil in MyTableView, which has the desired effect of ensuring the text gets drawn in black (which is what the op was after and is the reason I ended up resorting to this private message).
>
>>Am I missing something obvious? Is there something else that needs to be used in conjunction with this to force the text to be drawn in black even when highlighted? (To put this in context, I use NSOutlineView to provide an OmniOutliner-style outline with a light blue selection, so the text needs to be black even when highlighted given the light highlight, which is custom-drawn.)
>
>>Many thanks and all the best,
>
>Keith
>
>
>>----- Original Message ----
>>From: Corbin Dunn <email@hidden>
>>To: Keith Blount <email@hidden>
>>Cc: email@hidden; email@hidden
>>Sent: Fri, March 12, 2010 11:29:08 PM
>>Subject: Re: [NSTableview] can't make selected text stay black
>
>>>
>
>> P.S. I'm hesitant about mentioning private methods here, but I don't think there's another way of doing it - I filed an enhancement request for this method to be made public back in April '06, ID#4521167, so please do the same if you think it would be useful. I'm CC'ing Corbin so he can straighten me out on the private method thing if this is totally the wrong advice, but it works for me. :)
>
>>Thank you for logging the bug -- I do realize we could make this better. Currently, there is a way to do it (override highlightColorWithFrame:), so adding the requested method is "nice to have", but not essential.
>
>>corbin
>
>
>
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden