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