]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/msgdlg.cpp
Do not remove GDK events for native GTK+ controls.
[wxWidgets.git] / src / gtk / msgdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/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
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #if wxUSE_MSGDLG && defined(__WXGTK20__) && !defined(__WXGPE__)
20
21 #include "wx/msgdlg.h"
22
23 #ifndef WX_PRECOMP
24 #include "wx/intl.h"
25 #endif
26
27 #include "wx/gtk/private.h"
28 #include <gtk/gtk.h>
29
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;
40 SetMessageDialogStyle(style);
41 m_parent = wxGetTopLevelParent(parent);
42
43 GtkMessageType type = GTK_MESSAGE_ERROR;
44 GtkButtonsType buttons = GTK_BUTTONS_OK;
45
46 if (style & wxYES_NO)
47 {
48 buttons = GTK_BUTTONS_YES_NO;
49 }
50
51 if (style & wxOK)
52 {
53 if (style & wxCANCEL)
54 buttons = GTK_BUTTONS_OK_CANCEL;
55 else
56 buttons = GTK_BUTTONS_OK;
57 }
58
59 if (style & wxICON_EXCLAMATION)
60 type = GTK_MESSAGE_WARNING;
61 else if (style & wxICON_ERROR)
62 type = GTK_MESSAGE_ERROR;
63 else if (style & wxICON_INFORMATION)
64 type = GTK_MESSAGE_INFO;
65 else if (style & wxICON_QUESTION)
66 type = GTK_MESSAGE_QUESTION;
67 else
68 {
69 // GTK+ doesn't have a "typeless" msg box, so try to auto detect...
70 type = style & wxYES ? GTK_MESSAGE_QUESTION : GTK_MESSAGE_INFO;
71 }
72
73 m_widget = gtk_message_dialog_new(m_parent ?
74 GTK_WINDOW(m_parent->m_widget) : NULL,
75 GTK_DIALOG_MODAL,
76 type, buttons,
77 "%s", (const char*)wxGTK_CONV(m_message));
78 if (m_caption != wxMessageBoxCaptionStr)
79 gtk_window_set_title(GTK_WINDOW(m_widget), wxGTK_CONV(m_caption));
80
81 if (style & wxYES_NO)
82 {
83 if (style & wxCANCEL)
84 gtk_dialog_add_button(GTK_DIALOG(m_widget), GTK_STOCK_CANCEL,
85 GTK_RESPONSE_CANCEL);
86 if (style & wxNO_DEFAULT)
87 gtk_dialog_set_default_response(GTK_DIALOG(m_widget), GTK_RESPONSE_NO);
88 else
89 gtk_dialog_set_default_response(GTK_DIALOG(m_widget), GTK_RESPONSE_YES);
90 }
91
92 if (m_parent)
93 gtk_window_set_transient_for(GTK_WINDOW(m_widget),
94 GTK_WINDOW(m_parent->m_widget));
95 }
96
97 wxMessageDialog::~wxMessageDialog()
98 {
99 }
100
101 int wxMessageDialog::ShowModal()
102 {
103 // This should be necessary, but otherwise the
104 // parent TLW will disappear..
105 if (m_parent)
106 gtk_window_present( GTK_WINDOW(m_parent->m_widget) );
107
108 gint result = gtk_dialog_run(GTK_DIALOG(m_widget));
109 gtk_widget_destroy(m_widget);
110 m_widget = NULL;
111
112 switch (result)
113 {
114 default:
115 wxFAIL_MSG(_T("unexpected GtkMessageDialog return code"));
116 // fall through
117
118 case GTK_RESPONSE_CANCEL:
119 case GTK_RESPONSE_DELETE_EVENT:
120 case GTK_RESPONSE_CLOSE:
121 return wxID_CANCEL;
122 case GTK_RESPONSE_OK:
123 return wxID_OK;
124 case GTK_RESPONSE_YES:
125 return wxID_YES;
126 case GTK_RESPONSE_NO:
127 return wxID_NO;
128 }
129 }
130
131
132 #endif // wxUSE_MSGDLG && defined(__WXGTK20__) && !defined(__WXGPE__)