]>
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()
186 // if the dialog is modal, this will end its event loop
193 XtRemoveEventHandler((Widget
) m_mainWidget
, ExposureMask
, False
,
194 wxUniversalRepaintProc
, (XtPointer
) this);
197 m_modalShowing
= false;
199 #if !wxUSE_INVISIBLE_RESIZE
202 XtUnmapWidget((Widget
) m_mainWidget
);
210 wxDeleteWindowFromTable( (Widget
)m_mainWidget
);
211 XtDestroyWidget( (Widget
)m_mainWidget
);
215 void wxDialog::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
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
);
222 void wxDialog::DoSetClientSize(int width
, int height
)
224 wxWindow::SetSize(-1, -1, width
, height
);
227 void wxDialog::SetTitle(const wxString
& title
)
229 wxTopLevelWindow::SetTitle( title
);
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(),
242 bool wxDialog::Show( bool show
)
244 if( !wxWindowBase::Show( show
) )
247 if ( !show
&& IsModal() )
248 EndModal(wxID_CANCEL
);
254 if (CanDoLayoutAdaptation())
255 DoLayoutAdaptation();
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
265 #if !wxUSE_INVISIBLE_RESIZE
266 XtMapWidget(XtParent((Widget
) m_mainWidget
));
268 XtManageChild((Widget
)m_mainWidget
) ;
271 XRaiseWindow( XtDisplay( (Widget
)m_mainWidget
),
272 XtWindow( (Widget
)m_mainWidget
) );
277 #if !wxUSE_INVISIBLE_RESIZE
278 XtUnmapWidget(XtParent((Widget
) m_mainWidget
));
280 XtUnmanageChild((Widget
)m_mainWidget
) ;
283 XFlush(XtDisplay((Widget
)m_mainWidget
));
284 XSync(XtDisplay((Widget
)m_mainWidget
), False
);
290 // Shows a dialog modally, returning a return code
291 int wxDialog::ShowModal()
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
);
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
);