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::ShowWindowModal()
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 wxCHECK_RET( !IsModal(), wxT("DoShowModal() called twice") );
52 // If the app hasn't started, flush the event queue
53 // If we don't do this, the Dock doesn't get the message that
54 // the app has started so will refuse to activate it.
55 NSApplication *theNSApp = [NSApplication sharedApplication];
56 if (![theNSApp isRunning])
58 wxMacAutoreleasePool pool;
59 while(NSEvent *event = [theNSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil inMode:NSDefaultRunLoopMode dequeue:YES])
61 [theNSApp sendEvent:event];
65 wxModalDialogs.Append(this);
69 WindowGroupRef windowGroup;
70 WindowGroupRef formerParentGroup;
71 bool resetGroupParent = false;
73 if ( GetParent() == NULL )
75 windowGroup = GetWindowGroup(windowRef) ;
76 formerParentGroup = GetWindowGroupParent( windowGroup );
77 SetWindowGroupParent( windowGroup, GetWindowGroupOfClass( kMovableModalWindowClass ) );
78 resetGroupParent = true;
81 NSWindow* theWindow = GetWXWindow();
83 NSModalSession session = [NSApp beginModalSessionForWindow:theWindow];
86 wxMacAutoreleasePool autoreleasepool;
87 // we cannot break based on the return value, because nested
88 // alerts might set this to stopped as well, so it would be
90 [NSApp runModalSession:session];
92 // break if ended, perform no further idle processing
96 // do some idle processing
97 bool needMore = false;
100 wxTheApp->ProcessPendingEvents();
101 needMore = wxTheApp->ProcessIdle();
106 // no more idle processing wanted - block until the next event
107 [theNSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantFuture] inMode:NSDefaultRunLoopMode dequeue:NO];
110 [NSApp endModalSession:session];
113 if ( resetGroupParent )
115 SetWindowGroupParent( windowGroup , formerParentGroup );