On 20-Nov-09, at 6:57 AM, Andy Lee wrote:

On Nov 19, 2009, at 1:04 PM, Ben Haller wrote:
This led me to suspect the custom NSView subclass that I am using as a content view, and indeed, if I use that custom subclass as the content view in Andy's code, it breaks the tooltip there too.

Total shot in the dark: what if you don't change the window's content view but rather make your custom subclass a subview that fills the content view? There may be some behind-the-scenes logic specific to content views that is messing you up.

Yeah, that was what I figured too, that there is something special about the handling of the content view that means it can't be flipped, but a view inside it could be. But it turns out that is not the case; the following code exhibits the same bug:

- (void)awakeFromNib
{
NSWindow *testWindow = [[NSWindow alloc] initWithContentRect:NSMakeRect(100, 100, 500, 500)
                                                                                
                           styleMask:(NSTitledWindowMask | 
NSResizableWindowMask)
                                                                                
                                 backing:NSBackingStoreBuffered
                                                                                
                                   defer:YES];
        
        NSRect contentFrame = [[testWindow contentView] frame];
AKDocumentContentView *newContentView = [[AKDocumentContentView alloc] initWithFrame:contentFrame]; [newContentView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
        [[testWindow contentView] addSubview:newContentView];
        
NSButton *testButton = [[NSButton alloc] initWithFrame:NSMakeRect(100, 50, 100, 20)];
        [testButton setTitle:@"Hover Over Me"];
        [testButton sizeToFit];
        [testButton setToolTip:@"This is an NSButton"];
        [newContentView addSubview:testButton];

NSView *testView = [[NSView alloc] initWithFrame:NSMakeRect(100, 100, 100, 20)];
        [testView setToolTip:@"This is a test view"];
        [newContentView addSubview:testView];
        
        [testWindow setContentSize:NSMakeSize(500, 600)];
        [testWindow makeKeyAndOrderFront:self];
}

Where the AKDocumentContentView is, as before, a subclass of NSView that simply returns YES from -isFlipped and is otherwise empty. So it looks like it is a general bug that bites you when:

1. you add a new view, with a tooltip already set, to a superview
2. the superview returns YES from -isFlipped
3. the superview then gets resized as a consequence of a - setContentSize: call (but not a user resize, for some reason)

If any of these conditions are not met, then the tooltip will work fine. I've gone with the workaround of setting all my tooltips after I have set the final size on my window, and that is working fine for me for the time being, although it would be nice to have a workaround that would let me change the size of the window later on without all the tooltips suddenly breaking.

Thanks to everybody for their help in tracking this down. I think I'm having to re-learn the deductive mindset I used to have in tracking down problems like this; many aspects of coding have come back to me quite quickly after my six-year break from it, but I'm a bit rusty at this kind of analysis. :->

Ben Haller
Stick Software

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to