]>
Commit | Line | Data |
---|---|---|
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 | |
47 | static 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 | { | |
54 | s << a[n] << (n == count - 1 ? _T("\n") : _T(", ")); | |
55 | } | |
56 | ||
57 | return s; | |
58 | } | |
59 | ||
b9993189 VZ |
60 | // ---------------------------------------------------------------------------- |
61 | // wxAboutDialogInfo | |
62 | // ---------------------------------------------------------------------------- | |
63 | ||
fd3f8f5c VZ |
64 | wxString 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() ) | |
c147c966 | 74 | s << _T('\n') << _("Documentation by ") << AllAsString(GetDocWriters()); |
fd3f8f5c VZ |
75 | |
76 | if ( HasArtists() ) | |
c147c966 | 77 | s << _T('\n') << _("Graphics art by ") << AllAsString(GetArtists()); |
fd3f8f5c VZ |
78 | |
79 | if ( HasTranslators() ) | |
c147c966 | 80 | s << _T('\n') << _("Translations by ") << AllAsString(GetTranslators()); |
fd3f8f5c VZ |
81 | |
82 | return s; | |
83 | } | |
84 | ||
a11a0ead VZ |
85 | wxIcon 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 | ||
953aebc2 FM |
99 | wxString 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 | ||
fd3f8f5c | 112 | // ---------------------------------------------------------------------------- |
453c9e3b | 113 | // wxGenericAboutDialog |
fd3f8f5c VZ |
114 | // ---------------------------------------------------------------------------- |
115 | ||
453c9e3b | 116 | bool wxGenericAboutDialog::Create(const wxAboutDialogInfo& info) |
ca7adbf8 | 117 | { |
2229243b VZ |
118 | // this is a modal dialog thus we'll use GetParentForModalDialog: |
119 | if ( !wxDialog::Create(GetParentForModalDialog(), wxID_ANY, _("About ") + info.GetName(), | |
3c1f8cb1 | 120 | wxDefaultPosition, wxDefaultSize, wxRESIZE_BORDER|wxDEFAULT_DIALOG_STYLE) ) |
ca7adbf8 VZ |
121 | return false; |
122 | ||
123 | m_sizerText = new wxBoxSizer(wxVERTICAL); | |
124 | wxString nameAndVersion = info.GetName(); | |
125 | if ( info.HasVersion() ) | |
126 | nameAndVersion << _T(' ') << info.GetVersion(); | |
127 | wxStaticText *label = new wxStaticText(this, wxID_ANY, nameAndVersion); | |
128 | wxFont fontBig(*wxNORMAL_FONT); | |
129 | fontBig.SetPointSize(fontBig.GetPointSize() + 2); | |
130 | fontBig.SetWeight(wxFONTWEIGHT_BOLD); | |
131 | label->SetFont(fontBig); | |
132 | ||
133 | m_sizerText->Add(label, wxSizerFlags().Centre().Border()); | |
134 | m_sizerText->AddSpacer(5); | |
135 | ||
953aebc2 | 136 | AddText(info.GetCopyrightToDisplay()); |
ca7adbf8 VZ |
137 | AddText(info.GetDescription()); |
138 | ||
139 | if ( info.HasWebSite() ) | |
140 | { | |
141 | #if wxUSE_HYPERLINKCTRL | |
142 | AddControl(new wxHyperlinkCtrl(this, wxID_ANY, | |
143 | info.GetWebSiteDescription(), | |
144 | info.GetWebSiteURL())); | |
145 | #else | |
146 | AddText(info.GetWebSiteURL()); | |
147 | #endif // wxUSE_HYPERLINKCTRL/!wxUSE_HYPERLINKCTRL | |
148 | } | |
149 | ||
88df9199 | 150 | #if wxUSE_COLLPANE |
886b7d74 | 151 | if ( info.HasLicence() ) |
c7753f0a | 152 | AddCollapsiblePane(_("License"), info.GetLicence()); |
3c1f8cb1 | 153 | |
b9993189 | 154 | if ( info.HasDevelopers() ) |
c7753f0a | 155 | AddCollapsiblePane(_("Developers"), |
b9993189 | 156 | AllAsString(info.GetDevelopers())); |
3c1f8cb1 | 157 | |
b9993189 | 158 | if ( info.HasDocWriters() ) |
c7753f0a | 159 | AddCollapsiblePane(_("Documentation writers"), |
b9993189 | 160 | AllAsString(info.GetDocWriters())); |
ca7adbf8 | 161 | |
b9993189 | 162 | if ( info.HasArtists() ) |
c7753f0a | 163 | AddCollapsiblePane(_("Artists"), |
b9993189 VZ |
164 | AllAsString(info.GetArtists())); |
165 | ||
166 | if ( info.HasTranslators() ) | |
c7753f0a | 167 | AddCollapsiblePane(_("Translators"), |
b9993189 VZ |
168 | AllAsString(info.GetTranslators())); |
169 | #endif // wxUSE_COLLPANE | |
ca7adbf8 | 170 | |
453c9e3b VZ |
171 | DoAddCustomControls(); |
172 | ||
ca7adbf8 VZ |
173 | |
174 | wxSizer *sizerIconAndText = new wxBoxSizer(wxHORIZONTAL); | |
175 | #if wxUSE_STATBMP | |
cfa64370 | 176 | wxIcon icon = info.GetIcon(); |
cfa64370 VZ |
177 | if ( icon.Ok() ) |
178 | { | |
179 | sizerIconAndText->Add(new wxStaticBitmap(this, wxID_ANY, icon), | |
180 | wxSizerFlags().Border(wxRIGHT)); | |
181 | } | |
ca7adbf8 VZ |
182 | #endif // wxUSE_STATBMP |
183 | sizerIconAndText->Add(m_sizerText, wxSizerFlags(1).Expand()); | |
184 | ||
185 | wxSizer *sizerTop = new wxBoxSizer(wxVERTICAL); | |
186 | sizerTop->Add(sizerIconAndText, wxSizerFlags(1).Expand().Border()); | |
b9e5acc5 | 187 | |
ee29c3df KO |
188 | // Mac typically doesn't use OK buttons just for dismissing dialogs. |
189 | #if !defined(__WXMAC__) | |
bd9f3519 VZ |
190 | wxSizer *sizerBtns = CreateButtonSizer(wxOK); |
191 | if ( sizerBtns ) | |
b9e5acc5 | 192 | { |
bd9f3519 | 193 | sizerTop->Add(sizerBtns, wxSizerFlags().Expand().Border()); |
b9e5acc5 | 194 | } |
ee29c3df | 195 | #endif |
b9e5acc5 | 196 | |
ca7adbf8 VZ |
197 | SetSizerAndFit(sizerTop); |
198 | ||
199 | CentreOnScreen(); | |
5ecfa93a | 200 | |
ca7adbf8 VZ |
201 | return true; |
202 | } | |
203 | ||
453c9e3b | 204 | void wxGenericAboutDialog::AddControl(wxWindow *win, const wxSizerFlags& flags) |
ca7adbf8 VZ |
205 | { |
206 | wxCHECK_RET( m_sizerText, _T("can only be called after Create()") ); | |
207 | wxASSERT_MSG( win, _T("can't add NULL window to about dialog") ); | |
208 | ||
453c9e3b VZ |
209 | m_sizerText->Add(win, flags); |
210 | } | |
211 | ||
212 | void wxGenericAboutDialog::AddControl(wxWindow *win) | |
213 | { | |
214 | AddControl(win, wxSizerFlags().Border(wxDOWN).Centre()); | |
ca7adbf8 VZ |
215 | } |
216 | ||
453c9e3b | 217 | void wxGenericAboutDialog::AddText(const wxString& text) |
ca7adbf8 VZ |
218 | { |
219 | if ( !text.empty() ) | |
220 | AddControl(new wxStaticText(this, wxID_ANY, text)); | |
221 | } | |
222 | ||
b9993189 VZ |
223 | void wxGenericAboutDialog::AddCollapsiblePane(const wxString& title, |
224 | const wxString& text) | |
225 | { | |
226 | wxCollapsiblePane *pane = new wxCollapsiblePane(this, wxID_ANY, title); | |
227 | wxStaticText *txt = new wxStaticText(pane->GetPane(), wxID_ANY, text, | |
228 | wxDefaultPosition, wxDefaultSize, | |
229 | wxALIGN_CENTRE); | |
230 | ||
231 | // don't make the text unreasonably wide | |
232 | static const int maxWidth = wxGetDisplaySize().x/3; | |
233 | txt->Wrap(maxWidth); | |
234 | ||
235 | // NB: all the wxCollapsiblePanes must be added with a null proportion value | |
236 | m_sizerText->Add(pane, wxSizerFlags(0).Expand().Border(wxBOTTOM)); | |
237 | } | |
238 | ||
ca7adbf8 VZ |
239 | // ---------------------------------------------------------------------------- |
240 | // public functions | |
241 | // ---------------------------------------------------------------------------- | |
242 | ||
243 | void wxGenericAboutBox(const wxAboutDialogInfo& info) | |
244 | { | |
ee29c3df | 245 | #if !defined(__WXGTK__) && !defined(__WXMAC__) |
453c9e3b | 246 | wxGenericAboutDialog dlg(info); |
ca7adbf8 | 247 | dlg.ShowModal(); |
ee29c3df KO |
248 | #else |
249 | wxGenericAboutDialog* dlg = new wxGenericAboutDialog(info); | |
250 | dlg->Show(); | |
251 | #endif | |
ca7adbf8 VZ |
252 | } |
253 | ||
fd3f8f5c VZ |
254 | // currently wxAboutBox is implemented natively only under these platforms, for |
255 | // the others we provide a generic fallback here | |
a11a0ead | 256 | #if !defined(__WXMSW__) && !defined(__WXMAC__) && !defined(__WXGTK26__) |
ca7adbf8 VZ |
257 | |
258 | void wxAboutBox(const wxAboutDialogInfo& info) | |
259 | { | |
260 | wxGenericAboutBox(info); | |
261 | } | |
262 | ||
263 | #endif // platforms without native about dialog | |
264 | ||
265 | ||
266 | #endif // wxUSE_ABOUTDLG |