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
26 #include <wx/vms_x_fix.h>
31 #include <Xm/MessageB.h>
33 #pragma message enable nosimpint
38 #include "wx/motif/msgdlg.h"
39 #include "wx/motif/private.h"
41 // ----------------------------------------------------------------------------
43 // ----------------------------------------------------------------------------
45 IMPLEMENT_CLASS(wxMessageDialog
, wxDialog
)
47 // ============================================================================
49 // ============================================================================
51 // ----------------------------------------------------------------------------
52 // the callbacks for message box buttons
53 // ----------------------------------------------------------------------------
56 static void msgboxCallBack(Widget w
, void* client_data
, int id
)
61 wxMessageDialog
*dlg
= (wxMessageDialog
*)client_data
;
65 static void msgboxCallBackOk(Widget w
,
67 XmAnyCallbackStruct
*WXUNUSED(call_data
))
69 msgboxCallBack(w
, client_data
, wxID_OK
);
72 static void msgboxCallBackCancel(Widget w
,
74 XmAnyCallbackStruct
*WXUNUSED(call_data
))
76 msgboxCallBack(w
, client_data
, wxID_CANCEL
);
79 static void msgboxCallBackHelp(Widget w
,
81 XmAnyCallbackStruct
*WXUNUSED(call_data
))
83 msgboxCallBack(w
, client_data
, wxID_HELP
);
86 static void msgboxCallBackClose(Widget w
,
88 XmAnyCallbackStruct
*WXUNUSED(call_data
))
90 msgboxCallBack(w
, client_data
, wxID_CANCEL
);
93 // ----------------------------------------------------------------------------
95 // ----------------------------------------------------------------------------
97 wxMessageDialog::wxMessageDialog(wxWindow
*parent
,
98 const wxString
& message
,
99 const wxString
& caption
,
101 const wxPoint
& WXUNUSED(pos
))
105 m_dialogStyle
= style
;
109 int wxMessageDialog::ShowModal()
111 Widget (*dialogCreateFunction
)(Widget
, String
, ArgList
, Cardinal
) = NULL
;
112 if ( m_dialogStyle
& wxYES_NO
)
114 // if we have [Yes], it must be a question
115 dialogCreateFunction
= XmCreateQuestionDialog
;
117 else if ( m_dialogStyle
& wxICON_STOP
)
119 // error dialog is the one with error icon...
120 dialogCreateFunction
= XmCreateErrorDialog
;
122 else if ( m_dialogStyle
& wxICON_EXCLAMATION
)
124 // ...and the warning dialog too
125 dialogCreateFunction
= XmCreateWarningDialog
;
129 // finally, use the info dialog by default
130 dialogCreateFunction
= XmCreateInformationDialog
;
133 Widget wParent
= m_parent
? GetWidget(m_parent
) : (Widget
) 0;
136 wxWindow
*window
= wxTheApp
->GetTopWindow();
139 wxFAIL_MSG("can't show message box without parent window");
144 wParent
= GetWidget(window
);
147 // prepare the arg list
151 wxXmString
text(m_message
);
152 wxXmString
title(m_caption
);
153 XtSetArg(args
[ac
], XmNmessageString
, text()); ac
++;
154 XtSetArg(args
[ac
], XmNdialogTitle
, title()); ac
++;
156 wxComputeColours (XtDisplay(wParent
), & m_backgroundColour
,
159 XtSetArg(args
[ac
], XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
); ac
++;
160 XtSetArg(args
[ac
], XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
); ac
++;
161 XtSetArg(args
[ac
], XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
); ac
++;
162 XtSetArg(args
[ac
], XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
); ac
++;
164 // do create message box
166 Widget wMsgBox
= (*dialogCreateFunction
)(wParent
, "", args
, ac
);
168 wxCHECK_MSG( wMsgBox
, wxID_CANCEL
, "msg box creation failed" );
170 // get the buttons which we might either remove or rename
171 // depending on the requested style
173 Widget wBtnOk
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_OK_BUTTON
);
174 Widget wBtnHelp
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_HELP_BUTTON
);
175 Widget wBtnCancel
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_CANCEL_BUTTON
);
177 if ( m_dialogStyle
& wxYES_NO
)
179 wxXmString
yes(_("Yes")), no(_("No")), cancel(_("Cancel"));
181 if ( m_dialogStyle
& wxCANCEL
)
183 // use the cancel button for No and the help button for
186 XtVaSetValues(wBtnOk
, XmNlabelString
, yes(), NULL
);
187 XtVaSetValues(wBtnCancel
, XmNlabelString
, no(), NULL
);
188 XtVaSetValues(wBtnHelp
, XmNlabelString
, cancel(), NULL
);
192 // no cancel button requested...
193 // remove the help button and use cancel for no
195 XtVaSetValues(wBtnCancel
, XmNlabelString
, no(), NULL
);
196 XtUnmanageChild(wBtnHelp
);
201 // remove the help button and the cancel button (unless it was
204 XtUnmanageChild(wBtnHelp
);
205 if ( !(m_dialogStyle
& wxCANCEL
) ) XtUnmanageChild(wBtnCancel
);
208 // set the callbacks for the message box buttons
209 XtAddCallback(wMsgBox
, XmNokCallback
,
210 (XtCallbackProc
)msgboxCallBackOk
, (XtPointer
)this);
211 XtAddCallback(wMsgBox
, XmNcancelCallback
,
212 (XtCallbackProc
)msgboxCallBackCancel
, (XtPointer
)this);
213 XtAddCallback(wMsgBox
, XmNhelpCallback
,
214 (XtCallbackProc
)msgboxCallBackHelp
, (XtPointer
)this);
215 XtAddCallback(wMsgBox
, XmNunmapCallback
,
216 (XtCallbackProc
)msgboxCallBackClose
, (XtPointer
)this);
218 // show it as a modal dialog
219 XtManageChild(wMsgBox
);
220 XtAddGrab(wMsgBox
, True
, False
);
222 // the m_result will be changed when message box goes away
225 // local message loop
226 XtAppContext context
= XtWidgetToApplicationContext(wParent
);
228 while ( m_result
== -1 )
230 XtAppNextEvent(context
, &event
);
231 XtDispatchEvent(&event
);
234 // translate the result if necessary
235 if ( m_dialogStyle
& wxYES_NO
)
237 if ( m_result
== wxID_OK
)
239 else if ( m_result
== wxID_CANCEL
)
241 else if ( m_result
== wxID_HELP
)
242 m_result
= wxID_CANCEL
;