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"
24 #define XtDisplay XTDISPLAY
25 #pragma message disable nosimpint
26 #include "wx/vms_x_fix.h"
31 #include <Xm/MessageB.h>
33 #pragma message enable nosimpint
36 #include "wx/msgdlg.h"
41 #include "wx/settings.h"
44 #include "wx/motif/private.h"
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
50 IMPLEMENT_CLASS(wxMessageDialog
, wxDialog
)
52 // ============================================================================
54 // ============================================================================
56 // ----------------------------------------------------------------------------
57 // the callbacks for message box buttons
58 // ----------------------------------------------------------------------------
61 static void msgboxCallBack(Widget w
, void* client_data
, int id
)
66 wxMessageDialog
*dlg
= (wxMessageDialog
*)client_data
;
70 static void msgboxCallBackOk(Widget w
,
72 XmAnyCallbackStruct
*WXUNUSED(call_data
))
74 msgboxCallBack(w
, client_data
, wxID_OK
);
77 static void msgboxCallBackCancel(Widget w
,
79 XmAnyCallbackStruct
*WXUNUSED(call_data
))
81 msgboxCallBack(w
, client_data
, wxID_CANCEL
);
84 static void msgboxCallBackHelp(Widget w
,
86 XmAnyCallbackStruct
*WXUNUSED(call_data
))
88 msgboxCallBack(w
, client_data
, wxID_HELP
);
91 static void msgboxCallBackClose(Widget w
,
93 XmAnyCallbackStruct
*WXUNUSED(call_data
))
95 msgboxCallBack(w
, client_data
, wxID_CANCEL
);
98 // ----------------------------------------------------------------------------
100 // ----------------------------------------------------------------------------
104 typedef Widget (*DialogCreateFunction
)(Widget
, String
, ArgList
, Cardinal
);
107 int wxMessageDialog::ShowModal()
109 const long style
= GetMessageDialogStyle();
111 DialogCreateFunction dialogCreateFunction
;
112 if ( style
& wxYES_NO
)
114 // if we have [Yes], it must be a question
115 dialogCreateFunction
= XmCreateQuestionDialog
;
117 else if ( style
& wxICON_STOP
)
119 // error dialog is the one with error icon...
120 dialogCreateFunction
= XmCreateErrorDialog
;
122 else if ( style
& wxICON_EXCLAMATION
)
124 // ...and the warning dialog too
125 dialogCreateFunction
= XmCreateWarningDialog
;
129 // finally, use the info dialog by default
130 dialogCreateFunction
= XmCreateInformationDialog
;
133 Widget wParent
= m_parent
? GetWidget(m_parent
) : (Widget
) 0;
136 wxWindow
*window
= wxTheApp
->GetTopWindow();
139 wxFAIL_MSG("can't show message box without parent window");
144 wParent
= GetWidget(window
);
147 // prepare the arg list
151 wxXmString
text(GetFullMessage());
152 wxXmString
title(m_caption
);
153 XtSetArg(args
[ac
], XmNmessageString
, text()); ac
++;
154 XtSetArg(args
[ac
], XmNdialogTitle
, title()); ac
++;
156 Display
* dpy
= XtDisplay(wParent
);
158 if (m_backgroundColour
.Ok())
160 wxComputeColours (dpy
, & m_backgroundColour
, (wxColour
*) NULL
);
162 XtSetArg(args
[ac
], XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
); ac
++;
163 XtSetArg(args
[ac
], XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
); ac
++;
164 XtSetArg(args
[ac
], XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
); ac
++;
165 XtSetArg(args
[ac
], XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
); ac
++;
168 wxFont font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
170 #if __WXMOTIF20__ && !__WXLESSTIF__
171 XtSetArg(args
[ac
], XmNbuttonRenderTable
, font
.GetFontTypeC(dpy
)); ac
++;
172 XtSetArg(args
[ac
], XmNlabelRenderTable
, font
.GetFontTypeC(dpy
)); ac
++;
173 XtSetArg(args
[ac
], XmNtextRenderTable
, font
.GetFontTypeC(dpy
)); ac
++;
175 XtSetArg(args
[ac
], XmNbuttonFontList
, font
.GetFontTypeC(dpy
)); ac
++;
176 XtSetArg(args
[ac
], XmNlabelFontList
, font
.GetFontTypeC(dpy
)); ac
++;
177 XtSetArg(args
[ac
], XmNtextFontList
, font
.GetFontTypeC(dpy
)); ac
++;
180 // do create message box
182 Widget wMsgBox
= (*dialogCreateFunction
)(wParent
, wxMOTIF_STR(""), args
, ac
);
184 wxCHECK_MSG( wMsgBox
, wxID_CANCEL
, "msg box creation failed" );
186 // get the buttons which we might either remove or rename
187 // depending on the requested style
189 Widget wBtnOk
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_OK_BUTTON
);
190 Widget wBtnHelp
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_HELP_BUTTON
);
191 Widget wBtnCancel
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_CANCEL_BUTTON
);
193 if ( style
& wxYES_NO
)
195 wxXmString
yes(_("Yes")), no(_("No")), cancel(_("Cancel"));
197 if ( style
& wxCANCEL
)
199 // use the cancel button for No and the help button for
202 XtVaSetValues(wBtnOk
, XmNlabelString
, yes(), NULL
);
203 XtVaSetValues(wBtnCancel
, XmNlabelString
, no(), NULL
);
204 XtVaSetValues(wBtnHelp
, XmNlabelString
, cancel(), NULL
);
208 // no cancel button requested...
209 // remove the help button and use cancel for no
211 XtVaSetValues(wBtnCancel
, XmNlabelString
, no(), NULL
);
212 XtUnmanageChild(wBtnHelp
);
217 // remove the help button and the cancel button (unless it was
220 XtUnmanageChild(wBtnHelp
);
221 if ( !(style
& wxCANCEL
) ) XtUnmanageChild(wBtnCancel
);
224 // set the callbacks for the message box buttons
225 XtAddCallback(wMsgBox
, XmNokCallback
,
226 (XtCallbackProc
)msgboxCallBackOk
, (XtPointer
)this);
227 XtAddCallback(wMsgBox
, XmNcancelCallback
,
228 (XtCallbackProc
)msgboxCallBackCancel
, (XtPointer
)this);
229 XtAddCallback(wMsgBox
, XmNhelpCallback
,
230 (XtCallbackProc
)msgboxCallBackHelp
, (XtPointer
)this);
231 XtAddCallback(wMsgBox
, XmNunmapCallback
,
232 (XtCallbackProc
)msgboxCallBackClose
, (XtPointer
)this);
234 // show it as a modal dialog
235 XtManageChild(wMsgBox
);
236 XtAddGrab(wMsgBox
, True
, False
);
238 // the m_result will be changed when message box goes away
241 // local message loop
242 XtAppContext context
= XtWidgetToApplicationContext(wParent
);
244 while ( m_result
== -1 )
246 XtAppNextEvent(context
, &event
);
247 XtDispatchEvent(&event
);
250 // translate the result if necessary
251 if ( style
& wxYES_NO
)
253 if ( m_result
== wxID_OK
)
255 else if ( m_result
== wxID_CANCEL
)
257 else if ( m_result
== wxID_HELP
)
258 m_result
= wxID_CANCEL
;