1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/motif/msgdlg.cpp
3 // Purpose: wxMessageDialog
4 // Author: Julian Smart
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
23 #pragma message disable nosimpint
24 #include "wx/vms_x_fix.h"
29 #include <Xm/MessageB.h>
31 #pragma message enable nosimpint
34 #include "wx/msgdlg.h"
39 #include "wx/settings.h"
42 #include "wx/modalhook.h"
43 #include "wx/motif/private.h"
45 // ----------------------------------------------------------------------------
47 // ----------------------------------------------------------------------------
49 IMPLEMENT_CLASS(wxMessageDialog
, wxDialog
)
51 // ============================================================================
53 // ============================================================================
55 // ----------------------------------------------------------------------------
56 // the callbacks for message box buttons
57 // ----------------------------------------------------------------------------
60 static void msgboxCallBack(Widget w
, void* client_data
, int id
)
65 wxMessageDialog
*dlg
= (wxMessageDialog
*)client_data
;
69 static void msgboxCallBackOk(Widget w
,
71 XmAnyCallbackStruct
*WXUNUSED(call_data
))
73 msgboxCallBack(w
, client_data
, wxID_OK
);
76 static void msgboxCallBackCancel(Widget w
,
78 XmAnyCallbackStruct
*WXUNUSED(call_data
))
80 msgboxCallBack(w
, client_data
, wxID_CANCEL
);
83 static void msgboxCallBackHelp(Widget w
,
85 XmAnyCallbackStruct
*WXUNUSED(call_data
))
87 msgboxCallBack(w
, client_data
, wxID_HELP
);
90 static void msgboxCallBackClose(Widget w
,
92 XmAnyCallbackStruct
*WXUNUSED(call_data
))
94 msgboxCallBack(w
, client_data
, wxID_CANCEL
);
97 // ----------------------------------------------------------------------------
99 // ----------------------------------------------------------------------------
103 typedef Widget (*DialogCreateFunction
)(Widget
, String
, ArgList
, Cardinal
);
106 int wxMessageDialog::ShowModal()
108 WX_HOOK_MODAL_DIALOG();
110 const long style
= GetMessageDialogStyle();
112 DialogCreateFunction dialogCreateFunction
;
113 if ( style
& wxYES_NO
)
115 // if we have [Yes], it must be a question
116 dialogCreateFunction
= XmCreateQuestionDialog
;
118 else if ( style
& wxICON_STOP
)
120 // error dialog is the one with error icon...
121 dialogCreateFunction
= XmCreateErrorDialog
;
123 else if ( style
& wxICON_EXCLAMATION
)
125 // ...and the warning dialog too
126 dialogCreateFunction
= XmCreateWarningDialog
;
130 // finally, use the info dialog by default
131 dialogCreateFunction
= XmCreateInformationDialog
;
134 Widget wParent
= m_parent
? GetWidget(m_parent
) : (Widget
) 0;
137 wxWindow
*window
= wxTheApp
->GetTopWindow();
140 wxFAIL_MSG("can't show message box without parent window");
145 wParent
= GetWidget(window
);
148 // prepare the arg list
152 wxXmString
text(GetFullMessage());
153 wxXmString
title(m_caption
);
154 XtSetArg(args
[ac
], XmNmessageString
, text()); ac
++;
155 XtSetArg(args
[ac
], XmNdialogTitle
, title()); ac
++;
157 Display
* dpy
= XtDisplay(wParent
);
159 if (m_backgroundColour
.IsOk())
161 wxComputeColours (dpy
, & m_backgroundColour
, NULL
);
163 XtSetArg(args
[ac
], XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
); ac
++;
164 XtSetArg(args
[ac
], XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
); ac
++;
165 XtSetArg(args
[ac
], XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
); ac
++;
166 XtSetArg(args
[ac
], XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
); ac
++;
169 wxFont font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
171 #if __WXMOTIF20__ && !__WXLESSTIF__
172 XtSetArg(args
[ac
], XmNbuttonRenderTable
, font
.GetFontTypeC(dpy
)); ac
++;
173 XtSetArg(args
[ac
], XmNlabelRenderTable
, font
.GetFontTypeC(dpy
)); ac
++;
174 XtSetArg(args
[ac
], XmNtextRenderTable
, font
.GetFontTypeC(dpy
)); ac
++;
176 XtSetArg(args
[ac
], XmNbuttonFontList
, font
.GetFontTypeC(dpy
)); ac
++;
177 XtSetArg(args
[ac
], XmNlabelFontList
, font
.GetFontTypeC(dpy
)); ac
++;
178 XtSetArg(args
[ac
], XmNtextFontList
, font
.GetFontTypeC(dpy
)); ac
++;
181 // do create message box
183 Widget wMsgBox
= (*dialogCreateFunction
)(wParent
, wxMOTIF_STR(""), args
, ac
);
185 wxCHECK_MSG( wMsgBox
, wxID_CANCEL
, "msg box creation failed" );
187 // get the buttons which we might either remove or rename
188 // depending on the requested style
190 Widget wBtnOk
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_OK_BUTTON
);
191 Widget wBtnHelp
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_HELP_BUTTON
);
192 Widget wBtnCancel
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_CANCEL_BUTTON
);
194 if ( style
& wxYES_NO
)
196 wxXmString
yes(_("Yes")), no(_("No")), cancel(_("Cancel"));
198 if ( style
& wxCANCEL
)
200 // use the cancel button for No and the help button for
203 XtVaSetValues(wBtnOk
, XmNlabelString
, yes(), NULL
);
204 XtVaSetValues(wBtnCancel
, XmNlabelString
, no(), NULL
);
205 XtVaSetValues(wBtnHelp
, XmNlabelString
, cancel(), NULL
);
209 // no cancel button requested...
210 // remove the help button and use cancel for no
212 XtVaSetValues(wBtnCancel
, XmNlabelString
, no(), NULL
);
213 XtUnmanageChild(wBtnHelp
);
218 // remove the help button and the cancel button (unless it was
221 XtUnmanageChild(wBtnHelp
);
222 if ( !(style
& wxCANCEL
) ) XtUnmanageChild(wBtnCancel
);
225 // set the callbacks for the message box buttons
226 XtAddCallback(wMsgBox
, XmNokCallback
,
227 (XtCallbackProc
)msgboxCallBackOk
, (XtPointer
)this);
228 XtAddCallback(wMsgBox
, XmNcancelCallback
,
229 (XtCallbackProc
)msgboxCallBackCancel
, (XtPointer
)this);
230 XtAddCallback(wMsgBox
, XmNhelpCallback
,
231 (XtCallbackProc
)msgboxCallBackHelp
, (XtPointer
)this);
232 XtAddCallback(wMsgBox
, XmNunmapCallback
,
233 (XtCallbackProc
)msgboxCallBackClose
, (XtPointer
)this);
235 // show it as a modal dialog
236 XtManageChild(wMsgBox
);
237 XtAddGrab(wMsgBox
, True
, False
);
239 // the m_result will be changed when message box goes away
242 // local message loop
243 XtAppContext context
= XtWidgetToApplicationContext(wParent
);
245 while ( m_result
== -1 )
247 XtAppNextEvent(context
, &event
);
248 XtDispatchEvent(&event
);
251 // translate the result if necessary
252 if ( style
& wxYES_NO
)
254 if ( m_result
== wxID_OK
)
256 else if ( m_result
== wxID_CANCEL
)
258 else if ( m_result
== wxID_HELP
)
259 m_result
= wxID_CANCEL
;