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 // ----------------------------------------------------------------------------
25 #pragma message disable nosimpint
30 #include <Xm/MessageB.h>
32 #pragma message enable nosimpint
37 #include "wx/motif/msgdlg.h"
38 #include "wx/motif/private.h"
40 // ----------------------------------------------------------------------------
42 // ----------------------------------------------------------------------------
44 IMPLEMENT_CLASS(wxMessageDialog
, wxDialog
)
46 // ============================================================================
48 // ============================================================================
50 // ----------------------------------------------------------------------------
51 // the callbacks for message box buttons
52 // ----------------------------------------------------------------------------
55 static void msgboxCallBack(Widget w
, void* client_data
, int id
)
60 wxMessageDialog
*dlg
= (wxMessageDialog
*)client_data
;
64 static void msgboxCallBackOk(Widget w
,
66 XmAnyCallbackStruct
*WXUNUSED(call_data
))
68 msgboxCallBack(w
, client_data
, wxID_OK
);
71 static void msgboxCallBackCancel(Widget w
,
73 XmAnyCallbackStruct
*WXUNUSED(call_data
))
75 msgboxCallBack(w
, client_data
, wxID_CANCEL
);
78 static void msgboxCallBackHelp(Widget w
,
80 XmAnyCallbackStruct
*WXUNUSED(call_data
))
82 msgboxCallBack(w
, client_data
, wxID_HELP
);
85 static void msgboxCallBackClose(Widget w
,
87 XmAnyCallbackStruct
*WXUNUSED(call_data
))
89 msgboxCallBack(w
, client_data
, wxID_CANCEL
);
92 // ----------------------------------------------------------------------------
94 // ----------------------------------------------------------------------------
96 wxMessageDialog::wxMessageDialog(wxWindow
*parent
,
97 const wxString
& message
,
98 const wxString
& caption
,
100 const wxPoint
& WXUNUSED(pos
))
104 m_dialogStyle
= style
;
108 int wxMessageDialog::ShowModal()
110 Widget (*dialogCreateFunction
)(Widget
, String
, ArgList
, Cardinal
) = NULL
;
111 if ( m_dialogStyle
& wxYES_NO
)
113 // if we have [Yes], it must be a question
114 dialogCreateFunction
= XmCreateQuestionDialog
;
116 else if ( m_dialogStyle
& wxICON_STOP
)
118 // error dialog is the one with error icon...
119 dialogCreateFunction
= XmCreateErrorDialog
;
121 else if ( m_dialogStyle
& 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(m_message
);
151 wxXmString
title(m_caption
);
152 XtSetArg(args
[ac
], XmNmessageString
, text()); ac
++;
153 XtSetArg(args
[ac
], XmNdialogTitle
, title()); ac
++;
155 wxComputeColours (XtDisplay(wParent
), & m_backgroundColour
,
158 XtSetArg(args
[ac
], XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
); ac
++;
159 XtSetArg(args
[ac
], XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
); ac
++;
160 XtSetArg(args
[ac
], XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
); ac
++;
161 XtSetArg(args
[ac
], XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
); ac
++;
163 // do create message box
165 Widget wMsgBox
= (*dialogCreateFunction
)(wParent
, "", args
, ac
);
167 wxCHECK_MSG( wMsgBox
, wxID_CANCEL
, "msg box creation failed" );
169 // get the buttons which we might either remove or rename
170 // depending on the requested style
172 Widget wBtnOk
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_OK_BUTTON
);
173 Widget wBtnHelp
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_HELP_BUTTON
);
174 Widget wBtnCancel
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_CANCEL_BUTTON
);
176 if ( m_dialogStyle
& wxYES_NO
)
178 wxXmString
yes(_("Yes")), no(_("No")), cancel(_("Cancel"));
180 if ( m_dialogStyle
& wxCANCEL
)
182 // use the cancel button for No and the help button for
185 XtVaSetValues(wBtnOk
, XmNlabelString
, yes(), NULL
);
186 XtVaSetValues(wBtnCancel
, XmNlabelString
, no(), NULL
);
187 XtVaSetValues(wBtnHelp
, XmNlabelString
, cancel(), NULL
);
191 // no cancel button requested...
192 // remove the help button and use cancel for no
194 XtVaSetValues(wBtnCancel
, XmNlabelString
, no(), NULL
);
195 XtUnmanageChild(wBtnHelp
);
200 // remove the help button and the cancel button (unless it was
203 XtUnmanageChild(wBtnHelp
);
204 if ( !(m_dialogStyle
& wxCANCEL
) ) XtUnmanageChild(wBtnCancel
);
207 // set the callbacks for the message box buttons
208 XtAddCallback(wMsgBox
, XmNokCallback
,
209 (XtCallbackProc
)msgboxCallBackOk
, (XtPointer
)this);
210 XtAddCallback(wMsgBox
, XmNcancelCallback
,
211 (XtCallbackProc
)msgboxCallBackCancel
, (XtPointer
)this);
212 XtAddCallback(wMsgBox
, XmNhelpCallback
,
213 (XtCallbackProc
)msgboxCallBackHelp
, (XtPointer
)this);
214 XtAddCallback(wMsgBox
, XmNunmapCallback
,
215 (XtCallbackProc
)msgboxCallBackClose
, (XtPointer
)this);
217 // show it as a modal dialog
218 XtManageChild(wMsgBox
);
219 XtAddGrab(wMsgBox
, True
, False
);
221 // the m_result will be changed when message box goes away
224 // local message loop
225 XtAppContext context
= XtWidgetToApplicationContext(wParent
);
227 while ( m_result
== -1 )
229 XtAppNextEvent(context
, &event
);
230 XtDispatchEvent(&event
);
233 // translate the result if necessary
234 if ( m_dialogStyle
& wxYES_NO
)
236 if ( m_result
== wxID_OK
)
238 else if ( m_result
== wxID_CANCEL
)
240 else if ( m_result
== wxID_HELP
)
241 m_result
= wxID_CANCEL
;