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