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