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