]>
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) | |
837e5743 | 125 | const wxChar *dlg; |
462e2437 | 126 | if ( style & wxTHICK_FRAME ) |
837e5743 | 127 | dlg = _T("wxResizeableDialog"); |
462e2437 | 128 | else if ( style & wxCAPTION ) |
837e5743 | 129 | dlg = _T("wxCaptionDialog"); |
462e2437 | 130 | else |
837e5743 | 131 | dlg = _T("wxNoCaptionDialog"); |
462e2437 VZ |
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 | ||
edccf428 VZ |
174 | Show(FALSE); |
175 | ||
2bda0e17 KB |
176 | if (m_modalShowing) |
177 | { | |
2bda0e17 KB |
178 | // For some reason, wxWindows can activate another task altogether |
179 | // when a frame is destroyed after a modal dialog has been invoked. | |
180 | // Try to bring the parent to the top. | |
181 | // dfgg: I moved this following line from end of function - | |
182 | // must not call if another window is on top!! | |
183 | // This can often happen with Close() and delayed deleting | |
184 | if (GetParent() && GetParent()->GetHWND()) | |
185 | ::BringWindowToTop((HWND) GetParent()->GetHWND()); | |
186 | } | |
187 | ||
188 | m_modalShowing = FALSE; | |
2bda0e17 KB |
189 | |
190 | if ( (GetWindowStyleFlag() & wxDIALOG_MODAL) != wxDIALOG_MODAL ) | |
191 | wxModelessWindows.DeleteObject(this); | |
192 | ||
2bda0e17 KB |
193 | // If this is the last top-level window, exit. |
194 | if (wxTheApp && (wxTopLevelWindows.Number() == 0)) | |
195 | { | |
196 | wxTheApp->SetTopWindow(NULL); | |
197 | ||
198 | if (wxTheApp->GetExitOnFrameDelete()) | |
199 | { | |
200 | PostQuitMessage(0); | |
201 | } | |
202 | } | |
203 | } | |
204 | ||
205 | // By default, pressing escape cancels the dialog | |
206 | void wxDialog::OnCharHook(wxKeyEvent& event) | |
207 | { | |
208 | if (GetHWND()) | |
209 | { | |
210 | if (event.m_keyCode == WXK_ESCAPE) | |
211 | { | |
2a47d3c1 JS |
212 | // Behaviour changed in 2.0: we'll send a Cancel message |
213 | // to the dialog instead of Close. | |
214 | wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL); | |
215 | cancelEvent.SetEventObject( this ); | |
216 | GetEventHandler()->ProcessEvent(cancelEvent); | |
2bda0e17 | 217 | |
2a47d3c1 | 218 | return; |
2bda0e17 KB |
219 | } |
220 | } | |
221 | // We didn't process this event. | |
222 | event.Skip(); | |
223 | } | |
224 | ||
225 | void wxDialog::OnPaint(wxPaintEvent& event) | |
226 | { | |
dc1c4b62 VZ |
227 | // No: if you call the default procedure, it makes |
228 | // the following painting code not work. | |
229 | // wxWindow::OnPaint(event); | |
2bda0e17 KB |
230 | } |
231 | ||
a23fd0e1 | 232 | void wxDialog::Fit() |
2bda0e17 KB |
233 | { |
234 | wxWindow::Fit(); | |
235 | } | |
236 | ||
debe6624 | 237 | void wxDialog::Iconize(bool WXUNUSED(iconize)) |
2bda0e17 KB |
238 | { |
239 | // Windows dialog boxes can't be iconized | |
240 | } | |
241 | ||
a23fd0e1 | 242 | bool wxDialog::IsIconized() const |
2bda0e17 KB |
243 | { |
244 | return FALSE; | |
245 | } | |
246 | ||
721b32e0 | 247 | void wxDialog::DoSetClientSize(int width, int height) |
2bda0e17 KB |
248 | { |
249 | HWND hWnd = (HWND) GetHWND(); | |
250 | RECT rect; | |
2de8030d | 251 | ::GetClientRect(hWnd, &rect); |
2bda0e17 KB |
252 | |
253 | RECT rect2; | |
254 | GetWindowRect(hWnd, &rect2); | |
255 | ||
256 | // Find the difference between the entire window (title bar and all) | |
257 | // and the client area; add this to the new client size to move the | |
258 | // window | |
259 | int actual_width = rect2.right - rect2.left - rect.right + width; | |
260 | int actual_height = rect2.bottom - rect2.top - rect.bottom + height; | |
261 | ||
262 | MoveWindow(hWnd, rect2.left, rect2.top, actual_width, actual_height, TRUE); | |
debe6624 | 263 | |
2bda0e17 | 264 | wxSizeEvent event(wxSize(actual_width, actual_height), m_windowId); |
debe6624 | 265 | event.SetEventObject( this ); |
2bda0e17 | 266 | GetEventHandler()->ProcessEvent(event); |
2bda0e17 KB |
267 | } |
268 | ||
269 | void wxDialog::GetPosition(int *x, int *y) const | |
270 | { | |
271 | HWND hWnd = (HWND) GetHWND(); | |
272 | RECT rect; | |
273 | GetWindowRect(hWnd, &rect); | |
274 | ||
275 | *x = rect.left; | |
276 | *y = rect.top; | |
277 | } | |
278 | ||
a23fd0e1 | 279 | bool wxDialog::IsShown() const |
2bda0e17 KB |
280 | { |
281 | return m_isShown; | |
282 | } | |
283 | ||
debe6624 | 284 | bool wxDialog::Show(bool show) |
2bda0e17 KB |
285 | { |
286 | m_isShown = show; | |
287 | ||
288 | if (show) | |
289 | InitDialog(); | |
290 | ||
291 | bool modal = ((GetWindowStyleFlag() & wxDIALOG_MODAL) == wxDIALOG_MODAL) ; | |
292 | ||
293 | #if WXGARBAGE_COLLECTION_ON /* MATTHEW: GC */ | |
294 | if (!modal) { | |
295 | if (show) { | |
a23fd0e1 VZ |
296 | if (!wxModelessWindows.Find(this)) |
297 | wxModelessWindows.Append(this); | |
2bda0e17 KB |
298 | } else |
299 | wxModelessWindows.DeleteObject(this); | |
300 | } | |
301 | if (show) { | |
a23fd0e1 | 302 | if (!wxTopLevelWindows.Find(this)) |
2bda0e17 KB |
303 | wxTopLevelWindows.Append(this); |
304 | } else | |
305 | wxTopLevelWindows.DeleteObject(this); | |
306 | #endif | |
307 | ||
308 | if (modal) | |
309 | { | |
310 | if (show) | |
311 | { | |
7f68042c VZ |
312 | // find the top level window which had focus before - we will restore |
313 | // focus to it later | |
314 | m_hwndOldFocus = 0; | |
315 | for ( HWND hwnd = ::GetFocus(); hwnd; hwnd = ::GetParent(hwnd) ) | |
316 | { | |
317 | m_hwndOldFocus = (WXHWND)hwnd; | |
318 | } | |
dc1c4b62 | 319 | |
2bda0e17 KB |
320 | if (m_modalShowing) |
321 | { | |
322 | BringWindowToTop((HWND) GetHWND()); | |
323 | return TRUE; | |
324 | } | |
bd9d76cb | 325 | |
2bda0e17 KB |
326 | m_modalShowing = TRUE; |
327 | wxNode *node = wxModalDialogs.First(); | |
328 | while (node) | |
329 | { | |
330 | wxDialog *box = (wxDialog *)node->Data(); | |
331 | if (box != this) | |
332 | ::EnableWindow((HWND) box->GetHWND(), FALSE); | |
333 | node = node->Next(); | |
334 | } | |
9c9cff0b VZ |
335 | |
336 | // if we don't do it, some window might be deleted while we have pointers | |
337 | // to them in our disabledWindows list and the program will crash when it | |
338 | // will try to reenable them after the modal dialog end | |
339 | wxTheApp->DeletePendingObjects(); | |
340 | wxList disabledWindows; | |
341 | ||
2bda0e17 KB |
342 | node = wxModelessWindows.First(); |
343 | while (node) | |
344 | { | |
345 | wxWindow *win = (wxWindow *)node->Data(); | |
dc1c4b62 VZ |
346 | if (::IsWindowEnabled((HWND) win->GetHWND())) |
347 | { | |
2bda0e17 | 348 | ::EnableWindow((HWND) win->GetHWND(), FALSE); |
9c9cff0b | 349 | disabledWindows.Append(win); |
dc1c4b62 | 350 | } |
2bda0e17 KB |
351 | node = node->Next(); |
352 | } | |
353 | ||
354 | ShowWindow((HWND) GetHWND(), SW_SHOW); | |
355 | EnableWindow((HWND) GetHWND(), TRUE); | |
356 | BringWindowToTop((HWND) GetHWND()); | |
357 | ||
a23fd0e1 | 358 | if ( !wxModalDialogs.Find(this) ) |
2bda0e17 KB |
359 | wxModalDialogs.Append(this); |
360 | ||
361 | MSG msg; | |
362 | // Must test whether this dialog still exists: we may not process | |
363 | // a message before the deletion. | |
a23fd0e1 | 364 | while (wxModalDialogs.Find(this) && m_modalShowing && GetMessage(&msg, NULL, 0, 0)) |
2bda0e17 | 365 | { |
0a54c4a8 VZ |
366 | if ( m_acceleratorTable.Ok() && |
367 | ::TranslateAccelerator((HWND)GetHWND(), | |
368 | (HACCEL)m_acceleratorTable.GetHACCEL(), | |
369 | &msg) ) | |
567da5c6 JS |
370 | { |
371 | // Have processed the message | |
372 | } | |
0a54c4a8 | 373 | else if ( !wxTheApp->ProcessMessage((WXMSG *)&msg) ) |
2bda0e17 KB |
374 | { |
375 | TranslateMessage(&msg); | |
376 | DispatchMessage(&msg); | |
377 | } | |
9838df2c JS |
378 | |
379 | // If we get crashes (as per George Tasker's message) with nested modal dialogs, | |
380 | // we should try removing the m_modalShowing test | |
381 | ||
2bda0e17 | 382 | if (m_modalShowing && !::PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE)) |
dc1c4b62 VZ |
383 | // dfgg: NB MUST test m_modalShowing again as the message loop could have triggered |
384 | // a Show(FALSE) in the mean time!!! | |
385 | // Without the test, we might delete the dialog before the end of modal showing. | |
2bda0e17 KB |
386 | { |
387 | while (wxTheApp->ProcessIdle() && m_modalShowing) | |
388 | { | |
389 | // Keep going until we decide we've done enough | |
390 | } | |
391 | } | |
392 | } | |
393 | // dfgg: now must specifically re-enable all other app windows that we disabled earlier | |
9c9cff0b | 394 | node=disabledWindows.First(); |
2bda0e17 | 395 | while(node) { |
dc1c4b62 | 396 | wxWindow* win = (wxWindow*) node->Data(); |
a23fd0e1 | 397 | if (wxModalDialogs.Find(win) || wxModelessWindows.Find(win)) |
9838df2c JS |
398 | { |
399 | HWND hWnd = (HWND) win->GetHWND(); | |
400 | if (::IsWindow(hWnd)) | |
401 | ::EnableWindow(hWnd,TRUE); | |
402 | } | |
2bda0e17 KB |
403 | node=node->Next(); |
404 | } | |
405 | } | |
dc1c4b62 | 406 | else // !show |
2bda0e17 | 407 | { |
dc1c4b62 VZ |
408 | ::SetFocus((HWND)m_hwndOldFocus); |
409 | ||
2bda0e17 KB |
410 | wxModalDialogs.DeleteObject(this); |
411 | ||
412 | wxNode *last = wxModalDialogs.Last(); | |
413 | ||
414 | // If there's still a modal dialog active, we | |
415 | // enable it, else we enable all modeless windows | |
416 | if (last) | |
417 | { | |
cc2b7472 VZ |
418 | // VZ: I don't understand what this is supposed to do, so I'll leave |
419 | // it out for now and look for horrible consequences | |
2bda0e17 KB |
420 | wxDialog *box = (wxDialog *)last->Data(); |
421 | HWND hwnd = (HWND) box->GetHWND(); | |
cc2b7472 VZ |
422 | #if 0 |
423 | if (box->IsUserEnabled()) | |
424 | #endif // 0 | |
2bda0e17 KB |
425 | EnableWindow(hwnd, TRUE); |
426 | BringWindowToTop(hwnd); | |
427 | } | |
428 | else | |
429 | { | |
430 | wxNode *node = wxModelessWindows.First(); | |
431 | while (node) | |
432 | { | |
433 | wxWindow *win = (wxWindow *)node->Data(); | |
434 | HWND hwnd = (HWND) win->GetHWND(); | |
435 | // Only enable again if not user-disabled. | |
cc2b7472 | 436 | #if 0 |
2bda0e17 | 437 | if (win->IsUserEnabled()) |
cc2b7472 | 438 | #endif // 0 |
2bda0e17 KB |
439 | EnableWindow(hwnd, TRUE); |
440 | node = node->Next(); | |
441 | } | |
442 | } | |
443 | // Try to highlight the correct window (the parent) | |
444 | HWND hWndParent = 0; | |
445 | if (GetParent()) | |
446 | { | |
447 | hWndParent = (HWND) GetParent()->GetHWND(); | |
448 | if (hWndParent) | |
449 | ::BringWindowToTop(hWndParent); | |
450 | } | |
451 | ShowWindow((HWND) GetHWND(), SW_HIDE); | |
452 | m_modalShowing = FALSE; | |
453 | } | |
454 | } | |
dc1c4b62 | 455 | else // !modal |
2bda0e17 KB |
456 | { |
457 | if (show) | |
458 | { | |
459 | ShowWindow((HWND) GetHWND(), SW_SHOW); | |
460 | BringWindowToTop((HWND) GetHWND()); | |
461 | } | |
462 | else | |
463 | { | |
464 | // Try to highlight the correct window (the parent) | |
465 | HWND hWndParent = 0; | |
466 | if (GetParent()) | |
467 | { | |
468 | hWndParent = (HWND) GetParent()->GetHWND(); | |
469 | if (hWndParent) | |
470 | ::BringWindowToTop(hWndParent); | |
471 | } | |
472 | ShowWindow((HWND) GetHWND(), SW_HIDE); | |
473 | } | |
474 | } | |
475 | return TRUE; | |
476 | } | |
477 | ||
478 | void wxDialog::SetTitle(const wxString& title) | |
479 | { | |
837e5743 | 480 | SetWindowText((HWND) GetHWND(), title.c_str()); |
2bda0e17 KB |
481 | } |
482 | ||
a23fd0e1 | 483 | wxString wxDialog::GetTitle() const |
2bda0e17 KB |
484 | { |
485 | GetWindowText((HWND) GetHWND(), wxBuffer, 1000); | |
486 | return wxString(wxBuffer); | |
487 | } | |
488 | ||
debe6624 | 489 | void wxDialog::Centre(int direction) |
2bda0e17 KB |
490 | { |
491 | int x_offset,y_offset ; | |
492 | int display_width, display_height; | |
493 | int width, height, x, y; | |
dfc54541 JS |
494 | wxWindow *parent = GetParent(); |
495 | if ((direction & wxCENTER_FRAME) && parent) | |
2bda0e17 | 496 | { |
dfc54541 JS |
497 | parent->GetPosition(&x_offset,&y_offset) ; |
498 | parent->GetSize(&display_width,&display_height) ; | |
2bda0e17 KB |
499 | } |
500 | else | |
2bda0e17 KB |
501 | { |
502 | wxDisplaySize(&display_width, &display_height); | |
503 | x_offset = 0 ; | |
504 | y_offset = 0 ; | |
505 | } | |
506 | ||
2bda0e17 KB |
507 | GetSize(&width, &height); |
508 | GetPosition(&x, &y); | |
509 | ||
510 | if (direction & wxHORIZONTAL) | |
511 | x = (int)((display_width - width)/2); | |
512 | if (direction & wxVERTICAL) | |
513 | y = (int)((display_height - height)/2); | |
514 | ||
515 | SetSize(x+x_offset, y+y_offset, width, height); | |
516 | } | |
517 | ||
518 | // Replacement for Show(TRUE) for modal dialogs - returns return code | |
a23fd0e1 | 519 | int wxDialog::ShowModal() |
2bda0e17 | 520 | { |
dc1c4b62 VZ |
521 | m_windowStyle |= wxDIALOG_MODAL; |
522 | Show(TRUE); | |
523 | return GetReturnCode(); | |
2bda0e17 KB |
524 | } |
525 | ||
526 | void wxDialog::EndModal(int retCode) | |
527 | { | |
dc1c4b62 VZ |
528 | SetReturnCode(retCode); |
529 | Show(FALSE); | |
2bda0e17 KB |
530 | } |
531 | ||
532 | // Define for each class of dialog and control | |
debe6624 | 533 | WXHBRUSH wxDialog::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, |
dc1c4b62 | 534 | WXUINT message, WXWPARAM wParam, WXLPARAM lParam) |
2bda0e17 | 535 | { |
1f112209 | 536 | #if wxUSE_CTL3D |
2bda0e17 KB |
537 | HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam); |
538 | return (WXHBRUSH) hbrush; | |
539 | #else | |
540 | return 0; | |
541 | #endif | |
542 | } | |
543 | ||
544 | // Standard buttons | |
545 | void wxDialog::OnOK(wxCommandEvent& event) | |
546 | { | |
dc1c4b62 VZ |
547 | if ( Validate() && TransferDataFromWindow() ) |
548 | { | |
2bda0e17 KB |
549 | if ( IsModal() ) |
550 | EndModal(wxID_OK); | |
551 | else | |
552 | { | |
387a3b02 JS |
553 | SetReturnCode(wxID_OK); |
554 | this->Show(FALSE); | |
2bda0e17 | 555 | } |
dc1c4b62 | 556 | } |
2bda0e17 KB |
557 | } |
558 | ||
559 | void wxDialog::OnApply(wxCommandEvent& event) | |
560 | { | |
dc1c4b62 VZ |
561 | if (Validate()) |
562 | TransferDataFromWindow(); | |
563 | // TODO probably need to disable the Apply button until things change again | |
2bda0e17 KB |
564 | } |
565 | ||
566 | void wxDialog::OnCancel(wxCommandEvent& event) | |
567 | { | |
568 | if ( IsModal() ) | |
569 | EndModal(wxID_CANCEL); | |
570 | else | |
571 | { | |
572 | SetReturnCode(wxID_CANCEL); | |
2a47d3c1 | 573 | this->Show(FALSE); |
2bda0e17 KB |
574 | } |
575 | } | |
576 | ||
e3065973 | 577 | void wxDialog::OnCloseWindow(wxCloseEvent& event) |
2bda0e17 | 578 | { |
e3065973 | 579 | // We'll send a Cancel message by default, |
2bda0e17 | 580 | // which may close the dialog. |
e3065973 JS |
581 | // Check for looping if the Cancel event handler calls Close(). |
582 | ||
583 | // Note that if a cancel button and handler aren't present in the dialog, | |
584 | // nothing will happen when you close the dialog via the window manager, or | |
585 | // via Close(). | |
586 | // We wouldn't want to destroy the dialog by default, since the dialog may have been | |
587 | // created on the stack. | |
588 | // However, this does mean that calling dialog->Close() won't delete the dialog | |
589 | // unless the handler for wxID_CANCEL does so. So use Destroy() if you want to be | |
590 | // sure to destroy the dialog. | |
591 | // The default OnCancel (above) simply ends a modal dialog, and hides a modeless dialog. | |
2bda0e17 KB |
592 | |
593 | static wxList closing; | |
bd9d76cb | 594 | |
2bda0e17 | 595 | if ( closing.Member(this) ) |
e3065973 | 596 | return; |
bd9d76cb | 597 | |
2bda0e17 | 598 | closing.Append(this); |
bd9d76cb | 599 | |
387a3b02 JS |
600 | wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL); |
601 | cancelEvent.SetEventObject( this ); | |
e3065973 | 602 | GetEventHandler()->ProcessEvent(cancelEvent); // This may close the dialog |
2bda0e17 KB |
603 | |
604 | closing.DeleteObject(this); | |
e3065973 | 605 | } |
2bda0e17 | 606 | |
e3065973 | 607 | // Destroy the window (delayed, if a managed window) |
a23fd0e1 | 608 | bool wxDialog::Destroy() |
e3065973 JS |
609 | { |
610 | if (!wxPendingDelete.Member(this)) | |
611 | wxPendingDelete.Append(this); | |
612 | return TRUE; | |
2bda0e17 KB |
613 | } |
614 | ||
94b49b93 JS |
615 | void wxDialog::OnSize(wxSizeEvent& WXUNUSED(event)) |
616 | { | |
617 | // if we're using constraints - do use them | |
618 | #if wxUSE_CONSTRAINTS | |
a23fd0e1 VZ |
619 | if ( GetAutoLayout() ) |
620 | { | |
94b49b93 JS |
621 | Layout(); |
622 | } | |
623 | #endif | |
624 | } | |
625 | ||
2bda0e17 KB |
626 | void wxDialog::OnSysColourChanged(wxSysColourChangedEvent& event) |
627 | { | |
1f112209 | 628 | #if wxUSE_CTL3D |
2bda0e17 KB |
629 | Ctl3dColorChange(); |
630 | #else | |
631 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE)); | |
2bda0e17 KB |
632 | Refresh(); |
633 | #endif | |
68ad65f8 | 634 | } |
42e69d6b VZ |
635 | |
636 | // --------------------------------------------------------------------------- | |
637 | // dialog window proc | |
638 | // --------------------------------------------------------------------------- | |
639 | ||
640 | long wxDialog::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) | |
641 | { | |
642 | long rc = 0; | |
643 | bool processed = FALSE; | |
644 | ||
645 | switch ( message ) | |
646 | { | |
647 | case WM_CLOSE: | |
648 | // if we can't close, tell the system that we processed the | |
649 | // message - otherwise it would close us | |
650 | processed = !Close(); | |
651 | break; | |
652 | } | |
653 | ||
654 | if ( !processed ) | |
655 | rc = wxWindow::MSWWindowProc(message, wParam, lParam); | |
656 | ||
657 | return rc; | |
658 | } |