]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/aboutdlg.cpp
merge DoDrawText() and DoDrawRotatedText() into one function
[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
23
24 #include "wx/aboutdlg.h"
25
26 #ifndef WX_PRECOMP
27 #include "wx/utils.h" // for wxLaunchDefaultBrowser()
28 #endif //WX_PRECOMP
29
30 #include <gtk/gtk.h>
31 #include "wx/gtk/private.h"
32 #include "wx/gtk/private/gtk2-compat.h"
33
34 // ----------------------------------------------------------------------------
35 // GtkArray: temporary array of GTK strings
36 // ----------------------------------------------------------------------------
37
38 namespace
39 {
40
41 class GtkArray
42 {
43 public:
44 // Create empty GtkArray
45 GtkArray() : m_strings(0), m_count(0)
46 {
47 }
48
49 // Create GtkArray from wxArrayString. Note that the created object is
50 // only valid as long as 'a' is!
51 GtkArray(const wxArrayString& a)
52 {
53 m_count = a.size();
54 m_strings = new const gchar *[m_count + 1];
55
56 for ( size_t n = 0; n < m_count; n++ )
57 {
58 #if wxUSE_UNICODE
59 // notice that there is no need to copy the string pointer here
60 // because this class is used only as a temporary and during its
61 // existence the pointer persists in wxString which uses it either
62 // for internal representation (in wxUSE_UNICODE_UTF8 case) or as
63 // cached m_convertedToChar (in wxUSE_UNICODE_WCHAR case)
64 m_strings[n] = wxGTK_CONV_SYS(a[n]);
65 #else // !wxUSE_UNICODE
66 // and in ANSI build we can simply borrow the pointer from
67 // wxCharBuffer (which owns it in this case) instead of copying it
68 // but we then become responsible for freeing it
69 m_strings[n] = wxGTK_CONV_SYS(a[n]).release();
70 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
71 }
72
73 // array must be NULL-terminated
74 m_strings[m_count] = NULL;
75 }
76
77 operator const gchar **() const { return m_strings; }
78
79 ~GtkArray()
80 {
81 #if !wxUSE_UNICODE
82 for ( size_t n = 0; n < m_count; n++ )
83 free(const_cast<gchar *>(m_strings[n]));
84 #endif
85
86 delete [] m_strings;
87 }
88
89 private:
90 const gchar **m_strings;
91 size_t m_count;
92
93 wxDECLARE_NO_COPY_CLASS(GtkArray);
94 };
95
96 } // anonymous namespace
97
98 // ============================================================================
99 // implementation
100 // ============================================================================
101
102 // GTK+ about dialog is modeless, keep track of it in this variable
103 static GtkAboutDialog *gs_aboutDialog = NULL;
104
105 extern "C" {
106 static void wxGtkAboutDialogOnClose(GtkAboutDialog *about)
107 {
108 gtk_widget_destroy(GTK_WIDGET(about));
109 if ( about == gs_aboutDialog )
110 gs_aboutDialog = NULL;
111 }
112 }
113
114 #ifdef __WXGTK3__
115 extern "C" {
116 static gboolean activate_link(GtkAboutDialog*, const char* link, void* dontIgnore)
117 {
118 if (dontIgnore)
119 {
120 wxLaunchDefaultBrowser(wxGTK_CONV_BACK_SYS(link));
121 return true;
122 }
123 return false;
124 }
125 }
126 #else
127 extern "C" {
128 static void wxGtkAboutDialogOnLink(GtkAboutDialog*, const char* link, void*)
129 {
130 wxLaunchDefaultBrowser(wxGTK_CONV_BACK_SYS(link));
131 }
132 }
133 #endif
134
135 void wxAboutBox(const wxAboutDialogInfo& info, wxWindow* WXUNUSED(parent))
136 {
137 // don't create another dialog if one is already present
138 if ( !gs_aboutDialog )
139 gs_aboutDialog = GTK_ABOUT_DIALOG(gtk_about_dialog_new());
140
141 GtkAboutDialog * const dlg = gs_aboutDialog;
142 gtk_about_dialog_set_program_name(dlg, wxGTK_CONV_SYS(info.GetName()));
143 if ( info.HasVersion() )
144 gtk_about_dialog_set_version(dlg, wxGTK_CONV_SYS(info.GetVersion()));
145 else
146 gtk_about_dialog_set_version(dlg, NULL);
147 if ( info.HasCopyright() )
148 gtk_about_dialog_set_copyright(dlg, wxGTK_CONV_SYS(info.GetCopyrightToDisplay()));
149 else
150 gtk_about_dialog_set_copyright(dlg, NULL);
151 if ( info.HasDescription() )
152 gtk_about_dialog_set_comments(dlg, wxGTK_CONV_SYS(info.GetDescription()));
153 else
154 gtk_about_dialog_set_comments(dlg, NULL);
155 if ( info.HasLicence() )
156 gtk_about_dialog_set_license(dlg, wxGTK_CONV_SYS(info.GetLicence()));
157 else
158 gtk_about_dialog_set_license(dlg, NULL);
159
160 wxIcon icon = info.GetIcon();
161 if ( icon.IsOk() )
162 gtk_about_dialog_set_logo(dlg, info.GetIcon().GetPixbuf());
163
164 if ( info.HasWebSite() )
165 {
166 #ifdef __WXGTK3__
167 g_signal_connect(dlg, "activate-link", G_CALLBACK(activate_link), dlg);
168 #else
169 // NB: must be called before gtk_about_dialog_set_website() as
170 // otherwise it has no effect (although GTK+ docs don't mention
171 // this...)
172 gtk_about_dialog_set_url_hook(wxGtkAboutDialogOnLink, NULL, NULL);
173 #endif
174
175 gtk_about_dialog_set_website(dlg, wxGTK_CONV_SYS(info.GetWebSiteURL()));
176 gtk_about_dialog_set_website_label
177 (
178 dlg,
179 wxGTK_CONV_SYS(info.GetWebSiteDescription())
180 );
181 }
182 else
183 {
184 gtk_about_dialog_set_website(dlg, NULL);
185 gtk_about_dialog_set_website_label(dlg, NULL);
186 #ifdef __WXGTK3__
187 g_signal_connect(dlg, "activate-link", G_CALLBACK(activate_link), NULL);
188 #else
189 gtk_about_dialog_set_url_hook(NULL, NULL, NULL);
190 #endif
191 }
192
193 if ( info.HasDevelopers() )
194 gtk_about_dialog_set_authors(dlg, GtkArray(info.GetDevelopers()));
195 else
196 gtk_about_dialog_set_authors(dlg, GtkArray());
197 if ( info.HasDocWriters() )
198 gtk_about_dialog_set_documenters(dlg, GtkArray(info.GetDocWriters()));
199 else
200 gtk_about_dialog_set_documenters(dlg, GtkArray());
201 if ( info.HasArtists() )
202 gtk_about_dialog_set_artists(dlg, GtkArray(info.GetArtists()));
203 else
204 gtk_about_dialog_set_artists(dlg, GtkArray());
205
206 wxString transCredits;
207 if ( info.HasTranslators() )
208 {
209 const wxArrayString& translators = info.GetTranslators();
210 const size_t count = translators.size();
211 for ( size_t n = 0; n < count; n++ )
212 {
213 transCredits << translators[n] << wxT('\n');
214 }
215 }
216 else // no translators explicitly specified
217 {
218 // maybe we have translator credits in the message catalog?
219 wxString translator = _("translator-credits");
220
221 // gtk_about_dialog_set_translator_credits() is smart enough to
222 // detect if "translator-credits" is untranslated and hide the
223 // translators tab in that case, however it will still show the
224 // "credits" button, (at least GTK 2.10.6) even if there are no
225 // credits informations at all, so we still need to do the check
226 // ourselves
227 if ( translator != wxT("translator-credits") ) // untranslated!
228 transCredits = translator;
229 }
230
231 if ( !transCredits.empty() )
232 gtk_about_dialog_set_translator_credits(dlg, wxGTK_CONV_SYS(transCredits));
233 else
234 gtk_about_dialog_set_translator_credits(dlg, NULL);
235
236 g_signal_connect(dlg, "response",
237 G_CALLBACK(wxGtkAboutDialogOnClose), NULL);
238
239 gtk_window_present(GTK_WINDOW(dlg));
240 }
241
242 #endif // wxUSE_ABOUTDLG