]> git.saurik.com Git - wxWidgets.git/blob - src/generic/aboutdlgg.cpp
Document wxDateTime::GregorianAdoption enum and TimeZone class.
[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 // helper function: returns all array elements in a single comma-separated and
46 // newline-terminated string
47 static 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 ? wxT("\n") : wxT(", "));
55 }
56
57 return s;
58 }
59
60 // ----------------------------------------------------------------------------
61 // wxAboutDialogInfo
62 // ----------------------------------------------------------------------------
63
64 wxString wxAboutDialogInfo::GetDescriptionAndCredits() const
65 {
66 wxString s = GetDescription();
67 if ( !s.empty() )
68 s << wxT('\n');
69
70 if ( HasDevelopers() )
71 s << wxT('\n') << _("Developed by ") << AllAsString(GetDevelopers());
72
73 if ( HasDocWriters() )
74 s << wxT('\n') << _("Documentation by ") << AllAsString(GetDocWriters());
75
76 if ( HasArtists() )
77 s << wxT('\n') << _("Graphics art by ") << AllAsString(GetArtists());
78
79 if ( HasTranslators() )
80 s << wxT('\n') << _("Translations by ") << AllAsString(GetTranslators());
81
82 return s;
83 }
84
85 wxIcon wxAboutDialogInfo::GetIcon() const
86 {
87 wxIcon icon = m_icon;
88 if ( !icon.IsOk() && 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
99 wxString 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 void 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
135 // ----------------------------------------------------------------------------
136 // wxGenericAboutDialog
137 // ----------------------------------------------------------------------------
138
139 bool wxGenericAboutDialog::Create(const wxAboutDialogInfo& info, wxWindow* parent)
140 {
141 if ( !wxDialog::Create(parent, wxID_ANY, wxString::Format(_("About %s"), info.GetName()),
142 wxDefaultPosition, wxDefaultSize, wxRESIZE_BORDER|wxDEFAULT_DIALOG_STYLE) )
143 return false;
144
145 m_sizerText = new wxBoxSizer(wxVERTICAL);
146 wxString nameAndVersion = info.GetName();
147 if ( info.HasVersion() )
148 nameAndVersion << wxT(' ') << info.GetVersion();
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
158 AddText(info.GetCopyrightToDisplay());
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
172 #if wxUSE_COLLPANE
173 if ( info.HasLicence() )
174 AddCollapsiblePane(_("License"), info.GetLicence());
175
176 if ( info.HasDevelopers() )
177 AddCollapsiblePane(_("Developers"),
178 AllAsString(info.GetDevelopers()));
179
180 if ( info.HasDocWriters() )
181 AddCollapsiblePane(_("Documentation writers"),
182 AllAsString(info.GetDocWriters()));
183
184 if ( info.HasArtists() )
185 AddCollapsiblePane(_("Artists"),
186 AllAsString(info.GetArtists()));
187
188 if ( info.HasTranslators() )
189 AddCollapsiblePane(_("Translators"),
190 AllAsString(info.GetTranslators()));
191 #endif // wxUSE_COLLPANE
192
193 DoAddCustomControls();
194
195
196 wxSizer *sizerIconAndText = new wxBoxSizer(wxHORIZONTAL);
197 #if wxUSE_STATBMP
198 wxIcon icon = info.GetIcon();
199 if ( icon.IsOk() )
200 {
201 sizerIconAndText->Add(new wxStaticBitmap(this, wxID_ANY, icon),
202 wxSizerFlags().Border(wxRIGHT));
203 }
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());
209
210 // Mac typically doesn't use OK buttons just for dismissing dialogs.
211 #if !defined(__WXMAC__)
212 wxSizer *sizerBtns = CreateButtonSizer(wxOK);
213 if ( sizerBtns )
214 {
215 sizerTop->Add(sizerBtns, wxSizerFlags().Expand().Border());
216 }
217 #endif
218
219 SetSizerAndFit(sizerTop);
220
221 CentreOnParent();
222
223 #if !wxUSE_MODAL_ABOUT_DIALOG
224 Connect(wxEVT_CLOSE_WINDOW,
225 wxCloseEventHandler(wxGenericAboutDialog::OnCloseWindow));
226 Connect(wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED,
227 wxCommandEventHandler(wxGenericAboutDialog::OnOK));
228 #endif // !wxUSE_MODAL_ABOUT_DIALOG
229
230 return true;
231 }
232
233 void wxGenericAboutDialog::AddControl(wxWindow *win, const wxSizerFlags& flags)
234 {
235 wxCHECK_RET( m_sizerText, wxT("can only be called after Create()") );
236 wxASSERT_MSG( win, wxT("can't add NULL window to about dialog") );
237
238 m_sizerText->Add(win, flags);
239 }
240
241 void wxGenericAboutDialog::AddControl(wxWindow *win)
242 {
243 AddControl(win, wxSizerFlags().Border(wxDOWN).Centre());
244 }
245
246 void wxGenericAboutDialog::AddText(const wxString& text)
247 {
248 if ( !text.empty() )
249 AddControl(new wxStaticText(this, wxID_ANY, text));
250 }
251
252 void wxGenericAboutDialog::AddCollapsiblePane(const wxString& title,
253 const wxString& text)
254 {
255 wxCollapsiblePane *pane = new wxCollapsiblePane(this, wxID_ANY, title);
256 wxWindow * const paneContents = pane->GetPane();
257 wxStaticText *txt = new wxStaticText(paneContents, wxID_ANY, text,
258 wxDefaultPosition, wxDefaultSize,
259 wxALIGN_CENTRE);
260
261 // don't make the text unreasonably wide
262 static const int maxWidth = wxGetDisplaySize().x/3;
263 txt->Wrap(maxWidth);
264
265
266 // we need a sizer to make this text expand to fill the entire pane area
267 wxSizer * const sizerPane = new wxBoxSizer(wxHORIZONTAL);
268 sizerPane->Add(txt, wxSizerFlags(1).Expand());
269 paneContents->SetSizer(sizerPane);
270
271 // NB: all the wxCollapsiblePanes must be added with a null proportion value
272 m_sizerText->Add(pane, wxSizerFlags(0).Expand().Border(wxBOTTOM));
273 }
274
275 #if !wxUSE_MODAL_ABOUT_DIALOG
276
277 void wxGenericAboutDialog::OnCloseWindow(wxCloseEvent& event)
278 {
279 Destroy();
280
281 event.Skip();
282 }
283
284 void wxGenericAboutDialog::OnOK(wxCommandEvent& WXUNUSED(event))
285 {
286 // By default a modeless dialog would be just hidden, destroy this one
287 // instead.
288 Destroy();
289 }
290
291 #endif // !wxUSE_MODAL_ABOUT_DIALOG
292
293 // ----------------------------------------------------------------------------
294 // public functions
295 // ----------------------------------------------------------------------------
296
297 void wxGenericAboutBox(const wxAboutDialogInfo& info, wxWindow* parent)
298 {
299 #if wxUSE_MODAL_ABOUT_DIALOG
300 wxGenericAboutDialog dlg(info, parent);
301 dlg.ShowModal();
302 #else
303 wxGenericAboutDialog* dlg = new wxGenericAboutDialog(info, parent);
304 dlg->Show();
305 #endif
306 }
307
308 // currently wxAboutBox is implemented natively only under these platforms, for
309 // the others we provide a generic fallback here
310 #if !defined(__WXMSW__) && !defined(__WXMAC__) && !defined(__WXGTK26__)
311
312 void wxAboutBox(const wxAboutDialogInfo& info, wxWindow* parent)
313 {
314 wxGenericAboutBox(info, parent);
315 }
316
317 #endif // platforms without native about dialog
318
319
320 #endif // wxUSE_ABOUTDLG