]> git.saurik.com Git - wxWidgets.git/blame - src/generic/aboutdlgg.cpp
Enhance wxRibbonToolBar functionality to wxRibbonButtonBar level.
[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 {
9a83f860 54 s << a[n] << (n == count - 1 ? wxT("\n") : wxT(", "));
fd3f8f5c
VZ
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() )
9a83f860 68 s << wxT('\n');
fd3f8f5c
VZ
69
70 if ( HasDevelopers() )
9a83f860 71 s << wxT('\n') << _("Developed by ") << AllAsString(GetDevelopers());
fd3f8f5c
VZ
72
73 if ( HasDocWriters() )
9a83f860 74 s << wxT('\n') << _("Documentation by ") << AllAsString(GetDocWriters());
fd3f8f5c
VZ
75
76 if ( HasArtists() )
9a83f860 77 s << wxT('\n') << _("Graphics art by ") << AllAsString(GetArtists());
fd3f8f5c
VZ
78
79 if ( HasTranslators() )
9a83f860 80 s << wxT('\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;
a1b806b9 88 if ( !icon.IsOk() && wxTheApp )
a11a0ead
VZ
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
704006b3
VZ
112void wxAboutDialogInfo::SetVersion(const wxString& version,
113 const wxString& longVersion)
114{
115 if ( version.empty() )
116 {
117 m_version.clear();
118
119 wxASSERT_MSG( longVersion.empty(),
120 "long version should be empty if version is");
121
122 m_longVersion.clear();
123 }
124 else // setting valid version
125 {
126 m_version = version;
127
128 if ( longVersion.empty() )
129 m_longVersion = _("Version ") + m_version;
130 else
131 m_longVersion = longVersion;
132 }
133}
134
fd3f8f5c 135// ----------------------------------------------------------------------------
453c9e3b 136// wxGenericAboutDialog
fd3f8f5c
VZ
137// ----------------------------------------------------------------------------
138
c173e541 139bool wxGenericAboutDialog::Create(const wxAboutDialogInfo& info, wxWindow* parent)
ca7adbf8 140{
b82f92a8 141 if ( !wxDialog::Create(parent, wxID_ANY, wxString::Format(_("About %s"), info.GetName()),
3c1f8cb1 142 wxDefaultPosition, wxDefaultSize, wxRESIZE_BORDER|wxDEFAULT_DIALOG_STYLE) )
ca7adbf8
VZ
143 return false;
144
145 m_sizerText = new wxBoxSizer(wxVERTICAL);
146 wxString nameAndVersion = info.GetName();
147 if ( info.HasVersion() )
9a83f860 148 nameAndVersion << wxT(' ') << info.GetVersion();
ca7adbf8
VZ
149 wxStaticText *label = new wxStaticText(this, wxID_ANY, nameAndVersion);
150 wxFont fontBig(*wxNORMAL_FONT);
151 fontBig.SetPointSize(fontBig.GetPointSize() + 2);
152 fontBig.SetWeight(wxFONTWEIGHT_BOLD);
153 label->SetFont(fontBig);
154
155 m_sizerText->Add(label, wxSizerFlags().Centre().Border());
156 m_sizerText->AddSpacer(5);
157
953aebc2 158 AddText(info.GetCopyrightToDisplay());
ca7adbf8
VZ
159 AddText(info.GetDescription());
160
161 if ( info.HasWebSite() )
162 {
163#if wxUSE_HYPERLINKCTRL
164 AddControl(new wxHyperlinkCtrl(this, wxID_ANY,
165 info.GetWebSiteDescription(),
166 info.GetWebSiteURL()));
167#else
168 AddText(info.GetWebSiteURL());
169#endif // wxUSE_HYPERLINKCTRL/!wxUSE_HYPERLINKCTRL
170 }
171
88df9199 172#if wxUSE_COLLPANE
886b7d74 173 if ( info.HasLicence() )
c7753f0a 174 AddCollapsiblePane(_("License"), info.GetLicence());
3c1f8cb1 175
b9993189 176 if ( info.HasDevelopers() )
c7753f0a 177 AddCollapsiblePane(_("Developers"),
b9993189 178 AllAsString(info.GetDevelopers()));
3c1f8cb1 179
b9993189 180 if ( info.HasDocWriters() )
c7753f0a 181 AddCollapsiblePane(_("Documentation writers"),
b9993189 182 AllAsString(info.GetDocWriters()));
ca7adbf8 183
b9993189 184 if ( info.HasArtists() )
c7753f0a 185 AddCollapsiblePane(_("Artists"),
b9993189
VZ
186 AllAsString(info.GetArtists()));
187
188 if ( info.HasTranslators() )
c7753f0a 189 AddCollapsiblePane(_("Translators"),
b9993189
VZ
190 AllAsString(info.GetTranslators()));
191#endif // wxUSE_COLLPANE
ca7adbf8 192
453c9e3b
VZ
193 DoAddCustomControls();
194
ca7adbf8
VZ
195
196 wxSizer *sizerIconAndText = new wxBoxSizer(wxHORIZONTAL);
197#if wxUSE_STATBMP
cfa64370 198 wxIcon icon = info.GetIcon();
a1b806b9 199 if ( icon.IsOk() )
cfa64370
VZ
200 {
201 sizerIconAndText->Add(new wxStaticBitmap(this, wxID_ANY, icon),
202 wxSizerFlags().Border(wxRIGHT));
203 }
ca7adbf8
VZ
204#endif // wxUSE_STATBMP
205 sizerIconAndText->Add(m_sizerText, wxSizerFlags(1).Expand());
206
207 wxSizer *sizerTop = new wxBoxSizer(wxVERTICAL);
208 sizerTop->Add(sizerIconAndText, wxSizerFlags(1).Expand().Border());
b9e5acc5 209
ee29c3df
KO
210// Mac typically doesn't use OK buttons just for dismissing dialogs.
211#if !defined(__WXMAC__)
bd9f3519
VZ
212 wxSizer *sizerBtns = CreateButtonSizer(wxOK);
213 if ( sizerBtns )
b9e5acc5 214 {
bd9f3519 215 sizerTop->Add(sizerBtns, wxSizerFlags().Expand().Border());
b9e5acc5 216 }
ee29c3df 217#endif
b9e5acc5 218
ca7adbf8
VZ
219 SetSizerAndFit(sizerTop);
220
c173e541 221 CentreOnParent();
5ecfa93a 222
ca7adbf8
VZ
223 return true;
224}
225
453c9e3b 226void wxGenericAboutDialog::AddControl(wxWindow *win, const wxSizerFlags& flags)
ca7adbf8 227{
9a83f860
VZ
228 wxCHECK_RET( m_sizerText, wxT("can only be called after Create()") );
229 wxASSERT_MSG( win, wxT("can't add NULL window to about dialog") );
ca7adbf8 230
453c9e3b
VZ
231 m_sizerText->Add(win, flags);
232}
233
234void wxGenericAboutDialog::AddControl(wxWindow *win)
235{
236 AddControl(win, wxSizerFlags().Border(wxDOWN).Centre());
ca7adbf8
VZ
237}
238
453c9e3b 239void wxGenericAboutDialog::AddText(const wxString& text)
ca7adbf8
VZ
240{
241 if ( !text.empty() )
242 AddControl(new wxStaticText(this, wxID_ANY, text));
243}
244
b9993189
VZ
245void wxGenericAboutDialog::AddCollapsiblePane(const wxString& title,
246 const wxString& text)
247{
248 wxCollapsiblePane *pane = new wxCollapsiblePane(this, wxID_ANY, title);
a6982a38
VZ
249 wxWindow * const paneContents = pane->GetPane();
250 wxStaticText *txt = new wxStaticText(paneContents, wxID_ANY, text,
b9993189
VZ
251 wxDefaultPosition, wxDefaultSize,
252 wxALIGN_CENTRE);
253
254 // don't make the text unreasonably wide
255 static const int maxWidth = wxGetDisplaySize().x/3;
256 txt->Wrap(maxWidth);
257
a6982a38
VZ
258
259 // we need a sizer to make this text expand to fill the entire pane area
260 wxSizer * const sizerPane = new wxBoxSizer(wxHORIZONTAL);
261 sizerPane->Add(txt, wxSizerFlags(1).Expand());
262 paneContents->SetSizer(sizerPane);
263
b9993189
VZ
264 // NB: all the wxCollapsiblePanes must be added with a null proportion value
265 m_sizerText->Add(pane, wxSizerFlags(0).Expand().Border(wxBOTTOM));
266}
267
ca7adbf8
VZ
268// ----------------------------------------------------------------------------
269// public functions
270// ----------------------------------------------------------------------------
271
c173e541 272void wxGenericAboutBox(const wxAboutDialogInfo& info, wxWindow* parent)
ca7adbf8 273{
ee29c3df 274#if !defined(__WXGTK__) && !defined(__WXMAC__)
c173e541 275 wxGenericAboutDialog dlg(info, parent);
ca7adbf8 276 dlg.ShowModal();
ee29c3df 277#else
6b71941b 278 wxGenericAboutDialog* dlg = new wxGenericAboutDialog(info, parent);
ee29c3df
KO
279 dlg->Show();
280#endif
ca7adbf8
VZ
281}
282
fd3f8f5c
VZ
283// currently wxAboutBox is implemented natively only under these platforms, for
284// the others we provide a generic fallback here
a11a0ead 285#if !defined(__WXMSW__) && !defined(__WXMAC__) && !defined(__WXGTK26__)
ca7adbf8 286
c173e541 287void wxAboutBox(const wxAboutDialogInfo& info, wxWindow* parent)
ca7adbf8 288{
c173e541 289 wxGenericAboutBox(info, parent);
ca7adbf8
VZ
290}
291
292#endif // platforms without native about dialog
293
294
295#endif // wxUSE_ABOUTDLG