]> git.saurik.com Git - wxWidgets.git/blob - src/generic/aboutdlgg.cpp
Used wxConstCast where needed, fixed other compile errors, and removed TABs
[wxWidgets.git] / src / generic / aboutdlgg.cpp
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 // ----------------------------------------------------------------------------
46 // wxAboutDialogInfo
47 // ----------------------------------------------------------------------------
48
49 // helper function: returns all array elements in a single comma-separated and
50 // newline-terminated string
51 static 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
63 wxString 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() )
73 s << _T('\n') << _("Documentation by ") << AllAsString(GetDocWriters());
74
75 if ( HasArtists() )
76 s << _T('\n') << _("Graphics art by ") << AllAsString(GetArtists());
77
78 if ( HasTranslators() )
79 s << _T('\n') << _("Translations by ") << AllAsString(GetTranslators());
80
81 return s;
82 }
83
84 wxIcon 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
98 // ----------------------------------------------------------------------------
99 // wxGenericAboutDialog
100 // ----------------------------------------------------------------------------
101
102 bool wxGenericAboutDialog::Create(const wxAboutDialogInfo& info)
103 {
104 // TODO: should we use main frame as parent by default here?
105 if ( !wxDialog::Create(NULL, wxID_ANY, _("About ") + info.GetName(),
106 wxDefaultPosition, wxDefaultSize, wxRESIZE_BORDER|wxDEFAULT_DIALOG_STYLE) )
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
136 // add licence
137 wxCollapsiblePane *licensepnl = new wxCollapsiblePane(this, wxID_ANY, wxT("License"));
138
139 new wxStaticText(licensepnl->GetPane(), wxID_ANY, info.GetLicence(),
140 wxDefaultPosition, wxDefaultSize,
141 wxALIGN_CENTRE);
142
143 m_sizerText->Add(licensepnl, wxSizerFlags(1).Expand().Border(wxBOTTOM));
144
145 // TODO: add credits (developers, artists, doc writers, translators)
146
147 DoAddCustomControls();
148
149
150 wxSizer *sizerIconAndText = new wxBoxSizer(wxHORIZONTAL);
151 #if wxUSE_STATBMP
152 wxIcon icon = info.GetIcon();
153 if ( icon.Ok() )
154 {
155 sizerIconAndText->Add(new wxStaticBitmap(this, wxID_ANY, icon),
156 wxSizerFlags().Border(wxRIGHT));
157 }
158 #endif // wxUSE_STATBMP
159 sizerIconAndText->Add(m_sizerText, wxSizerFlags(1).Expand());
160
161 wxSizer *sizerTop = new wxBoxSizer(wxVERTICAL);
162 sizerTop->Add(sizerIconAndText, wxSizerFlags(1).Expand().Border());
163
164 wxSizer *sizerBtns = CreateButtonSizer(wxOK);
165 if ( sizerBtns )
166 {
167 sizerTop->Add(sizerBtns, wxSizerFlags().Expand().Border());
168 }
169
170 SetSizerAndFit(sizerTop);
171
172 CentreOnScreen();
173
174 return true;
175 }
176
177 void wxGenericAboutDialog::AddControl(wxWindow *win, const wxSizerFlags& flags)
178 {
179 wxCHECK_RET( m_sizerText, _T("can only be called after Create()") );
180 wxASSERT_MSG( win, _T("can't add NULL window to about dialog") );
181
182 m_sizerText->Add(win, flags);
183 }
184
185 void wxGenericAboutDialog::AddControl(wxWindow *win)
186 {
187 AddControl(win, wxSizerFlags().Border(wxDOWN).Centre());
188 }
189
190 void wxGenericAboutDialog::AddText(const wxString& text)
191 {
192 if ( !text.empty() )
193 AddControl(new wxStaticText(this, wxID_ANY, text));
194 }
195
196 // ----------------------------------------------------------------------------
197 // public functions
198 // ----------------------------------------------------------------------------
199
200 void wxGenericAboutBox(const wxAboutDialogInfo& info)
201 {
202 wxGenericAboutDialog dlg(info);
203 dlg.ShowModal();
204 }
205
206 // currently wxAboutBox is implemented natively only under these platforms, for
207 // the others we provide a generic fallback here
208 #if !defined(__WXMSW__) && !defined(__WXMAC__) && !defined(__WXGTK26__)
209
210 void wxAboutBox(const wxAboutDialogInfo& info)
211 {
212 wxGenericAboutBox(info);
213 }
214
215 #endif // platforms without native about dialog
216
217
218 #endif // wxUSE_ABOUTDLG