X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/dbeddfb93d3479d03d8ec4c0121dfbe3bbcc422b..a02a5cfcf33bb2c0edae246c1b19e286bf86d422:/src/osx/cocoa/dialog.mm diff --git a/src/osx/cocoa/dialog.mm b/src/osx/cocoa/dialog.mm index e5a9d3f658..d55449d1b5 100644 --- a/src/osx/cocoa/dialog.mm +++ b/src/osx/cocoa/dialog.mm @@ -24,11 +24,42 @@ extern wxList wxModalDialogs; -void wxDialog::DoShowModal() +void wxDialog::DoShowWindowModal() +{ + wxTopLevelWindow* parent = static_cast(wxGetTopLevelParent(GetParent())); + + wxASSERT_MSG(parent, "ShowWindowModal requires the dialog to have a parent."); + + NSWindow* parentWindow = parent->GetWXWindow(); + NSWindow* theWindow = GetWXWindow(); + + [NSApp beginSheet: theWindow + modalForWindow: parentWindow + modalDelegate: theWindow + didEndSelector: nil + contextInfo: nil]; +} + +void wxDialog::EndWindowModal() { - wxCHECK_RET( !IsModal(), wxT("DoShowModal() called twice") ); + [NSApp endSheet: GetWXWindow()]; + [GetWXWindow() orderOut:GetWXWindow()]; +} - wxModalDialogs.Append(this); +void wxDialog::DoShowModal() +{ + // If the app hasn't started, flush the event queue + // If we don't do this, the Dock doesn't get the message that + // the app has started so will refuse to activate it. + NSApplication *theNSApp = [NSApplication sharedApplication]; + if (![theNSApp isRunning]) + { + wxMacAutoreleasePool pool; + while(NSEvent *event = [theNSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil inMode:NSDefaultRunLoopMode dequeue:YES]) + { + [theNSApp sendEvent:event]; + } + } SetFocus() ; /* @@ -45,14 +76,33 @@ void wxDialog::DoShowModal() } */ NSWindow* theWindow = GetWXWindow(); - + NSModalSession session = [NSApp beginModalSessionForWindow:theWindow]; - while (IsModal()) + while (IsModal()) { wxMacAutoreleasePool autoreleasepool; - if ([NSApp runModalSession:session] != NSRunContinuesResponse) + // we cannot break based on the return value, because nested + // alerts might set this to stopped as well, so it would be + // unsafe + [NSApp runModalSession:session]; + + // break if ended, perform no further idle processing + if (!IsModal()) break; - // TODO should we do some idle processing ? + + // do some idle processing + bool needMore = false; + if (wxTheApp) + { + wxTheApp->ProcessPendingEvents(); + needMore = wxTheApp->ProcessIdle(); + } + + if (!needMore) + { + // no more idle processing wanted - block until the next event + [theNSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantFuture] inMode:NSDefaultRunLoopMode dequeue:NO]; + } } [NSApp endModalSession:session];