]>
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 | ||
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 |
37 | namespace |
38 | { | |
39 | ||
a11a0ead VZ |
40 | class GtkArray |
41 | { | |
42 | public: | |
49b3b52c VZ |
43 | // Create empty GtkArray |
44 | GtkArray() : m_strings(0), m_count(0) | |
45 | { | |
46 | } | |
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 VS |
56 | { |
57 | #if wxUSE_UNICODE_UTF8 | |
58 | m_strings[n] = a[n].utf8_str(); | |
59 | #else | |
a11a0ead | 60 | m_strings[n] = wxGTK_CONV_SYS(a[n]).release(); |
7e9b47df VS |
61 | #endif |
62 | } | |
a11a0ead VZ |
63 | |
64 | // array must be NULL-terminated | |
65 | m_strings[m_count] = NULL; | |
66 | } | |
67 | ||
68 | operator const gchar **() const { return m_strings; } | |
69 | ||
70 | ~GtkArray() | |
71 | { | |
7e9b47df | 72 | #if !wxUSE_UNICODE_UTF8 |
a11a0ead | 73 | for ( size_t n = 0; n < m_count; n++ ) |
5c33522f | 74 | free(const_cast<gchar *>(m_strings[n])); |
7e9b47df | 75 | #endif |
a11a0ead VZ |
76 | |
77 | delete [] m_strings; | |
78 | } | |
79 | ||
80 | private: | |
81 | const gchar **m_strings; | |
82 | size_t m_count; | |
83 | ||
84 | DECLARE_NO_COPY_CLASS(GtkArray) | |
85 | }; | |
86 | ||
c1d028f2 VS |
87 | } // anonymous namespace |
88 | ||
a11a0ead VZ |
89 | // ============================================================================ |
90 | // implementation | |
91 | // ============================================================================ | |
92 | ||
350bedb4 VZ |
93 | // GTK+ about dialog is modeless, keep track of it in this variable |
94 | static GtkAboutDialog *gs_aboutDialog = NULL; | |
95 | ||
9948db2b VZ |
96 | extern "C" void |
97 | wxGtkAboutDialogOnClose(GtkAboutDialog *about) | |
98 | { | |
99 | gtk_widget_destroy(GTK_WIDGET(about)); | |
350bedb4 VZ |
100 | if ( about == gs_aboutDialog ) |
101 | gs_aboutDialog = NULL; | |
9948db2b VZ |
102 | } |
103 | ||
6225e6e1 VZ |
104 | extern "C" void |
105 | wxGtkAboutDialogOnLink(GtkAboutDialog * WXUNUSED(about), | |
106 | const gchar *link, | |
107 | gpointer WXUNUSED(data)) | |
108 | { | |
30083ad8 | 109 | wxLaunchDefaultBrowser(wxGTK_CONV_BACK_SYS(link)); |
6225e6e1 VZ |
110 | } |
111 | ||
a11a0ead VZ |
112 | void wxAboutBox(const wxAboutDialogInfo& info) |
113 | { | |
114 | if ( !gtk_check_version(2,6,0) ) | |
115 | { | |
350bedb4 VZ |
116 | // don't create another dialog if one is already present |
117 | if ( !gs_aboutDialog ) | |
118 | gs_aboutDialog = GTK_ABOUT_DIALOG(gtk_about_dialog_new()); | |
119 | ||
120 | GtkAboutDialog * const dlg = gs_aboutDialog; | |
6e9b0919 | 121 | gtk_about_dialog_set_name(dlg, wxGTK_CONV_SYS(info.GetName())); |
a11a0ead | 122 | if ( info.HasVersion() ) |
6e9b0919 | 123 | gtk_about_dialog_set_version(dlg, wxGTK_CONV_SYS(info.GetVersion())); |
49b3b52c VZ |
124 | else |
125 | gtk_about_dialog_set_version(dlg, NULL); | |
a11a0ead | 126 | if ( info.HasCopyright() ) |
6e9b0919 | 127 | gtk_about_dialog_set_copyright(dlg, wxGTK_CONV_SYS(info.GetCopyright())); |
49b3b52c VZ |
128 | else |
129 | gtk_about_dialog_set_copyright(dlg, NULL); | |
a11a0ead | 130 | if ( info.HasDescription() ) |
6e9b0919 | 131 | gtk_about_dialog_set_comments(dlg, wxGTK_CONV_SYS(info.GetDescription())); |
49b3b52c VZ |
132 | else |
133 | gtk_about_dialog_set_comments(dlg, NULL); | |
a11a0ead | 134 | if ( info.HasLicence() ) |
6e9b0919 | 135 | gtk_about_dialog_set_license(dlg, wxGTK_CONV_SYS(info.GetLicence())); |
49b3b52c VZ |
136 | else |
137 | gtk_about_dialog_set_license(dlg, NULL); | |
a11a0ead VZ |
138 | |
139 | wxIcon icon = info.GetIcon(); | |
140 | if ( icon.Ok() ) | |
141 | gtk_about_dialog_set_logo(dlg, info.GetIcon().GetPixbuf()); | |
142 | ||
143 | if ( info.HasWebSite() ) | |
144 | { | |
6225e6e1 VZ |
145 | // NB: must be called before gtk_about_dialog_set_website() as |
146 | // otherwise it has no effect (although GTK+ docs don't mention | |
147 | // this...) | |
148 | gtk_about_dialog_set_url_hook(wxGtkAboutDialogOnLink, NULL, NULL); | |
149 | ||
6e9b0919 | 150 | gtk_about_dialog_set_website(dlg, wxGTK_CONV_SYS(info.GetWebSiteURL())); |
9b82d31b VZ |
151 | gtk_about_dialog_set_website_label |
152 | ( | |
153 | dlg, | |
6e9b0919 | 154 | wxGTK_CONV_SYS(info.GetWebSiteDescription()) |
9b82d31b | 155 | ); |
a11a0ead | 156 | } |
49b3b52c VZ |
157 | else |
158 | { | |
159 | gtk_about_dialog_set_website(dlg, NULL); | |
160 | gtk_about_dialog_set_website_label(dlg, NULL); | |
161 | gtk_about_dialog_set_url_hook(NULL, NULL, NULL); | |
162 | } | |
a11a0ead VZ |
163 | |
164 | if ( info.HasDevelopers() ) | |
165 | gtk_about_dialog_set_authors(dlg, GtkArray(info.GetDevelopers())); | |
49b3b52c VZ |
166 | else |
167 | gtk_about_dialog_set_authors(dlg, GtkArray()); | |
a11a0ead VZ |
168 | if ( info.HasDocWriters() ) |
169 | gtk_about_dialog_set_documenters(dlg, GtkArray(info.GetDocWriters())); | |
49b3b52c VZ |
170 | else |
171 | gtk_about_dialog_set_documenters(dlg, GtkArray()); | |
a11a0ead VZ |
172 | if ( info.HasArtists() ) |
173 | gtk_about_dialog_set_artists(dlg, GtkArray(info.GetArtists())); | |
49b3b52c VZ |
174 | else |
175 | gtk_about_dialog_set_artists(dlg, GtkArray()); | |
fb4f85bf VZ |
176 | |
177 | wxString transCredits; | |
a11a0ead | 178 | if ( info.HasTranslators() ) |
9b82d31b | 179 | { |
fb4f85bf VZ |
180 | const wxArrayString& translators = info.GetTranslators(); |
181 | const size_t count = translators.size(); | |
182 | for ( size_t n = 0; n < count; n++ ) | |
183 | { | |
184 | transCredits << translators[n] << _T('\n'); | |
185 | } | |
9b82d31b | 186 | } |
fb4f85bf VZ |
187 | else // no translators explicitely specified |
188 | { | |
189 | // maybe we have translator credits in the message catalog? | |
c153cc08 VZ |
190 | wxString translator = _("translator-credits"); |
191 | ||
192 | // gtk_about_dialog_set_translator_credits() is smart enough to | |
193 | // detect if "translator-credits" is untranslated and hide the | |
194 | // translators tab in that case, however it will still show the | |
195 | // "credits" button, (at least GTK 2.10.6) even if there are no | |
196 | // credits informations at all, so we still need to do the check | |
197 | // ourselves | |
198 | if ( translator != wxT("translator-credits") ) // untranslated! | |
199 | transCredits = translator; | |
fb4f85bf VZ |
200 | } |
201 | ||
c153cc08 | 202 | if ( !transCredits.empty() ) |
6e9b0919 | 203 | gtk_about_dialog_set_translator_credits(dlg, wxGTK_CONV_SYS(transCredits)); |
49b3b52c VZ |
204 | else |
205 | gtk_about_dialog_set_translator_credits(dlg, NULL); | |
a11a0ead | 206 | |
9948db2b VZ |
207 | g_signal_connect(dlg, "response", |
208 | G_CALLBACK(wxGtkAboutDialogOnClose), NULL); | |
209 | ||
350bedb4 | 210 | gtk_window_present(GTK_WINDOW(dlg)); |
a11a0ead VZ |
211 | return; |
212 | } | |
213 | ||
214 | // native about dialog not available, fall back to the generic one | |
215 | wxGenericAboutBox(info); | |
216 | } | |
217 | ||
218 | #endif // wxUSE_ABOUTDLG && GTK+ 2.6+ |