]> git.saurik.com Git - wxWidgets.git/blame - src/motif/msgdlg.cpp
Fix wxGLCanvas ctor prototypes in docs. Closes bug #1237072.
[wxWidgets.git] / src / motif / msgdlg.cpp
CommitLineData
4bb6408c 1/////////////////////////////////////////////////////////////////////////////
e5b50758 2// Name: src/motif/msgdlg.cpp
4bb6408c
JS
3// Purpose: wxMessageDialog
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
e5b50758 7// RCS-ID: $Id$
4bb6408c 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"
eaa6f9ad 44#include "wx/msgdlg.h"
ee31c392 45#include "wx/motif/private.h"
6ace5176 46#include "wx/settings.h"
ee31c392
VZ
47
48// ----------------------------------------------------------------------------
49// macros
50// ----------------------------------------------------------------------------
4bb6408c 51
ee31c392 52 IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
4bb6408c 53
ee31c392
VZ
54// ============================================================================
55// implementation
56// ============================================================================
57
58// ----------------------------------------------------------------------------
59// the callbacks for message box buttons
60// ----------------------------------------------------------------------------
61
62// the common part
ccebc98a 63static void msgboxCallBack(Widget w, void* client_data, int id)
ee31c392
VZ
64{
65 // close the dialog
66 XtUnmanageChild(w);
67
68 wxMessageDialog *dlg = (wxMessageDialog *)client_data;
69 dlg->SetResult(id);
70}
71
72static void msgboxCallBackOk(Widget w,
ccebc98a 73 void* client_data,
af111fc3 74 XmAnyCallbackStruct *WXUNUSED(call_data))
ee31c392
VZ
75{
76 msgboxCallBack(w, client_data, wxID_OK);
77}
78
79static void msgboxCallBackCancel(Widget w,
ccebc98a 80 void* client_data,
af111fc3 81 XmAnyCallbackStruct *WXUNUSED(call_data))
ee31c392
VZ
82{
83 msgboxCallBack(w, client_data, wxID_CANCEL);
84}
85
11d737b4 86static void msgboxCallBackHelp(Widget w,
ccebc98a 87 void* client_data,
af111fc3 88 XmAnyCallbackStruct *WXUNUSED(call_data))
11d737b4
MB
89{
90 msgboxCallBack(w, client_data, wxID_HELP);
91}
92
ee31c392 93static void msgboxCallBackClose(Widget w,
ccebc98a 94 void* client_data,
af111fc3 95 XmAnyCallbackStruct *WXUNUSED(call_data))
ee31c392
VZ
96{
97 msgboxCallBack(w, client_data, wxID_CANCEL);
98}
99
100// ----------------------------------------------------------------------------
101// wxMessageDialog
102// ----------------------------------------------------------------------------
103
104wxMessageDialog::wxMessageDialog(wxWindow *parent,
105 const wxString& message,
106 const wxString& caption,
107 long style,
af111fc3 108 const wxPoint& WXUNUSED(pos))
4bb6408c
JS
109{
110 m_caption = caption;
111 m_message = message;
4bb6408c 112 m_parent = parent;
e5b50758 113 SetMessageDialogStyle(style);
4bb6408c
JS
114}
115
116int wxMessageDialog::ShowModal()
117{
ee31c392 118 Widget (*dialogCreateFunction)(Widget, String, ArgList, Cardinal) = NULL;
e5b50758
WS
119 const long style = GetMessageDialogStyle();
120
121 if ( style & wxYES_NO )
ee31c392
VZ
122 {
123 // if we have [Yes], it must be a question
124 dialogCreateFunction = XmCreateQuestionDialog;
ee31c392 125 }
e5b50758 126 else if ( style & wxICON_STOP )
ee31c392
VZ
127 {
128 // error dialog is the one with error icon...
129 dialogCreateFunction = XmCreateErrorDialog;
130 }
e5b50758 131 else if ( style & wxICON_EXCLAMATION )
ee31c392
VZ
132 {
133 // ...and the warning dialog too
134 dialogCreateFunction = XmCreateWarningDialog;
135 }
136 else
137 {
138 // finally, use the info dialog by default
139 dialogCreateFunction = XmCreateInformationDialog;
140 }
141
af111fc3 142 Widget wParent = m_parent ? GetWidget(m_parent) : (Widget) 0;
ee31c392
VZ
143 if ( !wParent )
144 {
145 wxWindow *window = wxTheApp->GetTopWindow();
146 if ( !window )
147 {
148 wxFAIL_MSG("can't show message box without parent window");
149
150 return wxID_CANCEL;
151 }
152
153 wParent = GetWidget(window);
154 }
155
ee1aaf99
JS
156 // prepare the arg list
157 Arg args[10];
158 int ac = 0;
159
160 wxXmString text(m_message);
161 wxXmString title(m_caption);
162 XtSetArg(args[ac], XmNmessageString, text()); ac++;
163 XtSetArg(args[ac], XmNdialogTitle, title()); ac++;
164
6ace5176
MB
165 Display* dpy = XtDisplay(wParent);
166
167 wxComputeColours (dpy, & m_backgroundColour, (wxColour*) NULL);
ee1aaf99
JS
168
169 XtSetArg(args[ac], XmNbackground, g_itemColors[wxBACK_INDEX].pixel); ac++;
170 XtSetArg(args[ac], XmNtopShadowColor, g_itemColors[wxTOPS_INDEX].pixel); ac++;
171 XtSetArg(args[ac], XmNbottomShadowColor, g_itemColors[wxBOTS_INDEX].pixel); ac++;
172 XtSetArg(args[ac], XmNforeground, g_itemColors[wxFORE_INDEX].pixel); ac++;
173
6ace5176
MB
174 wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
175
7398fb81
MB
176#if __WXMOTIF20__ && !__WXLESSTIF__
177 XtSetArg(args[ac], XmNbuttonRenderTable, font.GetFontTypeC(dpy)); ac++;
178 XtSetArg(args[ac], XmNlabelRenderTable, font.GetFontTypeC(dpy)); ac++;
179 XtSetArg(args[ac], XmNtextRenderTable, font.GetFontTypeC(dpy)); ac++;
180#else
181 XtSetArg(args[ac], XmNbuttonFontList, font.GetFontTypeC(dpy)); ac++;
182 XtSetArg(args[ac], XmNlabelFontList, font.GetFontTypeC(dpy)); ac++;
183 XtSetArg(args[ac], XmNtextFontList, font.GetFontTypeC(dpy)); ac++;
184#endif
6ace5176 185
ee1aaf99
JS
186 // do create message box
187
ee31c392
VZ
188 Widget wMsgBox = (*dialogCreateFunction)(wParent, "", args, ac);
189
190 wxCHECK_MSG( wMsgBox, wxID_CANCEL, "msg box creation failed" );
191
11d737b4
MB
192 // get the buttons which we might either remove or rename
193 // depending on the requested style
194 //
195 Widget wBtnOk = XmMessageBoxGetChild(wMsgBox, XmDIALOG_OK_BUTTON);
196 Widget wBtnHelp = XmMessageBoxGetChild(wMsgBox, XmDIALOG_HELP_BUTTON);
197 Widget wBtnCancel = XmMessageBoxGetChild(wMsgBox, XmDIALOG_CANCEL_BUTTON);
ee31c392 198
e5b50758 199 if ( style & wxYES_NO )
ee31c392 200 {
e5b50758 201 wxXmString yes(_("Yes")), no(_("No")), cancel(_("Cancel"));
ee31c392 202
e5b50758 203 if ( style & wxCANCEL )
ee31c392 204 {
11d737b4
MB
205 // use the cancel button for No and the help button for
206 // Cancel Yuk :-) MB
207 //
ee31c392
VZ
208 XtVaSetValues(wBtnOk, XmNlabelString, yes(), NULL);
209 XtVaSetValues(wBtnCancel, XmNlabelString, no(), NULL);
11d737b4 210 XtVaSetValues(wBtnHelp, XmNlabelString, cancel(), NULL);
ee31c392
VZ
211 }
212 else
213 {
11d737b4
MB
214 // no cancel button requested...
215 // remove the help button and use cancel for no
216 //
217 XtVaSetValues(wBtnCancel, XmNlabelString, no(), NULL);
218 XtUnmanageChild(wBtnHelp);
ee31c392
VZ
219 }
220 }
11d737b4
MB
221 else
222 {
223 // remove the help button and the cancel button (unless it was
224 // requested)
225 //
226 XtUnmanageChild(wBtnHelp);
e5b50758 227 if ( !(style & wxCANCEL ) ) XtUnmanageChild(wBtnCancel);
11d737b4 228 }
ee31c392
VZ
229
230 // set the callbacks for the message box buttons
231 XtAddCallback(wMsgBox, XmNokCallback,
232 (XtCallbackProc)msgboxCallBackOk, (XtPointer)this);
233 XtAddCallback(wMsgBox, XmNcancelCallback,
234 (XtCallbackProc)msgboxCallBackCancel, (XtPointer)this);
11d737b4
MB
235 XtAddCallback(wMsgBox, XmNhelpCallback,
236 (XtCallbackProc)msgboxCallBackHelp, (XtPointer)this);
ee31c392
VZ
237 XtAddCallback(wMsgBox, XmNunmapCallback,
238 (XtCallbackProc)msgboxCallBackClose, (XtPointer)this);
239
240 // show it as a modal dialog
241 XtManageChild(wMsgBox);
242 XtAddGrab(wMsgBox, True, False);
243
244 // the m_result will be changed when message box goes away
245 m_result = -1;
246
247 // local message loop
248 XtAppContext context = XtWidgetToApplicationContext(wParent);
249 XEvent event;
250 while ( m_result == -1 )
251 {
252 XtAppNextEvent(context, &event);
253 XtDispatchEvent(&event);
254 }
255
256 // translate the result if necessary
e5b50758 257 if ( style & wxYES_NO )
ee31c392
VZ
258 {
259 if ( m_result == wxID_OK )
260 m_result = wxID_YES;
261 else if ( m_result == wxID_CANCEL )
262 m_result = wxID_NO;
11d737b4
MB
263 else if ( m_result == wxID_HELP )
264 m_result = wxID_CANCEL;
ee31c392
VZ
265 }
266
267 return m_result;
4bb6408c
JS
268}
269