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