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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "msgdlg.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
23 #if wxUSE_MSGDLG && defined(__WXGTK20__) && !defined(__WXGPE__)
25 #include "wx/msgdlg.h"
26 #include "wx/gtk/private.h"
31 IMPLEMENT_CLASS(wxMessageDialog
, wxDialog
)
33 wxMessageDialog::wxMessageDialog(wxWindow
*parent
,
34 const wxString
& message
,
35 const wxString
& caption
,
37 const wxPoint
& WXUNUSED(pos
))
41 SetMessageDialogStyle(style
);
42 m_parent
= wxGetTopLevelParent(parent
);
44 GtkMessageType type
= GTK_MESSAGE_ERROR
;
45 GtkButtonsType buttons
= GTK_BUTTONS_OK
;
49 buttons
= GTK_BUTTONS_YES_NO
;
55 buttons
= GTK_BUTTONS_OK_CANCEL
;
57 buttons
= GTK_BUTTONS_OK
;
60 if (style
& wxICON_EXCLAMATION
)
61 type
= GTK_MESSAGE_WARNING
;
62 else if (style
& wxICON_ERROR
)
63 type
= GTK_MESSAGE_ERROR
;
64 else if (style
& wxICON_INFORMATION
)
65 type
= GTK_MESSAGE_INFO
;
66 else if (style
& wxICON_QUESTION
)
67 type
= GTK_MESSAGE_QUESTION
;
70 // GTK+ doesn't have a "typeless" msg box, so try to auto detect...
71 type
= style
& wxYES
? GTK_MESSAGE_QUESTION
: GTK_MESSAGE_INFO
;
74 m_widget
= gtk_message_dialog_new(m_parent
?
75 GTK_WINDOW(m_parent
->m_widget
) : NULL
,
78 "%s", (const char*)wxGTK_CONV(m_message
));
79 if (m_caption
!= wxMessageBoxCaptionStr
)
80 gtk_window_set_title(GTK_WINDOW(m_widget
), wxGTK_CONV(m_caption
));
85 gtk_dialog_add_button(GTK_DIALOG(m_widget
), GTK_STOCK_CANCEL
,
87 if (style
& wxNO_DEFAULT
)
88 gtk_dialog_set_default_response(GTK_DIALOG(m_widget
), GTK_RESPONSE_NO
);
90 gtk_dialog_set_default_response(GTK_DIALOG(m_widget
), GTK_RESPONSE_YES
);
94 gtk_window_set_transient_for(GTK_WINDOW(m_widget
),
95 GTK_WINDOW(m_parent
->m_widget
));
98 wxMessageDialog::~wxMessageDialog()
102 int wxMessageDialog::ShowModal()
104 // This should be necessary, but otherwise the
105 // parent TLW will disappear..
107 gtk_window_present( GTK_WINDOW(m_parent
->m_widget
) );
109 gint result
= gtk_dialog_run(GTK_DIALOG(m_widget
));
110 gtk_widget_destroy(m_widget
);
116 wxFAIL_MSG(_T("unexpected GtkMessageDialog return code"));
119 case GTK_RESPONSE_CANCEL
:
120 case GTK_RESPONSE_DELETE_EVENT
:
121 case GTK_RESPONSE_CLOSE
:
123 case GTK_RESPONSE_OK
:
125 case GTK_RESPONSE_YES
:
127 case GTK_RESPONSE_NO
:
133 #endif // wxUSE_MSGDLG && defined(__WXGTK20__)