1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/msgdlg.cpp
3 // Purpose: wxMessageDialog for GTK+2
4 // Author: Vaclav Slavik
8 // Copyright: (c) Vaclav Slavik, 2003
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
19 #if wxUSE_MSGDLG && !defined(__WXGPE__)
21 #include "wx/msgdlg.h"
27 #include "wx/gtk/private.h"
28 #include "wx/gtk/private/mnemonics.h"
32 #include <hildon-widgets/hildon-note.h>
33 #endif // wxUSE_LIBHILDON
35 IMPLEMENT_CLASS(wxMessageDialog
, wxDialog
)
37 wxMessageDialog::wxMessageDialog(wxWindow
*parent
,
38 const wxString
& message
,
39 const wxString
& caption
,
41 const wxPoint
& WXUNUSED(pos
))
42 : wxMessageDialogWithCustomLabels(GetParentForModalDialog(parent
),
49 wxString
wxMessageDialog::GetDefaultYesLabel() const
54 wxString
wxMessageDialog::GetDefaultNoLabel() const
59 wxString
wxMessageDialog::GetDefaultOKLabel() const
64 wxString
wxMessageDialog::GetDefaultCancelLabel() const
66 return GTK_STOCK_CANCEL
;
69 void wxMessageDialog::DoSetCustomLabel(wxString
& var
, const wxString
& value
)
71 var
= wxConvertMnemonicsToGTK(value
);
74 void wxMessageDialog::GTKCreateMsgDialog()
76 GtkWindow
* const parent
= m_parent
? GTK_WINDOW(m_parent
->m_widget
) : NULL
;
79 const char *stockIcon
;
80 if ( m_dialogStyle
& wxICON_ERROR
)
81 stockIcon
= "qgn_note_gene_syserror";
82 else if ( m_dialogStyle
& wxICON_EXCLAMATION
)
83 stockIcon
= "qgn_note_gene_syswarning";
84 else if ( m_dialogStyle
& wxICON_INFORMATION
)
85 stockIcon
= "qgn_note_info";
86 else if ( m_dialogStyle
& wxICON_QUESTION
)
87 stockIcon
= "qgn_note_confirm";
91 // there is no generic note creation function in public API so we have no
92 // choice but to use g_object_new() directly
93 m_widget
= (GtkWidget
*)g_object_new
96 "note_type", HILDON_NOTE_CONFIRMATION_BUTTON_TYPE
,
97 "description", (const char *)GetFullMessage().utf8_str(),
101 #else // !wxUSE_LIBHILDON
102 GtkMessageType type
= GTK_MESSAGE_ERROR
;
103 GtkButtonsType buttons
= GTK_BUTTONS_NONE
;
105 // when using custom labels, we have to add all the buttons ourselves
106 if ( !HasCustomLabels() )
108 if ( m_dialogStyle
& wxYES_NO
)
110 if ( !(m_dialogStyle
& wxCANCEL
) )
111 buttons
= GTK_BUTTONS_YES_NO
;
112 //else: no standard GTK_BUTTONS_YES_NO_CANCEL so leave as NONE
114 else if ( m_dialogStyle
& wxOK
)
116 buttons
= m_dialogStyle
& wxCANCEL
? GTK_BUTTONS_OK_CANCEL
121 if (m_dialogStyle
& wxICON_EXCLAMATION
)
122 type
= GTK_MESSAGE_WARNING
;
123 else if (m_dialogStyle
& wxICON_ERROR
)
124 type
= GTK_MESSAGE_ERROR
;
125 else if (m_dialogStyle
& wxICON_INFORMATION
)
126 type
= GTK_MESSAGE_INFO
;
127 else if (m_dialogStyle
& wxICON_QUESTION
)
128 type
= GTK_MESSAGE_QUESTION
;
131 // GTK+ doesn't have a "typeless" msg box, so try to auto detect...
132 type
= m_dialogStyle
& wxYES
? GTK_MESSAGE_QUESTION
: GTK_MESSAGE_INFO
;
136 #if GTK_CHECK_VERSION(2, 6, 0)
137 bool needsExtMessage
= false;
138 if ( gtk_check_version(2, 6, 0) == NULL
&& !m_extendedMessage
.empty() )
141 needsExtMessage
= true;
143 else // extended message not needed or not supported
146 message
= GetFullMessage();
149 m_widget
= gtk_message_dialog_new(parent
,
154 (const char*)wxGTK_CONV(message
));
156 #if GTK_CHECK_VERSION(2, 6, 0)
157 if ( needsExtMessage
)
159 gtk_message_dialog_format_secondary_text
161 (GtkMessageDialog
*)m_widget
,
163 (const char *)wxGTK_CONV(m_extendedMessage
)
167 #endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON
169 g_object_ref(m_widget
);
171 if (m_caption
!= wxMessageBoxCaptionStr
)
172 gtk_window_set_title(GTK_WINDOW(m_widget
), wxGTK_CONV(m_caption
));
174 GtkDialog
* const dlg
= GTK_DIALOG(m_widget
);
176 // we need to add buttons manually if we use custom labels or always for
177 // Yes/No/Cancel dialog as GTK+ doesn't support it natively and when using
178 // Hildon we add all the buttons manually as it doesn't support too many of
179 // the combinations we may have
181 static const bool addButtons
= true;
182 #else // !wxUSE_LIBHILDON
183 const bool addButtons
= buttons
== GTK_BUTTONS_NONE
;
184 #endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON
186 if ( m_dialogStyle
& wxYES_NO
) // Yes/No or Yes/No/Cancel dialog
190 gtk_dialog_add_button(dlg
, GetNoLabel(), GTK_RESPONSE_NO
);
191 gtk_dialog_add_button(dlg
, GetYesLabel(), GTK_RESPONSE_YES
);
193 if ( m_dialogStyle
& wxCANCEL
)
195 gtk_dialog_add_button(dlg
, GetCancelLabel(),
196 GTK_RESPONSE_CANCEL
);
200 gtk_dialog_set_default_response(dlg
,
201 m_dialogStyle
& wxNO_DEFAULT
205 else if ( addButtons
) // Ok or Ok/Cancel dialog
207 gtk_dialog_add_button(dlg
, GetOKLabel(), GTK_RESPONSE_OK
);
208 if ( m_dialogStyle
& wxCANCEL
)
209 gtk_dialog_add_button(dlg
, GetCancelLabel(), GTK_RESPONSE_CANCEL
);
213 int wxMessageDialog::ShowModal()
215 // break the mouse capture as it would interfere with modal dialog (see
216 // wxDialog::ShowModal)
217 wxWindow
* const win
= wxWindow::GetCapture();
219 win
->GTKReleaseMouseAndNotify();
223 GTKCreateMsgDialog();
224 wxCHECK_MSG( m_widget
, wxID_CANCEL
,
225 _T("failed to create GtkMessageDialog") );
228 // This should be necessary, but otherwise the
229 // parent TLW will disappear..
231 gtk_window_present( GTK_WINDOW(m_parent
->m_widget
) );
233 gint result
= gtk_dialog_run(GTK_DIALOG(m_widget
));
234 gtk_widget_destroy(m_widget
);
235 g_object_unref(m_widget
);
241 wxFAIL_MSG(_T("unexpected GtkMessageDialog return code"));
244 case GTK_RESPONSE_CANCEL
:
245 case GTK_RESPONSE_DELETE_EVENT
:
246 case GTK_RESPONSE_CLOSE
:
248 case GTK_RESPONSE_OK
:
250 case GTK_RESPONSE_YES
:
252 case GTK_RESPONSE_NO
:
258 #endif // wxUSE_MSGDLG && !defined(__WXGPE__)