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