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
))
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());
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()));
146 gtk_about_dialog_set_version(dlg
, NULL
);
147 if ( info
.HasCopyright() )
148 gtk_about_dialog_set_copyright(dlg
, wxGTK_CONV_SYS(info
.GetCopyrightToDisplay()));
150 gtk_about_dialog_set_copyright(dlg
, NULL
);
151 if ( info
.HasDescription() )
152 gtk_about_dialog_set_comments(dlg
, wxGTK_CONV_SYS(info
.GetDescription()));
154 gtk_about_dialog_set_comments(dlg
, NULL
);
155 if ( info
.HasLicence() )
156 gtk_about_dialog_set_license(dlg
, wxGTK_CONV_SYS(info
.GetLicence()));
158 gtk_about_dialog_set_license(dlg
, NULL
);
160 wxIcon icon
= info
.GetIcon();
162 gtk_about_dialog_set_logo(dlg
, info
.GetIcon().GetPixbuf());
164 if ( info
.HasWebSite() )
167 g_signal_connect(dlg
, "activate-link", G_CALLBACK(activate_link
), dlg
);
169 // NB: must be called before gtk_about_dialog_set_website() as
170 // otherwise it has no effect (although GTK+ docs don't mention
172 gtk_about_dialog_set_url_hook(wxGtkAboutDialogOnLink
, NULL
, NULL
);
175 gtk_about_dialog_set_website(dlg
, wxGTK_CONV_SYS(info
.GetWebSiteURL()));
176 gtk_about_dialog_set_website_label
179 wxGTK_CONV_SYS(info
.GetWebSiteDescription())
184 gtk_about_dialog_set_website(dlg
, NULL
);
185 gtk_about_dialog_set_website_label(dlg
, NULL
);
187 g_signal_connect(dlg
, "activate-link", G_CALLBACK(activate_link
), NULL
);
189 gtk_about_dialog_set_url_hook(NULL
, NULL
, NULL
);
193 if ( info
.HasDevelopers() )
194 gtk_about_dialog_set_authors(dlg
, GtkArray(info
.GetDevelopers()));
196 gtk_about_dialog_set_authors(dlg
, GtkArray());
197 if ( info
.HasDocWriters() )
198 gtk_about_dialog_set_documenters(dlg
, GtkArray(info
.GetDocWriters()));
200 gtk_about_dialog_set_documenters(dlg
, GtkArray());
201 if ( info
.HasArtists() )
202 gtk_about_dialog_set_artists(dlg
, GtkArray(info
.GetArtists()));
204 gtk_about_dialog_set_artists(dlg
, GtkArray());
206 wxString transCredits
;
207 if ( info
.HasTranslators() )
209 const wxArrayString
& translators
= info
.GetTranslators();
210 const size_t count
= translators
.size();
211 for ( size_t n
= 0; n
< count
; n
++ )
213 transCredits
<< translators
[n
] << wxT('\n');
216 else // no translators explicitly specified
218 // maybe we have translator credits in the message catalog?
219 wxString translator
= _("translator-credits");
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
227 if ( translator
!= wxT("translator-credits") ) // untranslated!
228 transCredits
= translator
;
231 if ( !transCredits
.empty() )
232 gtk_about_dialog_set_translator_credits(dlg
, wxGTK_CONV_SYS(transCredits
));
234 gtk_about_dialog_set_translator_credits(dlg
, NULL
);
236 g_signal_connect(dlg
, "response",
237 G_CALLBACK(wxGtkAboutDialogOnClose
), NULL
);
239 gtk_window_present(GTK_WINDOW(dlg
));
242 #endif // wxUSE_ABOUTDLG