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