]>
git.saurik.com Git - wxWidgets.git/blob - src/generic/aboutdlgg.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/aboutdlgg.cpp
3 // Purpose: implements wxGenericAboutBox() function
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2006 Vadim Zeitlin <vadim@wxwindows.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // for compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
30 #include "wx/statbmp.h"
31 #include "wx/stattext.h"
32 #include "wx/button.h"
35 #include "wx/aboutdlg.h"
36 #include "wx/generic/aboutdlgg.h"
38 #include "wx/hyperlink.h"
39 #include "wx/collpane.h"
41 // ============================================================================
43 // ============================================================================
45 // helper function: returns all array elements in a single comma-separated and
46 // newline-terminated string
47 static wxString
AllAsString(const wxArrayString
& a
)
50 const size_t count
= a
.size();
52 for ( size_t n
= 0; n
< count
; n
++ )
54 s
<< a
[n
] << (n
== count
- 1 ? wxT("\n") : wxT(", "));
60 // ----------------------------------------------------------------------------
62 // ----------------------------------------------------------------------------
64 wxString
wxAboutDialogInfo::GetDescriptionAndCredits() const
66 wxString s
= GetDescription();
70 if ( HasDevelopers() )
71 s
<< wxT('\n') << _("Developed by ") << AllAsString(GetDevelopers());
73 if ( HasDocWriters() )
74 s
<< wxT('\n') << _("Documentation by ") << AllAsString(GetDocWriters());
77 s
<< wxT('\n') << _("Graphics art by ") << AllAsString(GetArtists());
79 if ( HasTranslators() )
80 s
<< wxT('\n') << _("Translations by ") << AllAsString(GetTranslators());
85 wxIcon
wxAboutDialogInfo::GetIcon() const
88 if ( !icon
.Ok() && wxTheApp
)
90 const wxTopLevelWindow
* const
91 tlw
= wxDynamicCast(wxTheApp
->GetTopWindow(), wxTopLevelWindow
);
93 icon
= tlw
->GetIcon();
99 wxString
wxAboutDialogInfo::GetCopyrightToDisplay() const
101 wxString ret
= m_copyright
;
104 const wxString copyrightSign
= wxString::FromUTF8("\xc2\xa9");
105 ret
.Replace("(c)", copyrightSign
);
106 ret
.Replace("(C)", copyrightSign
);
107 #endif // wxUSE_UNICODE
112 void wxAboutDialogInfo::SetVersion(const wxString
& version
,
113 const wxString
& longVersion
)
115 if ( version
.empty() )
119 wxASSERT_MSG( longVersion
.empty(),
120 "long version should be empty if version is");
122 m_longVersion
.clear();
124 else // setting valid version
128 if ( longVersion
.empty() )
129 m_longVersion
= _("Version ") + m_version
;
131 m_longVersion
= longVersion
;
135 // ----------------------------------------------------------------------------
136 // wxGenericAboutDialog
137 // ----------------------------------------------------------------------------
139 bool wxGenericAboutDialog::Create(const wxAboutDialogInfo
& info
, wxWindow
* parent
)
141 if ( !wxDialog::Create(parent
, wxID_ANY
, _("About ") + info
.GetName(),
142 wxDefaultPosition
, wxDefaultSize
, wxRESIZE_BORDER
|wxDEFAULT_DIALOG_STYLE
) )
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
);
155 m_sizerText
->Add(label
, wxSizerFlags().Centre().Border());
156 m_sizerText
->AddSpacer(5);
158 AddText(info
.GetCopyrightToDisplay());
159 AddText(info
.GetDescription());
161 if ( info
.HasWebSite() )
163 #if wxUSE_HYPERLINKCTRL
164 AddControl(new wxHyperlinkCtrl(this, wxID_ANY
,
165 info
.GetWebSiteDescription(),
166 info
.GetWebSiteURL()));
168 AddText(info
.GetWebSiteURL());
169 #endif // wxUSE_HYPERLINKCTRL/!wxUSE_HYPERLINKCTRL
173 if ( info
.HasLicence() )
174 AddCollapsiblePane(_("License"), info
.GetLicence());
176 if ( info
.HasDevelopers() )
177 AddCollapsiblePane(_("Developers"),
178 AllAsString(info
.GetDevelopers()));
180 if ( info
.HasDocWriters() )
181 AddCollapsiblePane(_("Documentation writers"),
182 AllAsString(info
.GetDocWriters()));
184 if ( info
.HasArtists() )
185 AddCollapsiblePane(_("Artists"),
186 AllAsString(info
.GetArtists()));
188 if ( info
.HasTranslators() )
189 AddCollapsiblePane(_("Translators"),
190 AllAsString(info
.GetTranslators()));
191 #endif // wxUSE_COLLPANE
193 DoAddCustomControls();
196 wxSizer
*sizerIconAndText
= new wxBoxSizer(wxHORIZONTAL
);
198 wxIcon icon
= info
.GetIcon();
201 sizerIconAndText
->Add(new wxStaticBitmap(this, wxID_ANY
, icon
),
202 wxSizerFlags().Border(wxRIGHT
));
204 #endif // wxUSE_STATBMP
205 sizerIconAndText
->Add(m_sizerText
, wxSizerFlags(1).Expand());
207 wxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
208 sizerTop
->Add(sizerIconAndText
, wxSizerFlags(1).Expand().Border());
210 // Mac typically doesn't use OK buttons just for dismissing dialogs.
211 #if !defined(__WXMAC__)
212 wxSizer
*sizerBtns
= CreateButtonSizer(wxOK
);
215 sizerTop
->Add(sizerBtns
, wxSizerFlags().Expand().Border());
219 SetSizerAndFit(sizerTop
);
226 void wxGenericAboutDialog::AddControl(wxWindow
*win
, const wxSizerFlags
& flags
)
228 wxCHECK_RET( m_sizerText
, wxT("can only be called after Create()") );
229 wxASSERT_MSG( win
, wxT("can't add NULL window to about dialog") );
231 m_sizerText
->Add(win
, flags
);
234 void wxGenericAboutDialog::AddControl(wxWindow
*win
)
236 AddControl(win
, wxSizerFlags().Border(wxDOWN
).Centre());
239 void wxGenericAboutDialog::AddText(const wxString
& text
)
242 AddControl(new wxStaticText(this, wxID_ANY
, text
));
245 void wxGenericAboutDialog::AddCollapsiblePane(const wxString
& title
,
246 const wxString
& text
)
248 wxCollapsiblePane
*pane
= new wxCollapsiblePane(this, wxID_ANY
, title
);
249 wxWindow
* const paneContents
= pane
->GetPane();
250 wxStaticText
*txt
= new wxStaticText(paneContents
, wxID_ANY
, text
,
251 wxDefaultPosition
, wxDefaultSize
,
254 // don't make the text unreasonably wide
255 static const int maxWidth
= wxGetDisplaySize().x
/3;
259 // we need a sizer to make this text expand to fill the entire pane area
260 wxSizer
* const sizerPane
= new wxBoxSizer(wxHORIZONTAL
);
261 sizerPane
->Add(txt
, wxSizerFlags(1).Expand());
262 paneContents
->SetSizer(sizerPane
);
264 // NB: all the wxCollapsiblePanes must be added with a null proportion value
265 m_sizerText
->Add(pane
, wxSizerFlags(0).Expand().Border(wxBOTTOM
));
268 // ----------------------------------------------------------------------------
270 // ----------------------------------------------------------------------------
272 void wxGenericAboutBox(const wxAboutDialogInfo
& info
, wxWindow
* parent
)
274 #if !defined(__WXGTK__) && !defined(__WXMAC__)
275 wxGenericAboutDialog
dlg(info
, parent
);
278 wxGenericAboutDialog
* dlg
= new wxGenericAboutDialog(info
, parent
);
283 // currently wxAboutBox is implemented natively only under these platforms, for
284 // the others we provide a generic fallback here
285 #if !defined(__WXMSW__) && !defined(__WXMAC__) && !defined(__WXGTK26__)
287 void wxAboutBox(const wxAboutDialogInfo
& info
, wxWindow
* parent
)
289 wxGenericAboutBox(info
, parent
);
292 #endif // platforms without native about dialog
295 #endif // wxUSE_ABOUTDLG