]> git.saurik.com Git - wxWidgets.git/blame - src/generic/aboutdlgg.cpp
add -mno-cygwin detection: we should treat cygwin as Windows, not Unix, when it's...
[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// ----------------------------------------------------------------------------
46// wxAboutDialogInfo
47// ----------------------------------------------------------------------------
48
49// helper function: returns all array elements in a single comma-separated and
50// newline-terminated string
51static wxString AllAsString(const wxArrayString& a)
52{
53 wxString s;
54 const size_t count = a.size();
55 for ( size_t n = 0; n < count; n++ )
56 {
57 s << a[n] << (n == count - 1 ? _T("\n") : _T(", "));
58 }
59
60 return s;
61}
62
63wxString wxAboutDialogInfo::GetDescriptionAndCredits() const
64{
65 wxString s = GetDescription();
66 if ( !s.empty() )
67 s << _T('\n');
68
69 if ( HasDevelopers() )
70 s << _T('\n') << _("Developed by ") << AllAsString(GetDevelopers());
71
72 if ( HasDocWriters() )
c147c966 73 s << _T('\n') << _("Documentation by ") << AllAsString(GetDocWriters());
fd3f8f5c
VZ
74
75 if ( HasArtists() )
c147c966 76 s << _T('\n') << _("Graphics art by ") << AllAsString(GetArtists());
fd3f8f5c
VZ
77
78 if ( HasTranslators() )
c147c966 79 s << _T('\n') << _("Translations by ") << AllAsString(GetTranslators());
fd3f8f5c
VZ
80
81 return s;
82}
83
a11a0ead
VZ
84wxIcon wxAboutDialogInfo::GetIcon() const
85{
86 wxIcon icon = m_icon;
87 if ( !icon.Ok() && wxTheApp )
88 {
89 const wxTopLevelWindow * const
90 tlw = wxDynamicCast(wxTheApp->GetTopWindow(), wxTopLevelWindow);
91 if ( tlw )
92 icon = tlw->GetIcon();
93 }
94
95 return icon;
96}
97
fd3f8f5c 98// ----------------------------------------------------------------------------
453c9e3b 99// wxGenericAboutDialog
fd3f8f5c
VZ
100// ----------------------------------------------------------------------------
101
453c9e3b 102bool wxGenericAboutDialog::Create(const wxAboutDialogInfo& info)
ca7adbf8
VZ
103{
104 // TODO: should we use main frame as parent by default here?
3c1f8cb1
VZ
105 if ( !wxDialog::Create(NULL, wxID_ANY, _("About ") + info.GetName(),
106 wxDefaultPosition, wxDefaultSize, wxRESIZE_BORDER|wxDEFAULT_DIALOG_STYLE) )
ca7adbf8
VZ
107 return false;
108
109 m_sizerText = new wxBoxSizer(wxVERTICAL);
110 wxString nameAndVersion = info.GetName();
111 if ( info.HasVersion() )
112 nameAndVersion << _T(' ') << info.GetVersion();
113 wxStaticText *label = new wxStaticText(this, wxID_ANY, nameAndVersion);
114 wxFont fontBig(*wxNORMAL_FONT);
115 fontBig.SetPointSize(fontBig.GetPointSize() + 2);
116 fontBig.SetWeight(wxFONTWEIGHT_BOLD);
117 label->SetFont(fontBig);
118
119 m_sizerText->Add(label, wxSizerFlags().Centre().Border());
120 m_sizerText->AddSpacer(5);
121
122 AddText(info.GetCopyright());
123 AddText(info.GetDescription());
124
125 if ( info.HasWebSite() )
126 {
127#if wxUSE_HYPERLINKCTRL
128 AddControl(new wxHyperlinkCtrl(this, wxID_ANY,
129 info.GetWebSiteDescription(),
130 info.GetWebSiteURL()));
131#else
132 AddText(info.GetWebSiteURL());
133#endif // wxUSE_HYPERLINKCTRL/!wxUSE_HYPERLINKCTRL
134 }
135
88df9199 136#if wxUSE_COLLPANE
3c1f8cb1 137 // add licence
886b7d74
VZ
138 if ( info.HasLicence() )
139 {
140 wxCollapsiblePane *
141 licensepnl = new wxCollapsiblePane(this, wxID_ANY, wxT("License"));
3c1f8cb1 142
886b7d74
VZ
143 new wxStaticText(licensepnl->GetPane(), wxID_ANY, info.GetLicence(),
144 wxDefaultPosition, wxDefaultSize,
145 wxALIGN_CENTRE);
3c1f8cb1 146
886b7d74
VZ
147 m_sizerText->Add(licensepnl, wxSizerFlags(1).Expand().Border(wxBOTTOM));
148 }
88df9199 149#endif // wxUSE_COLLPANE
ca7adbf8
VZ
150
151 // TODO: add credits (developers, artists, doc writers, translators)
152
453c9e3b
VZ
153 DoAddCustomControls();
154
ca7adbf8
VZ
155
156 wxSizer *sizerIconAndText = new wxBoxSizer(wxHORIZONTAL);
157#if wxUSE_STATBMP
cfa64370 158 wxIcon icon = info.GetIcon();
cfa64370
VZ
159 if ( icon.Ok() )
160 {
161 sizerIconAndText->Add(new wxStaticBitmap(this, wxID_ANY, icon),
162 wxSizerFlags().Border(wxRIGHT));
163 }
ca7adbf8
VZ
164#endif // wxUSE_STATBMP
165 sizerIconAndText->Add(m_sizerText, wxSizerFlags(1).Expand());
166
167 wxSizer *sizerTop = new wxBoxSizer(wxVERTICAL);
168 sizerTop->Add(sizerIconAndText, wxSizerFlags(1).Expand().Border());
b9e5acc5 169
bd9f3519
VZ
170 wxSizer *sizerBtns = CreateButtonSizer(wxOK);
171 if ( sizerBtns )
b9e5acc5 172 {
bd9f3519 173 sizerTop->Add(sizerBtns, wxSizerFlags().Expand().Border());
b9e5acc5
WS
174 }
175
ca7adbf8
VZ
176 SetSizerAndFit(sizerTop);
177
178 CentreOnScreen();
5ecfa93a 179
ca7adbf8
VZ
180 return true;
181}
182
453c9e3b 183void wxGenericAboutDialog::AddControl(wxWindow *win, const wxSizerFlags& flags)
ca7adbf8
VZ
184{
185 wxCHECK_RET( m_sizerText, _T("can only be called after Create()") );
186 wxASSERT_MSG( win, _T("can't add NULL window to about dialog") );
187
453c9e3b
VZ
188 m_sizerText->Add(win, flags);
189}
190
191void wxGenericAboutDialog::AddControl(wxWindow *win)
192{
193 AddControl(win, wxSizerFlags().Border(wxDOWN).Centre());
ca7adbf8
VZ
194}
195
453c9e3b 196void wxGenericAboutDialog::AddText(const wxString& text)
ca7adbf8
VZ
197{
198 if ( !text.empty() )
199 AddControl(new wxStaticText(this, wxID_ANY, text));
200}
201
202// ----------------------------------------------------------------------------
203// public functions
204// ----------------------------------------------------------------------------
205
206void wxGenericAboutBox(const wxAboutDialogInfo& info)
207{
453c9e3b 208 wxGenericAboutDialog dlg(info);
ca7adbf8
VZ
209 dlg.ShowModal();
210}
211
fd3f8f5c
VZ
212// currently wxAboutBox is implemented natively only under these platforms, for
213// the others we provide a generic fallback here
a11a0ead 214#if !defined(__WXMSW__) && !defined(__WXMAC__) && !defined(__WXGTK26__)
ca7adbf8
VZ
215
216void wxAboutBox(const wxAboutDialogInfo& info)
217{
218 wxGenericAboutBox(info);
219}
220
221#endif // platforms without native about dialog
222
223
224#endif // wxUSE_ABOUTDLG