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(__WXGTK20__) && !defined(__WXGPE__)
21 #include "wx/msgdlg.h"
27 #include "wx/gtk/private.h"
30 IMPLEMENT_CLASS(wxMessageDialog
, wxDialog
)
32 wxMessageDialog::wxMessageDialog(wxWindow
*parent
,
33 const wxString
& message
,
34 const wxString
& caption
,
36 const wxPoint
& WXUNUSED(pos
))
37 : wxMessageDialogBase(GetParentForModalDialog(parent
),
44 void wxMessageDialog::GTKCreateMsgDialog()
46 GtkMessageType type
= GTK_MESSAGE_ERROR
;
47 GtkButtonsType buttons
= GTK_BUTTONS_OK
;
49 if (m_dialogStyle
& wxYES_NO
)
51 if (m_dialogStyle
& wxCANCEL
)
52 buttons
= GTK_BUTTONS_NONE
;
54 buttons
= GTK_BUTTONS_YES_NO
;
57 if (m_dialogStyle
& wxOK
)
59 if (m_dialogStyle
& wxCANCEL
)
60 buttons
= GTK_BUTTONS_OK_CANCEL
;
62 buttons
= GTK_BUTTONS_OK
;
65 if (m_dialogStyle
& wxICON_EXCLAMATION
)
66 type
= GTK_MESSAGE_WARNING
;
67 else if (m_dialogStyle
& wxICON_ERROR
)
68 type
= GTK_MESSAGE_ERROR
;
69 else if (m_dialogStyle
& wxICON_INFORMATION
)
70 type
= GTK_MESSAGE_INFO
;
71 else if (m_dialogStyle
& wxICON_QUESTION
)
72 type
= GTK_MESSAGE_QUESTION
;
75 // GTK+ doesn't have a "typeless" msg box, so try to auto detect...
76 type
= m_dialogStyle
& wxYES
? GTK_MESSAGE_QUESTION
: GTK_MESSAGE_INFO
;
80 #if GTK_CHECK_VERSION(2, 6, 0)
81 bool needsExtMessage
= false;
82 if ( gtk_check_version(2, 6, 0) == NULL
&& !m_extendedMessage
.empty() )
85 needsExtMessage
= true;
87 else // extended message not needed or not supported
90 message
= GetFullMessage();
93 m_widget
= gtk_message_dialog_new(m_parent
? GTK_WINDOW(m_parent
->m_widget
)
99 (const char*)wxGTK_CONV(message
));
101 #if GTK_CHECK_VERSION(2, 6, 0)
102 if ( needsExtMessage
)
104 gtk_message_dialog_format_secondary_text
106 (GtkMessageDialog
*)m_widget
,
108 (const char *)wxGTK_CONV(m_extendedMessage
)
113 if (m_caption
!= wxMessageBoxCaptionStr
)
114 gtk_window_set_title(GTK_WINDOW(m_widget
), wxGTK_CONV(m_caption
));
116 if (m_dialogStyle
& wxYES_NO
)
118 if (m_dialogStyle
& wxCANCEL
)
120 gtk_dialog_add_button(GTK_DIALOG(m_widget
), GTK_STOCK_NO
,
122 gtk_dialog_add_button(GTK_DIALOG(m_widget
), GTK_STOCK_CANCEL
,
123 GTK_RESPONSE_CANCEL
);
124 gtk_dialog_add_button(GTK_DIALOG(m_widget
), GTK_STOCK_YES
,
127 if (m_dialogStyle
& wxNO_DEFAULT
)
128 gtk_dialog_set_default_response(GTK_DIALOG(m_widget
), GTK_RESPONSE_NO
);
130 gtk_dialog_set_default_response(GTK_DIALOG(m_widget
), GTK_RESPONSE_YES
);
134 gtk_window_set_transient_for(GTK_WINDOW(m_widget
),
135 GTK_WINDOW(m_parent
->m_widget
));
138 int wxMessageDialog::ShowModal()
142 GTKCreateMsgDialog();
143 wxCHECK_MSG( m_widget
, wxID_CANCEL
,
144 _T("failed to create GtkMessageDialog") );
147 // This should be necessary, but otherwise the
148 // parent TLW will disappear..
150 gtk_window_present( GTK_WINDOW(m_parent
->m_widget
) );
152 gint result
= gtk_dialog_run(GTK_DIALOG(m_widget
));
153 gtk_widget_destroy(m_widget
);
159 wxFAIL_MSG(_T("unexpected GtkMessageDialog return code"));
162 case GTK_RESPONSE_CANCEL
:
163 case GTK_RESPONSE_DELETE_EVENT
:
164 case GTK_RESPONSE_CLOSE
:
166 case GTK_RESPONSE_OK
:
168 case GTK_RESPONSE_YES
:
170 case GTK_RESPONSE_NO
:
176 #endif // wxUSE_MSGDLG && defined(__WXGTK20__) && !defined(__WXGPE__)