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"
31 #include <hildon-widgets/hildon-note.h>
32 #endif // wxUSE_LIBHILDON
34 IMPLEMENT_CLASS(wxMessageDialog
, wxDialog
)
36 wxMessageDialog::wxMessageDialog(wxWindow
*parent
,
37 const wxString
& message
,
38 const wxString
& caption
,
40 const wxPoint
& WXUNUSED(pos
))
41 : wxMessageDialogBase(GetParentForModalDialog(parent
),
48 void wxMessageDialog::GTKCreateMsgDialog()
50 GtkWindow
* const parent
= m_parent
? GTK_WINDOW(m_parent
->m_widget
) : NULL
;
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";
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
70 "note_type", HILDON_NOTE_CONFIRMATION_BUTTON_TYPE
,
71 "description", (const char *)GetFullMessage().utf8_str(),
75 #else // !wxUSE_LIBHILDON
76 GtkMessageType type
= GTK_MESSAGE_ERROR
;
77 GtkButtonsType buttons
= GTK_BUTTONS_OK
;
79 if (m_dialogStyle
& wxYES_NO
)
81 if (m_dialogStyle
& wxCANCEL
)
82 buttons
= GTK_BUTTONS_NONE
;
84 buttons
= GTK_BUTTONS_YES_NO
;
87 if (m_dialogStyle
& wxOK
)
89 if (m_dialogStyle
& wxCANCEL
)
90 buttons
= GTK_BUTTONS_OK_CANCEL
;
92 buttons
= GTK_BUTTONS_OK
;
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
;
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
;
110 #if GTK_CHECK_VERSION(2, 6, 0)
111 bool needsExtMessage
= false;
112 if ( gtk_check_version(2, 6, 0) == NULL
&& !m_extendedMessage
.empty() )
115 needsExtMessage
= true;
117 else // extended message not needed or not supported
120 message
= GetFullMessage();
123 m_widget
= gtk_message_dialog_new(parent
,
128 (const char*)wxGTK_CONV(message
));
130 #if GTK_CHECK_VERSION(2, 6, 0)
131 if ( needsExtMessage
)
133 gtk_message_dialog_format_secondary_text
135 (GtkMessageDialog
*)m_widget
,
137 (const char *)wxGTK_CONV(m_extendedMessage
)
141 #endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON
143 if (m_caption
!= wxMessageBoxCaptionStr
)
144 gtk_window_set_title(GTK_WINDOW(m_widget
), wxGTK_CONV(m_caption
));
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
)
152 if ( m_dialogStyle
& wxCANCEL
)
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
);
161 gtk_dialog_add_button(dlg
, GTK_STOCK_NO
, GTK_RESPONSE_NO
);
162 gtk_dialog_add_button(dlg
, GTK_STOCK_YES
, GTK_RESPONSE_YES
);
164 #endif // wxUSE_LIBHILDON
166 gtk_dialog_set_default_response(dlg
,
167 m_dialogStyle
& wxNO_DEFAULT
172 else // Ok or Ok/Cancel dialog
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
);
178 #endif // wxUSE_LIBHILDON
180 // VZ: isn't this done by GTK+ itself?
182 gtk_window_set_transient_for(GTK_WINDOW(m_widget
), parent
);
185 int wxMessageDialog::ShowModal()
187 // break the mouse capture as it would interfere with modal dialog (see
188 // wxDialog::ShowModal)
189 wxWindow
* const win
= wxWindow::GetCapture();
191 win
->GTKReleaseMouseAndNotify();
195 GTKCreateMsgDialog();
196 wxCHECK_MSG( m_widget
, wxID_CANCEL
,
197 _T("failed to create GtkMessageDialog") );
200 // This should be necessary, but otherwise the
201 // parent TLW will disappear..
203 gtk_window_present( GTK_WINDOW(m_parent
->m_widget
) );
205 gint result
= gtk_dialog_run(GTK_DIALOG(m_widget
));
206 gtk_widget_destroy(m_widget
);
212 wxFAIL_MSG(_T("unexpected GtkMessageDialog return code"));
215 case GTK_RESPONSE_CANCEL
:
216 case GTK_RESPONSE_DELETE_EVENT
:
217 case GTK_RESPONSE_CLOSE
:
219 case GTK_RESPONSE_OK
:
221 case GTK_RESPONSE_YES
:
223 case GTK_RESPONSE_NO
:
229 #endif // wxUSE_MSGDLG && !defined(__WXGPE__)