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