]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/motif/msgdlg.cpp
Added size constants to allow drawn control parts to match the window variant,
[wxWidgets.git] / src / motif / msgdlg.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/motif/msgdlg.cpp
3// Purpose: wxMessageDialog
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __VMS
24#define XtDisplay XTDISPLAY
25#pragma message disable nosimpint
26#include "wx/vms_x_fix.h"
27#endif
28#include <X11/Xlib.h>
29
30#include <Xm/Xm.h>
31#include <Xm/MessageB.h>
32#ifdef __VMS
33#pragma message enable nosimpint
34#endif
35
36#include "wx/msgdlg.h"
37
38#ifndef WX_PRECOMP
39 #include "wx/intl.h"
40 #include "wx/app.h"
41 #include "wx/settings.h"
42#endif
43
44#include "wx/motif/private.h"
45
46// ----------------------------------------------------------------------------
47// macros
48// ----------------------------------------------------------------------------
49
50 IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
51
52// ============================================================================
53// implementation
54// ============================================================================
55
56// ----------------------------------------------------------------------------
57// the callbacks for message box buttons
58// ----------------------------------------------------------------------------
59
60// the common part
61static void msgboxCallBack(Widget w, void* client_data, int id)
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,
71 void* client_data,
72 XmAnyCallbackStruct *WXUNUSED(call_data))
73{
74 msgboxCallBack(w, client_data, wxID_OK);
75}
76
77static void msgboxCallBackCancel(Widget w,
78 void* client_data,
79 XmAnyCallbackStruct *WXUNUSED(call_data))
80{
81 msgboxCallBack(w, client_data, wxID_CANCEL);
82}
83
84static void msgboxCallBackHelp(Widget w,
85 void* client_data,
86 XmAnyCallbackStruct *WXUNUSED(call_data))
87{
88 msgboxCallBack(w, client_data, wxID_HELP);
89}
90
91static void msgboxCallBackClose(Widget w,
92 void* client_data,
93 XmAnyCallbackStruct *WXUNUSED(call_data))
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,
106 const wxPoint& WXUNUSED(pos))
107{
108 m_caption = caption;
109 m_message = message;
110 m_parent = parent;
111 SetMessageDialogStyle(style);
112}
113
114extern "C"
115{
116 typedef Widget (*DialogCreateFunction)(Widget, String, ArgList, Cardinal);
117}
118
119int wxMessageDialog::ShowModal()
120{
121 const long style = GetMessageDialogStyle();
122
123 DialogCreateFunction dialogCreateFunction;
124 if ( style & wxYES_NO )
125 {
126 // if we have [Yes], it must be a question
127 dialogCreateFunction = XmCreateQuestionDialog;
128 }
129 else if ( style & wxICON_STOP )
130 {
131 // error dialog is the one with error icon...
132 dialogCreateFunction = XmCreateErrorDialog;
133 }
134 else if ( style & wxICON_EXCLAMATION )
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
145 Widget wParent = m_parent ? GetWidget(m_parent) : (Widget) 0;
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
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
168 Display* dpy = XtDisplay(wParent);
169
170 wxComputeColours (dpy, & m_backgroundColour, (wxColour*) NULL);
171
172 XtSetArg(args[ac], XmNbackground, g_itemColors[wxBACK_INDEX].pixel); ac++;
173 XtSetArg(args[ac], XmNtopShadowColor, g_itemColors[wxTOPS_INDEX].pixel); ac++;
174 XtSetArg(args[ac], XmNbottomShadowColor, g_itemColors[wxBOTS_INDEX].pixel); ac++;
175 XtSetArg(args[ac], XmNforeground, g_itemColors[wxFORE_INDEX].pixel); ac++;
176
177 wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
178
179#if __WXMOTIF20__ && !__WXLESSTIF__
180 XtSetArg(args[ac], XmNbuttonRenderTable, font.GetFontTypeC(dpy)); ac++;
181 XtSetArg(args[ac], XmNlabelRenderTable, font.GetFontTypeC(dpy)); ac++;
182 XtSetArg(args[ac], XmNtextRenderTable, font.GetFontTypeC(dpy)); ac++;
183#else
184 XtSetArg(args[ac], XmNbuttonFontList, font.GetFontTypeC(dpy)); ac++;
185 XtSetArg(args[ac], XmNlabelFontList, font.GetFontTypeC(dpy)); ac++;
186 XtSetArg(args[ac], XmNtextFontList, font.GetFontTypeC(dpy)); ac++;
187#endif
188
189 // do create message box
190
191 Widget wMsgBox = (*dialogCreateFunction)(wParent, wxMOTIF_STR(""), args, ac);
192
193 wxCHECK_MSG( wMsgBox, wxID_CANCEL, "msg box creation failed" );
194
195 // get the buttons which we might either remove or rename
196 // depending on the requested style
197 //
198 Widget wBtnOk = XmMessageBoxGetChild(wMsgBox, XmDIALOG_OK_BUTTON);
199 Widget wBtnHelp = XmMessageBoxGetChild(wMsgBox, XmDIALOG_HELP_BUTTON);
200 Widget wBtnCancel = XmMessageBoxGetChild(wMsgBox, XmDIALOG_CANCEL_BUTTON);
201
202 if ( style & wxYES_NO )
203 {
204 wxXmString yes(_("Yes")), no(_("No")), cancel(_("Cancel"));
205
206 if ( style & wxCANCEL )
207 {
208 // use the cancel button for No and the help button for
209 // Cancel Yuk :-) MB
210 //
211 XtVaSetValues(wBtnOk, XmNlabelString, yes(), NULL);
212 XtVaSetValues(wBtnCancel, XmNlabelString, no(), NULL);
213 XtVaSetValues(wBtnHelp, XmNlabelString, cancel(), NULL);
214 }
215 else
216 {
217 // no cancel button requested...
218 // remove the help button and use cancel for no
219 //
220 XtVaSetValues(wBtnCancel, XmNlabelString, no(), NULL);
221 XtUnmanageChild(wBtnHelp);
222 }
223 }
224 else
225 {
226 // remove the help button and the cancel button (unless it was
227 // requested)
228 //
229 XtUnmanageChild(wBtnHelp);
230 if ( !(style & wxCANCEL ) ) XtUnmanageChild(wBtnCancel);
231 }
232
233 // set the callbacks for the message box buttons
234 XtAddCallback(wMsgBox, XmNokCallback,
235 (XtCallbackProc)msgboxCallBackOk, (XtPointer)this);
236 XtAddCallback(wMsgBox, XmNcancelCallback,
237 (XtCallbackProc)msgboxCallBackCancel, (XtPointer)this);
238 XtAddCallback(wMsgBox, XmNhelpCallback,
239 (XtCallbackProc)msgboxCallBackHelp, (XtPointer)this);
240 XtAddCallback(wMsgBox, XmNunmapCallback,
241 (XtCallbackProc)msgboxCallBackClose, (XtPointer)this);
242
243 // show it as a modal dialog
244 XtManageChild(wMsgBox);
245 XtAddGrab(wMsgBox, True, False);
246
247 // the m_result will be changed when message box goes away
248 m_result = -1;
249
250 // local message loop
251 XtAppContext context = XtWidgetToApplicationContext(wParent);
252 XEvent event;
253 while ( m_result == -1 )
254 {
255 XtAppNextEvent(context, &event);
256 XtDispatchEvent(&event);
257 }
258
259 // translate the result if necessary
260 if ( style & wxYES_NO )
261 {
262 if ( m_result == wxID_OK )
263 m_result = wxID_YES;
264 else if ( m_result == wxID_CANCEL )
265 m_result = wxID_NO;
266 else if ( m_result == wxID_HELP )
267 m_result = wxID_CANCEL;
268 }
269
270 return m_result;
271}