]>
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"
16 #define XtDisplay XTDISPLAY
17 #define XtWindow XTWINDOW
18 #define XtParent XTPARENT
19 #define XtScreen XTSCREEN
22 #include "wx/dialog.h"
27 #include "wx/settings.h"
30 #include "wx/evtloop.h"
33 #pragma message disable nosimpint
37 #include <X11/Shell.h>
41 #include <Xm/MwmUtil.h>
43 #include <Xm/BulletinB.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>
52 #include <Xm/Protocols.h>
55 #pragma message enable nosimpint
58 #include "wx/motif/private.h"
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;
65 // Lists to keep track of windows, so we can disable/enable them
67 wxList wxModalDialogs
;
68 extern wxList wxModelessWindows
; // Frames and modeless dialogs
70 #define wxUSE_INVISIBLE_RESIZE 1
72 IMPLEMENT_DYNAMIC_CLASS(wxDialog
, wxTopLevelWindow
)
76 m_modalShowing
= false;
80 bool wxDialog::Create(wxWindow
*parent
, wxWindowID id
,
81 const wxString
& title
,
87 SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG
);
89 if( !wxTopLevelWindow::Create( parent
, id
, title
, pos
, size
, style
,
93 m_modalShowing
= false;
96 Widget dialogShell
= (Widget
) m_mainWidget
;
100 // Can't remember what this was about... but I think it's necessary.
101 #if wxUSE_INVISIBLE_RESIZE
103 XtVaSetValues(dialogShell
, XmNx
, pos
.x
,
106 XtVaSetValues(dialogShell
, XmNy
, pos
.y
,
110 XtVaSetValues(dialogShell
, XmNwidth
, size
.x
, NULL
);
112 XtVaSetValues(dialogShell
, XmNheight
, size
.y
, NULL
);
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
);
123 #if !wxUSE_INVISIBLE_RESIZE
124 XtManageChild(dialogShell
);
125 SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
128 XtAddEventHandler(dialogShell
,ExposureMask
,False
,
129 wxUniversalRepaintProc
, (XtPointer
) this);
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
)
144 Widget parentWidget
= (Widget
) 0;
146 parentWidget
= (Widget
) parent
->GetTopWidget();
148 parentWidget
= (Widget
) wxTheApp
->GetTopLevelWidget();
150 wxASSERT_MSG( (parentWidget
!= (Widget
) 0),
151 "Could not find a suitable parent shell for dialog." );
154 XtSetArg (args
[0], XmNdefaultPosition
, False
);
155 XtSetArg (args
[1], XmNautoUnmanage
, False
);
157 XmCreateBulletinBoardDialog( parentWidget
,
160 m_mainWidget
= (WXWidget
) dialogShell
;
162 // We don't want margins, since there is enough elsewhere.
163 XtVaSetValues( dialogShell
,
166 XmNresizePolicy
, XmRESIZE_NONE
,
170 XtOverrideTranslations(dialogShell
,
171 ptr
= XtParseTranslationTable("<Configure>: resize()"));
174 XtRealizeWidget(dialogShell
);
176 wxAddWindowToTable( (Widget
)m_mainWidget
, this );
181 void wxDialog::SetModal(bool flag
)
184 wxModelessWindows
.DeleteObject(this);
186 wxModelessWindows
.Append(this);
189 wxDialog::~wxDialog()
191 m_isBeingDeleted
= true;
197 XtRemoveEventHandler((Widget
) m_mainWidget
, ExposureMask
, False
,
198 wxUniversalRepaintProc
, (XtPointer
) this);
201 m_modalShowing
= false;
203 #if !wxUSE_INVISIBLE_RESIZE
206 XtUnmapWidget((Widget
) m_mainWidget
);
214 wxDeleteWindowFromTable( (Widget
)m_mainWidget
);
215 XtDestroyWidget( (Widget
)m_mainWidget
);
219 void wxDialog::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
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
);
226 void wxDialog::DoSetClientSize(int width
, int height
)
228 wxWindow::SetSize(-1, -1, width
, height
);
231 void wxDialog::SetTitle(const wxString
& title
)
233 wxTopLevelWindow::SetTitle( title
);
237 wxXmString
str( title
);
238 XtVaSetValues( (Widget
)m_mainWidget
,
239 XmNtitle
, (const char*)title
.mb_str(),
240 XmNdialogTitle
, str(),
241 XmNiconName
, (const char*)title
.mb_str(),
246 bool wxDialog::Show( bool show
)
248 if( !wxWindowBase::Show( show
) )
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
263 #if !wxUSE_INVISIBLE_RESIZE
264 XtMapWidget(XtParent((Widget
) m_mainWidget
));
266 XtManageChild((Widget
)m_mainWidget
) ;
269 XRaiseWindow( XtDisplay( (Widget
)m_mainWidget
),
270 XtWindow( (Widget
)m_mainWidget
) );
275 #if !wxUSE_INVISIBLE_RESIZE
276 XtUnmapWidget(XtParent((Widget
) m_mainWidget
));
278 XtUnmanageChild((Widget
)m_mainWidget
) ;
281 XFlush(XtDisplay((Widget
)m_mainWidget
));
282 XSync(XtDisplay((Widget
)m_mainWidget
), False
);
288 // Shows a dialog modally, returning a return code
289 int wxDialog::ShowModal()
293 // after the event loop ran, the widget might already have been destroyed
294 WXDisplay
* display
= (WXDisplay
*)XtDisplay( (Widget
)m_mainWidget
);
298 m_eventLoop
= new wxEventLoop
;
300 m_modalShowing
= true;
301 XtAddGrab((Widget
) m_mainWidget
, True
, False
);
305 // Now process all events in case they get sent to a destroyed dialog
306 wxFlushEvents( display
);
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();
316 void wxDialog::EndModal(int retCode
)
321 SetReturnCode(retCode
);
323 // Strangely, we don't seem to need this now.
324 // XtRemoveGrab((Widget) m_mainWidget);
328 m_modalShowing
= false;
334 // Destroy the window (delayed, if a managed window)
335 bool wxDialog::Destroy()
337 if (!wxPendingDelete
.Member(this))
338 wxPendingDelete
.Append(this);
342 void wxDialog::ChangeFont(bool keepOriginalSize
)
344 wxWindow::ChangeFont(keepOriginalSize
);
347 void wxDialog::ChangeBackgroundColour()
350 wxDoChangeBackgroundColour(GetMainWidget(), m_backgroundColour
);
353 void wxDialog::ChangeForegroundColour()
356 wxDoChangeForegroundColour(GetMainWidget(), m_foregroundColour
);