]> git.saurik.com Git - wxWidgets.git/blob - src/motif/msgdlg.cpp
wxHtmlFilterHTML adds fake <meta> tag so that the parser knows charset
[wxWidgets.git] / src / motif / msgdlg.cpp
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 #pragma message disable nosimpint
26 #endif
27 #include <X11/Xlib.h>
28
29 #include <Xm/Xm.h>
30 #include <Xm/MessageB.h>
31 #ifdef __VMS
32 #pragma message enable nosimpint
33 #endif
34
35 #include "wx/app.h"
36 #include "wx/intl.h"
37 #include "wx/motif/msgdlg.h"
38 #include "wx/motif/private.h"
39
40 // ----------------------------------------------------------------------------
41 // macros
42 // ----------------------------------------------------------------------------
43
44 IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
45
46 // ============================================================================
47 // implementation
48 // ============================================================================
49
50 // ----------------------------------------------------------------------------
51 // the callbacks for message box buttons
52 // ----------------------------------------------------------------------------
53
54 // the common part
55 static void msgboxCallBack(Widget w, void* client_data, int id)
56 {
57 // close the dialog
58 XtUnmanageChild(w);
59
60 wxMessageDialog *dlg = (wxMessageDialog *)client_data;
61 dlg->SetResult(id);
62 }
63
64 static void msgboxCallBackOk(Widget w,
65 void* client_data,
66 XmAnyCallbackStruct *WXUNUSED(call_data))
67 {
68 msgboxCallBack(w, client_data, wxID_OK);
69 }
70
71 static void msgboxCallBackCancel(Widget w,
72 void* client_data,
73 XmAnyCallbackStruct *WXUNUSED(call_data))
74 {
75 msgboxCallBack(w, client_data, wxID_CANCEL);
76 }
77
78 static void msgboxCallBackHelp(Widget w,
79 void* client_data,
80 XmAnyCallbackStruct *WXUNUSED(call_data))
81 {
82 msgboxCallBack(w, client_data, wxID_HELP);
83 }
84
85 static void msgboxCallBackClose(Widget w,
86 void* client_data,
87 XmAnyCallbackStruct *WXUNUSED(call_data))
88 {
89 msgboxCallBack(w, client_data, wxID_CANCEL);
90 }
91
92 // ----------------------------------------------------------------------------
93 // wxMessageDialog
94 // ----------------------------------------------------------------------------
95
96 wxMessageDialog::wxMessageDialog(wxWindow *parent,
97 const wxString& message,
98 const wxString& caption,
99 long style,
100 const wxPoint& WXUNUSED(pos))
101 {
102 m_caption = caption;
103 m_message = message;
104 m_dialogStyle = style;
105 m_parent = parent;
106 }
107
108 int wxMessageDialog::ShowModal()
109 {
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;
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
132 Widget wParent = m_parent ? GetWidget(m_parent) : (Widget) 0;
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
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
165 Widget wMsgBox = (*dialogCreateFunction)(wParent, "", args, ac);
166
167 wxCHECK_MSG( wMsgBox, wxID_CANCEL, "msg box creation failed" );
168
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);
175
176 if ( m_dialogStyle & wxYES_NO )
177 {
178 wxXmString yes(_("Yes")), no(_("No")), cancel(_("Cancel"));
179
180 if ( m_dialogStyle & wxCANCEL )
181 {
182 // use the cancel button for No and the help button for
183 // Cancel Yuk :-) MB
184 //
185 XtVaSetValues(wBtnOk, XmNlabelString, yes(), NULL);
186 XtVaSetValues(wBtnCancel, XmNlabelString, no(), NULL);
187 XtVaSetValues(wBtnHelp, XmNlabelString, cancel(), NULL);
188 }
189 else
190 {
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);
196 }
197 }
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 }
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);
212 XtAddCallback(wMsgBox, XmNhelpCallback,
213 (XtCallbackProc)msgboxCallBackHelp, (XtPointer)this);
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;
240 else if ( m_result == wxID_HELP )
241 m_result = wxID_CANCEL;
242 }
243
244 return m_result;
245 }
246