]> git.saurik.com Git - wxWidgets.git/blame - src/msw/dialog.cpp
new wxStringTokenizer
[wxWidgets.git] / src / msw / dialog.cpp
CommitLineData
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 65extern wxList WXDLLEXPORT wxPendingDelete;
2bda0e17 66
b6c588e1
VZ
67// all frames and modeless dialogs - not static, used in frame.cpp, mdi.cpp &c
68wxWindowList wxModelessWindows;
69
70// all modal dialogs currently shown
71static wxWindowList wxModalDialogs;
72
73// ----------------------------------------------------------------------------
74// wxWin macros
75// ----------------------------------------------------------------------------
76
1b6452df
VZ
77IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxPanel)
78
79BEGIN_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)
89END_EVENT_TABLE()
2bda0e17 90
b6c588e1
VZ
91// ============================================================================
92// implementation
93// ============================================================================
94
95// ----------------------------------------------------------------------------
96// wxDialog construction
97// ----------------------------------------------------------------------------
98
a23fd0e1 99wxDialog::wxDialog()
2bda0e17 100{
b6c588e1 101 m_isShown = FALSE;
2bda0e17 102
b6c588e1 103 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
2bda0e17
KB
104}
105
debe6624 106bool wxDialog::Create(wxWindow *parent, wxWindowID id,
462e2437
VZ
107 const wxString& title,
108 const wxPoint& pos,
109 const wxSize& size,
110 long style,
111 const wxString& name)
2bda0e17 112{
462e2437
VZ
113 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
114 SetName(name);
bd9d76cb 115
462e2437
VZ
116 if (!parent)
117 wxTopLevelWindows.Append(this);
2bda0e17 118
462e2437 119 // windowFont = wxTheFontList->FindOrCreateFont(11, wxSWISS, wxNORMAL, wxNORMAL);
2bda0e17 120
462e2437 121 if (parent) parent->AddChild(this);
2bda0e17 122
462e2437
VZ
123 if ( id == -1 )
124 m_windowId = (int)NewControlId();
125 else
126 m_windowId = id;
127
128 int x = pos.x;
129 int y = pos.y;
130 int width = size.x;
131 int height = size.y;
132
b6c588e1
VZ
133 if (x < 0)
134 x = wxDIALOG_DEFAULT_X;
135 if (y < 0)
136 y = wxDIALOG_DEFAULT_Y;
462e2437
VZ
137
138 m_windowStyle = style;
139
140 m_isShown = FALSE;
462e2437
VZ
141
142 if (width < 0)
b6c588e1 143 width = wxDIALOG_DEFAULT_WIDTH;
462e2437 144 if (height < 0)
b6c588e1 145 height = wxDIALOG_DEFAULT_HEIGHT;
462e2437 146
706bb5f9
JS
147 // All dialogs should really have this style
148 m_windowStyle |= wxTAB_TRAVERSAL;
149
462e2437
VZ
150 WXDWORD extendedStyle = MakeExtendedStyle(m_windowStyle);
151 if (m_windowStyle & wxSTAY_ON_TOP)
152 extendedStyle |= WS_EX_TOPMOST;
153
154 // Allows creation of dialogs with & without captions under MSWindows,
155 // resizeable or not (but a resizeable dialog always has caption -
156 // otherwise it would look too strange)
837e5743 157 const wxChar *dlg;
257bf510 158 if ( style & wxRESIZE_BORDER )
223d09f6 159 dlg = wxT("wxResizeableDialog");
462e2437 160 else if ( style & wxCAPTION )
223d09f6 161 dlg = wxT("wxCaptionDialog");
462e2437 162 else
223d09f6 163 dlg = wxT("wxNoCaptionDialog");
462e2437
VZ
164 MSWCreate(m_windowId, parent, NULL, this, NULL,
165 x, y, width, height,
166 0, // style is not used if we have dlg template
167 dlg,
168 extendedStyle);
2bda0e17 169
462e2437 170 HWND hwnd = (HWND)GetHWND();
2bda0e17 171
462e2437
VZ
172 if ( !hwnd )
173 {
68ad65f8 174 wxLogError(_("Failed to create dialog."));
2bda0e17 175
462e2437
VZ
176 return FALSE;
177 }
2bda0e17 178
462e2437 179 SubclassWin(GetHWND());
bd9d76cb 180
462e2437
VZ
181 SetWindowText(hwnd, title);
182 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
2bda0e17 183
462e2437 184 return TRUE;
2bda0e17
KB
185}
186
debe6624 187void wxDialog::SetModal(bool flag)
2bda0e17 188{
b6c588e1
VZ
189 if ( flag )
190 {
191 m_windowStyle |= wxDIALOG_MODAL;
192
193 wxModelessWindows.DeleteObject(this);
194 }
195 else
196 {
197 m_windowStyle &= ~wxDIALOG_MODAL;
198
199 wxModelessWindows.Append(this);
200 }
2bda0e17
KB
201}
202
203wxDialog::~wxDialog()
204{
b6c588e1 205 m_isBeingDeleted = TRUE;
2bda0e17 206
b6c588e1 207 wxTopLevelWindows.DeleteObject(this);
2bda0e17 208
b6c588e1 209 Show(FALSE);
edccf428 210
b6c588e1
VZ
211 // VZ: this is bogus and breaks focus handling - it won't be returned to
212 // the window which had it previosuly if we do this
1b6452df 213#if 0
b6c588e1
VZ
214 if (m_modalShowing)
215 {
216 // For some reason, wxWindows can activate another task altogether
217 // when a frame is destroyed after a modal dialog has been invoked.
218 // Try to bring the parent to the top.
219 // dfgg: I moved this following line from end of function -
220 // must not call if another window is on top!!
221 // This can often happen with Close() and delayed deleting
222 if (GetParent() && GetParent()->GetHWND())
223 ::BringWindowToTop((HWND) GetParent()->GetHWND());
224 }
2bda0e17 225
b6c588e1
VZ
226 m_modalShowing = FALSE;
227#endif // 0
2bda0e17 228
b6c588e1
VZ
229 if ( !IsModal() )
230 wxModelessWindows.DeleteObject(this);
2bda0e17 231
b6c588e1
VZ
232 // If this is the last top-level window, exit.
233 if ( wxTheApp && (wxTopLevelWindows.Number() == 0) )
2bda0e17 234 {
b6c588e1
VZ
235 wxTheApp->SetTopWindow(NULL);
236
237 if ( wxTheApp->GetExitOnFrameDelete() )
238 {
239 ::PostQuitMessage(0);
240 }
2bda0e17 241 }
2bda0e17
KB
242}
243
b6c588e1
VZ
244// ----------------------------------------------------------------------------
245// kbd handling
246// ----------------------------------------------------------------------------
247
2bda0e17
KB
248// By default, pressing escape cancels the dialog
249void wxDialog::OnCharHook(wxKeyEvent& event)
250{
251 if (GetHWND())
252 {
253 if (event.m_keyCode == WXK_ESCAPE)
254 {
2a47d3c1
JS
255 // Behaviour changed in 2.0: we'll send a Cancel message
256 // to the dialog instead of Close.
257 wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
258 cancelEvent.SetEventObject( this );
259 GetEventHandler()->ProcessEvent(cancelEvent);
2bda0e17 260
995a594a
RD
261 // ensure that there is another message for this window so the
262 // ShowModal loop will exit and won't get stuck in GetMessage().
263 ::PostMessage(GetHwnd(), WM_NULL, 0, 0);
2a47d3c1 264 return;
2bda0e17
KB
265 }
266 }
267 // We didn't process this event.
268 event.Skip();
269}
270
b6c588e1
VZ
271// ----------------------------------------------------------------------------
272// Windows dialog boxes can't be iconized
273// ----------------------------------------------------------------------------
2bda0e17 274
debe6624 275void wxDialog::Iconize(bool WXUNUSED(iconize))
2bda0e17 276{
2bda0e17
KB
277}
278
a23fd0e1 279bool wxDialog::IsIconized() const
2bda0e17 280{
b6c588e1 281 return FALSE;
2bda0e17
KB
282}
283
b6c588e1
VZ
284// ----------------------------------------------------------------------------
285// size/position handling
286// ----------------------------------------------------------------------------
287
721b32e0 288void wxDialog::DoSetClientSize(int width, int height)
2bda0e17 289{
b6c588e1
VZ
290 HWND hWnd = (HWND) GetHWND();
291 RECT rect;
292 ::GetClientRect(hWnd, &rect);
2bda0e17 293
b6c588e1
VZ
294 RECT rect2;
295 GetWindowRect(hWnd, &rect2);
2bda0e17 296
b6c588e1
VZ
297 // Find the difference between the entire window (title bar and all)
298 // and the client area; add this to the new client size to move the
299 // window
300 int actual_width = rect2.right - rect2.left - rect.right + width;
301 int actual_height = rect2.bottom - rect2.top - rect.bottom + height;
2bda0e17 302
b6c588e1 303 MoveWindow(hWnd, rect2.left, rect2.top, actual_width, actual_height, TRUE);
debe6624 304
b6c588e1
VZ
305 wxSizeEvent event(wxSize(actual_width, actual_height), m_windowId);
306 event.SetEventObject( this );
307 GetEventHandler()->ProcessEvent(event);
2bda0e17
KB
308}
309
b6c588e1 310void wxDialog::DoGetPosition(int *x, int *y) const
2bda0e17 311{
b6c588e1
VZ
312 RECT rect;
313 GetWindowRect(GetHwnd(), &rect);
2bda0e17 314
b6c588e1
VZ
315 if ( x )
316 *x = rect.left;
317 if ( y )
318 *y = rect.top;
2bda0e17
KB
319}
320
b6c588e1
VZ
321// ----------------------------------------------------------------------------
322// showing the dialogs
323// ----------------------------------------------------------------------------
22cf5fec
VZ
324
325bool wxDialog::IsModal() const
326{
b6c588e1 327 return (GetWindowStyleFlag() & wxDIALOG_MODAL) != 0;
2bda0e17
KB
328}
329
b6c588e1
VZ
330// VZ: this is the old version unchanged (reindented only), it will be removed
331// as soon as we're sure the new one works correctly
332#if 0
333
debe6624 334bool wxDialog::Show(bool show)
2bda0e17 335{
b6c588e1 336 m_isShown = show;
2bda0e17 337
b6c588e1
VZ
338 if (show)
339 InitDialog();
2bda0e17 340
b6c588e1 341 bool modal = IsModal();
2bda0e17 342
b6c588e1 343 if (modal)
2bda0e17 344 {
b6c588e1 345 if (show)
567da5c6 346 {
b6c588e1
VZ
347 // find the top level window which had focus before - we will restore
348 // focus to it later
349 m_hwndOldFocus = 0;
350 for ( HWND hwnd = ::GetFocus(); hwnd; hwnd = ::GetParent(hwnd) )
351 {
352 m_hwndOldFocus = (WXHWND)hwnd;
353 }
354
355 if (m_modalShowing)
356 {
357 BringWindowToTop((HWND) GetHWND());
358 return TRUE;
359 }
360
361 m_modalShowing = TRUE;
362 wxNode *node = wxModalDialogs.First();
363 while (node)
364 {
365 wxDialog *box = (wxDialog *)node->Data();
366 if (box != this)
367 ::EnableWindow((HWND) box->GetHWND(), FALSE);
368 node = node->Next();
369 }
370
371 // if we don't do it, some window might be deleted while we have pointers
372 // to them in our disabledWindows list and the program will crash when it
373 // will try to reenable them after the modal dialog end
374 wxTheApp->DeletePendingObjects();
375 wxList disabledWindows;
376
377 node = wxModelessWindows.First();
378 while (node)
379 {
380 wxWindow *win = (wxWindow *)node->Data();
381 if (::IsWindowEnabled((HWND) win->GetHWND()))
382 {
383 ::EnableWindow((HWND) win->GetHWND(), FALSE);
384 disabledWindows.Append(win);
385 }
386 node = node->Next();
387 }
388
389 ShowWindow((HWND) GetHWND(), SW_SHOW);
390 EnableWindow((HWND) GetHWND(), TRUE);
391 BringWindowToTop((HWND) GetHWND());
392
393 if ( !wxModalDialogs.Find(this) )
394 wxModalDialogs.Append(this);
395
396 MSG msg;
397 // Must test whether this dialog still exists: we may not process
398 // a message before the deletion.
399 while (wxModalDialogs.Find(this) && m_modalShowing && GetMessage(&msg, NULL, 0, 0))
400 {
401 if ( m_acceleratorTable.Ok() &&
402 ::TranslateAccelerator((HWND)GetHWND(),
403 (HACCEL)m_acceleratorTable.GetHACCEL(),
404 &msg) )
405 {
406 // Have processed the message
407 }
408 else if ( !wxTheApp->ProcessMessage((WXMSG *)&msg) )
409 {
410 TranslateMessage(&msg);
411 DispatchMessage(&msg);
412 }
9838df2c 413
b6c588e1
VZ
414 // If we get crashes (as per George Tasker's message) with nested modal dialogs,
415 // we should try removing the m_modalShowing test
9838df2c 416
b6c588e1
VZ
417 if (m_modalShowing && !::PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE))
418 // dfgg: NB MUST test m_modalShowing again as the message loop could have triggered
419 // a Show(FALSE) in the mean time!!!
420 // Without the test, we might delete the dialog before the end of modal showing.
2bda0e17 421 {
b6c588e1
VZ
422 while (wxTheApp->ProcessIdle() && m_modalShowing)
423 {
424 // Keep going until we decide we've done enough
425 }
2bda0e17 426 }
b6c588e1
VZ
427 }
428 // dfgg: now must specifically re-enable all other app windows that we disabled earlier
429 node=disabledWindows.First();
430 while(node) {
431 wxWindow* win = (wxWindow*) node->Data();
432 if (wxModalDialogs.Find(win) || wxModelessWindows.Find(win))
433 {
434 HWND hWnd = (HWND) win->GetHWND();
435 if (::IsWindow(hWnd))
436 ::EnableWindow(hWnd,TRUE);
437 }
438 node=node->Next();
439 }
9838df2c 440 }
b6c588e1
VZ
441 else // !show
442 {
443 ::SetFocus((HWND)m_hwndOldFocus);
dc1c4b62 444
b6c588e1 445 wxModalDialogs.DeleteObject(this);
2bda0e17 446
b6c588e1 447 wxNode *last = wxModalDialogs.Last();
2bda0e17 448
b6c588e1
VZ
449 // If there's still a modal dialog active, we
450 // enable it, else we enable all modeless windows
451 if (last)
452 {
453 // VZ: I don't understand what this is supposed to do, so I'll leave
454 // it out for now and look for horrible consequences
455 wxDialog *box = (wxDialog *)last->Data();
456 HWND hwnd = (HWND) box->GetHWND();
cc2b7472 457#if 0
b6c588e1 458 if (box->IsUserEnabled())
cc2b7472 459#endif // 0
b6c588e1
VZ
460 EnableWindow(hwnd, TRUE);
461 BringWindowToTop(hwnd);
462 }
463 else
464 {
465 wxNode *node = wxModelessWindows.First();
466 while (node)
467 {
468 wxWindow *win = (wxWindow *)node->Data();
469 HWND hwnd = (HWND) win->GetHWND();
470 // Only enable again if not user-disabled.
cc2b7472 471#if 0
b6c588e1 472 if (win->IsUserEnabled())
cc2b7472 473#endif // 0
b6c588e1
VZ
474 EnableWindow(hwnd, TRUE);
475 node = node->Next();
476 }
477 }
478 // Try to highlight the correct window (the parent)
479 HWND hWndParent = 0;
480 if (GetParent())
481 {
482 hWndParent = (HWND) GetParent()->GetHWND();
483 if (hWndParent)
484 ::BringWindowToTop(hWndParent);
485 }
486 ShowWindow((HWND) GetHWND(), SW_HIDE);
487 m_modalShowing = FALSE;
2bda0e17 488 }
2bda0e17 489 }
b6c588e1 490 else // !modal
2bda0e17 491 {
b6c588e1
VZ
492 if (show)
493 {
494 ShowWindow((HWND) GetHWND(), SW_SHOW);
495 BringWindowToTop((HWND) GetHWND());
496 }
497 else
498 {
499 // Try to highlight the correct window (the parent)
500 HWND hWndParent = 0;
501 if (GetParent())
502 {
503 hWndParent = (HWND) GetParent()->GetHWND();
504 if (hWndParent)
505 ::BringWindowToTop(hWndParent);
506 }
507
508 if ( m_hWnd )
509 ShowWindow((HWND) GetHWND(), SW_HIDE);
510 }
2bda0e17 511 }
b6c588e1
VZ
512
513 return TRUE;
2bda0e17
KB
514}
515
b6c588e1
VZ
516#else // 1
517
518bool wxDialog::IsModalShowing() const
2bda0e17 519{
b6c588e1 520 return wxModalDialogs.Find((wxDialog *)this) != NULL; // const_cast
2bda0e17
KB
521}
522
b6c588e1 523void wxDialog::DoShowModal()
2bda0e17 524{
b6c588e1
VZ
525 wxCHECK_RET( !IsModalShowing(), _T("DoShowModal() called twice") );
526
527 wxModalDialogs.Append(this);
528
529 wxWindow *parent = GetParent();
530
531 // remember where the focus was
532 wxWindow *winFocus = FindFocus();
533 if ( !winFocus )
534 {
535 winFocus = parent;
536 }
537 if ( !winFocus )
538 {
539 winFocus = wxTheApp->GetTopWindow();
540 }
541
542 // disable the parent window first
543 HWND hwndParent = parent ? GetHwndOf(parent) : (HWND)NULL;
544 if ( hwndParent )
545 {
546 ::EnableWindow(hwndParent, FALSE);
547 }
548
549 // enter the modal loop
550 while ( IsModalShowing() )
551 {
552#if wxUSE_THREADS
553 wxMutexGuiLeaveOrEnter();
554#endif // wxUSE_THREADS
555
556 while ( !wxTheApp->Pending() && wxTheApp->ProcessIdle() )
557 ;
558
559 // a message came or no more idle processing to do
560 wxTheApp->DoMessage();
561 }
562
563 // reenable the parent window if any
564 if ( hwndParent )
565 {
566 ::EnableWindow(hwndParent, TRUE);
567 }
568
569 // and restore focus
570 if ( winFocus )
571 {
572 winFocus->SetFocus();
573 }
2bda0e17
KB
574}
575
b6c588e1 576bool wxDialog::Show(bool show)
2bda0e17 577{
b6c588e1
VZ
578 if ( !wxDialogBase::Show(show) )
579 {
580 // nothing to do
581 return FALSE;
582 }
2bda0e17 583
b6c588e1
VZ
584 if ( show )
585 {
586 // usually will result in TransferDataToWindow() being called
587 InitDialog();
588 }
2bda0e17 589
b6c588e1
VZ
590 if ( IsModal() )
591 {
592 if ( show )
593 {
594 DoShowModal();
595 }
596 else // end of modal dialog
597 {
598 // this will cause IsModalShowing() return FALSE and our local
599 // message loop will terminate
600 wxModalDialogs.DeleteObject(this);
601 }
602 }
2bda0e17 603
b6c588e1 604 return TRUE;
2bda0e17
KB
605}
606
b6c588e1
VZ
607#endif // 0/1
608
2bda0e17 609// Replacement for Show(TRUE) for modal dialogs - returns return code
a23fd0e1 610int wxDialog::ShowModal()
2bda0e17 611{
b6c588e1
VZ
612 m_windowStyle |= wxDIALOG_MODAL;
613 Show(TRUE);
614 return GetReturnCode();
2bda0e17
KB
615}
616
b6c588e1
VZ
617// NB: this function (surprizingly) may be called for both modal and modeless
618// dialogs and should work for both of them
2bda0e17
KB
619void wxDialog::EndModal(int retCode)
620{
b6c588e1
VZ
621 SetReturnCode(retCode);
622 Show(FALSE);
2bda0e17
KB
623}
624
b6c588e1
VZ
625// ----------------------------------------------------------------------------
626// wxWin event handlers
627// ----------------------------------------------------------------------------
2bda0e17
KB
628
629// Standard buttons
630void wxDialog::OnOK(wxCommandEvent& event)
631{
dc1c4b62
VZ
632 if ( Validate() && TransferDataFromWindow() )
633 {
b6c588e1 634 EndModal(wxID_OK);
dc1c4b62 635 }
2bda0e17
KB
636}
637
638void wxDialog::OnApply(wxCommandEvent& event)
639{
b6c588e1
VZ
640 if ( Validate() )
641 TransferDataFromWindow();
642
643 // TODO probably need to disable the Apply button until things change again
2bda0e17
KB
644}
645
646void wxDialog::OnCancel(wxCommandEvent& event)
647{
b6c588e1 648 EndModal(wxID_CANCEL);
2bda0e17
KB
649}
650
e3065973 651void wxDialog::OnCloseWindow(wxCloseEvent& event)
2bda0e17 652{
b6c588e1 653 // We'll send a Cancel message by default, which may close the dialog.
e3065973
JS
654 // Check for looping if the Cancel event handler calls Close().
655
656 // Note that if a cancel button and handler aren't present in the dialog,
657 // nothing will happen when you close the dialog via the window manager, or
b6c588e1
VZ
658 // via Close(). We wouldn't want to destroy the dialog by default, since
659 // the dialog may have been created on the stack. However, this does mean
660 // that calling dialog->Close() won't delete the dialog unless the handler
661 // for wxID_CANCEL does so. So use Destroy() if you want to be sure to
662 // destroy the dialog. The default OnCancel (above) simply ends a modal
663 // dialog, and hides a modeless dialog.
664
665 // VZ: this is horrible and MT-unsafe. Can't we reuse some of these global
666 // lists here? don't dare to change it now, but should be done later!
2bda0e17 667 static wxList closing;
bd9d76cb 668
2bda0e17 669 if ( closing.Member(this) )
e3065973 670 return;
bd9d76cb 671
2bda0e17 672 closing.Append(this);
bd9d76cb 673
387a3b02
JS
674 wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
675 cancelEvent.SetEventObject( this );
e3065973 676 GetEventHandler()->ProcessEvent(cancelEvent); // This may close the dialog
2bda0e17
KB
677
678 closing.DeleteObject(this);
e3065973 679}
2bda0e17 680
e3065973 681// Destroy the window (delayed, if a managed window)
a23fd0e1 682bool wxDialog::Destroy()
e3065973 683{
b6c588e1
VZ
684 wxCHECK_MSG( !wxPendingDelete.Member(this), FALSE,
685 _T("wxDialog destroyed twice") );
686
e3065973 687 wxPendingDelete.Append(this);
2bda0e17 688
b6c588e1 689 return TRUE;
94b49b93
JS
690}
691
2bda0e17
KB
692void wxDialog::OnSysColourChanged(wxSysColourChangedEvent& event)
693{
1f112209 694#if wxUSE_CTL3D
b6c588e1 695 Ctl3dColorChange();
2bda0e17 696#else
b6c588e1
VZ
697 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
698 Refresh();
2bda0e17 699#endif
68ad65f8 700}
42e69d6b
VZ
701
702// ---------------------------------------------------------------------------
703// dialog window proc
704// ---------------------------------------------------------------------------
705
706long wxDialog::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
707{
708 long rc = 0;
709 bool processed = FALSE;
710
711 switch ( message )
712 {
713 case WM_CLOSE:
714 // if we can't close, tell the system that we processed the
715 // message - otherwise it would close us
716 processed = !Close();
717 break;
718 }
719
720 if ( !processed )
721 rc = wxWindow::MSWWindowProc(message, wParam, lParam);
722
723 return rc;
724}
b6c588e1
VZ
725
726#if wxUSE_CTL3D
727
728// Define for each class of dialog and control
729WXHBRUSH wxDialog::OnCtlColor(WXHDC WXUNUSED(pDC),
730 WXHWND WXUNUSED(pWnd),
731 WXUINT WXUNUSED(nCtlColor),
732 WXUINT message,
733 WXWPARAM wParam,
734 WXLPARAM lParam)
735{
736 return (WXHBRUSH)Ctl3dCtlColorEx(message, wParam, lParam);
737}
738
739#endif // wxUSE_CTL3D
740