]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/aboutdlg.cpp
Fix stc doxygen warnings and regen stc files.
[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
a11a0ead
VZ
6// Copyright: (c) 2006 Vadim Zeitlin <vadim@wxwindows.org>
7// Licence: wxWindows licence
8///////////////////////////////////////////////////////////////////////////////
9
10// ============================================================================
11// declarations
12// ============================================================================
13
14// ----------------------------------------------------------------------------
15// headers
16// ----------------------------------------------------------------------------
17
18// for compilers that support precompilation, includes "wx.h".
19#include "wx/wxprec.h"
20
4e621d24 21#if wxUSE_ABOUTDLG
a11a0ead 22
9dc44eff
PC
23#include "wx/aboutdlg.h"
24
a11a0ead 25#ifndef WX_PRECOMP
6225e6e1 26 #include "wx/utils.h" // for wxLaunchDefaultBrowser()
a11a0ead
VZ
27#endif //WX_PRECOMP
28
9dc44eff 29#include <gtk/gtk.h>
a11a0ead 30#include "wx/gtk/private.h"
9dc44eff 31#include "wx/gtk/private/gtk2-compat.h"
a11a0ead
VZ
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
9dc44eff
PC
104extern "C" {
105static void wxGtkAboutDialogOnClose(GtkAboutDialog *about)
9948db2b
VZ
106{
107 gtk_widget_destroy(GTK_WIDGET(about));
350bedb4
VZ
108 if ( about == gs_aboutDialog )
109 gs_aboutDialog = NULL;
9948db2b 110}
9dc44eff 111}
9948db2b 112
9dc44eff
PC
113#ifdef __WXGTK3__
114extern "C" {
115static gboolean activate_link(GtkAboutDialog*, const char* link, void* dontIgnore)
116{
117 if (dontIgnore)
118 {
119 wxLaunchDefaultBrowser(wxGTK_CONV_BACK_SYS(link));
120 return true;
121 }
122 return false;
123}
124}
125#else
126extern "C" {
127static void wxGtkAboutDialogOnLink(GtkAboutDialog*, const char* link, void*)
6225e6e1 128{
30083ad8 129 wxLaunchDefaultBrowser(wxGTK_CONV_BACK_SYS(link));
6225e6e1 130}
9dc44eff
PC
131}
132#endif
6225e6e1 133
c173e541 134void wxAboutBox(const wxAboutDialogInfo& info, wxWindow* WXUNUSED(parent))
a11a0ead 135{
c49ba211
PC
136 // don't create another dialog if one is already present
137 if ( !gs_aboutDialog )
138 gs_aboutDialog = GTK_ABOUT_DIALOG(gtk_about_dialog_new());
139
140 GtkAboutDialog * const dlg = gs_aboutDialog;
141 gtk_about_dialog_set_program_name(dlg, wxGTK_CONV_SYS(info.GetName()));
142 if ( info.HasVersion() )
143 gtk_about_dialog_set_version(dlg, wxGTK_CONV_SYS(info.GetVersion()));
144 else
145 gtk_about_dialog_set_version(dlg, NULL);
146 if ( info.HasCopyright() )
147 gtk_about_dialog_set_copyright(dlg, wxGTK_CONV_SYS(info.GetCopyrightToDisplay()));
148 else
149 gtk_about_dialog_set_copyright(dlg, NULL);
150 if ( info.HasDescription() )
151 gtk_about_dialog_set_comments(dlg, wxGTK_CONV_SYS(info.GetDescription()));
152 else
153 gtk_about_dialog_set_comments(dlg, NULL);
154 if ( info.HasLicence() )
155 gtk_about_dialog_set_license(dlg, wxGTK_CONV_SYS(info.GetLicence()));
156 else
157 gtk_about_dialog_set_license(dlg, NULL);
158
159 wxIcon icon = info.GetIcon();
160 if ( icon.IsOk() )
161 gtk_about_dialog_set_logo(dlg, info.GetIcon().GetPixbuf());
162
163 if ( info.HasWebSite() )
a11a0ead 164 {
9dc44eff 165#ifdef __WXGTK3__
c49ba211 166 g_signal_connect(dlg, "activate-link", G_CALLBACK(activate_link), dlg);
9dc44eff 167#else
c49ba211
PC
168 // NB: must be called before gtk_about_dialog_set_website() as
169 // otherwise it has no effect (although GTK+ docs don't mention
170 // this...)
171 gtk_about_dialog_set_url_hook(wxGtkAboutDialogOnLink, NULL, NULL);
9dc44eff 172#endif
6225e6e1 173
c49ba211
PC
174 gtk_about_dialog_set_website(dlg, wxGTK_CONV_SYS(info.GetWebSiteURL()));
175 gtk_about_dialog_set_website_label
176 (
177 dlg,
178 wxGTK_CONV_SYS(info.GetWebSiteDescription())
179 );
180 }
181 else
182 {
183 gtk_about_dialog_set_website(dlg, NULL);
184 gtk_about_dialog_set_website_label(dlg, NULL);
9dc44eff 185#ifdef __WXGTK3__
c49ba211 186 g_signal_connect(dlg, "activate-link", G_CALLBACK(activate_link), NULL);
9dc44eff 187#else
c49ba211 188 gtk_about_dialog_set_url_hook(NULL, NULL, NULL);
9dc44eff 189#endif
c49ba211 190 }
a11a0ead 191
c49ba211
PC
192 if ( info.HasDevelopers() )
193 gtk_about_dialog_set_authors(dlg, GtkArray(info.GetDevelopers()));
194 else
195 gtk_about_dialog_set_authors(dlg, GtkArray());
196 if ( info.HasDocWriters() )
197 gtk_about_dialog_set_documenters(dlg, GtkArray(info.GetDocWriters()));
198 else
199 gtk_about_dialog_set_documenters(dlg, GtkArray());
200 if ( info.HasArtists() )
201 gtk_about_dialog_set_artists(dlg, GtkArray(info.GetArtists()));
202 else
203 gtk_about_dialog_set_artists(dlg, GtkArray());
204
205 wxString transCredits;
206 if ( info.HasTranslators() )
207 {
208 const wxArrayString& translators = info.GetTranslators();
209 const size_t count = translators.size();
210 for ( size_t n = 0; n < count; n++ )
fb4f85bf 211 {
c49ba211 212 transCredits << translators[n] << wxT('\n');
fb4f85bf 213 }
c49ba211
PC
214 }
215 else // no translators explicitly specified
216 {
217 // maybe we have translator credits in the message catalog?
218 wxString translator = _("translator-credits");
219
220 // gtk_about_dialog_set_translator_credits() is smart enough to
221 // detect if "translator-credits" is untranslated and hide the
222 // translators tab in that case, however it will still show the
223 // "credits" button, (at least GTK 2.10.6) even if there are no
224 // credits informations at all, so we still need to do the check
225 // ourselves
226 if ( translator != wxT("translator-credits") ) // untranslated!
227 transCredits = translator;
228 }
fb4f85bf 229
c49ba211
PC
230 if ( !transCredits.empty() )
231 gtk_about_dialog_set_translator_credits(dlg, wxGTK_CONV_SYS(transCredits));
232 else
233 gtk_about_dialog_set_translator_credits(dlg, NULL);
a11a0ead 234
c49ba211
PC
235 g_signal_connect(dlg, "response",
236 G_CALLBACK(wxGtkAboutDialogOnClose), NULL);
9948db2b 237
c49ba211 238 gtk_window_present(GTK_WINDOW(dlg));
a11a0ead
VZ
239}
240
4e621d24 241#endif // wxUSE_ABOUTDLG