]>
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"
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 wxIcon
wxAboutDialogInfo::GetIcon() const
86 if ( !icon
.Ok() && wxTheApp
)
88 const wxTopLevelWindow
* const
89 tlw
= wxDynamicCast(wxTheApp
->GetTopWindow(), wxTopLevelWindow
);
91 icon
= tlw
->GetIcon();
97 // ----------------------------------------------------------------------------
98 // wxGenericAboutDialog
99 // ----------------------------------------------------------------------------
101 bool wxGenericAboutDialog::Create(const wxAboutDialogInfo
& info
)
103 // TODO: should we use main frame as parent by default here?
104 if ( !wxDialog::Create(NULL
, wxID_ANY
, _("About ") + info
.GetName()) )
107 m_sizerText
= new wxBoxSizer(wxVERTICAL
);
108 wxString nameAndVersion
= info
.GetName();
109 if ( info
.HasVersion() )
110 nameAndVersion
<< _T(' ') << info
.GetVersion();
111 wxStaticText
*label
= new wxStaticText(this, wxID_ANY
, nameAndVersion
);
112 wxFont
fontBig(*wxNORMAL_FONT
);
113 fontBig
.SetPointSize(fontBig
.GetPointSize() + 2);
114 fontBig
.SetWeight(wxFONTWEIGHT_BOLD
);
115 label
->SetFont(fontBig
);
117 m_sizerText
->Add(label
, wxSizerFlags().Centre().Border());
118 m_sizerText
->AddSpacer(5);
120 AddText(info
.GetCopyright());
121 AddText(info
.GetDescription());
123 if ( info
.HasWebSite() )
125 #if wxUSE_HYPERLINKCTRL
126 AddControl(new wxHyperlinkCtrl(this, wxID_ANY
,
127 info
.GetWebSiteDescription(),
128 info
.GetWebSiteURL()));
130 AddText(info
.GetWebSiteURL());
131 #endif // wxUSE_HYPERLINKCTRL/!wxUSE_HYPERLINKCTRL
136 // TODO: add credits (developers, artists, doc writers, translators)
138 DoAddCustomControls();
141 wxSizer
*sizerIconAndText
= new wxBoxSizer(wxHORIZONTAL
);
143 wxIcon icon
= info
.GetIcon();
146 sizerIconAndText
->Add(new wxStaticBitmap(this, wxID_ANY
, icon
),
147 wxSizerFlags().Border(wxRIGHT
));
149 #endif // wxUSE_STATBMP
150 sizerIconAndText
->Add(m_sizerText
, wxSizerFlags(1).Expand());
152 wxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
153 sizerTop
->Add(sizerIconAndText
, wxSizerFlags(1).Expand().Border());
155 int defBorder
= wxSizerFlags().Border().GetBorderInPixels();
156 wxSizer
*buttonSizer
= CreateButtonSizer( wxOK
, false, defBorder
);
157 if(buttonSizer
->GetChildren().GetCount() > 0 )
159 sizerTop
->Add( buttonSizer
, 0, wxEXPAND
| wxALL
, defBorder
);
163 sizerTop
->AddSpacer( defBorder
);
167 SetSizerAndFit(sizerTop
);
171 wxWindow
*ok
= FindWindow(wxID_OK
);
172 if (ok
) ok
->SetFocus();
177 void wxGenericAboutDialog::AddControl(wxWindow
*win
, const wxSizerFlags
& flags
)
179 wxCHECK_RET( m_sizerText
, _T("can only be called after Create()") );
180 wxASSERT_MSG( win
, _T("can't add NULL window to about dialog") );
182 m_sizerText
->Add(win
, flags
);
185 void wxGenericAboutDialog::AddControl(wxWindow
*win
)
187 AddControl(win
, wxSizerFlags().Border(wxDOWN
).Centre());
190 void wxGenericAboutDialog::AddText(const wxString
& text
)
193 AddControl(new wxStaticText(this, wxID_ANY
, text
));
196 // ----------------------------------------------------------------------------
198 // ----------------------------------------------------------------------------
200 void wxGenericAboutBox(const wxAboutDialogInfo
& info
)
202 wxGenericAboutDialog
dlg(info
);
206 // currently wxAboutBox is implemented natively only under these platforms, for
207 // the others we provide a generic fallback here
208 #if !defined(__WXMSW__) && !defined(__WXMAC__) && !defined(__WXGTK26__)
210 void wxAboutBox(const wxAboutDialogInfo
& info
)
212 wxGenericAboutBox(info
);
215 #endif // platforms without native about dialog
218 #endif // wxUSE_ABOUTDLG