1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/motif/msgdlg.cpp
3 // Purpose: wxMessageDialog
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
26 #define XtDisplay XTDISPLAY
27 #pragma message disable nosimpint
28 #include <wx/vms_x_fix.h>
33 #include <Xm/MessageB.h>
35 #pragma message enable nosimpint
40 #include "wx/msgdlg.h"
41 #include "wx/motif/private.h"
42 #include "wx/settings.h"
44 // ----------------------------------------------------------------------------
46 // ----------------------------------------------------------------------------
48 IMPLEMENT_CLASS(wxMessageDialog
, wxDialog
)
50 // ============================================================================
52 // ============================================================================
54 // ----------------------------------------------------------------------------
55 // the callbacks for message box buttons
56 // ----------------------------------------------------------------------------
59 static void msgboxCallBack(Widget w
, void* client_data
, int id
)
64 wxMessageDialog
*dlg
= (wxMessageDialog
*)client_data
;
68 static void msgboxCallBackOk(Widget w
,
70 XmAnyCallbackStruct
*WXUNUSED(call_data
))
72 msgboxCallBack(w
, client_data
, wxID_OK
);
75 static void msgboxCallBackCancel(Widget w
,
77 XmAnyCallbackStruct
*WXUNUSED(call_data
))
79 msgboxCallBack(w
, client_data
, wxID_CANCEL
);
82 static void msgboxCallBackHelp(Widget w
,
84 XmAnyCallbackStruct
*WXUNUSED(call_data
))
86 msgboxCallBack(w
, client_data
, wxID_HELP
);
89 static void msgboxCallBackClose(Widget w
,
91 XmAnyCallbackStruct
*WXUNUSED(call_data
))
93 msgboxCallBack(w
, client_data
, wxID_CANCEL
);
96 // ----------------------------------------------------------------------------
98 // ----------------------------------------------------------------------------
100 wxMessageDialog::wxMessageDialog(wxWindow
*parent
,
101 const wxString
& message
,
102 const wxString
& caption
,
104 const wxPoint
& WXUNUSED(pos
))
109 SetMessageDialogStyle(style
);
114 typedef Widget (*DialogCreateFunction
)(Widget
, String
, ArgList
, Cardinal
);
117 int wxMessageDialog::ShowModal()
119 const long style
= GetMessageDialogStyle();
121 DialogCreateFunction dialogCreateFunction
;
122 if ( style
& wxYES_NO
)
124 // if we have [Yes], it must be a question
125 dialogCreateFunction
= XmCreateQuestionDialog
;
127 else if ( style
& wxICON_STOP
)
129 // error dialog is the one with error icon...
130 dialogCreateFunction
= XmCreateErrorDialog
;
132 else if ( style
& wxICON_EXCLAMATION
)
134 // ...and the warning dialog too
135 dialogCreateFunction
= XmCreateWarningDialog
;
139 // finally, use the info dialog by default
140 dialogCreateFunction
= XmCreateInformationDialog
;
143 Widget wParent
= m_parent
? GetWidget(m_parent
) : (Widget
) 0;
146 wxWindow
*window
= wxTheApp
->GetTopWindow();
149 wxFAIL_MSG("can't show message box without parent window");
154 wParent
= GetWidget(window
);
157 // prepare the arg list
161 wxXmString
text(m_message
);
162 wxXmString
title(m_caption
);
163 XtSetArg(args
[ac
], XmNmessageString
, text()); ac
++;
164 XtSetArg(args
[ac
], XmNdialogTitle
, title()); ac
++;
166 Display
* dpy
= XtDisplay(wParent
);
168 wxComputeColours (dpy
, & m_backgroundColour
, (wxColour
*) NULL
);
170 XtSetArg(args
[ac
], XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
); ac
++;
171 XtSetArg(args
[ac
], XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
); ac
++;
172 XtSetArg(args
[ac
], XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
); ac
++;
173 XtSetArg(args
[ac
], XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
); ac
++;
175 wxFont font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
177 #if __WXMOTIF20__ && !__WXLESSTIF__
178 XtSetArg(args
[ac
], XmNbuttonRenderTable
, font
.GetFontTypeC(dpy
)); ac
++;
179 XtSetArg(args
[ac
], XmNlabelRenderTable
, font
.GetFontTypeC(dpy
)); ac
++;
180 XtSetArg(args
[ac
], XmNtextRenderTable
, font
.GetFontTypeC(dpy
)); ac
++;
182 XtSetArg(args
[ac
], XmNbuttonFontList
, font
.GetFontTypeC(dpy
)); ac
++;
183 XtSetArg(args
[ac
], XmNlabelFontList
, font
.GetFontTypeC(dpy
)); ac
++;
184 XtSetArg(args
[ac
], XmNtextFontList
, font
.GetFontTypeC(dpy
)); ac
++;
187 // do create message box
189 Widget wMsgBox
= (*dialogCreateFunction
)(wParent
, wxMOTIF_STR(""), args
, ac
);
191 wxCHECK_MSG( wMsgBox
, wxID_CANCEL
, "msg box creation failed" );
193 // get the buttons which we might either remove or rename
194 // depending on the requested style
196 Widget wBtnOk
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_OK_BUTTON
);
197 Widget wBtnHelp
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_HELP_BUTTON
);
198 Widget wBtnCancel
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_CANCEL_BUTTON
);
200 if ( style
& wxYES_NO
)
202 wxXmString
yes(_("Yes")), no(_("No")), cancel(_("Cancel"));
204 if ( style
& wxCANCEL
)
206 // use the cancel button for No and the help button for
209 XtVaSetValues(wBtnOk
, XmNlabelString
, yes(), NULL
);
210 XtVaSetValues(wBtnCancel
, XmNlabelString
, no(), NULL
);
211 XtVaSetValues(wBtnHelp
, XmNlabelString
, cancel(), NULL
);
215 // no cancel button requested...
216 // remove the help button and use cancel for no
218 XtVaSetValues(wBtnCancel
, XmNlabelString
, no(), NULL
);
219 XtUnmanageChild(wBtnHelp
);
224 // remove the help button and the cancel button (unless it was
227 XtUnmanageChild(wBtnHelp
);
228 if ( !(style
& wxCANCEL
) ) XtUnmanageChild(wBtnCancel
);
231 // set the callbacks for the message box buttons
232 XtAddCallback(wMsgBox
, XmNokCallback
,
233 (XtCallbackProc
)msgboxCallBackOk
, (XtPointer
)this);
234 XtAddCallback(wMsgBox
, XmNcancelCallback
,
235 (XtCallbackProc
)msgboxCallBackCancel
, (XtPointer
)this);
236 XtAddCallback(wMsgBox
, XmNhelpCallback
,
237 (XtCallbackProc
)msgboxCallBackHelp
, (XtPointer
)this);
238 XtAddCallback(wMsgBox
, XmNunmapCallback
,
239 (XtCallbackProc
)msgboxCallBackClose
, (XtPointer
)this);
241 // show it as a modal dialog
242 XtManageChild(wMsgBox
);
243 XtAddGrab(wMsgBox
, True
, False
);
245 // the m_result will be changed when message box goes away
248 // local message loop
249 XtAppContext context
= XtWidgetToApplicationContext(wParent
);
251 while ( m_result
== -1 )
253 XtAppNextEvent(context
, &event
);
254 XtDispatchEvent(&event
);
257 // translate the result if necessary
258 if ( style
& wxYES_NO
)
260 if ( m_result
== wxID_OK
)
262 else if ( m_result
== wxID_CANCEL
)
264 else if ( m_result
== wxID_HELP
)
265 m_result
= wxID_CANCEL
;