]>
Commit | Line | Data |
---|---|---|
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 | #if TARGET_API_MAC_OSX | |
57 | HIViewRef growBoxRef = 0 ; | |
58 | OSStatus err = HIViewFindByID( HIViewGetRoot( (WindowRef)m_macWindow ), kHIViewWindowGrowBoxID, &growBoxRef ); | |
59 | if ( err == noErr && growBoxRef != 0 ) | |
60 | HIGrowBoxViewSetTransparent( growBoxRef, true ) ; | |
61 | #endif | |
62 | ||
63 | return true; | |
64 | } | |
65 | ||
66 | void wxDialog::SetModal( bool flag ) | |
67 | { | |
68 | if ( flag ) | |
69 | { | |
70 | m_isModalStyle = true; | |
71 | ||
72 | wxModelessWindows.DeleteObject( this ); | |
73 | ||
74 | #if TARGET_CARBON | |
75 | SetWindowModality( (WindowRef)MacGetWindowRef(), kWindowModalityAppModal, NULL ) ; | |
76 | #endif | |
77 | } | |
78 | else | |
79 | { | |
80 | m_isModalStyle = false; | |
81 | ||
82 | wxModelessWindows.Append( this ); | |
83 | } | |
84 | } | |
85 | ||
86 | wxDialog::~wxDialog() | |
87 | { | |
88 | m_isBeingDeleted = true; | |
89 | Show(false); | |
90 | } | |
91 | ||
92 | // On mac command-stop does the same thing as Esc, let the base class know | |
93 | // about it | |
94 | bool wxDialog::IsEscapeKey(const wxKeyEvent& event) | |
95 | { | |
96 | if ( event.GetKeyCode() == '.' && event.GetModifiers() == wxMOD_CMD ) | |
97 | return true; | |
98 | ||
99 | return wxDialogBase::IsEscapeKey(event); | |
100 | } | |
101 | ||
102 | bool wxDialog::IsModal() const | |
103 | { | |
104 | return wxModalDialogs.Find((wxDialog *)this) != NULL; // const_cast | |
105 | // return m_isModalStyle; | |
106 | } | |
107 | ||
108 | ||
109 | bool wxDialog::IsModalShowing() const | |
110 | { | |
111 | return wxModalDialogs.Find((wxDialog *)this) != NULL; // const_cast | |
112 | } | |
113 | ||
114 | bool wxDialog::Show(bool show) | |
115 | { | |
116 | if ( !wxDialogBase::Show(show) ) | |
117 | // nothing to do | |
118 | return false; | |
119 | ||
120 | if ( show ) | |
121 | // usually will result in TransferDataToWindow() being called | |
122 | InitDialog(); | |
123 | ||
124 | if ( m_isModalStyle ) | |
125 | { | |
126 | if ( show ) | |
127 | { | |
128 | DoShowModal(); | |
129 | } | |
130 | else // end of modal dialog | |
131 | { | |
132 | // this will cause IsModalShowing() return false and our local | |
133 | // message loop will terminate | |
134 | wxModalDialogs.DeleteObject(this); | |
135 | } | |
136 | } | |
137 | ||
138 | return true; | |
139 | } | |
140 | ||
141 | #if !TARGET_CARBON | |
142 | extern bool s_macIsInModalLoop ; | |
143 | #endif | |
144 | ||
145 | void wxDialog::DoShowModal() | |
146 | { | |
147 | wxCHECK_RET( !IsModalShowing(), wxT("DoShowModal() called twice") ); | |
148 | ||
149 | wxModalDialogs.Append(this); | |
150 | ||
151 | SetFocus() ; | |
152 | ||
153 | #if TARGET_CARBON | |
154 | BeginAppModalStateForWindow( (WindowRef) MacGetWindowRef()) ; | |
155 | #else | |
156 | // TODO : test whether parent gets disabled | |
157 | bool formerModal = s_macIsInModalLoop ; | |
158 | s_macIsInModalLoop = true ; | |
159 | #endif | |
160 | ||
161 | while ( IsModalShowing() ) | |
162 | { | |
163 | wxTheApp->MacDoOneEvent() ; | |
164 | // calls process idle itself | |
165 | } | |
166 | ||
167 | #if TARGET_CARBON | |
168 | EndAppModalStateForWindow( (WindowRef) MacGetWindowRef() ) ; | |
169 | #else | |
170 | // TODO probably reenable the parent window if any | |
171 | s_macIsInModalLoop = formerModal ; | |
172 | #endif | |
173 | } | |
174 | ||
175 | ||
176 | // Replacement for Show(true) for modal dialogs - returns return code | |
177 | int wxDialog::ShowModal() | |
178 | { | |
179 | if ( !m_isModalStyle ) | |
180 | SetModal(true); | |
181 | ||
182 | Show(true); | |
183 | ||
184 | return GetReturnCode(); | |
185 | } | |
186 | ||
187 | // NB: this function (surprizingly) may be called for both modal and modeless | |
188 | // dialogs and should work for both of them | |
189 | void wxDialog::EndModal(int retCode) | |
190 | { | |
191 | SetReturnCode(retCode); | |
192 | Show(false); | |
193 | SetModal(false); | |
194 | } | |
195 |