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
*WXUNUSED(call_data
))
64 msgboxCallBack(w
, client_data
, wxID_OK
);
67 static void msgboxCallBackCancel(Widget w
,
69 XmAnyCallbackStruct
*WXUNUSED(call_data
))
71 msgboxCallBack(w
, client_data
, wxID_CANCEL
);
74 static void msgboxCallBackHelp(Widget w
,
76 XmAnyCallbackStruct
*WXUNUSED(call_data
))
78 msgboxCallBack(w
, client_data
, wxID_HELP
);
81 static void msgboxCallBackClose(Widget w
,
83 XmAnyCallbackStruct
*WXUNUSED(call_data
))
85 msgboxCallBack(w
, client_data
, wxID_CANCEL
);
88 // ----------------------------------------------------------------------------
90 // ----------------------------------------------------------------------------
92 wxMessageDialog::wxMessageDialog(wxWindow
*parent
,
93 const wxString
& message
,
94 const wxString
& caption
,
96 const wxPoint
& WXUNUSED(pos
))
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 Widget wParent
= m_parent
? GetWidget(m_parent
) : (Widget
) 0;
131 wxWindow
*window
= wxTheApp
->GetTopWindow();
134 wxFAIL_MSG("can't show message box without parent window");
139 wParent
= GetWidget(window
);
142 // prepare the arg list
146 wxXmString
text(m_message
);
147 wxXmString
title(m_caption
);
148 XtSetArg(args
[ac
], XmNmessageString
, text()); ac
++;
149 XtSetArg(args
[ac
], XmNdialogTitle
, title()); ac
++;
151 wxComputeColours (XtDisplay(wParent
), & m_backgroundColour
,
154 XtSetArg(args
[ac
], XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
); ac
++;
155 XtSetArg(args
[ac
], XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
); ac
++;
156 XtSetArg(args
[ac
], XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
); ac
++;
157 XtSetArg(args
[ac
], XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
); ac
++;
159 // do create message box
161 Widget wMsgBox
= (*dialogCreateFunction
)(wParent
, "", args
, ac
);
163 wxCHECK_MSG( wMsgBox
, wxID_CANCEL
, "msg box creation failed" );
165 // get the buttons which we might either remove or rename
166 // depending on the requested style
168 Widget wBtnOk
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_OK_BUTTON
);
169 Widget wBtnHelp
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_HELP_BUTTON
);
170 Widget wBtnCancel
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_CANCEL_BUTTON
);
172 if ( m_dialogStyle
& wxYES_NO
)
174 wxXmString
yes(_("Yes")), no(_("No")), cancel(_("Cancel"));
176 if ( m_dialogStyle
& wxCANCEL
)
178 // use the cancel button for No and the help button for
181 XtVaSetValues(wBtnOk
, XmNlabelString
, yes(), NULL
);
182 XtVaSetValues(wBtnCancel
, XmNlabelString
, no(), NULL
);
183 XtVaSetValues(wBtnHelp
, XmNlabelString
, cancel(), NULL
);
187 // no cancel button requested...
188 // remove the help button and use cancel for no
190 XtVaSetValues(wBtnCancel
, XmNlabelString
, no(), NULL
);
191 XtUnmanageChild(wBtnHelp
);
196 // remove the help button and the cancel button (unless it was
199 XtUnmanageChild(wBtnHelp
);
200 if ( !(m_dialogStyle
& wxCANCEL
) ) XtUnmanageChild(wBtnCancel
);
203 // set the callbacks for the message box buttons
204 XtAddCallback(wMsgBox
, XmNokCallback
,
205 (XtCallbackProc
)msgboxCallBackOk
, (XtPointer
)this);
206 XtAddCallback(wMsgBox
, XmNcancelCallback
,
207 (XtCallbackProc
)msgboxCallBackCancel
, (XtPointer
)this);
208 XtAddCallback(wMsgBox
, XmNhelpCallback
,
209 (XtCallbackProc
)msgboxCallBackHelp
, (XtPointer
)this);
210 XtAddCallback(wMsgBox
, XmNunmapCallback
,
211 (XtCallbackProc
)msgboxCallBackClose
, (XtPointer
)this);
213 // show it as a modal dialog
214 XtManageChild(wMsgBox
);
215 XtAddGrab(wMsgBox
, True
, False
);
217 // the m_result will be changed when message box goes away
220 // local message loop
221 XtAppContext context
= XtWidgetToApplicationContext(wParent
);
223 while ( m_result
== -1 )
225 XtAppNextEvent(context
, &event
);
226 XtDispatchEvent(&event
);
229 // translate the result if necessary
230 if ( m_dialogStyle
& wxYES_NO
)
232 if ( m_result
== wxID_OK
)
234 else if ( m_result
== wxID_CANCEL
)
236 else if ( m_result
== wxID_HELP
)
237 m_result
= wxID_CANCEL
;