]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/aboutdlg.cpp
7be26532d951b473a5097d8b79f06de9cbc90424
[wxWidgets.git] / src / gtk / aboutdlg.cpp
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
25 #include "wx/utils.h" // for wxLaunchDefaultBrowser()
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
37 namespace
38 {
39
40 class GtkArray
41 {
42 public:
43 // Create empty GtkArray
44 GtkArray() : m_strings(0), m_count(0)
45 {
46 }
47
48 // Create GtkArray from wxArrayString. Note that the created object is
49 // only valid as long as 'a' is!
50 GtkArray(const wxArrayString& a)
51 {
52 m_count = a.size();
53 m_strings = new const gchar *[m_count + 1];
54
55 for ( size_t n = 0; n < m_count; n++ )
56 {
57 #if wxUSE_UNICODE_UTF8
58 m_strings[n] = a[n].utf8_str();
59 #else
60 m_strings[n] = wxGTK_CONV_SYS(a[n]).release();
61 #endif
62 }
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 {
72 #if !wxUSE_UNICODE_UTF8
73 for ( size_t n = 0; n < m_count; n++ )
74 free(const_cast<gchar *>(m_strings[n]));
75 #endif
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
87 } // anonymous namespace
88
89 // ============================================================================
90 // implementation
91 // ============================================================================
92
93 // GTK+ about dialog is modeless, keep track of it in this variable
94 static GtkAboutDialog *gs_aboutDialog = NULL;
95
96 extern "C" void
97 wxGtkAboutDialogOnClose(GtkAboutDialog *about)
98 {
99 gtk_widget_destroy(GTK_WIDGET(about));
100 if ( about == gs_aboutDialog )
101 gs_aboutDialog = NULL;
102 }
103
104 extern "C" void
105 wxGtkAboutDialogOnLink(GtkAboutDialog * WXUNUSED(about),
106 const gchar *link,
107 gpointer WXUNUSED(data))
108 {
109 wxLaunchDefaultBrowser(wxGTK_CONV_BACK_SYS(link));
110 }
111
112 void wxAboutBox(const wxAboutDialogInfo& info)
113 {
114 if ( !gtk_check_version(2,6,0) )
115 {
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;
121 gtk_about_dialog_set_name(dlg, wxGTK_CONV_SYS(info.GetName()));
122 if ( info.HasVersion() )
123 gtk_about_dialog_set_version(dlg, wxGTK_CONV_SYS(info.GetVersion()));
124 else
125 gtk_about_dialog_set_version(dlg, NULL);
126 if ( info.HasCopyright() )
127 gtk_about_dialog_set_copyright(dlg, wxGTK_CONV_SYS(info.GetCopyrightToDisplay()));
128 else
129 gtk_about_dialog_set_copyright(dlg, NULL);
130 if ( info.HasDescription() )
131 gtk_about_dialog_set_comments(dlg, wxGTK_CONV_SYS(info.GetDescription()));
132 else
133 gtk_about_dialog_set_comments(dlg, NULL);
134 if ( info.HasLicence() )
135 gtk_about_dialog_set_license(dlg, wxGTK_CONV_SYS(info.GetLicence()));
136 else
137 gtk_about_dialog_set_license(dlg, NULL);
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 {
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
150 gtk_about_dialog_set_website(dlg, wxGTK_CONV_SYS(info.GetWebSiteURL()));
151 gtk_about_dialog_set_website_label
152 (
153 dlg,
154 wxGTK_CONV_SYS(info.GetWebSiteDescription())
155 );
156 }
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 }
163
164 if ( info.HasDevelopers() )
165 gtk_about_dialog_set_authors(dlg, GtkArray(info.GetDevelopers()));
166 else
167 gtk_about_dialog_set_authors(dlg, GtkArray());
168 if ( info.HasDocWriters() )
169 gtk_about_dialog_set_documenters(dlg, GtkArray(info.GetDocWriters()));
170 else
171 gtk_about_dialog_set_documenters(dlg, GtkArray());
172 if ( info.HasArtists() )
173 gtk_about_dialog_set_artists(dlg, GtkArray(info.GetArtists()));
174 else
175 gtk_about_dialog_set_artists(dlg, GtkArray());
176
177 wxString transCredits;
178 if ( info.HasTranslators() )
179 {
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 }
186 }
187 else // no translators explicitely specified
188 {
189 // maybe we have translator credits in the message catalog?
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;
200 }
201
202 if ( !transCredits.empty() )
203 gtk_about_dialog_set_translator_credits(dlg, wxGTK_CONV_SYS(transCredits));
204 else
205 gtk_about_dialog_set_translator_credits(dlg, NULL);
206
207 g_signal_connect(dlg, "response",
208 G_CALLBACK(wxGtkAboutDialogOnClose), NULL);
209
210 gtk_window_present(GTK_WINDOW(dlg));
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+