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