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 #pragma message disable nosimpint
25 #include "wx/vms_x_fix.h"
30 #include <Xm/MessageB.h>
32 #pragma message enable nosimpint
35 #include "wx/msgdlg.h"
40 #include "wx/settings.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 const long style
= GetMessageDialogStyle();
110 DialogCreateFunction dialogCreateFunction
;
111 if ( style
& wxYES_NO
)
113 // if we have [Yes], it must be a question
114 dialogCreateFunction
= XmCreateQuestionDialog
;
116 else if ( style
& wxICON_STOP
)
118 // error dialog is the one with error icon...
119 dialogCreateFunction
= XmCreateErrorDialog
;
121 else if ( style
& wxICON_EXCLAMATION
)
123 // ...and the warning dialog too
124 dialogCreateFunction
= XmCreateWarningDialog
;
128 // finally, use the info dialog by default
129 dialogCreateFunction
= XmCreateInformationDialog
;
132 Widget wParent
= m_parent
? GetWidget(m_parent
) : (Widget
) 0;
135 wxWindow
*window
= wxTheApp
->GetTopWindow();
138 wxFAIL_MSG("can't show message box without parent window");
143 wParent
= GetWidget(window
);
146 // prepare the arg list
150 wxXmString
text(GetFullMessage());
151 wxXmString
title(m_caption
);
152 XtSetArg(args
[ac
], XmNmessageString
, text()); ac
++;
153 XtSetArg(args
[ac
], XmNdialogTitle
, title()); ac
++;
155 Display
* dpy
= XtDisplay(wParent
);
157 if (m_backgroundColour
.Ok())
159 wxComputeColours (dpy
, & m_backgroundColour
, NULL
);
161 XtSetArg(args
[ac
], XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
); ac
++;
162 XtSetArg(args
[ac
], XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
); ac
++;
163 XtSetArg(args
[ac
], XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
); ac
++;
164 XtSetArg(args
[ac
], XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
); ac
++;
167 wxFont font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
169 #if __WXMOTIF20__ && !__WXLESSTIF__
170 XtSetArg(args
[ac
], XmNbuttonRenderTable
, font
.GetFontTypeC(dpy
)); ac
++;
171 XtSetArg(args
[ac
], XmNlabelRenderTable
, font
.GetFontTypeC(dpy
)); ac
++;
172 XtSetArg(args
[ac
], XmNtextRenderTable
, font
.GetFontTypeC(dpy
)); ac
++;
174 XtSetArg(args
[ac
], XmNbuttonFontList
, font
.GetFontTypeC(dpy
)); ac
++;
175 XtSetArg(args
[ac
], XmNlabelFontList
, font
.GetFontTypeC(dpy
)); ac
++;
176 XtSetArg(args
[ac
], XmNtextFontList
, font
.GetFontTypeC(dpy
)); ac
++;
179 // do create message box
181 Widget wMsgBox
= (*dialogCreateFunction
)(wParent
, wxMOTIF_STR(""), args
, ac
);
183 wxCHECK_MSG( wMsgBox
, wxID_CANCEL
, "msg box creation failed" );
185 // get the buttons which we might either remove or rename
186 // depending on the requested style
188 Widget wBtnOk
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_OK_BUTTON
);
189 Widget wBtnHelp
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_HELP_BUTTON
);
190 Widget wBtnCancel
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_CANCEL_BUTTON
);
192 if ( style
& wxYES_NO
)
194 wxXmString
yes(_("Yes")), no(_("No")), cancel(_("Cancel"));
196 if ( style
& wxCANCEL
)
198 // use the cancel button for No and the help button for
201 XtVaSetValues(wBtnOk
, XmNlabelString
, yes(), NULL
);
202 XtVaSetValues(wBtnCancel
, XmNlabelString
, no(), NULL
);
203 XtVaSetValues(wBtnHelp
, XmNlabelString
, cancel(), NULL
);
207 // no cancel button requested...
208 // remove the help button and use cancel for no
210 XtVaSetValues(wBtnCancel
, XmNlabelString
, no(), NULL
);
211 XtUnmanageChild(wBtnHelp
);
216 // remove the help button and the cancel button (unless it was
219 XtUnmanageChild(wBtnHelp
);
220 if ( !(style
& wxCANCEL
) ) XtUnmanageChild(wBtnCancel
);
223 // set the callbacks for the message box buttons
224 XtAddCallback(wMsgBox
, XmNokCallback
,
225 (XtCallbackProc
)msgboxCallBackOk
, (XtPointer
)this);
226 XtAddCallback(wMsgBox
, XmNcancelCallback
,
227 (XtCallbackProc
)msgboxCallBackCancel
, (XtPointer
)this);
228 XtAddCallback(wMsgBox
, XmNhelpCallback
,
229 (XtCallbackProc
)msgboxCallBackHelp
, (XtPointer
)this);
230 XtAddCallback(wMsgBox
, XmNunmapCallback
,
231 (XtCallbackProc
)msgboxCallBackClose
, (XtPointer
)this);
233 // show it as a modal dialog
234 XtManageChild(wMsgBox
);
235 XtAddGrab(wMsgBox
, True
, False
);
237 // the m_result will be changed when message box goes away
240 // local message loop
241 XtAppContext context
= XtWidgetToApplicationContext(wParent
);
243 while ( m_result
== -1 )
245 XtAppNextEvent(context
, &event
);
246 XtDispatchEvent(&event
);
249 // translate the result if necessary
250 if ( style
& wxYES_NO
)
252 if ( m_result
== wxID_OK
)
254 else if ( m_result
== wxID_CANCEL
)
256 else if ( m_result
== wxID_HELP
)
257 m_result
= wxID_CANCEL
;