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