]>
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 | ||
a23fd0e1 | 99 | wxDialog::wxDialog() |
2bda0e17 | 100 | { |
52a07708 | 101 | m_oldFocus = (wxWindow *)NULL; |
b6c588e1 | 102 | m_isShown = FALSE; |
2bda0e17 | 103 | |
b6c588e1 | 104 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE)); |
2bda0e17 KB |
105 | } |
106 | ||
debe6624 | 107 | bool wxDialog::Create(wxWindow *parent, wxWindowID id, |
462e2437 VZ |
108 | const wxString& title, |
109 | const wxPoint& pos, | |
110 | const wxSize& size, | |
111 | long style, | |
112 | const wxString& name) | |
2bda0e17 | 113 | { |
abceee76 VZ |
114 | m_oldFocus = FindFocus(); |
115 | ||
462e2437 VZ |
116 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE)); |
117 | SetName(name); | |
bd9d76cb | 118 | |
f6bcfd97 | 119 | wxTopLevelWindows.Append(this); |
2bda0e17 | 120 | |
462e2437 | 121 | // windowFont = wxTheFontList->FindOrCreateFont(11, wxSWISS, wxNORMAL, wxNORMAL); |
2bda0e17 | 122 | |
462e2437 | 123 | if (parent) parent->AddChild(this); |
2bda0e17 | 124 | |
462e2437 VZ |
125 | if ( id == -1 ) |
126 | m_windowId = (int)NewControlId(); | |
127 | else | |
128 | m_windowId = id; | |
129 | ||
130 | int x = pos.x; | |
131 | int y = pos.y; | |
132 | int width = size.x; | |
133 | int height = size.y; | |
134 | ||
b6c588e1 VZ |
135 | if (x < 0) |
136 | x = wxDIALOG_DEFAULT_X; | |
137 | if (y < 0) | |
138 | y = wxDIALOG_DEFAULT_Y; | |
462e2437 VZ |
139 | |
140 | m_windowStyle = style; | |
141 | ||
142 | m_isShown = FALSE; | |
462e2437 VZ |
143 | |
144 | if (width < 0) | |
b6c588e1 | 145 | width = wxDIALOG_DEFAULT_WIDTH; |
462e2437 | 146 | if (height < 0) |
b6c588e1 | 147 | height = wxDIALOG_DEFAULT_HEIGHT; |
462e2437 | 148 | |
706bb5f9 JS |
149 | // All dialogs should really have this style |
150 | m_windowStyle |= wxTAB_TRAVERSAL; | |
151 | ||
462e2437 VZ |
152 | WXDWORD extendedStyle = MakeExtendedStyle(m_windowStyle); |
153 | if (m_windowStyle & wxSTAY_ON_TOP) | |
154 | extendedStyle |= WS_EX_TOPMOST; | |
155 | ||
156 | // Allows creation of dialogs with & without captions under MSWindows, | |
157 | // resizeable or not (but a resizeable dialog always has caption - | |
158 | // otherwise it would look too strange) | |
837e5743 | 159 | const wxChar *dlg; |
257bf510 | 160 | if ( style & wxRESIZE_BORDER ) |
223d09f6 | 161 | dlg = wxT("wxResizeableDialog"); |
462e2437 | 162 | else if ( style & wxCAPTION ) |
223d09f6 | 163 | dlg = wxT("wxCaptionDialog"); |
462e2437 | 164 | else |
223d09f6 | 165 | dlg = wxT("wxNoCaptionDialog"); |
462e2437 VZ |
166 | MSWCreate(m_windowId, parent, NULL, this, NULL, |
167 | x, y, width, height, | |
168 | 0, // style is not used if we have dlg template | |
169 | dlg, | |
170 | extendedStyle); | |
2bda0e17 | 171 | |
462e2437 | 172 | HWND hwnd = (HWND)GetHWND(); |
2bda0e17 | 173 | |
462e2437 VZ |
174 | if ( !hwnd ) |
175 | { | |
f6bcfd97 | 176 | wxFAIL_MSG(_("Failed to create dialog. You probably forgot to include wx/msw/wx.rc in your resources.")); |
2bda0e17 | 177 | |
462e2437 VZ |
178 | return FALSE; |
179 | } | |
2bda0e17 | 180 | |
462e2437 | 181 | SubclassWin(GetHWND()); |
bd9d76cb | 182 | |
462e2437 VZ |
183 | SetWindowText(hwnd, title); |
184 | SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT)); | |
2bda0e17 | 185 | |
462e2437 | 186 | return TRUE; |
2bda0e17 KB |
187 | } |
188 | ||
debe6624 | 189 | void wxDialog::SetModal(bool flag) |
2bda0e17 | 190 | { |
b6c588e1 VZ |
191 | if ( flag ) |
192 | { | |
193 | m_windowStyle |= wxDIALOG_MODAL; | |
194 | ||
195 | wxModelessWindows.DeleteObject(this); | |
196 | } | |
197 | else | |
198 | { | |
199 | m_windowStyle &= ~wxDIALOG_MODAL; | |
200 | ||
201 | wxModelessWindows.Append(this); | |
202 | } | |
2bda0e17 KB |
203 | } |
204 | ||
205 | wxDialog::~wxDialog() | |
206 | { | |
b6c588e1 | 207 | m_isBeingDeleted = TRUE; |
2bda0e17 | 208 | |
b6c588e1 | 209 | wxTopLevelWindows.DeleteObject(this); |
2bda0e17 | 210 | |
abceee76 VZ |
211 | // this will call BringWindowToTop() if necessary to bring back our parent |
212 | // window to top | |
b6c588e1 | 213 | Show(FALSE); |
edccf428 | 214 | |
b6c588e1 VZ |
215 | if ( !IsModal() ) |
216 | wxModelessWindows.DeleteObject(this); | |
2bda0e17 | 217 | |
b6c588e1 VZ |
218 | // If this is the last top-level window, exit. |
219 | if ( wxTheApp && (wxTopLevelWindows.Number() == 0) ) | |
2bda0e17 | 220 | { |
b6c588e1 VZ |
221 | wxTheApp->SetTopWindow(NULL); |
222 | ||
223 | if ( wxTheApp->GetExitOnFrameDelete() ) | |
224 | { | |
225 | ::PostQuitMessage(0); | |
226 | } | |
2bda0e17 | 227 | } |
2bda0e17 KB |
228 | } |
229 | ||
b6c588e1 VZ |
230 | // ---------------------------------------------------------------------------- |
231 | // kbd handling | |
232 | // ---------------------------------------------------------------------------- | |
233 | ||
2bda0e17 KB |
234 | // By default, pressing escape cancels the dialog |
235 | void wxDialog::OnCharHook(wxKeyEvent& event) | |
236 | { | |
cbc66a27 | 237 | if (GetHWND()) |
2bda0e17 | 238 | { |
cbc66a27 VZ |
239 | // "Esc" works as an accelerator for the "Cancel" button, but it |
240 | // shouldn't close the dialog which doesn't have any cancel button | |
241 | if ( (event.m_keyCode == WXK_ESCAPE) && FindWindow(wxID_CANCEL) ) | |
242 | { | |
243 | wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL); | |
244 | cancelEvent.SetEventObject( this ); | |
245 | GetEventHandler()->ProcessEvent(cancelEvent); | |
246 | ||
247 | // ensure that there is another message for this window so the | |
248 | // ShowModal loop will exit and won't get stuck in GetMessage(). | |
249 | ::PostMessage(GetHwnd(), WM_NULL, 0, 0); | |
250 | ||
251 | return; | |
252 | } | |
2bda0e17 | 253 | } |
cbc66a27 VZ |
254 | |
255 | // We didn't process this event. | |
256 | event.Skip(); | |
2bda0e17 KB |
257 | } |
258 | ||
b6c588e1 VZ |
259 | // ---------------------------------------------------------------------------- |
260 | // Windows dialog boxes can't be iconized | |
261 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 262 | |
debe6624 | 263 | void wxDialog::Iconize(bool WXUNUSED(iconize)) |
2bda0e17 | 264 | { |
2bda0e17 KB |
265 | } |
266 | ||
a23fd0e1 | 267 | bool wxDialog::IsIconized() const |
2bda0e17 | 268 | { |
b6c588e1 | 269 | return FALSE; |
2bda0e17 KB |
270 | } |
271 | ||
b6c588e1 VZ |
272 | // ---------------------------------------------------------------------------- |
273 | // size/position handling | |
274 | // ---------------------------------------------------------------------------- | |
275 | ||
721b32e0 | 276 | void wxDialog::DoSetClientSize(int width, int height) |
2bda0e17 | 277 | { |
b6c588e1 VZ |
278 | HWND hWnd = (HWND) GetHWND(); |
279 | RECT rect; | |
280 | ::GetClientRect(hWnd, &rect); | |
2bda0e17 | 281 | |
b6c588e1 VZ |
282 | RECT rect2; |
283 | GetWindowRect(hWnd, &rect2); | |
2bda0e17 | 284 | |
b6c588e1 VZ |
285 | // Find the difference between the entire window (title bar and all) |
286 | // and the client area; add this to the new client size to move the | |
287 | // window | |
288 | int actual_width = rect2.right - rect2.left - rect.right + width; | |
289 | int actual_height = rect2.bottom - rect2.top - rect.bottom + height; | |
2bda0e17 | 290 | |
b6c588e1 | 291 | MoveWindow(hWnd, rect2.left, rect2.top, actual_width, actual_height, TRUE); |
debe6624 | 292 | |
b6c588e1 VZ |
293 | wxSizeEvent event(wxSize(actual_width, actual_height), m_windowId); |
294 | event.SetEventObject( this ); | |
295 | GetEventHandler()->ProcessEvent(event); | |
2bda0e17 KB |
296 | } |
297 | ||
b6c588e1 | 298 | void wxDialog::DoGetPosition(int *x, int *y) const |
2bda0e17 | 299 | { |
b6c588e1 VZ |
300 | RECT rect; |
301 | GetWindowRect(GetHwnd(), &rect); | |
2bda0e17 | 302 | |
b6c588e1 VZ |
303 | if ( x ) |
304 | *x = rect.left; | |
305 | if ( y ) | |
306 | *y = rect.top; | |
2bda0e17 KB |
307 | } |
308 | ||
b6c588e1 VZ |
309 | // ---------------------------------------------------------------------------- |
310 | // showing the dialogs | |
311 | // ---------------------------------------------------------------------------- | |
22cf5fec VZ |
312 | |
313 | bool wxDialog::IsModal() const | |
314 | { | |
b6c588e1 | 315 | return (GetWindowStyleFlag() & wxDIALOG_MODAL) != 0; |
2bda0e17 KB |
316 | } |
317 | ||
b6c588e1 | 318 | bool wxDialog::IsModalShowing() const |
2bda0e17 | 319 | { |
b6c588e1 | 320 | return wxModalDialogs.Find((wxDialog *)this) != NULL; // const_cast |
2bda0e17 KB |
321 | } |
322 | ||
b6c588e1 | 323 | void wxDialog::DoShowModal() |
2bda0e17 | 324 | { |
b6c588e1 | 325 | wxCHECK_RET( !IsModalShowing(), _T("DoShowModal() called twice") ); |
f6bcfd97 | 326 | wxCHECK_RET( IsModal(), _T("can't DoShowModal() modeless dialog") ); |
b6c588e1 VZ |
327 | |
328 | wxModalDialogs.Append(this); | |
329 | ||
330 | wxWindow *parent = GetParent(); | |
331 | ||
f6bcfd97 | 332 | wxWindow* oldFocus = m_oldFocus; |
b6c588e1 | 333 | |
f6bcfd97 BP |
334 | // We have to remember the HWND because we need to check |
335 | // the HWND still exists (oldFocus can be garbage when the dialog | |
336 | // exits, if it has been destroyed) | |
337 | HWND hwndOldFocus = 0; | |
338 | if (oldFocus) | |
339 | hwndOldFocus = (HWND) oldFocus->GetHWND(); | |
b6c588e1 | 340 | |
f6bcfd97 | 341 | // inside this block, all app windows are disabled |
b6c588e1 | 342 | { |
f6bcfd97 BP |
343 | wxWindowDisabler wd(this); |
344 | ||
345 | // remember where the focus was | |
346 | if ( !oldFocus ) | |
347 | { | |
348 | oldFocus = parent; | |
349 | if (parent) | |
350 | hwndOldFocus = (HWND) parent->GetHWND(); | |
351 | } | |
352 | ||
353 | // enter the modal loop | |
354 | while ( IsModalShowing() ) | |
355 | { | |
b6c588e1 | 356 | #if wxUSE_THREADS |
f6bcfd97 | 357 | wxMutexGuiLeaveOrEnter(); |
b6c588e1 VZ |
358 | #endif // wxUSE_THREADS |
359 | ||
f6bcfd97 BP |
360 | while ( !wxTheApp->Pending() && wxTheApp->ProcessIdle() ) |
361 | ; | |
b6c588e1 | 362 | |
f6bcfd97 BP |
363 | // a message came or no more idle processing to do |
364 | wxTheApp->DoMessage(); | |
365 | } | |
b6c588e1 VZ |
366 | } |
367 | ||
f6bcfd97 BP |
368 | #ifdef __WIN32__ |
369 | if ( parent ) | |
370 | ::SetActiveWindow(GetHwndOf(parent)); | |
371 | #endif // __WIN32__ | |
b6c588e1 VZ |
372 | |
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 VZ |
387 | // The following is required when the parent has been disabled, (modal |
388 | // dialogs, or modeless dialogs with disabling such as wxProgressDialog). | |
389 | // Otherwise the parent disappears behind other windows when the dialog is | |
390 | // hidden. | |
391 | if ( !show ) | |
86ad564e | 392 | { |
abceee76 VZ |
393 | wxWindow *parent = GetParent(); |
394 | if ( parent ) | |
86ad564e | 395 | { |
abceee76 | 396 | ::BringWindowToTop(GetHwndOf(parent)); |
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; | |
425 | } | |
426 | } | |
427 | ||
b6c588e1 VZ |
428 | DoShowModal(); |
429 | } | |
430 | else // end of modal dialog | |
431 | { | |
432 | // this will cause IsModalShowing() return FALSE and our local | |
433 | // message loop will terminate | |
434 | wxModalDialogs.DeleteObject(this); | |
435 | } | |
436 | } | |
2bda0e17 | 437 | |
b6c588e1 | 438 | return TRUE; |
2bda0e17 KB |
439 | } |
440 | ||
f6bcfd97 | 441 | // a special version for Show(TRUE) for modal dialogs which returns return code |
a23fd0e1 | 442 | int wxDialog::ShowModal() |
2bda0e17 | 443 | { |
f6bcfd97 | 444 | if ( !IsModal() ) |
5e1febfa | 445 | { |
f6bcfd97 | 446 | SetModal(TRUE); |
5e1febfa VZ |
447 | } |
448 | ||
b6c588e1 | 449 | Show(TRUE); |
5e1febfa | 450 | |
b6c588e1 | 451 | return GetReturnCode(); |
2bda0e17 KB |
452 | } |
453 | ||
b6c588e1 VZ |
454 | // NB: this function (surprizingly) may be called for both modal and modeless |
455 | // dialogs and should work for both of them | |
2bda0e17 KB |
456 | void wxDialog::EndModal(int retCode) |
457 | { | |
b6c588e1 | 458 | SetReturnCode(retCode); |
6a088435 | 459 | |
b6c588e1 | 460 | Show(FALSE); |
2bda0e17 KB |
461 | } |
462 | ||
b6c588e1 VZ |
463 | // ---------------------------------------------------------------------------- |
464 | // wxWin event handlers | |
465 | // ---------------------------------------------------------------------------- | |
2bda0e17 KB |
466 | |
467 | // Standard buttons | |
468 | void wxDialog::OnOK(wxCommandEvent& event) | |
469 | { | |
dc1c4b62 VZ |
470 | if ( Validate() && TransferDataFromWindow() ) |
471 | { | |
b6c588e1 | 472 | EndModal(wxID_OK); |
dc1c4b62 | 473 | } |
2bda0e17 KB |
474 | } |
475 | ||
476 | void wxDialog::OnApply(wxCommandEvent& event) | |
477 | { | |
b6c588e1 VZ |
478 | if ( Validate() ) |
479 | TransferDataFromWindow(); | |
480 | ||
481 | // TODO probably need to disable the Apply button until things change again | |
2bda0e17 KB |
482 | } |
483 | ||
484 | void wxDialog::OnCancel(wxCommandEvent& event) | |
485 | { | |
b6c588e1 | 486 | EndModal(wxID_CANCEL); |
2bda0e17 KB |
487 | } |
488 | ||
e3065973 | 489 | void wxDialog::OnCloseWindow(wxCloseEvent& event) |
2bda0e17 | 490 | { |
b6c588e1 | 491 | // We'll send a Cancel message by default, which may close the dialog. |
e3065973 JS |
492 | // Check for looping if the Cancel event handler calls Close(). |
493 | ||
494 | // Note that if a cancel button and handler aren't present in the dialog, | |
495 | // nothing will happen when you close the dialog via the window manager, or | |
b6c588e1 VZ |
496 | // via Close(). We wouldn't want to destroy the dialog by default, since |
497 | // the dialog may have been created on the stack. However, this does mean | |
498 | // that calling dialog->Close() won't delete the dialog unless the handler | |
499 | // for wxID_CANCEL does so. So use Destroy() if you want to be sure to | |
500 | // destroy the dialog. The default OnCancel (above) simply ends a modal | |
501 | // dialog, and hides a modeless dialog. | |
502 | ||
503 | // VZ: this is horrible and MT-unsafe. Can't we reuse some of these global | |
504 | // lists here? don't dare to change it now, but should be done later! | |
2bda0e17 | 505 | static wxList closing; |
bd9d76cb | 506 | |
2bda0e17 | 507 | if ( closing.Member(this) ) |
e3065973 | 508 | return; |
bd9d76cb | 509 | |
2bda0e17 | 510 | closing.Append(this); |
bd9d76cb | 511 | |
387a3b02 JS |
512 | wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL); |
513 | cancelEvent.SetEventObject( this ); | |
e3065973 | 514 | GetEventHandler()->ProcessEvent(cancelEvent); // This may close the dialog |
2bda0e17 KB |
515 | |
516 | closing.DeleteObject(this); | |
e3065973 | 517 | } |
2bda0e17 | 518 | |
e3065973 | 519 | // Destroy the window (delayed, if a managed window) |
a23fd0e1 | 520 | bool wxDialog::Destroy() |
e3065973 | 521 | { |
b6c588e1 VZ |
522 | wxCHECK_MSG( !wxPendingDelete.Member(this), FALSE, |
523 | _T("wxDialog destroyed twice") ); | |
524 | ||
e3065973 | 525 | wxPendingDelete.Append(this); |
2bda0e17 | 526 | |
b6c588e1 | 527 | return TRUE; |
94b49b93 JS |
528 | } |
529 | ||
2bda0e17 KB |
530 | void wxDialog::OnSysColourChanged(wxSysColourChangedEvent& event) |
531 | { | |
1f112209 | 532 | #if wxUSE_CTL3D |
b6c588e1 | 533 | Ctl3dColorChange(); |
2bda0e17 | 534 | #else |
b6c588e1 VZ |
535 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE)); |
536 | Refresh(); | |
2bda0e17 | 537 | #endif |
68ad65f8 | 538 | } |
42e69d6b VZ |
539 | |
540 | // --------------------------------------------------------------------------- | |
541 | // dialog window proc | |
542 | // --------------------------------------------------------------------------- | |
543 | ||
544 | long wxDialog::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) | |
545 | { | |
546 | long rc = 0; | |
547 | bool processed = FALSE; | |
548 | ||
549 | switch ( message ) | |
550 | { | |
5e1febfa VZ |
551 | case WM_ACTIVATE: |
552 | switch ( LOWORD(wParam) ) | |
553 | { | |
554 | case WA_ACTIVE: | |
555 | case WA_CLICKACTIVE: | |
556 | if ( IsModalShowing() && GetParent() ) | |
557 | { | |
558 | // bring the owner window to top as the standard dialog | |
559 | // boxes do | |
560 | if ( !::SetWindowPos | |
561 | ( | |
562 | GetHwndOf(GetParent()), | |
563 | GetHwnd(), | |
564 | 0, 0, | |
565 | 0, 0, | |
566 | SWP_NOACTIVATE | | |
567 | SWP_NOMOVE | | |
568 | SWP_NOSIZE | |
569 | ) ) | |
570 | { | |
f6bcfd97 | 571 | wxLogLastError(wxT("SetWindowPos(SWP_NOACTIVATE)")); |
5e1febfa VZ |
572 | } |
573 | } | |
574 | // fall through to process it normally as well | |
575 | } | |
576 | break; | |
577 | ||
42e69d6b VZ |
578 | case WM_CLOSE: |
579 | // if we can't close, tell the system that we processed the | |
580 | // message - otherwise it would close us | |
581 | processed = !Close(); | |
582 | break; | |
abceee76 VZ |
583 | |
584 | case WM_SETCURSOR: | |
585 | // we want to override the busy cursor for modal dialogs: | |
586 | // typically, wxBeginBusyCursor() is called and then a modal dialog | |
bfbd6dc1 | 587 | // is shown, but the modal dialog shouldn't have hourglass cursor |
d1477745 | 588 | if ( IsModalShowing() && wxIsBusy() ) |
abceee76 | 589 | { |
bfbd6dc1 VZ |
590 | // set our cursor for all windows (but see below) |
591 | wxCursor cursor = m_cursor; | |
592 | if ( !cursor.Ok() ) | |
593 | cursor = wxCURSOR_ARROW; | |
abceee76 | 594 | |
bfbd6dc1 VZ |
595 | ::SetCursor(GetHcursorOf(cursor)); |
596 | ||
597 | // in any case, stop here and don't let wxWindow process this | |
598 | // message (it would set the busy cursor) | |
abceee76 | 599 | processed = TRUE; |
bfbd6dc1 VZ |
600 | |
601 | // but return FALSE to tell the child window (if the event | |
602 | // comes from one of them and not from ourselves) that it can | |
603 | // set its own cursor if it has one: thus, standard controls | |
604 | // (e.g. text ctrl) still have correct cursors in a dialog | |
605 | // invoked while wxIsBusy() | |
606 | rc = FALSE; | |
abceee76 | 607 | } |
bfbd6dc1 | 608 | break; |
42e69d6b VZ |
609 | } |
610 | ||
611 | if ( !processed ) | |
612 | rc = wxWindow::MSWWindowProc(message, wParam, lParam); | |
613 | ||
614 | return rc; | |
615 | } | |
b6c588e1 VZ |
616 | |
617 | #if wxUSE_CTL3D | |
618 | ||
619 | // Define for each class of dialog and control | |
620 | WXHBRUSH wxDialog::OnCtlColor(WXHDC WXUNUSED(pDC), | |
621 | WXHWND WXUNUSED(pWnd), | |
622 | WXUINT WXUNUSED(nCtlColor), | |
623 | WXUINT message, | |
624 | WXWPARAM wParam, | |
625 | WXLPARAM lParam) | |
626 | { | |
627 | return (WXHBRUSH)Ctl3dCtlColorEx(message, wParam, lParam); | |
628 | } | |
629 | ||
630 | #endif // wxUSE_CTL3D | |
631 |