]> git.saurik.com Git - wxWidgets.git/blob - src/motif/msgdlg.cpp
mask fixes for non-core graphics case (this build uses CopyDeepMask for painting...
[wxWidgets.git] / src / motif / msgdlg.cpp
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 #include "wx/defs.h"
24
25 #ifdef __VMS
26 #define XtDisplay XTDISPLAY
27 #pragma message disable nosimpint
28 #include "wx/vms_x_fix.h"
29 #endif
30 #include <X11/Xlib.h>
31
32 #include <Xm/Xm.h>
33 #include <Xm/MessageB.h>
34 #ifdef __VMS
35 #pragma message enable nosimpint
36 #endif
37
38 #include "wx/app.h"
39 #include "wx/intl.h"
40 #include "wx/msgdlg.h"
41 #include "wx/motif/private.h"
42 #include "wx/settings.h"
43
44 // ----------------------------------------------------------------------------
45 // macros
46 // ----------------------------------------------------------------------------
47
48 IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
49
50 // ============================================================================
51 // implementation
52 // ============================================================================
53
54 // ----------------------------------------------------------------------------
55 // the callbacks for message box buttons
56 // ----------------------------------------------------------------------------
57
58 // the common part
59 static void msgboxCallBack(Widget w, void* client_data, int id)
60 {
61 // close the dialog
62 XtUnmanageChild(w);
63
64 wxMessageDialog *dlg = (wxMessageDialog *)client_data;
65 dlg->SetResult(id);
66 }
67
68 static void msgboxCallBackOk(Widget w,
69 void* client_data,
70 XmAnyCallbackStruct *WXUNUSED(call_data))
71 {
72 msgboxCallBack(w, client_data, wxID_OK);
73 }
74
75 static void msgboxCallBackCancel(Widget w,
76 void* client_data,
77 XmAnyCallbackStruct *WXUNUSED(call_data))
78 {
79 msgboxCallBack(w, client_data, wxID_CANCEL);
80 }
81
82 static void msgboxCallBackHelp(Widget w,
83 void* client_data,
84 XmAnyCallbackStruct *WXUNUSED(call_data))
85 {
86 msgboxCallBack(w, client_data, wxID_HELP);
87 }
88
89 static void msgboxCallBackClose(Widget w,
90 void* client_data,
91 XmAnyCallbackStruct *WXUNUSED(call_data))
92 {
93 msgboxCallBack(w, client_data, wxID_CANCEL);
94 }
95
96 // ----------------------------------------------------------------------------
97 // wxMessageDialog
98 // ----------------------------------------------------------------------------
99
100 wxMessageDialog::wxMessageDialog(wxWindow *parent,
101 const wxString& message,
102 const wxString& caption,
103 long style,
104 const wxPoint& WXUNUSED(pos))
105 {
106 m_caption = caption;
107 m_message = message;
108 m_parent = parent;
109 SetMessageDialogStyle(style);
110 }
111
112 extern "C"
113 {
114 typedef Widget (*DialogCreateFunction)(Widget, String, ArgList, Cardinal);
115 }
116
117 int wxMessageDialog::ShowModal()
118 {
119 const long style = GetMessageDialogStyle();
120
121 DialogCreateFunction dialogCreateFunction;
122 if ( style & wxYES_NO )
123 {
124 // if we have [Yes], it must be a question
125 dialogCreateFunction = XmCreateQuestionDialog;
126 }
127 else if ( style & wxICON_STOP )
128 {
129 // error dialog is the one with error icon...
130 dialogCreateFunction = XmCreateErrorDialog;
131 }
132 else if ( style & wxICON_EXCLAMATION )
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
143 Widget wParent = m_parent ? GetWidget(m_parent) : (Widget) 0;
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
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
166 Display* dpy = XtDisplay(wParent);
167
168 wxComputeColours (dpy, & m_backgroundColour, (wxColour*) NULL);
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
175 wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
176
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
186
187 // do create message box
188
189 Widget wMsgBox = (*dialogCreateFunction)(wParent, wxMOTIF_STR(""), args, ac);
190
191 wxCHECK_MSG( wMsgBox, wxID_CANCEL, "msg box creation failed" );
192
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);
199
200 if ( style & wxYES_NO )
201 {
202 wxXmString yes(_("Yes")), no(_("No")), cancel(_("Cancel"));
203
204 if ( style & wxCANCEL )
205 {
206 // use the cancel button for No and the help button for
207 // Cancel Yuk :-) MB
208 //
209 XtVaSetValues(wBtnOk, XmNlabelString, yes(), NULL);
210 XtVaSetValues(wBtnCancel, XmNlabelString, no(), NULL);
211 XtVaSetValues(wBtnHelp, XmNlabelString, cancel(), NULL);
212 }
213 else
214 {
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);
220 }
221 }
222 else
223 {
224 // remove the help button and the cancel button (unless it was
225 // requested)
226 //
227 XtUnmanageChild(wBtnHelp);
228 if ( !(style & wxCANCEL ) ) XtUnmanageChild(wBtnCancel);
229 }
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);
236 XtAddCallback(wMsgBox, XmNhelpCallback,
237 (XtCallbackProc)msgboxCallBackHelp, (XtPointer)this);
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
258 if ( style & wxYES_NO )
259 {
260 if ( m_result == wxID_OK )
261 m_result = wxID_YES;
262 else if ( m_result == wxID_CANCEL )
263 m_result = wxID_NO;
264 else if ( m_result == wxID_HELP )
265 m_result = wxID_CANCEL;
266 }
267
268 return m_result;
269 }