When a modal dialog is shown and the app isn't running, run the event
authorDavid Elliott <dfe@tgwbd.org>
Fri, 5 Sep 2003 02:48:49 +0000 (02:48 +0000)
committerDavid Elliott <dfe@tgwbd.org>
Fri, 5 Sep 2003 02:48:49 +0000 (02:48 +0000)
loop manually until it is out of events.  This will allow the application
to let the Dock know it has completed startup.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@23393 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/cocoa/dialog.mm

index a73f22e24453ee66f59af3bea5712f2ddde7bcaa..0b4e1a8406468311e2a10a6be63d48f940e527bc 100644 (file)
@@ -21,6 +21,8 @@
 
 #import <AppKit/NSPanel.h>
 #import <AppKit/NSApplication.h>
+#import <AppKit/NSEvent.h>
+#import <Foundation/NSRunLoop.h>
 
 // Lists to keep track of windows, so we can disable/enable them
 // for modal dialogs
@@ -120,6 +122,21 @@ bool wxDialog::Show(bool show)
             wxAutoNSAutoreleasePool pool;
             wxModalDialogs.Append(this);
             wxLogDebug("runModal");
+            NSApplication *theNSApp = wxTheApp->GetNSApplication();
+            // 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.
+            if(![theNSApp isRunning])
+            {
+                while(NSEvent *event = [theNSApp
+                            nextEventMatchingMask:NSAnyEventMask
+                            untilDate:[NSDate distantPast]
+                            inMode:NSDefaultRunLoopMode
+                            dequeue: YES])
+                {
+                    [theNSApp sendEvent: event];
+                }
+            }
             [wxTheApp->GetNSApplication() runModalForWindow:m_cocoaNSWindow];
             wxLogDebug("runModal END");
         }