1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/cocoa/dialog.cpp
3 // Purpose: wxDialog class
4 // Author: Stefan Csomor
7 // RCS-ID: $Id: dialog.cpp 54820 2008-07-29 20:04:11Z SC $
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 #include "wx/dialog.h"
20 #include "wx/settings.h"
23 #include "wx/osx/private.h"
25 extern wxList wxModalDialogs;
27 void wxDialog::DoShowModal()
29 wxCHECK_RET( !IsModal(), wxT("DoShowModal() called twice") );
31 // If the app hasn't started, flush the event queue
32 // If we don't do this, the Dock doesn't get the message that
33 // the app has started so will refuse to activate it.
34 NSApplication *theNSApp = [NSApplication sharedApplication];
35 if (![theNSApp isRunning])
37 wxMacAutoreleasePool pool;
38 while(NSEvent *event = [theNSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil inMode:NSDefaultRunLoopMode dequeue:YES])
40 [theNSApp sendEvent:event];
44 wxModalDialogs.Append(this);
48 WindowGroupRef windowGroup;
49 WindowGroupRef formerParentGroup;
50 bool resetGroupParent = false;
52 if ( GetParent() == NULL )
54 windowGroup = GetWindowGroup(windowRef) ;
55 formerParentGroup = GetWindowGroupParent( windowGroup );
56 SetWindowGroupParent( windowGroup, GetWindowGroupOfClass( kMovableModalWindowClass ) );
57 resetGroupParent = true;
60 NSWindow* theWindow = GetWXWindow();
62 NSModalSession session = [NSApp beginModalSessionForWindow:theWindow];
65 wxMacAutoreleasePool autoreleasepool;
66 // we cannot break based on the return value, because nested
67 // alerts might set this to stopped as well, so it would be
69 [NSApp runModalSession:session];
71 // break if ended, perform no further idle processing
75 // do some idle processing
76 bool needMore = false;
79 wxTheApp->ProcessPendingEvents();
80 needMore = wxTheApp->ProcessIdle();
85 // no more idle processing wanted - block until the next event
86 [theNSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantFuture] inMode:NSDefaultRunLoopMode dequeue:NO];
89 [NSApp endModalSession:session];
92 if ( resetGroupParent )
94 SetWindowGroupParent( windowGroup , formerParentGroup );