]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/generic/aboutdlgg.cpp
disclosure triangles on all implementations are able to give their true best size
[wxWidgets.git] / src / generic / aboutdlgg.cpp
... / ...
CommitLineData
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"
30 #include "wx/statbmp.h"
31 #include "wx/stattext.h"
32 #include "wx/button.h"
33#endif //WX_PRECOMP
34
35#include "wx/aboutdlg.h"
36#include "wx/generic/aboutdlgg.h"
37
38#include "wx/hyperlink.h"
39#include "wx/collpane.h"
40
41// ============================================================================
42// implementation
43// ============================================================================
44
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();
51 s.reserve(20*count);
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
60// ----------------------------------------------------------------------------
61// wxAboutDialogInfo
62// ----------------------------------------------------------------------------
63
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() )
74 s << _T('\n') << _("Documentation by ") << AllAsString(GetDocWriters());
75
76 if ( HasArtists() )
77 s << _T('\n') << _("Graphics art by ") << AllAsString(GetArtists());
78
79 if ( HasTranslators() )
80 s << _T('\n') << _("Translations by ") << AllAsString(GetTranslators());
81
82 return s;
83}
84
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
99wxString wxAboutDialogInfo::GetCopyrightToDisplay() const
100{
101 wxString ret = m_copyright;
102
103#if wxUSE_UNICODE
104 const wxString copyrightSign = wxString::FromUTF8("\xc2\xa9");
105 ret.Replace("(c)", copyrightSign);
106 ret.Replace("(C)", copyrightSign);
107#endif // wxUSE_UNICODE
108
109 return ret;
110}
111
112// ----------------------------------------------------------------------------
113// wxGenericAboutDialog
114// ----------------------------------------------------------------------------
115
116bool wxGenericAboutDialog::Create(const wxAboutDialogInfo& info, wxWindow* parent)
117{
118 if ( !wxDialog::Create(parent, wxID_ANY, _("About ") + info.GetName(),
119 wxDefaultPosition, wxDefaultSize, wxRESIZE_BORDER|wxDEFAULT_DIALOG_STYLE) )
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
135 AddText(info.GetCopyrightToDisplay());
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
149#if wxUSE_COLLPANE
150 if ( info.HasLicence() )
151 AddCollapsiblePane(_("License"), info.GetLicence());
152
153 if ( info.HasDevelopers() )
154 AddCollapsiblePane(_("Developers"),
155 AllAsString(info.GetDevelopers()));
156
157 if ( info.HasDocWriters() )
158 AddCollapsiblePane(_("Documentation writers"),
159 AllAsString(info.GetDocWriters()));
160
161 if ( info.HasArtists() )
162 AddCollapsiblePane(_("Artists"),
163 AllAsString(info.GetArtists()));
164
165 if ( info.HasTranslators() )
166 AddCollapsiblePane(_("Translators"),
167 AllAsString(info.GetTranslators()));
168#endif // wxUSE_COLLPANE
169
170 DoAddCustomControls();
171
172
173 wxSizer *sizerIconAndText = new wxBoxSizer(wxHORIZONTAL);
174#if wxUSE_STATBMP
175 wxIcon icon = info.GetIcon();
176 if ( icon.Ok() )
177 {
178 sizerIconAndText->Add(new wxStaticBitmap(this, wxID_ANY, icon),
179 wxSizerFlags().Border(wxRIGHT));
180 }
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());
186
187// Mac typically doesn't use OK buttons just for dismissing dialogs.
188#if !defined(__WXMAC__)
189 wxSizer *sizerBtns = CreateButtonSizer(wxOK);
190 if ( sizerBtns )
191 {
192 sizerTop->Add(sizerBtns, wxSizerFlags().Expand().Border());
193 }
194#endif
195
196 SetSizerAndFit(sizerTop);
197
198 CentreOnParent();
199
200 return true;
201}
202
203void wxGenericAboutDialog::AddControl(wxWindow *win, const wxSizerFlags& flags)
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
208 m_sizerText->Add(win, flags);
209}
210
211void wxGenericAboutDialog::AddControl(wxWindow *win)
212{
213 AddControl(win, wxSizerFlags().Border(wxDOWN).Centre());
214}
215
216void wxGenericAboutDialog::AddText(const wxString& text)
217{
218 if ( !text.empty() )
219 AddControl(new wxStaticText(this, wxID_ANY, text));
220}
221
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
238// ----------------------------------------------------------------------------
239// public functions
240// ----------------------------------------------------------------------------
241
242void wxGenericAboutBox(const wxAboutDialogInfo& info, wxWindow* parent)
243{
244#if !defined(__WXGTK__) && !defined(__WXMAC__)
245 wxGenericAboutDialog dlg(info, parent);
246 dlg.ShowModal();
247#else
248 wxGenericAboutDialog* dlg = new wxGenericAboutDialog(info, parent);
249 dlg->Show();
250#endif
251}
252
253// currently wxAboutBox is implemented natively only under these platforms, for
254// the others we provide a generic fallback here
255#if !defined(__WXMSW__) && !defined(__WXMAC__) && !defined(__WXGTK26__)
256
257void wxAboutBox(const wxAboutDialogInfo& info, wxWindow* parent)
258{
259 wxGenericAboutBox(info, parent);
260}
261
262#endif // platforms without native about dialog
263
264
265#endif // wxUSE_ABOUTDLG