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