]> git.saurik.com Git - wxWidgets.git/blob - src/osx/cocoa/dialog.mm
Start on ShowWindowModal for OS X Cocoa. Not working properly as children do not...
[wxWidgets.git] / src / osx / cocoa / dialog.mm
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/cocoa/dialog.cpp
3 // Purpose: wxDialog class
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id: dialog.cpp 54820 2008-07-29 20:04:11Z SC $
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #include "wx/dialog.h"
15
16 #ifndef WX_PRECOMP
17 #include "wx/app.h"
18 #include "wx/utils.h"
19 #include "wx/frame.h"
20 #include "wx/settings.h"
21 #endif // WX_PRECOMP
22
23 #include "wx/osx/private.h"
24
25 extern wxList wxModalDialogs;
26
27 void wxDialog::ShowWindowModal()
28 {
29 wxTopLevelWindow* parent = static_cast<wxTopLevelWindow*>(wxGetTopLevelParent(GetParent()));
30
31 wxASSERT_MSG(parent, "ShowWindowModal requires the dialog to have a parent.");
32
33 NSWindow* parentWindow = parent->GetWXWindow();
34 NSWindow* theWindow = GetWXWindow();
35
36 wxASSERT_MSG([theWindow styleMask] & NSDocModalWindowMask, "Window must have DocModal mask set.");
37
38 [NSApp beginSheet: theWindow
39 modalForWindow: parentWindow
40 modalDelegate: theWindow
41 didEndSelector: nil
42 contextInfo: nil];
43 }
44
45 void wxDialog::EndWindowModal()
46 {
47 [NSApp endSheet: GetWXWindow()];
48 }
49
50 void wxDialog::DoShowModal()
51 {
52 wxCHECK_RET( !IsModal(), wxT("DoShowModal() called twice") );
53
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])
59 {
60 wxMacAutoreleasePool pool;
61 while(NSEvent *event = [theNSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil inMode:NSDefaultRunLoopMode dequeue:YES])
62 {
63 [theNSApp sendEvent:event];
64 }
65 }
66
67 wxModalDialogs.Append(this);
68
69 SetFocus() ;
70 /*
71 WindowGroupRef windowGroup;
72 WindowGroupRef formerParentGroup;
73 bool resetGroupParent = false;
74
75 if ( GetParent() == NULL )
76 {
77 windowGroup = GetWindowGroup(windowRef) ;
78 formerParentGroup = GetWindowGroupParent( windowGroup );
79 SetWindowGroupParent( windowGroup, GetWindowGroupOfClass( kMovableModalWindowClass ) );
80 resetGroupParent = true;
81 }
82 */
83 NSWindow* theWindow = GetWXWindow();
84
85 NSModalSession session = [NSApp beginModalSessionForWindow:theWindow];
86 while (IsModal())
87 {
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
91 // unsafe
92 [NSApp runModalSession:session];
93
94 // break if ended, perform no further idle processing
95 if (!IsModal())
96 break;
97
98 // do some idle processing
99 bool needMore = false;
100 if (wxTheApp)
101 {
102 wxTheApp->ProcessPendingEvents();
103 needMore = wxTheApp->ProcessIdle();
104 }
105
106 if (!needMore)
107 {
108 // no more idle processing wanted - block until the next event
109 [theNSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantFuture] inMode:NSDefaultRunLoopMode dequeue:NO];
110 }
111 }
112 [NSApp endModalSession:session];
113
114 /*
115 if ( resetGroupParent )
116 {
117 SetWindowGroupParent( windowGroup , formerParentGroup );
118 }
119 */
120 }