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::DoShowWindowModal()
29 wxTopLevelWindow* parent = static_cast<wxTopLevelWindow*>(wxGetTopLevelParent(GetParent()));
31 wxASSERT_MSG(parent, "ShowWindowModal requires the dialog to have a parent.");
33 NSWindow* parentWindow = parent->GetWXWindow();
34 NSWindow* theWindow = GetWXWindow();
36 [NSApp beginSheet: theWindow
37 modalForWindow: parentWindow
38 modalDelegate: theWindow
43 void wxDialog::EndWindowModal()
45 [NSApp endSheet: GetWXWindow()];
46 [GetWXWindow() orderOut:GetWXWindow()];
49 void wxDialog::DoShowModal()
51 // If the app hasn't started, flush the event queue
52 // If we don't do this, the Dock doesn't get the message that
53 // the app has started so will refuse to activate it.
54 NSApplication *theNSApp = [NSApplication sharedApplication];
55 if (![theNSApp isRunning])
57 wxMacAutoreleasePool pool;
58 while(NSEvent *event = [theNSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil inMode:NSDefaultRunLoopMode dequeue:YES])
60 [theNSApp sendEvent:event];
66 WindowGroupRef windowGroup;
67 WindowGroupRef formerParentGroup;
68 bool resetGroupParent = false;
70 if ( GetParent() == NULL )
72 windowGroup = GetWindowGroup(windowRef) ;
73 formerParentGroup = GetWindowGroupParent( windowGroup );
74 SetWindowGroupParent( windowGroup, GetWindowGroupOfClass( kMovableModalWindowClass ) );
75 resetGroupParent = true;
78 NSWindow* theWindow = GetWXWindow();
80 NSModalSession session = [NSApp beginModalSessionForWindow:theWindow];
83 wxMacAutoreleasePool autoreleasepool;
84 // we cannot break based on the return value, because nested
85 // alerts might set this to stopped as well, so it would be
87 [NSApp runModalSession:session];
89 // break if ended, perform no further idle processing
93 // do some idle processing
94 bool needMore = false;
97 wxTheApp->ProcessPendingEvents();
98 needMore = wxTheApp->ProcessIdle();
103 // no more idle processing wanted - block until the next event
104 [theNSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantFuture] inMode:NSDefaultRunLoopMode dequeue:NO];
107 [NSApp endModalSession:session];
110 if ( resetGroupParent )
112 SetWindowGroupParent( windowGroup , formerParentGroup );