]>
Commit | Line | Data |
---|---|---|
fb8dcb05 SC |
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 | ||
9482c644 KO |
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(); | |
9482c644 | 35 | |
f44af1dc SC |
36 | wxWindow::Show(true); |
37 | ||
9482c644 KO |
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 | ||
fb8dcb05 SC |
50 | void wxDialog::DoShowModal() |
51 | { | |
dbeddfb9 SC |
52 | wxCHECK_RET( !IsModal(), wxT("DoShowModal() called twice") ); |
53 | ||
b0a9bfc8 SC |
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 | ||
dbeddfb9 | 67 | wxModalDialogs.Append(this); |
fb8dcb05 SC |
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 | */ | |
fb8dcb05 | 83 | NSWindow* theWindow = GetWXWindow(); |
03647350 | 84 | |
fb8dcb05 | 85 | NSModalSession session = [NSApp beginModalSessionForWindow:theWindow]; |
03647350 | 86 | while (IsModal()) |
fb8dcb05 | 87 | { |
dbeddfb9 | 88 | wxMacAutoreleasePool autoreleasepool; |
a43a9e55 SC |
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]; | |
336775c0 | 93 | |
b0a9bfc8 SC |
94 | // break if ended, perform no further idle processing |
95 | if (!IsModal()) | |
96 | break; | |
97 | ||
03647350 | 98 | // do some idle processing |
b0a9bfc8 | 99 | bool needMore = false; |
03647350 | 100 | if (wxTheApp) |
b0a9bfc8 SC |
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 | } | |
fb8dcb05 SC |
111 | } |
112 | [NSApp endModalSession:session]; | |
113 | ||
114 | /* | |
115 | if ( resetGroupParent ) | |
116 | { | |
117 | SetWindowGroupParent( windowGroup , formerParentGroup ); | |
118 | } | |
119 | */ | |
120 | } |