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"
22 #if wxUSE_ABOUTDLG && defined(__WXGTK26__)
25 #include "wx/utils.h" // for wxLaunchDefaultBrowser()
28 #include "wx/aboutdlg.h"
29 #include "wx/generic/aboutdlgg.h"
31 #include "wx/gtk/private.h"
33 // ----------------------------------------------------------------------------
34 // GtkStr: temporary GTK string
35 // ----------------------------------------------------------------------------
37 class GtkStr
: public wxGtkString
40 GtkStr(const wxString
& s
)
41 : wxGtkString(wx_const_cast(char *, wxGTK_CONV_SYS(s
).release()))
46 // ----------------------------------------------------------------------------
47 // GtkArray: temporary array of GTK strings
48 // ----------------------------------------------------------------------------
53 GtkArray(const wxArrayString
& a
)
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();
60 // array must be NULL-terminated
61 m_strings
[m_count
] = NULL
;
64 operator const gchar
**() const { return m_strings
; }
68 for ( size_t n
= 0; n
< m_count
; n
++ )
69 free(wx_const_cast(gchar
*, m_strings
[n
]));
75 const gchar
**m_strings
;
78 DECLARE_NO_COPY_CLASS(GtkArray
)
81 // ============================================================================
83 // ============================================================================
86 wxGtkAboutDialogOnClose(GtkAboutDialog
*about
)
88 gtk_widget_destroy(GTK_WIDGET(about
));
92 wxGtkAboutDialogOnLink(GtkAboutDialog
* WXUNUSED(about
),
94 gpointer
WXUNUSED(data
))
96 wxLaunchDefaultBrowser(wxGTK_CONV_BACK_SYS(link
));
99 void wxAboutBox(const wxAboutDialogInfo
& info
)
101 if ( !gtk_check_version(2,6,0) )
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()));
114 wxIcon icon
= info
.GetIcon();
116 gtk_about_dialog_set_logo(dlg
, info
.GetIcon().GetPixbuf());
118 if ( info
.HasWebSite() )
120 // NB: must be called before gtk_about_dialog_set_website() as
121 // otherwise it has no effect (although GTK+ docs don't mention
123 gtk_about_dialog_set_url_hook(wxGtkAboutDialogOnLink
, NULL
, NULL
);
125 gtk_about_dialog_set_website(dlg
, GtkStr(info
.GetWebSiteURL()));
126 gtk_about_dialog_set_website_label
129 GtkStr(info
.GetWebSiteDescription())
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()));
140 wxString transCredits
;
141 if ( info
.HasTranslators() )
143 const wxArrayString
& translators
= info
.GetTranslators();
144 const size_t count
= translators
.size();
145 for ( size_t n
= 0; n
< count
; n
++ )
147 transCredits
<< translators
[n
] << _T('\n');
150 else // no translators explicitely specified
152 // maybe we have translator credits in the message catalog?
153 wxString translator
= _("translator-credits");
155 // gtk_about_dialog_set_translator_credits() is smart enough to
156 // detect if "translator-credits" is untranslated and hide the
157 // translators tab in that case, however it will still show the
158 // "credits" button, (at least GTK 2.10.6) even if there are no
159 // credits informations at all, so we still need to do the check
161 if ( translator
!= wxT("translator-credits") ) // untranslated!
162 transCredits
= translator
;
165 if ( !transCredits
.empty() )
166 gtk_about_dialog_set_translator_credits(dlg
, GtkStr(transCredits
));
168 g_signal_connect(dlg
, "response",
169 G_CALLBACK(wxGtkAboutDialogOnClose
), NULL
);
171 gtk_widget_show(GTK_WIDGET(dlg
));
175 // native about dialog not available, fall back to the generic one
176 wxGenericAboutBox(info
);
179 #endif // wxUSE_ABOUTDLG && GTK+ 2.6+