1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/aboutdlg.cpp
3 // Purpose: native GTK+ wxAboutBox() implementation
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2006 Vadim Zeitlin <vadim@wxwindows.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // for compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
24 #include "wx/aboutdlg.h"
27 #include "wx/utils.h" // for wxLaunchDefaultBrowser()
31 #include "wx/gtk/private.h"
32 #include "wx/gtk/private/gtk2-compat.h"
34 // ----------------------------------------------------------------------------
35 // GtkArray: temporary array of GTK strings
36 // ----------------------------------------------------------------------------
44 // Create empty GtkArray
45 GtkArray() : m_strings(0), m_count(0)
49 // Create GtkArray from wxArrayString. Note that the created object is
50 // only valid as long as 'a' is!
51 GtkArray(const wxArrayString
& a
)
54 m_strings
= new const gchar
*[m_count
+ 1];
56 for ( size_t n
= 0; n
< m_count
; n
++ )
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
73 // array must be NULL-terminated
74 m_strings
[m_count
] = NULL
;
77 operator const gchar
**() const { return m_strings
; }
82 for ( size_t n
= 0; n
< m_count
; n
++ )
83 free(const_cast<gchar
*>(m_strings
[n
]));
90 const gchar
**m_strings
;
93 wxDECLARE_NO_COPY_CLASS(GtkArray
);
96 } // anonymous namespace
98 // ============================================================================
100 // ============================================================================
102 // GTK+ about dialog is modeless, keep track of it in this variable
103 static GtkAboutDialog
*gs_aboutDialog
= NULL
;
106 static void wxGtkAboutDialogOnClose(GtkAboutDialog
*about
)
108 gtk_widget_destroy(GTK_WIDGET(about
));
109 if ( about
== gs_aboutDialog
)
110 gs_aboutDialog
= NULL
;
116 static gboolean
activate_link(GtkAboutDialog
*, const char* link
, void* dontIgnore
)
120 wxLaunchDefaultBrowser(wxGTK_CONV_BACK_SYS(link
));
128 static void wxGtkAboutDialogOnLink(GtkAboutDialog
*, const char* link
, void*)
130 wxLaunchDefaultBrowser(wxGTK_CONV_BACK_SYS(link
));
135 void wxAboutBox(const wxAboutDialogInfo
& info
, wxWindow
* WXUNUSED(parent
))
138 // don't create another dialog if one is already present
139 if ( !gs_aboutDialog
)
140 gs_aboutDialog
= GTK_ABOUT_DIALOG(gtk_about_dialog_new());
142 GtkAboutDialog
* const dlg
= gs_aboutDialog
;
143 gtk_about_dialog_set_program_name(dlg
, wxGTK_CONV_SYS(info
.GetName()));
144 if ( info
.HasVersion() )
145 gtk_about_dialog_set_version(dlg
, wxGTK_CONV_SYS(info
.GetVersion()));
147 gtk_about_dialog_set_version(dlg
, NULL
);
148 if ( info
.HasCopyright() )
149 gtk_about_dialog_set_copyright(dlg
, wxGTK_CONV_SYS(info
.GetCopyrightToDisplay()));
151 gtk_about_dialog_set_copyright(dlg
, NULL
);
152 if ( info
.HasDescription() )
153 gtk_about_dialog_set_comments(dlg
, wxGTK_CONV_SYS(info
.GetDescription()));
155 gtk_about_dialog_set_comments(dlg
, NULL
);
156 if ( info
.HasLicence() )
157 gtk_about_dialog_set_license(dlg
, wxGTK_CONV_SYS(info
.GetLicence()));
159 gtk_about_dialog_set_license(dlg
, NULL
);
161 wxIcon icon
= info
.GetIcon();
163 gtk_about_dialog_set_logo(dlg
, info
.GetIcon().GetPixbuf());
165 if ( info
.HasWebSite() )
168 g_signal_connect(dlg
, "activate-link", G_CALLBACK(activate_link
), dlg
);
170 // NB: must be called before gtk_about_dialog_set_website() as
171 // otherwise it has no effect (although GTK+ docs don't mention
173 gtk_about_dialog_set_url_hook(wxGtkAboutDialogOnLink
, NULL
, NULL
);
176 gtk_about_dialog_set_website(dlg
, wxGTK_CONV_SYS(info
.GetWebSiteURL()));
177 gtk_about_dialog_set_website_label
180 wxGTK_CONV_SYS(info
.GetWebSiteDescription())
185 gtk_about_dialog_set_website(dlg
, NULL
);
186 gtk_about_dialog_set_website_label(dlg
, NULL
);
188 g_signal_connect(dlg
, "activate-link", G_CALLBACK(activate_link
), NULL
);
190 gtk_about_dialog_set_url_hook(NULL
, NULL
, NULL
);
194 if ( info
.HasDevelopers() )
195 gtk_about_dialog_set_authors(dlg
, GtkArray(info
.GetDevelopers()));
197 gtk_about_dialog_set_authors(dlg
, GtkArray());
198 if ( info
.HasDocWriters() )
199 gtk_about_dialog_set_documenters(dlg
, GtkArray(info
.GetDocWriters()));
201 gtk_about_dialog_set_documenters(dlg
, GtkArray());
202 if ( info
.HasArtists() )
203 gtk_about_dialog_set_artists(dlg
, GtkArray(info
.GetArtists()));
205 gtk_about_dialog_set_artists(dlg
, GtkArray());
207 wxString transCredits
;
208 if ( info
.HasTranslators() )
210 const wxArrayString
& translators
= info
.GetTranslators();
211 const size_t count
= translators
.size();
212 for ( size_t n
= 0; n
< count
; n
++ )
214 transCredits
<< translators
[n
] << wxT('\n');
217 else // no translators explicitly specified
219 // maybe we have translator credits in the message catalog?
220 wxString translator
= _("translator-credits");
222 // gtk_about_dialog_set_translator_credits() is smart enough to
223 // detect if "translator-credits" is untranslated and hide the
224 // translators tab in that case, however it will still show the
225 // "credits" button, (at least GTK 2.10.6) even if there are no
226 // credits informations at all, so we still need to do the check
228 if ( translator
!= wxT("translator-credits") ) // untranslated!
229 transCredits
= translator
;
232 if ( !transCredits
.empty() )
233 gtk_about_dialog_set_translator_credits(dlg
, wxGTK_CONV_SYS(transCredits
));
235 gtk_about_dialog_set_translator_credits(dlg
, NULL
);
237 g_signal_connect(dlg
, "response",
238 G_CALLBACK(wxGtkAboutDialogOnClose
), NULL
);
240 gtk_window_present(GTK_WINDOW(dlg
));
244 #endif // wxUSE_ABOUTDLG