]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/aboutdlg.cpp
Fix compiler warnings in the IE backend.
[wxWidgets.git] / src / gtk / aboutdlg.cpp
CommitLineData
a11a0ead
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: src/gtk/aboutdlg.cpp
3// Purpose: native GTK+ wxAboutBox() implementation
4// Author: Vadim Zeitlin
5// Created: 2006-10-08
6// RCS-ID: $Id$
7// Copyright: (c) 2006 Vadim Zeitlin <vadim@wxwindows.org>
8// Licence: wxWindows licence
9///////////////////////////////////////////////////////////////////////////////
10
11// ============================================================================
12// declarations
13// ============================================================================
14
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
19// for compilers that support precompilation, includes "wx.h".
20#include "wx/wxprec.h"
21
22#if wxUSE_ABOUTDLG && defined(__WXGTK26__)
23
24#ifndef WX_PRECOMP
6225e6e1 25 #include "wx/utils.h" // for wxLaunchDefaultBrowser()
a11a0ead
VZ
26#endif //WX_PRECOMP
27
28#include "wx/aboutdlg.h"
29#include "wx/generic/aboutdlgg.h"
30
31#include "wx/gtk/private.h"
32
33// ----------------------------------------------------------------------------
34// GtkArray: temporary array of GTK strings
35// ----------------------------------------------------------------------------
36
c1d028f2
VS
37namespace
38{
39
a11a0ead
VZ
40class GtkArray
41{
42public:
49b3b52c
VZ
43 // Create empty GtkArray
44 GtkArray() : m_strings(0), m_count(0)
45 {
46 }
953aebc2 47
7e9b47df
VS
48 // Create GtkArray from wxArrayString. Note that the created object is
49 // only valid as long as 'a' is!
a11a0ead
VZ
50 GtkArray(const wxArrayString& a)
51 {
52 m_count = a.size();
53 m_strings = new const gchar *[m_count + 1];
7e9b47df 54
a11a0ead 55 for ( size_t n = 0; n < m_count; n++ )
7e9b47df 56 {
f9cff6e1
VZ
57#if wxUSE_UNICODE
58 // notice that there is no need to copy the string pointer here
59 // because this class is used only as a temporary and during its
60 // existence the pointer persists in wxString which uses it either
61 // for internal representation (in wxUSE_UNICODE_UTF8 case) or as
62 // cached m_convertedToChar (in wxUSE_UNICODE_WCHAR case)
63 m_strings[n] = wxGTK_CONV_SYS(a[n]);
64#else // !wxUSE_UNICODE
65 // and in ANSI build we can simply borrow the pointer from
66 // wxCharBuffer (which owns it in this case) instead of copying it
67 // but we then become responsible for freeing it
a11a0ead 68 m_strings[n] = wxGTK_CONV_SYS(a[n]).release();
f9cff6e1 69#endif // wxUSE_UNICODE/!wxUSE_UNICODE
7e9b47df 70 }
a11a0ead
VZ
71
72 // array must be NULL-terminated
73 m_strings[m_count] = NULL;
74 }
75
76 operator const gchar **() const { return m_strings; }
77
78 ~GtkArray()
79 {
f9cff6e1 80#if !wxUSE_UNICODE
a11a0ead 81 for ( size_t n = 0; n < m_count; n++ )
5c33522f 82 free(const_cast<gchar *>(m_strings[n]));
7e9b47df 83#endif
a11a0ead
VZ
84
85 delete [] m_strings;
86 }
87
88private:
89 const gchar **m_strings;
90 size_t m_count;
91
c0c133e1 92 wxDECLARE_NO_COPY_CLASS(GtkArray);
a11a0ead
VZ
93};
94
c1d028f2
VS
95} // anonymous namespace
96
a11a0ead
VZ
97// ============================================================================
98// implementation
99// ============================================================================
100
350bedb4
VZ
101// GTK+ about dialog is modeless, keep track of it in this variable
102static GtkAboutDialog *gs_aboutDialog = NULL;
103
9948db2b
VZ
104extern "C" void
105wxGtkAboutDialogOnClose(GtkAboutDialog *about)
106{
107 gtk_widget_destroy(GTK_WIDGET(about));
350bedb4
VZ
108 if ( about == gs_aboutDialog )
109 gs_aboutDialog = NULL;
9948db2b
VZ
110}
111
6225e6e1
VZ
112extern "C" void
113wxGtkAboutDialogOnLink(GtkAboutDialog * WXUNUSED(about),
114 const gchar *link,
115 gpointer WXUNUSED(data))
116{
30083ad8 117 wxLaunchDefaultBrowser(wxGTK_CONV_BACK_SYS(link));
6225e6e1
VZ
118}
119
c173e541 120void wxAboutBox(const wxAboutDialogInfo& info, wxWindow* WXUNUSED(parent))
a11a0ead
VZ
121{
122 if ( !gtk_check_version(2,6,0) )
123 {
350bedb4
VZ
124 // don't create another dialog if one is already present
125 if ( !gs_aboutDialog )
126 gs_aboutDialog = GTK_ABOUT_DIALOG(gtk_about_dialog_new());
127
128 GtkAboutDialog * const dlg = gs_aboutDialog;
385e8575 129 gtk_about_dialog_set_program_name(dlg, wxGTK_CONV_SYS(info.GetName()));
a11a0ead 130 if ( info.HasVersion() )
6e9b0919 131 gtk_about_dialog_set_version(dlg, wxGTK_CONV_SYS(info.GetVersion()));
49b3b52c
VZ
132 else
133 gtk_about_dialog_set_version(dlg, NULL);
a11a0ead 134 if ( info.HasCopyright() )
953aebc2 135 gtk_about_dialog_set_copyright(dlg, wxGTK_CONV_SYS(info.GetCopyrightToDisplay()));
49b3b52c
VZ
136 else
137 gtk_about_dialog_set_copyright(dlg, NULL);
a11a0ead 138 if ( info.HasDescription() )
6e9b0919 139 gtk_about_dialog_set_comments(dlg, wxGTK_CONV_SYS(info.GetDescription()));
49b3b52c
VZ
140 else
141 gtk_about_dialog_set_comments(dlg, NULL);
a11a0ead 142 if ( info.HasLicence() )
6e9b0919 143 gtk_about_dialog_set_license(dlg, wxGTK_CONV_SYS(info.GetLicence()));
49b3b52c
VZ
144 else
145 gtk_about_dialog_set_license(dlg, NULL);
a11a0ead
VZ
146
147 wxIcon icon = info.GetIcon();
148 if ( icon.Ok() )
149 gtk_about_dialog_set_logo(dlg, info.GetIcon().GetPixbuf());
150
151 if ( info.HasWebSite() )
152 {
6225e6e1
VZ
153 // NB: must be called before gtk_about_dialog_set_website() as
154 // otherwise it has no effect (although GTK+ docs don't mention
155 // this...)
156 gtk_about_dialog_set_url_hook(wxGtkAboutDialogOnLink, NULL, NULL);
157
6e9b0919 158 gtk_about_dialog_set_website(dlg, wxGTK_CONV_SYS(info.GetWebSiteURL()));
9b82d31b
VZ
159 gtk_about_dialog_set_website_label
160 (
161 dlg,
6e9b0919 162 wxGTK_CONV_SYS(info.GetWebSiteDescription())
9b82d31b 163 );
a11a0ead 164 }
49b3b52c
VZ
165 else
166 {
167 gtk_about_dialog_set_website(dlg, NULL);
168 gtk_about_dialog_set_website_label(dlg, NULL);
169 gtk_about_dialog_set_url_hook(NULL, NULL, NULL);
170 }
a11a0ead
VZ
171
172 if ( info.HasDevelopers() )
173 gtk_about_dialog_set_authors(dlg, GtkArray(info.GetDevelopers()));
49b3b52c
VZ
174 else
175 gtk_about_dialog_set_authors(dlg, GtkArray());
a11a0ead
VZ
176 if ( info.HasDocWriters() )
177 gtk_about_dialog_set_documenters(dlg, GtkArray(info.GetDocWriters()));
49b3b52c
VZ
178 else
179 gtk_about_dialog_set_documenters(dlg, GtkArray());
a11a0ead
VZ
180 if ( info.HasArtists() )
181 gtk_about_dialog_set_artists(dlg, GtkArray(info.GetArtists()));
49b3b52c
VZ
182 else
183 gtk_about_dialog_set_artists(dlg, GtkArray());
fb4f85bf
VZ
184
185 wxString transCredits;
a11a0ead 186 if ( info.HasTranslators() )
9b82d31b 187 {
fb4f85bf
VZ
188 const wxArrayString& translators = info.GetTranslators();
189 const size_t count = translators.size();
190 for ( size_t n = 0; n < count; n++ )
191 {
9a83f860 192 transCredits << translators[n] << wxT('\n');
fb4f85bf 193 }
9b82d31b 194 }
4c51a665 195 else // no translators explicitly specified
fb4f85bf
VZ
196 {
197 // maybe we have translator credits in the message catalog?
c153cc08
VZ
198 wxString translator = _("translator-credits");
199
200 // gtk_about_dialog_set_translator_credits() is smart enough to
201 // detect if "translator-credits" is untranslated and hide the
202 // translators tab in that case, however it will still show the
203 // "credits" button, (at least GTK 2.10.6) even if there are no
204 // credits informations at all, so we still need to do the check
205 // ourselves
206 if ( translator != wxT("translator-credits") ) // untranslated!
207 transCredits = translator;
fb4f85bf
VZ
208 }
209
c153cc08 210 if ( !transCredits.empty() )
6e9b0919 211 gtk_about_dialog_set_translator_credits(dlg, wxGTK_CONV_SYS(transCredits));
49b3b52c
VZ
212 else
213 gtk_about_dialog_set_translator_credits(dlg, NULL);
a11a0ead 214
9948db2b
VZ
215 g_signal_connect(dlg, "response",
216 G_CALLBACK(wxGtkAboutDialogOnClose), NULL);
217
350bedb4 218 gtk_window_present(GTK_WINDOW(dlg));
a11a0ead
VZ
219 return;
220 }
221
222 // native about dialog not available, fall back to the generic one
223 wxGenericAboutBox(info);
224}
225
226#endif // wxUSE_ABOUTDLG && GTK+ 2.6+