]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/motif/dialog.cpp
non-pch build fix
[wxWidgets.git] / src / motif / dialog.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/motif/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// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __VMS
16#define XtDisplay XTDISPLAY
17#define XtWindow XTWINDOW
18#define XtParent XTPARENT
19#define XtScreen XTSCREEN
20#endif
21
22#include "wx/dialog.h"
23
24#ifndef WX_PRECOMP
25 #include "wx/app.h"
26 #include "wx/utils.h"
27 #include "wx/settings.h"
28#endif
29
30#include "wx/evtloop.h"
31
32#ifdef __VMS__
33#pragma message disable nosimpint
34#endif
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
54#ifdef __VMS__
55#pragma message enable nosimpint
56#endif
57
58#include "wx/motif/private.h"
59
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.
63// static wxList wxModalShowingStack;
64
65// Lists to keep track of windows, so we can disable/enable them
66// for modal dialogs
67wxList wxModalDialogs;
68extern wxList wxModelessWindows; // Frames and modeless dialogs
69
70#define wxUSE_INVISIBLE_RESIZE 1
71
72IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxTopLevelWindow)
73
74wxDialog::wxDialog()
75{
76 m_modalShowing = false;
77 m_eventLoop = NULL;
78}
79
80bool wxDialog::Create(wxWindow *parent, wxWindowID id,
81 const wxString& title,
82 const wxPoint& pos,
83 const wxSize& size,
84 long style,
85 const wxString& name)
86{
87 SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG);
88
89 if( !wxTopLevelWindow::Create( parent, id, title, pos, size, style,
90 name ) )
91 return false;
92
93 m_modalShowing = false;
94 m_eventLoop = NULL;
95
96 Widget dialogShell = (Widget) m_mainWidget;
97
98 SetTitle( title );
99
100 // Can't remember what this was about... but I think it's necessary.
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
114
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).
118#if !wxUSE_INVISIBLE_RESIZE
119 Widget shell = XtParent(dialogShell) ;
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
127
128 XtAddEventHandler(dialogShell,ExposureMask,False,
129 wxUniversalRepaintProc, (XtPointer) this);
130
131 PostCreation();
132
133 return true;
134}
135
136bool wxDialog::XmDoCreateTLW(wxWindow* parent,
137 wxWindowID WXUNUSED(id),
138 const wxString& WXUNUSED(title),
139 const wxPoint& WXUNUSED(pos),
140 const wxSize& WXUNUSED(size),
141 long WXUNUSED(style),
142 const wxString& name)
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 =
157 XmCreateBulletinBoardDialog( parentWidget,
158 name.char_str(),
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
178 return true;
179}
180
181void wxDialog::SetModal(bool flag)
182{
183 if ( flag )
184 wxModelessWindows.DeleteObject(this);
185 else
186 wxModelessWindows.Append(this);
187}
188
189wxDialog::~wxDialog()
190{
191 m_isBeingDeleted = true;
192
193 delete m_eventLoop;
194
195 if (m_mainWidget)
196 {
197 XtRemoveEventHandler((Widget) m_mainWidget, ExposureMask, False,
198 wxUniversalRepaintProc, (XtPointer) this);
199 }
200
201 m_modalShowing = false;
202
203#if !wxUSE_INVISIBLE_RESIZE
204 if (m_mainWidget)
205 {
206 XtUnmapWidget((Widget) m_mainWidget);
207 }
208#endif
209
210 PreDestroy();
211
212 if ( m_mainWidget )
213 {
214 wxDeleteWindowFromTable( (Widget)m_mainWidget );
215 XtDestroyWidget( (Widget)m_mainWidget );
216 }
217}
218
219void wxDialog::DoSetSize(int x, int y, int width, int height, int sizeFlags)
220{
221 XtVaSetValues((Widget) m_mainWidget, XmNresizePolicy, XmRESIZE_ANY, NULL);
222 wxWindow::DoSetSize(x, y, width, height, sizeFlags);
223 XtVaSetValues((Widget) m_mainWidget, XmNresizePolicy, XmRESIZE_NONE, NULL);
224}
225
226void wxDialog::DoSetClientSize(int width, int height)
227{
228 wxWindow::SetSize(-1, -1, width, height);
229}
230
231void wxDialog::SetTitle(const wxString& title)
232{
233 wxTopLevelWindow::SetTitle( title );
234
235 if( !title.empty() )
236 {
237 wxXmString str( title );
238 XtVaSetValues( (Widget)m_mainWidget,
239 XmNtitle, (const char*)title.mb_str(),
240 XmNdialogTitle, str(),
241 XmNiconName, (const char*)title.mb_str(),
242 NULL );
243 }
244}
245
246bool wxDialog::Show( bool show )
247{
248 if( !wxWindowBase::Show( show ) )
249 return false;
250
251 m_isShown = show;
252
253 if (show)
254 {
255 if (CanDoLayoutAdaptation())
256 DoLayoutAdaptation();
257
258 // this usually will result in TransferDataToWindow() being called
259 // which will change the controls values so do it before showing as
260 // otherwise we could have some flicker
261 InitDialog();
262 }
263
264 if (show)
265 {
266#if !wxUSE_INVISIBLE_RESIZE
267 XtMapWidget(XtParent((Widget) m_mainWidget));
268#else
269 XtManageChild((Widget)m_mainWidget) ;
270#endif
271
272 XRaiseWindow( XtDisplay( (Widget)m_mainWidget ),
273 XtWindow( (Widget)m_mainWidget) );
274
275 }
276 else
277 {
278#if !wxUSE_INVISIBLE_RESIZE
279 XtUnmapWidget(XtParent((Widget) m_mainWidget));
280#else
281 XtUnmanageChild((Widget)m_mainWidget) ;
282#endif
283
284 XFlush(XtDisplay((Widget)m_mainWidget));
285 XSync(XtDisplay((Widget)m_mainWidget), False);
286 }
287
288 return true;
289}
290
291// Shows a dialog modally, returning a return code
292int wxDialog::ShowModal()
293{
294 Show(true);
295
296 // after the event loop ran, the widget might already have been destroyed
297 WXDisplay* display = (WXDisplay*)XtDisplay( (Widget)m_mainWidget );
298
299 if (m_modalShowing)
300 return 0;
301 m_eventLoop = new wxEventLoop;
302
303 m_modalShowing = true;
304 XtAddGrab((Widget) m_mainWidget, True, False);
305
306 m_eventLoop->Run();
307
308 // Now process all events in case they get sent to a destroyed dialog
309 wxFlushEvents( display );
310
311 delete m_eventLoop;
312 m_eventLoop = NULL;
313
314 // TODO: is it safe to call this, if the dialog may have been deleted
315 // by now? Probably only if we're using delayed deletion of dialogs.
316 return GetReturnCode();
317}
318
319void wxDialog::EndModal(int retCode)
320{
321 if (!m_modalShowing)
322 return;
323
324 SetReturnCode(retCode);
325
326 // Strangely, we don't seem to need this now.
327 // XtRemoveGrab((Widget) m_mainWidget);
328
329 Show(false);
330
331 m_modalShowing = false;
332 m_eventLoop->Exit();
333
334 SetModal(false);
335}
336
337// Destroy the window (delayed, if a managed window)
338bool wxDialog::Destroy()
339{
340 if (!wxPendingDelete.Member(this))
341 wxPendingDelete.Append(this);
342 return true;
343}
344
345void wxDialog::ChangeFont(bool keepOriginalSize)
346{
347 wxWindow::ChangeFont(keepOriginalSize);
348}
349
350void wxDialog::ChangeBackgroundColour()
351{
352 if (GetMainWidget())
353 wxDoChangeBackgroundColour(GetMainWidget(), m_backgroundColour);
354}
355
356void wxDialog::ChangeForegroundColour()
357{
358 if (GetMainWidget())
359 wxDoChangeForegroundColour(GetMainWidget(), m_foregroundColour);
360}