]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/aboutdlg.cpp
cleanup for 10.5
[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 // GtkStr: temporary GTK string
35 // ----------------------------------------------------------------------------
36
37 class GtkStr : public wxGtkString
38 {
39 public:
40 GtkStr(const wxString& s)
41 : wxGtkString(wx_const_cast(char *, wxGTK_CONV_SYS(s).release()))
42 {
43 }
44 };
45
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
85 extern "C" void
86 wxGtkAboutDialogOnClose(GtkAboutDialog *about)
87 {
88 gtk_widget_destroy(GTK_WIDGET(about));
89 }
90
91 extern "C" void
92 wxGtkAboutDialogOnLink(GtkAboutDialog * WXUNUSED(about),
93 const gchar *link,
94 gpointer WXUNUSED(data))
95 {
96 wxLaunchDefaultBrowser(wxGTK_CONV_BACK(link));
97 }
98
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());
104 gtk_about_dialog_set_name(dlg, GtkStr(info.GetName()));
105 if ( info.HasVersion() )
106 gtk_about_dialog_set_version(dlg, GtkStr(info.GetVersion()));
107 if ( info.HasCopyright() )
108 gtk_about_dialog_set_copyright(dlg, GtkStr(info.GetCopyright()));
109 if ( info.HasDescription() )
110 gtk_about_dialog_set_comments(dlg, GtkStr(info.GetDescription()));
111 if ( info.HasLicence() )
112 gtk_about_dialog_set_license(dlg, GtkStr(info.GetLicence()));
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 {
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
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 );
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()));
139
140 wxString transCredits;
141 if ( info.HasTranslators() )
142 {
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 }
149 }
150 else // no translators explicitely specified
151 {
152 // maybe we have translator credits in the message catalog?
153 transCredits = _("translator-credits");
154 }
155
156 gtk_about_dialog_set_translator_credits(dlg, GtkStr(transCredits));
157
158 g_signal_connect(dlg, "response",
159 G_CALLBACK(wxGtkAboutDialogOnClose), NULL);
160
161 gtk_widget_show(GTK_WIDGET(dlg));
162 return;
163 }
164
165 // native about dialog not available, fall back to the generic one
166 wxGenericAboutBox(info);
167 }
168
169 #endif // wxUSE_ABOUTDLG && GTK+ 2.6+