]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/dialog.cpp
cleanup
[wxWidgets.git] / src / mac / carbon / dialog.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/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/mac/uma.h"
24
25
26 // Lists to keep track of windows, so we can disable/enable them
27 // for modal dialogs
28 wxList wxModalDialogs;
29
30 IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxTopLevelWindow)
31
32 void wxDialog::Init()
33 {
34 m_isModalStyle = false;
35 }
36
37 bool wxDialog::Create( wxWindow *parent,
38 wxWindowID id,
39 const wxString& title,
40 const wxPoint& pos,
41 const wxSize& size,
42 long style,
43 const wxString& name )
44 {
45 SetExtraStyle( GetExtraStyle() | wxTOPLEVEL_EX_DIALOG );
46
47 // All dialogs should really have this style...
48 style |= wxTAB_TRAVERSAL;
49
50 // ...but not these styles
51 style &= ~(wxYES | wxOK | wxNO); // | wxCANCEL
52
53 if ( !wxTopLevelWindow::Create( parent, id, title, pos, size, style, name ) )
54 return false;
55
56 return true;
57 }
58
59 void wxDialog::SetModal( bool flag )
60 {
61 if ( flag )
62 {
63 m_isModalStyle = true;
64
65 wxModelessWindows.DeleteObject( this );
66
67 #if TARGET_CARBON
68 SetWindowModality( (WindowRef)MacGetWindowRef(), kWindowModalityAppModal, NULL ) ;
69 #endif
70 }
71 else
72 {
73 m_isModalStyle = false;
74
75 wxModelessWindows.Append( this );
76 }
77 }
78
79 wxDialog::~wxDialog()
80 {
81 m_isBeingDeleted = true;
82 Show(false);
83 }
84
85 // On mac command-stop does the same thing as Esc, let the base class know
86 // about it
87 bool wxDialog::IsEscapeKey(const wxKeyEvent& event)
88 {
89 if ( event.GetKeyCode() == '.' && event.GetModifiers() == wxMOD_CMD )
90 return true;
91
92 return wxDialogBase::IsEscapeKey(event);
93 }
94
95 bool wxDialog::IsModal() const
96 {
97 return wxModalDialogs.Find((wxDialog *)this) != NULL; // const_cast
98 // return m_isModalStyle;
99 }
100
101
102 bool wxDialog::Show(bool show)
103 {
104 if ( !wxDialogBase::Show(show) )
105 // nothing to do
106 return false;
107
108 if ( show )
109 // usually will result in TransferDataToWindow() being called
110 InitDialog();
111
112 HiliteMenu(0);
113
114 if ( m_isModalStyle )
115 {
116 if ( show )
117 {
118 DoShowModal();
119 }
120 else // end of modal dialog
121 {
122 // this will cause IsModalShowing() return false and our local
123 // message loop will terminate
124 wxModalDialogs.DeleteObject(this);
125 }
126 }
127
128 return true;
129 }
130
131 #if !TARGET_CARBON
132 extern bool s_macIsInModalLoop ;
133 #endif
134
135 void wxDialog::DoShowModal()
136 {
137 wxCHECK_RET( !IsModal(), wxT("DoShowModal() called twice") );
138
139 wxModalDialogs.Append(this);
140
141 SetFocus() ;
142
143 WindowRef windowRef = (WindowRef) MacGetWindowRef();
144 WindowGroupRef windowGroup;
145 WindowGroupRef formerParentGroup;
146 bool resetGroupParent = false;
147
148 if ( GetParent() == NULL )
149 {
150 windowGroup = GetWindowGroup(windowRef) ;
151 formerParentGroup = GetWindowGroupParent( windowGroup );
152 SetWindowGroupParent( windowGroup, GetWindowGroupOfClass( kMovableModalWindowClass ) );
153 resetGroupParent = true;
154 }
155 BeginAppModalStateForWindow(windowRef) ;
156
157 while ( IsModal() )
158 {
159 wxTheApp->MacDoOneEvent() ;
160 // calls process idle itself
161 }
162
163 EndAppModalStateForWindow(windowRef) ;
164 if ( resetGroupParent )
165 {
166 SetWindowGroupParent( windowGroup , formerParentGroup );
167 }
168 }
169
170
171 // Replacement for Show(true) for modal dialogs - returns return code
172 int wxDialog::ShowModal()
173 {
174 if ( !m_isModalStyle )
175 SetModal(true);
176
177 Show(true);
178
179 return GetReturnCode();
180 }
181
182 // NB: this function (surprizingly) may be called for both modal and modeless
183 // dialogs and should work for both of them
184 void wxDialog::EndModal(int retCode)
185 {
186 SetReturnCode(retCode);
187 Show(false);
188 SetModal(false);
189 }
190