]> git.saurik.com Git - wxWidgets.git/blob - src/motif/dialog.cpp
add m_ prefix to the member variables and remove unneeded dialogParent field (part...
[wxWidgets.git] / src / motif / dialog.cpp
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
67 wxList wxModalDialogs;
68 extern wxList wxModelessWindows; // Frames and modeless dialogs
69
70 #define wxUSE_INVISIBLE_RESIZE 1
71
72 IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxTopLevelWindow)
73
74 wxDialog::wxDialog()
75 {
76 m_modalShowing = false;
77 m_eventLoop = NULL;
78 }
79
80 bool 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
136 bool 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 wxConstCast(name.mb_str(), char),
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
181 void wxDialog::SetModal(bool flag)
182 {
183 if ( flag )
184 wxModelessWindows.DeleteObject(this);
185 else
186 wxModelessWindows.Append(this);
187 }
188
189 wxDialog::~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
219 void 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
226 void wxDialog::DoSetClientSize(int width, int height)
227 {
228 wxWindow::SetSize(-1, -1, width, height);
229 }
230
231 void 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, title.mb_str(),
240 XmNdialogTitle, str(),
241 XmNiconName, title.mb_str(),
242 NULL );
243 }
244 }
245
246 bool wxDialog::Show( bool show )
247 {
248 if( !wxWindowBase::Show( show ) )
249 return false;
250
251 m_isShown = show;
252
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
261 if (show)
262 {
263 #if !wxUSE_INVISIBLE_RESIZE
264 XtMapWidget(XtParent((Widget) m_mainWidget));
265 #else
266 XtManageChild((Widget)m_mainWidget) ;
267 #endif
268
269 XRaiseWindow( XtDisplay( (Widget)m_mainWidget ),
270 XtWindow( (Widget)m_mainWidget) );
271
272 }
273 else
274 {
275 #if !wxUSE_INVISIBLE_RESIZE
276 XtUnmapWidget(XtParent((Widget) m_mainWidget));
277 #else
278 XtUnmanageChild((Widget)m_mainWidget) ;
279 #endif
280
281 XFlush(XtDisplay((Widget)m_mainWidget));
282 XSync(XtDisplay((Widget)m_mainWidget), False);
283 }
284
285 return true;
286 }
287
288 // Shows a dialog modally, returning a return code
289 int wxDialog::ShowModal()
290 {
291 Show(true);
292
293 // after the event loop ran, the widget might already have been destroyed
294 WXDisplay* display = (WXDisplay*)XtDisplay( (Widget)m_mainWidget );
295
296 if (m_modalShowing)
297 return 0;
298 m_eventLoop = new wxEventLoop;
299
300 m_modalShowing = true;
301 XtAddGrab((Widget) m_mainWidget, True, False);
302
303 m_eventLoop->Run();
304
305 // Now process all events in case they get sent to a destroyed dialog
306 wxFlushEvents( display );
307
308 delete m_eventLoop;
309 m_eventLoop = NULL;
310
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();
314 }
315
316 void wxDialog::EndModal(int retCode)
317 {
318 if (!m_modalShowing)
319 return;
320
321 SetReturnCode(retCode);
322
323 // Strangely, we don't seem to need this now.
324 // XtRemoveGrab((Widget) m_mainWidget);
325
326 Show(false);
327
328 m_modalShowing = false;
329 m_eventLoop->Exit();
330
331 SetModal(false);
332 }
333
334 // Destroy the window (delayed, if a managed window)
335 bool wxDialog::Destroy()
336 {
337 if (!wxPendingDelete.Member(this))
338 wxPendingDelete.Append(this);
339 return true;
340 }
341
342 void wxDialog::ChangeFont(bool keepOriginalSize)
343 {
344 wxWindow::ChangeFont(keepOriginalSize);
345 }
346
347 void wxDialog::ChangeBackgroundColour()
348 {
349 if (GetMainWidget())
350 wxDoChangeBackgroundColour(GetMainWidget(), m_backgroundColour);
351 }
352
353 void wxDialog::ChangeForegroundColour()
354 {
355 if (GetMainWidget())
356 wxDoChangeForegroundColour(GetMainWidget(), m_foregroundColour);
357 }