]>
Commit | Line | Data |
---|---|---|
2bda0e17 KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: dialog.cpp | |
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 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "dialog.h" | |
14 | #endif | |
15 | ||
16 | // For compilers that support precompilation, includes "wx.h". | |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifdef __BORLANDC__ | |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
23 | #ifndef WX_PRECOMP | |
24 | #include "wx/dialog.h" | |
25 | #include "wx/utils.h" | |
26 | #include "wx/frame.h" | |
27 | #include "wx/app.h" | |
28 | #include "wx/settings.h" | |
0c589ad0 BM |
29 | #include "wx/intl.h" |
30 | #include "wx/log.h" | |
2bda0e17 KB |
31 | #endif |
32 | ||
33 | #include "wx/msw/private.h" | |
dbda9e86 | 34 | #include "wx/log.h" |
2bda0e17 | 35 | |
47d67540 | 36 | #if wxUSE_COMMON_DIALOGS |
2bda0e17 KB |
37 | #include <commdlg.h> |
38 | #endif | |
39 | ||
40 | #define wxDIALOG_DEFAULT_X 300 | |
41 | #define wxDIALOG_DEFAULT_Y 300 | |
42 | ||
43 | // Lists to keep track of windows, so we can disable/enable them | |
44 | // for modal dialogs | |
a23fd0e1 VZ |
45 | wxWindowList wxModalDialogs; |
46 | wxWindowList wxModelessWindows; // Frames and modeless dialogs | |
cde9f08e | 47 | extern wxList WXDLLEXPORT wxPendingDelete; |
2bda0e17 KB |
48 | |
49 | #if !USE_SHARED_LIBRARY | |
462e2437 VZ |
50 | IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxPanel) |
51 | ||
52 | BEGIN_EVENT_TABLE(wxDialog, wxPanel) | |
53 | EVT_SIZE(wxDialog::OnSize) | |
54 | EVT_BUTTON(wxID_OK, wxDialog::OnOK) | |
55 | EVT_BUTTON(wxID_APPLY, wxDialog::OnApply) | |
56 | EVT_BUTTON(wxID_CANCEL, wxDialog::OnCancel) | |
57 | EVT_CHAR_HOOK(wxDialog::OnCharHook) | |
58 | EVT_SYS_COLOUR_CHANGED(wxDialog::OnSysColourChanged) | |
59 | EVT_CLOSE(wxDialog::OnCloseWindow) | |
60 | END_EVENT_TABLE() | |
2bda0e17 KB |
61 | #endif |
62 | ||
a23fd0e1 | 63 | wxDialog::wxDialog() |
2bda0e17 KB |
64 | { |
65 | m_isShown = FALSE; | |
66 | m_modalShowing = FALSE; | |
67 | ||
68 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE)); | |
2bda0e17 KB |
69 | } |
70 | ||
debe6624 | 71 | bool wxDialog::Create(wxWindow *parent, wxWindowID id, |
462e2437 VZ |
72 | const wxString& title, |
73 | const wxPoint& pos, | |
74 | const wxSize& size, | |
75 | long style, | |
76 | const wxString& name) | |
2bda0e17 | 77 | { |
bd9d76cb VZ |
78 | #if wxUSE_TOOLTIPS |
79 | m_hwndToolTip = 0; | |
80 | #endif | |
81 | ||
462e2437 VZ |
82 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE)); |
83 | SetName(name); | |
bd9d76cb | 84 | |
462e2437 VZ |
85 | if (!parent) |
86 | wxTopLevelWindows.Append(this); | |
2bda0e17 | 87 | |
462e2437 | 88 | // windowFont = wxTheFontList->FindOrCreateFont(11, wxSWISS, wxNORMAL, wxNORMAL); |
2bda0e17 | 89 | |
462e2437 | 90 | if (parent) parent->AddChild(this); |
2bda0e17 | 91 | |
462e2437 VZ |
92 | if ( id == -1 ) |
93 | m_windowId = (int)NewControlId(); | |
94 | else | |
95 | m_windowId = id; | |
96 | ||
97 | int x = pos.x; | |
98 | int y = pos.y; | |
99 | int width = size.x; | |
100 | int height = size.y; | |
101 | ||
102 | if (x < 0) x = wxDIALOG_DEFAULT_X; | |
103 | if (y < 0) y = wxDIALOG_DEFAULT_Y; | |
104 | ||
105 | m_windowStyle = style; | |
106 | ||
107 | m_isShown = FALSE; | |
108 | m_modalShowing = FALSE; | |
109 | ||
110 | if (width < 0) | |
111 | width = 500; | |
112 | if (height < 0) | |
113 | height = 500; | |
114 | ||
706bb5f9 JS |
115 | // All dialogs should really have this style |
116 | m_windowStyle |= wxTAB_TRAVERSAL; | |
117 | ||
462e2437 VZ |
118 | WXDWORD extendedStyle = MakeExtendedStyle(m_windowStyle); |
119 | if (m_windowStyle & wxSTAY_ON_TOP) | |
120 | extendedStyle |= WS_EX_TOPMOST; | |
121 | ||
122 | // Allows creation of dialogs with & without captions under MSWindows, | |
123 | // resizeable or not (but a resizeable dialog always has caption - | |
124 | // otherwise it would look too strange) | |
125 | const char *dlg; | |
126 | if ( style & wxTHICK_FRAME ) | |
127 | dlg = "wxResizeableDialog"; | |
128 | else if ( style & wxCAPTION ) | |
129 | dlg = "wxCaptionDialog"; | |
130 | else | |
131 | dlg = "wxNoCaptionDialog"; | |
132 | MSWCreate(m_windowId, parent, NULL, this, NULL, | |
133 | x, y, width, height, | |
134 | 0, // style is not used if we have dlg template | |
135 | dlg, | |
136 | extendedStyle); | |
2bda0e17 | 137 | |
462e2437 | 138 | HWND hwnd = (HWND)GetHWND(); |
2bda0e17 | 139 | |
462e2437 VZ |
140 | if ( !hwnd ) |
141 | { | |
68ad65f8 | 142 | wxLogError(_("Failed to create dialog.")); |
2bda0e17 | 143 | |
462e2437 VZ |
144 | return FALSE; |
145 | } | |
2bda0e17 | 146 | |
462e2437 | 147 | SubclassWin(GetHWND()); |
bd9d76cb | 148 | |
462e2437 VZ |
149 | SetWindowText(hwnd, title); |
150 | SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT)); | |
2bda0e17 | 151 | |
462e2437 | 152 | return TRUE; |
2bda0e17 KB |
153 | } |
154 | ||
debe6624 | 155 | void wxDialog::SetModal(bool flag) |
2bda0e17 | 156 | { |
dc1c4b62 VZ |
157 | if ( flag ) |
158 | m_windowStyle |= wxDIALOG_MODAL ; | |
159 | else | |
160 | if ( m_windowStyle & wxDIALOG_MODAL ) | |
161 | m_windowStyle -= wxDIALOG_MODAL ; | |
bd9d76cb | 162 | |
2bda0e17 KB |
163 | wxModelessWindows.DeleteObject(this); |
164 | if (!flag) | |
165 | wxModelessWindows.Append(this); | |
166 | } | |
167 | ||
168 | wxDialog::~wxDialog() | |
169 | { | |
170 | m_isBeingDeleted = TRUE; | |
171 | ||
172 | wxTopLevelWindows.DeleteObject(this); | |
173 | ||
174 | if (m_modalShowing) | |
175 | { | |
176 | Show(FALSE); | |
177 | // For some reason, wxWindows can activate another task altogether | |
178 | // when a frame is destroyed after a modal dialog has been invoked. | |
179 | // Try to bring the parent to the top. | |
180 | // dfgg: I moved this following line from end of function - | |
181 | // must not call if another window is on top!! | |
182 | // This can often happen with Close() and delayed deleting | |
183 | if (GetParent() && GetParent()->GetHWND()) | |
184 | ::BringWindowToTop((HWND) GetParent()->GetHWND()); | |
185 | } | |
186 | ||
187 | m_modalShowing = FALSE; | |
188 | if ( GetHWND() ) | |
189 | ShowWindow((HWND) GetHWND(), SW_HIDE); | |
190 | ||
191 | if ( (GetWindowStyleFlag() & wxDIALOG_MODAL) != wxDIALOG_MODAL ) | |
192 | wxModelessWindows.DeleteObject(this); | |
193 | ||
194 | UnsubclassWin(); | |
195 | ||
196 | // If this is the last top-level window, exit. | |
197 | if (wxTheApp && (wxTopLevelWindows.Number() == 0)) | |
198 | { | |
199 | wxTheApp->SetTopWindow(NULL); | |
200 | ||
201 | if (wxTheApp->GetExitOnFrameDelete()) | |
202 | { | |
203 | PostQuitMessage(0); | |
204 | } | |
205 | } | |
206 | } | |
207 | ||
208 | // By default, pressing escape cancels the dialog | |
209 | void wxDialog::OnCharHook(wxKeyEvent& event) | |
210 | { | |
211 | if (GetHWND()) | |
212 | { | |
213 | if (event.m_keyCode == WXK_ESCAPE) | |
214 | { | |
2a47d3c1 JS |
215 | // Behaviour changed in 2.0: we'll send a Cancel message |
216 | // to the dialog instead of Close. | |
217 | wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL); | |
218 | cancelEvent.SetEventObject( this ); | |
219 | GetEventHandler()->ProcessEvent(cancelEvent); | |
2bda0e17 | 220 | |
2a47d3c1 | 221 | return; |
2bda0e17 KB |
222 | } |
223 | } | |
224 | // We didn't process this event. | |
225 | event.Skip(); | |
226 | } | |
227 | ||
228 | void wxDialog::OnPaint(wxPaintEvent& event) | |
229 | { | |
dc1c4b62 VZ |
230 | // No: if you call the default procedure, it makes |
231 | // the following painting code not work. | |
232 | // wxWindow::OnPaint(event); | |
2bda0e17 KB |
233 | } |
234 | ||
a23fd0e1 | 235 | void wxDialog::Fit() |
2bda0e17 KB |
236 | { |
237 | wxWindow::Fit(); | |
238 | } | |
239 | ||
debe6624 | 240 | void wxDialog::Iconize(bool WXUNUSED(iconize)) |
2bda0e17 KB |
241 | { |
242 | // Windows dialog boxes can't be iconized | |
243 | } | |
244 | ||
a23fd0e1 | 245 | bool wxDialog::IsIconized() const |
2bda0e17 KB |
246 | { |
247 | return FALSE; | |
248 | } | |
249 | ||
721b32e0 | 250 | void wxDialog::DoSetClientSize(int width, int height) |
2bda0e17 KB |
251 | { |
252 | HWND hWnd = (HWND) GetHWND(); | |
253 | RECT rect; | |
2de8030d | 254 | ::GetClientRect(hWnd, &rect); |
2bda0e17 KB |
255 | |
256 | RECT rect2; | |
257 | GetWindowRect(hWnd, &rect2); | |
258 | ||
259 | // Find the difference between the entire window (title bar and all) | |
260 | // and the client area; add this to the new client size to move the | |
261 | // window | |
262 | int actual_width = rect2.right - rect2.left - rect.right + width; | |
263 | int actual_height = rect2.bottom - rect2.top - rect.bottom + height; | |
264 | ||
265 | MoveWindow(hWnd, rect2.left, rect2.top, actual_width, actual_height, TRUE); | |
debe6624 | 266 | |
2bda0e17 | 267 | wxSizeEvent event(wxSize(actual_width, actual_height), m_windowId); |
debe6624 | 268 | event.SetEventObject( this ); |
2bda0e17 | 269 | GetEventHandler()->ProcessEvent(event); |
2bda0e17 KB |
270 | } |
271 | ||
272 | void wxDialog::GetPosition(int *x, int *y) const | |
273 | { | |
274 | HWND hWnd = (HWND) GetHWND(); | |
275 | RECT rect; | |
276 | GetWindowRect(hWnd, &rect); | |
277 | ||
278 | *x = rect.left; | |
279 | *y = rect.top; | |
280 | } | |
281 | ||
a23fd0e1 | 282 | bool wxDialog::IsShown() const |
2bda0e17 KB |
283 | { |
284 | return m_isShown; | |
285 | } | |
286 | ||
debe6624 | 287 | bool wxDialog::Show(bool show) |
2bda0e17 KB |
288 | { |
289 | m_isShown = show; | |
290 | ||
291 | if (show) | |
292 | InitDialog(); | |
293 | ||
294 | bool modal = ((GetWindowStyleFlag() & wxDIALOG_MODAL) == wxDIALOG_MODAL) ; | |
295 | ||
296 | #if WXGARBAGE_COLLECTION_ON /* MATTHEW: GC */ | |
297 | if (!modal) { | |
298 | if (show) { | |
a23fd0e1 VZ |
299 | if (!wxModelessWindows.Find(this)) |
300 | wxModelessWindows.Append(this); | |
2bda0e17 KB |
301 | } else |
302 | wxModelessWindows.DeleteObject(this); | |
303 | } | |
304 | if (show) { | |
a23fd0e1 | 305 | if (!wxTopLevelWindows.Find(this)) |
2bda0e17 KB |
306 | wxTopLevelWindows.Append(this); |
307 | } else | |
308 | wxTopLevelWindows.DeleteObject(this); | |
309 | #endif | |
310 | ||
311 | if (modal) | |
312 | { | |
313 | if (show) | |
314 | { | |
7f68042c VZ |
315 | // find the top level window which had focus before - we will restore |
316 | // focus to it later | |
317 | m_hwndOldFocus = 0; | |
318 | for ( HWND hwnd = ::GetFocus(); hwnd; hwnd = ::GetParent(hwnd) ) | |
319 | { | |
320 | m_hwndOldFocus = (WXHWND)hwnd; | |
321 | } | |
dc1c4b62 | 322 | |
2bda0e17 KB |
323 | if (m_modalShowing) |
324 | { | |
325 | BringWindowToTop((HWND) GetHWND()); | |
326 | return TRUE; | |
327 | } | |
bd9d76cb | 328 | |
2bda0e17 KB |
329 | m_modalShowing = TRUE; |
330 | wxNode *node = wxModalDialogs.First(); | |
331 | while (node) | |
332 | { | |
333 | wxDialog *box = (wxDialog *)node->Data(); | |
334 | if (box != this) | |
335 | ::EnableWindow((HWND) box->GetHWND(), FALSE); | |
336 | node = node->Next(); | |
337 | } | |
9c9cff0b VZ |
338 | |
339 | // if we don't do it, some window might be deleted while we have pointers | |
340 | // to them in our disabledWindows list and the program will crash when it | |
341 | // will try to reenable them after the modal dialog end | |
342 | wxTheApp->DeletePendingObjects(); | |
343 | wxList disabledWindows; | |
344 | ||
2bda0e17 KB |
345 | node = wxModelessWindows.First(); |
346 | while (node) | |
347 | { | |
348 | wxWindow *win = (wxWindow *)node->Data(); | |
dc1c4b62 VZ |
349 | if (::IsWindowEnabled((HWND) win->GetHWND())) |
350 | { | |
2bda0e17 | 351 | ::EnableWindow((HWND) win->GetHWND(), FALSE); |
9c9cff0b | 352 | disabledWindows.Append(win); |
dc1c4b62 | 353 | } |
2bda0e17 KB |
354 | node = node->Next(); |
355 | } | |
356 | ||
357 | ShowWindow((HWND) GetHWND(), SW_SHOW); | |
358 | EnableWindow((HWND) GetHWND(), TRUE); | |
359 | BringWindowToTop((HWND) GetHWND()); | |
360 | ||
a23fd0e1 | 361 | if ( !wxModalDialogs.Find(this) ) |
2bda0e17 KB |
362 | wxModalDialogs.Append(this); |
363 | ||
364 | MSG msg; | |
365 | // Must test whether this dialog still exists: we may not process | |
366 | // a message before the deletion. | |
a23fd0e1 | 367 | while (wxModalDialogs.Find(this) && m_modalShowing && GetMessage(&msg, NULL, 0, 0)) |
2bda0e17 | 368 | { |
0a54c4a8 VZ |
369 | if ( m_acceleratorTable.Ok() && |
370 | ::TranslateAccelerator((HWND)GetHWND(), | |
371 | (HACCEL)m_acceleratorTable.GetHACCEL(), | |
372 | &msg) ) | |
567da5c6 JS |
373 | { |
374 | // Have processed the message | |
375 | } | |
0a54c4a8 | 376 | else if ( !wxTheApp->ProcessMessage((WXMSG *)&msg) ) |
2bda0e17 KB |
377 | { |
378 | TranslateMessage(&msg); | |
379 | DispatchMessage(&msg); | |
380 | } | |
9838df2c JS |
381 | |
382 | // If we get crashes (as per George Tasker's message) with nested modal dialogs, | |
383 | // we should try removing the m_modalShowing test | |
384 | ||
2bda0e17 | 385 | if (m_modalShowing && !::PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE)) |
dc1c4b62 VZ |
386 | // dfgg: NB MUST test m_modalShowing again as the message loop could have triggered |
387 | // a Show(FALSE) in the mean time!!! | |
388 | // Without the test, we might delete the dialog before the end of modal showing. | |
2bda0e17 KB |
389 | { |
390 | while (wxTheApp->ProcessIdle() && m_modalShowing) | |
391 | { | |
392 | // Keep going until we decide we've done enough | |
393 | } | |
394 | } | |
395 | } | |
396 | // dfgg: now must specifically re-enable all other app windows that we disabled earlier | |
9c9cff0b | 397 | node=disabledWindows.First(); |
2bda0e17 | 398 | while(node) { |
dc1c4b62 | 399 | wxWindow* win = (wxWindow*) node->Data(); |
a23fd0e1 | 400 | if (wxModalDialogs.Find(win) || wxModelessWindows.Find(win)) |
9838df2c JS |
401 | { |
402 | HWND hWnd = (HWND) win->GetHWND(); | |
403 | if (::IsWindow(hWnd)) | |
404 | ::EnableWindow(hWnd,TRUE); | |
405 | } | |
2bda0e17 KB |
406 | node=node->Next(); |
407 | } | |
408 | } | |
dc1c4b62 | 409 | else // !show |
2bda0e17 | 410 | { |
dc1c4b62 VZ |
411 | ::SetFocus((HWND)m_hwndOldFocus); |
412 | ||
2bda0e17 KB |
413 | wxModalDialogs.DeleteObject(this); |
414 | ||
415 | wxNode *last = wxModalDialogs.Last(); | |
416 | ||
417 | // If there's still a modal dialog active, we | |
418 | // enable it, else we enable all modeless windows | |
419 | if (last) | |
420 | { | |
cc2b7472 VZ |
421 | // VZ: I don't understand what this is supposed to do, so I'll leave |
422 | // it out for now and look for horrible consequences | |
2bda0e17 KB |
423 | wxDialog *box = (wxDialog *)last->Data(); |
424 | HWND hwnd = (HWND) box->GetHWND(); | |
cc2b7472 VZ |
425 | #if 0 |
426 | if (box->IsUserEnabled()) | |
427 | #endif // 0 | |
2bda0e17 KB |
428 | EnableWindow(hwnd, TRUE); |
429 | BringWindowToTop(hwnd); | |
430 | } | |
431 | else | |
432 | { | |
433 | wxNode *node = wxModelessWindows.First(); | |
434 | while (node) | |
435 | { | |
436 | wxWindow *win = (wxWindow *)node->Data(); | |
437 | HWND hwnd = (HWND) win->GetHWND(); | |
438 | // Only enable again if not user-disabled. | |
cc2b7472 | 439 | #if 0 |
2bda0e17 | 440 | if (win->IsUserEnabled()) |
cc2b7472 | 441 | #endif // 0 |
2bda0e17 KB |
442 | EnableWindow(hwnd, TRUE); |
443 | node = node->Next(); | |
444 | } | |
445 | } | |
446 | // Try to highlight the correct window (the parent) | |
447 | HWND hWndParent = 0; | |
448 | if (GetParent()) | |
449 | { | |
450 | hWndParent = (HWND) GetParent()->GetHWND(); | |
451 | if (hWndParent) | |
452 | ::BringWindowToTop(hWndParent); | |
453 | } | |
454 | ShowWindow((HWND) GetHWND(), SW_HIDE); | |
455 | m_modalShowing = FALSE; | |
456 | } | |
457 | } | |
dc1c4b62 | 458 | else // !modal |
2bda0e17 KB |
459 | { |
460 | if (show) | |
461 | { | |
462 | ShowWindow((HWND) GetHWND(), SW_SHOW); | |
463 | BringWindowToTop((HWND) GetHWND()); | |
464 | } | |
465 | else | |
466 | { | |
467 | // Try to highlight the correct window (the parent) | |
468 | HWND hWndParent = 0; | |
469 | if (GetParent()) | |
470 | { | |
471 | hWndParent = (HWND) GetParent()->GetHWND(); | |
472 | if (hWndParent) | |
473 | ::BringWindowToTop(hWndParent); | |
474 | } | |
475 | ShowWindow((HWND) GetHWND(), SW_HIDE); | |
476 | } | |
477 | } | |
478 | return TRUE; | |
479 | } | |
480 | ||
481 | void wxDialog::SetTitle(const wxString& title) | |
482 | { | |
483 | SetWindowText((HWND) GetHWND(), (const char *)title); | |
484 | } | |
485 | ||
a23fd0e1 | 486 | wxString wxDialog::GetTitle() const |
2bda0e17 KB |
487 | { |
488 | GetWindowText((HWND) GetHWND(), wxBuffer, 1000); | |
489 | return wxString(wxBuffer); | |
490 | } | |
491 | ||
debe6624 | 492 | void wxDialog::Centre(int direction) |
2bda0e17 KB |
493 | { |
494 | int x_offset,y_offset ; | |
495 | int display_width, display_height; | |
496 | int width, height, x, y; | |
dfc54541 JS |
497 | wxWindow *parent = GetParent(); |
498 | if ((direction & wxCENTER_FRAME) && parent) | |
2bda0e17 | 499 | { |
dfc54541 JS |
500 | parent->GetPosition(&x_offset,&y_offset) ; |
501 | parent->GetSize(&display_width,&display_height) ; | |
2bda0e17 KB |
502 | } |
503 | else | |
2bda0e17 KB |
504 | { |
505 | wxDisplaySize(&display_width, &display_height); | |
506 | x_offset = 0 ; | |
507 | y_offset = 0 ; | |
508 | } | |
509 | ||
2bda0e17 KB |
510 | GetSize(&width, &height); |
511 | GetPosition(&x, &y); | |
512 | ||
513 | if (direction & wxHORIZONTAL) | |
514 | x = (int)((display_width - width)/2); | |
515 | if (direction & wxVERTICAL) | |
516 | y = (int)((display_height - height)/2); | |
517 | ||
518 | SetSize(x+x_offset, y+y_offset, width, height); | |
519 | } | |
520 | ||
521 | // Replacement for Show(TRUE) for modal dialogs - returns return code | |
a23fd0e1 | 522 | int wxDialog::ShowModal() |
2bda0e17 | 523 | { |
dc1c4b62 VZ |
524 | m_windowStyle |= wxDIALOG_MODAL; |
525 | Show(TRUE); | |
526 | return GetReturnCode(); | |
2bda0e17 KB |
527 | } |
528 | ||
529 | void wxDialog::EndModal(int retCode) | |
530 | { | |
dc1c4b62 VZ |
531 | SetReturnCode(retCode); |
532 | Show(FALSE); | |
2bda0e17 KB |
533 | } |
534 | ||
535 | // Define for each class of dialog and control | |
debe6624 | 536 | WXHBRUSH wxDialog::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, |
dc1c4b62 | 537 | WXUINT message, WXWPARAM wParam, WXLPARAM lParam) |
2bda0e17 | 538 | { |
1f112209 | 539 | #if wxUSE_CTL3D |
2bda0e17 KB |
540 | HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam); |
541 | return (WXHBRUSH) hbrush; | |
542 | #else | |
543 | return 0; | |
544 | #endif | |
545 | } | |
546 | ||
547 | // Standard buttons | |
548 | void wxDialog::OnOK(wxCommandEvent& event) | |
549 | { | |
dc1c4b62 VZ |
550 | if ( Validate() && TransferDataFromWindow() ) |
551 | { | |
2bda0e17 KB |
552 | if ( IsModal() ) |
553 | EndModal(wxID_OK); | |
554 | else | |
555 | { | |
387a3b02 JS |
556 | SetReturnCode(wxID_OK); |
557 | this->Show(FALSE); | |
2bda0e17 | 558 | } |
dc1c4b62 | 559 | } |
2bda0e17 KB |
560 | } |
561 | ||
562 | void wxDialog::OnApply(wxCommandEvent& event) | |
563 | { | |
dc1c4b62 VZ |
564 | if (Validate()) |
565 | TransferDataFromWindow(); | |
566 | // TODO probably need to disable the Apply button until things change again | |
2bda0e17 KB |
567 | } |
568 | ||
569 | void wxDialog::OnCancel(wxCommandEvent& event) | |
570 | { | |
571 | if ( IsModal() ) | |
572 | EndModal(wxID_CANCEL); | |
573 | else | |
574 | { | |
575 | SetReturnCode(wxID_CANCEL); | |
2a47d3c1 | 576 | this->Show(FALSE); |
2bda0e17 KB |
577 | } |
578 | } | |
579 | ||
e3065973 | 580 | void wxDialog::OnCloseWindow(wxCloseEvent& event) |
2bda0e17 | 581 | { |
e3065973 | 582 | // We'll send a Cancel message by default, |
2bda0e17 | 583 | // which may close the dialog. |
e3065973 JS |
584 | // Check for looping if the Cancel event handler calls Close(). |
585 | ||
586 | // Note that if a cancel button and handler aren't present in the dialog, | |
587 | // nothing will happen when you close the dialog via the window manager, or | |
588 | // via Close(). | |
589 | // We wouldn't want to destroy the dialog by default, since the dialog may have been | |
590 | // created on the stack. | |
591 | // However, this does mean that calling dialog->Close() won't delete the dialog | |
592 | // unless the handler for wxID_CANCEL does so. So use Destroy() if you want to be | |
593 | // sure to destroy the dialog. | |
594 | // The default OnCancel (above) simply ends a modal dialog, and hides a modeless dialog. | |
2bda0e17 KB |
595 | |
596 | static wxList closing; | |
bd9d76cb | 597 | |
2bda0e17 | 598 | if ( closing.Member(this) ) |
e3065973 | 599 | return; |
bd9d76cb | 600 | |
2bda0e17 | 601 | closing.Append(this); |
bd9d76cb | 602 | |
387a3b02 JS |
603 | wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL); |
604 | cancelEvent.SetEventObject( this ); | |
e3065973 | 605 | GetEventHandler()->ProcessEvent(cancelEvent); // This may close the dialog |
2bda0e17 KB |
606 | |
607 | closing.DeleteObject(this); | |
e3065973 | 608 | } |
2bda0e17 | 609 | |
e3065973 | 610 | // Destroy the window (delayed, if a managed window) |
a23fd0e1 | 611 | bool wxDialog::Destroy() |
e3065973 JS |
612 | { |
613 | if (!wxPendingDelete.Member(this)) | |
614 | wxPendingDelete.Append(this); | |
615 | return TRUE; | |
2bda0e17 KB |
616 | } |
617 | ||
94b49b93 JS |
618 | void wxDialog::OnSize(wxSizeEvent& WXUNUSED(event)) |
619 | { | |
620 | // if we're using constraints - do use them | |
621 | #if wxUSE_CONSTRAINTS | |
a23fd0e1 VZ |
622 | if ( GetAutoLayout() ) |
623 | { | |
94b49b93 JS |
624 | Layout(); |
625 | } | |
626 | #endif | |
627 | } | |
628 | ||
2bda0e17 KB |
629 | void wxDialog::OnSysColourChanged(wxSysColourChangedEvent& event) |
630 | { | |
1f112209 | 631 | #if wxUSE_CTL3D |
2bda0e17 KB |
632 | Ctl3dColorChange(); |
633 | #else | |
634 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE)); | |
2bda0e17 KB |
635 | Refresh(); |
636 | #endif | |
68ad65f8 | 637 | } |
42e69d6b VZ |
638 | |
639 | // --------------------------------------------------------------------------- | |
640 | // dialog window proc | |
641 | // --------------------------------------------------------------------------- | |
642 | ||
643 | long wxDialog::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) | |
644 | { | |
645 | long rc = 0; | |
646 | bool processed = FALSE; | |
647 | ||
648 | switch ( message ) | |
649 | { | |
650 | case WM_CLOSE: | |
651 | // if we can't close, tell the system that we processed the | |
652 | // message - otherwise it would close us | |
653 | processed = !Close(); | |
654 | break; | |
655 | } | |
656 | ||
657 | if ( !processed ) | |
658 | rc = wxWindow::MSWWindowProc(message, wParam, lParam); | |
659 | ||
660 | return rc; | |
661 | } |