]>
Commit | Line | Data |
---|---|---|
0e320a79 | 1 | ///////////////////////////////////////////////////////////////////////////// |
743e24aa | 2 | // Name: src/os2/dialog.cpp |
0e320a79 | 3 | // Purpose: wxDialog class |
fb46a9a6 | 4 | // Author: David Webster |
0e320a79 | 5 | // Modified by: |
fb46a9a6 | 6 | // Created: 10/14/99 |
0e320a79 | 7 | // RCS-ID: $Id$ |
fb46a9a6 | 8 | // Copyright: (c) David Webster |
65571936 | 9 | // Licence: wxWindows licence |
0e320a79 DW |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
27476f73 DW |
12 | // For compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
0e320a79 DW |
14 | |
15 | #include "wx/dialog.h" | |
e4db172a WS |
16 | |
17 | #ifndef WX_PRECOMP | |
18 | #include "wx/utils.h" | |
19 | #include "wx/frame.h" | |
20 | #include "wx/app.h" | |
21 | #include "wx/settings.h" | |
22 | #include "wx/intl.h" | |
23 | #include "wx/log.h" | |
27476f73 DW |
24 | #endif |
25 | ||
26 | #include "wx/os2/private.h" | |
598dc9b7 | 27 | #include "wx/evtloop.h" |
664e1314 | 28 | #include "wx/scopedptr.h" |
27476f73 | 29 | |
27476f73 DW |
30 | #define wxDIALOG_DEFAULT_X 300 |
31 | #define wxDIALOG_DEFAULT_Y 300 | |
0e320a79 | 32 | |
c9cb56f7 DW |
33 | #define wxDIALOG_DEFAULT_WIDTH 500 |
34 | #define wxDIALOG_DEFAULT_HEIGHT 500 | |
35 | ||
5d44b24e | 36 | IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxTopLevelWindow) |
27476f73 | 37 | |
598dc9b7 SN |
38 | // ---------------------------------------------------------------------------- |
39 | // wxDialogModalData | |
40 | // ---------------------------------------------------------------------------- | |
41 | ||
42 | // this is simply a container for any data we need to implement modality which | |
43 | // allows us to avoid changing wxDialog each time the implementation changes | |
44 | class wxDialogModalData | |
45 | { | |
46 | public: | |
47 | wxDialogModalData(wxDialog *dialog) : m_evtLoop(dialog) { } | |
48 | ||
49 | void RunLoop() | |
50 | { | |
51 | m_evtLoop.Run(); | |
52 | } | |
53 | ||
54 | void ExitLoop() | |
55 | { | |
56 | m_evtLoop.Exit(); | |
57 | } | |
58 | ||
59 | private: | |
60 | wxModalEventLoop m_evtLoop; | |
61 | }; | |
62 | ||
63 | wxDEFINE_TIED_SCOPED_PTR_TYPE(wxDialogModalData); | |
64 | ||
65 | // ============================================================================ | |
66 | // implementation | |
67 | // ============================================================================ | |
68 | ||
69 | // ---------------------------------------------------------------------------- | |
70 | // wxDialog construction | |
71 | // ---------------------------------------------------------------------------- | |
72 | ||
c9cb56f7 | 73 | void wxDialog::Init() |
0e320a79 | 74 | { |
d3b9f782 | 75 | m_pOldFocus = NULL; |
743e24aa | 76 | m_isShown = false; |
d3b9f782 | 77 | m_pWindowDisabler = NULL; |
ee22d7f3 | 78 | m_modalData = NULL; |
a756f210 | 79 | SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)); |
c9cb56f7 DW |
80 | } // end of wxDialog::Init |
81 | ||
6670f564 WS |
82 | bool wxDialog::Create( wxWindow* pParent, |
83 | wxWindowID vId, | |
84 | const wxString& rsTitle, | |
85 | const wxPoint& rPos, | |
86 | const wxSize& rSize, | |
87 | long lStyle, | |
88 | const wxString& rsName ) | |
0e320a79 | 89 | { |
c9cb56f7 | 90 | Init(); |
5d44b24e | 91 | SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG); |
c9cb56f7 DW |
92 | |
93 | // | |
5d44b24e | 94 | // Save focus before doing anything which can potentially change it |
c9cb56f7 | 95 | // |
5d44b24e | 96 | m_pOldFocus = FindFocus(); |
c9cb56f7 DW |
97 | |
98 | // | |
5d44b24e | 99 | // All dialogs should really have this style |
c9cb56f7 | 100 | // |
5d44b24e DW |
101 | lStyle |= wxTAB_TRAVERSAL; |
102 | ||
103 | if (!wxTopLevelWindow::Create( pParent | |
104 | ,vId | |
105 | ,rsTitle | |
106 | ,rPos | |
107 | ,rSize | |
108 | ,lStyle | |
109 | ,rsName | |
110 | )) | |
6670f564 WS |
111 | return false; |
112 | ||
a756f210 | 113 | SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); |
c9b9e020 DW |
114 | |
115 | // | |
116 | // Must defer setting the title until after dialog is created and sized | |
117 | // | |
118 | if (!rsTitle.IsNull()) | |
119 | SetTitle(rsTitle); | |
6670f564 | 120 | return true; |
c9cb56f7 | 121 | } // end of wxDialog::Create |
0e320a79 | 122 | |
89831b54 WS |
123 | #if WXWIN_COMPATIBILITY_2_6 |
124 | ||
86dc2301 SN |
125 | // deprecated ctor |
126 | wxDialog::wxDialog(wxWindow *parent, | |
127 | const wxString& title, | |
128 | bool WXUNUSED(modal), | |
129 | int x, | |
130 | int y, | |
131 | int w, | |
132 | int h, | |
133 | long style, | |
134 | const wxString& name) | |
135 | { | |
136 | Init(); | |
137 | ||
138 | Create(parent, wxID_ANY, title, wxPoint(x, y), wxSize(w, h), style, name); | |
139 | } | |
140 | ||
89831b54 | 141 | void wxDialog::SetModal(bool WXUNUSED(bFlag)) |
0e320a79 | 142 | { |
86dc2301 | 143 | // nothing to do, obsolete method |
c9cb56f7 | 144 | } // end of wxDialog::SetModal |
0e320a79 | 145 | |
89831b54 WS |
146 | #endif // WXWIN_COMPATIBILITY_2_6 |
147 | ||
0e320a79 DW |
148 | wxDialog::~wxDialog() |
149 | { | |
c6212a0c | 150 | SendDestroyEvent(); |
86dc2301 SN |
151 | |
152 | // this will also reenable all the other windows for a modal dialog | |
153 | Show(false); | |
c9cb56f7 | 154 | } // end of wxDialog::~wxDialog |
0e320a79 | 155 | |
5d44b24e DW |
156 | // ---------------------------------------------------------------------------- |
157 | // showing the dialogs | |
158 | // ---------------------------------------------------------------------------- | |
27476f73 | 159 | |
89831b54 WS |
160 | #if WXWIN_COMPATIBILITY_2_6 |
161 | ||
c9cb56f7 | 162 | bool wxDialog::IsModalShowing() const |
0e320a79 | 163 | { |
86dc2301 | 164 | return IsModal(); |
c9cb56f7 | 165 | } // end of wxDialog::IsModalShowing |
0e320a79 | 166 | |
89831b54 | 167 | #endif // WXWIN_COMPATIBILITY_2_6 |
0e320a79 | 168 | |
743e24aa | 169 | bool wxDialog::Show( bool bShow ) |
0e320a79 | 170 | { |
86dc2301 SN |
171 | if ( bShow == IsShown() ) |
172 | return false; | |
173 | ||
174 | if (!bShow && m_modalData ) | |
c9cb56f7 | 175 | { |
86dc2301 SN |
176 | // we need to do this before calling wxDialogBase version because if we |
177 | // had disabled other app windows, they must be reenabled right now as | |
c9cb56f7 | 178 | // if they stay disabled Windows will activate another window (one |
86dc2301 SN |
179 | // which is enabled, anyhow) when we're hidden in the base class Show() |
180 | // and we will lose activation | |
181 | m_modalData->ExitLoop(); | |
182 | #if 0 | |
5276b0a5 | 183 | wxDELETE(m_pWindowDisabler); |
86dc2301 | 184 | #endif |
c9cb56f7 | 185 | } |
0e320a79 | 186 | |
86dc2301 | 187 | if (bShow) |
c9cb56f7 | 188 | { |
3aa8e4ea JS |
189 | if (CanDoLayoutAdaptation()) |
190 | DoLayoutAdaptation(); | |
191 | ||
86dc2301 SN |
192 | // this usually will result in TransferDataToWindow() being called |
193 | // which will change the controls values so do it before showing as | |
194 | // otherwise we could have some flicker | |
195 | InitDialog(); | |
c9cb56f7 DW |
196 | } |
197 | ||
86dc2301 SN |
198 | wxDialogBase::Show(bShow); |
199 | ||
743e24aa WS |
200 | wxString title = GetTitle(); |
201 | if (!title.empty()) | |
65f3f920 | 202 | ::WinSetWindowText((HWND)GetHwnd(), title.c_str()); |
86dc2301 SN |
203 | |
204 | if ( bShow ) | |
c9cb56f7 | 205 | { |
ee22d7f3 | 206 | // dialogs don't get WM_SIZE message after creation unlike most (all?) |
42782237 | 207 | // other windows and so could start their life not laid out correctly |
ee22d7f3 SN |
208 | // if we didn't call Layout() from here |
209 | // | |
210 | // NB: normally we should call it just the first time but doing it | |
211 | // every time is simpler than keeping a flag | |
86dc2301 | 212 | Layout(); |
c9cb56f7 DW |
213 | } |
214 | ||
86dc2301 | 215 | return true; |
c9cb56f7 DW |
216 | } // end of wxDialog::Show |
217 | ||
218 | // | |
6670f564 | 219 | // Replacement for Show(true) for modal dialogs - returns return code |
c9cb56f7 | 220 | // |
0e320a79 DW |
221 | int wxDialog::ShowModal() |
222 | { | |
9a83f860 | 223 | wxASSERT_MSG( !IsModal(), wxT("wxDialog::ShowModal() reentered?") ); |
86dc2301 SN |
224 | |
225 | m_endModalCalled = false; | |
226 | ||
227 | Show(); | |
228 | ||
229 | // EndModal may have been called from InitDialog handler (called from | |
230 | // inside Show()), which would cause an infinite loop if we didn't take it | |
231 | // into account | |
232 | if ( !m_endModalCalled ) | |
c9cb56f7 | 233 | { |
86dc2301 | 234 | // modal dialog needs a parent window, so try to find one |
9fb0eb46 | 235 | wxWindow * const parent = GetParentForModalDialog(); |
86dc2301 SN |
236 | |
237 | // remember where the focus was | |
238 | wxWindow *oldFocus = m_pOldFocus; | |
239 | if ( !oldFocus ) | |
240 | { | |
241 | // VZ: do we really want to do this? | |
242 | oldFocus = parent; | |
243 | } | |
244 | ||
245 | // We have to remember the HWND because we need to check | |
246 | // the HWND still exists (oldFocus can be garbage when the dialog | |
247 | // exits, if it has been destroyed) | |
248 | HWND hwndOldFocus = oldFocus ? GetHwndOf(oldFocus) : NULL; | |
249 | ||
250 | ||
251 | // | |
252 | // Before entering the modal loop, reset the "is in OnIdle()" flag (see | |
253 | // comment in app.cpp) | |
254 | // | |
255 | extern bool gbInOnIdle; | |
256 | bool bWasInOnIdle = gbInOnIdle; | |
257 | ||
743e24aa | 258 | gbInOnIdle = false; |
86dc2301 SN |
259 | |
260 | // enter and run the modal loop | |
261 | { | |
262 | wxDialogModalDataTiedPtr modalData(&m_modalData, | |
263 | new wxDialogModalData(this)); | |
264 | modalData->RunLoop(); | |
265 | } | |
266 | gbInOnIdle = bWasInOnIdle; | |
267 | ||
268 | // and restore focus | |
269 | // Note that this code MUST NOT access the dialog object's data | |
270 | // in case the object has been deleted (which will be the case | |
271 | // for a modal dialog that has been destroyed before calling EndModal). | |
272 | if ( oldFocus && (oldFocus != this) && ::WinIsWindow(vHabmain, hwndOldFocus)) | |
273 | { | |
274 | // This is likely to prove that the object still exists | |
275 | if (wxFindWinFromHandle((WXHWND) hwndOldFocus) == oldFocus) | |
276 | oldFocus->SetFocus(); | |
277 | } | |
c9cb56f7 | 278 | } |
86dc2301 | 279 | |
27476f73 | 280 | return GetReturnCode(); |
c9cb56f7 | 281 | } // end of wxDialog::ShowModal |
0e320a79 | 282 | |
c9cb56f7 DW |
283 | void wxDialog::EndModal( |
284 | int nRetCode | |
285 | ) | |
0e320a79 | 286 | { |
9a83f860 | 287 | wxASSERT_MSG( IsModal(), wxT("EndModal() called for non modal dialog") ); |
86dc2301 SN |
288 | |
289 | m_endModalCalled = true; | |
c9cb56f7 | 290 | SetReturnCode(nRetCode); |
86dc2301 SN |
291 | |
292 | Hide(); | |
c9cb56f7 | 293 | } // end of wxDialog::EndModal |
0e320a79 | 294 | |
743e24aa | 295 | MRESULT wxDialog::OS2WindowProc( WXUINT uMessage, WXWPARAM wParam, WXLPARAM lParam ) |
0e320a79 | 296 | { |
743e24aa WS |
297 | MRESULT rc = 0; |
298 | bool bProcessed = false; | |
27476f73 | 299 | |
c9cb56f7 | 300 | switch (uMessage) |
27476f73 DW |
301 | { |
302 | case WM_CLOSE: | |
c9cb56f7 DW |
303 | // |
304 | // If we can't close, tell the system that we processed the | |
27476f73 | 305 | // message - otherwise it would close us |
c9cb56f7 DW |
306 | // |
307 | bProcessed = !Close(); | |
27476f73 DW |
308 | break; |
309 | } | |
310 | ||
c9cb56f7 DW |
311 | if (!bProcessed) |
312 | rc = wxWindow::OS2WindowProc( uMessage | |
313 | ,wParam | |
314 | ,lParam | |
315 | ); | |
27476f73 | 316 | return rc; |
c9cb56f7 | 317 | } // end of wxDialog::OS2WindowProc |