]>
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 | 190 | SetWindowText(hwnd, title); |
2bda0e17 | 191 | |
462e2437 | 192 | return TRUE; |
2bda0e17 KB |
193 | } |
194 | ||
debe6624 | 195 | void wxDialog::SetModal(bool flag) |
2bda0e17 | 196 | { |
b6c588e1 VZ |
197 | if ( flag ) |
198 | { | |
199 | m_windowStyle |= wxDIALOG_MODAL; | |
200 | ||
201 | wxModelessWindows.DeleteObject(this); | |
202 | } | |
203 | else | |
204 | { | |
205 | m_windowStyle &= ~wxDIALOG_MODAL; | |
206 | ||
207 | wxModelessWindows.Append(this); | |
208 | } | |
2bda0e17 KB |
209 | } |
210 | ||
211 | wxDialog::~wxDialog() | |
212 | { | |
b6c588e1 | 213 | m_isBeingDeleted = TRUE; |
2bda0e17 | 214 | |
b6c588e1 | 215 | wxTopLevelWindows.DeleteObject(this); |
2bda0e17 | 216 | |
b0a6bb75 | 217 | // this will also reenable all the other windows for a modal dialog |
b6c588e1 | 218 | Show(FALSE); |
edccf428 | 219 | |
b6c588e1 VZ |
220 | if ( !IsModal() ) |
221 | wxModelessWindows.DeleteObject(this); | |
2bda0e17 | 222 | |
b6c588e1 VZ |
223 | // If this is the last top-level window, exit. |
224 | if ( wxTheApp && (wxTopLevelWindows.Number() == 0) ) | |
2bda0e17 | 225 | { |
b6c588e1 VZ |
226 | wxTheApp->SetTopWindow(NULL); |
227 | ||
228 | if ( wxTheApp->GetExitOnFrameDelete() ) | |
229 | { | |
230 | ::PostQuitMessage(0); | |
231 | } | |
2bda0e17 | 232 | } |
2bda0e17 KB |
233 | } |
234 | ||
b6c588e1 VZ |
235 | // ---------------------------------------------------------------------------- |
236 | // kbd handling | |
237 | // ---------------------------------------------------------------------------- | |
238 | ||
2bda0e17 KB |
239 | // By default, pressing escape cancels the dialog |
240 | void wxDialog::OnCharHook(wxKeyEvent& event) | |
241 | { | |
cbc66a27 | 242 | if (GetHWND()) |
2bda0e17 | 243 | { |
cbc66a27 VZ |
244 | // "Esc" works as an accelerator for the "Cancel" button, but it |
245 | // shouldn't close the dialog which doesn't have any cancel button | |
246 | if ( (event.m_keyCode == WXK_ESCAPE) && FindWindow(wxID_CANCEL) ) | |
247 | { | |
248 | wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL); | |
249 | cancelEvent.SetEventObject( this ); | |
250 | GetEventHandler()->ProcessEvent(cancelEvent); | |
251 | ||
252 | // ensure that there is another message for this window so the | |
253 | // ShowModal loop will exit and won't get stuck in GetMessage(). | |
254 | ::PostMessage(GetHwnd(), WM_NULL, 0, 0); | |
255 | ||
256 | return; | |
257 | } | |
2bda0e17 | 258 | } |
cbc66a27 VZ |
259 | |
260 | // We didn't process this event. | |
261 | event.Skip(); | |
2bda0e17 KB |
262 | } |
263 | ||
b6c588e1 VZ |
264 | // ---------------------------------------------------------------------------- |
265 | // Windows dialog boxes can't be iconized | |
266 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 267 | |
debe6624 | 268 | void wxDialog::Iconize(bool WXUNUSED(iconize)) |
2bda0e17 | 269 | { |
2bda0e17 KB |
270 | } |
271 | ||
a23fd0e1 | 272 | bool wxDialog::IsIconized() const |
2bda0e17 | 273 | { |
b6c588e1 | 274 | return FALSE; |
2bda0e17 KB |
275 | } |
276 | ||
b6c588e1 VZ |
277 | // ---------------------------------------------------------------------------- |
278 | // size/position handling | |
279 | // ---------------------------------------------------------------------------- | |
280 | ||
721b32e0 | 281 | void wxDialog::DoSetClientSize(int width, int height) |
2bda0e17 | 282 | { |
b6c588e1 VZ |
283 | HWND hWnd = (HWND) GetHWND(); |
284 | RECT rect; | |
285 | ::GetClientRect(hWnd, &rect); | |
2bda0e17 | 286 | |
b6c588e1 VZ |
287 | RECT rect2; |
288 | GetWindowRect(hWnd, &rect2); | |
2bda0e17 | 289 | |
b6c588e1 VZ |
290 | // Find the difference between the entire window (title bar and all) |
291 | // and the client area; add this to the new client size to move the | |
292 | // window | |
293 | int actual_width = rect2.right - rect2.left - rect.right + width; | |
294 | int actual_height = rect2.bottom - rect2.top - rect.bottom + height; | |
2bda0e17 | 295 | |
b6c588e1 | 296 | MoveWindow(hWnd, rect2.left, rect2.top, actual_width, actual_height, TRUE); |
debe6624 | 297 | |
b6c588e1 VZ |
298 | wxSizeEvent event(wxSize(actual_width, actual_height), m_windowId); |
299 | event.SetEventObject( this ); | |
300 | GetEventHandler()->ProcessEvent(event); | |
2bda0e17 KB |
301 | } |
302 | ||
b6c588e1 | 303 | void wxDialog::DoGetPosition(int *x, int *y) const |
2bda0e17 | 304 | { |
b6c588e1 VZ |
305 | RECT rect; |
306 | GetWindowRect(GetHwnd(), &rect); | |
2bda0e17 | 307 | |
b6c588e1 VZ |
308 | if ( x ) |
309 | *x = rect.left; | |
310 | if ( y ) | |
311 | *y = rect.top; | |
2bda0e17 KB |
312 | } |
313 | ||
b6c588e1 VZ |
314 | // ---------------------------------------------------------------------------- |
315 | // showing the dialogs | |
316 | // ---------------------------------------------------------------------------- | |
22cf5fec VZ |
317 | |
318 | bool wxDialog::IsModal() const | |
319 | { | |
b6c588e1 | 320 | return (GetWindowStyleFlag() & wxDIALOG_MODAL) != 0; |
2bda0e17 KB |
321 | } |
322 | ||
b6c588e1 | 323 | bool wxDialog::IsModalShowing() const |
2bda0e17 | 324 | { |
b6c588e1 | 325 | return wxModalDialogs.Find((wxDialog *)this) != NULL; // const_cast |
2bda0e17 KB |
326 | } |
327 | ||
b6c588e1 | 328 | void wxDialog::DoShowModal() |
2bda0e17 | 329 | { |
b6c588e1 | 330 | wxCHECK_RET( !IsModalShowing(), _T("DoShowModal() called twice") ); |
f6bcfd97 | 331 | wxCHECK_RET( IsModal(), _T("can't DoShowModal() modeless dialog") ); |
b6c588e1 VZ |
332 | |
333 | wxModalDialogs.Append(this); | |
334 | ||
335 | wxWindow *parent = GetParent(); | |
336 | ||
f6bcfd97 | 337 | wxWindow* oldFocus = m_oldFocus; |
b6c588e1 | 338 | |
f6bcfd97 BP |
339 | // We have to remember the HWND because we need to check |
340 | // the HWND still exists (oldFocus can be garbage when the dialog | |
341 | // exits, if it has been destroyed) | |
342 | HWND hwndOldFocus = 0; | |
343 | if (oldFocus) | |
344 | hwndOldFocus = (HWND) oldFocus->GetHWND(); | |
b6c588e1 | 345 | |
b0a6bb75 VZ |
346 | // remember where the focus was |
347 | if ( !oldFocus ) | |
b6c588e1 | 348 | { |
b0a6bb75 VZ |
349 | oldFocus = parent; |
350 | if ( parent ) | |
351 | hwndOldFocus = GetHwndOf(parent); | |
352 | } | |
f6bcfd97 | 353 | |
b0a6bb75 VZ |
354 | // disable all other app windows |
355 | wxASSERT_MSG( !m_windowDisabler, _T("disabling windows twice?") ); | |
f6bcfd97 | 356 | |
b0a6bb75 VZ |
357 | m_windowDisabler = new wxWindowDisabler(this); |
358 | ||
359 | // enter the modal loop | |
360 | while ( IsModalShowing() ) | |
361 | { | |
b6c588e1 | 362 | #if wxUSE_THREADS |
b0a6bb75 | 363 | wxMutexGuiLeaveOrEnter(); |
b6c588e1 VZ |
364 | #endif // wxUSE_THREADS |
365 | ||
b0a6bb75 VZ |
366 | while ( !wxTheApp->Pending() && wxTheApp->ProcessIdle() ) |
367 | ; | |
b6c588e1 | 368 | |
b0a6bb75 VZ |
369 | // a message came or no more idle processing to do |
370 | wxTheApp->DoMessage(); | |
b6c588e1 VZ |
371 | } |
372 | ||
b6c588e1 | 373 | // and restore focus |
f6bcfd97 BP |
374 | // Note that this code MUST NOT access the dialog object's data |
375 | // in case the object has been deleted (which will be the case | |
376 | // for a modal dialog that has been destroyed before calling EndModal). | |
377 | if ( oldFocus && (oldFocus != this) && ::IsWindow(hwndOldFocus)) | |
b6c588e1 | 378 | { |
f6bcfd97 BP |
379 | // This is likely to prove that the object still exists |
380 | if (wxFindWinFromHandle((WXHWND) hwndOldFocus) == oldFocus) | |
381 | oldFocus->SetFocus(); | |
b6c588e1 | 382 | } |
2bda0e17 KB |
383 | } |
384 | ||
b6c588e1 | 385 | bool wxDialog::Show(bool show) |
2bda0e17 | 386 | { |
abceee76 | 387 | if ( !show ) |
86ad564e | 388 | { |
b0a6bb75 VZ |
389 | // if we had disabled other app windows, reenable them back now because |
390 | // if they stay disabled Windows will activate another window (one | |
391 | // which is enabled, anyhow) and we will lose activation | |
392 | if ( m_windowDisabler ) | |
86ad564e | 393 | { |
b0a6bb75 VZ |
394 | delete m_windowDisabler; |
395 | m_windowDisabler = NULL; | |
86ad564e JS |
396 | } |
397 | } | |
398 | ||
abceee76 VZ |
399 | // ShowModal() may be called for already shown dialog |
400 | if ( !wxDialogBase::Show(show) && !(show && IsModal()) ) | |
b6c588e1 VZ |
401 | { |
402 | // nothing to do | |
403 | return FALSE; | |
404 | } | |
2bda0e17 | 405 | |
b6c588e1 VZ |
406 | if ( show ) |
407 | { | |
408 | // usually will result in TransferDataToWindow() being called | |
409 | InitDialog(); | |
410 | } | |
2bda0e17 | 411 | |
b6c588e1 VZ |
412 | if ( IsModal() ) |
413 | { | |
414 | if ( show ) | |
415 | { | |
f6bcfd97 BP |
416 | // modal dialog needs a parent window, so try to find one |
417 | if ( !GetParent() ) | |
418 | { | |
419 | wxWindow *parent = wxTheApp->GetTopWindow(); | |
420 | if ( parent && parent != this && parent->IsShown() ) | |
421 | { | |
422 | // use it | |
423 | m_parent = parent; | |
e5f741e5 VZ |
424 | |
425 | // VZ: to make dialog behave properly we should reparent | |
426 | // the dialog for Windows as well - unfortunately, | |
427 | // following the docs for SetParent() results in this | |
428 | // code which plainly doesn't work | |
429 | #if 0 | |
430 | long dwStyle = ::GetWindowLong(GetHwnd(), GWL_STYLE); | |
431 | dwStyle &= ~WS_POPUP; | |
432 | dwStyle |= WS_CHILD; | |
433 | ::SetWindowLong(GetHwnd(), GWL_STYLE, dwStyle); | |
434 | ::SetParent(GetHwnd(), GetHwndOf(parent)); | |
435 | #endif // 0 | |
f6bcfd97 BP |
436 | } |
437 | } | |
438 | ||
b6c588e1 VZ |
439 | DoShowModal(); |
440 | } | |
441 | else // end of modal dialog | |
442 | { | |
443 | // this will cause IsModalShowing() return FALSE and our local | |
444 | // message loop will terminate | |
445 | wxModalDialogs.DeleteObject(this); | |
446 | } | |
447 | } | |
2bda0e17 | 448 | |
b6c588e1 | 449 | return TRUE; |
2bda0e17 KB |
450 | } |
451 | ||
f6bcfd97 | 452 | // a special version for Show(TRUE) for modal dialogs which returns return code |
a23fd0e1 | 453 | int wxDialog::ShowModal() |
2bda0e17 | 454 | { |
f6bcfd97 | 455 | if ( !IsModal() ) |
5e1febfa | 456 | { |
f6bcfd97 | 457 | SetModal(TRUE); |
5e1febfa VZ |
458 | } |
459 | ||
b6c588e1 | 460 | Show(TRUE); |
5e1febfa | 461 | |
b6c588e1 | 462 | return GetReturnCode(); |
2bda0e17 KB |
463 | } |
464 | ||
b6c588e1 VZ |
465 | // NB: this function (surprizingly) may be called for both modal and modeless |
466 | // dialogs and should work for both of them | |
2bda0e17 KB |
467 | void wxDialog::EndModal(int retCode) |
468 | { | |
b6c588e1 | 469 | SetReturnCode(retCode); |
6a088435 | 470 | |
b6c588e1 | 471 | Show(FALSE); |
2bda0e17 KB |
472 | } |
473 | ||
b6c588e1 VZ |
474 | // ---------------------------------------------------------------------------- |
475 | // wxWin event handlers | |
476 | // ---------------------------------------------------------------------------- | |
2bda0e17 KB |
477 | |
478 | // Standard buttons | |
479 | void wxDialog::OnOK(wxCommandEvent& event) | |
480 | { | |
dc1c4b62 VZ |
481 | if ( Validate() && TransferDataFromWindow() ) |
482 | { | |
b6c588e1 | 483 | EndModal(wxID_OK); |
dc1c4b62 | 484 | } |
2bda0e17 KB |
485 | } |
486 | ||
487 | void wxDialog::OnApply(wxCommandEvent& event) | |
488 | { | |
b6c588e1 VZ |
489 | if ( Validate() ) |
490 | TransferDataFromWindow(); | |
491 | ||
492 | // TODO probably need to disable the Apply button until things change again | |
2bda0e17 KB |
493 | } |
494 | ||
495 | void wxDialog::OnCancel(wxCommandEvent& event) | |
496 | { | |
b6c588e1 | 497 | EndModal(wxID_CANCEL); |
2bda0e17 KB |
498 | } |
499 | ||
e3065973 | 500 | void wxDialog::OnCloseWindow(wxCloseEvent& event) |
2bda0e17 | 501 | { |
b6c588e1 | 502 | // We'll send a Cancel message by default, which may close the dialog. |
e3065973 JS |
503 | // Check for looping if the Cancel event handler calls Close(). |
504 | ||
505 | // Note that if a cancel button and handler aren't present in the dialog, | |
506 | // nothing will happen when you close the dialog via the window manager, or | |
b6c588e1 VZ |
507 | // via Close(). We wouldn't want to destroy the dialog by default, since |
508 | // the dialog may have been created on the stack. However, this does mean | |
509 | // that calling dialog->Close() won't delete the dialog unless the handler | |
510 | // for wxID_CANCEL does so. So use Destroy() if you want to be sure to | |
511 | // destroy the dialog. The default OnCancel (above) simply ends a modal | |
512 | // dialog, and hides a modeless dialog. | |
513 | ||
514 | // VZ: this is horrible and MT-unsafe. Can't we reuse some of these global | |
515 | // lists here? don't dare to change it now, but should be done later! | |
2bda0e17 | 516 | static wxList closing; |
bd9d76cb | 517 | |
2bda0e17 | 518 | if ( closing.Member(this) ) |
e3065973 | 519 | return; |
bd9d76cb | 520 | |
2bda0e17 | 521 | closing.Append(this); |
bd9d76cb | 522 | |
387a3b02 JS |
523 | wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL); |
524 | cancelEvent.SetEventObject( this ); | |
e3065973 | 525 | GetEventHandler()->ProcessEvent(cancelEvent); // This may close the dialog |
2bda0e17 KB |
526 | |
527 | closing.DeleteObject(this); | |
e3065973 | 528 | } |
2bda0e17 | 529 | |
e3065973 | 530 | // Destroy the window (delayed, if a managed window) |
a23fd0e1 | 531 | bool wxDialog::Destroy() |
e3065973 | 532 | { |
b6c588e1 VZ |
533 | wxCHECK_MSG( !wxPendingDelete.Member(this), FALSE, |
534 | _T("wxDialog destroyed twice") ); | |
535 | ||
e3065973 | 536 | wxPendingDelete.Append(this); |
2bda0e17 | 537 | |
b6c588e1 | 538 | return TRUE; |
94b49b93 JS |
539 | } |
540 | ||
2bda0e17 KB |
541 | void wxDialog::OnSysColourChanged(wxSysColourChangedEvent& event) |
542 | { | |
1f112209 | 543 | #if wxUSE_CTL3D |
b6c588e1 | 544 | Ctl3dColorChange(); |
2bda0e17 | 545 | #else |
b6c588e1 VZ |
546 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE)); |
547 | Refresh(); | |
2bda0e17 | 548 | #endif |
68ad65f8 | 549 | } |
42e69d6b VZ |
550 | |
551 | // --------------------------------------------------------------------------- | |
552 | // dialog window proc | |
553 | // --------------------------------------------------------------------------- | |
554 | ||
555 | long wxDialog::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) | |
556 | { | |
557 | long rc = 0; | |
558 | bool processed = FALSE; | |
559 | ||
560 | switch ( message ) | |
561 | { | |
b0a6bb75 | 562 | #if 0 // now that we got owner window right it doesn't seem to be needed |
5e1febfa VZ |
563 | case WM_ACTIVATE: |
564 | switch ( LOWORD(wParam) ) | |
565 | { | |
566 | case WA_ACTIVE: | |
567 | case WA_CLICKACTIVE: | |
568 | if ( IsModalShowing() && GetParent() ) | |
569 | { | |
570 | // bring the owner window to top as the standard dialog | |
571 | // boxes do | |
572 | if ( !::SetWindowPos | |
573 | ( | |
574 | GetHwndOf(GetParent()), | |
575 | GetHwnd(), | |
576 | 0, 0, | |
577 | 0, 0, | |
578 | SWP_NOACTIVATE | | |
579 | SWP_NOMOVE | | |
580 | SWP_NOSIZE | |
581 | ) ) | |
582 | { | |
f6bcfd97 | 583 | wxLogLastError(wxT("SetWindowPos(SWP_NOACTIVATE)")); |
5e1febfa VZ |
584 | } |
585 | } | |
586 | // fall through to process it normally as well | |
587 | } | |
588 | break; | |
b0a6bb75 | 589 | #endif // 0 |
5e1febfa | 590 | |
42e69d6b VZ |
591 | case WM_CLOSE: |
592 | // if we can't close, tell the system that we processed the | |
593 | // message - otherwise it would close us | |
594 | processed = !Close(); | |
595 | break; | |
abceee76 VZ |
596 | |
597 | case WM_SETCURSOR: | |
598 | // we want to override the busy cursor for modal dialogs: | |
599 | // typically, wxBeginBusyCursor() is called and then a modal dialog | |
bfbd6dc1 | 600 | // is shown, but the modal dialog shouldn't have hourglass cursor |
d1477745 | 601 | if ( IsModalShowing() && wxIsBusy() ) |
abceee76 | 602 | { |
bfbd6dc1 VZ |
603 | // set our cursor for all windows (but see below) |
604 | wxCursor cursor = m_cursor; | |
605 | if ( !cursor.Ok() ) | |
606 | cursor = wxCURSOR_ARROW; | |
abceee76 | 607 | |
bfbd6dc1 VZ |
608 | ::SetCursor(GetHcursorOf(cursor)); |
609 | ||
610 | // in any case, stop here and don't let wxWindow process this | |
611 | // message (it would set the busy cursor) | |
abceee76 | 612 | processed = TRUE; |
bfbd6dc1 VZ |
613 | |
614 | // but return FALSE to tell the child window (if the event | |
615 | // comes from one of them and not from ourselves) that it can | |
616 | // set its own cursor if it has one: thus, standard controls | |
617 | // (e.g. text ctrl) still have correct cursors in a dialog | |
618 | // invoked while wxIsBusy() | |
619 | rc = FALSE; | |
abceee76 | 620 | } |
bfbd6dc1 | 621 | break; |
42e69d6b VZ |
622 | } |
623 | ||
624 | if ( !processed ) | |
625 | rc = wxWindow::MSWWindowProc(message, wParam, lParam); | |
626 | ||
627 | return rc; | |
628 | } | |
b6c588e1 VZ |
629 | |
630 | #if wxUSE_CTL3D | |
631 | ||
632 | // Define for each class of dialog and control | |
633 | WXHBRUSH wxDialog::OnCtlColor(WXHDC WXUNUSED(pDC), | |
634 | WXHWND WXUNUSED(pWnd), | |
635 | WXUINT WXUNUSED(nCtlColor), | |
636 | WXUINT message, | |
637 | WXWPARAM wParam, | |
638 | WXLPARAM lParam) | |
639 | { | |
640 | return (WXHBRUSH)Ctl3dCtlColorEx(message, wParam, lParam); | |
641 | } | |
642 | ||
643 | #endif // wxUSE_CTL3D | |
644 |