]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/msgdlg.cpp
renaming
[wxWidgets.git] / src / gtk / msgdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/msgdlg.cpp
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
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #if wxUSE_MSGDLG && !defined(__WXGPE__)
20
21 #include "wx/msgdlg.h"
22
23 #ifndef WX_PRECOMP
24 #include "wx/intl.h"
25 #endif
26
27 #include "wx/gtk/private.h"
28 #include <gtk/gtk.h>
29
30 #if wxUSE_LIBHILDON
31 #include <hildon-widgets/hildon-note.h>
32 #endif // wxUSE_LIBHILDON
33
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))
41 : wxMessageDialogBase(GetParentForModalDialog(parent),
42 message,
43 caption,
44 style)
45 {
46 }
47
48 void wxMessageDialog::GTKCreateMsgDialog()
49 {
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
76 GtkMessageType type = GTK_MESSAGE_ERROR;
77 GtkButtonsType buttons = GTK_BUTTONS_OK;
78
79 if (m_dialogStyle & wxYES_NO)
80 {
81 if (m_dialogStyle & wxCANCEL)
82 buttons = GTK_BUTTONS_NONE;
83 else
84 buttons = GTK_BUTTONS_YES_NO;
85 }
86
87 if (m_dialogStyle & wxOK)
88 {
89 if (m_dialogStyle & wxCANCEL)
90 buttons = GTK_BUTTONS_OK_CANCEL;
91 else
92 buttons = GTK_BUTTONS_OK;
93 }
94
95 if (m_dialogStyle & wxICON_EXCLAMATION)
96 type = GTK_MESSAGE_WARNING;
97 else if (m_dialogStyle & wxICON_ERROR)
98 type = GTK_MESSAGE_ERROR;
99 else if (m_dialogStyle & wxICON_INFORMATION)
100 type = GTK_MESSAGE_INFO;
101 else if (m_dialogStyle & wxICON_QUESTION)
102 type = GTK_MESSAGE_QUESTION;
103 else
104 {
105 // GTK+ doesn't have a "typeless" msg box, so try to auto detect...
106 type = m_dialogStyle & wxYES ? GTK_MESSAGE_QUESTION : GTK_MESSAGE_INFO;
107 }
108
109 wxString message;
110 #if GTK_CHECK_VERSION(2, 6, 0)
111 bool needsExtMessage = false;
112 if ( gtk_check_version(2, 6, 0) == NULL && !m_extendedMessage.empty() )
113 {
114 message = m_message;
115 needsExtMessage = true;
116 }
117 else // extended message not needed or not supported
118 #endif // GTK+ 2.6+
119 {
120 message = GetFullMessage();
121 }
122
123 m_widget = gtk_message_dialog_new(parent,
124 GTK_DIALOG_MODAL,
125 type,
126 buttons,
127 "%s",
128 (const char*)wxGTK_CONV(message));
129
130 #if GTK_CHECK_VERSION(2, 6, 0)
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 }
140 #endif // GTK+ 2.6+
141 #endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON
142
143 if (m_caption != wxMessageBoxCaptionStr)
144 gtk_window_set_title(GTK_WINDOW(m_widget), wxGTK_CONV(m_caption));
145
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 )
151 {
152 if ( m_dialogStyle & wxCANCEL )
153 {
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);
157 }
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);
177 }
178 #endif // wxUSE_LIBHILDON
179
180 // VZ: isn't this done by GTK+ itself?
181 if (parent)
182 gtk_window_set_transient_for(GTK_WINDOW(m_widget), parent);
183 }
184
185 int wxMessageDialog::ShowModal()
186 {
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
193 if ( !m_widget )
194 {
195 GTKCreateMsgDialog();
196 wxCHECK_MSG( m_widget, wxID_CANCEL,
197 _T("failed to create GtkMessageDialog") );
198 }
199
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) );
204
205 gint result = gtk_dialog_run(GTK_DIALOG(m_widget));
206 gtk_widget_destroy(m_widget);
207 m_widget = NULL;
208
209 switch (result)
210 {
211 default:
212 wxFAIL_MSG(_T("unexpected GtkMessageDialog return code"));
213 // fall through
214
215 case GTK_RESPONSE_CANCEL:
216 case GTK_RESPONSE_DELETE_EVENT:
217 case GTK_RESPONSE_CLOSE:
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
228
229 #endif // wxUSE_MSGDLG && !defined(__WXGPE__)