]> git.saurik.com Git - wxWidgets.git/blame - src/motif/dialog.cpp
catch unhandled exceptions in POSIX threads implementation the same way wxMSW does
[wxWidgets.git] / src / motif / dialog.cpp
CommitLineData
4bb6408c 1/////////////////////////////////////////////////////////////////////////////
55034339 2// Name: src/motif/dialog.cpp
4bb6408c
JS
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
65571936 9// Licence: wxWindows licence
4bb6408c
JS
10/////////////////////////////////////////////////////////////////////////////
11
1248b41f
MB
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
bcd055ae
JJ
15#ifdef __VMS
16#define XtDisplay XTDISPLAY
17#define XtWindow XTWINDOW
18#define XtParent XTPARENT
19#define XtScreen XTSCREEN
20#endif
21
4bb6408c 22#include "wx/dialog.h"
670f9935
WS
23
24#ifndef WX_PRECOMP
25 #include "wx/app.h"
de6185e2 26 #include "wx/utils.h"
9eddec69 27 #include "wx/settings.h"
670f9935
WS
28#endif
29
7e1bcfa8 30#include "wx/evtloop.h"
4bb6408c 31
338dd992
JJ
32#ifdef __VMS__
33#pragma message disable nosimpint
34#endif
dfc54541
JS
35#include <Xm/Xm.h>
36
37#include <X11/Shell.h>
38#if XmVersion >= 1002
39#include <Xm/XmAll.h>
40#endif
41#include <Xm/MwmUtil.h>
42#include <Xm/Label.h>
43#include <Xm/BulletinB.h>
44#include <Xm/Frame.h>
45#include <Xm/Text.h>
46#include <Xm/DialogS.h>
47#include <Xm/FileSB.h>
48#include <Xm/RowColumn.h>
49#include <Xm/LabelG.h>
50#include <Xm/AtomMgr.h>
51#if XmVersion > 1000
52#include <Xm/Protocols.h>
53#endif
338dd992
JJ
54#ifdef __VMS__
55#pragma message enable nosimpint
56#endif
dfc54541
JS
57
58#include "wx/motif/private.h"
59
dfc54541
JS
60// A stack of modal_showing flags, since we can't rely
61// on accessing wxDialog::m_modalShowing within
62// wxDialog::Show in case a callback has deleted the wxDialog.
7e1bcfa8 63// static wxList wxModalShowingStack;
dfc54541 64
4bb6408c
JS
65// Lists to keep track of windows, so we can disable/enable them
66// for modal dialogs
67wxList wxModalDialogs;
798a4529 68extern wxList wxModelessWindows; // Frames and modeless dialogs
4bb6408c 69
47d67540 70#define wxUSE_INVISIBLE_RESIZE 1
dfc54541 71
798a4529 72IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxTopLevelWindow)
4bb6408c 73
4bb6408c
JS
74wxDialog::wxDialog()
75{
96be256b 76 m_modalShowing = false;
7e1bcfa8 77 m_eventLoop = NULL;
4bb6408c
JS
78}
79
80bool wxDialog::Create(wxWindow *parent, wxWindowID id,
2d120f83
JS
81 const wxString& title,
82 const wxPoint& pos,
83 const wxSize& size,
84 long style,
85 const wxString& name)
4bb6408c 86{
798a4529
MB
87 SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG);
88
89 if( !wxTopLevelWindow::Create( parent, id, title, pos, size, style,
90 name ) )
96be256b 91 return false;
798a4529 92
96be256b 93 m_modalShowing = false;
7e1bcfa8 94 m_eventLoop = NULL;
dfe1eee3 95
798a4529 96 Widget dialogShell = (Widget) m_mainWidget;
798a4529
MB
97
98 SetTitle( title );
dfe1eee3 99
dfc54541 100 // Can't remember what this was about... but I think it's necessary.
355b4d3d
WS
101#if wxUSE_INVISIBLE_RESIZE
102 if (pos.x > -1)
103 XtVaSetValues(dialogShell, XmNx, pos.x,
104 NULL);
105 if (pos.y > -1)
106 XtVaSetValues(dialogShell, XmNy, pos.y,
107 NULL);
108
109 if (size.x > -1)
110 XtVaSetValues(dialogShell, XmNwidth, size.x, NULL);
111 if (size.y > -1)
112 XtVaSetValues(dialogShell, XmNheight, size.y, NULL);
113#endif
dfe1eee3 114
dfc54541
JS
115 // Positioning of the dialog doesn't work properly unless the dialog
116 // is managed, so we manage without mapping to the screen.
117 // To show, we map the shell (actually it's parent).
355b4d3d 118#if !wxUSE_INVISIBLE_RESIZE
31df756d 119 Widget shell = XtParent(dialogShell) ;
355b4d3d
WS
120 XtVaSetValues(shell, XmNmappedWhenManaged, False, NULL);
121#endif
122
123#if !wxUSE_INVISIBLE_RESIZE
124 XtManageChild(dialogShell);
125 SetSize(pos.x, pos.y, size.x, size.y);
126#endif
dfe1eee3 127
96be256b 128 XtAddEventHandler(dialogShell,ExposureMask,False,
2e35f56f 129 wxUniversalRepaintProc, (XtPointer) this);
dfe1eee3 130
105fbe1f 131 PostCreation();
dfe1eee3 132
96be256b 133 return true;
4bb6408c
JS
134}
135
02bcd285 136bool wxDialog::XmDoCreateTLW(wxWindow* parent,
355b4d3d
WS
137 wxWindowID WXUNUSED(id),
138 const wxString& WXUNUSED(title),
139 const wxPoint& WXUNUSED(pos),
140 const wxSize& WXUNUSED(size),
141 long WXUNUSED(style),
f58585c0 142 const wxString& name)
798a4529
MB
143{
144 Widget parentWidget = (Widget) 0;
145 if( parent )
146 parentWidget = (Widget) parent->GetTopWidget();
147 if( !parent )
148 parentWidget = (Widget) wxTheApp->GetTopLevelWidget();
149
150 wxASSERT_MSG( (parentWidget != (Widget) 0),
151 "Could not find a suitable parent shell for dialog." );
152
153 Arg args[2];
154 XtSetArg (args[0], XmNdefaultPosition, False);
155 XtSetArg (args[1], XmNautoUnmanage, False);
156 Widget dialogShell =
d3a80c92 157 XmCreateBulletinBoardDialog( parentWidget,
6991087b 158 name.char_str(),
798a4529
MB
159 args, 2);
160 m_mainWidget = (WXWidget) dialogShell;
161
162 // We don't want margins, since there is enough elsewhere.
163 XtVaSetValues( dialogShell,
164 XmNmarginHeight, 0,
165 XmNmarginWidth, 0,
166 XmNresizePolicy, XmRESIZE_NONE,
167 NULL ) ;
168
169 XtTranslations ptr ;
170 XtOverrideTranslations(dialogShell,
171 ptr = XtParseTranslationTable("<Configure>: resize()"));
172 XtFree((char *)ptr);
173
174 XtRealizeWidget(dialogShell);
175
176 wxAddWindowToTable( (Widget)m_mainWidget, this );
177
96be256b 178 return true;
798a4529
MB
179}
180
4bb6408c
JS
181void wxDialog::SetModal(bool flag)
182{
5f9a153c 183 if ( flag )
31df756d
VZ
184 wxModelessWindows.DeleteObject(this);
185 else
186 wxModelessWindows.Append(this);
4bb6408c
JS
187}
188
189wxDialog::~wxDialog()
190{
96be256b 191 m_isBeingDeleted = true;
2187eef5 192
7e1bcfa8 193 delete m_eventLoop;
798a4529 194
2e35f56f 195 if (m_mainWidget)
798a4529 196 {
96be256b 197 XtRemoveEventHandler((Widget) m_mainWidget, ExposureMask, False,
798a4529
MB
198 wxUniversalRepaintProc, (XtPointer) this);
199 }
dfe1eee3 200
96be256b 201 m_modalShowing = false;
355b4d3d
WS
202
203#if !wxUSE_INVISIBLE_RESIZE
204 if (m_mainWidget)
dfc54541 205 {
2d120f83 206 XtUnmapWidget((Widget) m_mainWidget);
dfc54541 207 }
355b4d3d 208#endif
2187eef5
MB
209
210 PreDestroy();
dfe1eee3 211
f58585c0 212 if ( m_mainWidget )
cba2db0c 213 {
798a4529
MB
214 wxDeleteWindowFromTable( (Widget)m_mainWidget );
215 XtDestroyWidget( (Widget)m_mainWidget );
dfc54541 216 }
4bb6408c
JS
217}
218
bfc6fde4 219void wxDialog::DoSetSize(int x, int y, int width, int height, int sizeFlags)
4bb6408c 220{
dfc54541 221 XtVaSetValues((Widget) m_mainWidget, XmNresizePolicy, XmRESIZE_ANY, NULL);
bfc6fde4 222 wxWindow::DoSetSize(x, y, width, height, sizeFlags);
dfc54541 223 XtVaSetValues((Widget) m_mainWidget, XmNresizePolicy, XmRESIZE_NONE, NULL);
4bb6408c
JS
224}
225
ad813b00
JS
226void wxDialog::DoSetClientSize(int width, int height)
227{
228 wxWindow::SetSize(-1, -1, width, height);
229}
230
4bb6408c
JS
231void wxDialog::SetTitle(const wxString& title)
232{
798a4529 233 wxTopLevelWindow::SetTitle( title );
4bb6408c 234
798a4529
MB
235 if( !title.empty() )
236 {
237 wxXmString str( title );
238 XtVaSetValues( (Widget)m_mainWidget,
6991087b 239 XmNtitle, (const char*)title.mb_str(),
9b135950 240 XmNdialogTitle, str(),
6991087b 241 XmNiconName, (const char*)title.mb_str(),
798a4529 242 NULL );
dfc54541 243 }
dfc54541
JS
244}
245
798a4529 246bool wxDialog::Show( bool show )
dfc54541 247{
5a2e3d8c
MB
248 if( !wxWindowBase::Show( show ) )
249 return false;
dfc54541 250
dfc54541 251 m_isShown = show;
dfe1eee3 252
b3090d48
MB
253 if (show)
254 {
255 // this usually will result in TransferDataToWindow() being called
256 // which will change the controls values so do it before showing as
257 // otherwise we could have some flicker
258 InitDialog();
259 }
260
dfc54541
JS
261 if (show)
262 {
355b4d3d
WS
263#if !wxUSE_INVISIBLE_RESIZE
264 XtMapWidget(XtParent((Widget) m_mainWidget));
265#else
266 XtManageChild((Widget)m_mainWidget) ;
267#endif
dfe1eee3 268
55034339 269 XRaiseWindow( XtDisplay( (Widget)m_mainWidget ),
798a4529 270 XtWindow( (Widget)m_mainWidget) );
dfe1eee3 271
dfc54541
JS
272 }
273 else
274 {
355b4d3d
WS
275#if !wxUSE_INVISIBLE_RESIZE
276 XtUnmapWidget(XtParent((Widget) m_mainWidget));
277#else
278 XtUnmanageChild((Widget)m_mainWidget) ;
279#endif
dfe1eee3 280
eb6fa4b4 281 XFlush(XtDisplay((Widget)m_mainWidget));
96be256b 282 XSync(XtDisplay((Widget)m_mainWidget), False);
dfc54541 283 }
dfe1eee3 284
96be256b 285 return true;
dfc54541
JS
286}
287
288// Shows a dialog modally, returning a return code
4bb6408c
JS
289int wxDialog::ShowModal()
290{
96be256b 291 Show(true);
dfe1eee3 292
eb6fa4b4
MB
293 // after the event loop ran, the widget might already have been destroyed
294 WXDisplay* display = (WXDisplay*)XtDisplay( (Widget)m_mainWidget );
295
dfc54541
JS
296 if (m_modalShowing)
297 return 0;
7e1bcfa8 298 m_eventLoop = new wxEventLoop;
dfe1eee3 299
96be256b
MB
300 m_modalShowing = true;
301 XtAddGrab((Widget) m_mainWidget, True, False);
dfe1eee3 302
7e1bcfa8 303 m_eventLoop->Run();
dfe1eee3 304
dfc54541 305 // Now process all events in case they get sent to a destroyed dialog
eb6fa4b4 306 wxFlushEvents( display );
dfe1eee3 307
7e1bcfa8
MB
308 delete m_eventLoop;
309 m_eventLoop = NULL;
310
dfc54541
JS
311 // TODO: is it safe to call this, if the dialog may have been deleted
312 // by now? Probably only if we're using delayed deletion of dialogs.
313 return GetReturnCode();
4bb6408c
JS
314}
315
316void wxDialog::EndModal(int retCode)
317{
dfc54541
JS
318 if (!m_modalShowing)
319 return;
dfe1eee3 320
dfc54541 321 SetReturnCode(retCode);
dfe1eee3 322
88150e60
JS
323 // Strangely, we don't seem to need this now.
324 // XtRemoveGrab((Widget) m_mainWidget);
dfe1eee3 325
96be256b 326 Show(false);
dfe1eee3 327
96be256b 328 m_modalShowing = false;
7e1bcfa8 329 m_eventLoop->Exit();
e95b8d5a
JS
330
331 SetModal(false);
4bb6408c
JS
332}
333
4bb6408c
JS
334// Destroy the window (delayed, if a managed window)
335bool wxDialog::Destroy()
336{
2d120f83
JS
337 if (!wxPendingDelete.Member(this))
338 wxPendingDelete.Append(this);
96be256b 339 return true;
4bb6408c
JS
340}
341
94b49b93 342void wxDialog::ChangeFont(bool keepOriginalSize)
0d57be45 343{
94b49b93 344 wxWindow::ChangeFont(keepOriginalSize);
0d57be45
JS
345}
346
347void wxDialog::ChangeBackgroundColour()
348{
94b49b93 349 if (GetMainWidget())
a8680e3e 350 wxDoChangeBackgroundColour(GetMainWidget(), m_backgroundColour);
0d57be45
JS
351}
352
353void wxDialog::ChangeForegroundColour()
354{
94b49b93 355 if (GetMainWidget())
a8680e3e 356 wxDoChangeForegroundColour(GetMainWidget(), m_foregroundColour);
0d57be45 357}