]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: dialog.cpp | |
3 | // Purpose: wxDialog class | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 17/09/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "dialog.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/dialog.h" | |
17 | #include "wx/utils.h" | |
18 | #include "wx/frame.h" | |
19 | #include "wx/app.h" | |
20 | #include "wx/settings.h" | |
21 | ||
22 | #include <Xm/Xm.h> | |
23 | ||
24 | #include <X11/Shell.h> | |
25 | #if XmVersion >= 1002 | |
26 | #include <Xm/XmAll.h> | |
27 | #endif | |
28 | #include <Xm/MwmUtil.h> | |
29 | #include <Xm/Label.h> | |
30 | #include <Xm/BulletinB.h> | |
31 | #include <Xm/Frame.h> | |
32 | #include <Xm/Text.h> | |
33 | #include <Xm/DialogS.h> | |
34 | #include <Xm/FileSB.h> | |
35 | #include <Xm/RowColumn.h> | |
36 | #include <Xm/LabelG.h> | |
37 | #include <Xm/AtomMgr.h> | |
38 | #if XmVersion > 1000 | |
39 | #include <Xm/Protocols.h> | |
40 | #endif | |
41 | ||
42 | #include "wx/motif/private.h" | |
43 | ||
44 | static void wxCloseDialogCallback(Widget widget, XtPointer client_data, XmAnyCallbackStruct *cbs); | |
45 | static void wxDialogBoxEventHandler (Widget wid, | |
46 | XtPointer client_data, | |
47 | XEvent* event, | |
48 | Boolean *continueToDispatch); | |
49 | ||
50 | static void wxUnmapBulletinBoard(Widget dialog, wxDialog *client,XtPointer call); | |
51 | ||
52 | // A stack of modal_showing flags, since we can't rely | |
53 | // on accessing wxDialog::m_modalShowing within | |
54 | // wxDialog::Show in case a callback has deleted the wxDialog. | |
55 | static wxList wxModalShowingStack; | |
56 | ||
57 | // Lists to keep track of windows, so we can disable/enable them | |
58 | // for modal dialogs | |
59 | wxList wxModalDialogs; | |
60 | wxList wxModelessWindows; // Frames and modeless dialogs | |
61 | extern wxList wxPendingDelete; | |
62 | ||
63 | extern wxHashTable *wxWidgetHashTable; | |
64 | ||
65 | #define wxUSE_INVISIBLE_RESIZE 1 | |
66 | ||
67 | #if !USE_SHARED_LIBRARY | |
68 | IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxPanel) | |
69 | ||
70 | BEGIN_EVENT_TABLE(wxDialog, wxPanel) | |
71 | EVT_BUTTON(wxID_OK, wxDialog::OnOK) | |
72 | EVT_BUTTON(wxID_APPLY, wxDialog::OnApply) | |
73 | EVT_BUTTON(wxID_CANCEL, wxDialog::OnCancel) | |
74 | EVT_CHAR_HOOK(wxDialog::OnCharHook) | |
75 | EVT_SYS_COLOUR_CHANGED(wxDialog::OnSysColourChanged) | |
76 | EVT_CLOSE(wxDialog::OnCloseWindow) | |
77 | END_EVENT_TABLE() | |
78 | ||
79 | #endif | |
80 | ||
81 | wxDialog::wxDialog() | |
82 | { | |
83 | m_modalShowing = FALSE; | |
84 | m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE); | |
85 | } | |
86 | ||
87 | bool wxDialog::Create(wxWindow *parent, wxWindowID id, | |
88 | const wxString& title, | |
89 | const wxPoint& pos, | |
90 | const wxSize& size, | |
91 | long style, | |
92 | const wxString& name) | |
93 | { | |
94 | m_windowStyle = style; | |
95 | m_modalShowing = FALSE; | |
96 | m_dialogTitle = title; | |
97 | ||
98 | m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE); | |
99 | m_foregroundColour = *wxBLACK; | |
100 | ||
101 | SetName(name); | |
102 | ||
103 | if (!parent) | |
104 | wxTopLevelWindows.Append(this); | |
105 | ||
106 | if (parent) parent->AddChild(this); | |
107 | ||
108 | if ( id == -1 ) | |
109 | m_windowId = (int)NewControlId(); | |
110 | else | |
111 | m_windowId = id; | |
112 | ||
113 | Widget parentWidget = (Widget) 0; | |
114 | if (parent) | |
115 | parentWidget = (Widget) parent->GetTopWidget(); | |
116 | if (!parent) | |
117 | parentWidget = (Widget) wxTheApp->GetTopLevelWidget(); | |
118 | ||
119 | wxASSERT_MSG( (parentWidget != (Widget) 0), "Could not find a suitable parent shell for dialog." ); | |
120 | ||
121 | Arg args[2]; | |
122 | XtSetArg (args[0], XmNdefaultPosition, False); | |
123 | XtSetArg (args[1], XmNautoUnmanage, False); | |
124 | Widget dialogShell = XmCreateBulletinBoardDialog(parentWidget, (char*) (const char*) name, args, 2); | |
125 | m_mainWidget = (WXWidget) dialogShell; | |
126 | ||
127 | // We don't want margins, since there is enough elsewhere. | |
128 | XtVaSetValues(dialogShell, | |
129 | XmNmarginHeight, 0, | |
130 | XmNmarginWidth, 0, | |
131 | XmNresizePolicy, XmRESIZE_NONE, | |
132 | NULL) ; | |
133 | ||
134 | Widget shell = XtParent(dialogShell) ; | |
135 | if (!title.IsNull()) | |
136 | { | |
137 | XmString str = XmStringCreateSimple((char*) (const char*)title); | |
138 | XtVaSetValues(dialogShell, | |
139 | XmNdialogTitle, str, | |
140 | NULL); | |
141 | XmStringFree(str); | |
142 | } | |
143 | ||
144 | m_font = wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT); | |
145 | ChangeFont(FALSE); | |
146 | ||
147 | wxAddWindowToTable(dialogShell, this); | |
148 | ||
149 | // Intercept CLOSE messages from the window manager | |
150 | Atom WM_DELETE_WINDOW = XmInternAtom(XtDisplay(shell), "WM_DELETE_WINDOW", False); | |
151 | ||
152 | /* Remove and add WM_DELETE_WINDOW so ours is only handler */ | |
153 | /* Why do we have to do this for wxDialog, but not wxFrame? */ | |
154 | XmRemoveWMProtocols(shell, &WM_DELETE_WINDOW, 1); | |
155 | XmAddWMProtocols(shell, &WM_DELETE_WINDOW, 1); | |
156 | XmActivateWMProtocol(shell, WM_DELETE_WINDOW); | |
157 | ||
158 | // Modified Steve Hammes for Motif 2.0 | |
159 | #if (XmREVISION > 1 || XmVERSION > 1) | |
160 | XmAddWMProtocolCallback(shell, WM_DELETE_WINDOW, (XtCallbackProc) wxCloseDialogCallback, (XtPointer)this); | |
161 | #elif XmREVISION == 1 | |
162 | XmAddWMProtocolCallback(shell, WM_DELETE_WINDOW, (XtCallbackProc) wxCloseDialogCallback, (caddr_t)this); | |
163 | #else | |
164 | XmAddWMProtocolCallback(shell, WM_DELETE_WINDOW, (void (*)())wxCloseDialogCallback, (caddr_t)this); | |
165 | #endif | |
166 | ||
167 | XtTranslations ptr ; | |
168 | XtOverrideTranslations(dialogShell, | |
169 | ptr = XtParseTranslationTable("<Configure>: resize()")); | |
170 | XtFree((char *)ptr); | |
171 | ||
172 | // Can't remember what this was about... but I think it's necessary. | |
173 | ||
174 | if (wxUSE_INVISIBLE_RESIZE) | |
175 | { | |
176 | if (pos.x > -1) | |
177 | XtVaSetValues(dialogShell, XmNx, pos.x, | |
178 | NULL); | |
179 | if (pos.y > -1) | |
180 | XtVaSetValues(dialogShell, XmNy, pos.y, | |
181 | NULL); | |
182 | ||
183 | if (size.x > -1) | |
184 | XtVaSetValues(dialogShell, XmNwidth, size.x, NULL); | |
185 | if (size.y > -1) | |
186 | XtVaSetValues(dialogShell, XmNheight, size.y, NULL); | |
187 | } | |
188 | ||
189 | // This patch come from Torsten Liermann lier@lier1.muc.de | |
190 | if (XmIsMotifWMRunning(shell)) | |
191 | { | |
192 | int decor = 0 ; | |
193 | if (m_windowStyle & wxRESIZE_BORDER) | |
194 | decor |= MWM_DECOR_RESIZEH ; | |
195 | if (m_windowStyle & wxSYSTEM_MENU) | |
196 | decor |= MWM_DECOR_MENU; | |
197 | if ((m_windowStyle & wxCAPTION) || | |
198 | (m_windowStyle & wxTINY_CAPTION_HORIZ) || | |
199 | (m_windowStyle & wxTINY_CAPTION_VERT)) | |
200 | decor |= MWM_DECOR_TITLE; | |
201 | if (m_windowStyle & wxTHICK_FRAME) | |
202 | decor |= MWM_DECOR_BORDER; | |
203 | if (m_windowStyle & wxMINIMIZE_BOX) | |
204 | decor |= MWM_DECOR_MINIMIZE; | |
205 | if (m_windowStyle & wxMAXIMIZE_BOX) | |
206 | decor |= MWM_DECOR_MAXIMIZE; | |
207 | ||
208 | XtVaSetValues(shell,XmNmwmDecorations,decor,NULL) ; | |
209 | } | |
210 | // This allows non-Motif window managers to support at least the | |
211 | // no-decorations case. | |
212 | else | |
213 | { | |
214 | if ((m_windowStyle & wxCAPTION) != wxCAPTION) | |
215 | XtVaSetValues((Widget) shell,XmNoverrideRedirect,TRUE,NULL); | |
216 | } | |
217 | ||
218 | XtRealizeWidget(dialogShell); | |
219 | ||
220 | XtAddCallback(dialogShell,XmNunmapCallback, | |
221 | (XtCallbackProc)wxUnmapBulletinBoard,this) ; | |
222 | ||
223 | // Positioning of the dialog doesn't work properly unless the dialog | |
224 | // is managed, so we manage without mapping to the screen. | |
225 | // To show, we map the shell (actually it's parent). | |
226 | if (!wxUSE_INVISIBLE_RESIZE) | |
227 | XtVaSetValues(shell, XmNmappedWhenManaged, FALSE, NULL); | |
228 | ||
229 | if (!wxUSE_INVISIBLE_RESIZE) | |
230 | { | |
231 | XtManageChild(dialogShell); | |
232 | SetSize(pos.x, pos.y, size.x, size.y); | |
233 | } | |
234 | XtAddEventHandler(dialogShell,ExposureMask,FALSE, | |
235 | wxUniversalRepaintProc, (XtPointer) this); | |
236 | ||
237 | XtAddEventHandler(dialogShell, | |
238 | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | KeyPressMask, | |
239 | FALSE, | |
240 | wxDialogBoxEventHandler, | |
241 | (XtPointer)this); | |
242 | ||
243 | ChangeBackgroundColour(); | |
244 | ||
245 | return TRUE; | |
246 | } | |
247 | ||
248 | void wxDialog::SetModal(bool flag) | |
249 | { | |
250 | if ( flag ) | |
251 | m_windowStyle |= wxDIALOG_MODAL ; | |
252 | else | |
253 | if ( m_windowStyle & wxDIALOG_MODAL ) | |
254 | m_windowStyle -= wxDIALOG_MODAL ; | |
255 | ||
256 | wxModelessWindows.DeleteObject(this); | |
257 | if (!flag) | |
258 | wxModelessWindows.Append(this); | |
259 | } | |
260 | ||
261 | wxDialog::~wxDialog() | |
262 | { | |
263 | if (m_mainWidget) | |
264 | XtRemoveEventHandler((Widget) m_mainWidget, ExposureMask, FALSE, | |
265 | wxUniversalRepaintProc, (XtPointer) this); | |
266 | ||
267 | m_modalShowing = FALSE; | |
268 | if (!wxUSE_INVISIBLE_RESIZE && m_mainWidget) | |
269 | { | |
270 | XtUnmapWidget((Widget) m_mainWidget); | |
271 | } | |
272 | ||
273 | wxTopLevelWindows.DeleteObject(this); | |
274 | ||
275 | if ( (GetWindowStyleFlag() & wxDIALOG_MODAL) != wxDIALOG_MODAL ) | |
276 | wxModelessWindows.DeleteObject(this); | |
277 | ||
278 | // If this is the last top-level window, exit. | |
279 | if (wxTheApp && (wxTopLevelWindows.Number() == 0)) | |
280 | { | |
281 | wxTheApp->SetTopWindow(NULL); | |
282 | ||
283 | if (wxTheApp->GetExitOnFrameDelete()) | |
284 | { | |
285 | wxTheApp->ExitMainLoop(); | |
286 | } | |
287 | } | |
288 | ||
289 | // This event-flushing code used to be in wxWindow::PostDestroyChildren (wx_dialog.cpp) | |
290 | // but I think this should work, if we destroy the children first. | |
291 | // Note that this might need to be done for wxFrame also. | |
292 | DestroyChildren(); | |
293 | ||
294 | // The idea about doing it here is that if you have to remove the | |
295 | // XtDestroyWidget from ~wxWindow, at least top-level windows | |
296 | // will still be deleted (and destroy children implicitly). | |
297 | if (GetMainWidget()) | |
298 | { | |
299 | DetachWidget(GetMainWidget()); // Removes event handlers | |
300 | XtDestroyWidget((Widget) GetMainWidget()); | |
301 | SetMainWidget((WXWidget) NULL); | |
302 | } | |
303 | } | |
304 | ||
305 | // By default, pressing escape cancels the dialog | |
306 | void wxDialog::OnCharHook(wxKeyEvent& event) | |
307 | { | |
308 | if (event.m_keyCode == WXK_ESCAPE) | |
309 | { | |
310 | // Behaviour changed in 2.0: we'll send a Cancel message | |
311 | // to the dialog instead of Close. | |
312 | wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL); | |
313 | cancelEvent.SetEventObject( this ); | |
314 | GetEventHandler()->ProcessEvent(cancelEvent); | |
315 | ||
316 | return; | |
317 | } | |
318 | // We didn't process this event. | |
319 | event.Skip(); | |
320 | } | |
321 | ||
322 | void wxDialog::Iconize(bool WXUNUSED(iconize)) | |
323 | { | |
324 | // Can't iconize a dialog in Motif, apparently | |
325 | // TODO: try using the parent of m_mainShell. | |
326 | // XtVaSetValues((Widget) m_mainWidget, XmNiconic, iconize, NULL); | |
327 | } | |
328 | ||
329 | bool wxDialog::IsIconized() const | |
330 | { | |
331 | /* | |
332 | Boolean iconic; | |
333 | XtVaGetValues((Widget) m_mainWidget, XmNiconic, &iconic, NULL); | |
334 | ||
335 | return iconic; | |
336 | */ | |
337 | return FALSE; | |
338 | } | |
339 | ||
340 | void wxDialog::DoSetSize(int x, int y, int width, int height, int sizeFlags) | |
341 | { | |
342 | XtVaSetValues((Widget) m_mainWidget, XmNresizePolicy, XmRESIZE_ANY, NULL); | |
343 | wxWindow::DoSetSize(x, y, width, height, sizeFlags); | |
344 | XtVaSetValues((Widget) m_mainWidget, XmNresizePolicy, XmRESIZE_NONE, NULL); | |
345 | } | |
346 | ||
347 | void wxDialog::DoSetClientSize(int width, int height) | |
348 | { | |
349 | wxWindow::SetSize(-1, -1, width, height); | |
350 | } | |
351 | ||
352 | void wxDialog::SetTitle(const wxString& title) | |
353 | { | |
354 | m_dialogTitle = title; | |
355 | if (!title.IsNull()) | |
356 | { | |
357 | XmString str = XmStringCreateSimple((char*) (const char*) title); | |
358 | XtVaSetValues((Widget) m_mainWidget, | |
359 | XmNtitle, (char*) (const char*) title, | |
360 | XmNdialogTitle, str, // Roberto Cocchi | |
361 | XmNiconName, (char*) (const char*) title, | |
362 | NULL); | |
363 | XmStringFree(str); | |
364 | } | |
365 | } | |
366 | ||
367 | wxString wxDialog::GetTitle() const | |
368 | { | |
369 | return m_dialogTitle; | |
370 | } | |
371 | ||
372 | void wxDialog::Raise() | |
373 | { | |
374 | Window parent_window = XtWindow((Widget) m_mainWidget), | |
375 | next_parent = XtWindow((Widget) m_mainWidget), | |
376 | root = RootWindowOfScreen(XtScreen((Widget) m_mainWidget)); | |
377 | // search for the parent that is child of ROOT, because the WM may | |
378 | // reparent twice and notify only the next parent (like FVWM) | |
379 | while (next_parent != root) { | |
380 | Window *theChildren; unsigned int n; | |
381 | parent_window = next_parent; | |
382 | XQueryTree(XtDisplay((Widget) m_mainWidget), parent_window, &root, | |
383 | &next_parent, &theChildren, &n); | |
384 | XFree(theChildren); // not needed | |
385 | } | |
386 | XRaiseWindow(XtDisplay((Widget) m_mainWidget), parent_window); | |
387 | } | |
388 | ||
389 | void wxDialog::Lower() | |
390 | { | |
391 | Window parent_window = XtWindow((Widget) m_mainWidget), | |
392 | next_parent = XtWindow((Widget) m_mainWidget), | |
393 | root = RootWindowOfScreen(XtScreen((Widget) m_mainWidget)); | |
394 | // search for the parent that is child of ROOT, because the WM may | |
395 | // reparent twice and notify only the next parent (like FVWM) | |
396 | while (next_parent != root) { | |
397 | Window *theChildren; unsigned int n; | |
398 | parent_window = next_parent; | |
399 | XQueryTree(XtDisplay((Widget) m_mainWidget), parent_window, &root, | |
400 | &next_parent, &theChildren, &n); | |
401 | XFree(theChildren); // not needed | |
402 | } | |
403 | XLowerWindow(XtDisplay((Widget) m_mainWidget), parent_window); | |
404 | } | |
405 | ||
406 | bool wxDialog::Show(bool show) | |
407 | { | |
408 | m_isShown = show; | |
409 | ||
410 | if (show) | |
411 | { | |
412 | if (!wxUSE_INVISIBLE_RESIZE) | |
413 | XtMapWidget(XtParent((Widget) m_mainWidget)); | |
414 | else | |
415 | XtManageChild((Widget) m_mainWidget) ; | |
416 | ||
417 | XRaiseWindow(XtDisplay((Widget) m_mainWidget), XtWindow((Widget) m_mainWidget)); | |
418 | ||
419 | } | |
420 | else | |
421 | { | |
422 | if (!wxUSE_INVISIBLE_RESIZE) | |
423 | XtUnmapWidget(XtParent((Widget) m_mainWidget)); | |
424 | else | |
425 | XtUnmanageChild((Widget) m_mainWidget) ; | |
426 | ||
427 | XFlush(XtDisplay((Widget) wxTheApp->GetTopLevelWidget())); | |
428 | XSync(XtDisplay((Widget) wxTheApp->GetTopLevelWidget()), FALSE); | |
429 | } | |
430 | ||
431 | return TRUE; | |
432 | } | |
433 | ||
434 | // Shows a dialog modally, returning a return code | |
435 | int wxDialog::ShowModal() | |
436 | { | |
437 | m_windowStyle |= wxDIALOG_MODAL; | |
438 | ||
439 | Show(TRUE); | |
440 | ||
441 | if (m_modalShowing) | |
442 | return 0; | |
443 | ||
444 | wxModalShowingStack.Insert((wxObject *)TRUE); | |
445 | ||
446 | m_modalShowing = TRUE; | |
447 | XtAddGrab((Widget) m_mainWidget, TRUE, FALSE); | |
448 | ||
449 | XEvent event; | |
450 | ||
451 | // Loop until we signal that the dialog should be closed | |
452 | while ((wxModalShowingStack.Number() > 0) && ((int)(wxModalShowingStack.First()->Data()) != 0)) | |
453 | { | |
454 | // XtAppProcessEvent((XtAppContext) wxTheApp->GetAppContext(), XtIMAll); | |
455 | ||
456 | XtAppNextEvent((XtAppContext) wxTheApp->GetAppContext(), &event); | |
457 | wxTheApp->ProcessXEvent((WXEvent*) &event); | |
458 | } | |
459 | ||
460 | // Remove modal dialog flag from stack | |
461 | wxNode *node = wxModalShowingStack.First(); | |
462 | if (node) | |
463 | delete node; | |
464 | ||
465 | // Now process all events in case they get sent to a destroyed dialog | |
466 | XSync(XtDisplay((Widget) wxTheApp->GetTopLevelWidget()), FALSE); | |
467 | while (XtAppPending((XtAppContext) wxTheApp->GetAppContext())) | |
468 | { | |
469 | XFlush(XtDisplay((Widget) wxTheApp->GetTopLevelWidget())); | |
470 | XtAppNextEvent((XtAppContext) wxTheApp->GetAppContext(), &event); | |
471 | ||
472 | wxTheApp->ProcessXEvent((WXEvent*) &event); | |
473 | } | |
474 | ||
475 | // TODO: is it safe to call this, if the dialog may have been deleted | |
476 | // by now? Probably only if we're using delayed deletion of dialogs. | |
477 | return GetReturnCode(); | |
478 | } | |
479 | ||
480 | void wxDialog::EndModal(int retCode) | |
481 | { | |
482 | if (!m_modalShowing) | |
483 | return; | |
484 | ||
485 | SetReturnCode(retCode); | |
486 | ||
487 | // Strangely, we don't seem to need this now. | |
488 | // XtRemoveGrab((Widget) m_mainWidget); | |
489 | ||
490 | Show(FALSE); | |
491 | ||
492 | m_modalShowing = FALSE; | |
493 | ||
494 | wxNode *node = wxModalShowingStack.First(); | |
495 | if (node) | |
496 | node->SetData((wxObject *)FALSE); | |
497 | } | |
498 | ||
499 | // Standard buttons | |
500 | void wxDialog::OnOK(wxCommandEvent& WXUNUSED(event)) | |
501 | { | |
502 | if ( Validate() && TransferDataFromWindow() ) | |
503 | { | |
504 | if ( IsModal() ) | |
505 | EndModal(wxID_OK); | |
506 | else | |
507 | { | |
508 | SetReturnCode(wxID_OK); | |
509 | this->Show(FALSE); | |
510 | } | |
511 | } | |
512 | } | |
513 | ||
514 | void wxDialog::OnApply(wxCommandEvent& WXUNUSED(event)) | |
515 | { | |
516 | if (Validate()) | |
517 | TransferDataFromWindow(); | |
518 | // TODO probably need to disable the Apply button until things change again | |
519 | } | |
520 | ||
521 | void wxDialog::OnCancel(wxCommandEvent& WXUNUSED(event)) | |
522 | { | |
523 | if ( IsModal() ) | |
524 | EndModal(wxID_CANCEL); | |
525 | else | |
526 | { | |
527 | SetReturnCode(wxID_CANCEL); | |
528 | this->Show(FALSE); | |
529 | } | |
530 | } | |
531 | ||
532 | void wxDialog::OnCloseWindow(wxCloseEvent& event) | |
533 | { | |
534 | // We'll send a Cancel message by default, | |
535 | // which may close the dialog. | |
536 | // Check for looping if the Cancel event handler calls Close(). | |
537 | ||
538 | // Note that if a cancel button and handler aren't present in the dialog, | |
539 | // nothing will happen when you close the dialog via the window manager, or | |
540 | // via Close(). | |
541 | // We wouldn't want to destroy the dialog by default, since the dialog may have been | |
542 | // created on the stack. | |
543 | // However, this does mean that calling dialog->Close() won't delete the dialog | |
544 | // unless the handler for wxID_CANCEL does so. So use Destroy() if you want to be | |
545 | // sure to destroy the dialog. | |
546 | // The default OnCancel (above) simply ends a modal dialog, and hides a modeless dialog. | |
547 | ||
548 | static wxList closing; | |
549 | ||
550 | if ( closing.Member(this) ) | |
551 | return; | |
552 | ||
553 | closing.Append(this); | |
554 | ||
555 | wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL); | |
556 | cancelEvent.SetEventObject( this ); | |
557 | GetEventHandler()->ProcessEvent(cancelEvent); // This may close the dialog | |
558 | ||
559 | closing.DeleteObject(this); | |
560 | } | |
561 | ||
562 | void wxDialog::OnPaint(wxPaintEvent &WXUNUSED(event)) | |
563 | { | |
564 | // added for compatiblity only | |
565 | } | |
566 | ||
567 | // Destroy the window (delayed, if a managed window) | |
568 | bool wxDialog::Destroy() | |
569 | { | |
570 | if (!wxPendingDelete.Member(this)) | |
571 | wxPendingDelete.Append(this); | |
572 | return TRUE; | |
573 | } | |
574 | ||
575 | void wxDialog::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(event)) | |
576 | { | |
577 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE)); | |
578 | Refresh(); | |
579 | } | |
580 | ||
581 | // Handle a close event from the window manager | |
582 | static void wxCloseDialogCallback( Widget WXUNUSED(widget), XtPointer client_data, | |
583 | XmAnyCallbackStruct *WXUNUSED(cbs)) | |
584 | { | |
585 | wxDialog *dialog = (wxDialog *)client_data; | |
586 | wxCloseEvent closeEvent(wxEVT_CLOSE_WINDOW, dialog->GetId()); | |
587 | closeEvent.SetEventObject(dialog); | |
588 | ||
589 | // May delete the dialog (with delayed deletion) | |
590 | dialog->GetEventHandler()->ProcessEvent(closeEvent); | |
591 | } | |
592 | ||
593 | void wxDialogBoxEventHandler(Widget wid, | |
594 | XtPointer WXUNUSED(client_data), | |
595 | XEvent* event, | |
596 | Boolean* continueToDispatch) | |
597 | { | |
598 | wxDialog *dialog = (wxDialog *)wxGetWindowFromTable(wid); | |
599 | if (dialog) | |
600 | { | |
601 | wxMouseEvent wxevent(wxEVT_NULL); | |
602 | if (wxTranslateMouseEvent(wxevent, dialog, wid, event)) | |
603 | { | |
604 | wxevent.SetEventObject(dialog); | |
605 | wxevent.SetId(dialog->GetId()); | |
606 | dialog->GetEventHandler()->ProcessEvent(wxevent); | |
607 | } | |
608 | else | |
609 | { | |
610 | // An attempt to implement OnCharHook by calling OnCharHook first; | |
611 | // if this returns TRUE, set continueToDispatch to False | |
612 | // (don't continue processing). | |
613 | // Otherwise set it to True and call OnChar. | |
614 | wxKeyEvent keyEvent(wxEVT_CHAR); | |
615 | if (wxTranslateKeyEvent(keyEvent, dialog, wid, event)) | |
616 | { | |
617 | keyEvent.SetEventObject(dialog); | |
618 | keyEvent.SetId(dialog->GetId()); | |
619 | keyEvent.SetEventType(wxEVT_CHAR_HOOK); | |
620 | if (dialog->GetEventHandler()->ProcessEvent(keyEvent)) | |
621 | { | |
622 | *continueToDispatch = False; | |
623 | return; | |
624 | } | |
625 | else | |
626 | { | |
627 | // For simplicity, OnKeyDown is the same as OnChar | |
628 | // TODO: filter modifier key presses from OnChar | |
629 | keyEvent.SetEventType(wxEVT_KEY_DOWN); | |
630 | ||
631 | // Only process OnChar if OnKeyDown didn't swallow it | |
632 | if (!dialog->GetEventHandler()->ProcessEvent (keyEvent)) | |
633 | { | |
634 | keyEvent.SetEventType(wxEVT_CHAR); | |
635 | dialog->GetEventHandler()->ProcessEvent(keyEvent); | |
636 | } | |
637 | } | |
638 | } | |
639 | } | |
640 | } | |
641 | *continueToDispatch = True; | |
642 | } | |
643 | ||
644 | static void wxUnmapBulletinBoard(Widget WXUNUSED(dialog), wxDialog *WXUNUSED(client), XtPointer WXUNUSED(call) ) | |
645 | { | |
646 | /* This gets called when the dialog is being shown, which | |
647 | * defeats modal showing. | |
648 | client->m_modalShowing = FALSE ; | |
649 | client->m_isShown = FALSE; | |
650 | */ | |
651 | } | |
652 | ||
653 | void wxDialog::ChangeFont(bool keepOriginalSize) | |
654 | { | |
655 | wxWindow::ChangeFont(keepOriginalSize); | |
656 | } | |
657 | ||
658 | void wxDialog::ChangeBackgroundColour() | |
659 | { | |
660 | if (GetMainWidget()) | |
661 | DoChangeBackgroundColour(GetMainWidget(), m_backgroundColour); | |
662 | } | |
663 | ||
664 | void wxDialog::ChangeForegroundColour() | |
665 | { | |
666 | if (GetMainWidget()) | |
667 | DoChangeForegroundColour(GetMainWidget(), m_foregroundColour); | |
668 | } | |
669 |