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
);
118 typedef Widget (*DialogCreateFunction
)(Widget
, String
, ArgList
, Cardinal
);
121 int wxMessageDialog::ShowModal()
123 const long style
= GetMessageDialogStyle();
125 DialogCreateFunction dialogCreateFunction
;
126 if ( style
& wxYES_NO
)
128 // if we have [Yes], it must be a question
129 dialogCreateFunction
= XmCreateQuestionDialog
;
131 else if ( style
& wxICON_STOP
)
133 // error dialog is the one with error icon...
134 dialogCreateFunction
= XmCreateErrorDialog
;
136 else if ( style
& wxICON_EXCLAMATION
)
138 // ...and the warning dialog too
139 dialogCreateFunction
= XmCreateWarningDialog
;
143 // finally, use the info dialog by default
144 dialogCreateFunction
= XmCreateInformationDialog
;
147 Widget wParent
= m_parent
? GetWidget(m_parent
) : (Widget
) 0;
150 wxWindow
*window
= wxTheApp
->GetTopWindow();
153 wxFAIL_MSG("can't show message box without parent window");
158 wParent
= GetWidget(window
);
161 // prepare the arg list
165 wxXmString
text(m_message
);
166 wxXmString
title(m_caption
);
167 XtSetArg(args
[ac
], XmNmessageString
, text()); ac
++;
168 XtSetArg(args
[ac
], XmNdialogTitle
, title()); ac
++;
170 Display
* dpy
= XtDisplay(wParent
);
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
++;
179 wxFont font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
181 #if __WXMOTIF20__ && !__WXLESSTIF__
182 XtSetArg(args
[ac
], XmNbuttonRenderTable
, font
.GetFontTypeC(dpy
)); ac
++;
183 XtSetArg(args
[ac
], XmNlabelRenderTable
, font
.GetFontTypeC(dpy
)); ac
++;
184 XtSetArg(args
[ac
], XmNtextRenderTable
, font
.GetFontTypeC(dpy
)); ac
++;
186 XtSetArg(args
[ac
], XmNbuttonFontList
, font
.GetFontTypeC(dpy
)); ac
++;
187 XtSetArg(args
[ac
], XmNlabelFontList
, font
.GetFontTypeC(dpy
)); ac
++;
188 XtSetArg(args
[ac
], XmNtextFontList
, font
.GetFontTypeC(dpy
)); ac
++;
191 // do create message box
193 Widget wMsgBox
= (*dialogCreateFunction
)(wParent
, wxMOTIF_STR(""), args
, ac
);
195 wxCHECK_MSG( wMsgBox
, wxID_CANCEL
, "msg box creation failed" );
197 // get the buttons which we might either remove or rename
198 // depending on the requested style
200 Widget wBtnOk
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_OK_BUTTON
);
201 Widget wBtnHelp
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_HELP_BUTTON
);
202 Widget wBtnCancel
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_CANCEL_BUTTON
);
204 if ( style
& wxYES_NO
)
206 wxXmString
yes(_("Yes")), no(_("No")), cancel(_("Cancel"));
208 if ( style
& wxCANCEL
)
210 // use the cancel button for No and the help button for
213 XtVaSetValues(wBtnOk
, XmNlabelString
, yes(), NULL
);
214 XtVaSetValues(wBtnCancel
, XmNlabelString
, no(), NULL
);
215 XtVaSetValues(wBtnHelp
, XmNlabelString
, cancel(), NULL
);
219 // no cancel button requested...
220 // remove the help button and use cancel for no
222 XtVaSetValues(wBtnCancel
, XmNlabelString
, no(), NULL
);
223 XtUnmanageChild(wBtnHelp
);
228 // remove the help button and the cancel button (unless it was
231 XtUnmanageChild(wBtnHelp
);
232 if ( !(style
& wxCANCEL
) ) XtUnmanageChild(wBtnCancel
);
235 // set the callbacks for the message box buttons
236 XtAddCallback(wMsgBox
, XmNokCallback
,
237 (XtCallbackProc
)msgboxCallBackOk
, (XtPointer
)this);
238 XtAddCallback(wMsgBox
, XmNcancelCallback
,
239 (XtCallbackProc
)msgboxCallBackCancel
, (XtPointer
)this);
240 XtAddCallback(wMsgBox
, XmNhelpCallback
,
241 (XtCallbackProc
)msgboxCallBackHelp
, (XtPointer
)this);
242 XtAddCallback(wMsgBox
, XmNunmapCallback
,
243 (XtCallbackProc
)msgboxCallBackClose
, (XtPointer
)this);
245 // show it as a modal dialog
246 XtManageChild(wMsgBox
);
247 XtAddGrab(wMsgBox
, True
, False
);
249 // the m_result will be changed when message box goes away
252 // local message loop
253 XtAppContext context
= XtWidgetToApplicationContext(wParent
);
255 while ( m_result
== -1 )
257 XtAppNextEvent(context
, &event
);
258 XtDispatchEvent(&event
);
261 // translate the result if necessary
262 if ( style
& wxYES_NO
)
264 if ( m_result
== wxID_OK
)
266 else if ( m_result
== wxID_CANCEL
)
268 else if ( m_result
== wxID_HELP
)
269 m_result
= wxID_CANCEL
;