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