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 msgboxCallBackClose(Widget w
,
76 XmAnyCallbackStruct
*call_data
)
78 msgboxCallBack(w
, client_data
, wxID_CANCEL
);
81 // ----------------------------------------------------------------------------
83 // ----------------------------------------------------------------------------
85 wxMessageDialog::wxMessageDialog(wxWindow
*parent
,
86 const wxString
& message
,
87 const wxString
& caption
,
93 m_dialogStyle
= style
;
97 int wxMessageDialog::ShowModal()
99 Widget (*dialogCreateFunction
)(Widget
, String
, ArgList
, Cardinal
) = NULL
;
100 if ( m_dialogStyle
& wxYES_NO
)
102 // if we have [Yes], it must be a question
103 dialogCreateFunction
= XmCreateQuestionDialog
;
105 // TODO we could support this by using the help button...
106 wxASSERT_MSG( !(m_dialogStyle
& wxCANCEL
), "not supported" );
108 else if ( m_dialogStyle
& wxICON_STOP
)
110 // error dialog is the one with error icon...
111 dialogCreateFunction
= XmCreateErrorDialog
;
113 else if ( m_dialogStyle
& wxICON_EXCLAMATION
)
115 // ...and the warning dialog too
116 dialogCreateFunction
= XmCreateWarningDialog
;
120 // finally, use the info dialog by default
121 dialogCreateFunction
= XmCreateInformationDialog
;
124 // prepare the arg list
128 wxXmString
text(m_message
);
129 wxXmString
title(m_caption
);
130 XtSetArg(args
[ac
], XmNmessageString
, text()); ac
++;
131 XtSetArg(args
[ac
], XmNdialogTitle
, title()); ac
++;
133 // do create message box
134 Widget wParent
= m_parent
? GetWidget(m_parent
) : NULL
;
137 wxWindow
*window
= wxTheApp
->GetTopWindow();
140 wxFAIL_MSG("can't show message box without parent window");
145 wParent
= GetWidget(window
);
148 Widget wMsgBox
= (*dialogCreateFunction
)(wParent
, "", args
, ac
);
150 wxCHECK_MSG( wMsgBox
, wxID_CANCEL
, "msg box creation failed" );
152 // remove the [Help] button which wouldn't do anything anyhow
153 XtUnmanageChild(XmMessageBoxGetChild(wMsgBox
, XmDIALOG_HELP_BUTTON
));
155 // and the [Cancel] button too if we were not asked for it
156 if ( !(m_dialogStyle
& wxCANCEL
) )
158 Widget wBtnCancel
= XmMessageBoxGetChild(wMsgBox
,
159 XmDIALOG_CANCEL_BUTTON
);
161 // ... unless it's a wxYES_NO dialog in which case we just rename
162 // [Cancel] to [No] instead
163 if ( m_dialogStyle
& wxYES_NO
)
165 Widget wBtnOk
= XmMessageBoxGetChild(wMsgBox
,
168 wxXmString
yes(_("Yes")), no(_("No"));
169 XtVaSetValues(wBtnOk
, XmNlabelString
, yes(), NULL
);
170 XtVaSetValues(wBtnCancel
, XmNlabelString
, no(), NULL
);
174 XtUnmanageChild(wBtnCancel
);
178 // set the callbacks for the message box buttons
179 XtAddCallback(wMsgBox
, XmNokCallback
,
180 (XtCallbackProc
)msgboxCallBackOk
, (XtPointer
)this);
181 XtAddCallback(wMsgBox
, XmNcancelCallback
,
182 (XtCallbackProc
)msgboxCallBackCancel
, (XtPointer
)this);
184 XtAddCallback(wMsgBox
, XmNunmapCallback
,
185 (XtCallbackProc
)msgboxCallBackClose
, (XtPointer
)this);
187 // show it as a modal dialog
188 XtManageChild(wMsgBox
);
189 XtAddGrab(wMsgBox
, True
, False
);
191 // the m_result will be changed when message box goes away
194 // local message loop
195 XtAppContext context
= XtWidgetToApplicationContext(wParent
);
197 while ( m_result
== -1 )
199 XtAppNextEvent(context
, &event
);
200 XtDispatchEvent(&event
);
203 // translate the result if necessary
204 if ( m_dialogStyle
& wxYES_NO
)
206 if ( m_result
== wxID_OK
)
208 else if ( m_result
== wxID_CANCEL
)