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
38 #include "wx/msgdlg.h"
39 #include "wx/motif/private.h"
40 #include "wx/settings.h"
42 // ----------------------------------------------------------------------------
44 // ----------------------------------------------------------------------------
46 IMPLEMENT_CLASS(wxMessageDialog
, wxDialog
)
48 // ============================================================================
50 // ============================================================================
52 // ----------------------------------------------------------------------------
53 // the callbacks for message box buttons
54 // ----------------------------------------------------------------------------
57 static void msgboxCallBack(Widget w
, void* client_data
, int id
)
62 wxMessageDialog
*dlg
= (wxMessageDialog
*)client_data
;
66 static void msgboxCallBackOk(Widget w
,
68 XmAnyCallbackStruct
*WXUNUSED(call_data
))
70 msgboxCallBack(w
, client_data
, wxID_OK
);
73 static void msgboxCallBackCancel(Widget w
,
75 XmAnyCallbackStruct
*WXUNUSED(call_data
))
77 msgboxCallBack(w
, client_data
, wxID_CANCEL
);
80 static void msgboxCallBackHelp(Widget w
,
82 XmAnyCallbackStruct
*WXUNUSED(call_data
))
84 msgboxCallBack(w
, client_data
, wxID_HELP
);
87 static void msgboxCallBackClose(Widget w
,
89 XmAnyCallbackStruct
*WXUNUSED(call_data
))
91 msgboxCallBack(w
, client_data
, wxID_CANCEL
);
94 // ----------------------------------------------------------------------------
96 // ----------------------------------------------------------------------------
98 wxMessageDialog::wxMessageDialog(wxWindow
*parent
,
99 const wxString
& message
,
100 const wxString
& caption
,
102 const wxPoint
& WXUNUSED(pos
))
107 SetMessageDialogStyle(style
);
112 typedef Widget (*DialogCreateFunction
)(Widget
, String
, ArgList
, Cardinal
);
115 int wxMessageDialog::ShowModal()
117 const long style
= GetMessageDialogStyle();
119 DialogCreateFunction dialogCreateFunction
;
120 if ( style
& wxYES_NO
)
122 // if we have [Yes], it must be a question
123 dialogCreateFunction
= XmCreateQuestionDialog
;
125 else if ( style
& wxICON_STOP
)
127 // error dialog is the one with error icon...
128 dialogCreateFunction
= XmCreateErrorDialog
;
130 else if ( style
& wxICON_EXCLAMATION
)
132 // ...and the warning dialog too
133 dialogCreateFunction
= XmCreateWarningDialog
;
137 // finally, use the info dialog by default
138 dialogCreateFunction
= XmCreateInformationDialog
;
141 Widget wParent
= m_parent
? GetWidget(m_parent
) : (Widget
) 0;
144 wxWindow
*window
= wxTheApp
->GetTopWindow();
147 wxFAIL_MSG("can't show message box without parent window");
152 wParent
= GetWidget(window
);
155 // prepare the arg list
159 wxXmString
text(m_message
);
160 wxXmString
title(m_caption
);
161 XtSetArg(args
[ac
], XmNmessageString
, text()); ac
++;
162 XtSetArg(args
[ac
], XmNdialogTitle
, title()); ac
++;
164 Display
* dpy
= XtDisplay(wParent
);
166 wxComputeColours (dpy
, & m_backgroundColour
, (wxColour
*) NULL
);
168 XtSetArg(args
[ac
], XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
); ac
++;
169 XtSetArg(args
[ac
], XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
); ac
++;
170 XtSetArg(args
[ac
], XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
); ac
++;
171 XtSetArg(args
[ac
], XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
); ac
++;
173 wxFont font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
175 #if __WXMOTIF20__ && !__WXLESSTIF__
176 XtSetArg(args
[ac
], XmNbuttonRenderTable
, font
.GetFontTypeC(dpy
)); ac
++;
177 XtSetArg(args
[ac
], XmNlabelRenderTable
, font
.GetFontTypeC(dpy
)); ac
++;
178 XtSetArg(args
[ac
], XmNtextRenderTable
, font
.GetFontTypeC(dpy
)); ac
++;
180 XtSetArg(args
[ac
], XmNbuttonFontList
, font
.GetFontTypeC(dpy
)); ac
++;
181 XtSetArg(args
[ac
], XmNlabelFontList
, font
.GetFontTypeC(dpy
)); ac
++;
182 XtSetArg(args
[ac
], XmNtextFontList
, font
.GetFontTypeC(dpy
)); ac
++;
185 // do create message box
187 Widget wMsgBox
= (*dialogCreateFunction
)(wParent
, wxMOTIF_STR(""), args
, ac
);
189 wxCHECK_MSG( wMsgBox
, wxID_CANCEL
, "msg box creation failed" );
191 // get the buttons which we might either remove or rename
192 // depending on the requested style
194 Widget wBtnOk
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_OK_BUTTON
);
195 Widget wBtnHelp
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_HELP_BUTTON
);
196 Widget wBtnCancel
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_CANCEL_BUTTON
);
198 if ( style
& wxYES_NO
)
200 wxXmString
yes(_("Yes")), no(_("No")), cancel(_("Cancel"));
202 if ( style
& wxCANCEL
)
204 // use the cancel button for No and the help button for
207 XtVaSetValues(wBtnOk
, XmNlabelString
, yes(), NULL
);
208 XtVaSetValues(wBtnCancel
, XmNlabelString
, no(), NULL
);
209 XtVaSetValues(wBtnHelp
, XmNlabelString
, cancel(), NULL
);
213 // no cancel button requested...
214 // remove the help button and use cancel for no
216 XtVaSetValues(wBtnCancel
, XmNlabelString
, no(), NULL
);
217 XtUnmanageChild(wBtnHelp
);
222 // remove the help button and the cancel button (unless it was
225 XtUnmanageChild(wBtnHelp
);
226 if ( !(style
& wxCANCEL
) ) XtUnmanageChild(wBtnCancel
);
229 // set the callbacks for the message box buttons
230 XtAddCallback(wMsgBox
, XmNokCallback
,
231 (XtCallbackProc
)msgboxCallBackOk
, (XtPointer
)this);
232 XtAddCallback(wMsgBox
, XmNcancelCallback
,
233 (XtCallbackProc
)msgboxCallBackCancel
, (XtPointer
)this);
234 XtAddCallback(wMsgBox
, XmNhelpCallback
,
235 (XtCallbackProc
)msgboxCallBackHelp
, (XtPointer
)this);
236 XtAddCallback(wMsgBox
, XmNunmapCallback
,
237 (XtCallbackProc
)msgboxCallBackClose
, (XtPointer
)this);
239 // show it as a modal dialog
240 XtManageChild(wMsgBox
);
241 XtAddGrab(wMsgBox
, True
, False
);
243 // the m_result will be changed when message box goes away
246 // local message loop
247 XtAppContext context
= XtWidgetToApplicationContext(wParent
);
249 while ( m_result
== -1 )
251 XtAppNextEvent(context
, &event
);
252 XtDispatchEvent(&event
);
255 // translate the result if necessary
256 if ( style
& wxYES_NO
)
258 if ( m_result
== wxID_OK
)
260 else if ( m_result
== wxID_CANCEL
)
262 else if ( m_result
== wxID_HELP
)
263 m_result
= wxID_CANCEL
;