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 #pragma message disable nosimpint
25 #include "wx/vms_x_fix.h"
30 #include <Xm/MessageB.h>
32 #pragma message enable nosimpint
35 #include "wx/msgdlg.h"
40 #include "wx/settings.h"
43 #include "wx/modalhook.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 WX_HOOK_MODAL_DIALOG();
111 const long style
= GetMessageDialogStyle();
113 DialogCreateFunction dialogCreateFunction
;
114 if ( style
& wxYES_NO
)
116 // if we have [Yes], it must be a question
117 dialogCreateFunction
= XmCreateQuestionDialog
;
119 else if ( style
& wxICON_STOP
)
121 // error dialog is the one with error icon...
122 dialogCreateFunction
= XmCreateErrorDialog
;
124 else if ( style
& wxICON_EXCLAMATION
)
126 // ...and the warning dialog too
127 dialogCreateFunction
= XmCreateWarningDialog
;
131 // finally, use the info dialog by default
132 dialogCreateFunction
= XmCreateInformationDialog
;
135 Widget wParent
= m_parent
? GetWidget(m_parent
) : (Widget
) 0;
138 wxWindow
*window
= wxTheApp
->GetTopWindow();
141 wxFAIL_MSG("can't show message box without parent window");
146 wParent
= GetWidget(window
);
149 // prepare the arg list
153 wxXmString
text(GetFullMessage());
154 wxXmString
title(m_caption
);
155 XtSetArg(args
[ac
], XmNmessageString
, text()); ac
++;
156 XtSetArg(args
[ac
], XmNdialogTitle
, title()); ac
++;
158 Display
* dpy
= XtDisplay(wParent
);
160 if (m_backgroundColour
.IsOk())
162 wxComputeColours (dpy
, & m_backgroundColour
, NULL
);
164 XtSetArg(args
[ac
], XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
); ac
++;
165 XtSetArg(args
[ac
], XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
); ac
++;
166 XtSetArg(args
[ac
], XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
); ac
++;
167 XtSetArg(args
[ac
], XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
); ac
++;
170 wxFont font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
172 #if __WXMOTIF20__ && !__WXLESSTIF__
173 XtSetArg(args
[ac
], XmNbuttonRenderTable
, font
.GetFontTypeC(dpy
)); ac
++;
174 XtSetArg(args
[ac
], XmNlabelRenderTable
, font
.GetFontTypeC(dpy
)); ac
++;
175 XtSetArg(args
[ac
], XmNtextRenderTable
, font
.GetFontTypeC(dpy
)); ac
++;
177 XtSetArg(args
[ac
], XmNbuttonFontList
, font
.GetFontTypeC(dpy
)); ac
++;
178 XtSetArg(args
[ac
], XmNlabelFontList
, font
.GetFontTypeC(dpy
)); ac
++;
179 XtSetArg(args
[ac
], XmNtextFontList
, font
.GetFontTypeC(dpy
)); ac
++;
182 // do create message box
184 Widget wMsgBox
= (*dialogCreateFunction
)(wParent
, wxMOTIF_STR(""), args
, ac
);
186 wxCHECK_MSG( wMsgBox
, wxID_CANCEL
, "msg box creation failed" );
188 // get the buttons which we might either remove or rename
189 // depending on the requested style
191 Widget wBtnOk
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_OK_BUTTON
);
192 Widget wBtnHelp
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_HELP_BUTTON
);
193 Widget wBtnCancel
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_CANCEL_BUTTON
);
195 if ( style
& wxYES_NO
)
197 wxXmString
yes(_("Yes")), no(_("No")), cancel(_("Cancel"));
199 if ( style
& wxCANCEL
)
201 // use the cancel button for No and the help button for
204 XtVaSetValues(wBtnOk
, XmNlabelString
, yes(), NULL
);
205 XtVaSetValues(wBtnCancel
, XmNlabelString
, no(), NULL
);
206 XtVaSetValues(wBtnHelp
, XmNlabelString
, cancel(), NULL
);
210 // no cancel button requested...
211 // remove the help button and use cancel for no
213 XtVaSetValues(wBtnCancel
, XmNlabelString
, no(), NULL
);
214 XtUnmanageChild(wBtnHelp
);
219 // remove the help button and the cancel button (unless it was
222 XtUnmanageChild(wBtnHelp
);
223 if ( !(style
& wxCANCEL
) ) XtUnmanageChild(wBtnCancel
);
226 // set the callbacks for the message box buttons
227 XtAddCallback(wMsgBox
, XmNokCallback
,
228 (XtCallbackProc
)msgboxCallBackOk
, (XtPointer
)this);
229 XtAddCallback(wMsgBox
, XmNcancelCallback
,
230 (XtCallbackProc
)msgboxCallBackCancel
, (XtPointer
)this);
231 XtAddCallback(wMsgBox
, XmNhelpCallback
,
232 (XtCallbackProc
)msgboxCallBackHelp
, (XtPointer
)this);
233 XtAddCallback(wMsgBox
, XmNunmapCallback
,
234 (XtCallbackProc
)msgboxCallBackClose
, (XtPointer
)this);
236 // show it as a modal dialog
237 XtManageChild(wMsgBox
);
238 XtAddGrab(wMsgBox
, True
, False
);
240 // the m_result will be changed when message box goes away
243 // local message loop
244 XtAppContext context
= XtWidgetToApplicationContext(wParent
);
246 while ( m_result
== -1 )
248 XtAppNextEvent(context
, &event
);
249 XtDispatchEvent(&event
);
252 // translate the result if necessary
253 if ( style
& wxYES_NO
)
255 if ( m_result
== wxID_OK
)
257 else if ( m_result
== wxID_CANCEL
)
259 else if ( m_result
== wxID_HELP
)
260 m_result
= wxID_CANCEL
;