]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/msgdlg.cpp
Generate wxPropertyGrid splitter (column divider) events: wxEVT_PG_COL_BEGIN_DRAG...
[wxWidgets.git] / src / gtk / msgdlg.cpp
CommitLineData
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 27#include "wx/gtk/private.h"
ce668f29 28#include "wx/gtk/private/messagetype.h"
92763588 29#include "wx/gtk/private/mnemonics.h"
13a7abf9
VS
30#include <gtk/gtk.h>
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
40IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
41
42wxMessageDialog::wxMessageDialog(wxWindow *parent,
43 const wxString& message,
44 const wxString& caption,
45 long style,
46 const wxPoint& WXUNUSED(pos))
92763588
VZ
47 : wxMessageDialogWithCustomLabels(GetParentForModalDialog(parent),
48 message,
49 caption,
50 style)
13a7abf9 51{
2afb9e16 52}
13a7abf9 53
92763588
VZ
54wxString wxMessageDialog::GetDefaultYesLabel() const
55{
56 return GTK_STOCK_YES;
57}
58
59wxString wxMessageDialog::GetDefaultNoLabel() const
60{
61 return GTK_STOCK_NO;
62}
63
64wxString wxMessageDialog::GetDefaultOKLabel() const
65{
66 return GTK_STOCK_OK;
67}
68
69wxString wxMessageDialog::GetDefaultCancelLabel() const
70{
71 return GTK_STOCK_CANCEL;
72}
73
e08931c0 74void wxMessageDialog::DoSetCustomLabel(wxString& var, const ButtonLabel& label)
92763588 75{
e08931c0
VZ
76 int stockId = label.GetStockId();
77 if ( stockId == wxID_NONE )
78 {
79 wxMessageDialogWithCustomLabels::DoSetCustomLabel(var, label);
80 var = wxConvertMnemonicsToGTK(var);
81 }
82 else // stock label
83 {
84 var = wxGetStockGtkID(stockId);
85 }
92763588
VZ
86}
87
2afb9e16
VZ
88void wxMessageDialog::GTKCreateMsgDialog()
89{
c96d7bec
VZ
90 GtkWindow * const parent = m_parent ? GTK_WINDOW(m_parent->m_widget) : NULL;
91
426d19f1 92#if wxUSE_LIBHILDON || wxUSE_LIBHILDON2
c96d7bec 93 const char *stockIcon;
7e3204b4
VZ
94 if ( m_dialogStyle & wxICON_NONE )
95 stockIcon = "";
96 else if ( m_dialogStyle & wxICON_ERROR )
c96d7bec
VZ
97 stockIcon = "qgn_note_gene_syserror";
98 else if ( m_dialogStyle & wxICON_EXCLAMATION )
99 stockIcon = "qgn_note_gene_syswarning";
100 else if ( m_dialogStyle & wxICON_INFORMATION )
101 stockIcon = "qgn_note_info";
102 else if ( m_dialogStyle & wxICON_QUESTION )
103 stockIcon = "qgn_note_confirm";
104 else
105 stockIcon = "";
106
107 // there is no generic note creation function in public API so we have no
108 // choice but to use g_object_new() directly
109 m_widget = (GtkWidget *)g_object_new
110 (
111 HILDON_TYPE_NOTE,
426d19f1 112#if wxUSE_LIBHILDON
c96d7bec 113 "note_type", HILDON_NOTE_CONFIRMATION_BUTTON_TYPE,
426d19f1
JS
114#else // wxUSE_LIBHILDON
115 "note_type", HILDON_NOTE_TYPE_CONFIRMATION_BUTTON,
116#endif // wxUSE_LIBHILDON /wxUSE_LIBHILDON2
c96d7bec
VZ
117 "description", (const char *)GetFullMessage().utf8_str(),
118 "icon", stockIcon,
119 NULL
120 );
426d19f1 121#else // !wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
b63b07a8 122 GtkMessageType type = GTK_MESSAGE_ERROR;
92763588 123 GtkButtonsType buttons = GTK_BUTTONS_NONE;
13a7abf9 124
92763588
VZ
125 // when using custom labels, we have to add all the buttons ourselves
126 if ( !HasCustomLabels() )
13a7abf9 127 {
92763588
VZ
128 if ( m_dialogStyle & wxYES_NO )
129 {
130 if ( !(m_dialogStyle & wxCANCEL) )
131 buttons = GTK_BUTTONS_YES_NO;
132 //else: no standard GTK_BUTTONS_YES_NO_CANCEL so leave as NONE
133 }
134 else if ( m_dialogStyle & wxOK )
135 {
136 buttons = m_dialogStyle & wxCANCEL ? GTK_BUTTONS_OK_CANCEL
137 : GTK_BUTTONS_OK;
138 }
13a7abf9 139 }
b63b07a8 140
ce668f29 141 if ( !wxGTKImpl::ConvertMessageTypeFromWX(m_dialogStyle, &type) )
e0ae1a0a 142 {
7e3204b4
VZ
143 // if no style is explicitly specified, detect the suitable icon
144 // ourselves (this can be disabled by using wxICON_NONE)
2afb9e16 145 type = m_dialogStyle & wxYES ? GTK_MESSAGE_QUESTION : GTK_MESSAGE_INFO;
e0ae1a0a 146 }
13a7abf9 147
2afb9e16 148 wxString message;
ff9bb105 149#if GTK_CHECK_VERSION(2, 6, 0)
2afb9e16 150 bool needsExtMessage = false;
1878d1ec 151 if ( gtk_check_version(2, 6, 0) == NULL && !m_extendedMessage.empty() )
2afb9e16
VZ
152 {
153 message = m_message;
154 needsExtMessage = true;
155 }
156 else // extended message not needed or not supported
c96d7bec 157#endif // GTK+ 2.6+
2afb9e16
VZ
158 {
159 message = GetFullMessage();
160 }
161
c96d7bec 162 m_widget = gtk_message_dialog_new(parent,
b2ce5e1b 163 GTK_DIALOG_MODAL,
2afb9e16
VZ
164 type,
165 buttons,
166 "%s",
167 (const char*)wxGTK_CONV(message));
168
ff9bb105 169#if GTK_CHECK_VERSION(2, 6, 0)
2afb9e16
VZ
170 if ( needsExtMessage )
171 {
172 gtk_message_dialog_format_secondary_text
173 (
174 (GtkMessageDialog *)m_widget,
175 "%s",
176 (const char *)wxGTK_CONV(m_extendedMessage)
177 );
178 }
c96d7bec 179#endif // GTK+ 2.6+
426d19f1 180#endif // wxUSE_LIBHILDON || wxUSE_LIBHILDON2/!wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
2afb9e16 181
9ff9d30c
PC
182 g_object_ref(m_widget);
183
13a7abf9 184 if (m_caption != wxMessageBoxCaptionStr)
b2ce5e1b 185 gtk_window_set_title(GTK_WINDOW(m_widget), wxGTK_CONV(m_caption));
13a7abf9 186
c96d7bec 187 GtkDialog * const dlg = GTK_DIALOG(m_widget);
92763588 188
4566dcbe
VZ
189 if ( m_dialogStyle & wxSTAY_ON_TOP )
190 {
191 gtk_window_set_keep_above(GTK_WINDOW(m_widget), TRUE);
192 }
193
92763588
VZ
194 // we need to add buttons manually if we use custom labels or always for
195 // Yes/No/Cancel dialog as GTK+ doesn't support it natively and when using
196 // Hildon we add all the buttons manually as it doesn't support too many of
197 // the combinations we may have
426d19f1 198#if wxUSE_LIBHILDON || wxUSE_LIBHILDON2
92763588
VZ
199 static const bool addButtons = true;
200#else // !wxUSE_LIBHILDON
201 const bool addButtons = buttons == GTK_BUTTONS_NONE;
202#endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON
203
204 if ( m_dialogStyle & wxYES_NO ) // Yes/No or Yes/No/Cancel dialog
205 {
206 if ( addButtons )
c96d7bec 207 {
150c8eb9
VZ
208 gtk_dialog_add_button(dlg, wxGTK_CONV(GetNoLabel()),
209 GTK_RESPONSE_NO);
210 gtk_dialog_add_button(dlg, wxGTK_CONV(GetYesLabel()),
211 GTK_RESPONSE_YES);
92763588
VZ
212
213 if ( m_dialogStyle & wxCANCEL )
214 {
150c8eb9 215 gtk_dialog_add_button(dlg, wxGTK_CONV(GetCancelLabel()),
92763588
VZ
216 GTK_RESPONSE_CANCEL);
217 }
c96d7bec 218 }
c96d7bec 219
24689293
VZ
220 // it'd probably be harmless to call gtk_dialog_set_default_response()
221 // twice but why do it if we're going to change the default below
222 // anyhow
223 if ( !(m_dialogStyle & wxCANCEL_DEFAULT) )
224 {
225 gtk_dialog_set_default_response(dlg,
226 m_dialogStyle & wxNO_DEFAULT
227 ? GTK_RESPONSE_NO
228 : GTK_RESPONSE_YES);
229 }
c96d7bec 230 }
92763588 231 else if ( addButtons ) // Ok or Ok/Cancel dialog
c96d7bec 232 {
150c8eb9 233 gtk_dialog_add_button(dlg, wxGTK_CONV(GetOKLabel()), GTK_RESPONSE_OK);
c96d7bec 234 if ( m_dialogStyle & wxCANCEL )
150c8eb9
VZ
235 {
236 gtk_dialog_add_button(dlg, wxGTK_CONV(GetCancelLabel()),
237 GTK_RESPONSE_CANCEL);
238 }
13a7abf9 239 }
24689293
VZ
240
241 if ( m_dialogStyle & wxCANCEL_DEFAULT )
242 {
243 gtk_dialog_set_default_response(dlg, GTK_RESPONSE_CANCEL);
244 }
b2ce5e1b 245}
e5b50758 246
b2ce5e1b
RD
247int wxMessageDialog::ShowModal()
248{
7738af59
VZ
249 // break the mouse capture as it would interfere with modal dialog (see
250 // wxDialog::ShowModal)
251 wxWindow * const win = wxWindow::GetCapture();
252 if ( win )
253 win->GTKReleaseMouseAndNotify();
254
2afb9e16
VZ
255 if ( !m_widget )
256 {
257 GTKCreateMsgDialog();
258 wxCHECK_MSG( m_widget, wxID_CANCEL,
9a83f860 259 wxT("failed to create GtkMessageDialog") );
2afb9e16
VZ
260 }
261
3b439e60
RR
262 // This should be necessary, but otherwise the
263 // parent TLW will disappear..
264 if (m_parent)
265 gtk_window_present( GTK_WINDOW(m_parent->m_widget) );
e5b50758 266
b2ce5e1b
RD
267 gint result = gtk_dialog_run(GTK_DIALOG(m_widget));
268 gtk_widget_destroy(m_widget);
9ff9d30c 269 g_object_unref(m_widget);
b2ce5e1b 270 m_widget = NULL;
13a7abf9
VS
271
272 switch (result)
273 {
274 default:
9a83f860 275 wxFAIL_MSG(wxT("unexpected GtkMessageDialog return code"));
13a7abf9
VS
276 // fall through
277
b63b07a8 278 case GTK_RESPONSE_CANCEL:
0e4a7045
VS
279 case GTK_RESPONSE_DELETE_EVENT:
280 case GTK_RESPONSE_CLOSE:
13a7abf9
VS
281 return wxID_CANCEL;
282 case GTK_RESPONSE_OK:
283 return wxID_OK;
284 case GTK_RESPONSE_YES:
285 return wxID_YES;
286 case GTK_RESPONSE_NO:
287 return wxID_NO;
288 }
289}
290
b2ce5e1b 291
ff654490 292#endif // wxUSE_MSGDLG && !defined(__WXGPE__)