]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/msgdlg.cpp
corrected off by 1 error in cMB2WC() call (thanks valgrind)
[wxWidgets.git] / src / gtk / msgdlg.cpp
CommitLineData
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
30IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
31
32wxMessageDialog::wxMessageDialog(wxWindow *parent,
33 const wxString& message,
34 const wxString& caption,
35 long style,
36 const wxPoint& WXUNUSED(pos))
2afb9e16
VZ
37 : wxMessageDialogBase(GetParentForModalDialog(parent),
38 message,
39 caption,
40 style)
13a7abf9 41{
2afb9e16 42}
13a7abf9 43
2afb9e16
VZ
44void wxMessageDialog::GTKCreateMsgDialog()
45{
b63b07a8 46 GtkMessageType type = GTK_MESSAGE_ERROR;
13a7abf9 47 GtkButtonsType buttons = GTK_BUTTONS_OK;
b63b07a8 48
2afb9e16 49 if (m_dialogStyle & wxYES_NO)
13a7abf9 50 {
2afb9e16 51 if (m_dialogStyle & wxCANCEL)
f4322df6
VZ
52 buttons = GTK_BUTTONS_NONE;
53 else
54 buttons = GTK_BUTTONS_YES_NO;
13a7abf9
VS
55 }
56
2afb9e16 57 if (m_dialogStyle & wxOK)
13a7abf9 58 {
2afb9e16 59 if (m_dialogStyle & wxCANCEL)
13a7abf9
VS
60 buttons = GTK_BUTTONS_OK_CANCEL;
61 else
62 buttons = GTK_BUTTONS_OK;
63 }
b63b07a8 64
2afb9e16 65 if (m_dialogStyle & wxICON_EXCLAMATION)
13a7abf9 66 type = GTK_MESSAGE_WARNING;
2afb9e16 67 else if (m_dialogStyle & wxICON_ERROR)
13a7abf9 68 type = GTK_MESSAGE_ERROR;
2afb9e16 69 else if (m_dialogStyle & wxICON_INFORMATION)
13a7abf9 70 type = GTK_MESSAGE_INFO;
2afb9e16 71 else if (m_dialogStyle & wxICON_QUESTION)
13a7abf9 72 type = GTK_MESSAGE_QUESTION;
b63b07a8 73 else
e0ae1a0a
VZ
74 {
75 // GTK+ doesn't have a "typeless" msg box, so try to auto detect...
2afb9e16 76 type = m_dialogStyle & wxYES ? GTK_MESSAGE_QUESTION : GTK_MESSAGE_INFO;
e0ae1a0a 77 }
13a7abf9 78
2afb9e16 79 wxString message;
ff9bb105 80#if GTK_CHECK_VERSION(2, 6, 0)
2afb9e16 81 bool needsExtMessage = false;
1878d1ec 82 if ( gtk_check_version(2, 6, 0) == NULL && !m_extendedMessage.empty() )
2afb9e16
VZ
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,
b2ce5e1b 95 GTK_DIALOG_MODAL,
2afb9e16
VZ
96 type,
97 buttons,
98 "%s",
99 (const char*)wxGTK_CONV(message));
100
ff9bb105 101#if GTK_CHECK_VERSION(2, 6, 0)
2afb9e16
VZ
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
13a7abf9 113 if (m_caption != wxMessageBoxCaptionStr)
b2ce5e1b 114 gtk_window_set_title(GTK_WINDOW(m_widget), wxGTK_CONV(m_caption));
13a7abf9 115
2afb9e16 116 if (m_dialogStyle & wxYES_NO)
13a7abf9 117 {
2afb9e16 118 if (m_dialogStyle & wxCANCEL)
f4322df6 119 {
d182ca1b
RR
120 gtk_dialog_add_button(GTK_DIALOG(m_widget), GTK_STOCK_NO,
121 GTK_RESPONSE_NO);
b2ce5e1b 122 gtk_dialog_add_button(GTK_DIALOG(m_widget), GTK_STOCK_CANCEL,
13a7abf9 123 GTK_RESPONSE_CANCEL);
d182ca1b
RR
124 gtk_dialog_add_button(GTK_DIALOG(m_widget), GTK_STOCK_YES,
125 GTK_RESPONSE_YES);
f4322df6 126 }
2afb9e16 127 if (m_dialogStyle & wxNO_DEFAULT)
b2ce5e1b 128 gtk_dialog_set_default_response(GTK_DIALOG(m_widget), GTK_RESPONSE_NO);
13a7abf9 129 else
b2ce5e1b 130 gtk_dialog_set_default_response(GTK_DIALOG(m_widget), GTK_RESPONSE_YES);
13a7abf9 131 }
633c71ef 132
3b439e60 133 if (m_parent)
633c71ef
VS
134 gtk_window_set_transient_for(GTK_WINDOW(m_widget),
135 GTK_WINDOW(m_parent->m_widget));
b2ce5e1b 136}
e5b50758 137
b2ce5e1b
RD
138int wxMessageDialog::ShowModal()
139{
2afb9e16
VZ
140 if ( !m_widget )
141 {
142 GTKCreateMsgDialog();
143 wxCHECK_MSG( m_widget, wxID_CANCEL,
144 _T("failed to create GtkMessageDialog") );
145 }
146
3b439e60
RR
147 // This should be necessary, but otherwise the
148 // parent TLW will disappear..
149 if (m_parent)
150 gtk_window_present( GTK_WINDOW(m_parent->m_widget) );
e5b50758 151
b2ce5e1b
RD
152 gint result = gtk_dialog_run(GTK_DIALOG(m_widget));
153 gtk_widget_destroy(m_widget);
154 m_widget = NULL;
13a7abf9
VS
155
156 switch (result)
157 {
158 default:
159 wxFAIL_MSG(_T("unexpected GtkMessageDialog return code"));
160 // fall through
161
b63b07a8 162 case GTK_RESPONSE_CANCEL:
0e4a7045
VS
163 case GTK_RESPONSE_DELETE_EVENT:
164 case GTK_RESPONSE_CLOSE:
13a7abf9
VS
165 return wxID_CANCEL;
166 case GTK_RESPONSE_OK:
167 return wxID_OK;
168 case GTK_RESPONSE_YES:
169 return wxID_YES;
170 case GTK_RESPONSE_NO:
171 return wxID_NO;
172 }
173}
174
b2ce5e1b 175
88a7a4e1 176#endif // wxUSE_MSGDLG && defined(__WXGTK20__) && !defined(__WXGPE__)