]>
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 | ||
13a7abf9 VS |
27 | #include "wx/gtk/private.h" |
28 | #include <gtk/gtk.h> | |
29 | ||
c96d7bec VZ |
30 | #if wxUSE_LIBHILDON |
31 | #include <hildon-widgets/hildon-note.h> | |
32 | #endif // wxUSE_LIBHILDON | |
33 | ||
13a7abf9 VS |
34 | IMPLEMENT_CLASS(wxMessageDialog, wxDialog) |
35 | ||
36 | wxMessageDialog::wxMessageDialog(wxWindow *parent, | |
37 | const wxString& message, | |
38 | const wxString& caption, | |
39 | long style, | |
40 | const wxPoint& WXUNUSED(pos)) | |
2afb9e16 VZ |
41 | : wxMessageDialogBase(GetParentForModalDialog(parent), |
42 | message, | |
43 | caption, | |
44 | style) | |
13a7abf9 | 45 | { |
2afb9e16 | 46 | } |
13a7abf9 | 47 | |
2afb9e16 VZ |
48 | void wxMessageDialog::GTKCreateMsgDialog() |
49 | { | |
c96d7bec VZ |
50 | GtkWindow * const parent = m_parent ? GTK_WINDOW(m_parent->m_widget) : NULL; |
51 | ||
52 | #if wxUSE_LIBHILDON | |
53 | const char *stockIcon; | |
54 | if ( m_dialogStyle & wxICON_ERROR ) | |
55 | stockIcon = "qgn_note_gene_syserror"; | |
56 | else if ( m_dialogStyle & wxICON_EXCLAMATION ) | |
57 | stockIcon = "qgn_note_gene_syswarning"; | |
58 | else if ( m_dialogStyle & wxICON_INFORMATION ) | |
59 | stockIcon = "qgn_note_info"; | |
60 | else if ( m_dialogStyle & wxICON_QUESTION ) | |
61 | stockIcon = "qgn_note_confirm"; | |
62 | else | |
63 | stockIcon = ""; | |
64 | ||
65 | // there is no generic note creation function in public API so we have no | |
66 | // choice but to use g_object_new() directly | |
67 | m_widget = (GtkWidget *)g_object_new | |
68 | ( | |
69 | HILDON_TYPE_NOTE, | |
70 | "note_type", HILDON_NOTE_CONFIRMATION_BUTTON_TYPE, | |
71 | "description", (const char *)GetFullMessage().utf8_str(), | |
72 | "icon", stockIcon, | |
73 | NULL | |
74 | ); | |
75 | #else // !wxUSE_LIBHILDON | |
b63b07a8 | 76 | GtkMessageType type = GTK_MESSAGE_ERROR; |
13a7abf9 | 77 | GtkButtonsType buttons = GTK_BUTTONS_OK; |
b63b07a8 | 78 | |
2afb9e16 | 79 | if (m_dialogStyle & wxYES_NO) |
13a7abf9 | 80 | { |
2afb9e16 | 81 | if (m_dialogStyle & wxCANCEL) |
f4322df6 VZ |
82 | buttons = GTK_BUTTONS_NONE; |
83 | else | |
84 | buttons = GTK_BUTTONS_YES_NO; | |
13a7abf9 VS |
85 | } |
86 | ||
2afb9e16 | 87 | if (m_dialogStyle & wxOK) |
13a7abf9 | 88 | { |
2afb9e16 | 89 | if (m_dialogStyle & wxCANCEL) |
13a7abf9 VS |
90 | buttons = GTK_BUTTONS_OK_CANCEL; |
91 | else | |
92 | buttons = GTK_BUTTONS_OK; | |
93 | } | |
b63b07a8 | 94 | |
2afb9e16 | 95 | if (m_dialogStyle & wxICON_EXCLAMATION) |
13a7abf9 | 96 | type = GTK_MESSAGE_WARNING; |
2afb9e16 | 97 | else if (m_dialogStyle & wxICON_ERROR) |
13a7abf9 | 98 | type = GTK_MESSAGE_ERROR; |
2afb9e16 | 99 | else if (m_dialogStyle & wxICON_INFORMATION) |
13a7abf9 | 100 | type = GTK_MESSAGE_INFO; |
2afb9e16 | 101 | else if (m_dialogStyle & wxICON_QUESTION) |
13a7abf9 | 102 | type = GTK_MESSAGE_QUESTION; |
b63b07a8 | 103 | else |
e0ae1a0a VZ |
104 | { |
105 | // GTK+ doesn't have a "typeless" msg box, so try to auto detect... | |
2afb9e16 | 106 | type = m_dialogStyle & wxYES ? GTK_MESSAGE_QUESTION : GTK_MESSAGE_INFO; |
e0ae1a0a | 107 | } |
13a7abf9 | 108 | |
2afb9e16 | 109 | wxString message; |
ff9bb105 | 110 | #if GTK_CHECK_VERSION(2, 6, 0) |
2afb9e16 | 111 | bool needsExtMessage = false; |
1878d1ec | 112 | if ( gtk_check_version(2, 6, 0) == NULL && !m_extendedMessage.empty() ) |
2afb9e16 VZ |
113 | { |
114 | message = m_message; | |
115 | needsExtMessage = true; | |
116 | } | |
117 | else // extended message not needed or not supported | |
c96d7bec | 118 | #endif // GTK+ 2.6+ |
2afb9e16 VZ |
119 | { |
120 | message = GetFullMessage(); | |
121 | } | |
122 | ||
c96d7bec | 123 | m_widget = gtk_message_dialog_new(parent, |
b2ce5e1b | 124 | GTK_DIALOG_MODAL, |
2afb9e16 VZ |
125 | type, |
126 | buttons, | |
127 | "%s", | |
128 | (const char*)wxGTK_CONV(message)); | |
129 | ||
ff9bb105 | 130 | #if GTK_CHECK_VERSION(2, 6, 0) |
2afb9e16 VZ |
131 | if ( needsExtMessage ) |
132 | { | |
133 | gtk_message_dialog_format_secondary_text | |
134 | ( | |
135 | (GtkMessageDialog *)m_widget, | |
136 | "%s", | |
137 | (const char *)wxGTK_CONV(m_extendedMessage) | |
138 | ); | |
139 | } | |
c96d7bec VZ |
140 | #endif // GTK+ 2.6+ |
141 | #endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON | |
2afb9e16 | 142 | |
13a7abf9 | 143 | if (m_caption != wxMessageBoxCaptionStr) |
b2ce5e1b | 144 | gtk_window_set_title(GTK_WINDOW(m_widget), wxGTK_CONV(m_caption)); |
13a7abf9 | 145 | |
c96d7bec VZ |
146 | // we need to add dialogs manually when using Yes/No/Cancel dialog as GTK+ |
147 | // doesn't support it natively and when using Hildon we add all the buttons | |
148 | // manually as it doesn't support too many of the combinations we have | |
149 | GtkDialog * const dlg = GTK_DIALOG(m_widget); | |
150 | if ( m_dialogStyle & wxYES_NO ) | |
13a7abf9 | 151 | { |
c96d7bec | 152 | if ( m_dialogStyle & wxCANCEL ) |
f4322df6 | 153 | { |
c96d7bec VZ |
154 | gtk_dialog_add_button(dlg, GTK_STOCK_NO, GTK_RESPONSE_NO); |
155 | gtk_dialog_add_button(dlg, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); | |
156 | gtk_dialog_add_button(dlg, GTK_STOCK_YES, GTK_RESPONSE_YES); | |
f4322df6 | 157 | } |
c96d7bec VZ |
158 | #if wxUSE_LIBHILDON |
159 | else // just Yes/No | |
160 | { | |
161 | gtk_dialog_add_button(dlg, GTK_STOCK_NO, GTK_RESPONSE_NO); | |
162 | gtk_dialog_add_button(dlg, GTK_STOCK_YES, GTK_RESPONSE_YES); | |
163 | } | |
164 | #endif // wxUSE_LIBHILDON | |
165 | ||
166 | gtk_dialog_set_default_response(dlg, | |
167 | m_dialogStyle & wxNO_DEFAULT | |
168 | ? GTK_RESPONSE_NO | |
169 | : GTK_RESPONSE_YES); | |
170 | } | |
171 | #if wxUSE_LIBHILDON | |
172 | else // Ok or Ok/Cancel dialog | |
173 | { | |
174 | gtk_dialog_add_button(dlg, GTK_STOCK_OK, GTK_RESPONSE_OK); | |
175 | if ( m_dialogStyle & wxCANCEL ) | |
176 | gtk_dialog_add_button(dlg, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); | |
13a7abf9 | 177 | } |
c96d7bec | 178 | #endif // wxUSE_LIBHILDON |
633c71ef | 179 | |
c96d7bec VZ |
180 | // VZ: isn't this done by GTK+ itself? |
181 | if (parent) | |
182 | gtk_window_set_transient_for(GTK_WINDOW(m_widget), parent); | |
b2ce5e1b | 183 | } |
e5b50758 | 184 | |
b2ce5e1b RD |
185 | int wxMessageDialog::ShowModal() |
186 | { | |
7738af59 VZ |
187 | // break the mouse capture as it would interfere with modal dialog (see |
188 | // wxDialog::ShowModal) | |
189 | wxWindow * const win = wxWindow::GetCapture(); | |
190 | if ( win ) | |
191 | win->GTKReleaseMouseAndNotify(); | |
192 | ||
2afb9e16 VZ |
193 | if ( !m_widget ) |
194 | { | |
195 | GTKCreateMsgDialog(); | |
196 | wxCHECK_MSG( m_widget, wxID_CANCEL, | |
197 | _T("failed to create GtkMessageDialog") ); | |
198 | } | |
199 | ||
3b439e60 RR |
200 | // This should be necessary, but otherwise the |
201 | // parent TLW will disappear.. | |
202 | if (m_parent) | |
203 | gtk_window_present( GTK_WINDOW(m_parent->m_widget) ); | |
e5b50758 | 204 | |
b2ce5e1b RD |
205 | gint result = gtk_dialog_run(GTK_DIALOG(m_widget)); |
206 | gtk_widget_destroy(m_widget); | |
207 | m_widget = NULL; | |
13a7abf9 VS |
208 | |
209 | switch (result) | |
210 | { | |
211 | default: | |
212 | wxFAIL_MSG(_T("unexpected GtkMessageDialog return code")); | |
213 | // fall through | |
214 | ||
b63b07a8 | 215 | case GTK_RESPONSE_CANCEL: |
0e4a7045 VS |
216 | case GTK_RESPONSE_DELETE_EVENT: |
217 | case GTK_RESPONSE_CLOSE: | |
13a7abf9 VS |
218 | return wxID_CANCEL; |
219 | case GTK_RESPONSE_OK: | |
220 | return wxID_OK; | |
221 | case GTK_RESPONSE_YES: | |
222 | return wxID_YES; | |
223 | case GTK_RESPONSE_NO: | |
224 | return wxID_NO; | |
225 | } | |
226 | } | |
227 | ||
b2ce5e1b | 228 | |
ff654490 | 229 | #endif // wxUSE_MSGDLG && !defined(__WXGPE__) |