1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMessageDialog
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
17 #pragma implementation "msgdlg.h"
20 // ----------------------------------------------------------------------------
22 // ----------------------------------------------------------------------------
27 #include <Xm/MessageB.h>
31 #include "wx/motif/msgdlg.h"
32 #include "wx/motif/private.h"
34 // ----------------------------------------------------------------------------
36 // ----------------------------------------------------------------------------
38 #if !USE_SHARED_LIBRARY
39 IMPLEMENT_CLASS(wxMessageDialog
, wxDialog
)
42 // ============================================================================
44 // ============================================================================
46 // ----------------------------------------------------------------------------
47 // the callbacks for message box buttons
48 // ----------------------------------------------------------------------------
51 static void msgboxCallBack(Widget w
, int client_data
, int id
)
56 wxMessageDialog
*dlg
= (wxMessageDialog
*)client_data
;
60 static void msgboxCallBackOk(Widget w
,
62 XmAnyCallbackStruct
*call_data
)
64 msgboxCallBack(w
, client_data
, wxID_OK
);
67 static void msgboxCallBackCancel(Widget w
,
69 XmAnyCallbackStruct
*call_data
)
71 msgboxCallBack(w
, client_data
, wxID_CANCEL
);
74 static void msgboxCallBackHelp(Widget w
,
76 XmAnyCallbackStruct
*call_data
)
78 msgboxCallBack(w
, client_data
, wxID_HELP
);
81 static void msgboxCallBackClose(Widget w
,
83 XmAnyCallbackStruct
*call_data
)
85 msgboxCallBack(w
, client_data
, wxID_CANCEL
);
88 // ----------------------------------------------------------------------------
90 // ----------------------------------------------------------------------------
92 wxMessageDialog::wxMessageDialog(wxWindow
*parent
,
93 const wxString
& message
,
94 const wxString
& caption
,
100 m_dialogStyle
= style
;
104 int wxMessageDialog::ShowModal()
106 Widget (*dialogCreateFunction
)(Widget
, String
, ArgList
, Cardinal
) = NULL
;
107 if ( m_dialogStyle
& wxYES_NO
)
109 // if we have [Yes], it must be a question
110 dialogCreateFunction
= XmCreateQuestionDialog
;
112 else if ( m_dialogStyle
& wxICON_STOP
)
114 // error dialog is the one with error icon...
115 dialogCreateFunction
= XmCreateErrorDialog
;
117 else if ( m_dialogStyle
& wxICON_EXCLAMATION
)
119 // ...and the warning dialog too
120 dialogCreateFunction
= XmCreateWarningDialog
;
124 // finally, use the info dialog by default
125 dialogCreateFunction
= XmCreateInformationDialog
;
128 // prepare the arg list
132 wxXmString
text(m_message
);
133 wxXmString
title(m_caption
);
134 XtSetArg(args
[ac
], XmNmessageString
, text()); ac
++;
135 XtSetArg(args
[ac
], XmNdialogTitle
, title()); ac
++;
137 // do create message box
138 Widget wParent
= m_parent
? GetWidget(m_parent
) : NULL
;
141 wxWindow
*window
= wxTheApp
->GetTopWindow();
144 wxFAIL_MSG("can't show message box without parent window");
149 wParent
= GetWidget(window
);
152 Widget wMsgBox
= (*dialogCreateFunction
)(wParent
, "", args
, ac
);
154 wxCHECK_MSG( wMsgBox
, wxID_CANCEL
, "msg box creation failed" );
156 // get the buttons which we might either remove or rename
157 // depending on the requested style
159 Widget wBtnOk
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_OK_BUTTON
);
160 Widget wBtnHelp
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_HELP_BUTTON
);
161 Widget wBtnCancel
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_CANCEL_BUTTON
);
163 if ( m_dialogStyle
& wxYES_NO
)
165 wxXmString
yes(_("Yes")), no(_("No")), cancel(_("Cancel"));
167 if ( m_dialogStyle
& wxCANCEL
)
169 // use the cancel button for No and the help button for
172 XtVaSetValues(wBtnOk
, XmNlabelString
, yes(), NULL
);
173 XtVaSetValues(wBtnCancel
, XmNlabelString
, no(), NULL
);
174 XtVaSetValues(wBtnHelp
, XmNlabelString
, cancel(), NULL
);
178 // no cancel button requested...
179 // remove the help button and use cancel for no
181 XtVaSetValues(wBtnCancel
, XmNlabelString
, no(), NULL
);
182 XtUnmanageChild(wBtnHelp
);
187 // remove the help button and the cancel button (unless it was
190 XtUnmanageChild(wBtnHelp
);
191 if ( !(m_dialogStyle
& wxCANCEL
) ) XtUnmanageChild(wBtnCancel
);
194 // set the callbacks for the message box buttons
195 XtAddCallback(wMsgBox
, XmNokCallback
,
196 (XtCallbackProc
)msgboxCallBackOk
, (XtPointer
)this);
197 XtAddCallback(wMsgBox
, XmNcancelCallback
,
198 (XtCallbackProc
)msgboxCallBackCancel
, (XtPointer
)this);
199 XtAddCallback(wMsgBox
, XmNhelpCallback
,
200 (XtCallbackProc
)msgboxCallBackHelp
, (XtPointer
)this);
201 XtAddCallback(wMsgBox
, XmNunmapCallback
,
202 (XtCallbackProc
)msgboxCallBackClose
, (XtPointer
)this);
204 // show it as a modal dialog
205 XtManageChild(wMsgBox
);
206 XtAddGrab(wMsgBox
, True
, False
);
208 // the m_result will be changed when message box goes away
211 // local message loop
212 XtAppContext context
= XtWidgetToApplicationContext(wParent
);
214 while ( m_result
== -1 )
216 XtAppNextEvent(context
, &event
);
217 XtDispatchEvent(&event
);
220 // translate the result if necessary
221 if ( m_dialogStyle
& wxYES_NO
)
223 if ( m_result
== wxID_OK
)
225 else if ( m_result
== wxID_CANCEL
)
227 else if ( m_result
== wxID_HELP
)
228 m_result
= wxID_CANCEL
;