]>
git.saurik.com Git - wxWidgets.git/blob - src/motif/dialog.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/motif/dialog.cpp
3 // Purpose: wxDialog class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
15 #include "wx/dialog.h"
20 #include "wx/settings.h"
23 #include "wx/evtloop.h"
26 #pragma message disable nosimpint
30 #include <X11/Shell.h>
34 #include <Xm/MwmUtil.h>
36 #include <Xm/BulletinB.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>
45 #include <Xm/Protocols.h>
48 #pragma message enable nosimpint
51 #include "wx/motif/private.h"
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;
58 // Lists to keep track of windows, so we can disable/enable them
60 wxList wxModalDialogs
;
61 extern wxList wxModelessWindows
; // Frames and modeless dialogs
63 #define wxUSE_INVISIBLE_RESIZE 1
65 IMPLEMENT_DYNAMIC_CLASS(wxDialog
, wxTopLevelWindow
)
69 m_modalShowing
= false;
73 bool wxDialog::Create(wxWindow
*parent
, wxWindowID id
,
74 const wxString
& title
,
80 SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG
);
82 if( !wxTopLevelWindow::Create( parent
, id
, title
, pos
, size
, style
,
86 m_modalShowing
= false;
89 Widget dialogShell
= (Widget
) m_mainWidget
;
93 // Can't remember what this was about... but I think it's necessary.
94 #if wxUSE_INVISIBLE_RESIZE
96 XtVaSetValues(dialogShell
, XmNx
, pos
.x
,
99 XtVaSetValues(dialogShell
, XmNy
, pos
.y
,
103 XtVaSetValues(dialogShell
, XmNwidth
, size
.x
, NULL
);
105 XtVaSetValues(dialogShell
, XmNheight
, size
.y
, NULL
);
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
);
116 #if !wxUSE_INVISIBLE_RESIZE
117 XtManageChild(dialogShell
);
118 SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
121 XtAddEventHandler(dialogShell
,ExposureMask
,False
,
122 wxUniversalRepaintProc
, (XtPointer
) this);
129 bool 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
)
137 Widget parentWidget
= (Widget
) 0;
139 parentWidget
= (Widget
) parent
->GetTopWidget();
141 parentWidget
= (Widget
) wxTheApp
->GetTopLevelWidget();
143 wxASSERT_MSG( (parentWidget
!= (Widget
) 0),
144 "Could not find a suitable parent shell for dialog." );
147 XtSetArg (args
[0], XmNdefaultPosition
, False
);
148 XtSetArg (args
[1], XmNautoUnmanage
, False
);
150 XmCreateBulletinBoardDialog( parentWidget
,
153 m_mainWidget
= (WXWidget
) dialogShell
;
155 // We don't want margins, since there is enough elsewhere.
156 XtVaSetValues( dialogShell
,
159 XmNresizePolicy
, XmRESIZE_NONE
,
163 XtOverrideTranslations(dialogShell
,
164 ptr
= XtParseTranslationTable("<Configure>: resize()"));
167 XtRealizeWidget(dialogShell
);
169 wxAddWindowToTable( (Widget
)m_mainWidget
, this );
174 void wxDialog::SetModal(bool flag
)
177 wxModelessWindows
.DeleteObject(this);
179 wxModelessWindows
.Append(this);
182 wxDialog::~wxDialog()
184 m_isBeingDeleted
= true;
190 XtRemoveEventHandler((Widget
) m_mainWidget
, ExposureMask
, False
,
191 wxUniversalRepaintProc
, (XtPointer
) this);
194 m_modalShowing
= false;
196 #if !wxUSE_INVISIBLE_RESIZE
199 XtUnmapWidget((Widget
) m_mainWidget
);
207 wxDeleteWindowFromTable( (Widget
)m_mainWidget
);
208 XtDestroyWidget( (Widget
)m_mainWidget
);
212 void wxDialog::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
214 XtVaSetValues((Widget
) m_mainWidget
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
215 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
216 XtVaSetValues((Widget
) m_mainWidget
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
219 void wxDialog::DoSetClientSize(int width
, int height
)
221 wxWindow::SetSize(-1, -1, width
, height
);
224 void wxDialog::SetTitle(const wxString
& title
)
226 wxTopLevelWindow::SetTitle( title
);
230 wxXmString
str( title
);
231 XtVaSetValues( (Widget
)m_mainWidget
,
232 XmNtitle
, (const char*)title
.mb_str(),
233 XmNdialogTitle
, str(),
234 XmNiconName
, (const char*)title
.mb_str(),
239 bool wxDialog::Show( bool show
)
241 if( !wxWindowBase::Show( show
) )
248 if (CanDoLayoutAdaptation())
249 DoLayoutAdaptation();
251 // this usually will result in TransferDataToWindow() being called
252 // which will change the controls values so do it before showing as
253 // otherwise we could have some flicker
259 #if !wxUSE_INVISIBLE_RESIZE
260 XtMapWidget(XtParent((Widget
) m_mainWidget
));
262 XtManageChild((Widget
)m_mainWidget
) ;
265 XRaiseWindow( XtDisplay( (Widget
)m_mainWidget
),
266 XtWindow( (Widget
)m_mainWidget
) );
271 #if !wxUSE_INVISIBLE_RESIZE
272 XtUnmapWidget(XtParent((Widget
) m_mainWidget
));
274 XtUnmanageChild((Widget
)m_mainWidget
) ;
277 XFlush(XtDisplay((Widget
)m_mainWidget
));
278 XSync(XtDisplay((Widget
)m_mainWidget
), False
);
284 // Shows a dialog modally, returning a return code
285 int wxDialog::ShowModal()
289 // after the event loop ran, the widget might already have been destroyed
290 WXDisplay
* display
= (WXDisplay
*)XtDisplay( (Widget
)m_mainWidget
);
294 m_eventLoop
= new wxEventLoop
;
296 m_modalShowing
= true;
297 XtAddGrab((Widget
) m_mainWidget
, True
, False
);
301 // Now process all events in case they get sent to a destroyed dialog
302 wxFlushEvents( display
);
307 // TODO: is it safe to call this, if the dialog may have been deleted
308 // by now? Probably only if we're using delayed deletion of dialogs.
309 return GetReturnCode();
312 void wxDialog::EndModal(int retCode
)
317 SetReturnCode(retCode
);
319 // Strangely, we don't seem to need this now.
320 // XtRemoveGrab((Widget) m_mainWidget);
324 m_modalShowing
= false;
330 // Destroy the window (delayed, if a managed window)
331 bool wxDialog::Destroy()
333 if (!wxPendingDelete
.Member(this))
334 wxPendingDelete
.Append(this);
338 void wxDialog::ChangeFont(bool keepOriginalSize
)
340 wxWindow::ChangeFont(keepOriginalSize
);
343 void wxDialog::ChangeBackgroundColour()
346 wxDoChangeBackgroundColour(GetMainWidget(), m_backgroundColour
);
349 void wxDialog::ChangeForegroundColour()
352 wxDoChangeForegroundColour(GetMainWidget(), m_foregroundColour
);