]>
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"
24 #include "wx/modalhook.h"
27 #pragma message disable nosimpint
31 #include <X11/Shell.h>
35 #include <Xm/MwmUtil.h>
37 #include <Xm/BulletinB.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>
46 #include <Xm/Protocols.h>
49 #pragma message enable nosimpint
52 #include "wx/motif/private.h"
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.
57 // static wxList wxModalShowingStack;
59 // Lists to keep track of windows, so we can disable/enable them
61 wxList wxModalDialogs
;
62 extern wxList wxModelessWindows
; // Frames and modeless dialogs
64 #define wxUSE_INVISIBLE_RESIZE 1
68 m_modalShowing
= false;
72 bool wxDialog::Create(wxWindow
*parent
, wxWindowID id
,
73 const wxString
& title
,
79 SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG
);
81 if( !wxTopLevelWindow::Create( parent
, id
, title
, pos
, size
, style
,
85 m_modalShowing
= false;
88 Widget dialogShell
= (Widget
) m_mainWidget
;
92 // Can't remember what this was about... but I think it's necessary.
93 #if wxUSE_INVISIBLE_RESIZE
95 XtVaSetValues(dialogShell
, XmNx
, pos
.x
,
98 XtVaSetValues(dialogShell
, XmNy
, pos
.y
,
102 XtVaSetValues(dialogShell
, XmNwidth
, size
.x
, NULL
);
104 XtVaSetValues(dialogShell
, XmNheight
, size
.y
, NULL
);
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).
110 #if !wxUSE_INVISIBLE_RESIZE
111 Widget shell
= XtParent(dialogShell
) ;
112 XtVaSetValues(shell
, XmNmappedWhenManaged
, False
, NULL
);
115 #if !wxUSE_INVISIBLE_RESIZE
116 XtManageChild(dialogShell
);
117 SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
120 XtAddEventHandler(dialogShell
,ExposureMask
,False
,
121 wxUniversalRepaintProc
, (XtPointer
) this);
128 bool wxDialog::XmDoCreateTLW(wxWindow
* parent
,
129 wxWindowID
WXUNUSED(id
),
130 const wxString
& WXUNUSED(title
),
131 const wxPoint
& WXUNUSED(pos
),
132 const wxSize
& WXUNUSED(size
),
133 long WXUNUSED(style
),
134 const wxString
& name
)
136 Widget parentWidget
= (Widget
) 0;
138 parentWidget
= (Widget
) parent
->GetTopWidget();
140 parentWidget
= (Widget
) wxTheApp
->GetTopLevelWidget();
142 wxASSERT_MSG( (parentWidget
!= (Widget
) 0),
143 "Could not find a suitable parent shell for dialog." );
146 XtSetArg (args
[0], XmNdefaultPosition
, False
);
147 XtSetArg (args
[1], XmNautoUnmanage
, False
);
149 XmCreateBulletinBoardDialog( parentWidget
,
152 m_mainWidget
= (WXWidget
) dialogShell
;
154 // We don't want margins, since there is enough elsewhere.
155 XtVaSetValues( dialogShell
,
158 XmNresizePolicy
, XmRESIZE_NONE
,
162 XtOverrideTranslations(dialogShell
,
163 ptr
= XtParseTranslationTable("<Configure>: resize()"));
166 XtRealizeWidget(dialogShell
);
168 wxAddWindowToTable( (Widget
)m_mainWidget
, this );
173 void wxDialog::SetModal(bool flag
)
176 wxModelessWindows
.DeleteObject(this);
178 wxModelessWindows
.Append(this);
181 wxDialog::~wxDialog()
185 // if the dialog is modal, this will end its event loop
192 XtRemoveEventHandler((Widget
) m_mainWidget
, ExposureMask
, False
,
193 wxUniversalRepaintProc
, (XtPointer
) this);
196 m_modalShowing
= false;
198 #if !wxUSE_INVISIBLE_RESIZE
201 XtUnmapWidget((Widget
) m_mainWidget
);
209 wxDeleteWindowFromTable( (Widget
)m_mainWidget
);
210 XtDestroyWidget( (Widget
)m_mainWidget
);
214 void wxDialog::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
216 XtVaSetValues((Widget
) m_mainWidget
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
217 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
218 XtVaSetValues((Widget
) m_mainWidget
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
221 void wxDialog::DoSetClientSize(int width
, int height
)
223 wxWindow::SetSize(-1, -1, width
, height
);
226 void wxDialog::SetTitle(const wxString
& title
)
228 wxTopLevelWindow::SetTitle( title
);
232 wxXmString
str( title
);
233 XtVaSetValues( (Widget
)m_mainWidget
,
234 XmNtitle
, (const char*)title
.mb_str(),
235 XmNdialogTitle
, str(),
236 XmNiconName
, (const char*)title
.mb_str(),
241 bool wxDialog::Show( bool show
)
243 if( !wxWindowBase::Show( show
) )
246 if ( !show
&& IsModal() )
247 EndModal(wxID_CANCEL
);
253 if (CanDoLayoutAdaptation())
254 DoLayoutAdaptation();
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
264 #if !wxUSE_INVISIBLE_RESIZE
265 XtMapWidget(XtParent((Widget
) m_mainWidget
));
267 XtManageChild((Widget
)m_mainWidget
) ;
270 XRaiseWindow( XtDisplay( (Widget
)m_mainWidget
),
271 XtWindow( (Widget
)m_mainWidget
) );
276 #if !wxUSE_INVISIBLE_RESIZE
277 XtUnmapWidget(XtParent((Widget
) m_mainWidget
));
279 XtUnmanageChild((Widget
)m_mainWidget
) ;
282 XFlush(XtDisplay((Widget
)m_mainWidget
));
283 XSync(XtDisplay((Widget
)m_mainWidget
), False
);
289 // Shows a dialog modally, returning a return code
290 int wxDialog::ShowModal()
292 WX_HOOK_MODAL_DIALOG();
296 // after the event loop ran, the widget might already have been destroyed
297 WXDisplay
* display
= (WXDisplay
*)XtDisplay( (Widget
)m_mainWidget
);
301 m_eventLoop
= new wxEventLoop
;
303 m_modalShowing
= true;
304 XtAddGrab((Widget
) m_mainWidget
, True
, False
);
308 // Now process all events in case they get sent to a destroyed dialog
309 wxFlushEvents( display
);
311 wxDELETE(m_eventLoop
);
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();
318 void wxDialog::EndModal(int retCode
)
323 SetReturnCode(retCode
);
325 // Strangely, we don't seem to need this now.
326 // XtRemoveGrab((Widget) m_mainWidget);
330 m_modalShowing
= false;
336 // Destroy the window (delayed, if a managed window)
337 bool wxDialog::Destroy()
339 if (!wxPendingDelete
.Member(this))
340 wxPendingDelete
.Append(this);
344 void wxDialog::ChangeFont(bool keepOriginalSize
)
346 wxWindow::ChangeFont(keepOriginalSize
);
349 void wxDialog::ChangeBackgroundColour()
352 wxDoChangeBackgroundColour(GetMainWidget(), m_backgroundColour
);
355 void wxDialog::ChangeForegroundColour()
358 wxDoChangeForegroundColour(GetMainWidget(), m_foregroundColour
);