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