]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/msgdlg.cpp
Fix various minor PS issues
[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 : wxMessageDialogBase(GetParentForModalDialog(parent),
38 message,
39 caption,
40 style)
41 {
42 }
43
44 void wxMessageDialog::GTKCreateMsgDialog()
45 {
46 GtkMessageType type = GTK_MESSAGE_ERROR;
47 GtkButtonsType buttons = GTK_BUTTONS_OK;
48
49 if (m_dialogStyle & wxYES_NO)
50 {
51 if (m_dialogStyle & wxCANCEL)
52 buttons = GTK_BUTTONS_NONE;
53 else
54 buttons = GTK_BUTTONS_YES_NO;
55 }
56
57 if (m_dialogStyle & wxOK)
58 {
59 if (m_dialogStyle & wxCANCEL)
60 buttons = GTK_BUTTONS_OK_CANCEL;
61 else
62 buttons = GTK_BUTTONS_OK;
63 }
64
65 if (m_dialogStyle & wxICON_EXCLAMATION)
66 type = GTK_MESSAGE_WARNING;
67 else if (m_dialogStyle & wxICON_ERROR)
68 type = GTK_MESSAGE_ERROR;
69 else if (m_dialogStyle & wxICON_INFORMATION)
70 type = GTK_MESSAGE_INFO;
71 else if (m_dialogStyle & wxICON_QUESTION)
72 type = GTK_MESSAGE_QUESTION;
73 else
74 {
75 // GTK+ doesn't have a "typeless" msg box, so try to auto detect...
76 type = m_dialogStyle & wxYES ? GTK_MESSAGE_QUESTION : GTK_MESSAGE_INFO;
77 }
78
79 wxString message;
80 #if GTK_CHECK_VERSION(2, 6, 0)
81 bool needsExtMessage = false;
82 if ( gtk_check_version(2, 6, 0) == NULL && !m_extendedMessage.empty() )
83 {
84 message = m_message;
85 needsExtMessage = true;
86 }
87 else // extended message not needed or not supported
88 #endif // GTK+ 2.4+
89 {
90 message = GetFullMessage();
91 }
92
93 m_widget = gtk_message_dialog_new(m_parent ? GTK_WINDOW(m_parent->m_widget)
94 : NULL,
95 GTK_DIALOG_MODAL,
96 type,
97 buttons,
98 "%s",
99 (const char*)wxGTK_CONV(message));
100
101 #if GTK_CHECK_VERSION(2, 6, 0)
102 if ( needsExtMessage )
103 {
104 gtk_message_dialog_format_secondary_text
105 (
106 (GtkMessageDialog *)m_widget,
107 "%s",
108 (const char *)wxGTK_CONV(m_extendedMessage)
109 );
110 }
111 #endif // GTK+ 2.4+
112
113 if (m_caption != wxMessageBoxCaptionStr)
114 gtk_window_set_title(GTK_WINDOW(m_widget), wxGTK_CONV(m_caption));
115
116 if (m_dialogStyle & wxYES_NO)
117 {
118 if (m_dialogStyle & wxCANCEL)
119 {
120 gtk_dialog_add_button(GTK_DIALOG(m_widget), GTK_STOCK_NO,
121 GTK_RESPONSE_NO);
122 gtk_dialog_add_button(GTK_DIALOG(m_widget), GTK_STOCK_CANCEL,
123 GTK_RESPONSE_CANCEL);
124 gtk_dialog_add_button(GTK_DIALOG(m_widget), GTK_STOCK_YES,
125 GTK_RESPONSE_YES);
126 }
127 if (m_dialogStyle & wxNO_DEFAULT)
128 gtk_dialog_set_default_response(GTK_DIALOG(m_widget), GTK_RESPONSE_NO);
129 else
130 gtk_dialog_set_default_response(GTK_DIALOG(m_widget), GTK_RESPONSE_YES);
131 }
132
133 if (m_parent)
134 gtk_window_set_transient_for(GTK_WINDOW(m_widget),
135 GTK_WINDOW(m_parent->m_widget));
136 }
137
138 int wxMessageDialog::ShowModal()
139 {
140 // break the mouse capture as it would interfere with modal dialog (see
141 // wxDialog::ShowModal)
142 wxWindow * const win = wxWindow::GetCapture();
143 if ( win )
144 win->GTKReleaseMouseAndNotify();
145
146 if ( !m_widget )
147 {
148 GTKCreateMsgDialog();
149 wxCHECK_MSG( m_widget, wxID_CANCEL,
150 _T("failed to create GtkMessageDialog") );
151 }
152
153 // This should be necessary, but otherwise the
154 // parent TLW will disappear..
155 if (m_parent)
156 gtk_window_present( GTK_WINDOW(m_parent->m_widget) );
157
158 gint result = gtk_dialog_run(GTK_DIALOG(m_widget));
159 gtk_widget_destroy(m_widget);
160 m_widget = NULL;
161
162 switch (result)
163 {
164 default:
165 wxFAIL_MSG(_T("unexpected GtkMessageDialog return code"));
166 // fall through
167
168 case GTK_RESPONSE_CANCEL:
169 case GTK_RESPONSE_DELETE_EVENT:
170 case GTK_RESPONSE_CLOSE:
171 return wxID_CANCEL;
172 case GTK_RESPONSE_OK:
173 return wxID_OK;
174 case GTK_RESPONSE_YES:
175 return wxID_YES;
176 case GTK_RESPONSE_NO:
177 return wxID_NO;
178 }
179 }
180
181
182 #endif // wxUSE_MSGDLG && defined(__WXGTK20__) && !defined(__WXGPE__)