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