[futurebasic] Yosemite show sheet window bug

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : October 2014 : Group Archive : Group : All Groups

From: Bernie <fblist.bw@...>
Date: Sat, 18 Oct 2014 16:57:36 +0200
Noticed a possible cosmetic bug when showing a sheet window in Yosemite. Only seems to be when displaying a sheet as the result of a popup button action. The sheet doesn’t animate down from the window title bar, it just appears (boom!).

In this example, click the Show Sheet button and the sheet appears as normal. Close the sheet then choose a popup item.

Delaying the display of the sheet by 1 second fixes it, but isn’t really an ideal solution. Can anyone come up with a better fix?
'---------------
BeginCDeclaration
@interface AppDelegate : NSObject {
     NSWindow *_window;
     NSWindow *_sheet;
}
@end
EndC

BeginCFunction
@implementation AppDelegate

- (void)applicationWillFinishLaunching:(NSNotification *)notification {
     [self buildMainMenu];
     [self buildSheet];
     [self buildWindow];
}

- (void)didEndSheet:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo {
    [sheet orderOut:self];
}

- (void)showSheet:(id)sender {
     [NSApp beginSheet:_sheet modalForWindow:_window modalDelegate:self didEndSelector:@selector(didEndSheet:returnCode:contextInfo:) contextInfo:nil];
}

- (void)closeSheet:(id)sender {
     [NSApp endSheet:_sheet];
}

- (void)buildMainMenu {
     NSMenu *mainMenu = [[[NSMenu alloc] initWithTitle:@"MainMenu"] autorelease];
     NSMenuItem *item;
     item = [mainMenu addItemWithTitle:@"" action:nil keyEquivalent:@""];
     NSMenu *mApp = [[[NSMenu alloc] initWithTitle:@""] autorelease];
     [mainMenu setSubmenu:mApp forItem:item];
     [mApp addItem:[NSMenuItem separatorItem]];
     [mApp addItemWithTitle:@"Quit" action:@selector(terminate:) keyEquivalent:@"q"];
     [NSApp setMainMenu:mainMenu];
}

- (void)buildSheet {
     _sheet = [[NSWindow alloc] initWithContentRect:NSMakeRect(131,158,380,133) styleMask:NSTitledWindowMask | NSResizableWindowMask backing:NSBackingStoreBuffered defer:NO];
     NSView *contentView = [_sheet contentView];

     // view1 - NSButton
     NSButton *view1 = [[NSButton alloc] initWithFrame:NSMakeRect(152,13,76,32)];
     [view1 setAutoresizingMask:NSViewMaxXMargin | NSViewMinYMargin];
     [view1 setFont:[NSFont fontWithName:@".HelveticaNeueDeskInterface-Regular" size:13]];
     [view1 setBezelStyle:NSRoundedBezelStyle];
     [view1 setTitle:@"Close"];
     [view1 setTarget:self];
     [view1 setKeyEquivalent:@"\r"];
     [view1 setAction:@selector(closeSheet:)];
     [contentView addSubview:view1];
     [view1 release];
}

- (void)buildWindow {
     _window = [[NSWindow alloc] initWithContentRect:NSMakeRect(98,449,480,360)
          styleMask:NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask
          backing:NSBackingStoreBuffered defer:NO];
     [_window setTitle:@"Window"];
     NSView *contentView = [_window contentView];

     // view1 - NSButton
     NSButton *view1 = [[NSButton alloc] initWithFrame:NSMakeRect(183,13,115,32)];
     [view1 setAutoresizingMask:NSViewMaxXMargin | NSViewMinYMargin];
     [view1 setFont:[NSFont fontWithName:@".HelveticaNeueDeskInterface-Regular" size:13]];
     [view1 setBezelStyle:NSRoundedBezelStyle];
     [view1 setTitle:@"Show Sheet"];
     [view1 setTarget:self];
     [view1 setAction:@selector(showSheet:)];
     [contentView addSubview:view1];
     [view1 release];

     // view2 - NSPopUpButton
     NSPopUpButton *view2 = [[NSPopUpButton alloc] initWithFrame:NSMakeRect(181,167,120,26) pullsDown:NO];
     [view2 setAutoresizingMask:NSViewMaxXMargin | NSViewMinYMargin];
     NSArray *view2_itemArray = [NSArray arrayWithObjects: @"Item 1", @"Item 2", @"Item 3", nil];
     [view2 addItemsWithTitles:view2_itemArray];
     [view2 selectItemAtIndex:0];
     [view2 setTarget:self];
     [view2 setAction:@selector(showSheet:)];
     [contentView addSubview:view2];
     [view2 release];

     [_window makeKeyAndOrderFront:nil];
}
@end
EndC

BeginCCode
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
[NSApplication sharedApplication];
AppDelegate *myDelegate = [[[AppDelegate alloc] init] autorelease];
[NSApp setDelegate:myDelegate];
[NSApp run];
[pool drain];
EndC
'---------------