]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/msgdlg.cpp
add wxUSE_TASKBARICON wrapper
[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{
7738af59
VZ
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
2afb9e16
VZ
146 if ( !m_widget )
147 {
148 GTKCreateMsgDialog();
149 wxCHECK_MSG( m_widget, wxID_CANCEL,
150 _T("failed to create GtkMessageDialog") );
151 }
152
3b439e60
RR
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) );
e5b50758 157
b2ce5e1b
RD
158 gint result = gtk_dialog_run(GTK_DIALOG(m_widget));
159 gtk_widget_destroy(m_widget);
160 m_widget = NULL;
13a7abf9
VS
161
162 switch (result)
163 {
164 default:
165 wxFAIL_MSG(_T("unexpected GtkMessageDialog return code"));
166 // fall through
167
b63b07a8 168 case GTK_RESPONSE_CANCEL:
0e4a7045
VS
169 case GTK_RESPONSE_DELETE_EVENT:
170 case GTK_RESPONSE_CLOSE:
13a7abf9
VS
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
b2ce5e1b 181
88a7a4e1 182#endif // wxUSE_MSGDLG && defined(__WXGTK20__) && !defined(__WXGPE__)