NSBrowser tooltips (Tiger and Leopard)

  • I'm having trouble with tooltips in an NSBrowser. I posted a few days
    ago about this in a Tiger context.

    I have an NSMatrix subclass, that implements -[toolTipForCell:].

    On Tiger, this never seems to get called, and I get no tooltips.

    On Leopard, the method also doesn't get called, but I do get a
    tooltip for my root item (the first column of the browser has only
    one item), with text that seems to be taken from the text of my
    (custom) NSBrowerCell. None of the other items (incorrectly) show
    tooltips at all.

    However, after this tooltip has been displayed, the underlying
    NSBrowserCell seems to have been released by something, judging by
    the crashes I get next time it's accessed.

    Any hints as to where to look/other approaches to try would be great ...

        cheers,
              m.
  • >
    >
    > On Leopard, the method also doesn't get called, but I do get a
    > tooltip for my root item (the first column of the browser has only
    > one item), with text that seems to be taken from the text of my
    > (custom) NSBrowerCell. None of the other items (incorrectly) show
    > tooltips at all.
    >

    That's the expansion tool tip. It is documented, and mentioned in the
    release notes:

    http://developer.apple.com/releasenotes/Cocoa/AppKit.html

    > NSCell Automatic Expansion ToolTip FrameNSCell has some new API to
    > support expansion tool tips in certain controls:
    > - (NSRect)expansionFrameWithFrame:(NSRect)cellFrame inView:(NSView
    > *)view;
    > - (void)drawWithExpansionFrame:(NSRect)cellFrame inView:(NSView
    > *)view;
    > An expansion tool tip allows one to see truncated text in a special
    > floating window that is similar but different from a normal ToolTip.
    > Currently, NSTableView, NSOutlineView and NSBrowser display
    > expansion tool tips when the text is truncated. If you have a cell
    > that will be displayed in one of these controls, it is recommended
    > that you implement the above methods to properly support the
    > expansion tool tip feature. By default, the methods are properly
    > implemented in NSTextFieldCell and NSBrowserCell. NSCell will always
    > return NSZeroRect, and prevent the expansion from happening. For an
    > example of how to implement it, see the SimpleBrowser demo app.
    >
    > Clients of NSTableView, NSOutlineView and NSBrowser can prevent the
    > cell expansion from happening on a particular row/column by using
    > the new delegate methods declared in the appropriate header files.
    >
    >

    > However, after this tooltip has been displayed, the underlying
    > NSBrowserCell seems to have been released by something, judging by
    > the crashes I get next time it's accessed.

    This is because you aren't properly implementing copyWithZone; in it,
    you should retain or copy your ivars.

    corbin
  • Thanks Corbin,

    copyWithZone certainly fixed the crashes.

    I implemented the new delegate methods for expansion tooltips in my
    NSBrowser and NSOutlineView (I hadn't noticed a similar rogue tooltip
    there) delegates (with an #ifdef for NSInteger to let it compile
    against Tiger), returning NO.

    Bizarrely, NSLog's in the delegate methods never seem to produce any
    output, but the rogues tips seem to have gone away.

    I'm still pretty puzzled, as although what I was seeing can't really
    be anything except the expansion tooltips, the cells in question
    weren't actually truncated, and it only seems to happen for the first
    (left uppermost) cell in my NSBrowser, and the first child of the
    root item in an NSOutlineView.

    If I have time, I'll go back and see if I can work out what's going on.

    I'd still love to know how to get proper tooltips working in
    NSBrowser though.

        cheers,
                m.

    On 6 Nov 2007, at 23:09, Corbin Dunn wrote:

    >>
    >>
    >> On Leopard, the method also doesn't get called, but I do get a
    >> tooltip for my root item (the first column of the browser has only
    >> one item), with text that seems to be taken from the text of my
    >> (custom) NSBrowerCell. None of the other items (incorrectly) show
    >> tooltips at all.
    >>
    >
    > That's the expansion tool tip. It is documented, and mentioned in
    > the release notes:
    >
    > http://developer.apple.com/releasenotes/Cocoa/AppKit.html
    >
    >> NSCell Automatic Expansion ToolTip FrameNSCell has some new API to
    >> support expansion tool tips in certain controls:
    >> - (NSRect)expansionFrameWithFrame:(NSRect)cellFrame inView:(NSView
    >> *)view;
    >> - (void)drawWithExpansionFrame:(NSRect)cellFrame inView:(NSView *)
    >> view;
    >> An expansion tool tip allows one to see truncated text in a
    >> special floating window that is similar but different from a
    >> normal ToolTip. Currently, NSTableView, NSOutlineView and
    >> NSBrowser display expansion tool tips when the text is truncated.
    >> If you have a cell that will be displayed in one of these
    >> controls, it is recommended that you implement the above methods
    >> to properly support the expansion tool tip feature. By default,
    >> the methods are properly implemented in NSTextFieldCell and
    >> NSBrowserCell. NSCell will always return NSZeroRect, and prevent
    >> the expansion from happening. For an example of how to implement
    >> it, see the SimpleBrowser demo app.
    >>
    >> Clients of NSTableView, NSOutlineView and NSBrowser can prevent
    >> the cell expansion from happening on a particular row/column by
    >> using the new delegate methods declared in the appropriate header
    >> files.
    >>
    >>
    >
    >
    >
    >> However, after this tooltip has been displayed, the underlying
    >> NSBrowserCell seems to have been released by something, judging by
    >> the crashes I get next time it's accessed.
    >
    > This is because you aren't properly implementing copyWithZone; in
    > it, you should retain or copy your ivars.
    >
    > corbin
    >
previous month november 2007 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today