Re: NSBrowserCell not extensible; need sample using NSButtonCell
Re: NSBrowserCell not extensible; need sample using NSButtonCell
- Subject: Re: NSBrowserCell not extensible; need sample using NSButtonCell
- From: James Bucanek <email@hidden>
- Date: Thu, 20 Jul 2006 12:48:35 -0700
Corbin Dunn wrote on Thursday, July 20, 2006:
>>
>
>James,
>
>> I have several NSOutlineViews that use NSBrowserCell to display file
>> icons and names. I've already hacked up some subclasses of
>> NSBrowserCell to draw icons+filenames, dim the text, another other
>> stuff that NSBrowserCell doesn't normally do.
>
>Well, my first question is why are you using an NSBrowserCell subclass
>in an NSOutlineView? There is no reason why you have to do this, and
>generally, the reason people do this is to share the cell with
>NSBrowser.
Well, I'll be monkey's uncle. When I started playing with this a year ago, I got the dataCell of the outline view and I'd swear on a stack of bibles that is was an NSBrowserCell. Since then, I've just assumed that NSOutlineView used an NSBrowserCell for the column that includes the expansion buttons.
So I wrote a quick Cocoa app with an outline view, and darned if the cell returned by dataCell isn't an NSTextFieldCell!
I might still be interested in subclassing NSBrowserCell though, as I'm considering offering users a a browser view of their files in addition to an outline view. So I'm not entirely out of the woods yet....
But some of this discussion might be moot if I'm going to subclass NSTextFieldCell instead of NSBrowser cell. Specifically, if NSTextFieldCell is used by NSOutlineView, then I can only assume that NSOutlineView is the one that is creating, drawing, and animating all of the disclosure buttons in the outline. So maybe I don't have to emulate those button in the cell after all.
>> However, I'm hitting the wall: I need to draw things in the
>> background (think FInder labels), do more elaborate selection
>> indication,
>
>This should be possible to do with a subclassed NSBrowserCell without
>any trouble. Overriding drawInteriorWithFrame can let you do whatever
>you want. For instance, the NSOpenPanel uses a subclass of
>NSBrowserCell to draw the finder label background before everything
>else.
No you can't, and this is where I got stuck. [NSBrowserCell drawInteriorWithFrame] draws everything, including the background with a highlight color of the cell's choosing. You can't call [super drawInteriorWithFrame] first, or everything (including the background) is already drawn and you're just stuck drawing over it. Anything you draw first gets wiped when [super drawInteriorWithFrame] is called. So it's a catch-22 if you want to draw your own background. You either don't, or you draw everything yourself.
What I was really hoping or was a -[NSCell drawBackgroundOfFrame] message that I could override to draw my own background, while letting the base class draw the contents of the cell. (I feel that this is an architectural oversight in the framework.)
And if I decide to provide an NSBrowserView in my interface and I want to emulate the same background look as my outline view, I might still end up tackling this problem.
>> But the NSBrowserCell class just wasn't built to be extended.
>
>What are you having trouble extending? It is built to be extended.
See above.
>> The only choice I see is to roll my own and replace NSBrowserCell
>> entirely.
>
>That would be fine too; there is nothing that requires an
>NSBrowserCell to be used in an NSTableView or NSOutlineView.
>
>
>> Here are my questions:
>>
>> The big deal will be getting the disclosure controls to work the
>> same way they do in NSBrowserCell.
>
>I think you have some confusion here; the disclosure triangle in an
>NSOutlineView does not use an NSBrowserCell. It is an NSButtonCell. It
>is not easily customizable, but you can customize it a little in
>willDisplayOutlineCell (delegate method).
I understand that (which I explained later.) Clearly, something uses and NSButtonCell to draw the disclosure triangles as I doubt NSOutlineView adds thousands of individual NSButton subviews. I surmised that NSBrowserCell does that (and it still might), but now it looks like NSOutlineView does all of that work itself (again, via NSButtonCell).
>> I've looked at Joar's code on placing NSViews into a NSTable
><http://www.stepwise.com/Articles/Technical/2003-12-20.01.html
>> >, but that sounds very heavy handed or the disclosure triangle -- I
>> don't want to add thousands of NSButton views to my table. I would
>> assume that NSBrowserCell uses a single NSButtonCell to draw and
>> animate all of the "buttons" in the table, but I have no idea how to
>> use an NSCell to "fake" a button display. Does anyone have sample
>> code that does this?
>
>You can have an NSCell subclass which draws a button area and tracks
>just that button area. You can also have a subclassed NSCell that uses
>another NSButtonCell to delegate drawing and tracking to.
>
>> Does anyone know how NSOutlineView handles the indenting of items in
>> the column that controls the outline?
>
>Yes -- I do know! What types of things are you wanting to know or do?
Uh, emulate a button using NSButtonCell -- which I thought I stated pretty clearly. But ignore that request for now as I might not have to.
--
James Bucanek
_______________________________________________
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