]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/motif/msgdlg.cpp
Made wxContextHelp implementation generic and added wxFindWindowAtPointer,
[wxWidgets.git] / src / motif / msgdlg.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: msgdlg.cpp
3// Purpose: wxMessageDialog
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $$
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16#ifdef __GNUG__
17 #pragma implementation "msgdlg.h"
18#endif
19
20// ----------------------------------------------------------------------------
21// headers
22// ----------------------------------------------------------------------------
23
24#ifdef __VMS
25#define XtDisplay XTDISPLAY
26#pragma message disable nosimpint
27#include <wx/vms_x_fix.h>
28#endif
29#include <X11/Xlib.h>
30
31#include <Xm/Xm.h>
32#include <Xm/MessageB.h>
33#ifdef __VMS
34#pragma message enable nosimpint
35#endif
36
37#include "wx/app.h"
38#include "wx/intl.h"
39#include "wx/motif/msgdlg.h"
40#include "wx/motif/private.h"
41
42// ----------------------------------------------------------------------------
43// macros
44// ----------------------------------------------------------------------------
45
46 IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
47
48// ============================================================================
49// implementation
50// ============================================================================
51
52// ----------------------------------------------------------------------------
53// the callbacks for message box buttons
54// ----------------------------------------------------------------------------
55
56// the common part
57static void msgboxCallBack(Widget w, void* client_data, int id)
58{
59 // close the dialog
60 XtUnmanageChild(w);
61
62 wxMessageDialog *dlg = (wxMessageDialog *)client_data;
63 dlg->SetResult(id);
64}
65
66static void msgboxCallBackOk(Widget w,
67 void* client_data,
68 XmAnyCallbackStruct *WXUNUSED(call_data))
69{
70 msgboxCallBack(w, client_data, wxID_OK);
71}
72
73static void msgboxCallBackCancel(Widget w,
74 void* client_data,
75 XmAnyCallbackStruct *WXUNUSED(call_data))
76{
77 msgboxCallBack(w, client_data, wxID_CANCEL);
78}
79
80static void msgboxCallBackHelp(Widget w,
81 void* client_data,
82 XmAnyCallbackStruct *WXUNUSED(call_data))
83{
84 msgboxCallBack(w, client_data, wxID_HELP);
85}
86
87static void msgboxCallBackClose(Widget w,
88 void* client_data,
89 XmAnyCallbackStruct *WXUNUSED(call_data))
90{
91 msgboxCallBack(w, client_data, wxID_CANCEL);
92}
93
94// ----------------------------------------------------------------------------
95// wxMessageDialog
96// ----------------------------------------------------------------------------
97
98wxMessageDialog::wxMessageDialog(wxWindow *parent,
99 const wxString& message,
100 const wxString& caption,
101 long style,
102 const wxPoint& WXUNUSED(pos))
103{
104 m_caption = caption;
105 m_message = message;
106 m_dialogStyle = style;
107 m_parent = parent;
108}
109
110int wxMessageDialog::ShowModal()
111{
112 Widget (*dialogCreateFunction)(Widget, String, ArgList, Cardinal) = NULL;
113 if ( m_dialogStyle & wxYES_NO )
114 {
115 // if we have [Yes], it must be a question
116 dialogCreateFunction = XmCreateQuestionDialog;
117 }
118 else if ( m_dialogStyle & wxICON_STOP )
119 {
120 // error dialog is the one with error icon...
121 dialogCreateFunction = XmCreateErrorDialog;
122 }
123 else if ( m_dialogStyle & wxICON_EXCLAMATION )
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
134 Widget wParent = m_parent ? GetWidget(m_parent) : (Widget) 0;
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
148 // prepare the arg list
149 Arg args[10];
150 int ac = 0;
151
152 wxXmString text(m_message);
153 wxXmString title(m_caption);
154 XtSetArg(args[ac], XmNmessageString, text()); ac++;
155 XtSetArg(args[ac], XmNdialogTitle, title()); ac++;
156
157 wxComputeColours (XtDisplay(wParent), & m_backgroundColour,
158 (wxColour*) NULL);
159
160 XtSetArg(args[ac], XmNbackground, g_itemColors[wxBACK_INDEX].pixel); ac++;
161 XtSetArg(args[ac], XmNtopShadowColor, g_itemColors[wxTOPS_INDEX].pixel); ac++;
162 XtSetArg(args[ac], XmNbottomShadowColor, g_itemColors[wxBOTS_INDEX].pixel); ac++;
163 XtSetArg(args[ac], XmNforeground, g_itemColors[wxFORE_INDEX].pixel); ac++;
164
165 // do create message box
166
167 Widget wMsgBox = (*dialogCreateFunction)(wParent, "", args, ac);
168
169 wxCHECK_MSG( wMsgBox, wxID_CANCEL, "msg box creation failed" );
170
171 // get the buttons which we might either remove or rename
172 // depending on the requested style
173 //
174 Widget wBtnOk = XmMessageBoxGetChild(wMsgBox, XmDIALOG_OK_BUTTON);
175 Widget wBtnHelp = XmMessageBoxGetChild(wMsgBox, XmDIALOG_HELP_BUTTON);
176 Widget wBtnCancel = XmMessageBoxGetChild(wMsgBox, XmDIALOG_CANCEL_BUTTON);
177
178 if ( m_dialogStyle & wxYES_NO )
179 {
180 wxXmString yes(_("Yes")), no(_("No")), cancel(_("Cancel"));
181
182 if ( m_dialogStyle & wxCANCEL )
183 {
184 // use the cancel button for No and the help button for
185 // Cancel Yuk :-) MB
186 //
187 XtVaSetValues(wBtnOk, XmNlabelString, yes(), NULL);
188 XtVaSetValues(wBtnCancel, XmNlabelString, no(), NULL);
189 XtVaSetValues(wBtnHelp, XmNlabelString, cancel(), NULL);
190 }
191 else
192 {
193 // no cancel button requested...
194 // remove the help button and use cancel for no
195 //
196 XtVaSetValues(wBtnCancel, XmNlabelString, no(), NULL);
197 XtUnmanageChild(wBtnHelp);
198 }
199 }
200 else
201 {
202 // remove the help button and the cancel button (unless it was
203 // requested)
204 //
205 XtUnmanageChild(wBtnHelp);
206 if ( !(m_dialogStyle & wxCANCEL ) ) XtUnmanageChild(wBtnCancel);
207 }
208
209 // set the callbacks for the message box buttons
210 XtAddCallback(wMsgBox, XmNokCallback,
211 (XtCallbackProc)msgboxCallBackOk, (XtPointer)this);
212 XtAddCallback(wMsgBox, XmNcancelCallback,
213 (XtCallbackProc)msgboxCallBackCancel, (XtPointer)this);
214 XtAddCallback(wMsgBox, XmNhelpCallback,
215 (XtCallbackProc)msgboxCallBackHelp, (XtPointer)this);
216 XtAddCallback(wMsgBox, XmNunmapCallback,
217 (XtCallbackProc)msgboxCallBackClose, (XtPointer)this);
218
219 // show it as a modal dialog
220 XtManageChild(wMsgBox);
221 XtAddGrab(wMsgBox, True, False);
222
223 // the m_result will be changed when message box goes away
224 m_result = -1;
225
226 // local message loop
227 XtAppContext context = XtWidgetToApplicationContext(wParent);
228 XEvent event;
229 while ( m_result == -1 )
230 {
231 XtAppNextEvent(context, &event);
232 XtDispatchEvent(&event);
233 }
234
235 // translate the result if necessary
236 if ( m_dialogStyle & wxYES_NO )
237 {
238 if ( m_result == wxID_OK )
239 m_result = wxID_YES;
240 else if ( m_result == wxID_CANCEL )
241 m_result = wxID_NO;
242 else if ( m_result == wxID_HELP )
243 m_result = wxID_CANCEL;
244 }
245
246 return m_result;
247}
248