]>
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;
78 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
81 bool wxDialog::Create(wxWindow
*parent
, wxWindowID id
,
82 const wxString
& title
,
88 SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG
);
90 if( !wxTopLevelWindow::Create( parent
, id
, title
, pos
, size
, style
,
94 m_modalShowing
= false;
97 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
98 m_foregroundColour
= *wxBLACK
;
100 Widget dialogShell
= (Widget
) m_mainWidget
;
104 m_font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
107 // Can't remember what this was about... but I think it's necessary.
108 #if wxUSE_INVISIBLE_RESIZE
110 XtVaSetValues(dialogShell
, XmNx
, pos
.x
,
113 XtVaSetValues(dialogShell
, XmNy
, pos
.y
,
117 XtVaSetValues(dialogShell
, XmNwidth
, size
.x
, NULL
);
119 XtVaSetValues(dialogShell
, XmNheight
, size
.y
, NULL
);
122 // Positioning of the dialog doesn't work properly unless the dialog
123 // is managed, so we manage without mapping to the screen.
124 // To show, we map the shell (actually it's parent).
125 #if !wxUSE_INVISIBLE_RESIZE
126 Widget shell
= XtParent(dialogShell
) ;
127 XtVaSetValues(shell
, XmNmappedWhenManaged
, False
, NULL
);
130 #if !wxUSE_INVISIBLE_RESIZE
131 XtManageChild(dialogShell
);
132 SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
135 XtAddEventHandler(dialogShell
,ExposureMask
,False
,
136 wxUniversalRepaintProc
, (XtPointer
) this);
138 ChangeBackgroundColour();
143 bool wxDialog::XmDoCreateTLW(wxWindow
* parent
,
144 wxWindowID
WXUNUSED(id
),
145 const wxString
& WXUNUSED(title
),
146 const wxPoint
& WXUNUSED(pos
),
147 const wxSize
& WXUNUSED(size
),
148 long WXUNUSED(style
),
149 const wxString
& name
)
151 Widget parentWidget
= (Widget
) 0;
153 parentWidget
= (Widget
) parent
->GetTopWidget();
155 parentWidget
= (Widget
) wxTheApp
->GetTopLevelWidget();
157 wxASSERT_MSG( (parentWidget
!= (Widget
) 0),
158 "Could not find a suitable parent shell for dialog." );
161 XtSetArg (args
[0], XmNdefaultPosition
, False
);
162 XtSetArg (args
[1], XmNautoUnmanage
, False
);
164 XmCreateBulletinBoardDialog( parentWidget
,
165 wxConstCast(name
.c_str(), char),
167 m_mainWidget
= (WXWidget
) dialogShell
;
169 // We don't want margins, since there is enough elsewhere.
170 XtVaSetValues( dialogShell
,
173 XmNresizePolicy
, XmRESIZE_NONE
,
177 XtOverrideTranslations(dialogShell
,
178 ptr
= XtParseTranslationTable("<Configure>: resize()"));
181 XtRealizeWidget(dialogShell
);
183 wxAddWindowToTable( (Widget
)m_mainWidget
, this );
188 void wxDialog::SetModal(bool flag
)
191 wxModelessWindows
.DeleteObject(this);
193 wxModelessWindows
.Append(this);
196 wxDialog::~wxDialog()
198 m_isBeingDeleted
= true;
204 XtRemoveEventHandler((Widget
) m_mainWidget
, ExposureMask
, False
,
205 wxUniversalRepaintProc
, (XtPointer
) this);
208 m_modalShowing
= false;
210 #if !wxUSE_INVISIBLE_RESIZE
213 XtUnmapWidget((Widget
) m_mainWidget
);
221 wxDeleteWindowFromTable( (Widget
)m_mainWidget
);
222 XtDestroyWidget( (Widget
)m_mainWidget
);
226 void wxDialog::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
228 XtVaSetValues((Widget
) m_mainWidget
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
229 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
230 XtVaSetValues((Widget
) m_mainWidget
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
233 void wxDialog::DoSetClientSize(int width
, int height
)
235 wxWindow::SetSize(-1, -1, width
, height
);
238 void wxDialog::SetTitle(const wxString
& title
)
240 wxTopLevelWindow::SetTitle( title
);
244 wxXmString
str( title
);
245 XtVaSetValues( (Widget
)m_mainWidget
,
246 XmNtitle
, title
.c_str(),
247 XmNdialogTitle
, str(), // Roberto Cocchi
248 XmNiconName
, title
.c_str(),
253 bool wxDialog::Show( bool show
)
255 if( !wxWindowBase::Show( show
) )
262 // this usually will result in TransferDataToWindow() being called
263 // which will change the controls values so do it before showing as
264 // otherwise we could have some flicker
270 #if !wxUSE_INVISIBLE_RESIZE
271 XtMapWidget(XtParent((Widget
) m_mainWidget
));
273 XtManageChild((Widget
)m_mainWidget
) ;
276 XRaiseWindow( XtDisplay( (Widget
)m_mainWidget
),
277 XtWindow( (Widget
)m_mainWidget
) );
282 #if !wxUSE_INVISIBLE_RESIZE
283 XtUnmapWidget(XtParent((Widget
) m_mainWidget
));
285 XtUnmanageChild((Widget
)m_mainWidget
) ;
288 XFlush(XtDisplay((Widget
)m_mainWidget
));
289 XSync(XtDisplay((Widget
)m_mainWidget
), False
);
295 // Shows a dialog modally, returning a return code
296 int wxDialog::ShowModal()
300 // after the event loop ran, the widget might already have been destroyed
301 WXDisplay
* display
= (WXDisplay
*)XtDisplay( (Widget
)m_mainWidget
);
305 m_eventLoop
= new wxEventLoop
;
307 m_modalShowing
= true;
308 XtAddGrab((Widget
) m_mainWidget
, True
, False
);
312 // Now process all events in case they get sent to a destroyed dialog
313 wxFlushEvents( display
);
318 // TODO: is it safe to call this, if the dialog may have been deleted
319 // by now? Probably only if we're using delayed deletion of dialogs.
320 return GetReturnCode();
323 void wxDialog::EndModal(int retCode
)
328 SetReturnCode(retCode
);
330 // Strangely, we don't seem to need this now.
331 // XtRemoveGrab((Widget) m_mainWidget);
335 m_modalShowing
= false;
341 // Destroy the window (delayed, if a managed window)
342 bool wxDialog::Destroy()
344 if (!wxPendingDelete
.Member(this))
345 wxPendingDelete
.Append(this);
349 void wxDialog::ChangeFont(bool keepOriginalSize
)
351 wxWindow::ChangeFont(keepOriginalSize
);
354 void wxDialog::ChangeBackgroundColour()
357 wxDoChangeBackgroundColour(GetMainWidget(), m_backgroundColour
);
360 void wxDialog::ChangeForegroundColour()
363 wxDoChangeForegroundColour(GetMainWidget(), m_foregroundColour
);