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