]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/osx/cocoa/dialog.mm
Create an autorelease pool to catch objects created during several special situations...
[wxWidgets.git] / src / osx / cocoa / dialog.mm
... / ...
CommitLineData
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
27void wxDialog::DoShowModal()
28{
29 wxCHECK_RET( !IsModal(), wxT("DoShowModal() called twice") );
30
31 // If the app hasn't started, flush the event queue
32 // If we don't do this, the Dock doesn't get the message that
33 // the app has started so will refuse to activate it.
34 NSApplication *theNSApp = [NSApplication sharedApplication];
35 if (![theNSApp isRunning])
36 {
37 wxMacAutoreleasePool pool;
38 while(NSEvent *event = [theNSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil inMode:NSDefaultRunLoopMode dequeue:YES])
39 {
40 [theNSApp sendEvent:event];
41 }
42 }
43
44 wxModalDialogs.Append(this);
45
46 SetFocus() ;
47/*
48 WindowGroupRef windowGroup;
49 WindowGroupRef formerParentGroup;
50 bool resetGroupParent = false;
51
52 if ( GetParent() == NULL )
53 {
54 windowGroup = GetWindowGroup(windowRef) ;
55 formerParentGroup = GetWindowGroupParent( windowGroup );
56 SetWindowGroupParent( windowGroup, GetWindowGroupOfClass( kMovableModalWindowClass ) );
57 resetGroupParent = true;
58 }
59*/
60 NSWindow* theWindow = GetWXWindow();
61
62 NSModalSession session = [NSApp beginModalSessionForWindow:theWindow];
63 while (IsModal())
64 {
65 wxMacAutoreleasePool autoreleasepool;
66 // we cannot break based on the return value, because nested
67 // alerts might set this to stopped as well, so it would be
68 // unsafe
69 [NSApp runModalSession:session];
70
71 // break if ended, perform no further idle processing
72 if (!IsModal())
73 break;
74
75 // do some idle processing
76 bool needMore = false;
77 if (wxTheApp)
78 {
79 wxTheApp->ProcessPendingEvents();
80 needMore = wxTheApp->ProcessIdle();
81 }
82
83 if (!needMore)
84 {
85 // no more idle processing wanted - block until the next event
86 [theNSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantFuture] inMode:NSDefaultRunLoopMode dequeue:NO];
87 }
88 }
89 [NSApp endModalSession:session];
90
91/*
92 if ( resetGroupParent )
93 {
94 SetWindowGroupParent( windowGroup , formerParentGroup );
95 }
96*/
97}