1
///////////////////////////////////////////////////////////////////////////////
2
// Name: src/gtk/aboutdlg.cpp
3
// Purpose: native GTK+ wxAboutBox() implementation
4
// Author: Vadim Zeitlin
6
// RCS-ID: $Id: aboutdlg.cpp 71894 2012-06-30 20:39:06Z PC $
7
// Copyright: (c) 2006 Vadim Zeitlin <vadim@wxwindows.org>
8
// Licence: wxWindows licence
9
///////////////////////////////////////////////////////////////////////////////
11
// ============================================================================
13
// ============================================================================
15
// ----------------------------------------------------------------------------
17
// ----------------------------------------------------------------------------
19
// for compilers that support precompilation, includes "wx.h".
20
#include "wx/wxprec.h"
22
#if wxUSE_ABOUTDLG && defined(__WXGTK26__)
24
#include "wx/aboutdlg.h"
27
#include "wx/utils.h" // for wxLaunchDefaultBrowser()
31
#include "wx/generic/aboutdlgg.h"
35
#include "wx/gtk/private.h"
36
#include "wx/gtk/private/gtk2-compat.h"
38
// ----------------------------------------------------------------------------
39
// GtkArray: temporary array of GTK strings
40
// ----------------------------------------------------------------------------
48
// Create empty GtkArray
49
GtkArray() : m_strings(0), m_count(0)
53
// Create GtkArray from wxArrayString. Note that the created object is
54
// only valid as long as 'a' is!
55
GtkArray(const wxArrayString& a)
58
m_strings = new const gchar *[m_count + 1];
60
for ( size_t n = 0; n < m_count; n++ )
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
73
m_strings[n] = wxGTK_CONV_SYS(a[n]).release();
74
#endif // wxUSE_UNICODE/!wxUSE_UNICODE
77
// array must be NULL-terminated
78
m_strings[m_count] = NULL;
81
operator const gchar **() const { return m_strings; }
86
for ( size_t n = 0; n < m_count; n++ )
87
free(const_cast<gchar *>(m_strings[n]));
94
const gchar **m_strings;
97
wxDECLARE_NO_COPY_CLASS(GtkArray);
100
} // anonymous namespace
102
// ============================================================================
104
// ============================================================================
106
// GTK+ about dialog is modeless, keep track of it in this variable
107
static GtkAboutDialog *gs_aboutDialog = NULL;
110
static void wxGtkAboutDialogOnClose(GtkAboutDialog *about)
112
gtk_widget_destroy(GTK_WIDGET(about));
113
if ( about == gs_aboutDialog )
114
gs_aboutDialog = NULL;
120
static gboolean activate_link(GtkAboutDialog*, const char* link, void* dontIgnore)
124
wxLaunchDefaultBrowser(wxGTK_CONV_BACK_SYS(link));
132
static void wxGtkAboutDialogOnLink(GtkAboutDialog*, const char* link, void*)
134
wxLaunchDefaultBrowser(wxGTK_CONV_BACK_SYS(link));
139
void wxAboutBox(const wxAboutDialogInfo& info, wxWindow* WXUNUSED(parent))
142
if ( !gtk_check_version(2,6,0) )
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());
149
GtkAboutDialog * const dlg = gs_aboutDialog;
150
gtk_about_dialog_set_program_name(dlg, wxGTK_CONV_SYS(info.GetName()));
151
if ( info.HasVersion() )
152
gtk_about_dialog_set_version(dlg, wxGTK_CONV_SYS(info.GetVersion()));
154
gtk_about_dialog_set_version(dlg, NULL);
155
if ( info.HasCopyright() )
156
gtk_about_dialog_set_copyright(dlg, wxGTK_CONV_SYS(info.GetCopyrightToDisplay()));
158
gtk_about_dialog_set_copyright(dlg, NULL);
159
if ( info.HasDescription() )
160
gtk_about_dialog_set_comments(dlg, wxGTK_CONV_SYS(info.GetDescription()));
162
gtk_about_dialog_set_comments(dlg, NULL);
163
if ( info.HasLicence() )
164
gtk_about_dialog_set_license(dlg, wxGTK_CONV_SYS(info.GetLicence()));
166
gtk_about_dialog_set_license(dlg, NULL);
168
wxIcon icon = info.GetIcon();
170
gtk_about_dialog_set_logo(dlg, info.GetIcon().GetPixbuf());
172
if ( info.HasWebSite() )
175
g_signal_connect(dlg, "activate-link", G_CALLBACK(activate_link), dlg);
177
// NB: must be called before gtk_about_dialog_set_website() as
178
// otherwise it has no effect (although GTK+ docs don't mention
180
gtk_about_dialog_set_url_hook(wxGtkAboutDialogOnLink, NULL, NULL);
183
gtk_about_dialog_set_website(dlg, wxGTK_CONV_SYS(info.GetWebSiteURL()));
184
gtk_about_dialog_set_website_label
187
wxGTK_CONV_SYS(info.GetWebSiteDescription())
192
gtk_about_dialog_set_website(dlg, NULL);
193
gtk_about_dialog_set_website_label(dlg, NULL);
195
g_signal_connect(dlg, "activate-link", G_CALLBACK(activate_link), NULL);
197
gtk_about_dialog_set_url_hook(NULL, NULL, NULL);
201
if ( info.HasDevelopers() )
202
gtk_about_dialog_set_authors(dlg, GtkArray(info.GetDevelopers()));
204
gtk_about_dialog_set_authors(dlg, GtkArray());
205
if ( info.HasDocWriters() )
206
gtk_about_dialog_set_documenters(dlg, GtkArray(info.GetDocWriters()));
208
gtk_about_dialog_set_documenters(dlg, GtkArray());
209
if ( info.HasArtists() )
210
gtk_about_dialog_set_artists(dlg, GtkArray(info.GetArtists()));
212
gtk_about_dialog_set_artists(dlg, GtkArray());
214
wxString transCredits;
215
if ( info.HasTranslators() )
217
const wxArrayString& translators = info.GetTranslators();
218
const size_t count = translators.size();
219
for ( size_t n = 0; n < count; n++ )
221
transCredits << translators[n] << wxT('\n');
224
else // no translators explicitly specified
226
// maybe we have translator credits in the message catalog?
227
wxString translator = _("translator-credits");
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
235
if ( translator != wxT("translator-credits") ) // untranslated!
236
transCredits = translator;
239
if ( !transCredits.empty() )
240
gtk_about_dialog_set_translator_credits(dlg, wxGTK_CONV_SYS(transCredits));
242
gtk_about_dialog_set_translator_credits(dlg, NULL);
244
g_signal_connect(dlg, "response",
245
G_CALLBACK(wxGtkAboutDialogOnClose), NULL);
247
gtk_window_present(GTK_WINDOW(dlg));
251
// native about dialog not available, fall back to the generic one
252
wxGenericAboutBox(info);
256
#endif // wxUSE_ABOUTDLG && GTK+ 2.6+