]>
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
, wxWindow
* parent
)
118 if ( !wxDialog::Create(parent
, wxID_ANY
, _("About ") + info
.GetName(),
119 wxDefaultPosition
, wxDefaultSize
, wxRESIZE_BORDER
|wxDEFAULT_DIALOG_STYLE
) )
122 m_sizerText
= new wxBoxSizer(wxVERTICAL
);
123 wxString nameAndVersion
= info
.GetName();
124 if ( info
.HasVersion() )
125 nameAndVersion
<< _T(' ') << info
.GetVersion();
126 wxStaticText
*label
= new wxStaticText(this, wxID_ANY
, nameAndVersion
);
127 wxFont
fontBig(*wxNORMAL_FONT
);
128 fontBig
.SetPointSize(fontBig
.GetPointSize() + 2);
129 fontBig
.SetWeight(wxFONTWEIGHT_BOLD
);
130 label
->SetFont(fontBig
);
132 m_sizerText
->Add(label
, wxSizerFlags().Centre().Border());
133 m_sizerText
->AddSpacer(5);
135 AddText(info
.GetCopyrightToDisplay());
136 AddText(info
.GetDescription());
138 if ( info
.HasWebSite() )
140 #if wxUSE_HYPERLINKCTRL
141 AddControl(new wxHyperlinkCtrl(this, wxID_ANY
,
142 info
.GetWebSiteDescription(),
143 info
.GetWebSiteURL()));
145 AddText(info
.GetWebSiteURL());
146 #endif // wxUSE_HYPERLINKCTRL/!wxUSE_HYPERLINKCTRL
150 if ( info
.HasLicence() )
151 AddCollapsiblePane(_("License"), info
.GetLicence());
153 if ( info
.HasDevelopers() )
154 AddCollapsiblePane(_("Developers"),
155 AllAsString(info
.GetDevelopers()));
157 if ( info
.HasDocWriters() )
158 AddCollapsiblePane(_("Documentation writers"),
159 AllAsString(info
.GetDocWriters()));
161 if ( info
.HasArtists() )
162 AddCollapsiblePane(_("Artists"),
163 AllAsString(info
.GetArtists()));
165 if ( info
.HasTranslators() )
166 AddCollapsiblePane(_("Translators"),
167 AllAsString(info
.GetTranslators()));
168 #endif // wxUSE_COLLPANE
170 DoAddCustomControls();
173 wxSizer
*sizerIconAndText
= new wxBoxSizer(wxHORIZONTAL
);
175 wxIcon icon
= info
.GetIcon();
178 sizerIconAndText
->Add(new wxStaticBitmap(this, wxID_ANY
, icon
),
179 wxSizerFlags().Border(wxRIGHT
));
181 #endif // wxUSE_STATBMP
182 sizerIconAndText
->Add(m_sizerText
, wxSizerFlags(1).Expand());
184 wxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
185 sizerTop
->Add(sizerIconAndText
, wxSizerFlags(1).Expand().Border());
187 // Mac typically doesn't use OK buttons just for dismissing dialogs.
188 #if !defined(__WXMAC__)
189 wxSizer
*sizerBtns
= CreateButtonSizer(wxOK
);
192 sizerTop
->Add(sizerBtns
, wxSizerFlags().Expand().Border());
196 SetSizerAndFit(sizerTop
);
203 void wxGenericAboutDialog::AddControl(wxWindow
*win
, const wxSizerFlags
& flags
)
205 wxCHECK_RET( m_sizerText
, _T("can only be called after Create()") );
206 wxASSERT_MSG( win
, _T("can't add NULL window to about dialog") );
208 m_sizerText
->Add(win
, flags
);
211 void wxGenericAboutDialog::AddControl(wxWindow
*win
)
213 AddControl(win
, wxSizerFlags().Border(wxDOWN
).Centre());
216 void wxGenericAboutDialog::AddText(const wxString
& text
)
219 AddControl(new wxStaticText(this, wxID_ANY
, text
));
222 void wxGenericAboutDialog::AddCollapsiblePane(const wxString
& title
,
223 const wxString
& text
)
225 wxCollapsiblePane
*pane
= new wxCollapsiblePane(this, wxID_ANY
, title
);
226 wxStaticText
*txt
= new wxStaticText(pane
->GetPane(), wxID_ANY
, text
,
227 wxDefaultPosition
, wxDefaultSize
,
230 // don't make the text unreasonably wide
231 static const int maxWidth
= wxGetDisplaySize().x
/3;
234 // NB: all the wxCollapsiblePanes must be added with a null proportion value
235 m_sizerText
->Add(pane
, wxSizerFlags(0).Expand().Border(wxBOTTOM
));
238 // ----------------------------------------------------------------------------
240 // ----------------------------------------------------------------------------
242 void wxGenericAboutBox(const wxAboutDialogInfo
& info
, wxWindow
* parent
)
244 #if !defined(__WXGTK__) && !defined(__WXMAC__)
245 wxGenericAboutDialog
dlg(info
, parent
);
248 wxGenericAboutDialog
* dlg
= new wxGenericAboutDialog(info
, parent
);
253 // currently wxAboutBox is implemented natively only under these platforms, for
254 // the others we provide a generic fallback here
255 #if !defined(__WXMSW__) && !defined(__WXMAC__) && !defined(__WXGTK26__)
257 void wxAboutBox(const wxAboutDialogInfo
& info
, wxWindow
* parent
)
259 wxGenericAboutBox(info
, parent
);
262 #endif // platforms without native about dialog
265 #endif // wxUSE_ABOUTDLG