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