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 wxASSERT_MSG([theWindow styleMask] & NSDocModalWindowMask, "Window must have DocModal mask set.");
38 [NSApp beginSheet: theWindow
39 modalForWindow: parentWindow
40 modalDelegate: theWindow
45 void wxDialog::EndWindowModal()
47 [NSApp endSheet: GetWXWindow()];
50 void wxDialog::DoShowModal()
52 wxCHECK_RET( !IsModal(), wxT("DoShowModal() called twice") );
54 // If the app hasn't started, flush the event queue
55 // If we don't do this, the Dock doesn't get the message that
56 // the app has started so will refuse to activate it.
57 NSApplication *theNSApp = [NSApplication sharedApplication];
58 if (![theNSApp isRunning])
60 wxMacAutoreleasePool pool;
61 while(NSEvent *event = [theNSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil inMode:NSDefaultRunLoopMode dequeue:YES])
63 [theNSApp sendEvent:event];
67 wxModalDialogs.Append(this);
71 WindowGroupRef windowGroup;
72 WindowGroupRef formerParentGroup;
73 bool resetGroupParent = false;
75 if ( GetParent() == NULL )
77 windowGroup = GetWindowGroup(windowRef) ;
78 formerParentGroup = GetWindowGroupParent( windowGroup );
79 SetWindowGroupParent( windowGroup, GetWindowGroupOfClass( kMovableModalWindowClass ) );
80 resetGroupParent = true;
83 NSWindow* theWindow = GetWXWindow();
85 NSModalSession session = [NSApp beginModalSessionForWindow:theWindow];
88 wxMacAutoreleasePool autoreleasepool;
89 // we cannot break based on the return value, because nested
90 // alerts might set this to stopped as well, so it would be
92 [NSApp runModalSession:session];
94 // break if ended, perform no further idle processing
98 // do some idle processing
99 bool needMore = false;
102 wxTheApp->ProcessPendingEvents();
103 needMore = wxTheApp->ProcessIdle();
108 // no more idle processing wanted - block until the next event
109 [theNSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantFuture] inMode:NSDefaultRunLoopMode dequeue:NO];
112 [NSApp endModalSession:session];
115 if ( resetGroupParent )
117 SetWindowGroupParent( windowGroup , formerParentGroup );