]> git.saurik.com Git - wxWidgets.git/blob - src/osx/carbon/dialog.cpp
ensure that we have event loop before showing a modal dialog; this allows to do it...
[wxWidgets.git] / src / osx / carbon / dialog.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/dialog.cpp
3 // Purpose: wxDialog class
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
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 #include "wx/evtloop.h"
25
26 extern wxList wxModalDialogs;
27
28 void wxDialog::DoShowModal()
29 {
30 wxCHECK_RET( !IsModal(), wxT("DoShowModal() called twice") );
31
32 wxModalDialogs.Append(this);
33
34 SetFocus() ;
35
36 WindowRef windowRef = (WindowRef) GetWXWindow();
37 WindowGroupRef windowGroup = NULL;
38 WindowGroupRef formerParentGroup = NULL;
39 bool resetGroupParent = false;
40
41 if ( GetParent() == NULL )
42 {
43 windowGroup = GetWindowGroup(windowRef) ;
44 formerParentGroup = GetWindowGroupParent( windowGroup );
45 SetWindowGroupParent( windowGroup, GetWindowGroupOfClass( kMovableModalWindowClass ) );
46 resetGroupParent = true;
47 }
48 BeginAppModalStateForWindow(windowRef) ;
49
50 wxEventLoopGuarantor ensureHasLoop;
51 wxEventLoopBase * const loop = wxEventLoop::GetActive();
52 while ( IsModal() )
53 loop->Dispatch();
54
55 EndAppModalStateForWindow(windowRef) ;
56 if ( resetGroupParent )
57 {
58 SetWindowGroupParent( windowGroup , formerParentGroup );
59 }
60 }