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()];
48 void wxDialog::DoShowModal()
50 // If the app hasn't started, flush the event queue
51 // If we don't do this, the Dock doesn't get the message that
52 // the app has started so will refuse to activate it.
53 NSApplication *theNSApp = [NSApplication sharedApplication];
54 if (![theNSApp isRunning])
56 wxMacAutoreleasePool pool;
57 while(NSEvent *event = [theNSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil inMode:NSDefaultRunLoopMode dequeue:YES])
59 [theNSApp sendEvent:event];
65 WindowGroupRef windowGroup;
66 WindowGroupRef formerParentGroup;
67 bool resetGroupParent = false;
69 if ( GetParent() == NULL )
71 windowGroup = GetWindowGroup(windowRef) ;
72 formerParentGroup = GetWindowGroupParent( windowGroup );
73 SetWindowGroupParent( windowGroup, GetWindowGroupOfClass( kMovableModalWindowClass ) );
74 resetGroupParent = true;
77 NSWindow* theWindow = GetWXWindow();
79 NSModalSession session = [NSApp beginModalSessionForWindow:theWindow];
82 wxMacAutoreleasePool autoreleasepool;
83 // we cannot break based on the return value, because nested
84 // alerts might set this to stopped as well, so it would be
86 [NSApp runModalSession:session];
88 // break if ended, perform no further idle processing
92 // do some idle processing
93 bool needMore = false;
96 wxTheApp->ProcessPendingEvents();
97 needMore = wxTheApp->ProcessIdle();
102 // no more idle processing wanted - block until the next event
103 [theNSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantFuture] inMode:NSDefaultRunLoopMode dequeue:NO];
106 [NSApp endModalSession:session];
109 if ( resetGroupParent )
111 SetWindowGroupParent( windowGroup , formerParentGroup );