]>
Commit | Line | Data |
---|---|---|
13a7abf9 VS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: msgdlg.cpp | |
3 | // Purpose: wxMessageDialog for GTK+2 | |
4 | // Author: Vaclav Slavik | |
5 | // Modified by: | |
6 | // Created: 2003/02/28 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Vaclav Slavik, 2003 | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
14f355c2 | 12 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
13a7abf9 VS |
13 | #pragma implementation "msgdlg.h" |
14 | #endif | |
15 | ||
16 | // For compilers that support precompilation, includes "wx.h". | |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifdef __BORLANDC__ | |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
47e118ba | 23 | #if wxUSE_MSGDLG && defined(__WXGTK20__) && !defined(__WXGPE__) |
13a7abf9 VS |
24 | |
25 | #include "wx/gtk/private.h" | |
26 | #include <gtk/gtk.h> | |
27 | ||
28 | #include "wx/msgdlg.h" | |
29 | #include "wx/intl.h" | |
30 | ||
31 | IMPLEMENT_CLASS(wxMessageDialog, wxDialog) | |
32 | ||
33 | wxMessageDialog::wxMessageDialog(wxWindow *parent, | |
34 | const wxString& message, | |
35 | const wxString& caption, | |
36 | long style, | |
37 | const wxPoint& WXUNUSED(pos)) | |
38 | { | |
39 | m_caption = caption; | |
40 | m_message = message; | |
41 | m_dialogStyle = style; | |
1840af03 | 42 | m_parent = wxGetTopLevelParent(parent); |
13a7abf9 | 43 | |
b63b07a8 | 44 | GtkMessageType type = GTK_MESSAGE_ERROR; |
13a7abf9 | 45 | GtkButtonsType buttons = GTK_BUTTONS_OK; |
b63b07a8 | 46 | |
13a7abf9 VS |
47 | if (m_dialogStyle & wxYES_NO) |
48 | { | |
49 | buttons = GTK_BUTTONS_YES_NO; | |
50 | } | |
51 | ||
52 | if (m_dialogStyle & wxOK) | |
53 | { | |
54 | if (m_dialogStyle & wxCANCEL) | |
55 | buttons = GTK_BUTTONS_OK_CANCEL; | |
56 | else | |
57 | buttons = GTK_BUTTONS_OK; | |
58 | } | |
b63b07a8 | 59 | |
13a7abf9 VS |
60 | if (m_dialogStyle & wxICON_EXCLAMATION) |
61 | type = GTK_MESSAGE_WARNING; | |
62 | else if (m_dialogStyle & wxICON_ERROR) | |
63 | type = GTK_MESSAGE_ERROR; | |
64 | else if (m_dialogStyle & wxICON_INFORMATION) | |
65 | type = GTK_MESSAGE_INFO; | |
66 | else if (m_dialogStyle & wxICON_QUESTION) | |
67 | type = GTK_MESSAGE_QUESTION; | |
b63b07a8 | 68 | else |
e0ae1a0a VZ |
69 | { |
70 | // GTK+ doesn't have a "typeless" msg box, so try to auto detect... | |
71 | type = m_dialogStyle & wxYES ? GTK_MESSAGE_QUESTION : GTK_MESSAGE_INFO; | |
72 | } | |
13a7abf9 | 73 | |
b2ce5e1b RD |
74 | m_widget = gtk_message_dialog_new(m_parent ? |
75 | GTK_WINDOW(m_parent->m_widget) : NULL, | |
76 | GTK_DIALOG_MODAL, | |
77 | type, buttons, | |
78 | "%s", (const char*)wxGTK_CONV(m_message)); | |
13a7abf9 | 79 | if (m_caption != wxMessageBoxCaptionStr) |
b2ce5e1b | 80 | gtk_window_set_title(GTK_WINDOW(m_widget), wxGTK_CONV(m_caption)); |
13a7abf9 VS |
81 | |
82 | if (m_dialogStyle & wxYES_NO) | |
83 | { | |
84 | if (m_dialogStyle & wxCANCEL) | |
b2ce5e1b | 85 | gtk_dialog_add_button(GTK_DIALOG(m_widget), GTK_STOCK_CANCEL, |
13a7abf9 VS |
86 | GTK_RESPONSE_CANCEL); |
87 | if (m_dialogStyle & wxNO_DEFAULT) | |
b2ce5e1b | 88 | gtk_dialog_set_default_response(GTK_DIALOG(m_widget), GTK_RESPONSE_NO); |
13a7abf9 | 89 | else |
b2ce5e1b | 90 | gtk_dialog_set_default_response(GTK_DIALOG(m_widget), GTK_RESPONSE_YES); |
13a7abf9 | 91 | } |
b2ce5e1b RD |
92 | } |
93 | ||
94 | int wxMessageDialog::ShowModal() | |
95 | { | |
96 | gint result = gtk_dialog_run(GTK_DIALOG(m_widget)); | |
97 | gtk_widget_destroy(m_widget); | |
98 | m_widget = NULL; | |
13a7abf9 VS |
99 | |
100 | switch (result) | |
101 | { | |
102 | default: | |
103 | wxFAIL_MSG(_T("unexpected GtkMessageDialog return code")); | |
104 | // fall through | |
105 | ||
b63b07a8 | 106 | case GTK_RESPONSE_CANCEL: |
13a7abf9 VS |
107 | return wxID_CANCEL; |
108 | case GTK_RESPONSE_OK: | |
109 | return wxID_OK; | |
110 | case GTK_RESPONSE_YES: | |
111 | return wxID_YES; | |
112 | case GTK_RESPONSE_NO: | |
113 | return wxID_NO; | |
114 | } | |
115 | } | |
116 | ||
b2ce5e1b | 117 | |
13a7abf9 VS |
118 | #endif // wxUSE_MSGDLG && defined(__WXGTK20__) |
119 |