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 // GtkArray: temporary array of GTK strings
35 // ----------------------------------------------------------------------------
43 // Create empty GtkArray
44 GtkArray() : m_strings(0), m_count(0)
48 // Create GtkArray from wxArrayString. Note that the created object is
49 // only valid as long as 'a' is!
50 GtkArray(const wxArrayString
& a
)
53 m_strings
= new const gchar
*[m_count
+ 1];
55 for ( size_t n
= 0; n
< m_count
; n
++ )
57 #if wxUSE_UNICODE_UTF8
58 m_strings
[n
] = a
[n
].utf8_str();
60 m_strings
[n
] = wxGTK_CONV_SYS(a
[n
]).release();
64 // array must be NULL-terminated
65 m_strings
[m_count
] = NULL
;
68 operator const gchar
**() const { return m_strings
; }
72 #if !wxUSE_UNICODE_UTF8
73 for ( size_t n
= 0; n
< m_count
; n
++ )
74 free(const_cast<gchar
*>(m_strings
[n
]));
81 const gchar
**m_strings
;
84 DECLARE_NO_COPY_CLASS(GtkArray
)
87 } // anonymous namespace
89 // ============================================================================
91 // ============================================================================
93 // GTK+ about dialog is modeless, keep track of it in this variable
94 static GtkAboutDialog
*gs_aboutDialog
= NULL
;
97 wxGtkAboutDialogOnClose(GtkAboutDialog
*about
)
99 gtk_widget_destroy(GTK_WIDGET(about
));
100 if ( about
== gs_aboutDialog
)
101 gs_aboutDialog
= NULL
;
105 wxGtkAboutDialogOnLink(GtkAboutDialog
* WXUNUSED(about
),
107 gpointer
WXUNUSED(data
))
109 wxLaunchDefaultBrowser(wxGTK_CONV_BACK_SYS(link
));
112 void wxAboutBox(const wxAboutDialogInfo
& info
)
114 if ( !gtk_check_version(2,6,0) )
116 // don't create another dialog if one is already present
117 if ( !gs_aboutDialog
)
118 gs_aboutDialog
= GTK_ABOUT_DIALOG(gtk_about_dialog_new());
120 GtkAboutDialog
* const dlg
= gs_aboutDialog
;
121 gtk_about_dialog_set_name(dlg
, wxGTK_CONV_SYS(info
.GetName()));
122 if ( info
.HasVersion() )
123 gtk_about_dialog_set_version(dlg
, wxGTK_CONV_SYS(info
.GetVersion()));
125 gtk_about_dialog_set_version(dlg
, NULL
);
126 if ( info
.HasCopyright() )
127 gtk_about_dialog_set_copyright(dlg
, wxGTK_CONV_SYS(info
.GetCopyrightToDisplay()));
129 gtk_about_dialog_set_copyright(dlg
, NULL
);
130 if ( info
.HasDescription() )
131 gtk_about_dialog_set_comments(dlg
, wxGTK_CONV_SYS(info
.GetDescription()));
133 gtk_about_dialog_set_comments(dlg
, NULL
);
134 if ( info
.HasLicence() )
135 gtk_about_dialog_set_license(dlg
, wxGTK_CONV_SYS(info
.GetLicence()));
137 gtk_about_dialog_set_license(dlg
, NULL
);
139 wxIcon icon
= info
.GetIcon();
141 gtk_about_dialog_set_logo(dlg
, info
.GetIcon().GetPixbuf());
143 if ( info
.HasWebSite() )
145 // NB: must be called before gtk_about_dialog_set_website() as
146 // otherwise it has no effect (although GTK+ docs don't mention
148 gtk_about_dialog_set_url_hook(wxGtkAboutDialogOnLink
, NULL
, NULL
);
150 gtk_about_dialog_set_website(dlg
, wxGTK_CONV_SYS(info
.GetWebSiteURL()));
151 gtk_about_dialog_set_website_label
154 wxGTK_CONV_SYS(info
.GetWebSiteDescription())
159 gtk_about_dialog_set_website(dlg
, NULL
);
160 gtk_about_dialog_set_website_label(dlg
, NULL
);
161 gtk_about_dialog_set_url_hook(NULL
, NULL
, NULL
);
164 if ( info
.HasDevelopers() )
165 gtk_about_dialog_set_authors(dlg
, GtkArray(info
.GetDevelopers()));
167 gtk_about_dialog_set_authors(dlg
, GtkArray());
168 if ( info
.HasDocWriters() )
169 gtk_about_dialog_set_documenters(dlg
, GtkArray(info
.GetDocWriters()));
171 gtk_about_dialog_set_documenters(dlg
, GtkArray());
172 if ( info
.HasArtists() )
173 gtk_about_dialog_set_artists(dlg
, GtkArray(info
.GetArtists()));
175 gtk_about_dialog_set_artists(dlg
, GtkArray());
177 wxString transCredits
;
178 if ( info
.HasTranslators() )
180 const wxArrayString
& translators
= info
.GetTranslators();
181 const size_t count
= translators
.size();
182 for ( size_t n
= 0; n
< count
; n
++ )
184 transCredits
<< translators
[n
] << _T('\n');
187 else // no translators explicitely specified
189 // maybe we have translator credits in the message catalog?
190 wxString translator
= _("translator-credits");
192 // gtk_about_dialog_set_translator_credits() is smart enough to
193 // detect if "translator-credits" is untranslated and hide the
194 // translators tab in that case, however it will still show the
195 // "credits" button, (at least GTK 2.10.6) even if there are no
196 // credits informations at all, so we still need to do the check
198 if ( translator
!= wxT("translator-credits") ) // untranslated!
199 transCredits
= translator
;
202 if ( !transCredits
.empty() )
203 gtk_about_dialog_set_translator_credits(dlg
, wxGTK_CONV_SYS(transCredits
));
205 gtk_about_dialog_set_translator_credits(dlg
, NULL
);
207 g_signal_connect(dlg
, "response",
208 G_CALLBACK(wxGtkAboutDialogOnClose
), NULL
);
210 gtk_window_present(GTK_WINDOW(dlg
));
214 // native about dialog not available, fall back to the generic one
215 wxGenericAboutBox(info
);
218 #endif // wxUSE_ABOUTDLG && GTK+ 2.6+