]>
Commit | Line | Data |
---|---|---|
13a7abf9 | 1 | ///////////////////////////////////////////////////////////////////////////// |
e5b50758 | 2 | // Name: src/gtk/msgdlg.cpp |
13a7abf9 VS |
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 | |
e5b50758 | 9 | // Licence: wxWindows licence |
13a7abf9 VS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
13a7abf9 VS |
12 | // For compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
14 | ||
15 | #ifdef __BORLANDC__ | |
88a7a4e1 | 16 | #pragma hdrstop |
13a7abf9 VS |
17 | #endif |
18 | ||
47e118ba | 19 | #if wxUSE_MSGDLG && defined(__WXGTK20__) && !defined(__WXGPE__) |
13a7abf9 | 20 | |
e1bf3ad3 | 21 | #include "wx/msgdlg.h" |
88a7a4e1 WS |
22 | |
23 | #ifndef WX_PRECOMP | |
24 | #include "wx/intl.h" | |
25 | #endif | |
26 | ||
13a7abf9 VS |
27 | #include "wx/gtk/private.h" |
28 | #include <gtk/gtk.h> | |
29 | ||
13a7abf9 VS |
30 | IMPLEMENT_CLASS(wxMessageDialog, wxDialog) |
31 | ||
32 | wxMessageDialog::wxMessageDialog(wxWindow *parent, | |
33 | const wxString& message, | |
34 | const wxString& caption, | |
35 | long style, | |
36 | const wxPoint& WXUNUSED(pos)) | |
37 | { | |
38 | m_caption = caption; | |
39 | m_message = message; | |
e5b50758 | 40 | SetMessageDialogStyle(style); |
2229243b VZ |
41 | |
42 | m_parent = GetParentForModalDialog(parent); | |
13a7abf9 | 43 | |
b63b07a8 | 44 | GtkMessageType type = GTK_MESSAGE_ERROR; |
13a7abf9 | 45 | GtkButtonsType buttons = GTK_BUTTONS_OK; |
b63b07a8 | 46 | |
e5b50758 | 47 | if (style & wxYES_NO) |
13a7abf9 | 48 | { |
f4322df6 VZ |
49 | if (style & wxCANCEL) |
50 | buttons = GTK_BUTTONS_NONE; | |
51 | else | |
52 | buttons = GTK_BUTTONS_YES_NO; | |
13a7abf9 VS |
53 | } |
54 | ||
e5b50758 | 55 | if (style & wxOK) |
13a7abf9 | 56 | { |
e5b50758 | 57 | if (style & wxCANCEL) |
13a7abf9 VS |
58 | buttons = GTK_BUTTONS_OK_CANCEL; |
59 | else | |
60 | buttons = GTK_BUTTONS_OK; | |
61 | } | |
b63b07a8 | 62 | |
e5b50758 | 63 | if (style & wxICON_EXCLAMATION) |
13a7abf9 | 64 | type = GTK_MESSAGE_WARNING; |
e5b50758 | 65 | else if (style & wxICON_ERROR) |
13a7abf9 | 66 | type = GTK_MESSAGE_ERROR; |
e5b50758 | 67 | else if (style & wxICON_INFORMATION) |
13a7abf9 | 68 | type = GTK_MESSAGE_INFO; |
e5b50758 | 69 | else if (style & wxICON_QUESTION) |
13a7abf9 | 70 | type = GTK_MESSAGE_QUESTION; |
b63b07a8 | 71 | else |
e0ae1a0a VZ |
72 | { |
73 | // GTK+ doesn't have a "typeless" msg box, so try to auto detect... | |
e5b50758 | 74 | type = style & wxYES ? GTK_MESSAGE_QUESTION : GTK_MESSAGE_INFO; |
e0ae1a0a | 75 | } |
13a7abf9 | 76 | |
b2ce5e1b RD |
77 | m_widget = gtk_message_dialog_new(m_parent ? |
78 | GTK_WINDOW(m_parent->m_widget) : NULL, | |
79 | GTK_DIALOG_MODAL, | |
80 | type, buttons, | |
81 | "%s", (const char*)wxGTK_CONV(m_message)); | |
13a7abf9 | 82 | if (m_caption != wxMessageBoxCaptionStr) |
b2ce5e1b | 83 | gtk_window_set_title(GTK_WINDOW(m_widget), wxGTK_CONV(m_caption)); |
13a7abf9 | 84 | |
e5b50758 | 85 | if (style & wxYES_NO) |
13a7abf9 | 86 | { |
e5b50758 | 87 | if (style & wxCANCEL) |
f4322df6 | 88 | { |
d182ca1b RR |
89 | gtk_dialog_add_button(GTK_DIALOG(m_widget), GTK_STOCK_NO, |
90 | GTK_RESPONSE_NO); | |
b2ce5e1b | 91 | gtk_dialog_add_button(GTK_DIALOG(m_widget), GTK_STOCK_CANCEL, |
13a7abf9 | 92 | GTK_RESPONSE_CANCEL); |
d182ca1b RR |
93 | gtk_dialog_add_button(GTK_DIALOG(m_widget), GTK_STOCK_YES, |
94 | GTK_RESPONSE_YES); | |
f4322df6 | 95 | } |
e5b50758 | 96 | if (style & wxNO_DEFAULT) |
b2ce5e1b | 97 | gtk_dialog_set_default_response(GTK_DIALOG(m_widget), GTK_RESPONSE_NO); |
13a7abf9 | 98 | else |
b2ce5e1b | 99 | gtk_dialog_set_default_response(GTK_DIALOG(m_widget), GTK_RESPONSE_YES); |
13a7abf9 | 100 | } |
633c71ef | 101 | |
3b439e60 | 102 | if (m_parent) |
633c71ef VS |
103 | gtk_window_set_transient_for(GTK_WINDOW(m_widget), |
104 | GTK_WINDOW(m_parent->m_widget)); | |
b2ce5e1b | 105 | } |
e5b50758 | 106 | |
f1dec25f RR |
107 | wxMessageDialog::~wxMessageDialog() |
108 | { | |
f1dec25f RR |
109 | } |
110 | ||
b2ce5e1b RD |
111 | int wxMessageDialog::ShowModal() |
112 | { | |
3b439e60 RR |
113 | // This should be necessary, but otherwise the |
114 | // parent TLW will disappear.. | |
115 | if (m_parent) | |
116 | gtk_window_present( GTK_WINDOW(m_parent->m_widget) ); | |
e5b50758 | 117 | |
b2ce5e1b RD |
118 | gint result = gtk_dialog_run(GTK_DIALOG(m_widget)); |
119 | gtk_widget_destroy(m_widget); | |
120 | m_widget = NULL; | |
13a7abf9 VS |
121 | |
122 | switch (result) | |
123 | { | |
124 | default: | |
125 | wxFAIL_MSG(_T("unexpected GtkMessageDialog return code")); | |
126 | // fall through | |
127 | ||
b63b07a8 | 128 | case GTK_RESPONSE_CANCEL: |
0e4a7045 VS |
129 | case GTK_RESPONSE_DELETE_EVENT: |
130 | case GTK_RESPONSE_CLOSE: | |
13a7abf9 VS |
131 | return wxID_CANCEL; |
132 | case GTK_RESPONSE_OK: | |
133 | return wxID_OK; | |
134 | case GTK_RESPONSE_YES: | |
135 | return wxID_YES; | |
136 | case GTK_RESPONSE_NO: | |
137 | return wxID_NO; | |
138 | } | |
139 | } | |
140 | ||
b2ce5e1b | 141 | |
88a7a4e1 | 142 | #endif // wxUSE_MSGDLG && defined(__WXGTK20__) && !defined(__WXGPE__) |