Re: modal alert sheets
Re: modal alert sheets
- Subject: Re: modal alert sheets
- From: Kristin Webster <email@hidden>
- Date: Mon, 12 Aug 2002 17:50:16 -0700
Hi Robert,
It is a general problem that we do not officially support app-modal
sheets. However, several applications work around this by doing their
own modal sheets using methods similar to yours.
In Jaguar, we fixed a number of problems where sheets could actually
break app-modality (eg. a sheet on an app-modal window would cause the
app to forget it was running app-modally). This has the side-effect of
making the distinction between sheets and modal windows more strict.
After the Jaguar WWDC preview, we discovered that apps like yours were
now broken since they were depending on being able to dismiss sheets
using stopModalWithCode:, and modal windows using endSheet: (your code
works in 10.1 because this used to be allowed). You can get the 10.1
behavior by setting the default NSModalCompatibilityWithMacOS10.1 to
YES.
Alternatively, you can make your app work on both 10.1 and 10.2 by
adding code to handle both semantics. When the "OK" button is pressed
on the modal sheet on 10.2, this causes a call to -[NSApp
endSheet:returnCode:]. If you passed a didEndSelector to -[NSApp
beginSheet:modalForWindow:modalDelegate:didEndSelector:contextInfo:],
you could call -[NSApp stopModalWithCode:] from that selector.
NSWindow
*alertPanel=NSGetAlertPanel(aTitle,message,@"OK",nil,nil);
// pass a selector so you get called back when the sheet is dismissed
[NSApp beginSheet: alertPanel modalForWindow: aWindow
modalDelegate:self
didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
contextInfo:NULL];
retCode=[NSApp runModalForWindow:alertPanel];
if ([aWindow attachedSheet])
[NSApp endSheet:alertPanel]; // this will get called on 10.1, but
not on 10.2
[alertPanel orderOut:self]; // call the orderOut after the endSheet:
NSReleaseAlertPanel(alertPanel);
- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode
contextInfo:(void *)ignore {
if (sheet == [NSApp modalWindow])
[NSApp stopModalWithCode:returnCode]; // this will get called on
10.2, but not on 10.1
}
Kristin
>
Date: Mon, 12 Aug 2002 12:43:43 -0700 (PDT)
>
From: Robert Vasvari <email@hidden>
>
Subject: modal alert sheets
>
>
Howdy,
>
I am trying to get an alert sheet that is like the
>
panel of NSGetAlertPanel, but attached to a window as
>
a sheet. NSGetAlertPanel has a convenient modal API,
>
and it would be convenient to use where it is
>
difficult to replace it with non modal alert sheets. I
>
did this in 10.1.x like this:
>
NSWindow
>
*alertPanel=NSGetAlertPanel(aTitle,message,@"OK",nil,nil);
>
[NSApp beginSheet:alertPanel
>
modalForWindow:aWindow modalDelegate:nil
>
didEndSelector:nil
>
contextInfo:nil];
>
retCode=[NSApp runModalForWindow:alertPanel];
>
[alertPanel orderOut:self];
>
[NSApp endSheet:alertPanel];
>
NSReleaseAlertPanel(alertPanel);
>
>
This no longer works correctly on the Jaguar previews.
>
I do get the sheet with the buttons, but each button
>
must be pressed twice in order for [NSApp
>
stopModalWithCode:] to be called. This might just be a
>
Jag bug, but is there an easier way to get this modal
>
alert sheet up?
>
R
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.