]>
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 | ||
9b82d31b VZ |
33 | // ---------------------------------------------------------------------------- |
34 | // GtkStr: temporary GTK string | |
35 | // ---------------------------------------------------------------------------- | |
36 | ||
37 | class GtkStr : public wxGtkString | |
38 | { | |
39 | public: | |
40 | GtkStr(const wxString& s) | |
36183141 | 41 | : wxGtkString(wx_const_cast(char *, wxGTK_CONV_SYS(s).release())) |
9b82d31b VZ |
42 | { |
43 | } | |
44 | }; | |
45 | ||
a11a0ead VZ |
46 | // ---------------------------------------------------------------------------- |
47 | // GtkArray: temporary array of GTK strings | |
48 | // ---------------------------------------------------------------------------- | |
49 | ||
50 | class GtkArray | |
51 | { | |
52 | public: | |
53 | GtkArray(const wxArrayString& a) | |
54 | { | |
55 | m_count = a.size(); | |
56 | m_strings = new const gchar *[m_count + 1]; | |
57 | for ( size_t n = 0; n < m_count; n++ ) | |
58 | m_strings[n] = wxGTK_CONV_SYS(a[n]).release(); | |
59 | ||
60 | // array must be NULL-terminated | |
61 | m_strings[m_count] = NULL; | |
62 | } | |
63 | ||
64 | operator const gchar **() const { return m_strings; } | |
65 | ||
66 | ~GtkArray() | |
67 | { | |
68 | for ( size_t n = 0; n < m_count; n++ ) | |
69 | free(wx_const_cast(gchar *, m_strings[n])); | |
70 | ||
71 | delete [] m_strings; | |
72 | } | |
73 | ||
74 | private: | |
75 | const gchar **m_strings; | |
76 | size_t m_count; | |
77 | ||
78 | DECLARE_NO_COPY_CLASS(GtkArray) | |
79 | }; | |
80 | ||
81 | // ============================================================================ | |
82 | // implementation | |
83 | // ============================================================================ | |
84 | ||
9948db2b VZ |
85 | extern "C" void |
86 | wxGtkAboutDialogOnClose(GtkAboutDialog *about) | |
87 | { | |
88 | gtk_widget_destroy(GTK_WIDGET(about)); | |
89 | } | |
90 | ||
6225e6e1 VZ |
91 | extern "C" void |
92 | wxGtkAboutDialogOnLink(GtkAboutDialog * WXUNUSED(about), | |
93 | const gchar *link, | |
94 | gpointer WXUNUSED(data)) | |
95 | { | |
30083ad8 | 96 | wxLaunchDefaultBrowser(wxGTK_CONV_BACK_SYS(link)); |
6225e6e1 VZ |
97 | } |
98 | ||
a11a0ead VZ |
99 | void wxAboutBox(const wxAboutDialogInfo& info) |
100 | { | |
101 | if ( !gtk_check_version(2,6,0) ) | |
102 | { | |
103 | GtkAboutDialog * const dlg = GTK_ABOUT_DIALOG(gtk_about_dialog_new()); | |
9b82d31b | 104 | gtk_about_dialog_set_name(dlg, GtkStr(info.GetName())); |
a11a0ead | 105 | if ( info.HasVersion() ) |
9b82d31b | 106 | gtk_about_dialog_set_version(dlg, GtkStr(info.GetVersion())); |
a11a0ead | 107 | if ( info.HasCopyright() ) |
9b82d31b | 108 | gtk_about_dialog_set_copyright(dlg, GtkStr(info.GetCopyright())); |
a11a0ead | 109 | if ( info.HasDescription() ) |
9b82d31b | 110 | gtk_about_dialog_set_comments(dlg, GtkStr(info.GetDescription())); |
a11a0ead | 111 | if ( info.HasLicence() ) |
9b82d31b | 112 | gtk_about_dialog_set_license(dlg, GtkStr(info.GetLicence())); |
a11a0ead VZ |
113 | |
114 | wxIcon icon = info.GetIcon(); | |
115 | if ( icon.Ok() ) | |
116 | gtk_about_dialog_set_logo(dlg, info.GetIcon().GetPixbuf()); | |
117 | ||
118 | if ( info.HasWebSite() ) | |
119 | { | |
6225e6e1 VZ |
120 | // NB: must be called before gtk_about_dialog_set_website() as |
121 | // otherwise it has no effect (although GTK+ docs don't mention | |
122 | // this...) | |
123 | gtk_about_dialog_set_url_hook(wxGtkAboutDialogOnLink, NULL, NULL); | |
124 | ||
9b82d31b VZ |
125 | gtk_about_dialog_set_website(dlg, GtkStr(info.GetWebSiteURL())); |
126 | gtk_about_dialog_set_website_label | |
127 | ( | |
128 | dlg, | |
129 | GtkStr(info.GetWebSiteDescription()) | |
130 | ); | |
a11a0ead VZ |
131 | } |
132 | ||
133 | if ( info.HasDevelopers() ) | |
134 | gtk_about_dialog_set_authors(dlg, GtkArray(info.GetDevelopers())); | |
135 | if ( info.HasDocWriters() ) | |
136 | gtk_about_dialog_set_documenters(dlg, GtkArray(info.GetDocWriters())); | |
137 | if ( info.HasArtists() ) | |
138 | gtk_about_dialog_set_artists(dlg, GtkArray(info.GetArtists())); | |
fb4f85bf VZ |
139 | |
140 | wxString transCredits; | |
a11a0ead | 141 | if ( info.HasTranslators() ) |
9b82d31b | 142 | { |
fb4f85bf VZ |
143 | const wxArrayString& translators = info.GetTranslators(); |
144 | const size_t count = translators.size(); | |
145 | for ( size_t n = 0; n < count; n++ ) | |
146 | { | |
147 | transCredits << translators[n] << _T('\n'); | |
148 | } | |
9b82d31b | 149 | } |
fb4f85bf VZ |
150 | else // no translators explicitely specified |
151 | { | |
152 | // maybe we have translator credits in the message catalog? | |
c153cc08 VZ |
153 | wxString translator = _("translator-credits"); |
154 | ||
155 | // gtk_about_dialog_set_translator_credits() is smart enough to | |
156 | // detect if "translator-credits" is untranslated and hide the | |
157 | // translators tab in that case, however it will still show the | |
158 | // "credits" button, (at least GTK 2.10.6) even if there are no | |
159 | // credits informations at all, so we still need to do the check | |
160 | // ourselves | |
161 | if ( translator != wxT("translator-credits") ) // untranslated! | |
162 | transCredits = translator; | |
fb4f85bf VZ |
163 | } |
164 | ||
c153cc08 VZ |
165 | if ( !transCredits.empty() ) |
166 | gtk_about_dialog_set_translator_credits(dlg, GtkStr(transCredits)); | |
a11a0ead | 167 | |
9948db2b VZ |
168 | g_signal_connect(dlg, "response", |
169 | G_CALLBACK(wxGtkAboutDialogOnClose), NULL); | |
170 | ||
a11a0ead VZ |
171 | gtk_widget_show(GTK_WIDGET(dlg)); |
172 | return; | |
173 | } | |
174 | ||
175 | // native about dialog not available, fall back to the generic one | |
176 | wxGenericAboutBox(info); | |
177 | } | |
178 | ||
179 | #endif // wxUSE_ABOUTDLG && GTK+ 2.6+ |