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"
31 #include "wx/statbmp.h"
32 #include "wx/stattext.h"
35 #include "wx/aboutdlg.h"
36 #include "wx/generic/aboutdlgg.h"
38 #include "wx/hyperlink.h"
40 // ============================================================================
42 // ============================================================================
44 // ----------------------------------------------------------------------------
46 // ----------------------------------------------------------------------------
48 // helper function: returns all array elements in a single comma-separated and
49 // newline-terminated string
50 static wxString
AllAsString(const wxArrayString
& a
)
53 const size_t count
= a
.size();
54 for ( size_t n
= 0; n
< count
; n
++ )
56 s
<< a
[n
] << (n
== count
- 1 ?
_T("\n") : _T(", "));
62 wxString wxAboutDialogInfo
::GetDescriptionAndCredits() const
64 wxString s
= GetDescription();
68 if ( HasDevelopers() )
69 s
<< _T('\n') << _("Developed by ") << AllAsString(GetDevelopers());
71 if ( HasDocWriters() )
72 s
<< _T('\n') << ("Documentation by ") << AllAsString(GetDocWriters());
75 s
<< _T('\n') << ("Graphics art by ") << AllAsString(GetArtists());
77 if ( HasTranslators() )
78 s
<< _T('\n') << ("Translations by ") << AllAsString(GetTranslators());
83 // ----------------------------------------------------------------------------
85 // ----------------------------------------------------------------------------
87 bool wxAboutDialog
::Create(const wxAboutDialogInfo
& info
)
89 // TODO: should we use main frame as parent by default here?
90 if ( !wxDialog
::Create(NULL
, wxID_ANY
, _("About ") + info
.GetName()) )
93 m_sizerText
= new wxBoxSizer(wxVERTICAL
);
94 wxString nameAndVersion
= info
.GetName();
95 if ( info
.HasVersion() )
96 nameAndVersion
<< _T(' ') << info
.GetVersion();
97 wxStaticText
*label
= new wxStaticText(this, wxID_ANY
, nameAndVersion
);
98 wxFont
fontBig(*wxNORMAL_FONT
);
99 fontBig
.SetPointSize(fontBig
.GetPointSize() + 2);
100 fontBig
.SetWeight(wxFONTWEIGHT_BOLD
);
101 label
->SetFont(fontBig
);
103 m_sizerText
->Add(label
, wxSizerFlags().Centre().Border());
104 m_sizerText
->AddSpacer(5);
106 AddText(info
.GetCopyright());
107 AddText(info
.GetDescription());
109 if ( info
.HasWebSite() )
111 #if wxUSE_HYPERLINKCTRL
112 AddControl(new wxHyperlinkCtrl(this, wxID_ANY
,
113 info
.GetWebSiteDescription(),
114 info
.GetWebSiteURL()));
116 AddText(info
.GetWebSiteURL());
117 #endif // wxUSE_HYPERLINKCTRL/!wxUSE_HYPERLINKCTRL
122 // TODO: add credits (developers, artists, doc writers, translators)
125 wxSizer
*sizerIconAndText
= new wxBoxSizer(wxHORIZONTAL
);
127 wxIcon icon
= info
.GetIcon();
128 if ( !icon
.Ok() && wxTheApp
)
130 const wxTopLevelWindow
* const
131 tlw
= wxDynamicCast(wxTheApp
->GetTopWindow(), wxTopLevelWindow
);
133 icon
= tlw
->GetIcon();
138 sizerIconAndText
->Add(new wxStaticBitmap(this, wxID_ANY
, icon
),
139 wxSizerFlags().Border(wxRIGHT
));
141 #endif // wxUSE_STATBMP
142 sizerIconAndText
->Add(m_sizerText
, wxSizerFlags(1).Expand());
144 wxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
145 sizerTop
->Add(sizerIconAndText
, wxSizerFlags(1).Expand().Border());
146 sizerTop
->Add(new wxButton(this, wxID_OK
), wxSizerFlags().Right().Border());
147 SetSizerAndFit(sizerTop
);
153 void wxAboutDialog
::AddControl(wxWindow
*win
)
155 wxCHECK_RET( m_sizerText
, _T("can only be called after Create()") );
156 wxASSERT_MSG( win
, _T("can't add NULL window to about dialog") );
158 m_sizerText
->Add(win
, wxSizerFlags().Border(wxDOWN
).Centre());
161 void wxAboutDialog
::AddText(const wxString
& text
)
164 AddControl(new wxStaticText(this, wxID_ANY
, text
));
167 // ----------------------------------------------------------------------------
169 // ----------------------------------------------------------------------------
171 void wxGenericAboutBox(const wxAboutDialogInfo
& info
)
173 wxAboutDialog
dlg(info
);
177 // currently wxAboutBox is implemented natively only under these platforms, for
178 // the others we provide a generic fallback here
179 #if !defined(__WXMSW__) && !defined(__WXMAC__)
181 void wxAboutBox(const wxAboutDialogInfo
& info
)
183 wxGenericAboutBox(info
);
186 #endif // platforms without native about dialog
189 #endif // wxUSE_ABOUTDLG