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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
17 #pragma implementation "msgdlg.h"
20 // ----------------------------------------------------------------------------
22 // ----------------------------------------------------------------------------
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
30 #define XtDisplay XTDISPLAY
31 #pragma message disable nosimpint
32 #include <wx/vms_x_fix.h>
37 #include <Xm/MessageB.h>
39 #pragma message enable nosimpint
44 #include "wx/msgdlg.h"
45 #include "wx/motif/private.h"
46 #include "wx/settings.h"
48 // ----------------------------------------------------------------------------
50 // ----------------------------------------------------------------------------
52 IMPLEMENT_CLASS(wxMessageDialog
, wxDialog
)
54 // ============================================================================
56 // ============================================================================
58 // ----------------------------------------------------------------------------
59 // the callbacks for message box buttons
60 // ----------------------------------------------------------------------------
63 static void msgboxCallBack(Widget w
, void* client_data
, int id
)
68 wxMessageDialog
*dlg
= (wxMessageDialog
*)client_data
;
72 static void msgboxCallBackOk(Widget w
,
74 XmAnyCallbackStruct
*WXUNUSED(call_data
))
76 msgboxCallBack(w
, client_data
, wxID_OK
);
79 static void msgboxCallBackCancel(Widget w
,
81 XmAnyCallbackStruct
*WXUNUSED(call_data
))
83 msgboxCallBack(w
, client_data
, wxID_CANCEL
);
86 static void msgboxCallBackHelp(Widget w
,
88 XmAnyCallbackStruct
*WXUNUSED(call_data
))
90 msgboxCallBack(w
, client_data
, wxID_HELP
);
93 static void msgboxCallBackClose(Widget w
,
95 XmAnyCallbackStruct
*WXUNUSED(call_data
))
97 msgboxCallBack(w
, client_data
, wxID_CANCEL
);
100 // ----------------------------------------------------------------------------
102 // ----------------------------------------------------------------------------
104 wxMessageDialog::wxMessageDialog(wxWindow
*parent
,
105 const wxString
& message
,
106 const wxString
& caption
,
108 const wxPoint
& WXUNUSED(pos
))
113 SetMessageDialogStyle(style
);
116 int wxMessageDialog::ShowModal()
118 Widget (*dialogCreateFunction
)(Widget
, String
, ArgList
, Cardinal
) = NULL
;
119 const long style
= GetMessageDialogStyle();
121 if ( style
& wxYES_NO
)
123 // if we have [Yes], it must be a question
124 dialogCreateFunction
= XmCreateQuestionDialog
;
126 else if ( style
& wxICON_STOP
)
128 // error dialog is the one with error icon...
129 dialogCreateFunction
= XmCreateErrorDialog
;
131 else if ( style
& wxICON_EXCLAMATION
)
133 // ...and the warning dialog too
134 dialogCreateFunction
= XmCreateWarningDialog
;
138 // finally, use the info dialog by default
139 dialogCreateFunction
= XmCreateInformationDialog
;
142 Widget wParent
= m_parent
? GetWidget(m_parent
) : (Widget
) 0;
145 wxWindow
*window
= wxTheApp
->GetTopWindow();
148 wxFAIL_MSG("can't show message box without parent window");
153 wParent
= GetWidget(window
);
156 // prepare the arg list
160 wxXmString
text(m_message
);
161 wxXmString
title(m_caption
);
162 XtSetArg(args
[ac
], XmNmessageString
, text()); ac
++;
163 XtSetArg(args
[ac
], XmNdialogTitle
, title()); ac
++;
165 Display
* dpy
= XtDisplay(wParent
);
167 wxComputeColours (dpy
, & m_backgroundColour
, (wxColour
*) NULL
);
169 XtSetArg(args
[ac
], XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
); ac
++;
170 XtSetArg(args
[ac
], XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
); ac
++;
171 XtSetArg(args
[ac
], XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
); ac
++;
172 XtSetArg(args
[ac
], XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
); ac
++;
174 wxFont font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
176 #if __WXMOTIF20__ && !__WXLESSTIF__
177 XtSetArg(args
[ac
], XmNbuttonRenderTable
, font
.GetFontTypeC(dpy
)); ac
++;
178 XtSetArg(args
[ac
], XmNlabelRenderTable
, font
.GetFontTypeC(dpy
)); ac
++;
179 XtSetArg(args
[ac
], XmNtextRenderTable
, font
.GetFontTypeC(dpy
)); ac
++;
181 XtSetArg(args
[ac
], XmNbuttonFontList
, font
.GetFontTypeC(dpy
)); ac
++;
182 XtSetArg(args
[ac
], XmNlabelFontList
, font
.GetFontTypeC(dpy
)); ac
++;
183 XtSetArg(args
[ac
], XmNtextFontList
, font
.GetFontTypeC(dpy
)); ac
++;
186 // do create message box
188 Widget wMsgBox
= (*dialogCreateFunction
)(wParent
, "", args
, ac
);
190 wxCHECK_MSG( wMsgBox
, wxID_CANCEL
, "msg box creation failed" );
192 // get the buttons which we might either remove or rename
193 // depending on the requested style
195 Widget wBtnOk
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_OK_BUTTON
);
196 Widget wBtnHelp
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_HELP_BUTTON
);
197 Widget wBtnCancel
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_CANCEL_BUTTON
);
199 if ( style
& wxYES_NO
)
201 wxXmString
yes(_("Yes")), no(_("No")), cancel(_("Cancel"));
203 if ( style
& wxCANCEL
)
205 // use the cancel button for No and the help button for
208 XtVaSetValues(wBtnOk
, XmNlabelString
, yes(), NULL
);
209 XtVaSetValues(wBtnCancel
, XmNlabelString
, no(), NULL
);
210 XtVaSetValues(wBtnHelp
, XmNlabelString
, cancel(), NULL
);
214 // no cancel button requested...
215 // remove the help button and use cancel for no
217 XtVaSetValues(wBtnCancel
, XmNlabelString
, no(), NULL
);
218 XtUnmanageChild(wBtnHelp
);
223 // remove the help button and the cancel button (unless it was
226 XtUnmanageChild(wBtnHelp
);
227 if ( !(style
& wxCANCEL
) ) XtUnmanageChild(wBtnCancel
);
230 // set the callbacks for the message box buttons
231 XtAddCallback(wMsgBox
, XmNokCallback
,
232 (XtCallbackProc
)msgboxCallBackOk
, (XtPointer
)this);
233 XtAddCallback(wMsgBox
, XmNcancelCallback
,
234 (XtCallbackProc
)msgboxCallBackCancel
, (XtPointer
)this);
235 XtAddCallback(wMsgBox
, XmNhelpCallback
,
236 (XtCallbackProc
)msgboxCallBackHelp
, (XtPointer
)this);
237 XtAddCallback(wMsgBox
, XmNunmapCallback
,
238 (XtCallbackProc
)msgboxCallBackClose
, (XtPointer
)this);
240 // show it as a modal dialog
241 XtManageChild(wMsgBox
);
242 XtAddGrab(wMsgBox
, True
, False
);
244 // the m_result will be changed when message box goes away
247 // local message loop
248 XtAppContext context
= XtWidgetToApplicationContext(wParent
);
250 while ( m_result
== -1 )
252 XtAppNextEvent(context
, &event
);
253 XtDispatchEvent(&event
);
256 // translate the result if necessary
257 if ( style
& wxYES_NO
)
259 if ( m_result
== wxID_OK
)
261 else if ( m_result
== wxID_CANCEL
)
263 else if ( m_result
== wxID_HELP
)
264 m_result
= wxID_CANCEL
;