]>
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
;
104 const wxString copyrightSign
= wxString::FromUTF8("\xc2\xa9");
105 ret
.Replace("(c)", copyrightSign
);
106 ret
.Replace("(C)", copyrightSign
);
107 #endif // wxUSE_UNICODE
112 // ----------------------------------------------------------------------------
113 // wxGenericAboutDialog
114 // ----------------------------------------------------------------------------
116 bool wxGenericAboutDialog::Create(const wxAboutDialogInfo
& info
)
118 // this is a modal dialog thus we'll use GetParentForModalDialog:
119 if ( !wxDialog::Create(GetParentForModalDialog(), wxID_ANY
, _("About ") + info
.GetName(),
120 wxDefaultPosition
, wxDefaultSize
, wxRESIZE_BORDER
|wxDEFAULT_DIALOG_STYLE
) )
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
);
133 m_sizerText
->Add(label
, wxSizerFlags().Centre().Border());
134 m_sizerText
->AddSpacer(5);
136 AddText(info
.GetCopyrightToDisplay());
137 AddText(info
.GetDescription());
139 if ( info
.HasWebSite() )
141 #if wxUSE_HYPERLINKCTRL
142 AddControl(new wxHyperlinkCtrl(this, wxID_ANY
,
143 info
.GetWebSiteDescription(),
144 info
.GetWebSiteURL()));
146 AddText(info
.GetWebSiteURL());
147 #endif // wxUSE_HYPERLINKCTRL/!wxUSE_HYPERLINKCTRL
151 if ( info
.HasLicence() )
152 AddCollapsiblePane(_("License"), info
.GetLicence());
154 if ( info
.HasDevelopers() )
155 AddCollapsiblePane(_("Developers"),
156 AllAsString(info
.GetDevelopers()));
158 if ( info
.HasDocWriters() )
159 AddCollapsiblePane(_("Documentation writers"),
160 AllAsString(info
.GetDocWriters()));
162 if ( info
.HasArtists() )
163 AddCollapsiblePane(_("Artists"),
164 AllAsString(info
.GetArtists()));
166 if ( info
.HasTranslators() )
167 AddCollapsiblePane(_("Translators"),
168 AllAsString(info
.GetTranslators()));
169 #endif // wxUSE_COLLPANE
171 DoAddCustomControls();
174 wxSizer
*sizerIconAndText
= new wxBoxSizer(wxHORIZONTAL
);
176 wxIcon icon
= info
.GetIcon();
179 sizerIconAndText
->Add(new wxStaticBitmap(this, wxID_ANY
, icon
),
180 wxSizerFlags().Border(wxRIGHT
));
182 #endif // wxUSE_STATBMP
183 sizerIconAndText
->Add(m_sizerText
, wxSizerFlags(1).Expand());
185 wxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
186 sizerTop
->Add(sizerIconAndText
, wxSizerFlags(1).Expand().Border());
188 // Mac typically doesn't use OK buttons just for dismissing dialogs.
189 #if !defined(__WXMAC__)
190 wxSizer
*sizerBtns
= CreateButtonSizer(wxOK
);
193 sizerTop
->Add(sizerBtns
, wxSizerFlags().Expand().Border());
197 SetSizerAndFit(sizerTop
);
204 void wxGenericAboutDialog::AddControl(wxWindow
*win
, const wxSizerFlags
& flags
)
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") );
209 m_sizerText
->Add(win
, flags
);
212 void wxGenericAboutDialog::AddControl(wxWindow
*win
)
214 AddControl(win
, wxSizerFlags().Border(wxDOWN
).Centre());
217 void wxGenericAboutDialog::AddText(const wxString
& text
)
220 AddControl(new wxStaticText(this, wxID_ANY
, text
));
223 void wxGenericAboutDialog::AddCollapsiblePane(const wxString
& title
,
224 const wxString
& text
)
226 wxCollapsiblePane
*pane
= new wxCollapsiblePane(this, wxID_ANY
, title
);
227 wxStaticText
*txt
= new wxStaticText(pane
->GetPane(), wxID_ANY
, text
,
228 wxDefaultPosition
, wxDefaultSize
,
231 // don't make the text unreasonably wide
232 static const int maxWidth
= wxGetDisplaySize().x
/3;
235 // NB: all the wxCollapsiblePanes must be added with a null proportion value
236 m_sizerText
->Add(pane
, wxSizerFlags(0).Expand().Border(wxBOTTOM
));
239 // ----------------------------------------------------------------------------
241 // ----------------------------------------------------------------------------
243 void wxGenericAboutBox(const wxAboutDialogInfo
& info
)
245 #if !defined(__WXGTK__) && !defined(__WXMAC__)
246 wxGenericAboutDialog
dlg(info
);
249 wxGenericAboutDialog
* dlg
= new wxGenericAboutDialog(info
);
254 // currently wxAboutBox is implemented natively only under these platforms, for
255 // the others we provide a generic fallback here
256 #if !defined(__WXMSW__) && !defined(__WXMAC__) && !defined(__WXGTK26__)
258 void wxAboutBox(const wxAboutDialogInfo
& info
)
260 wxGenericAboutBox(info
);
263 #endif // platforms without native about dialog
266 #endif // wxUSE_ABOUTDLG