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