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 #define XtDisplay XTDISPLAY
28 #pragma message disable nosimpint
29 #include <wx/vms_x_fix.h>
34 #include <Xm/MessageB.h>
36 #pragma message enable nosimpint
41 #include "wx/motif/msgdlg.h"
42 #include "wx/motif/private.h"
44 // ----------------------------------------------------------------------------
46 // ----------------------------------------------------------------------------
48 IMPLEMENT_CLASS(wxMessageDialog
, wxDialog
)
50 // ============================================================================
52 // ============================================================================
54 // ----------------------------------------------------------------------------
55 // the callbacks for message box buttons
56 // ----------------------------------------------------------------------------
59 static void msgboxCallBack(Widget w
, void* client_data
, int id
)
64 wxMessageDialog
*dlg
= (wxMessageDialog
*)client_data
;
68 static void msgboxCallBackOk(Widget w
,
70 XmAnyCallbackStruct
*WXUNUSED(call_data
))
72 msgboxCallBack(w
, client_data
, wxID_OK
);
75 static void msgboxCallBackCancel(Widget w
,
77 XmAnyCallbackStruct
*WXUNUSED(call_data
))
79 msgboxCallBack(w
, client_data
, wxID_CANCEL
);
82 static void msgboxCallBackHelp(Widget w
,
84 XmAnyCallbackStruct
*WXUNUSED(call_data
))
86 msgboxCallBack(w
, client_data
, wxID_HELP
);
89 static void msgboxCallBackClose(Widget w
,
91 XmAnyCallbackStruct
*WXUNUSED(call_data
))
93 msgboxCallBack(w
, client_data
, wxID_CANCEL
);
96 // ----------------------------------------------------------------------------
98 // ----------------------------------------------------------------------------
100 wxMessageDialog::wxMessageDialog(wxWindow
*parent
,
101 const wxString
& message
,
102 const wxString
& caption
,
104 const wxPoint
& WXUNUSED(pos
))
108 m_dialogStyle
= style
;
112 int wxMessageDialog::ShowModal()
114 Widget (*dialogCreateFunction
)(Widget
, String
, ArgList
, Cardinal
) = NULL
;
115 if ( m_dialogStyle
& wxYES_NO
)
117 // if we have [Yes], it must be a question
118 dialogCreateFunction
= XmCreateQuestionDialog
;
120 else if ( m_dialogStyle
& wxICON_STOP
)
122 // error dialog is the one with error icon...
123 dialogCreateFunction
= XmCreateErrorDialog
;
125 else if ( m_dialogStyle
& wxICON_EXCLAMATION
)
127 // ...and the warning dialog too
128 dialogCreateFunction
= XmCreateWarningDialog
;
132 // finally, use the info dialog by default
133 dialogCreateFunction
= XmCreateInformationDialog
;
136 Widget wParent
= m_parent
? GetWidget(m_parent
) : (Widget
) 0;
139 wxWindow
*window
= wxTheApp
->GetTopWindow();
142 wxFAIL_MSG("can't show message box without parent window");
147 wParent
= GetWidget(window
);
150 // prepare the arg list
154 wxXmString
text(m_message
);
155 wxXmString
title(m_caption
);
156 XtSetArg(args
[ac
], XmNmessageString
, text()); ac
++;
157 XtSetArg(args
[ac
], XmNdialogTitle
, title()); ac
++;
159 wxComputeColours (XtDisplay(wParent
), & m_backgroundColour
,
162 XtSetArg(args
[ac
], XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
); ac
++;
163 XtSetArg(args
[ac
], XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
); ac
++;
164 XtSetArg(args
[ac
], XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
); ac
++;
165 XtSetArg(args
[ac
], XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
); ac
++;
167 // do create message box
169 Widget wMsgBox
= (*dialogCreateFunction
)(wParent
, "", args
, ac
);
171 wxCHECK_MSG( wMsgBox
, wxID_CANCEL
, "msg box creation failed" );
173 // get the buttons which we might either remove or rename
174 // depending on the requested style
176 Widget wBtnOk
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_OK_BUTTON
);
177 Widget wBtnHelp
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_HELP_BUTTON
);
178 Widget wBtnCancel
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_CANCEL_BUTTON
);
180 if ( m_dialogStyle
& wxYES_NO
)
182 wxXmString
yes(_("Yes")), no(_("No")), cancel(_("Cancel"));
184 if ( m_dialogStyle
& wxCANCEL
)
186 // use the cancel button for No and the help button for
189 XtVaSetValues(wBtnOk
, XmNlabelString
, yes(), NULL
);
190 XtVaSetValues(wBtnCancel
, XmNlabelString
, no(), NULL
);
191 XtVaSetValues(wBtnHelp
, XmNlabelString
, cancel(), NULL
);
195 // no cancel button requested...
196 // remove the help button and use cancel for no
198 XtVaSetValues(wBtnCancel
, XmNlabelString
, no(), NULL
);
199 XtUnmanageChild(wBtnHelp
);
204 // remove the help button and the cancel button (unless it was
207 XtUnmanageChild(wBtnHelp
);
208 if ( !(m_dialogStyle
& wxCANCEL
) ) XtUnmanageChild(wBtnCancel
);
211 // set the callbacks for the message box buttons
212 XtAddCallback(wMsgBox
, XmNokCallback
,
213 (XtCallbackProc
)msgboxCallBackOk
, (XtPointer
)this);
214 XtAddCallback(wMsgBox
, XmNcancelCallback
,
215 (XtCallbackProc
)msgboxCallBackCancel
, (XtPointer
)this);
216 XtAddCallback(wMsgBox
, XmNhelpCallback
,
217 (XtCallbackProc
)msgboxCallBackHelp
, (XtPointer
)this);
218 XtAddCallback(wMsgBox
, XmNunmapCallback
,
219 (XtCallbackProc
)msgboxCallBackClose
, (XtPointer
)this);
221 // show it as a modal dialog
222 XtManageChild(wMsgBox
);
223 XtAddGrab(wMsgBox
, True
, False
);
225 // the m_result will be changed when message box goes away
228 // local message loop
229 XtAppContext context
= XtWidgetToApplicationContext(wParent
);
231 while ( m_result
== -1 )
233 XtAppNextEvent(context
, &event
);
234 XtDispatchEvent(&event
);
237 // translate the result if necessary
238 if ( m_dialogStyle
& wxYES_NO
)
240 if ( m_result
== wxID_OK
)
242 else if ( m_result
== wxID_CANCEL
)
244 else if ( m_result
== wxID_HELP
)
245 m_result
= wxID_CANCEL
;