]> git.saurik.com Git - wxWidgets.git/blame - src/generic/aboutdlgg.cpp
Converted wxVariant to use wxObject's reference counting facilities. Should make...
[wxWidgets.git] / src / generic / aboutdlgg.cpp
CommitLineData
ca7adbf8
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: src/generic/aboutdlgg.cpp
3// Purpose: implements wxGenericAboutBox() function
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#ifdef __BORLANDC__
23 #pragma hdrstop
24#endif
25
26#if wxUSE_ABOUTDLG
27
28#ifndef WX_PRECOMP
29 #include "wx/sizer.h"
ca7adbf8
VZ
30 #include "wx/statbmp.h"
31 #include "wx/stattext.h"
c147c966 32 #include "wx/button.h"
ca7adbf8
VZ
33#endif //WX_PRECOMP
34
35#include "wx/aboutdlg.h"
36#include "wx/generic/aboutdlgg.h"
37
38#include "wx/hyperlink.h"
3c1f8cb1 39#include "wx/collpane.h"
ca7adbf8
VZ
40
41// ============================================================================
fd3f8f5c 42// implementation
ca7adbf8
VZ
43// ============================================================================
44
fd3f8f5c
VZ
45// helper function: returns all array elements in a single comma-separated and
46// newline-terminated string
47static wxString AllAsString(const wxArrayString& a)
48{
49 wxString s;
50 const size_t count = a.size();
b9993189 51 s.reserve(20*count);
fd3f8f5c
VZ
52 for ( size_t n = 0; n < count; n++ )
53 {
54 s << a[n] << (n == count - 1 ? _T("\n") : _T(", "));
55 }
56
57 return s;
58}
59
b9993189
VZ
60// ----------------------------------------------------------------------------
61// wxAboutDialogInfo
62// ----------------------------------------------------------------------------
63
fd3f8f5c
VZ
64wxString wxAboutDialogInfo::GetDescriptionAndCredits() const
65{
66 wxString s = GetDescription();
67 if ( !s.empty() )
68 s << _T('\n');
69
70 if ( HasDevelopers() )
71 s << _T('\n') << _("Developed by ") << AllAsString(GetDevelopers());
72
73 if ( HasDocWriters() )
c147c966 74 s << _T('\n') << _("Documentation by ") << AllAsString(GetDocWriters());
fd3f8f5c
VZ
75
76 if ( HasArtists() )
c147c966 77 s << _T('\n') << _("Graphics art by ") << AllAsString(GetArtists());
fd3f8f5c
VZ
78
79 if ( HasTranslators() )
c147c966 80 s << _T('\n') << _("Translations by ") << AllAsString(GetTranslators());
fd3f8f5c
VZ
81
82 return s;
83}
84
a11a0ead
VZ
85wxIcon wxAboutDialogInfo::GetIcon() const
86{
87 wxIcon icon = m_icon;
88 if ( !icon.Ok() && wxTheApp )
89 {
90 const wxTopLevelWindow * const
91 tlw = wxDynamicCast(wxTheApp->GetTopWindow(), wxTopLevelWindow);
92 if ( tlw )
93 icon = tlw->GetIcon();
94 }
95
96 return icon;
97}
98
953aebc2
FM
99wxString wxAboutDialogInfo::GetCopyrightToDisplay() const
100{
101 wxString ret = m_copyright;
102
6fc5f04e 103#if wxUSE_UNICODE
5b05d3ee
VZ
104 const wxString copyrightSign = wxString::FromUTF8("\xc2\xa9");
105 ret.Replace("(c)", copyrightSign);
106 ret.Replace("(C)", copyrightSign);
6fc5f04e 107#endif // wxUSE_UNICODE
953aebc2
FM
108
109 return ret;
110}
111
fd3f8f5c 112// ----------------------------------------------------------------------------
453c9e3b 113// wxGenericAboutDialog
fd3f8f5c
VZ
114// ----------------------------------------------------------------------------
115
c173e541 116bool wxGenericAboutDialog::Create(const wxAboutDialogInfo& info, wxWindow* parent)
ca7adbf8 117{
c173e541 118 if ( !wxDialog::Create(parent, wxID_ANY, _("About ") + info.GetName(),
3c1f8cb1 119 wxDefaultPosition, wxDefaultSize, wxRESIZE_BORDER|wxDEFAULT_DIALOG_STYLE) )
ca7adbf8
VZ
120 return false;
121
122 m_sizerText = new wxBoxSizer(wxVERTICAL);
123 wxString nameAndVersion = info.GetName();
124 if ( info.HasVersion() )
125 nameAndVersion << _T(' ') << info.GetVersion();
126 wxStaticText *label = new wxStaticText(this, wxID_ANY, nameAndVersion);
127 wxFont fontBig(*wxNORMAL_FONT);
128 fontBig.SetPointSize(fontBig.GetPointSize() + 2);
129 fontBig.SetWeight(wxFONTWEIGHT_BOLD);
130 label->SetFont(fontBig);
131
132 m_sizerText->Add(label, wxSizerFlags().Centre().Border());
133 m_sizerText->AddSpacer(5);
134
953aebc2 135 AddText(info.GetCopyrightToDisplay());
ca7adbf8
VZ
136 AddText(info.GetDescription());
137
138 if ( info.HasWebSite() )
139 {
140#if wxUSE_HYPERLINKCTRL
141 AddControl(new wxHyperlinkCtrl(this, wxID_ANY,
142 info.GetWebSiteDescription(),
143 info.GetWebSiteURL()));
144#else
145 AddText(info.GetWebSiteURL());
146#endif // wxUSE_HYPERLINKCTRL/!wxUSE_HYPERLINKCTRL
147 }
148
88df9199 149#if wxUSE_COLLPANE
886b7d74 150 if ( info.HasLicence() )
c7753f0a 151 AddCollapsiblePane(_("License"), info.GetLicence());
3c1f8cb1 152
b9993189 153 if ( info.HasDevelopers() )
c7753f0a 154 AddCollapsiblePane(_("Developers"),
b9993189 155 AllAsString(info.GetDevelopers()));
3c1f8cb1 156
b9993189 157 if ( info.HasDocWriters() )
c7753f0a 158 AddCollapsiblePane(_("Documentation writers"),
b9993189 159 AllAsString(info.GetDocWriters()));
ca7adbf8 160
b9993189 161 if ( info.HasArtists() )
c7753f0a 162 AddCollapsiblePane(_("Artists"),
b9993189
VZ
163 AllAsString(info.GetArtists()));
164
165 if ( info.HasTranslators() )
c7753f0a 166 AddCollapsiblePane(_("Translators"),
b9993189
VZ
167 AllAsString(info.GetTranslators()));
168#endif // wxUSE_COLLPANE
ca7adbf8 169
453c9e3b
VZ
170 DoAddCustomControls();
171
ca7adbf8
VZ
172
173 wxSizer *sizerIconAndText = new wxBoxSizer(wxHORIZONTAL);
174#if wxUSE_STATBMP
cfa64370 175 wxIcon icon = info.GetIcon();
cfa64370
VZ
176 if ( icon.Ok() )
177 {
178 sizerIconAndText->Add(new wxStaticBitmap(this, wxID_ANY, icon),
179 wxSizerFlags().Border(wxRIGHT));
180 }
ca7adbf8
VZ
181#endif // wxUSE_STATBMP
182 sizerIconAndText->Add(m_sizerText, wxSizerFlags(1).Expand());
183
184 wxSizer *sizerTop = new wxBoxSizer(wxVERTICAL);
185 sizerTop->Add(sizerIconAndText, wxSizerFlags(1).Expand().Border());
b9e5acc5 186
ee29c3df
KO
187// Mac typically doesn't use OK buttons just for dismissing dialogs.
188#if !defined(__WXMAC__)
bd9f3519
VZ
189 wxSizer *sizerBtns = CreateButtonSizer(wxOK);
190 if ( sizerBtns )
b9e5acc5 191 {
bd9f3519 192 sizerTop->Add(sizerBtns, wxSizerFlags().Expand().Border());
b9e5acc5 193 }
ee29c3df 194#endif
b9e5acc5 195
ca7adbf8
VZ
196 SetSizerAndFit(sizerTop);
197
c173e541 198 CentreOnParent();
5ecfa93a 199
ca7adbf8
VZ
200 return true;
201}
202
453c9e3b 203void wxGenericAboutDialog::AddControl(wxWindow *win, const wxSizerFlags& flags)
ca7adbf8
VZ
204{
205 wxCHECK_RET( m_sizerText, _T("can only be called after Create()") );
206 wxASSERT_MSG( win, _T("can't add NULL window to about dialog") );
207
453c9e3b
VZ
208 m_sizerText->Add(win, flags);
209}
210
211void wxGenericAboutDialog::AddControl(wxWindow *win)
212{
213 AddControl(win, wxSizerFlags().Border(wxDOWN).Centre());
ca7adbf8
VZ
214}
215
453c9e3b 216void wxGenericAboutDialog::AddText(const wxString& text)
ca7adbf8
VZ
217{
218 if ( !text.empty() )
219 AddControl(new wxStaticText(this, wxID_ANY, text));
220}
221
b9993189
VZ
222void wxGenericAboutDialog::AddCollapsiblePane(const wxString& title,
223 const wxString& text)
224{
225 wxCollapsiblePane *pane = new wxCollapsiblePane(this, wxID_ANY, title);
226 wxStaticText *txt = new wxStaticText(pane->GetPane(), wxID_ANY, text,
227 wxDefaultPosition, wxDefaultSize,
228 wxALIGN_CENTRE);
229
230 // don't make the text unreasonably wide
231 static const int maxWidth = wxGetDisplaySize().x/3;
232 txt->Wrap(maxWidth);
233
234 // NB: all the wxCollapsiblePanes must be added with a null proportion value
235 m_sizerText->Add(pane, wxSizerFlags(0).Expand().Border(wxBOTTOM));
236}
237
ca7adbf8
VZ
238// ----------------------------------------------------------------------------
239// public functions
240// ----------------------------------------------------------------------------
241
c173e541 242void wxGenericAboutBox(const wxAboutDialogInfo& info, wxWindow* parent)
ca7adbf8 243{
ee29c3df 244#if !defined(__WXGTK__) && !defined(__WXMAC__)
c173e541 245 wxGenericAboutDialog dlg(info, parent);
ca7adbf8 246 dlg.ShowModal();
ee29c3df 247#else
6b71941b 248 wxGenericAboutDialog* dlg = new wxGenericAboutDialog(info, parent);
ee29c3df
KO
249 dlg->Show();
250#endif
ca7adbf8
VZ
251}
252
fd3f8f5c
VZ
253// currently wxAboutBox is implemented natively only under these platforms, for
254// the others we provide a generic fallback here
a11a0ead 255#if !defined(__WXMSW__) && !defined(__WXMAC__) && !defined(__WXGTK26__)
ca7adbf8 256
c173e541 257void wxAboutBox(const wxAboutDialogInfo& info, wxWindow* parent)
ca7adbf8 258{
c173e541 259 wxGenericAboutBox(info, parent);
ca7adbf8
VZ
260}
261
262#endif // platforms without native about dialog
263
264
265#endif // wxUSE_ABOUTDLG