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"
22 #include "wx/gtk/private.h"
27 IMPLEMENT_CLASS(wxMessageDialog
, wxDialog
)
29 wxMessageDialog::wxMessageDialog(wxWindow
*parent
,
30 const wxString
& message
,
31 const wxString
& caption
,
33 const wxPoint
& WXUNUSED(pos
))
37 SetMessageDialogStyle(style
);
38 m_parent
= wxGetTopLevelParent(parent
);
40 GtkMessageType type
= GTK_MESSAGE_ERROR
;
41 GtkButtonsType buttons
= GTK_BUTTONS_OK
;
45 buttons
= GTK_BUTTONS_YES_NO
;
51 buttons
= GTK_BUTTONS_OK_CANCEL
;
53 buttons
= GTK_BUTTONS_OK
;
56 if (style
& wxICON_EXCLAMATION
)
57 type
= GTK_MESSAGE_WARNING
;
58 else if (style
& wxICON_ERROR
)
59 type
= GTK_MESSAGE_ERROR
;
60 else if (style
& wxICON_INFORMATION
)
61 type
= GTK_MESSAGE_INFO
;
62 else if (style
& wxICON_QUESTION
)
63 type
= GTK_MESSAGE_QUESTION
;
66 // GTK+ doesn't have a "typeless" msg box, so try to auto detect...
67 type
= style
& wxYES
? GTK_MESSAGE_QUESTION
: GTK_MESSAGE_INFO
;
70 m_widget
= gtk_message_dialog_new(m_parent
?
71 GTK_WINDOW(m_parent
->m_widget
) : NULL
,
74 "%s", (const char*)wxGTK_CONV(m_message
));
75 if (m_caption
!= wxMessageBoxCaptionStr
)
76 gtk_window_set_title(GTK_WINDOW(m_widget
), wxGTK_CONV(m_caption
));
81 gtk_dialog_add_button(GTK_DIALOG(m_widget
), GTK_STOCK_CANCEL
,
83 if (style
& wxNO_DEFAULT
)
84 gtk_dialog_set_default_response(GTK_DIALOG(m_widget
), GTK_RESPONSE_NO
);
86 gtk_dialog_set_default_response(GTK_DIALOG(m_widget
), GTK_RESPONSE_YES
);
90 gtk_window_set_transient_for(GTK_WINDOW(m_widget
),
91 GTK_WINDOW(m_parent
->m_widget
));
94 wxMessageDialog::~wxMessageDialog()
98 int wxMessageDialog::ShowModal()
100 // This should be necessary, but otherwise the
101 // parent TLW will disappear..
103 gtk_window_present( GTK_WINDOW(m_parent
->m_widget
) );
105 gint result
= gtk_dialog_run(GTK_DIALOG(m_widget
));
106 gtk_widget_destroy(m_widget
);
112 wxFAIL_MSG(_T("unexpected GtkMessageDialog return code"));
115 case GTK_RESPONSE_CANCEL
:
116 case GTK_RESPONSE_DELETE_EVENT
:
117 case GTK_RESPONSE_CLOSE
:
119 case GTK_RESPONSE_OK
:
121 case GTK_RESPONSE_YES
:
123 case GTK_RESPONSE_NO
:
129 #endif // wxUSE_MSGDLG && defined(__WXGTK20__)