]>
Commit | Line | Data |
---|---|---|
13a7abf9 | 1 | ///////////////////////////////////////////////////////////////////////////// |
e5b50758 | 2 | // Name: src/gtk/msgdlg.cpp |
13a7abf9 VS |
3 | // Purpose: wxMessageDialog for GTK+2 |
4 | // Author: Vaclav Slavik | |
5 | // Modified by: | |
6 | // Created: 2003/02/28 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Vaclav Slavik, 2003 | |
e5b50758 | 9 | // Licence: wxWindows licence |
13a7abf9 VS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
13a7abf9 VS |
12 | // For compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
14 | ||
15 | #ifdef __BORLANDC__ | |
88a7a4e1 | 16 | #pragma hdrstop |
13a7abf9 VS |
17 | #endif |
18 | ||
ff654490 | 19 | #if wxUSE_MSGDLG && !defined(__WXGPE__) |
13a7abf9 | 20 | |
e1bf3ad3 | 21 | #include "wx/msgdlg.h" |
88a7a4e1 WS |
22 | |
23 | #ifndef WX_PRECOMP | |
24 | #include "wx/intl.h" | |
25 | #endif | |
26 | ||
9dc44eff | 27 | #include <gtk/gtk.h> |
13a7abf9 | 28 | #include "wx/gtk/private.h" |
ce668f29 | 29 | #include "wx/gtk/private/messagetype.h" |
92763588 | 30 | #include "wx/gtk/private/mnemonics.h" |
13a7abf9 | 31 | |
c96d7bec VZ |
32 | #if wxUSE_LIBHILDON |
33 | #include <hildon-widgets/hildon-note.h> | |
34 | #endif // wxUSE_LIBHILDON | |
35 | ||
426d19f1 JS |
36 | #if wxUSE_LIBHILDON2 |
37 | #include <hildon/hildon.h> | |
38 | #endif // wxUSE_LIBHILDON2 | |
39 | ||
13a7abf9 VS |
40 | IMPLEMENT_CLASS(wxMessageDialog, wxDialog) |
41 | ||
42 | wxMessageDialog::wxMessageDialog(wxWindow *parent, | |
43 | const wxString& message, | |
44 | const wxString& caption, | |
45 | long style, | |
46 | const wxPoint& WXUNUSED(pos)) | |
ede7b017 | 47 | : wxMessageDialogBase |
cdc48273 VZ |
48 | ( |
49 | GetParentForModalDialog(parent, style), | |
50 | message, | |
51 | caption, | |
52 | style | |
53 | ) | |
13a7abf9 | 54 | { |
2afb9e16 | 55 | } |
13a7abf9 | 56 | |
92763588 VZ |
57 | wxString wxMessageDialog::GetDefaultYesLabel() const |
58 | { | |
59 | return GTK_STOCK_YES; | |
60 | } | |
61 | ||
62 | wxString wxMessageDialog::GetDefaultNoLabel() const | |
63 | { | |
64 | return GTK_STOCK_NO; | |
65 | } | |
66 | ||
67 | wxString wxMessageDialog::GetDefaultOKLabel() const | |
68 | { | |
69 | return GTK_STOCK_OK; | |
70 | } | |
71 | ||
72 | wxString wxMessageDialog::GetDefaultCancelLabel() const | |
73 | { | |
74 | return GTK_STOCK_CANCEL; | |
75 | } | |
76 | ||
7112cdd1 VZ |
77 | wxString wxMessageDialog::GetDefaultHelpLabel() const |
78 | { | |
79 | return GTK_STOCK_HELP; | |
80 | } | |
81 | ||
e08931c0 | 82 | void wxMessageDialog::DoSetCustomLabel(wxString& var, const ButtonLabel& label) |
92763588 | 83 | { |
e08931c0 VZ |
84 | int stockId = label.GetStockId(); |
85 | if ( stockId == wxID_NONE ) | |
86 | { | |
ede7b017 | 87 | wxMessageDialogBase::DoSetCustomLabel(var, label); |
e08931c0 VZ |
88 | var = wxConvertMnemonicsToGTK(var); |
89 | } | |
90 | else // stock label | |
91 | { | |
92 | var = wxGetStockGtkID(stockId); | |
93 | } | |
92763588 VZ |
94 | } |
95 | ||
2afb9e16 VZ |
96 | void wxMessageDialog::GTKCreateMsgDialog() |
97 | { | |
c96d7bec VZ |
98 | GtkWindow * const parent = m_parent ? GTK_WINDOW(m_parent->m_widget) : NULL; |
99 | ||
426d19f1 | 100 | #if wxUSE_LIBHILDON || wxUSE_LIBHILDON2 |
a4578b0c VZ |
101 | const char *stockIcon = ""; |
102 | ||
103 | switch ( GetEffectiveIcon() ) | |
104 | { | |
105 | case wxICON_ERROR: | |
106 | stockIcon = "qgn_note_gene_syserror"; | |
107 | break; | |
108 | ||
109 | case wxICON_WARNING: | |
110 | stockIcon = "qgn_note_gene_syswarning"; | |
111 | break; | |
112 | ||
113 | case wxICON_QUESTION: | |
114 | stockIcon = "qgn_note_confirm"; | |
115 | break; | |
116 | ||
117 | case wxICON_INFORMATION: | |
118 | stockIcon = "qgn_note_info"; | |
119 | break; | |
120 | } | |
c96d7bec VZ |
121 | |
122 | // there is no generic note creation function in public API so we have no | |
123 | // choice but to use g_object_new() directly | |
124 | m_widget = (GtkWidget *)g_object_new | |
125 | ( | |
126 | HILDON_TYPE_NOTE, | |
426d19f1 | 127 | #if wxUSE_LIBHILDON |
c96d7bec | 128 | "note_type", HILDON_NOTE_CONFIRMATION_BUTTON_TYPE, |
426d19f1 JS |
129 | #else // wxUSE_LIBHILDON |
130 | "note_type", HILDON_NOTE_TYPE_CONFIRMATION_BUTTON, | |
131 | #endif // wxUSE_LIBHILDON /wxUSE_LIBHILDON2 | |
c96d7bec VZ |
132 | "description", (const char *)GetFullMessage().utf8_str(), |
133 | "icon", stockIcon, | |
134 | NULL | |
135 | ); | |
426d19f1 | 136 | #else // !wxUSE_LIBHILDON && !wxUSE_LIBHILDON2 |
b63b07a8 | 137 | GtkMessageType type = GTK_MESSAGE_ERROR; |
92763588 | 138 | GtkButtonsType buttons = GTK_BUTTONS_NONE; |
13a7abf9 | 139 | |
92763588 VZ |
140 | // when using custom labels, we have to add all the buttons ourselves |
141 | if ( !HasCustomLabels() ) | |
13a7abf9 | 142 | { |
7112cdd1 VZ |
143 | // "Help" button is not supported by predefined combinations so we |
144 | // always need to create the buttons manually when it's used. | |
145 | if ( !(m_dialogStyle & wxHELP) ) | |
92763588 | 146 | { |
7112cdd1 VZ |
147 | if ( m_dialogStyle & wxYES_NO ) |
148 | { | |
149 | if ( !(m_dialogStyle & wxCANCEL) ) | |
150 | buttons = GTK_BUTTONS_YES_NO; | |
151 | //else: no standard GTK_BUTTONS_YES_NO_CANCEL so leave as NONE | |
152 | } | |
153 | else if ( m_dialogStyle & wxOK ) | |
154 | { | |
155 | buttons = m_dialogStyle & wxCANCEL ? GTK_BUTTONS_OK_CANCEL | |
156 | : GTK_BUTTONS_OK; | |
157 | } | |
92763588 | 158 | } |
13a7abf9 | 159 | } |
b63b07a8 | 160 | |
a4578b0c | 161 | if ( !wxGTKImpl::ConvertMessageTypeFromWX(GetEffectiveIcon(), &type) ) |
e0ae1a0a | 162 | { |
7e3204b4 VZ |
163 | // if no style is explicitly specified, detect the suitable icon |
164 | // ourselves (this can be disabled by using wxICON_NONE) | |
2afb9e16 | 165 | type = m_dialogStyle & wxYES ? GTK_MESSAGE_QUESTION : GTK_MESSAGE_INFO; |
e0ae1a0a | 166 | } |
13a7abf9 | 167 | |
2afb9e16 | 168 | wxString message; |
ff9bb105 | 169 | #if GTK_CHECK_VERSION(2, 6, 0) |
2afb9e16 | 170 | bool needsExtMessage = false; |
9dc44eff PC |
171 | if (!m_extendedMessage.empty() |
172 | #ifndef __WXGTK3__ | |
173 | && gtk_check_version(2, 6, 0) == NULL | |
174 | #endif | |
175 | ) | |
2afb9e16 VZ |
176 | { |
177 | message = m_message; | |
178 | needsExtMessage = true; | |
179 | } | |
180 | else // extended message not needed or not supported | |
c96d7bec | 181 | #endif // GTK+ 2.6+ |
2afb9e16 VZ |
182 | { |
183 | message = GetFullMessage(); | |
184 | } | |
185 | ||
c96d7bec | 186 | m_widget = gtk_message_dialog_new(parent, |
b2ce5e1b | 187 | GTK_DIALOG_MODAL, |
2afb9e16 VZ |
188 | type, |
189 | buttons, | |
190 | "%s", | |
191 | (const char*)wxGTK_CONV(message)); | |
192 | ||
ff9bb105 | 193 | #if GTK_CHECK_VERSION(2, 6, 0) |
2afb9e16 VZ |
194 | if ( needsExtMessage ) |
195 | { | |
196 | gtk_message_dialog_format_secondary_text | |
197 | ( | |
198 | (GtkMessageDialog *)m_widget, | |
199 | "%s", | |
200 | (const char *)wxGTK_CONV(m_extendedMessage) | |
201 | ); | |
202 | } | |
c96d7bec | 203 | #endif // GTK+ 2.6+ |
426d19f1 | 204 | #endif // wxUSE_LIBHILDON || wxUSE_LIBHILDON2/!wxUSE_LIBHILDON && !wxUSE_LIBHILDON2 |
2afb9e16 | 205 | |
9ff9d30c PC |
206 | g_object_ref(m_widget); |
207 | ||
13a7abf9 | 208 | if (m_caption != wxMessageBoxCaptionStr) |
b2ce5e1b | 209 | gtk_window_set_title(GTK_WINDOW(m_widget), wxGTK_CONV(m_caption)); |
13a7abf9 | 210 | |
c96d7bec | 211 | GtkDialog * const dlg = GTK_DIALOG(m_widget); |
92763588 | 212 | |
4566dcbe VZ |
213 | if ( m_dialogStyle & wxSTAY_ON_TOP ) |
214 | { | |
215 | gtk_window_set_keep_above(GTK_WINDOW(m_widget), TRUE); | |
216 | } | |
217 | ||
92763588 VZ |
218 | // we need to add buttons manually if we use custom labels or always for |
219 | // Yes/No/Cancel dialog as GTK+ doesn't support it natively and when using | |
220 | // Hildon we add all the buttons manually as it doesn't support too many of | |
221 | // the combinations we may have | |
426d19f1 | 222 | #if wxUSE_LIBHILDON || wxUSE_LIBHILDON2 |
92763588 VZ |
223 | static const bool addButtons = true; |
224 | #else // !wxUSE_LIBHILDON | |
225 | const bool addButtons = buttons == GTK_BUTTONS_NONE; | |
226 | #endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON | |
227 | ||
7112cdd1 VZ |
228 | |
229 | if ( addButtons ) | |
92763588 | 230 | { |
7112cdd1 VZ |
231 | if ( m_dialogStyle & wxHELP ) |
232 | { | |
233 | gtk_dialog_add_button(dlg, wxGTK_CONV(GetHelpLabel()), | |
234 | GTK_RESPONSE_HELP); | |
235 | } | |
236 | ||
237 | if ( m_dialogStyle & wxYES_NO ) // Yes/No or Yes/No/Cancel dialog | |
c96d7bec | 238 | { |
5d3056f1 VZ |
239 | // Add the buttons in the correct order which is, according to |
240 | // http://library.gnome.org/devel/hig-book/stable/windows-alert.html.en | |
241 | // the following one: | |
242 | // | |
243 | // [Help] [Alternative] [Cancel] [Affirmative] | |
244 | ||
150c8eb9 VZ |
245 | gtk_dialog_add_button(dlg, wxGTK_CONV(GetNoLabel()), |
246 | GTK_RESPONSE_NO); | |
92763588 VZ |
247 | |
248 | if ( m_dialogStyle & wxCANCEL ) | |
249 | { | |
150c8eb9 | 250 | gtk_dialog_add_button(dlg, wxGTK_CONV(GetCancelLabel()), |
92763588 VZ |
251 | GTK_RESPONSE_CANCEL); |
252 | } | |
5d3056f1 VZ |
253 | |
254 | gtk_dialog_add_button(dlg, wxGTK_CONV(GetYesLabel()), | |
255 | GTK_RESPONSE_YES); | |
c96d7bec | 256 | } |
7112cdd1 | 257 | else // Ok or Ok/Cancel dialog |
150c8eb9 | 258 | { |
7112cdd1 VZ |
259 | gtk_dialog_add_button(dlg, wxGTK_CONV(GetOKLabel()), GTK_RESPONSE_OK); |
260 | if ( m_dialogStyle & wxCANCEL ) | |
261 | { | |
262 | gtk_dialog_add_button(dlg, wxGTK_CONV(GetCancelLabel()), | |
263 | GTK_RESPONSE_CANCEL); | |
264 | } | |
150c8eb9 | 265 | } |
13a7abf9 | 266 | } |
24689293 | 267 | |
7112cdd1 | 268 | gint defaultButton; |
24689293 | 269 | if ( m_dialogStyle & wxCANCEL_DEFAULT ) |
7112cdd1 VZ |
270 | defaultButton = GTK_RESPONSE_CANCEL; |
271 | else if ( m_dialogStyle & wxNO_DEFAULT ) | |
272 | defaultButton = GTK_RESPONSE_NO; | |
273 | else if ( m_dialogStyle & wxYES_NO ) | |
274 | defaultButton = GTK_RESPONSE_YES; | |
275 | else // No need to change the default value, whatever it is. | |
276 | defaultButton = GTK_RESPONSE_NONE; | |
277 | ||
278 | if ( defaultButton != GTK_RESPONSE_NONE ) | |
279 | gtk_dialog_set_default_response(dlg, defaultButton); | |
b2ce5e1b | 280 | } |
e5b50758 | 281 | |
b2ce5e1b RD |
282 | int wxMessageDialog::ShowModal() |
283 | { | |
7738af59 VZ |
284 | // break the mouse capture as it would interfere with modal dialog (see |
285 | // wxDialog::ShowModal) | |
286 | wxWindow * const win = wxWindow::GetCapture(); | |
287 | if ( win ) | |
288 | win->GTKReleaseMouseAndNotify(); | |
289 | ||
2afb9e16 VZ |
290 | if ( !m_widget ) |
291 | { | |
292 | GTKCreateMsgDialog(); | |
293 | wxCHECK_MSG( m_widget, wxID_CANCEL, | |
9a83f860 | 294 | wxT("failed to create GtkMessageDialog") ); |
2afb9e16 VZ |
295 | } |
296 | ||
3b439e60 RR |
297 | // This should be necessary, but otherwise the |
298 | // parent TLW will disappear.. | |
299 | if (m_parent) | |
300 | gtk_window_present( GTK_WINDOW(m_parent->m_widget) ); | |
e5b50758 | 301 | |
b2ce5e1b RD |
302 | gint result = gtk_dialog_run(GTK_DIALOG(m_widget)); |
303 | gtk_widget_destroy(m_widget); | |
9ff9d30c | 304 | g_object_unref(m_widget); |
b2ce5e1b | 305 | m_widget = NULL; |
13a7abf9 VS |
306 | |
307 | switch (result) | |
308 | { | |
309 | default: | |
9a83f860 | 310 | wxFAIL_MSG(wxT("unexpected GtkMessageDialog return code")); |
13a7abf9 VS |
311 | // fall through |
312 | ||
b63b07a8 | 313 | case GTK_RESPONSE_CANCEL: |
0e4a7045 VS |
314 | case GTK_RESPONSE_DELETE_EVENT: |
315 | case GTK_RESPONSE_CLOSE: | |
13a7abf9 VS |
316 | return wxID_CANCEL; |
317 | case GTK_RESPONSE_OK: | |
318 | return wxID_OK; | |
319 | case GTK_RESPONSE_YES: | |
320 | return wxID_YES; | |
321 | case GTK_RESPONSE_NO: | |
322 | return wxID_NO; | |
7112cdd1 VZ |
323 | case GTK_RESPONSE_HELP: |
324 | return wxID_HELP; | |
13a7abf9 VS |
325 | } |
326 | } | |
327 | ||
b2ce5e1b | 328 | |
ff654490 | 329 | #endif // wxUSE_MSGDLG && !defined(__WXGPE__) |