]>
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 ? _T("\n") : _T(", "));
60 // ----------------------------------------------------------------------------
62 // ----------------------------------------------------------------------------
64 wxString
wxAboutDialogInfo::GetDescriptionAndCredits() const
66 wxString s
= GetDescription();
70 if ( HasDevelopers() )
71 s
<< _T('\n') << _("Developed by ") << AllAsString(GetDevelopers());
73 if ( HasDocWriters() )
74 s
<< _T('\n') << _("Documentation by ") << AllAsString(GetDocWriters());
77 s
<< _T('\n') << _("Graphics art by ") << AllAsString(GetArtists());
79 if ( HasTranslators() )
80 s
<< _T('\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
;
103 ret
.Replace("(c)", "\u00A9");
104 ret
.Replace("(C)", "\u00A9");
109 // ----------------------------------------------------------------------------
110 // wxGenericAboutDialog
111 // ----------------------------------------------------------------------------
113 bool wxGenericAboutDialog::Create(const wxAboutDialogInfo
& info
)
115 // this is a modal dialog thus we'll use GetParentForModalDialog:
116 if ( !wxDialog::Create(GetParentForModalDialog(), wxID_ANY
, _("About ") + info
.GetName(),
117 wxDefaultPosition
, wxDefaultSize
, wxRESIZE_BORDER
|wxDEFAULT_DIALOG_STYLE
) )
120 m_sizerText
= new wxBoxSizer(wxVERTICAL
);
121 wxString nameAndVersion
= info
.GetName();
122 if ( info
.HasVersion() )
123 nameAndVersion
<< _T(' ') << info
.GetVersion();
124 wxStaticText
*label
= new wxStaticText(this, wxID_ANY
, nameAndVersion
);
125 wxFont
fontBig(*wxNORMAL_FONT
);
126 fontBig
.SetPointSize(fontBig
.GetPointSize() + 2);
127 fontBig
.SetWeight(wxFONTWEIGHT_BOLD
);
128 label
->SetFont(fontBig
);
130 m_sizerText
->Add(label
, wxSizerFlags().Centre().Border());
131 m_sizerText
->AddSpacer(5);
133 AddText(info
.GetCopyrightToDisplay());
134 AddText(info
.GetDescription());
136 if ( info
.HasWebSite() )
138 #if wxUSE_HYPERLINKCTRL
139 AddControl(new wxHyperlinkCtrl(this, wxID_ANY
,
140 info
.GetWebSiteDescription(),
141 info
.GetWebSiteURL()));
143 AddText(info
.GetWebSiteURL());
144 #endif // wxUSE_HYPERLINKCTRL/!wxUSE_HYPERLINKCTRL
148 if ( info
.HasLicence() )
149 AddCollapsiblePane(_("License"), info
.GetLicence());
151 if ( info
.HasDevelopers() )
152 AddCollapsiblePane(_("Developers"),
153 AllAsString(info
.GetDevelopers()));
155 if ( info
.HasDocWriters() )
156 AddCollapsiblePane(_("Documentation writers"),
157 AllAsString(info
.GetDocWriters()));
159 if ( info
.HasArtists() )
160 AddCollapsiblePane(_("Artists"),
161 AllAsString(info
.GetArtists()));
163 if ( info
.HasTranslators() )
164 AddCollapsiblePane(_("Translators"),
165 AllAsString(info
.GetTranslators()));
166 #endif // wxUSE_COLLPANE
168 DoAddCustomControls();
171 wxSizer
*sizerIconAndText
= new wxBoxSizer(wxHORIZONTAL
);
173 wxIcon icon
= info
.GetIcon();
176 sizerIconAndText
->Add(new wxStaticBitmap(this, wxID_ANY
, icon
),
177 wxSizerFlags().Border(wxRIGHT
));
179 #endif // wxUSE_STATBMP
180 sizerIconAndText
->Add(m_sizerText
, wxSizerFlags(1).Expand());
182 wxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
183 sizerTop
->Add(sizerIconAndText
, wxSizerFlags(1).Expand().Border());
185 wxSizer
*sizerBtns
= CreateButtonSizer(wxOK
);
188 sizerTop
->Add(sizerBtns
, wxSizerFlags().Expand().Border());
191 SetSizerAndFit(sizerTop
);
198 void wxGenericAboutDialog::AddControl(wxWindow
*win
, const wxSizerFlags
& flags
)
200 wxCHECK_RET( m_sizerText
, _T("can only be called after Create()") );
201 wxASSERT_MSG( win
, _T("can't add NULL window to about dialog") );
203 m_sizerText
->Add(win
, flags
);
206 void wxGenericAboutDialog::AddControl(wxWindow
*win
)
208 AddControl(win
, wxSizerFlags().Border(wxDOWN
).Centre());
211 void wxGenericAboutDialog::AddText(const wxString
& text
)
214 AddControl(new wxStaticText(this, wxID_ANY
, text
));
217 void wxGenericAboutDialog::AddCollapsiblePane(const wxString
& title
,
218 const wxString
& text
)
220 wxCollapsiblePane
*pane
= new wxCollapsiblePane(this, wxID_ANY
, title
);
221 wxStaticText
*txt
= new wxStaticText(pane
->GetPane(), wxID_ANY
, text
,
222 wxDefaultPosition
, wxDefaultSize
,
225 // don't make the text unreasonably wide
226 static const int maxWidth
= wxGetDisplaySize().x
/3;
229 // NB: all the wxCollapsiblePanes must be added with a null proportion value
230 m_sizerText
->Add(pane
, wxSizerFlags(0).Expand().Border(wxBOTTOM
));
233 // ----------------------------------------------------------------------------
235 // ----------------------------------------------------------------------------
237 void wxGenericAboutBox(const wxAboutDialogInfo
& info
)
239 wxGenericAboutDialog
dlg(info
);
243 // currently wxAboutBox is implemented natively only under these platforms, for
244 // the others we provide a generic fallback here
245 #if !defined(__WXMSW__) && !defined(__WXMAC__) && !defined(__WXGTK26__)
247 void wxAboutBox(const wxAboutDialogInfo
& info
)
249 wxGenericAboutBox(info
);
252 #endif // platforms without native about dialog
255 #endif // wxUSE_ABOUTDLG