]>
Commit | Line | Data |
---|---|---|
4bb6408c | 1 | ///////////////////////////////////////////////////////////////////////////// |
e5b50758 | 2 | // Name: src/motif/msgdlg.cpp |
4bb6408c JS |
3 | // Purpose: wxMessageDialog |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
e5b50758 | 7 | // RCS-ID: $Id$ |
4bb6408c | 8 | // Copyright: (c) Julian Smart |
65571936 | 9 | // Licence: wxWindows licence |
4bb6408c JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
ee31c392 VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
ee31c392 VZ |
16 | // ---------------------------------------------------------------------------- |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
1248b41f MB |
20 | // For compilers that support precompilation, includes "wx.h". |
21 | #include "wx/wxprec.h" | |
22 | ||
338dd992 JJ |
23 | #ifdef __VMS |
24 | #pragma message disable nosimpint | |
7ec69821 | 25 | #include "wx/vms_x_fix.h" |
338dd992 | 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 | 34 | |
eaa6f9ad | 35 | #include "wx/msgdlg.h" |
88a7a4e1 WS |
36 | |
37 | #ifndef WX_PRECOMP | |
38 | #include "wx/intl.h" | |
670f9935 | 39 | #include "wx/app.h" |
9eddec69 | 40 | #include "wx/settings.h" |
88a7a4e1 WS |
41 | #endif |
42 | ||
691745ab | 43 | #include "wx/modalhook.h" |
ee31c392 VZ |
44 | #include "wx/motif/private.h" |
45 | ||
46 | // ---------------------------------------------------------------------------- | |
47 | // macros | |
48 | // ---------------------------------------------------------------------------- | |
4bb6408c | 49 | |
ee31c392 | 50 | IMPLEMENT_CLASS(wxMessageDialog, wxDialog) |
4bb6408c | 51 | |
ee31c392 VZ |
52 | // ============================================================================ |
53 | // implementation | |
54 | // ============================================================================ | |
55 | ||
56 | // ---------------------------------------------------------------------------- | |
57 | // the callbacks for message box buttons | |
58 | // ---------------------------------------------------------------------------- | |
59 | ||
60 | // the common part | |
ccebc98a | 61 | static void msgboxCallBack(Widget w, void* client_data, int id) |
ee31c392 VZ |
62 | { |
63 | // close the dialog | |
64 | XtUnmanageChild(w); | |
65 | ||
66 | wxMessageDialog *dlg = (wxMessageDialog *)client_data; | |
67 | dlg->SetResult(id); | |
68 | } | |
69 | ||
70 | static void msgboxCallBackOk(Widget w, | |
ccebc98a | 71 | void* client_data, |
af111fc3 | 72 | XmAnyCallbackStruct *WXUNUSED(call_data)) |
ee31c392 VZ |
73 | { |
74 | msgboxCallBack(w, client_data, wxID_OK); | |
75 | } | |
76 | ||
77 | static void msgboxCallBackCancel(Widget w, | |
ccebc98a | 78 | void* client_data, |
af111fc3 | 79 | XmAnyCallbackStruct *WXUNUSED(call_data)) |
ee31c392 VZ |
80 | { |
81 | msgboxCallBack(w, client_data, wxID_CANCEL); | |
82 | } | |
83 | ||
11d737b4 | 84 | static void msgboxCallBackHelp(Widget w, |
ccebc98a | 85 | void* client_data, |
af111fc3 | 86 | XmAnyCallbackStruct *WXUNUSED(call_data)) |
11d737b4 MB |
87 | { |
88 | msgboxCallBack(w, client_data, wxID_HELP); | |
89 | } | |
90 | ||
ee31c392 | 91 | static void msgboxCallBackClose(Widget w, |
ccebc98a | 92 | void* client_data, |
af111fc3 | 93 | XmAnyCallbackStruct *WXUNUSED(call_data)) |
ee31c392 VZ |
94 | { |
95 | msgboxCallBack(w, client_data, wxID_CANCEL); | |
96 | } | |
97 | ||
98 | // ---------------------------------------------------------------------------- | |
99 | // wxMessageDialog | |
100 | // ---------------------------------------------------------------------------- | |
101 | ||
ed05b5c6 VZ |
102 | extern "C" |
103 | { | |
104 | typedef Widget (*DialogCreateFunction)(Widget, String, ArgList, Cardinal); | |
105 | } | |
106 | ||
4bb6408c JS |
107 | int wxMessageDialog::ShowModal() |
108 | { | |
691745ab | 109 | WX_HOOK_MODAL_DIALOG(); |
643e9cf9 | 110 | |
e5b50758 WS |
111 | const long style = GetMessageDialogStyle(); |
112 | ||
ed05b5c6 | 113 | DialogCreateFunction dialogCreateFunction; |
e5b50758 | 114 | if ( style & wxYES_NO ) |
ee31c392 VZ |
115 | { |
116 | // if we have [Yes], it must be a question | |
117 | dialogCreateFunction = XmCreateQuestionDialog; | |
ee31c392 | 118 | } |
e5b50758 | 119 | else if ( style & wxICON_STOP ) |
ee31c392 VZ |
120 | { |
121 | // error dialog is the one with error icon... | |
122 | dialogCreateFunction = XmCreateErrorDialog; | |
123 | } | |
e5b50758 | 124 | else if ( style & wxICON_EXCLAMATION ) |
ee31c392 VZ |
125 | { |
126 | // ...and the warning dialog too | |
127 | dialogCreateFunction = XmCreateWarningDialog; | |
128 | } | |
129 | else | |
130 | { | |
131 | // finally, use the info dialog by default | |
132 | dialogCreateFunction = XmCreateInformationDialog; | |
133 | } | |
134 | ||
af111fc3 | 135 | Widget wParent = m_parent ? GetWidget(m_parent) : (Widget) 0; |
ee31c392 VZ |
136 | if ( !wParent ) |
137 | { | |
138 | wxWindow *window = wxTheApp->GetTopWindow(); | |
139 | if ( !window ) | |
140 | { | |
141 | wxFAIL_MSG("can't show message box without parent window"); | |
142 | ||
143 | return wxID_CANCEL; | |
144 | } | |
145 | ||
146 | wParent = GetWidget(window); | |
147 | } | |
148 | ||
ee1aaf99 JS |
149 | // prepare the arg list |
150 | Arg args[10]; | |
151 | int ac = 0; | |
152 | ||
2afb9e16 | 153 | wxXmString text(GetFullMessage()); |
ee1aaf99 JS |
154 | wxXmString title(m_caption); |
155 | XtSetArg(args[ac], XmNmessageString, text()); ac++; | |
156 | XtSetArg(args[ac], XmNdialogTitle, title()); ac++; | |
157 | ||
6ace5176 MB |
158 | Display* dpy = XtDisplay(wParent); |
159 | ||
a1b806b9 | 160 | if (m_backgroundColour.IsOk()) |
105fbe1f | 161 | { |
d3b9f782 | 162 | wxComputeColours (dpy, & m_backgroundColour, NULL); |
ee1aaf99 | 163 | |
105fbe1f MB |
164 | XtSetArg(args[ac], XmNbackground, g_itemColors[wxBACK_INDEX].pixel); ac++; |
165 | XtSetArg(args[ac], XmNtopShadowColor, g_itemColors[wxTOPS_INDEX].pixel); ac++; | |
166 | XtSetArg(args[ac], XmNbottomShadowColor, g_itemColors[wxBOTS_INDEX].pixel); ac++; | |
167 | XtSetArg(args[ac], XmNforeground, g_itemColors[wxFORE_INDEX].pixel); ac++; | |
168 | } | |
ee1aaf99 | 169 | |
6ace5176 MB |
170 | wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); |
171 | ||
7398fb81 MB |
172 | #if __WXMOTIF20__ && !__WXLESSTIF__ |
173 | XtSetArg(args[ac], XmNbuttonRenderTable, font.GetFontTypeC(dpy)); ac++; | |
174 | XtSetArg(args[ac], XmNlabelRenderTable, font.GetFontTypeC(dpy)); ac++; | |
175 | XtSetArg(args[ac], XmNtextRenderTable, font.GetFontTypeC(dpy)); ac++; | |
176 | #else | |
177 | XtSetArg(args[ac], XmNbuttonFontList, font.GetFontTypeC(dpy)); ac++; | |
178 | XtSetArg(args[ac], XmNlabelFontList, font.GetFontTypeC(dpy)); ac++; | |
179 | XtSetArg(args[ac], XmNtextFontList, font.GetFontTypeC(dpy)); ac++; | |
180 | #endif | |
6ace5176 | 181 | |
ee1aaf99 JS |
182 | // do create message box |
183 | ||
da8cf723 | 184 | Widget wMsgBox = (*dialogCreateFunction)(wParent, wxMOTIF_STR(""), args, ac); |
ee31c392 VZ |
185 | |
186 | wxCHECK_MSG( wMsgBox, wxID_CANCEL, "msg box creation failed" ); | |
187 | ||
11d737b4 MB |
188 | // get the buttons which we might either remove or rename |
189 | // depending on the requested style | |
190 | // | |
191 | Widget wBtnOk = XmMessageBoxGetChild(wMsgBox, XmDIALOG_OK_BUTTON); | |
192 | Widget wBtnHelp = XmMessageBoxGetChild(wMsgBox, XmDIALOG_HELP_BUTTON); | |
193 | Widget wBtnCancel = XmMessageBoxGetChild(wMsgBox, XmDIALOG_CANCEL_BUTTON); | |
ee31c392 | 194 | |
e5b50758 | 195 | if ( style & wxYES_NO ) |
ee31c392 | 196 | { |
e5b50758 | 197 | wxXmString yes(_("Yes")), no(_("No")), cancel(_("Cancel")); |
ee31c392 | 198 | |
e5b50758 | 199 | if ( style & wxCANCEL ) |
ee31c392 | 200 | { |
11d737b4 MB |
201 | // use the cancel button for No and the help button for |
202 | // Cancel Yuk :-) MB | |
203 | // | |
ee31c392 VZ |
204 | XtVaSetValues(wBtnOk, XmNlabelString, yes(), NULL); |
205 | XtVaSetValues(wBtnCancel, XmNlabelString, no(), NULL); | |
11d737b4 | 206 | XtVaSetValues(wBtnHelp, XmNlabelString, cancel(), NULL); |
ee31c392 VZ |
207 | } |
208 | else | |
209 | { | |
11d737b4 MB |
210 | // no cancel button requested... |
211 | // remove the help button and use cancel for no | |
212 | // | |
213 | XtVaSetValues(wBtnCancel, XmNlabelString, no(), NULL); | |
214 | XtUnmanageChild(wBtnHelp); | |
ee31c392 VZ |
215 | } |
216 | } | |
11d737b4 MB |
217 | else |
218 | { | |
219 | // remove the help button and the cancel button (unless it was | |
220 | // requested) | |
221 | // | |
222 | XtUnmanageChild(wBtnHelp); | |
e5b50758 | 223 | if ( !(style & wxCANCEL ) ) XtUnmanageChild(wBtnCancel); |
11d737b4 | 224 | } |
ee31c392 VZ |
225 | |
226 | // set the callbacks for the message box buttons | |
227 | XtAddCallback(wMsgBox, XmNokCallback, | |
228 | (XtCallbackProc)msgboxCallBackOk, (XtPointer)this); | |
229 | XtAddCallback(wMsgBox, XmNcancelCallback, | |
230 | (XtCallbackProc)msgboxCallBackCancel, (XtPointer)this); | |
11d737b4 MB |
231 | XtAddCallback(wMsgBox, XmNhelpCallback, |
232 | (XtCallbackProc)msgboxCallBackHelp, (XtPointer)this); | |
ee31c392 VZ |
233 | XtAddCallback(wMsgBox, XmNunmapCallback, |
234 | (XtCallbackProc)msgboxCallBackClose, (XtPointer)this); | |
235 | ||
236 | // show it as a modal dialog | |
237 | XtManageChild(wMsgBox); | |
238 | XtAddGrab(wMsgBox, True, False); | |
239 | ||
240 | // the m_result will be changed when message box goes away | |
241 | m_result = -1; | |
242 | ||
243 | // local message loop | |
244 | XtAppContext context = XtWidgetToApplicationContext(wParent); | |
245 | XEvent event; | |
246 | while ( m_result == -1 ) | |
247 | { | |
248 | XtAppNextEvent(context, &event); | |
249 | XtDispatchEvent(&event); | |
250 | } | |
251 | ||
252 | // translate the result if necessary | |
e5b50758 | 253 | if ( style & wxYES_NO ) |
ee31c392 VZ |
254 | { |
255 | if ( m_result == wxID_OK ) | |
256 | m_result = wxID_YES; | |
257 | else if ( m_result == wxID_CANCEL ) | |
258 | m_result = wxID_NO; | |
11d737b4 MB |
259 | else if ( m_result == wxID_HELP ) |
260 | m_result = wxID_CANCEL; | |
ee31c392 VZ |
261 | } |
262 | ||
263 | return m_result; | |
4bb6408c | 264 | } |