NSClosableWindowMask dialog acting strange

Viewed 480

I have a Safari browser plugin, and in it, I want to open an NSWindow to display a copyright note. While the Ok button in the dialog closes the dialog's window, and works perfectly, when I click on the red close window "x" in the top left corner, it also closes the window, but it's parent window (the entire browser tab, I had the plugin running in), remains disabled, as if still a modal window was open somewhere.

I even tried to attach a new selector to the window close notification, which runs the same code as the Ok button, but still, it's not working properly.

Here is the relevant part of the code:

- (void) closeBox
{
    // called when the Ok button pressed
    [NSApp abortModal];

}

- (void)closeClicked:(NSNotification *)notification
{
    // called when the close window 'x' button pressed
    NSLog(@"Closed");
    [NSApp abortModal];
}


- (void) openBox
{
    NSRect frame = NSMakeRect(0, 0, 300, 250);
     mwin  = [[[NSWindow alloc] initWithContentRect:frame
                                     styleMask:NSClosableWindowMask |NSTitledWindowMask
                                       backing:NSBackingStoreBuffered
                                         defer:NO] autorelease];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(closeClicked:)
                                             name:NSWindowWillCloseNotification
                                           object:mwin];
    NSButton * bn;
    bn = [[[NSButton alloc] initWithFrame:NSMakeRect(10, 10, 100, 20) ] autorelease];

    [bn setButtonType:NSMomentaryPushInButton];
    [bn setTitle:@"Ok"];
    [bn setTarget:self];
    [bn setAction:@selector(closeBox)];

    [[mwin contentView] addSubview:bn];

    [NSApp runModalForWindow:mwin];   
}
2 Answers
Related