]>
Commit | Line | Data |
---|---|---|
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 | |
67 | wxList wxModalDialogs; | |
798a4529 | 68 | extern wxList wxModelessWindows; // Frames and modeless dialogs |
4bb6408c | 69 | |
47d67540 | 70 | #define wxUSE_INVISIBLE_RESIZE 1 |
dfc54541 | 71 | |
798a4529 | 72 | IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxTopLevelWindow) |
4bb6408c | 73 | |
4bb6408c JS |
74 | wxDialog::wxDialog() |
75 | { | |
96be256b | 76 | m_modalShowing = false; |
7e1bcfa8 | 77 | m_eventLoop = NULL; |
4bb6408c JS |
78 | } |
79 | ||
80 | bool 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 | 136 | bool 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 |
181 | void 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 | ||
189 | wxDialog::~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 | 219 | void 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 |
226 | void wxDialog::DoSetClientSize(int width, int height) |
227 | { | |
228 | wxWindow::SetSize(-1, -1, width, height); | |
229 | } | |
230 | ||
4bb6408c JS |
231 | void 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 | 246 | bool 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 | { | |
3aa8e4ea JS |
255 | if (CanDoLayoutAdaptation()) |
256 | DoLayoutAdaptation(); | |
257 | ||
b3090d48 MB |
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 | ||
dfc54541 JS |
264 | if (show) |
265 | { | |
355b4d3d WS |
266 | #if !wxUSE_INVISIBLE_RESIZE |
267 | XtMapWidget(XtParent((Widget) m_mainWidget)); | |
268 | #else | |
269 | XtManageChild((Widget)m_mainWidget) ; | |
270 | #endif | |
dfe1eee3 | 271 | |
55034339 | 272 | XRaiseWindow( XtDisplay( (Widget)m_mainWidget ), |
798a4529 | 273 | XtWindow( (Widget)m_mainWidget) ); |
dfe1eee3 | 274 | |
dfc54541 JS |
275 | } |
276 | else | |
277 | { | |
355b4d3d WS |
278 | #if !wxUSE_INVISIBLE_RESIZE |
279 | XtUnmapWidget(XtParent((Widget) m_mainWidget)); | |
280 | #else | |
281 | XtUnmanageChild((Widget)m_mainWidget) ; | |
282 | #endif | |
dfe1eee3 | 283 | |
eb6fa4b4 | 284 | XFlush(XtDisplay((Widget)m_mainWidget)); |
96be256b | 285 | XSync(XtDisplay((Widget)m_mainWidget), False); |
dfc54541 | 286 | } |
dfe1eee3 | 287 | |
96be256b | 288 | return true; |
dfc54541 JS |
289 | } |
290 | ||
291 | // Shows a dialog modally, returning a return code | |
4bb6408c JS |
292 | int wxDialog::ShowModal() |
293 | { | |
96be256b | 294 | Show(true); |
dfe1eee3 | 295 | |
eb6fa4b4 MB |
296 | // after the event loop ran, the widget might already have been destroyed |
297 | WXDisplay* display = (WXDisplay*)XtDisplay( (Widget)m_mainWidget ); | |
298 | ||
dfc54541 JS |
299 | if (m_modalShowing) |
300 | return 0; | |
7e1bcfa8 | 301 | m_eventLoop = new wxEventLoop; |
dfe1eee3 | 302 | |
96be256b MB |
303 | m_modalShowing = true; |
304 | XtAddGrab((Widget) m_mainWidget, True, False); | |
dfe1eee3 | 305 | |
7e1bcfa8 | 306 | m_eventLoop->Run(); |
dfe1eee3 | 307 | |
dfc54541 | 308 | // Now process all events in case they get sent to a destroyed dialog |
eb6fa4b4 | 309 | wxFlushEvents( display ); |
dfe1eee3 | 310 | |
7e1bcfa8 MB |
311 | delete m_eventLoop; |
312 | m_eventLoop = NULL; | |
313 | ||
dfc54541 JS |
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(); | |
4bb6408c JS |
317 | } |
318 | ||
319 | void wxDialog::EndModal(int retCode) | |
320 | { | |
dfc54541 JS |
321 | if (!m_modalShowing) |
322 | return; | |
dfe1eee3 | 323 | |
dfc54541 | 324 | SetReturnCode(retCode); |
dfe1eee3 | 325 | |
88150e60 JS |
326 | // Strangely, we don't seem to need this now. |
327 | // XtRemoveGrab((Widget) m_mainWidget); | |
dfe1eee3 | 328 | |
96be256b | 329 | Show(false); |
dfe1eee3 | 330 | |
96be256b | 331 | m_modalShowing = false; |
7e1bcfa8 | 332 | m_eventLoop->Exit(); |
e95b8d5a JS |
333 | |
334 | SetModal(false); | |
4bb6408c JS |
335 | } |
336 | ||
4bb6408c JS |
337 | // Destroy the window (delayed, if a managed window) |
338 | bool wxDialog::Destroy() | |
339 | { | |
2d120f83 JS |
340 | if (!wxPendingDelete.Member(this)) |
341 | wxPendingDelete.Append(this); | |
96be256b | 342 | return true; |
4bb6408c JS |
343 | } |
344 | ||
94b49b93 | 345 | void wxDialog::ChangeFont(bool keepOriginalSize) |
0d57be45 | 346 | { |
94b49b93 | 347 | wxWindow::ChangeFont(keepOriginalSize); |
0d57be45 JS |
348 | } |
349 | ||
350 | void wxDialog::ChangeBackgroundColour() | |
351 | { | |
94b49b93 | 352 | if (GetMainWidget()) |
a8680e3e | 353 | wxDoChangeBackgroundColour(GetMainWidget(), m_backgroundColour); |
0d57be45 JS |
354 | } |
355 | ||
356 | void wxDialog::ChangeForegroundColour() | |
357 | { | |
94b49b93 | 358 | if (GetMainWidget()) |
a8680e3e | 359 | wxDoChangeForegroundColour(GetMainWidget(), m_foregroundColour); |
0d57be45 | 360 | } |