]>
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 // ----------------------------------------------------------------------------
47 // ----------------------------------------------------------------------------
49 // helper function: returns all array elements in a single comma-separated and
50 // newline-terminated string
51 static wxString
AllAsString(const wxArrayString
& a
)
54 const size_t count
= a
.size();
55 for ( size_t n
= 0; n
< count
; n
++ )
57 s
<< a
[n
] << (n
== count
- 1 ? _T("\n") : _T(", "));
63 wxString
wxAboutDialogInfo::GetDescriptionAndCredits() const
65 wxString s
= GetDescription();
69 if ( HasDevelopers() )
70 s
<< _T('\n') << _("Developed by ") << AllAsString(GetDevelopers());
72 if ( HasDocWriters() )
73 s
<< _T('\n') << _("Documentation by ") << AllAsString(GetDocWriters());
76 s
<< _T('\n') << _("Graphics art by ") << AllAsString(GetArtists());
78 if ( HasTranslators() )
79 s
<< _T('\n') << _("Translations by ") << AllAsString(GetTranslators());
84 wxIcon
wxAboutDialogInfo::GetIcon() const
87 if ( !icon
.Ok() && wxTheApp
)
89 const wxTopLevelWindow
* const
90 tlw
= wxDynamicCast(wxTheApp
->GetTopWindow(), wxTopLevelWindow
);
92 icon
= tlw
->GetIcon();
98 // ----------------------------------------------------------------------------
99 // wxGenericAboutDialog
100 // ----------------------------------------------------------------------------
102 bool wxGenericAboutDialog::Create(const wxAboutDialogInfo
& info
)
104 // TODO: should we use main frame as parent by default here?
105 if ( !wxDialog::Create(NULL
, wxID_ANY
, _("About ") + info
.GetName(),
106 wxDefaultPosition
, wxDefaultSize
, wxRESIZE_BORDER
|wxDEFAULT_DIALOG_STYLE
) )
109 m_sizerText
= new wxBoxSizer(wxVERTICAL
);
110 wxString nameAndVersion
= info
.GetName();
111 if ( info
.HasVersion() )
112 nameAndVersion
<< _T(' ') << info
.GetVersion();
113 wxStaticText
*label
= new wxStaticText(this, wxID_ANY
, nameAndVersion
);
114 wxFont
fontBig(*wxNORMAL_FONT
);
115 fontBig
.SetPointSize(fontBig
.GetPointSize() + 2);
116 fontBig
.SetWeight(wxFONTWEIGHT_BOLD
);
117 label
->SetFont(fontBig
);
119 m_sizerText
->Add(label
, wxSizerFlags().Centre().Border());
120 m_sizerText
->AddSpacer(5);
122 AddText(info
.GetCopyright());
123 AddText(info
.GetDescription());
125 if ( info
.HasWebSite() )
127 #if wxUSE_HYPERLINKCTRL
128 AddControl(new wxHyperlinkCtrl(this, wxID_ANY
,
129 info
.GetWebSiteDescription(),
130 info
.GetWebSiteURL()));
132 AddText(info
.GetWebSiteURL());
133 #endif // wxUSE_HYPERLINKCTRL/!wxUSE_HYPERLINKCTRL
137 if ( info
.HasLicence() )
140 licensepnl
= new wxCollapsiblePane(this, wxID_ANY
, wxT("License"));
142 new wxStaticText(licensepnl
->GetPane(), wxID_ANY
, info
.GetLicence(),
143 wxDefaultPosition
, wxDefaultSize
,
146 m_sizerText
->Add(licensepnl
, wxSizerFlags(1).Expand().Border(wxBOTTOM
));
149 // TODO: add credits (developers, artists, doc writers, translators)
151 DoAddCustomControls();
154 wxSizer
*sizerIconAndText
= new wxBoxSizer(wxHORIZONTAL
);
156 wxIcon icon
= info
.GetIcon();
159 sizerIconAndText
->Add(new wxStaticBitmap(this, wxID_ANY
, icon
),
160 wxSizerFlags().Border(wxRIGHT
));
162 #endif // wxUSE_STATBMP
163 sizerIconAndText
->Add(m_sizerText
, wxSizerFlags(1).Expand());
165 wxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
166 sizerTop
->Add(sizerIconAndText
, wxSizerFlags(1).Expand().Border());
168 wxSizer
*sizerBtns
= CreateButtonSizer(wxOK
);
171 sizerTop
->Add(sizerBtns
, wxSizerFlags().Expand().Border());
174 SetSizerAndFit(sizerTop
);
181 void wxGenericAboutDialog::AddControl(wxWindow
*win
, const wxSizerFlags
& flags
)
183 wxCHECK_RET( m_sizerText
, _T("can only be called after Create()") );
184 wxASSERT_MSG( win
, _T("can't add NULL window to about dialog") );
186 m_sizerText
->Add(win
, flags
);
189 void wxGenericAboutDialog::AddControl(wxWindow
*win
)
191 AddControl(win
, wxSizerFlags().Border(wxDOWN
).Centre());
194 void wxGenericAboutDialog::AddText(const wxString
& text
)
197 AddControl(new wxStaticText(this, wxID_ANY
, text
));
200 // ----------------------------------------------------------------------------
202 // ----------------------------------------------------------------------------
204 void wxGenericAboutBox(const wxAboutDialogInfo
& info
)
206 wxGenericAboutDialog
dlg(info
);
210 // currently wxAboutBox is implemented natively only under these platforms, for
211 // the others we provide a generic fallback here
212 #if !defined(__WXMSW__) && !defined(__WXMAC__) && !defined(__WXGTK26__)
214 void wxAboutBox(const wxAboutDialogInfo
& info
)
216 wxGenericAboutBox(info
);
219 #endif // platforms without native about dialog
222 #endif // wxUSE_ABOUTDLG