]> git.saurik.com Git - wxWidgets.git/blame - src/osx/cocoa/dialog.mm
Adding wxUIActionSimulator, a class for programmatically controlling the mouse and...
[wxWidgets.git] / src / osx / cocoa / dialog.mm
CommitLineData
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
25extern wxList wxModalDialogs;
26
4d572a2c 27void wxDialog::DoShowWindowModal()
9482c644
KO
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();
f44af1dc 35
9482c644
KO
36 [NSApp beginSheet: theWindow
37 modalForWindow: parentWindow
38 modalDelegate: theWindow
39 didEndSelector: nil
40 contextInfo: nil];
41}
42
43void wxDialog::EndWindowModal()
44{
45 [NSApp endSheet: GetWXWindow()];
779a4d41 46 [GetWXWindow() orderOut:GetWXWindow()];
9482c644
KO
47}
48
fb8dcb05
SC
49void wxDialog::DoShowModal()
50{
b0a9bfc8
SC
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
fb8dcb05
SC
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*/
fb8dcb05 78 NSWindow* theWindow = GetWXWindow();
03647350 79
fb8dcb05 80 NSModalSession session = [NSApp beginModalSessionForWindow:theWindow];
03647350 81 while (IsModal())
fb8dcb05 82 {
dbeddfb9 83 wxMacAutoreleasePool autoreleasepool;
a43a9e55
SC
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];
336775c0 88
b0a9bfc8
SC
89 // break if ended, perform no further idle processing
90 if (!IsModal())
91 break;
92
03647350 93 // do some idle processing
b0a9bfc8 94 bool needMore = false;
03647350 95 if (wxTheApp)
b0a9bfc8
SC
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 }
fb8dcb05
SC
106 }
107 [NSApp endModalSession:session];
108
109/*
110 if ( resetGroupParent )
111 {
112 SetWindowGroupParent( windowGroup , formerParentGroup );
113 }
114*/
115}