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