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 // ----------------------------------------------------------------------------
102 wxMessageDialog::wxMessageDialog(wxWindow
*parent
,
103 const wxString
& message
,
104 const wxString
& caption
,
106 const wxPoint
& WXUNUSED(pos
))
111 SetMessageDialogStyle(style
);
116 typedef Widget (*DialogCreateFunction
)(Widget
, String
, ArgList
, Cardinal
);
119 int wxMessageDialog::ShowModal()
121 const long style
= GetMessageDialogStyle();
123 DialogCreateFunction dialogCreateFunction
;
124 if ( style
& wxYES_NO
)
126 // if we have [Yes], it must be a question
127 dialogCreateFunction
= XmCreateQuestionDialog
;
129 else if ( style
& wxICON_STOP
)
131 // error dialog is the one with error icon...
132 dialogCreateFunction
= XmCreateErrorDialog
;
134 else if ( style
& wxICON_EXCLAMATION
)
136 // ...and the warning dialog too
137 dialogCreateFunction
= XmCreateWarningDialog
;
141 // finally, use the info dialog by default
142 dialogCreateFunction
= XmCreateInformationDialog
;
145 Widget wParent
= m_parent
? GetWidget(m_parent
) : (Widget
) 0;
148 wxWindow
*window
= wxTheApp
->GetTopWindow();
151 wxFAIL_MSG("can't show message box without parent window");
156 wParent
= GetWidget(window
);
159 // prepare the arg list
163 wxXmString
text(m_message
);
164 wxXmString
title(m_caption
);
165 XtSetArg(args
[ac
], XmNmessageString
, text()); ac
++;
166 XtSetArg(args
[ac
], XmNdialogTitle
, title()); ac
++;
168 Display
* dpy
= XtDisplay(wParent
);
170 if (m_backgroundColour
.Ok())
172 wxComputeColours (dpy
, & m_backgroundColour
, (wxColour
*) NULL
);
174 XtSetArg(args
[ac
], XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
); ac
++;
175 XtSetArg(args
[ac
], XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
); ac
++;
176 XtSetArg(args
[ac
], XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
); ac
++;
177 XtSetArg(args
[ac
], XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
); ac
++;
180 wxFont font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
182 #if __WXMOTIF20__ && !__WXLESSTIF__
183 XtSetArg(args
[ac
], XmNbuttonRenderTable
, font
.GetFontTypeC(dpy
)); ac
++;
184 XtSetArg(args
[ac
], XmNlabelRenderTable
, font
.GetFontTypeC(dpy
)); ac
++;
185 XtSetArg(args
[ac
], XmNtextRenderTable
, font
.GetFontTypeC(dpy
)); ac
++;
187 XtSetArg(args
[ac
], XmNbuttonFontList
, font
.GetFontTypeC(dpy
)); ac
++;
188 XtSetArg(args
[ac
], XmNlabelFontList
, font
.GetFontTypeC(dpy
)); ac
++;
189 XtSetArg(args
[ac
], XmNtextFontList
, font
.GetFontTypeC(dpy
)); ac
++;
192 // do create message box
194 Widget wMsgBox
= (*dialogCreateFunction
)(wParent
, wxMOTIF_STR(""), args
, ac
);
196 wxCHECK_MSG( wMsgBox
, wxID_CANCEL
, "msg box creation failed" );
198 // get the buttons which we might either remove or rename
199 // depending on the requested style
201 Widget wBtnOk
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_OK_BUTTON
);
202 Widget wBtnHelp
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_HELP_BUTTON
);
203 Widget wBtnCancel
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_CANCEL_BUTTON
);
205 if ( style
& wxYES_NO
)
207 wxXmString
yes(_("Yes")), no(_("No")), cancel(_("Cancel"));
209 if ( style
& wxCANCEL
)
211 // use the cancel button for No and the help button for
214 XtVaSetValues(wBtnOk
, XmNlabelString
, yes(), NULL
);
215 XtVaSetValues(wBtnCancel
, XmNlabelString
, no(), NULL
);
216 XtVaSetValues(wBtnHelp
, XmNlabelString
, cancel(), NULL
);
220 // no cancel button requested...
221 // remove the help button and use cancel for no
223 XtVaSetValues(wBtnCancel
, XmNlabelString
, no(), NULL
);
224 XtUnmanageChild(wBtnHelp
);
229 // remove the help button and the cancel button (unless it was
232 XtUnmanageChild(wBtnHelp
);
233 if ( !(style
& wxCANCEL
) ) XtUnmanageChild(wBtnCancel
);
236 // set the callbacks for the message box buttons
237 XtAddCallback(wMsgBox
, XmNokCallback
,
238 (XtCallbackProc
)msgboxCallBackOk
, (XtPointer
)this);
239 XtAddCallback(wMsgBox
, XmNcancelCallback
,
240 (XtCallbackProc
)msgboxCallBackCancel
, (XtPointer
)this);
241 XtAddCallback(wMsgBox
, XmNhelpCallback
,
242 (XtCallbackProc
)msgboxCallBackHelp
, (XtPointer
)this);
243 XtAddCallback(wMsgBox
, XmNunmapCallback
,
244 (XtCallbackProc
)msgboxCallBackClose
, (XtPointer
)this);
246 // show it as a modal dialog
247 XtManageChild(wMsgBox
);
248 XtAddGrab(wMsgBox
, True
, False
);
250 // the m_result will be changed when message box goes away
253 // local message loop
254 XtAppContext context
= XtWidgetToApplicationContext(wParent
);
256 while ( m_result
== -1 )
258 XtAppNextEvent(context
, &event
);
259 XtDispatchEvent(&event
);
262 // translate the result if necessary
263 if ( style
& wxYES_NO
)
265 if ( m_result
== wxID_OK
)
267 else if ( m_result
== wxID_CANCEL
)
269 else if ( m_result
== wxID_HELP
)
270 m_result
= wxID_CANCEL
;