Skip navigation.
 
mlRe: NSBrowserCell not extensible; need sample using NSButtonCell
FROM : Corbin Dunn
DATE : Thu Jul 20 23:32:35 2006

>
> 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!


Well -- the default cell created for you by an OutlineView or 
TableView is an NSTextFieldCell...but you can control it by setting it 
to whatever you want to in IB and using the custom class after it is 
selected (you must drag a cell over from the ib palette first, and 
then click the white triangle in the top right of the column to see 
the cell's properties in an iB inspecdtor).

>
> 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.



The layout is like this:


|-------------------------------------------------
| indent    | + outline cell | your cell        |
|-------------------------------------------------
| indent       | + outline cell | your cell    |
|-------------------------------------------------
....

Your cell (NSTextFieldCell) in this case has nothing to do with the 
disclosure triangle cell. They are separate.


> 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.


Well..I know you can; as I said before, the NSOutlineView does this.

> 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.


Okay -- you need to make sure the cell's background color is set to 
[NSColor clearColor] or nil, and not white. So, you can draw your 
stuff without having it overwrite you when it draws the background.

If you want to control the highlight color, you can use 
highlightColorWithFrame:inView: and return something special (or nil).

>
> 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.)


It will work; you just have to make sure the background color isn't set.

>
> 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.


It should work fine in both; as I said, the open panel uses the same 
cell in the NSOutlineView and NSBrowser.

>

>>> 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.


It uses the same cell "stamped out" on each row...just like every 
other cell.

> I surmised that NSBrowserCell does that (and it still might),


NSBrowserCell does not; NSBrowser uses an individual cell for each col/
row you see, since it uses NSMatrix. NSTableView (and hence 
NSOutlineView, its subclass), do not; they use the same cell stamped 
out on each row.

> but now it looks like NSOutlineView does all of that work itself 
> (again, via NSButtonCell).


Yes; it handles the rotation animation. The down look, etc...but this 
can be customized in the delegate method I mentioned (side note: the 
animation can't be customized).

>

>>> 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.


Okay -- I'm still confused as to what you want to do.

Heck, you could replace the NSTextFieldCell in the NSOutlineView 
column with an NSButtonCell -- just drag it over in IB, if that's all 
you need to do.

-corbin

Related mailsAuthorDate
mlNSBrowserCell not extensible; need sample using NSButtonCell James Bucanek Jul 20, 18:53
mlRe: NSBrowserCell not extensible; need sample using NSButtonCell Corbin Dunn Jul 20, 19:23
mlRe: NSBrowserCell not extensible; need sample using NSButtonCell James Bucanek Jul 20, 21:48
mlRe: NSBrowserCell not extensible; need sample using NSButtonCell Corbin Dunn Jul 20, 23:32
mlRe: NSBrowserCell not extensible; need sample using NSButtonCell James Bucanek Jul 21, 00:17
mlRe: NSBrowserCell not extensible; need sample using NSButtonCell Corbin Dunn Jul 21, 00:28
mlRe: NSBrowserCell not extensible; need sample using NSButtonCell James Bucanek Jul 21, 00:31