]>
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
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
14 #include "wx/dialog.h"
19 #include "wx/settings.h"
22 #include "wx/evtloop.h"
23 #include "wx/modalhook.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
67 m_modalShowing
= false;
71 bool wxDialog::Create(wxWindow
*parent
, wxWindowID id
,
72 const wxString
& title
,
78 SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG
);
80 if( !wxTopLevelWindow::Create( parent
, id
, title
, pos
, size
, style
,
84 m_modalShowing
= false;
87 Widget dialogShell
= (Widget
) m_mainWidget
;
91 // Can't remember what this was about... but I think it's necessary.
92 #if wxUSE_INVISIBLE_RESIZE
94 XtVaSetValues(dialogShell
, XmNx
, pos
.x
,
97 XtVaSetValues(dialogShell
, XmNy
, pos
.y
,
101 XtVaSetValues(dialogShell
, XmNwidth
, size
.x
, NULL
);
103 XtVaSetValues(dialogShell
, XmNheight
, size
.y
, NULL
);
106 // Positioning of the dialog doesn't work properly unless the dialog
107 // is managed, so we manage without mapping to the screen.
108 // To show, we map the shell (actually it's parent).
109 #if !wxUSE_INVISIBLE_RESIZE
110 Widget shell
= XtParent(dialogShell
) ;
111 XtVaSetValues(shell
, XmNmappedWhenManaged
, False
, NULL
);
114 #if !wxUSE_INVISIBLE_RESIZE
115 XtManageChild(dialogShell
);
116 SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
119 XtAddEventHandler(dialogShell
,ExposureMask
,False
,
120 wxUniversalRepaintProc
, (XtPointer
) this);
127 bool wxDialog::XmDoCreateTLW(wxWindow
* parent
,
128 wxWindowID
WXUNUSED(id
),
129 const wxString
& WXUNUSED(title
),
130 const wxPoint
& WXUNUSED(pos
),
131 const wxSize
& WXUNUSED(size
),
132 long WXUNUSED(style
),
133 const wxString
& name
)
135 Widget parentWidget
= (Widget
) 0;
137 parentWidget
= (Widget
) parent
->GetTopWidget();
139 parentWidget
= (Widget
) wxTheApp
->GetTopLevelWidget();
141 wxASSERT_MSG( (parentWidget
!= (Widget
) 0),
142 "Could not find a suitable parent shell for dialog." );
145 XtSetArg (args
[0], XmNdefaultPosition
, False
);
146 XtSetArg (args
[1], XmNautoUnmanage
, False
);
148 XmCreateBulletinBoardDialog( parentWidget
,
151 m_mainWidget
= (WXWidget
) dialogShell
;
153 // We don't want margins, since there is enough elsewhere.
154 XtVaSetValues( dialogShell
,
157 XmNresizePolicy
, XmRESIZE_NONE
,
161 XtOverrideTranslations(dialogShell
,
162 ptr
= XtParseTranslationTable("<Configure>: resize()"));
165 XtRealizeWidget(dialogShell
);
167 wxAddWindowToTable( (Widget
)m_mainWidget
, this );
172 void wxDialog::SetModal(bool flag
)
175 wxModelessWindows
.DeleteObject(this);
177 wxModelessWindows
.Append(this);
180 wxDialog::~wxDialog()
184 // if the dialog is modal, this will end its event loop
191 XtRemoveEventHandler((Widget
) m_mainWidget
, ExposureMask
, False
,
192 wxUniversalRepaintProc
, (XtPointer
) this);
195 m_modalShowing
= false;
197 #if !wxUSE_INVISIBLE_RESIZE
200 XtUnmapWidget((Widget
) m_mainWidget
);
208 wxDeleteWindowFromTable( (Widget
)m_mainWidget
);
209 XtDestroyWidget( (Widget
)m_mainWidget
);
213 void wxDialog::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
215 XtVaSetValues((Widget
) m_mainWidget
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
216 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
217 XtVaSetValues((Widget
) m_mainWidget
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
220 void wxDialog::DoSetClientSize(int width
, int height
)
222 wxWindow::SetSize(-1, -1, width
, height
);
225 void wxDialog::SetTitle(const wxString
& title
)
227 wxTopLevelWindow::SetTitle( title
);
231 wxXmString
str( title
);
232 XtVaSetValues( (Widget
)m_mainWidget
,
233 XmNtitle
, (const char*)title
.mb_str(),
234 XmNdialogTitle
, str(),
235 XmNiconName
, (const char*)title
.mb_str(),
240 bool wxDialog::Show( bool show
)
242 if( !wxWindowBase::Show( show
) )
245 if ( !show
&& IsModal() )
246 EndModal(wxID_CANCEL
);
252 if (CanDoLayoutAdaptation())
253 DoLayoutAdaptation();
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()
291 WX_HOOK_MODAL_DIALOG();
295 // after the event loop ran, the widget might already have been destroyed
296 WXDisplay
* display
= (WXDisplay
*)XtDisplay( (Widget
)m_mainWidget
);
300 m_eventLoop
= new wxEventLoop
;
302 m_modalShowing
= true;
303 XtAddGrab((Widget
) m_mainWidget
, True
, False
);
307 // Now process all events in case they get sent to a destroyed dialog
308 wxFlushEvents( display
);
310 wxDELETE(m_eventLoop
);
312 // TODO: is it safe to call this, if the dialog may have been deleted
313 // by now? Probably only if we're using delayed deletion of dialogs.
314 return GetReturnCode();
317 void wxDialog::EndModal(int retCode
)
322 SetReturnCode(retCode
);
324 // Strangely, we don't seem to need this now.
325 // XtRemoveGrab((Widget) m_mainWidget);
329 m_modalShowing
= false;
335 // Destroy the window (delayed, if a managed window)
336 bool wxDialog::Destroy()
338 if (!wxPendingDelete
.Member(this))
339 wxPendingDelete
.Append(this);
343 void wxDialog::ChangeFont(bool keepOriginalSize
)
345 wxWindow::ChangeFont(keepOriginalSize
);
348 void wxDialog::ChangeBackgroundColour()
351 wxDoChangeBackgroundColour(GetMainWidget(), m_backgroundColour
);
354 void wxDialog::ChangeForegroundColour()
357 wxDoChangeForegroundColour(GetMainWidget(), m_foregroundColour
);