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