• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Ellipsis + Proper Expansion Frame + HScroll-Edit in 10.6 NSTableView (was "Clipped Tooltip")
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Ellipsis + Proper Expansion Frame + HScroll-Edit in 10.6 NSTableView (was "Clipped Tooltip")


  • Subject: Re: Ellipsis + Proper Expansion Frame + HScroll-Edit in 10.6 NSTableView (was "Clipped Tooltip")
  • From: Jerry Krinock <email@hidden>
  • Date: Wed, 27 Jan 2010 14:59:14 -0800

I gave up on trying to find the magic formula of settings which would make my custom subclassed NSTextFieldCell return the correct expansion frame, as the cell which is returned by -[NSTableColumn dataCell] does.  Instead, I overrode expansionFrameWithFrame:inView:, replacing the multi-line frame returned by super with a single-line frame which I calculate myself.

It solves the same problem when used in NSTokenFieldCell subclasses too.

Thanks again for the tip, Corbin.

/*!
 @brief    Calculates the expansion frame which is used to display the
 entire text in a special expansion frame tool tip, if text is truncated.

 @details  This is a workaround for the fact that -[NSTableColumn dataCell],
 even though it claims to be an NSTextFieldCell, must have some magic built
 into it which allows the expansion frame tool tip to be calculated
 correctly regardless of -wraps, -isScrollable, and -truncatesLastVisibleLine.
 The [[NSTextFieldCell alloc] init] used to draw the text in this class
 does not have that magic, so we calculate it from scratch, based on the
 current attributed string value.
*/
- (NSRect)expansionFrameWithFrame:(NSRect)frame
                           inView:(NSView*)view {
    NSRect expansionFrame = [super expansionFrameWithFrame:frame
                                           inView:view] ;
    // Since we are not using a magic NSTextFieldCell, the
    // expansionFrame at this point may be no wider than the
    // cell, and will be high enough to display the text if
    // it were wrapped to multiple lines, which it does not.
    // (You can get the correct rect if you setWraps:NO, but
    // then the ellipsis does not show when drawing normally.)
    // So we discard the size and use only the origin.

    // Super does correctly return NSZeroRect if the text
    // is not currently truncated, so we use that and do same.
    if (
        (expansionFrame.size.width == 0.0)
        &&
        (expansionFrame.size.height == 0.0)
        ) {
        return NSZeroRect ;
    }

    NSAttributedString* as = [self attributedStringValue] ;
    CGFloat height = frame.size.height ;
    CGFloat width = [as widthForHeight:height] ;
    expansionFrame.size.width = width ;
    expansionFrame.size.height = height ;
    return expansionFrame ;
}



_______________________________________________

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

References: 
 >10.6 Clips Tooltip if you return NSTextFieldCell in -dataCellForRow: (From: Jerry Krinock <email@hidden>)
 >Re: 10.6 Clips Tooltip if you return NSTextFieldCell in -dataCellForRow: (From: Corbin Dunn <email@hidden>)
 >Re: Ellipsis + Proper Expansion Frame + HScroll-Edit in 10.6 NSTableView (was "Clipped Tooltip") (From: Jerry Krinock <email@hidden>)

  • Prev by Date: Re: NSBundle unloading crash
  • Next by Date: Re: CALayer maybe silly question
  • Previous by thread: Re: Ellipsis + Proper Expansion Frame + HScroll-Edit in 10.6 NSTableView (was "Clipped Tooltip")
  • Next by thread: Re: Ellipsis + Proper Expansion Frame + HScroll-Edit in 10.6 NSTableView (was "Clipped Tooltip")
  • Index(es):
    • Date
    • Thread