]> git.saurik.com Git - wxWidgets.git/blame - src/motif/msgdlg.cpp
BCC compilation fix
[wxWidgets.git] / src / motif / msgdlg.cpp
CommitLineData
4bb6408c
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: msgdlg.cpp
3// Purpose: wxMessageDialog
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $$
8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
4bb6408c
JS
10/////////////////////////////////////////////////////////////////////////////
11
ee31c392
VZ
12// ============================================================================
13// declarations
14// ============================================================================
15
14f355c2 16#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
ee31c392 17 #pragma implementation "msgdlg.h"
4bb6408c
JS
18#endif
19
ee31c392
VZ
20// ----------------------------------------------------------------------------
21// headers
22// ----------------------------------------------------------------------------
23
1248b41f
MB
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
11334a9e
VZ
27#include "wx/defs.h"
28
338dd992 29#ifdef __VMS
bcd055ae 30#define XtDisplay XTDISPLAY
338dd992 31#pragma message disable nosimpint
4dff3400 32#include <wx/vms_x_fix.h>
338dd992 33#endif
ee31c392
VZ
34#include <X11/Xlib.h>
35
36#include <Xm/Xm.h>
37#include <Xm/MessageB.h>
338dd992
JJ
38#ifdef __VMS
39#pragma message enable nosimpint
40#endif
ee31c392
VZ
41
42#include "wx/app.h"
43#include "wx/intl.h"
5dcf05ae 44#include "wx/motif/msgdlg.h"
ee31c392
VZ
45#include "wx/motif/private.h"
46
47// ----------------------------------------------------------------------------
48// macros
49// ----------------------------------------------------------------------------
4bb6408c 50
ee31c392 51 IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
4bb6408c 52
ee31c392
VZ
53// ============================================================================
54// implementation
55// ============================================================================
56
57// ----------------------------------------------------------------------------
58// the callbacks for message box buttons
59// ----------------------------------------------------------------------------
60
61// the common part
ccebc98a 62static void msgboxCallBack(Widget w, void* client_data, int id)
ee31c392
VZ
63{
64 // close the dialog
65 XtUnmanageChild(w);
66
67 wxMessageDialog *dlg = (wxMessageDialog *)client_data;
68 dlg->SetResult(id);
69}
70
71static void msgboxCallBackOk(Widget w,
ccebc98a 72 void* client_data,
af111fc3 73 XmAnyCallbackStruct *WXUNUSED(call_data))
ee31c392
VZ
74{
75 msgboxCallBack(w, client_data, wxID_OK);
76}
77
78static void msgboxCallBackCancel(Widget w,
ccebc98a 79 void* client_data,
af111fc3 80 XmAnyCallbackStruct *WXUNUSED(call_data))
ee31c392
VZ
81{
82 msgboxCallBack(w, client_data, wxID_CANCEL);
83}
84
11d737b4 85static void msgboxCallBackHelp(Widget w,
ccebc98a 86 void* client_data,
af111fc3 87 XmAnyCallbackStruct *WXUNUSED(call_data))
11d737b4
MB
88{
89 msgboxCallBack(w, client_data, wxID_HELP);
90}
91
ee31c392 92static void msgboxCallBackClose(Widget w,
ccebc98a 93 void* client_data,
af111fc3 94 XmAnyCallbackStruct *WXUNUSED(call_data))
ee31c392
VZ
95{
96 msgboxCallBack(w, client_data, wxID_CANCEL);
97}
98
99// ----------------------------------------------------------------------------
100// wxMessageDialog
101// ----------------------------------------------------------------------------
102
103wxMessageDialog::wxMessageDialog(wxWindow *parent,
104 const wxString& message,
105 const wxString& caption,
106 long style,
af111fc3 107 const wxPoint& WXUNUSED(pos))
4bb6408c
JS
108{
109 m_caption = caption;
110 m_message = message;
111 m_dialogStyle = style;
112 m_parent = parent;
113}
114
115int wxMessageDialog::ShowModal()
116{
ee31c392
VZ
117 Widget (*dialogCreateFunction)(Widget, String, ArgList, Cardinal) = NULL;
118 if ( m_dialogStyle & wxYES_NO )
119 {
120 // if we have [Yes], it must be a question
121 dialogCreateFunction = XmCreateQuestionDialog;
ee31c392
VZ
122 }
123 else if ( m_dialogStyle & wxICON_STOP )
124 {
125 // error dialog is the one with error icon...
126 dialogCreateFunction = XmCreateErrorDialog;
127 }
128 else if ( m_dialogStyle & wxICON_EXCLAMATION )
129 {
130 // ...and the warning dialog too
131 dialogCreateFunction = XmCreateWarningDialog;
132 }
133 else
134 {
135 // finally, use the info dialog by default
136 dialogCreateFunction = XmCreateInformationDialog;
137 }
138
af111fc3 139 Widget wParent = m_parent ? GetWidget(m_parent) : (Widget) 0;
ee31c392
VZ
140 if ( !wParent )
141 {
142 wxWindow *window = wxTheApp->GetTopWindow();
143 if ( !window )
144 {
145 wxFAIL_MSG("can't show message box without parent window");
146
147 return wxID_CANCEL;
148 }
149
150 wParent = GetWidget(window);
151 }
152
ee1aaf99
JS
153 // prepare the arg list
154 Arg args[10];
155 int ac = 0;
156
157 wxXmString text(m_message);
158 wxXmString title(m_caption);
159 XtSetArg(args[ac], XmNmessageString, text()); ac++;
160 XtSetArg(args[ac], XmNdialogTitle, title()); ac++;
161
162 wxComputeColours (XtDisplay(wParent), & m_backgroundColour,
163 (wxColour*) NULL);
164
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++;
169
170 // do create message box
171
ee31c392
VZ
172 Widget wMsgBox = (*dialogCreateFunction)(wParent, "", args, ac);
173
174 wxCHECK_MSG( wMsgBox, wxID_CANCEL, "msg box creation failed" );
175
11d737b4
MB
176 // get the buttons which we might either remove or rename
177 // depending on the requested style
178 //
179 Widget wBtnOk = XmMessageBoxGetChild(wMsgBox, XmDIALOG_OK_BUTTON);
180 Widget wBtnHelp = XmMessageBoxGetChild(wMsgBox, XmDIALOG_HELP_BUTTON);
181 Widget wBtnCancel = XmMessageBoxGetChild(wMsgBox, XmDIALOG_CANCEL_BUTTON);
ee31c392 182
11d737b4 183 if ( m_dialogStyle & wxYES_NO )
ee31c392 184 {
11d737b4 185 wxXmString yes(_("Yes")), no(_("No")), cancel(_("Cancel"));
ee31c392 186
11d737b4 187 if ( m_dialogStyle & wxCANCEL )
ee31c392 188 {
11d737b4
MB
189 // use the cancel button for No and the help button for
190 // Cancel Yuk :-) MB
191 //
ee31c392
VZ
192 XtVaSetValues(wBtnOk, XmNlabelString, yes(), NULL);
193 XtVaSetValues(wBtnCancel, XmNlabelString, no(), NULL);
11d737b4 194 XtVaSetValues(wBtnHelp, XmNlabelString, cancel(), NULL);
ee31c392
VZ
195 }
196 else
197 {
11d737b4
MB
198 // no cancel button requested...
199 // remove the help button and use cancel for no
200 //
201 XtVaSetValues(wBtnCancel, XmNlabelString, no(), NULL);
202 XtUnmanageChild(wBtnHelp);
ee31c392
VZ
203 }
204 }
11d737b4
MB
205 else
206 {
207 // remove the help button and the cancel button (unless it was
208 // requested)
209 //
210 XtUnmanageChild(wBtnHelp);
211 if ( !(m_dialogStyle & wxCANCEL ) ) XtUnmanageChild(wBtnCancel);
212 }
ee31c392
VZ
213
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);
11d737b4
MB
219 XtAddCallback(wMsgBox, XmNhelpCallback,
220 (XtCallbackProc)msgboxCallBackHelp, (XtPointer)this);
ee31c392
VZ
221 XtAddCallback(wMsgBox, XmNunmapCallback,
222 (XtCallbackProc)msgboxCallBackClose, (XtPointer)this);
223
224 // show it as a modal dialog
225 XtManageChild(wMsgBox);
226 XtAddGrab(wMsgBox, True, False);
227
228 // the m_result will be changed when message box goes away
229 m_result = -1;
230
231 // local message loop
232 XtAppContext context = XtWidgetToApplicationContext(wParent);
233 XEvent event;
234 while ( m_result == -1 )
235 {
236 XtAppNextEvent(context, &event);
237 XtDispatchEvent(&event);
238 }
239
240 // translate the result if necessary
241 if ( m_dialogStyle & wxYES_NO )
242 {
243 if ( m_result == wxID_OK )
244 m_result = wxID_YES;
245 else if ( m_result == wxID_CANCEL )
246 m_result = wxID_NO;
11d737b4
MB
247 else if ( m_result == wxID_HELP )
248 m_result = wxID_CANCEL;
ee31c392
VZ
249 }
250
251 return m_result;
4bb6408c
JS
252}
253