]>
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" | |
39 | ||
40 | // ============================================================================ | |
fd3f8f5c | 41 | // implementation |
ca7adbf8 VZ |
42 | // ============================================================================ |
43 | ||
fd3f8f5c VZ |
44 | // ---------------------------------------------------------------------------- |
45 | // wxAboutDialogInfo | |
46 | // ---------------------------------------------------------------------------- | |
47 | ||
48 | // helper function: returns all array elements in a single comma-separated and | |
49 | // newline-terminated string | |
50 | static wxString AllAsString(const wxArrayString& a) | |
51 | { | |
52 | wxString s; | |
53 | const size_t count = a.size(); | |
54 | for ( size_t n = 0; n < count; n++ ) | |
55 | { | |
56 | s << a[n] << (n == count - 1 ? _T("\n") : _T(", ")); | |
57 | } | |
58 | ||
59 | return s; | |
60 | } | |
61 | ||
62 | wxString wxAboutDialogInfo::GetDescriptionAndCredits() const | |
63 | { | |
64 | wxString s = GetDescription(); | |
65 | if ( !s.empty() ) | |
66 | s << _T('\n'); | |
67 | ||
68 | if ( HasDevelopers() ) | |
69 | s << _T('\n') << _("Developed by ") << AllAsString(GetDevelopers()); | |
70 | ||
71 | if ( HasDocWriters() ) | |
c147c966 | 72 | s << _T('\n') << _("Documentation by ") << AllAsString(GetDocWriters()); |
fd3f8f5c VZ |
73 | |
74 | if ( HasArtists() ) | |
c147c966 | 75 | s << _T('\n') << _("Graphics art by ") << AllAsString(GetArtists()); |
fd3f8f5c VZ |
76 | |
77 | if ( HasTranslators() ) | |
c147c966 | 78 | s << _T('\n') << _("Translations by ") << AllAsString(GetTranslators()); |
fd3f8f5c VZ |
79 | |
80 | return s; | |
81 | } | |
82 | ||
a11a0ead VZ |
83 | wxIcon wxAboutDialogInfo::GetIcon() const |
84 | { | |
85 | wxIcon icon = m_icon; | |
86 | if ( !icon.Ok() && wxTheApp ) | |
87 | { | |
88 | const wxTopLevelWindow * const | |
89 | tlw = wxDynamicCast(wxTheApp->GetTopWindow(), wxTopLevelWindow); | |
90 | if ( tlw ) | |
91 | icon = tlw->GetIcon(); | |
92 | } | |
93 | ||
94 | return icon; | |
95 | } | |
96 | ||
fd3f8f5c | 97 | // ---------------------------------------------------------------------------- |
453c9e3b | 98 | // wxGenericAboutDialog |
fd3f8f5c VZ |
99 | // ---------------------------------------------------------------------------- |
100 | ||
453c9e3b | 101 | bool wxGenericAboutDialog::Create(const wxAboutDialogInfo& info) |
ca7adbf8 VZ |
102 | { |
103 | // TODO: should we use main frame as parent by default here? | |
104 | if ( !wxDialog::Create(NULL, wxID_ANY, _("About ") + info.GetName()) ) | |
105 | return false; | |
106 | ||
107 | m_sizerText = new wxBoxSizer(wxVERTICAL); | |
108 | wxString nameAndVersion = info.GetName(); | |
109 | if ( info.HasVersion() ) | |
110 | nameAndVersion << _T(' ') << info.GetVersion(); | |
111 | wxStaticText *label = new wxStaticText(this, wxID_ANY, nameAndVersion); | |
112 | wxFont fontBig(*wxNORMAL_FONT); | |
113 | fontBig.SetPointSize(fontBig.GetPointSize() + 2); | |
114 | fontBig.SetWeight(wxFONTWEIGHT_BOLD); | |
115 | label->SetFont(fontBig); | |
116 | ||
117 | m_sizerText->Add(label, wxSizerFlags().Centre().Border()); | |
118 | m_sizerText->AddSpacer(5); | |
119 | ||
120 | AddText(info.GetCopyright()); | |
121 | AddText(info.GetDescription()); | |
122 | ||
123 | if ( info.HasWebSite() ) | |
124 | { | |
125 | #if wxUSE_HYPERLINKCTRL | |
126 | AddControl(new wxHyperlinkCtrl(this, wxID_ANY, | |
127 | info.GetWebSiteDescription(), | |
128 | info.GetWebSiteURL())); | |
129 | #else | |
130 | AddText(info.GetWebSiteURL()); | |
131 | #endif // wxUSE_HYPERLINKCTRL/!wxUSE_HYPERLINKCTRL | |
132 | } | |
133 | ||
134 | // TODO: add licence | |
135 | ||
136 | // TODO: add credits (developers, artists, doc writers, translators) | |
137 | ||
453c9e3b VZ |
138 | DoAddCustomControls(); |
139 | ||
ca7adbf8 VZ |
140 | |
141 | wxSizer *sizerIconAndText = new wxBoxSizer(wxHORIZONTAL); | |
142 | #if wxUSE_STATBMP | |
cfa64370 | 143 | wxIcon icon = info.GetIcon(); |
cfa64370 VZ |
144 | if ( icon.Ok() ) |
145 | { | |
146 | sizerIconAndText->Add(new wxStaticBitmap(this, wxID_ANY, icon), | |
147 | wxSizerFlags().Border(wxRIGHT)); | |
148 | } | |
ca7adbf8 VZ |
149 | #endif // wxUSE_STATBMP |
150 | sizerIconAndText->Add(m_sizerText, wxSizerFlags(1).Expand()); | |
151 | ||
152 | wxSizer *sizerTop = new wxBoxSizer(wxVERTICAL); | |
153 | sizerTop->Add(sizerIconAndText, wxSizerFlags(1).Expand().Border()); | |
b9e5acc5 WS |
154 | |
155 | int defBorder = wxSizerFlags().Border().GetBorderInPixels(); | |
156 | wxSizer *buttonSizer = CreateButtonSizer( wxOK , false, defBorder ); | |
157 | if(buttonSizer->GetChildren().GetCount() > 0 ) | |
158 | { | |
159 | sizerTop->Add( buttonSizer, 0, wxEXPAND | wxALL, defBorder ); | |
160 | } | |
161 | else | |
162 | { | |
163 | sizerTop->AddSpacer( defBorder ); | |
164 | delete buttonSizer; | |
165 | } | |
166 | ||
ca7adbf8 VZ |
167 | SetSizerAndFit(sizerTop); |
168 | ||
169 | CentreOnScreen(); | |
5ecfa93a | 170 | |
b9e5acc5 WS |
171 | wxWindow *ok = FindWindow(wxID_OK); |
172 | if (ok) ok->SetFocus(); | |
5ecfa93a | 173 | |
ca7adbf8 VZ |
174 | return true; |
175 | } | |
176 | ||
453c9e3b | 177 | void wxGenericAboutDialog::AddControl(wxWindow *win, const wxSizerFlags& flags) |
ca7adbf8 VZ |
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 | ||
453c9e3b VZ |
182 | m_sizerText->Add(win, flags); |
183 | } | |
184 | ||
185 | void wxGenericAboutDialog::AddControl(wxWindow *win) | |
186 | { | |
187 | AddControl(win, wxSizerFlags().Border(wxDOWN).Centre()); | |
ca7adbf8 VZ |
188 | } |
189 | ||
453c9e3b | 190 | void wxGenericAboutDialog::AddText(const wxString& text) |
ca7adbf8 VZ |
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 | { | |
453c9e3b | 202 | wxGenericAboutDialog dlg(info); |
ca7adbf8 VZ |
203 | dlg.ShowModal(); |
204 | } | |
205 | ||
fd3f8f5c VZ |
206 | // currently wxAboutBox is implemented natively only under these platforms, for |
207 | // the others we provide a generic fallback here | |
a11a0ead | 208 | #if !defined(__WXMSW__) && !defined(__WXMAC__) && !defined(__WXGTK26__) |
ca7adbf8 VZ |
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 |