Re: NSButtonCell in NSTableView doesn't receive setHighlighted:
Re: NSButtonCell in NSTableView doesn't receive setHighlighted:
- Subject: Re: NSButtonCell in NSTableView doesn't receive setHighlighted:
- From: "Ken Ferry" <email@hidden>
- Date: Sat, 5 Jan 2008 10:29:46 -0800
> It's not a big deal of course, but since setHighlight: is a superclass
> method from NSCell it seems strange to me that the table doesn't treat
> all cells equally. Is this expected behaviour or is it worth filing a
> bug?
It's always fine to file a bug, but this probably isn't going to
change. There are too many clients that rely on the existing
behavior, whether they're aware of it or not.
The problem is that 'highlight' does not have a sufficiently defined
meaning at the NSCell level. Different cells use the flag in
different ways, which makes it difficult for a client that deals with
cells generically to use it. For button and button-like objects,
highlighted means pressed. You probably don't want your buttons to
look pressed in selected table rows. NSTableView, sadly, special
cases those cells types that should not be highlighted in selected
rows.
If you can require 10.5, I suggest you take a look at -[NSCell
backgroundStyle] and related API instead. The most common reason for
a cell wanting to know that it's in a selected row is to draw
differently. For example, text drawn on top of selected rows of a
table should be white. In this case, and usually, it isn't really
that the cell is in a selected table row that's important, it's that
it's being drawn on top of something dark. The text needs to be white
for contrast.
This information is what the background style API gives you. It lets
you know some very high level information about the context where the
cell is being drawn, that it's on something 'light', 'dark', 'raised'
or 'lowered'. Please see the AppKit Leopard release notes for more
detail, and also the NSCell documentation.
-Ken
Cocoa Frameworks
On Jan 5, 2008 6:24 AM, Sebastian Morsch <email@hidden> wrote:
> Hi,
>
> I just found out that an NSButtonCell that sits in an NSTableView
> doesn't receive the setHighlighted: message from the table when it's
> displayed for a selected row. In the case of NSImageCell and
> NSTextFieldCell it DOES happen, they both receive that message from
> the table's preparedCellAtColumn:row: method.
>
> I couldn't find an answer to this in previous posts.
>
> I worked around this by subclassing NSTableView and overriding that
> method to make sure all cells get the setHighlighted:
>
> - (NSCell *)preparedCellAtColumn:(NSInteger)column row:(NSInteger)row
> {
> NSCell* cell = [super preparedCellAtColumn:column row:row];
>
> [cell setHighlighted:(row == [self selectedRow])];
>
> return cell;
> }
>
>
> It's not a big deal of course, but since setHighlight: is a superclass
> method from NSCell it seems strange to me that the table doesn't treat
> all cells equally. Is this expected behaviour or is it worth filing a
> bug?
>
>
> Sebastian
> _______________________________________________
>
> 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
>
_______________________________________________
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