Re: Modal window
Re: Modal window
- Subject: Re: Modal window
- From: Jean-Daniel Dupas <email@hidden>
- Date: Mon, 25 Aug 2008 13:07:06 +0200
Le 25 août 08 à 12:04, Marcus a écrit :
25 aug 2008 kl. 11.03 skrev Macarov Anatoli:
When modal window is started up the application stops carrying out
other processes. How to work out this issue?
Cod:
- (void)showCustomDialog: (NSWindow *)window widi:(NSPanel
*)windowDialog
{
if (!windowDialog)
[NSBundle loadNibNamed: @"MyCustomDialog" owner: self];
[NSApp beginSheet: windowDialog
modalForWindow: window
modalDelegate: nil
didEndSelector: nil
contextInfo: nil];
[NSApp runModalForWindow: windowDialog];
// Dialog is up here.
[NSApp endSheet: windowDialog];
[windowDialog orderOut: self];
}
The problem is that runModalForWindow: blocks background processing.
I'm not an expert on modal windows but according to the
documentation you should be able to use runModalSession: instead. I
think that you could also try to split showCustomDialog:widi: into
two methods and set didEndSelector to the second method.
Marcus
If you handle the modal session yourself, it's easy to let the
background processes do some processing while the modal window is open:
Replace -[NSApp runModalForWindow:[self window]] by this and it
should do the trick.
/* Create a modal session, and in each loop,
we process the default runloop event sources (url download,
network connections, etc.) */
NSModalSession session = [NSApp beginModalSessionForWindow:[self
window]]; // 1
for (;;) {
if ((result = [NSApp runModalSession:session]) !=
NSRunContinuesResponse) // 2
break; // 3
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode
beforeDate:[NSDate distantFuture]]; // 4
}
[NSApp endModalSession:session];
This snippet creates a modal session. (//1)
Then it checks the modal session state and processes UI events if some
events are ready ([NSApp runModalSession:session]) (//2)
Note that runModalSession: does not block and always returns immediatly.
Break if the user stops the modal session (//3)
After that it blocks until something append (network event, ui event,
etc). (//4)
Each time a network event occurs, the run loop pass it to the handler.
Each time a UI event occurs, the run loop push it on the UI event
queue and the next call the runModalSession: process it.
Each time an event occurs, runMode:beforeDate: returns.
_______________________________________________
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