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