]> git.saurik.com Git - wxWidgets.git/blob - src/osx/cocoa/dialog.mm
Move wx/evtloop.h from GUI_CMN_HDR to BASE_CMN_HDR in files.bkl.
[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 [NSApp beginSheet: theWindow
37 modalForWindow: parentWindow
38 modalDelegate: theWindow
39 didEndSelector: nil
40 contextInfo: nil];
41 }
42
43 void wxDialog::EndWindowModal()
44 {
45 [NSApp endSheet: GetWXWindow()];
46 }
47
48 void wxDialog::DoShowModal()
49 {
50 wxCHECK_RET( !IsModal(), wxT("DoShowModal() called twice") );
51
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])
57 {
58 wxMacAutoreleasePool pool;
59 while(NSEvent *event = [theNSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil inMode:NSDefaultRunLoopMode dequeue:YES])
60 {
61 [theNSApp sendEvent:event];
62 }
63 }
64
65 wxModalDialogs.Append(this);
66
67 SetFocus() ;
68 /*
69 WindowGroupRef windowGroup;
70 WindowGroupRef formerParentGroup;
71 bool resetGroupParent = false;
72
73 if ( GetParent() == NULL )
74 {
75 windowGroup = GetWindowGroup(windowRef) ;
76 formerParentGroup = GetWindowGroupParent( windowGroup );
77 SetWindowGroupParent( windowGroup, GetWindowGroupOfClass( kMovableModalWindowClass ) );
78 resetGroupParent = true;
79 }
80 */
81 NSWindow* theWindow = GetWXWindow();
82
83 NSModalSession session = [NSApp beginModalSessionForWindow:theWindow];
84 while (IsModal())
85 {
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
89 // unsafe
90 [NSApp runModalSession:session];
91
92 // break if ended, perform no further idle processing
93 if (!IsModal())
94 break;
95
96 // do some idle processing
97 bool needMore = false;
98 if (wxTheApp)
99 {
100 wxTheApp->ProcessPendingEvents();
101 needMore = wxTheApp->ProcessIdle();
102 }
103
104 if (!needMore)
105 {
106 // no more idle processing wanted - block until the next event
107 [theNSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantFuture] inMode:NSDefaultRunLoopMode dequeue:NO];
108 }
109 }
110 [NSApp endModalSession:session];
111
112 /*
113 if ( resetGroupParent )
114 {
115 SetWindowGroupParent( windowGroup , formerParentGroup );
116 }
117 */
118 }