]>
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
6 // Copyright: (c) 2006 Vadim Zeitlin <vadim@wxwindows.org>
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
10 // ============================================================================
12 // ============================================================================
14 // ----------------------------------------------------------------------------
16 // ----------------------------------------------------------------------------
18 // for compilers that support precompilation, includes "wx.h".
19 #include "wx/wxprec.h"
29 #include "wx/statbmp.h"
30 #include "wx/stattext.h"
31 #include "wx/button.h"
34 #include "wx/aboutdlg.h"
35 #include "wx/generic/aboutdlgg.h"
37 #include "wx/hyperlink.h"
38 #include "wx/collpane.h"
40 // ============================================================================
42 // ============================================================================
44 // helper function: returns all array elements in a single comma-separated and
45 // newline-terminated string
46 static wxString
AllAsString(const wxArrayString
& a
)
49 const size_t count
= a
.size();
51 for ( size_t n
= 0; n
< count
; n
++ )
53 s
<< a
[n
] << (n
== count
- 1 ? wxT("\n") : wxT(", "));
59 // ----------------------------------------------------------------------------
61 // ----------------------------------------------------------------------------
63 wxString
wxAboutDialogInfo::GetDescriptionAndCredits() const
65 wxString s
= GetDescription();
69 if ( HasDevelopers() )
70 s
<< wxT('\n') << _("Developed by ") << AllAsString(GetDevelopers());
72 if ( HasDocWriters() )
73 s
<< wxT('\n') << _("Documentation by ") << AllAsString(GetDocWriters());
76 s
<< wxT('\n') << _("Graphics art by ") << AllAsString(GetArtists());
78 if ( HasTranslators() )
79 s
<< wxT('\n') << _("Translations by ") << AllAsString(GetTranslators());
84 wxIcon
wxAboutDialogInfo::GetIcon() const
87 if ( !icon
.IsOk() && wxTheApp
)
89 const wxTopLevelWindow
* const
90 tlw
= wxDynamicCast(wxTheApp
->GetTopWindow(), wxTopLevelWindow
);
92 icon
= tlw
->GetIcon();
98 wxString
wxAboutDialogInfo::GetCopyrightToDisplay() const
100 wxString ret
= m_copyright
;
103 const wxString copyrightSign
= wxString::FromUTF8("\xc2\xa9");
104 ret
.Replace("(c)", copyrightSign
);
105 ret
.Replace("(C)", copyrightSign
);
106 #endif // wxUSE_UNICODE
111 void wxAboutDialogInfo::SetVersion(const wxString
& version
,
112 const wxString
& longVersion
)
114 if ( version
.empty() )
118 wxASSERT_MSG( longVersion
.empty(),
119 "long version should be empty if version is");
121 m_longVersion
.clear();
123 else // setting valid version
127 if ( longVersion
.empty() )
128 m_longVersion
= _("Version ") + m_version
;
130 m_longVersion
= longVersion
;
134 // ----------------------------------------------------------------------------
135 // wxGenericAboutDialog
136 // ----------------------------------------------------------------------------
138 bool wxGenericAboutDialog::Create(const wxAboutDialogInfo
& info
, wxWindow
* parent
)
140 if ( !wxDialog::Create(parent
, wxID_ANY
, wxString::Format(_("About %s"), info
.GetName()),
141 wxDefaultPosition
, wxDefaultSize
, wxRESIZE_BORDER
|wxDEFAULT_DIALOG_STYLE
) )
144 m_sizerText
= new wxBoxSizer(wxVERTICAL
);
145 wxString nameAndVersion
= info
.GetName();
146 if ( info
.HasVersion() )
147 nameAndVersion
<< wxT(' ') << info
.GetVersion();
148 wxStaticText
*label
= new wxStaticText(this, wxID_ANY
, nameAndVersion
);
149 wxFont
fontBig(*wxNORMAL_FONT
);
150 fontBig
.SetPointSize(fontBig
.GetPointSize() + 2);
151 fontBig
.SetWeight(wxFONTWEIGHT_BOLD
);
152 label
->SetFont(fontBig
);
154 m_sizerText
->Add(label
, wxSizerFlags().Centre().Border());
155 m_sizerText
->AddSpacer(5);
157 AddText(info
.GetCopyrightToDisplay());
158 AddText(info
.GetDescription());
160 if ( info
.HasWebSite() )
162 #if wxUSE_HYPERLINKCTRL
163 AddControl(new wxHyperlinkCtrl(this, wxID_ANY
,
164 info
.GetWebSiteDescription(),
165 info
.GetWebSiteURL()));
167 AddText(info
.GetWebSiteURL());
168 #endif // wxUSE_HYPERLINKCTRL/!wxUSE_HYPERLINKCTRL
172 if ( info
.HasLicence() )
173 AddCollapsiblePane(_("License"), info
.GetLicence());
175 if ( info
.HasDevelopers() )
176 AddCollapsiblePane(_("Developers"),
177 AllAsString(info
.GetDevelopers()));
179 if ( info
.HasDocWriters() )
180 AddCollapsiblePane(_("Documentation writers"),
181 AllAsString(info
.GetDocWriters()));
183 if ( info
.HasArtists() )
184 AddCollapsiblePane(_("Artists"),
185 AllAsString(info
.GetArtists()));
187 if ( info
.HasTranslators() )
188 AddCollapsiblePane(_("Translators"),
189 AllAsString(info
.GetTranslators()));
190 #endif // wxUSE_COLLPANE
192 DoAddCustomControls();
195 wxSizer
*sizerIconAndText
= new wxBoxSizer(wxHORIZONTAL
);
197 wxIcon icon
= info
.GetIcon();
200 sizerIconAndText
->Add(new wxStaticBitmap(this, wxID_ANY
, icon
),
201 wxSizerFlags().Border(wxRIGHT
));
203 #endif // wxUSE_STATBMP
204 sizerIconAndText
->Add(m_sizerText
, wxSizerFlags(1).Expand());
206 wxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
207 sizerTop
->Add(sizerIconAndText
, wxSizerFlags(1).Expand().Border());
209 // Mac typically doesn't use OK buttons just for dismissing dialogs.
210 #if !defined(__WXMAC__)
211 wxSizer
*sizerBtns
= CreateButtonSizer(wxOK
);
214 sizerTop
->Add(sizerBtns
, wxSizerFlags().Expand().Border());
218 SetSizerAndFit(sizerTop
);
222 #if !wxUSE_MODAL_ABOUT_DIALOG
223 Connect(wxEVT_CLOSE_WINDOW
,
224 wxCloseEventHandler(wxGenericAboutDialog::OnCloseWindow
));
225 Connect(wxID_OK
, wxEVT_BUTTON
,
226 wxCommandEventHandler(wxGenericAboutDialog::OnOK
));
227 #endif // !wxUSE_MODAL_ABOUT_DIALOG
232 void wxGenericAboutDialog::AddControl(wxWindow
*win
, const wxSizerFlags
& flags
)
234 wxCHECK_RET( m_sizerText
, wxT("can only be called after Create()") );
235 wxASSERT_MSG( win
, wxT("can't add NULL window to about dialog") );
237 m_sizerText
->Add(win
, flags
);
240 void wxGenericAboutDialog::AddControl(wxWindow
*win
)
242 AddControl(win
, wxSizerFlags().Border(wxDOWN
).Centre());
245 void wxGenericAboutDialog::AddText(const wxString
& text
)
248 AddControl(new wxStaticText(this, wxID_ANY
, text
));
252 void wxGenericAboutDialog::AddCollapsiblePane(const wxString
& title
,
253 const wxString
& text
)
255 wxCollapsiblePane
*pane
= new wxCollapsiblePane(this, wxID_ANY
, title
);
256 wxWindow
* const paneContents
= pane
->GetPane();
257 wxStaticText
*txt
= new wxStaticText(paneContents
, wxID_ANY
, text
,
258 wxDefaultPosition
, wxDefaultSize
,
261 // don't make the text unreasonably wide
262 static const int maxWidth
= wxGetDisplaySize().x
/3;
266 // we need a sizer to make this text expand to fill the entire pane area
267 wxSizer
* const sizerPane
= new wxBoxSizer(wxHORIZONTAL
);
268 sizerPane
->Add(txt
, wxSizerFlags(1).Expand());
269 paneContents
->SetSizer(sizerPane
);
271 // NB: all the wxCollapsiblePanes must be added with a null proportion value
272 m_sizerText
->Add(pane
, wxSizerFlags(0).Expand().Border(wxBOTTOM
));
276 #if !wxUSE_MODAL_ABOUT_DIALOG
278 void wxGenericAboutDialog::OnCloseWindow(wxCloseEvent
& event
)
285 void wxGenericAboutDialog::OnOK(wxCommandEvent
& WXUNUSED(event
))
287 // By default a modeless dialog would be just hidden, destroy this one
292 #endif // !wxUSE_MODAL_ABOUT_DIALOG
294 // ----------------------------------------------------------------------------
296 // ----------------------------------------------------------------------------
298 void wxGenericAboutBox(const wxAboutDialogInfo
& info
, wxWindow
* parent
)
300 #if wxUSE_MODAL_ABOUT_DIALOG
301 wxGenericAboutDialog
dlg(info
, parent
);
304 wxGenericAboutDialog
* dlg
= new wxGenericAboutDialog(info
, parent
);
309 // currently wxAboutBox is implemented natively only under these platforms, for
310 // the others we provide a generic fallback here
311 #if !defined(__WXMSW__) && !defined(__WXMAC__) && \
312 (!defined(__WXGTK20__) || defined(__WXUNIVERSAL__))
314 void wxAboutBox(const wxAboutDialogInfo
& info
, wxWindow
* parent
)
316 wxGenericAboutBox(info
, parent
);
319 #endif // platforms without native about dialog
322 #endif // wxUSE_ABOUTDLG