]>
Commit | Line | Data |
---|---|---|
2bda0e17 | 1 | ///////////////////////////////////////////////////////////////////////////// |
b6c588e1 | 2 | // Name: src/msw/dialog.cpp |
2bda0e17 KB |
3 | // Purpose: wxDialog class |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
dc1c4b62 | 9 | // Licence: wxWindows licence |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
b6c588e1 VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
2bda0e17 | 20 | #ifdef __GNUG__ |
b6c588e1 | 21 | #pragma implementation "dialog.h" |
2bda0e17 KB |
22 | #endif |
23 | ||
24 | // For compilers that support precompilation, includes "wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
b6c588e1 | 28 | #pragma hdrstop |
2bda0e17 KB |
29 | #endif |
30 | ||
31 | #ifndef WX_PRECOMP | |
b6c588e1 VZ |
32 | #include "wx/dialog.h" |
33 | #include "wx/utils.h" | |
34 | #include "wx/frame.h" | |
35 | #include "wx/app.h" | |
36 | #include "wx/settings.h" | |
37 | #include "wx/intl.h" | |
38 | #include "wx/log.h" | |
2bda0e17 KB |
39 | #endif |
40 | ||
41 | #include "wx/msw/private.h" | |
dbda9e86 | 42 | #include "wx/log.h" |
2bda0e17 | 43 | |
47d67540 | 44 | #if wxUSE_COMMON_DIALOGS |
b6c588e1 | 45 | #include <commdlg.h> |
2bda0e17 KB |
46 | #endif |
47 | ||
b6c588e1 VZ |
48 | // ---------------------------------------------------------------------------- |
49 | // constants | |
50 | // ---------------------------------------------------------------------------- | |
51 | ||
52 | // default dialog pos and size | |
53 | ||
2bda0e17 KB |
54 | #define wxDIALOG_DEFAULT_X 300 |
55 | #define wxDIALOG_DEFAULT_Y 300 | |
56 | ||
b6c588e1 VZ |
57 | #define wxDIALOG_DEFAULT_WIDTH 500 |
58 | #define wxDIALOG_DEFAULT_HEIGHT 500 | |
59 | ||
60 | // ---------------------------------------------------------------------------- | |
61 | // globals | |
62 | // ---------------------------------------------------------------------------- | |
63 | ||
64 | // all objects to be deleted during next idle processing - from window.cpp | |
cde9f08e | 65 | extern wxList WXDLLEXPORT wxPendingDelete; |
2bda0e17 | 66 | |
b6c588e1 VZ |
67 | // all frames and modeless dialogs - not static, used in frame.cpp, mdi.cpp &c |
68 | wxWindowList wxModelessWindows; | |
69 | ||
70 | // all modal dialogs currently shown | |
71 | static wxWindowList wxModalDialogs; | |
72 | ||
73 | // ---------------------------------------------------------------------------- | |
74 | // wxWin macros | |
75 | // ---------------------------------------------------------------------------- | |
76 | ||
1b6452df VZ |
77 | IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxPanel) |
78 | ||
79 | BEGIN_EVENT_TABLE(wxDialog, wxPanel) | |
1b6452df VZ |
80 | EVT_BUTTON(wxID_OK, wxDialog::OnOK) |
81 | EVT_BUTTON(wxID_APPLY, wxDialog::OnApply) | |
82 | EVT_BUTTON(wxID_CANCEL, wxDialog::OnCancel) | |
b6c588e1 | 83 | |
1b6452df | 84 | EVT_CHAR_HOOK(wxDialog::OnCharHook) |
b6c588e1 | 85 | |
1b6452df | 86 | EVT_SYS_COLOUR_CHANGED(wxDialog::OnSysColourChanged) |
b6c588e1 | 87 | |
1b6452df VZ |
88 | EVT_CLOSE(wxDialog::OnCloseWindow) |
89 | END_EVENT_TABLE() | |
2bda0e17 | 90 | |
b6c588e1 VZ |
91 | // ============================================================================ |
92 | // implementation | |
93 | // ============================================================================ | |
94 | ||
95 | // ---------------------------------------------------------------------------- | |
96 | // wxDialog construction | |
97 | // ---------------------------------------------------------------------------- | |
98 | ||
b0a6bb75 | 99 | void wxDialog::Init() |
2bda0e17 | 100 | { |
52a07708 | 101 | m_oldFocus = (wxWindow *)NULL; |
b0a6bb75 | 102 | |
b6c588e1 | 103 | m_isShown = FALSE; |
2bda0e17 | 104 | |
b0a6bb75 VZ |
105 | m_windowDisabler = (wxWindowDisabler *)NULL; |
106 | ||
b6c588e1 | 107 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE)); |
2bda0e17 KB |
108 | } |
109 | ||
b3daa5a3 VZ |
110 | bool wxDialog::Create(wxWindow *parent, |
111 | wxWindowID id, | |
462e2437 VZ |
112 | const wxString& title, |
113 | const wxPoint& pos, | |
114 | const wxSize& size, | |
115 | long style, | |
116 | const wxString& name) | |
2bda0e17 | 117 | { |
b0a6bb75 VZ |
118 | Init(); |
119 | ||
abceee76 VZ |
120 | m_oldFocus = FindFocus(); |
121 | ||
462e2437 | 122 | SetName(name); |
bd9d76cb | 123 | |
f6bcfd97 | 124 | wxTopLevelWindows.Append(this); |
2bda0e17 | 125 | |
b3daa5a3 VZ |
126 | if ( parent ) |
127 | parent->AddChild(this); | |
2bda0e17 | 128 | |
462e2437 VZ |
129 | if ( id == -1 ) |
130 | m_windowId = (int)NewControlId(); | |
131 | else | |
132 | m_windowId = id; | |
133 | ||
134 | int x = pos.x; | |
135 | int y = pos.y; | |
136 | int width = size.x; | |
137 | int height = size.y; | |
138 | ||
b6c588e1 VZ |
139 | if (x < 0) |
140 | x = wxDIALOG_DEFAULT_X; | |
141 | if (y < 0) | |
142 | y = wxDIALOG_DEFAULT_Y; | |
462e2437 VZ |
143 | |
144 | m_windowStyle = style; | |
145 | ||
462e2437 | 146 | if (width < 0) |
b6c588e1 | 147 | width = wxDIALOG_DEFAULT_WIDTH; |
462e2437 | 148 | if (height < 0) |
b6c588e1 | 149 | height = wxDIALOG_DEFAULT_HEIGHT; |
462e2437 | 150 | |
706bb5f9 JS |
151 | // All dialogs should really have this style |
152 | m_windowStyle |= wxTAB_TRAVERSAL; | |
153 | ||
462e2437 VZ |
154 | WXDWORD extendedStyle = MakeExtendedStyle(m_windowStyle); |
155 | if (m_windowStyle & wxSTAY_ON_TOP) | |
156 | extendedStyle |= WS_EX_TOPMOST; | |
157 | ||
4204da65 JS |
158 | #ifndef __WIN16__ |
159 | if (m_exStyle & wxDIALOG_EX_CONTEXTHELP) | |
160 | extendedStyle |= WS_EX_CONTEXTHELP; | |
161 | #endif | |
b3daa5a3 | 162 | |
462e2437 VZ |
163 | // Allows creation of dialogs with & without captions under MSWindows, |
164 | // resizeable or not (but a resizeable dialog always has caption - | |
165 | // otherwise it would look too strange) | |
837e5743 | 166 | const wxChar *dlg; |
257bf510 | 167 | if ( style & wxRESIZE_BORDER ) |
223d09f6 | 168 | dlg = wxT("wxResizeableDialog"); |
462e2437 | 169 | else if ( style & wxCAPTION ) |
223d09f6 | 170 | dlg = wxT("wxCaptionDialog"); |
462e2437 | 171 | else |
223d09f6 | 172 | dlg = wxT("wxNoCaptionDialog"); |
462e2437 VZ |
173 | MSWCreate(m_windowId, parent, NULL, this, NULL, |
174 | x, y, width, height, | |
175 | 0, // style is not used if we have dlg template | |
176 | dlg, | |
177 | extendedStyle); | |
2bda0e17 | 178 | |
462e2437 | 179 | HWND hwnd = (HWND)GetHWND(); |
2bda0e17 | 180 | |
462e2437 VZ |
181 | if ( !hwnd ) |
182 | { | |
f6bcfd97 | 183 | wxFAIL_MSG(_("Failed to create dialog. You probably forgot to include wx/msw/wx.rc in your resources.")); |
2bda0e17 | 184 | |
462e2437 VZ |
185 | return FALSE; |
186 | } | |
2bda0e17 | 187 | |
462e2437 | 188 | SubclassWin(GetHWND()); |
bd9d76cb | 189 | |
462e2437 VZ |
190 | SetWindowText(hwnd, title); |
191 | SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT)); | |
2bda0e17 | 192 | |
462e2437 | 193 | return TRUE; |
2bda0e17 KB |
194 | } |
195 | ||
debe6624 | 196 | void wxDialog::SetModal(bool flag) |
2bda0e17 | 197 | { |
b6c588e1 VZ |
198 | if ( flag ) |
199 | { | |
200 | m_windowStyle |= wxDIALOG_MODAL; | |
201 | ||
202 | wxModelessWindows.DeleteObject(this); | |
203 | } | |
204 | else | |
205 | { | |
206 | m_windowStyle &= ~wxDIALOG_MODAL; | |
207 | ||
208 | wxModelessWindows.Append(this); | |
209 | } | |
2bda0e17 KB |
210 | } |
211 | ||
212 | wxDialog::~wxDialog() | |
213 | { | |
b6c588e1 | 214 | m_isBeingDeleted = TRUE; |
2bda0e17 | 215 | |
b6c588e1 | 216 | wxTopLevelWindows.DeleteObject(this); |
2bda0e17 | 217 | |
b0a6bb75 | 218 | // this will also reenable all the other windows for a modal dialog |
b6c588e1 | 219 | Show(FALSE); |
edccf428 | 220 | |
b6c588e1 VZ |
221 | if ( !IsModal() ) |
222 | wxModelessWindows.DeleteObject(this); | |
2bda0e17 | 223 | |
b6c588e1 VZ |
224 | // If this is the last top-level window, exit. |
225 | if ( wxTheApp && (wxTopLevelWindows.Number() == 0) ) | |
2bda0e17 | 226 | { |
b6c588e1 VZ |
227 | wxTheApp->SetTopWindow(NULL); |
228 | ||
229 | if ( wxTheApp->GetExitOnFrameDelete() ) | |
230 | { | |
231 | ::PostQuitMessage(0); | |
232 | } | |
2bda0e17 | 233 | } |
2bda0e17 KB |
234 | } |
235 | ||
b6c588e1 VZ |
236 | // ---------------------------------------------------------------------------- |
237 | // kbd handling | |
238 | // ---------------------------------------------------------------------------- | |
239 | ||
2bda0e17 KB |
240 | // By default, pressing escape cancels the dialog |
241 | void wxDialog::OnCharHook(wxKeyEvent& event) | |
242 | { | |
cbc66a27 | 243 | if (GetHWND()) |
2bda0e17 | 244 | { |
cbc66a27 VZ |
245 | // "Esc" works as an accelerator for the "Cancel" button, but it |
246 | // shouldn't close the dialog which doesn't have any cancel button | |
247 | if ( (event.m_keyCode == WXK_ESCAPE) && FindWindow(wxID_CANCEL) ) | |
248 | { | |
249 | wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL); | |
250 | cancelEvent.SetEventObject( this ); | |
251 | GetEventHandler()->ProcessEvent(cancelEvent); | |
252 | ||
253 | // ensure that there is another message for this window so the | |
254 | // ShowModal loop will exit and won't get stuck in GetMessage(). | |
255 | ::PostMessage(GetHwnd(), WM_NULL, 0, 0); | |
256 | ||
257 | return; | |
258 | } | |
2bda0e17 | 259 | } |
cbc66a27 VZ |
260 | |
261 | // We didn't process this event. | |
262 | event.Skip(); | |
2bda0e17 KB |
263 | } |
264 | ||
b6c588e1 VZ |
265 | // ---------------------------------------------------------------------------- |
266 | // Windows dialog boxes can't be iconized | |
267 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 268 | |
debe6624 | 269 | void wxDialog::Iconize(bool WXUNUSED(iconize)) |
2bda0e17 | 270 | { |
2bda0e17 KB |
271 | } |
272 | ||
a23fd0e1 | 273 | bool wxDialog::IsIconized() const |
2bda0e17 | 274 | { |
b6c588e1 | 275 | return FALSE; |
2bda0e17 KB |
276 | } |
277 | ||
b6c588e1 VZ |
278 | // ---------------------------------------------------------------------------- |
279 | // size/position handling | |
280 | // ---------------------------------------------------------------------------- | |
281 | ||
721b32e0 | 282 | void wxDialog::DoSetClientSize(int width, int height) |
2bda0e17 | 283 | { |
b6c588e1 VZ |
284 | HWND hWnd = (HWND) GetHWND(); |
285 | RECT rect; | |
286 | ::GetClientRect(hWnd, &rect); | |
2bda0e17 | 287 | |
b6c588e1 VZ |
288 | RECT rect2; |
289 | GetWindowRect(hWnd, &rect2); | |
2bda0e17 | 290 | |
b6c588e1 VZ |
291 | // Find the difference between the entire window (title bar and all) |
292 | // and the client area; add this to the new client size to move the | |
293 | // window | |
294 | int actual_width = rect2.right - rect2.left - rect.right + width; | |
295 | int actual_height = rect2.bottom - rect2.top - rect.bottom + height; | |
2bda0e17 | 296 | |
b6c588e1 | 297 | MoveWindow(hWnd, rect2.left, rect2.top, actual_width, actual_height, TRUE); |
debe6624 | 298 | |
b6c588e1 VZ |
299 | wxSizeEvent event(wxSize(actual_width, actual_height), m_windowId); |
300 | event.SetEventObject( this ); | |
301 | GetEventHandler()->ProcessEvent(event); | |
2bda0e17 KB |
302 | } |
303 | ||
b6c588e1 | 304 | void wxDialog::DoGetPosition(int *x, int *y) const |
2bda0e17 | 305 | { |
b6c588e1 VZ |
306 | RECT rect; |
307 | GetWindowRect(GetHwnd(), &rect); | |
2bda0e17 | 308 | |
b6c588e1 VZ |
309 | if ( x ) |
310 | *x = rect.left; | |
311 | if ( y ) | |
312 | *y = rect.top; | |
2bda0e17 KB |
313 | } |
314 | ||
b6c588e1 VZ |
315 | // ---------------------------------------------------------------------------- |
316 | // showing the dialogs | |
317 | // ---------------------------------------------------------------------------- | |
22cf5fec VZ |
318 | |
319 | bool wxDialog::IsModal() const | |
320 | { | |
b6c588e1 | 321 | return (GetWindowStyleFlag() & wxDIALOG_MODAL) != 0; |
2bda0e17 KB |
322 | } |
323 | ||
b6c588e1 | 324 | bool wxDialog::IsModalShowing() const |
2bda0e17 | 325 | { |
b6c588e1 | 326 | return wxModalDialogs.Find((wxDialog *)this) != NULL; // const_cast |
2bda0e17 KB |
327 | } |
328 | ||
b6c588e1 | 329 | void wxDialog::DoShowModal() |
2bda0e17 | 330 | { |
b6c588e1 | 331 | wxCHECK_RET( !IsModalShowing(), _T("DoShowModal() called twice") ); |
f6bcfd97 | 332 | wxCHECK_RET( IsModal(), _T("can't DoShowModal() modeless dialog") ); |
b6c588e1 VZ |
333 | |
334 | wxModalDialogs.Append(this); | |
335 | ||
336 | wxWindow *parent = GetParent(); | |
337 | ||
f6bcfd97 | 338 | wxWindow* oldFocus = m_oldFocus; |
b6c588e1 | 339 | |
f6bcfd97 BP |
340 | // We have to remember the HWND because we need to check |
341 | // the HWND still exists (oldFocus can be garbage when the dialog | |
342 | // exits, if it has been destroyed) | |
343 | HWND hwndOldFocus = 0; | |
344 | if (oldFocus) | |
345 | hwndOldFocus = (HWND) oldFocus->GetHWND(); | |
b6c588e1 | 346 | |
b0a6bb75 VZ |
347 | // remember where the focus was |
348 | if ( !oldFocus ) | |
b6c588e1 | 349 | { |
b0a6bb75 VZ |
350 | oldFocus = parent; |
351 | if ( parent ) | |
352 | hwndOldFocus = GetHwndOf(parent); | |
353 | } | |
f6bcfd97 | 354 | |
b0a6bb75 VZ |
355 | // disable all other app windows |
356 | wxASSERT_MSG( !m_windowDisabler, _T("disabling windows twice?") ); | |
f6bcfd97 | 357 | |
b0a6bb75 VZ |
358 | m_windowDisabler = new wxWindowDisabler(this); |
359 | ||
360 | // enter the modal loop | |
361 | while ( IsModalShowing() ) | |
362 | { | |
b6c588e1 | 363 | #if wxUSE_THREADS |
b0a6bb75 | 364 | wxMutexGuiLeaveOrEnter(); |
b6c588e1 VZ |
365 | #endif // wxUSE_THREADS |
366 | ||
b0a6bb75 VZ |
367 | while ( !wxTheApp->Pending() && wxTheApp->ProcessIdle() ) |
368 | ; | |
b6c588e1 | 369 | |
b0a6bb75 VZ |
370 | // a message came or no more idle processing to do |
371 | wxTheApp->DoMessage(); | |
b6c588e1 VZ |
372 | } |
373 | ||
b6c588e1 | 374 | // and restore focus |
f6bcfd97 BP |
375 | // Note that this code MUST NOT access the dialog object's data |
376 | // in case the object has been deleted (which will be the case | |
377 | // for a modal dialog that has been destroyed before calling EndModal). | |
378 | if ( oldFocus && (oldFocus != this) && ::IsWindow(hwndOldFocus)) | |
b6c588e1 | 379 | { |
f6bcfd97 BP |
380 | // This is likely to prove that the object still exists |
381 | if (wxFindWinFromHandle((WXHWND) hwndOldFocus) == oldFocus) | |
382 | oldFocus->SetFocus(); | |
b6c588e1 | 383 | } |
2bda0e17 KB |
384 | } |
385 | ||
b6c588e1 | 386 | bool wxDialog::Show(bool show) |
2bda0e17 | 387 | { |
abceee76 | 388 | if ( !show ) |
86ad564e | 389 | { |
b0a6bb75 VZ |
390 | // if we had disabled other app windows, reenable them back now because |
391 | // if they stay disabled Windows will activate another window (one | |
392 | // which is enabled, anyhow) and we will lose activation | |
393 | if ( m_windowDisabler ) | |
86ad564e | 394 | { |
b0a6bb75 VZ |
395 | delete m_windowDisabler; |
396 | m_windowDisabler = NULL; | |
86ad564e JS |
397 | } |
398 | } | |
399 | ||
abceee76 VZ |
400 | // ShowModal() may be called for already shown dialog |
401 | if ( !wxDialogBase::Show(show) && !(show && IsModal()) ) | |
b6c588e1 VZ |
402 | { |
403 | // nothing to do | |
404 | return FALSE; | |
405 | } | |
2bda0e17 | 406 | |
b6c588e1 VZ |
407 | if ( show ) |
408 | { | |
409 | // usually will result in TransferDataToWindow() being called | |
410 | InitDialog(); | |
411 | } | |
2bda0e17 | 412 | |
b6c588e1 VZ |
413 | if ( IsModal() ) |
414 | { | |
415 | if ( show ) | |
416 | { | |
f6bcfd97 BP |
417 | // modal dialog needs a parent window, so try to find one |
418 | if ( !GetParent() ) | |
419 | { | |
420 | wxWindow *parent = wxTheApp->GetTopWindow(); | |
421 | if ( parent && parent != this && parent->IsShown() ) | |
422 | { | |
423 | // use it | |
424 | m_parent = parent; | |
e5f741e5 VZ |
425 | |
426 | // VZ: to make dialog behave properly we should reparent | |
427 | // the dialog for Windows as well - unfortunately, | |
428 | // following the docs for SetParent() results in this | |
429 | // code which plainly doesn't work | |
430 | #if 0 | |
431 | long dwStyle = ::GetWindowLong(GetHwnd(), GWL_STYLE); | |
432 | dwStyle &= ~WS_POPUP; | |
433 | dwStyle |= WS_CHILD; | |
434 | ::SetWindowLong(GetHwnd(), GWL_STYLE, dwStyle); | |
435 | ::SetParent(GetHwnd(), GetHwndOf(parent)); | |
436 | #endif // 0 | |
f6bcfd97 BP |
437 | } |
438 | } | |
439 | ||
b6c588e1 VZ |
440 | DoShowModal(); |
441 | } | |
442 | else // end of modal dialog | |
443 | { | |
444 | // this will cause IsModalShowing() return FALSE and our local | |
445 | // message loop will terminate | |
446 | wxModalDialogs.DeleteObject(this); | |
447 | } | |
448 | } | |
2bda0e17 | 449 | |
b6c588e1 | 450 | return TRUE; |
2bda0e17 KB |
451 | } |
452 | ||
f6bcfd97 | 453 | // a special version for Show(TRUE) for modal dialogs which returns return code |
a23fd0e1 | 454 | int wxDialog::ShowModal() |
2bda0e17 | 455 | { |
f6bcfd97 | 456 | if ( !IsModal() ) |
5e1febfa | 457 | { |
f6bcfd97 | 458 | SetModal(TRUE); |
5e1febfa VZ |
459 | } |
460 | ||
b6c588e1 | 461 | Show(TRUE); |
5e1febfa | 462 | |
b6c588e1 | 463 | return GetReturnCode(); |
2bda0e17 KB |
464 | } |
465 | ||
b6c588e1 VZ |
466 | // NB: this function (surprizingly) may be called for both modal and modeless |
467 | // dialogs and should work for both of them | |
2bda0e17 KB |
468 | void wxDialog::EndModal(int retCode) |
469 | { | |
b6c588e1 | 470 | SetReturnCode(retCode); |
6a088435 | 471 | |
b6c588e1 | 472 | Show(FALSE); |
2bda0e17 KB |
473 | } |
474 | ||
b6c588e1 VZ |
475 | // ---------------------------------------------------------------------------- |
476 | // wxWin event handlers | |
477 | // ---------------------------------------------------------------------------- | |
2bda0e17 KB |
478 | |
479 | // Standard buttons | |
480 | void wxDialog::OnOK(wxCommandEvent& event) | |
481 | { | |
dc1c4b62 VZ |
482 | if ( Validate() && TransferDataFromWindow() ) |
483 | { | |
b6c588e1 | 484 | EndModal(wxID_OK); |
dc1c4b62 | 485 | } |
2bda0e17 KB |
486 | } |
487 | ||
488 | void wxDialog::OnApply(wxCommandEvent& event) | |
489 | { | |
b6c588e1 VZ |
490 | if ( Validate() ) |
491 | TransferDataFromWindow(); | |
492 | ||
493 | // TODO probably need to disable the Apply button until things change again | |
2bda0e17 KB |
494 | } |
495 | ||
496 | void wxDialog::OnCancel(wxCommandEvent& event) | |
497 | { | |
b6c588e1 | 498 | EndModal(wxID_CANCEL); |
2bda0e17 KB |
499 | } |
500 | ||
e3065973 | 501 | void wxDialog::OnCloseWindow(wxCloseEvent& event) |
2bda0e17 | 502 | { |
b6c588e1 | 503 | // We'll send a Cancel message by default, which may close the dialog. |
e3065973 JS |
504 | // Check for looping if the Cancel event handler calls Close(). |
505 | ||
506 | // Note that if a cancel button and handler aren't present in the dialog, | |
507 | // nothing will happen when you close the dialog via the window manager, or | |
b6c588e1 VZ |
508 | // via Close(). We wouldn't want to destroy the dialog by default, since |
509 | // the dialog may have been created on the stack. However, this does mean | |
510 | // that calling dialog->Close() won't delete the dialog unless the handler | |
511 | // for wxID_CANCEL does so. So use Destroy() if you want to be sure to | |
512 | // destroy the dialog. The default OnCancel (above) simply ends a modal | |
513 | // dialog, and hides a modeless dialog. | |
514 | ||
515 | // VZ: this is horrible and MT-unsafe. Can't we reuse some of these global | |
516 | // lists here? don't dare to change it now, but should be done later! | |
2bda0e17 | 517 | static wxList closing; |
bd9d76cb | 518 | |
2bda0e17 | 519 | if ( closing.Member(this) ) |
e3065973 | 520 | return; |
bd9d76cb | 521 | |
2bda0e17 | 522 | closing.Append(this); |
bd9d76cb | 523 | |
387a3b02 JS |
524 | wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL); |
525 | cancelEvent.SetEventObject( this ); | |
e3065973 | 526 | GetEventHandler()->ProcessEvent(cancelEvent); // This may close the dialog |
2bda0e17 KB |
527 | |
528 | closing.DeleteObject(this); | |
e3065973 | 529 | } |
2bda0e17 | 530 | |
e3065973 | 531 | // Destroy the window (delayed, if a managed window) |
a23fd0e1 | 532 | bool wxDialog::Destroy() |
e3065973 | 533 | { |
b6c588e1 VZ |
534 | wxCHECK_MSG( !wxPendingDelete.Member(this), FALSE, |
535 | _T("wxDialog destroyed twice") ); | |
536 | ||
e3065973 | 537 | wxPendingDelete.Append(this); |
2bda0e17 | 538 | |
b6c588e1 | 539 | return TRUE; |
94b49b93 JS |
540 | } |
541 | ||
2bda0e17 KB |
542 | void wxDialog::OnSysColourChanged(wxSysColourChangedEvent& event) |
543 | { | |
1f112209 | 544 | #if wxUSE_CTL3D |
b6c588e1 | 545 | Ctl3dColorChange(); |
2bda0e17 | 546 | #else |
b6c588e1 VZ |
547 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE)); |
548 | Refresh(); | |
2bda0e17 | 549 | #endif |
68ad65f8 | 550 | } |
42e69d6b VZ |
551 | |
552 | // --------------------------------------------------------------------------- | |
553 | // dialog window proc | |
554 | // --------------------------------------------------------------------------- | |
555 | ||
556 | long wxDialog::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) | |
557 | { | |
558 | long rc = 0; | |
559 | bool processed = FALSE; | |
560 | ||
561 | switch ( message ) | |
562 | { | |
b0a6bb75 | 563 | #if 0 // now that we got owner window right it doesn't seem to be needed |
5e1febfa VZ |
564 | case WM_ACTIVATE: |
565 | switch ( LOWORD(wParam) ) | |
566 | { | |
567 | case WA_ACTIVE: | |
568 | case WA_CLICKACTIVE: | |
569 | if ( IsModalShowing() && GetParent() ) | |
570 | { | |
571 | // bring the owner window to top as the standard dialog | |
572 | // boxes do | |
573 | if ( !::SetWindowPos | |
574 | ( | |
575 | GetHwndOf(GetParent()), | |
576 | GetHwnd(), | |
577 | 0, 0, | |
578 | 0, 0, | |
579 | SWP_NOACTIVATE | | |
580 | SWP_NOMOVE | | |
581 | SWP_NOSIZE | |
582 | ) ) | |
583 | { | |
f6bcfd97 | 584 | wxLogLastError(wxT("SetWindowPos(SWP_NOACTIVATE)")); |
5e1febfa VZ |
585 | } |
586 | } | |
587 | // fall through to process it normally as well | |
588 | } | |
589 | break; | |
b0a6bb75 | 590 | #endif // 0 |
5e1febfa | 591 | |
42e69d6b VZ |
592 | case WM_CLOSE: |
593 | // if we can't close, tell the system that we processed the | |
594 | // message - otherwise it would close us | |
595 | processed = !Close(); | |
596 | break; | |
abceee76 VZ |
597 | |
598 | case WM_SETCURSOR: | |
599 | // we want to override the busy cursor for modal dialogs: | |
600 | // typically, wxBeginBusyCursor() is called and then a modal dialog | |
bfbd6dc1 | 601 | // is shown, but the modal dialog shouldn't have hourglass cursor |
d1477745 | 602 | if ( IsModalShowing() && wxIsBusy() ) |
abceee76 | 603 | { |
bfbd6dc1 VZ |
604 | // set our cursor for all windows (but see below) |
605 | wxCursor cursor = m_cursor; | |
606 | if ( !cursor.Ok() ) | |
607 | cursor = wxCURSOR_ARROW; | |
abceee76 | 608 | |
bfbd6dc1 VZ |
609 | ::SetCursor(GetHcursorOf(cursor)); |
610 | ||
611 | // in any case, stop here and don't let wxWindow process this | |
612 | // message (it would set the busy cursor) | |
abceee76 | 613 | processed = TRUE; |
bfbd6dc1 VZ |
614 | |
615 | // but return FALSE to tell the child window (if the event | |
616 | // comes from one of them and not from ourselves) that it can | |
617 | // set its own cursor if it has one: thus, standard controls | |
618 | // (e.g. text ctrl) still have correct cursors in a dialog | |
619 | // invoked while wxIsBusy() | |
620 | rc = FALSE; | |
abceee76 | 621 | } |
bfbd6dc1 | 622 | break; |
42e69d6b VZ |
623 | } |
624 | ||
625 | if ( !processed ) | |
626 | rc = wxWindow::MSWWindowProc(message, wParam, lParam); | |
627 | ||
628 | return rc; | |
629 | } | |
b6c588e1 VZ |
630 | |
631 | #if wxUSE_CTL3D | |
632 | ||
633 | // Define for each class of dialog and control | |
634 | WXHBRUSH wxDialog::OnCtlColor(WXHDC WXUNUSED(pDC), | |
635 | WXHWND WXUNUSED(pWnd), | |
636 | WXUINT WXUNUSED(nCtlColor), | |
637 | WXUINT message, | |
638 | WXWPARAM wParam, | |
639 | WXLPARAM lParam) | |
640 | { | |
641 | return (WXHBRUSH)Ctl3dCtlColorEx(message, wParam, lParam); | |
642 | } | |
643 | ||
644 | #endif // wxUSE_CTL3D | |
645 |