]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/msgdlg.cpp
define wxString::iterator::iterator_category correctly if wxUSE_STD_STRING and not...
[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
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
34IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
35
36wxMessageDialog::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
48void 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
9ff9d30c
PC
143 g_object_ref(m_widget);
144
13a7abf9 145 if (m_caption != wxMessageBoxCaptionStr)
b2ce5e1b 146 gtk_window_set_title(GTK_WINDOW(m_widget), wxGTK_CONV(m_caption));
13a7abf9 147
c96d7bec
VZ
148 // we need to add dialogs manually when using Yes/No/Cancel dialog as GTK+
149 // doesn't support it natively and when using Hildon we add all the buttons
150 // manually as it doesn't support too many of the combinations we have
151 GtkDialog * const dlg = GTK_DIALOG(m_widget);
152 if ( m_dialogStyle & wxYES_NO )
13a7abf9 153 {
c96d7bec 154 if ( m_dialogStyle & wxCANCEL )
f4322df6 155 {
c96d7bec
VZ
156 gtk_dialog_add_button(dlg, GTK_STOCK_NO, GTK_RESPONSE_NO);
157 gtk_dialog_add_button(dlg, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
158 gtk_dialog_add_button(dlg, GTK_STOCK_YES, GTK_RESPONSE_YES);
f4322df6 159 }
c96d7bec
VZ
160#if wxUSE_LIBHILDON
161 else // just Yes/No
162 {
163 gtk_dialog_add_button(dlg, GTK_STOCK_NO, GTK_RESPONSE_NO);
164 gtk_dialog_add_button(dlg, GTK_STOCK_YES, GTK_RESPONSE_YES);
165 }
166#endif // wxUSE_LIBHILDON
167
168 gtk_dialog_set_default_response(dlg,
169 m_dialogStyle & wxNO_DEFAULT
170 ? GTK_RESPONSE_NO
171 : GTK_RESPONSE_YES);
172 }
173#if wxUSE_LIBHILDON
174 else // Ok or Ok/Cancel dialog
175 {
176 gtk_dialog_add_button(dlg, GTK_STOCK_OK, GTK_RESPONSE_OK);
177 if ( m_dialogStyle & wxCANCEL )
178 gtk_dialog_add_button(dlg, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
13a7abf9 179 }
c96d7bec 180#endif // wxUSE_LIBHILDON
633c71ef 181
c96d7bec
VZ
182 // VZ: isn't this done by GTK+ itself?
183 if (parent)
184 gtk_window_set_transient_for(GTK_WINDOW(m_widget), parent);
b2ce5e1b 185}
e5b50758 186
b2ce5e1b
RD
187int wxMessageDialog::ShowModal()
188{
7738af59
VZ
189 // break the mouse capture as it would interfere with modal dialog (see
190 // wxDialog::ShowModal)
191 wxWindow * const win = wxWindow::GetCapture();
192 if ( win )
193 win->GTKReleaseMouseAndNotify();
194
2afb9e16
VZ
195 if ( !m_widget )
196 {
197 GTKCreateMsgDialog();
198 wxCHECK_MSG( m_widget, wxID_CANCEL,
199 _T("failed to create GtkMessageDialog") );
200 }
201
3b439e60
RR
202 // This should be necessary, but otherwise the
203 // parent TLW will disappear..
204 if (m_parent)
205 gtk_window_present( GTK_WINDOW(m_parent->m_widget) );
e5b50758 206
b2ce5e1b
RD
207 gint result = gtk_dialog_run(GTK_DIALOG(m_widget));
208 gtk_widget_destroy(m_widget);
9ff9d30c 209 g_object_unref(m_widget);
b2ce5e1b 210 m_widget = NULL;
13a7abf9
VS
211
212 switch (result)
213 {
214 default:
215 wxFAIL_MSG(_T("unexpected GtkMessageDialog return code"));
216 // fall through
217
b63b07a8 218 case GTK_RESPONSE_CANCEL:
0e4a7045
VS
219 case GTK_RESPONSE_DELETE_EVENT:
220 case GTK_RESPONSE_CLOSE:
13a7abf9
VS
221 return wxID_CANCEL;
222 case GTK_RESPONSE_OK:
223 return wxID_OK;
224 case GTK_RESPONSE_YES:
225 return wxID_YES;
226 case GTK_RESPONSE_NO:
227 return wxID_NO;
228 }
229}
230
b2ce5e1b 231
ff654490 232#endif // wxUSE_MSGDLG && !defined(__WXGPE__)