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