1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/motif/msgdlg.cpp
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/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
))
112 SetMessageDialogStyle(style
);
115 int wxMessageDialog::ShowModal()
117 Widget (*dialogCreateFunction
)(Widget
, String
, ArgList
, Cardinal
) = NULL
;
118 const long style
= GetMessageDialogStyle();
120 if ( style
& wxYES_NO
)
122 // if we have [Yes], it must be a question
123 dialogCreateFunction
= XmCreateQuestionDialog
;
125 else if ( style
& wxICON_STOP
)
127 // error dialog is the one with error icon...
128 dialogCreateFunction
= XmCreateErrorDialog
;
130 else if ( style
& wxICON_EXCLAMATION
)
132 // ...and the warning dialog too
133 dialogCreateFunction
= XmCreateWarningDialog
;
137 // finally, use the info dialog by default
138 dialogCreateFunction
= XmCreateInformationDialog
;
141 Widget wParent
= m_parent
? GetWidget(m_parent
) : (Widget
) 0;
144 wxWindow
*window
= wxTheApp
->GetTopWindow();
147 wxFAIL_MSG("can't show message box without parent window");
152 wParent
= GetWidget(window
);
155 // prepare the arg list
159 wxXmString
text(m_message
);
160 wxXmString
title(m_caption
);
161 XtSetArg(args
[ac
], XmNmessageString
, text()); ac
++;
162 XtSetArg(args
[ac
], XmNdialogTitle
, title()); ac
++;
164 wxComputeColours (XtDisplay(wParent
), & m_backgroundColour
,
167 XtSetArg(args
[ac
], XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
); ac
++;
168 XtSetArg(args
[ac
], XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
); ac
++;
169 XtSetArg(args
[ac
], XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
); ac
++;
170 XtSetArg(args
[ac
], XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
); ac
++;
172 // do create message box
174 Widget wMsgBox
= (*dialogCreateFunction
)(wParent
, "", args
, ac
);
176 wxCHECK_MSG( wMsgBox
, wxID_CANCEL
, "msg box creation failed" );
178 // get the buttons which we might either remove or rename
179 // depending on the requested style
181 Widget wBtnOk
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_OK_BUTTON
);
182 Widget wBtnHelp
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_HELP_BUTTON
);
183 Widget wBtnCancel
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_CANCEL_BUTTON
);
185 if ( style
& wxYES_NO
)
187 wxXmString
yes(_("Yes")), no(_("No")), cancel(_("Cancel"));
189 if ( style
& wxCANCEL
)
191 // use the cancel button for No and the help button for
194 XtVaSetValues(wBtnOk
, XmNlabelString
, yes(), NULL
);
195 XtVaSetValues(wBtnCancel
, XmNlabelString
, no(), NULL
);
196 XtVaSetValues(wBtnHelp
, XmNlabelString
, cancel(), NULL
);
200 // no cancel button requested...
201 // remove the help button and use cancel for no
203 XtVaSetValues(wBtnCancel
, XmNlabelString
, no(), NULL
);
204 XtUnmanageChild(wBtnHelp
);
209 // remove the help button and the cancel button (unless it was
212 XtUnmanageChild(wBtnHelp
);
213 if ( !(style
& wxCANCEL
) ) XtUnmanageChild(wBtnCancel
);
216 // set the callbacks for the message box buttons
217 XtAddCallback(wMsgBox
, XmNokCallback
,
218 (XtCallbackProc
)msgboxCallBackOk
, (XtPointer
)this);
219 XtAddCallback(wMsgBox
, XmNcancelCallback
,
220 (XtCallbackProc
)msgboxCallBackCancel
, (XtPointer
)this);
221 XtAddCallback(wMsgBox
, XmNhelpCallback
,
222 (XtCallbackProc
)msgboxCallBackHelp
, (XtPointer
)this);
223 XtAddCallback(wMsgBox
, XmNunmapCallback
,
224 (XtCallbackProc
)msgboxCallBackClose
, (XtPointer
)this);
226 // show it as a modal dialog
227 XtManageChild(wMsgBox
);
228 XtAddGrab(wMsgBox
, True
, False
);
230 // the m_result will be changed when message box goes away
233 // local message loop
234 XtAppContext context
= XtWidgetToApplicationContext(wParent
);
236 while ( m_result
== -1 )
238 XtAppNextEvent(context
, &event
);
239 XtDispatchEvent(&event
);
242 // translate the result if necessary
243 if ( style
& wxYES_NO
)
245 if ( m_result
== wxID_OK
)
247 else if ( m_result
== wxID_CANCEL
)
249 else if ( m_result
== wxID_HELP
)
250 m_result
= wxID_CANCEL
;