initial implementation of wxAboutBox()

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41683 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2006-10-08 01:02:04 +00:00
parent 9211cf3c43
commit ca7adbf8bc
6 changed files with 509 additions and 16 deletions

135
src/generic/aboutdlgg.cpp Normal file
View File

@@ -0,0 +1,135 @@
///////////////////////////////////////////////////////////////////////////////
// Name: src/generic/aboutdlgg.cpp
// Purpose: implements wxGenericAboutBox() function
// Author: Vadim Zeitlin
// Created: 2006-10-08
// RCS-ID: $Id$
// Copyright: (c) 2006 Vadim Zeitlin <vadim@wxwindows.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
// for compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#if wxUSE_ABOUTDLG
#ifndef WX_PRECOMP
#include "wx/sizer.h"
#include "wx/statbmp.h"
#include "wx/stattext.h"
#endif //WX_PRECOMP
#include "wx/aboutdlg.h"
#include "wx/generic/aboutdlgg.h"
#include "wx/hyperlink.h"
// ============================================================================
// wxAboutDialog implementation
// ============================================================================
bool wxAboutDialog::Create(const wxAboutDialogInfo& info)
{
// TODO: should we use main frame as parent by default here?
if ( !wxDialog::Create(NULL, wxID_ANY, _("About ") + info.GetName()) )
return false;
m_sizerText = new wxBoxSizer(wxVERTICAL);
wxString nameAndVersion = info.GetName();
if ( info.HasVersion() )
nameAndVersion << _T(' ') << info.GetVersion();
wxStaticText *label = new wxStaticText(this, wxID_ANY, nameAndVersion);
wxFont fontBig(*wxNORMAL_FONT);
fontBig.SetPointSize(fontBig.GetPointSize() + 2);
fontBig.SetWeight(wxFONTWEIGHT_BOLD);
label->SetFont(fontBig);
m_sizerText->Add(label, wxSizerFlags().Centre().Border());
m_sizerText->AddSpacer(5);
AddText(info.GetCopyright());
AddText(info.GetDescription());
if ( info.HasWebSite() )
{
#if wxUSE_HYPERLINKCTRL
AddControl(new wxHyperlinkCtrl(this, wxID_ANY,
info.GetWebSiteDescription(),
info.GetWebSiteURL()));
#else
AddText(info.GetWebSiteURL());
#endif // wxUSE_HYPERLINKCTRL/!wxUSE_HYPERLINKCTRL
}
// TODO: add licence
// TODO: add credits (developers, artists, doc writers, translators)
wxSizer *sizerIconAndText = new wxBoxSizer(wxHORIZONTAL);
#if wxUSE_STATBMP
if ( info.HasIcon() )
sizerIconAndText->Add(new wxStaticBitmap(this, wxID_ANY, info.GetIcon()));
#endif // wxUSE_STATBMP
sizerIconAndText->Add(m_sizerText, wxSizerFlags(1).Expand());
wxSizer *sizerTop = new wxBoxSizer(wxVERTICAL);
sizerTop->Add(sizerIconAndText, wxSizerFlags(1).Expand().Border());
sizerTop->Add(new wxButton(this, wxID_OK), wxSizerFlags().Right().Border());
SetSizerAndFit(sizerTop);
CentreOnScreen();
return true;
}
void wxAboutDialog::AddControl(wxWindow *win)
{
wxCHECK_RET( m_sizerText, _T("can only be called after Create()") );
wxASSERT_MSG( win, _T("can't add NULL window to about dialog") );
m_sizerText->Add(win, wxSizerFlags().Border(wxDOWN).Centre());
}
void wxAboutDialog::AddText(const wxString& text)
{
if ( !text.empty() )
AddControl(new wxStaticText(this, wxID_ANY, text));
}
// ----------------------------------------------------------------------------
// public functions
// ----------------------------------------------------------------------------
void wxGenericAboutBox(const wxAboutDialogInfo& info)
{
wxAboutDialog dlg(info);
dlg.ShowModal();
}
// currently wxAboutBox is implemented natively only under wxMSW, so we provide
// it here for the other platforms (this is going to change when GTK+ and Mac
// native versions are implemented)
#ifndef __WXMSW__
void wxAboutBox(const wxAboutDialogInfo& info)
{
wxGenericAboutBox(info);
}
#endif // platforms without native about dialog
#endif // wxUSE_ABOUTDLG

94
src/msw/aboutdlg.cpp Normal file
View File

@@ -0,0 +1,94 @@
///////////////////////////////////////////////////////////////////////////////
// Name: src/msw/aboutdlg.cpp
// Purpose: implementation of wxAboutBox() for wxMSW
// Author: Vadim Zeitlin
// Created: 2006-10-07
// RCS-ID: $Id$
// Copyright: (c) 2006 Vadim Zeitlin <vadim@wxwindows.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
// for compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#if wxUSE_ABOUTDLG
#ifndef WX_PRECOMP
#endif //WX_PRECOMP
#include "wx/aboutdlg.h"
#include "wx/generic/aboutdlgg.h"
// ============================================================================
// implementation
// ============================================================================
// helper function: returns all array elements in a single comma-separated and
// newline-terminated string
static wxString AllAsString(const wxArrayString& a)
{
wxString s;
const size_t count = a.size();
for ( size_t n = 0; n < count; n++ )
{
s << a[n] << (n == count - 1 ? _T("\n") : _T(", "));
}
return s;
}
// our public entry point
void wxAboutBox(const wxAboutDialogInfo& info)
{
// we prefer to show a simple message box if we don't have any fields which
// can't be shown in it because as much as there is a standard about box
// under MSW at all, this is it
if ( info.HasWebSite() || info.HasIcon() || info.HasLicence() )
{
// we need to use the full-blown generic version
wxGenericAboutBox(info);
}
else // simple "native" version should do
{
// build the text to show in the box
const wxString name = info.GetName();
wxString msg;
msg << name;
if ( info.HasVersion() )
msg << _(" Version ") << info.GetVersion();
msg << _T('\n');
if ( info.HasCopyright() )
msg << info.GetCopyright() << _T('\n');
msg << info.GetDescription() << _T('\n');
if ( info.HasDevelopers() )
msg << _("Developed by ") << AllAsString(info.GetDevelopers());
if ( info.HasDocWriters() )
msg << _("Documentation by ") << AllAsString(info.GetDocWriters());
if ( info.HasArtists() )
msg << _("Graphics art by ") << AllAsString(info.GetArtists());
if ( info.HasTranslators() )
msg << _("Translations by ") << AllAsString(info.GetTranslators());
wxMessageBox(msg, _T("About ") + name);
}
}
#endif // wxUSE_ABOUTDLG