]> git.saurik.com Git - wxWidgets.git/blob - src/osx/cocoa/dialog.mm
Override CanFocus because the wxWindow level test will check if the NSTextView's...
[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::DoShowWindowModal()
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 [GetWXWindow() orderOut:GetWXWindow()];
47 }
48
49 void wxDialog::DoShowModal()
50 {
51 // If the app hasn't started, flush the event queue
52 // If we don't do this, the Dock doesn't get the message that
53 // the app has started so will refuse to activate it.
54 NSApplication *theNSApp = [NSApplication sharedApplication];
55 if (![theNSApp isRunning])
56 {
57 wxMacAutoreleasePool pool;
58 while(NSEvent *event = [theNSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil inMode:NSDefaultRunLoopMode dequeue:YES])
59 {
60 [theNSApp sendEvent:event];
61 }
62 }
63
64 SetFocus() ;
65 /*
66 WindowGroupRef windowGroup;
67 WindowGroupRef formerParentGroup;
68 bool resetGroupParent = false;
69
70 if ( GetParent() == NULL )
71 {
72 windowGroup = GetWindowGroup(windowRef) ;
73 formerParentGroup = GetWindowGroupParent( windowGroup );
74 SetWindowGroupParent( windowGroup, GetWindowGroupOfClass( kMovableModalWindowClass ) );
75 resetGroupParent = true;
76 }
77 */
78 NSWindow* theWindow = GetWXWindow();
79
80 NSModalSession session = [NSApp beginModalSessionForWindow:theWindow];
81 while (IsModal())
82 {
83 wxMacAutoreleasePool autoreleasepool;
84 // we cannot break based on the return value, because nested
85 // alerts might set this to stopped as well, so it would be
86 // unsafe
87 [NSApp runModalSession:session];
88
89 // break if ended, perform no further idle processing
90 if (!IsModal())
91 break;
92
93 // do some idle processing
94 bool needMore = false;
95 if (wxTheApp)
96 {
97 wxTheApp->ProcessPendingEvents();
98 needMore = wxTheApp->ProcessIdle();
99 }
100
101 if (!needMore)
102 {
103 // no more idle processing wanted - block until the next event
104 [theNSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantFuture] inMode:NSDefaultRunLoopMode dequeue:NO];
105 }
106 }
107 [NSApp endModalSession:session];
108
109 /*
110 if ( resetGroupParent )
111 {
112 SetWindowGroupParent( windowGroup , formerParentGroup );
113 }
114 */
115 }