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