1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMessageDialog
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
17 #pragma implementation "msgdlg.h"
20 // ----------------------------------------------------------------------------
22 // ----------------------------------------------------------------------------
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
30 #define XtDisplay XTDISPLAY
31 #pragma message disable nosimpint
32 #include <wx/vms_x_fix.h>
37 #include <Xm/MessageB.h>
39 #pragma message enable nosimpint
44 #include "wx/motif/msgdlg.h"
45 #include "wx/motif/private.h"
47 // ----------------------------------------------------------------------------
49 // ----------------------------------------------------------------------------
51 IMPLEMENT_CLASS(wxMessageDialog
, wxDialog
)
53 // ============================================================================
55 // ============================================================================
57 // ----------------------------------------------------------------------------
58 // the callbacks for message box buttons
59 // ----------------------------------------------------------------------------
62 static void msgboxCallBack(Widget w
, void* client_data
, int id
)
67 wxMessageDialog
*dlg
= (wxMessageDialog
*)client_data
;
71 static void msgboxCallBackOk(Widget w
,
73 XmAnyCallbackStruct
*WXUNUSED(call_data
))
75 msgboxCallBack(w
, client_data
, wxID_OK
);
78 static void msgboxCallBackCancel(Widget w
,
80 XmAnyCallbackStruct
*WXUNUSED(call_data
))
82 msgboxCallBack(w
, client_data
, wxID_CANCEL
);
85 static void msgboxCallBackHelp(Widget w
,
87 XmAnyCallbackStruct
*WXUNUSED(call_data
))
89 msgboxCallBack(w
, client_data
, wxID_HELP
);
92 static void msgboxCallBackClose(Widget w
,
94 XmAnyCallbackStruct
*WXUNUSED(call_data
))
96 msgboxCallBack(w
, client_data
, wxID_CANCEL
);
99 // ----------------------------------------------------------------------------
101 // ----------------------------------------------------------------------------
103 wxMessageDialog::wxMessageDialog(wxWindow
*parent
,
104 const wxString
& message
,
105 const wxString
& caption
,
107 const wxPoint
& WXUNUSED(pos
))
111 m_dialogStyle
= style
;
115 int wxMessageDialog::ShowModal()
117 Widget (*dialogCreateFunction
)(Widget
, String
, ArgList
, Cardinal
) = NULL
;
118 if ( m_dialogStyle
& wxYES_NO
)
120 // if we have [Yes], it must be a question
121 dialogCreateFunction
= XmCreateQuestionDialog
;
123 else if ( m_dialogStyle
& wxICON_STOP
)
125 // error dialog is the one with error icon...
126 dialogCreateFunction
= XmCreateErrorDialog
;
128 else if ( m_dialogStyle
& wxICON_EXCLAMATION
)
130 // ...and the warning dialog too
131 dialogCreateFunction
= XmCreateWarningDialog
;
135 // finally, use the info dialog by default
136 dialogCreateFunction
= XmCreateInformationDialog
;
139 Widget wParent
= m_parent
? GetWidget(m_parent
) : (Widget
) 0;
142 wxWindow
*window
= wxTheApp
->GetTopWindow();
145 wxFAIL_MSG("can't show message box without parent window");
150 wParent
= GetWidget(window
);
153 // prepare the arg list
157 wxXmString
text(m_message
);
158 wxXmString
title(m_caption
);
159 XtSetArg(args
[ac
], XmNmessageString
, text()); ac
++;
160 XtSetArg(args
[ac
], XmNdialogTitle
, title()); ac
++;
162 wxComputeColours (XtDisplay(wParent
), & m_backgroundColour
,
165 XtSetArg(args
[ac
], XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
); ac
++;
166 XtSetArg(args
[ac
], XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
); ac
++;
167 XtSetArg(args
[ac
], XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
); ac
++;
168 XtSetArg(args
[ac
], XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
); ac
++;
170 // do create message box
172 Widget wMsgBox
= (*dialogCreateFunction
)(wParent
, "", args
, ac
);
174 wxCHECK_MSG( wMsgBox
, wxID_CANCEL
, "msg box creation failed" );
176 // get the buttons which we might either remove or rename
177 // depending on the requested style
179 Widget wBtnOk
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_OK_BUTTON
);
180 Widget wBtnHelp
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_HELP_BUTTON
);
181 Widget wBtnCancel
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_CANCEL_BUTTON
);
183 if ( m_dialogStyle
& wxYES_NO
)
185 wxXmString
yes(_("Yes")), no(_("No")), cancel(_("Cancel"));
187 if ( m_dialogStyle
& wxCANCEL
)
189 // use the cancel button for No and the help button for
192 XtVaSetValues(wBtnOk
, XmNlabelString
, yes(), NULL
);
193 XtVaSetValues(wBtnCancel
, XmNlabelString
, no(), NULL
);
194 XtVaSetValues(wBtnHelp
, XmNlabelString
, cancel(), NULL
);
198 // no cancel button requested...
199 // remove the help button and use cancel for no
201 XtVaSetValues(wBtnCancel
, XmNlabelString
, no(), NULL
);
202 XtUnmanageChild(wBtnHelp
);
207 // remove the help button and the cancel button (unless it was
210 XtUnmanageChild(wBtnHelp
);
211 if ( !(m_dialogStyle
& wxCANCEL
) ) XtUnmanageChild(wBtnCancel
);
214 // set the callbacks for the message box buttons
215 XtAddCallback(wMsgBox
, XmNokCallback
,
216 (XtCallbackProc
)msgboxCallBackOk
, (XtPointer
)this);
217 XtAddCallback(wMsgBox
, XmNcancelCallback
,
218 (XtCallbackProc
)msgboxCallBackCancel
, (XtPointer
)this);
219 XtAddCallback(wMsgBox
, XmNhelpCallback
,
220 (XtCallbackProc
)msgboxCallBackHelp
, (XtPointer
)this);
221 XtAddCallback(wMsgBox
, XmNunmapCallback
,
222 (XtCallbackProc
)msgboxCallBackClose
, (XtPointer
)this);
224 // show it as a modal dialog
225 XtManageChild(wMsgBox
);
226 XtAddGrab(wMsgBox
, True
, False
);
228 // the m_result will be changed when message box goes away
231 // local message loop
232 XtAppContext context
= XtWidgetToApplicationContext(wParent
);
234 while ( m_result
== -1 )
236 XtAppNextEvent(context
, &event
);
237 XtDispatchEvent(&event
);
240 // translate the result if necessary
241 if ( m_dialogStyle
& wxYES_NO
)
243 if ( m_result
== wxID_OK
)
245 else if ( m_result
== wxID_CANCEL
)
247 else if ( m_result
== wxID_HELP
)
248 m_result
= wxID_CANCEL
;