added example of customizing the generic about dialog and renamed wxAboutDialog to wxGenericAboutDialog
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41713 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
cd5dc5e628
commit
453c9e3b0b
@ -1,6 +1,6 @@
|
|||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// Name: wx/generic/aboutdlgg.h
|
// Name: wx/generic/aboutdlgg.h
|
||||||
// Purpose: generic wxAboutDialog implementation
|
// Purpose: generic wxAboutBox() implementation
|
||||||
// Author: Vadim Zeitlin
|
// Author: Vadim Zeitlin
|
||||||
// Created: 2006-10-07
|
// Created: 2006-10-07
|
||||||
// RCS-ID: $Id$
|
// RCS-ID: $Id$
|
||||||
@ -19,22 +19,23 @@
|
|||||||
|
|
||||||
class WXDLLIMPEXP_CORE wxAboutDialogInfo;
|
class WXDLLIMPEXP_CORE wxAboutDialogInfo;
|
||||||
class WXDLLIMPEXP_CORE wxSizer;
|
class WXDLLIMPEXP_CORE wxSizer;
|
||||||
|
class WXDLLIMPEXP_CORE wxSizerFlags;
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxAboutDialog: generic "About" dialog implementation
|
// wxGenericAboutDialog: generic "About" dialog implementation
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
class WXDLLIMPEXP_CORE wxAboutDialog : public wxDialog
|
class WXDLLIMPEXP_CORE wxGenericAboutDialog : public wxDialog
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// constructors and Create() method
|
// constructors and Create() method
|
||||||
// --------------------------------
|
// --------------------------------
|
||||||
|
|
||||||
// default ctor, you must use Create() to really initialize the dialog
|
// default ctor, you must use Create() to really initialize the dialog
|
||||||
wxAboutDialog() { Init(); }
|
wxGenericAboutDialog() { Init(); }
|
||||||
|
|
||||||
// ctor which fully initializes the object
|
// ctor which fully initializes the object
|
||||||
wxAboutDialog(const wxAboutDialogInfo& info)
|
wxGenericAboutDialog(const wxAboutDialogInfo& info)
|
||||||
{
|
{
|
||||||
Init();
|
Init();
|
||||||
|
|
||||||
@ -45,15 +46,28 @@ public:
|
|||||||
bool Create(const wxAboutDialogInfo& info);
|
bool Create(const wxAboutDialogInfo& info);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// common part of all ctors
|
// this virtual method may be overridden to add some more controls to the
|
||||||
void Init() { m_sizerText = NULL; }
|
// dialog
|
||||||
|
//
|
||||||
|
// notice that for this to work you must call Create() from the derived
|
||||||
|
// class ctor and not use the base class ctor directly as otherwise the
|
||||||
|
// virtual function of the derived class wouldn't be called
|
||||||
|
virtual void DoAddCustomControls() { }
|
||||||
|
|
||||||
// add arbitrary control to the text sizer contents
|
// add arbitrary control to the text sizer contents with the specified
|
||||||
|
// flags
|
||||||
|
void AddControl(wxWindow *win, const wxSizerFlags& flags);
|
||||||
|
|
||||||
|
// add arbitrary control to the text sizer contents and center it
|
||||||
void AddControl(wxWindow *win);
|
void AddControl(wxWindow *win);
|
||||||
|
|
||||||
// add the text, if it's not empty, to the text sizer contents
|
// add the text, if it's not empty, to the text sizer contents
|
||||||
void AddText(const wxString& text);
|
void AddText(const wxString& text);
|
||||||
|
|
||||||
|
private:
|
||||||
|
// common part of all ctors
|
||||||
|
void Init() { m_sizerText = NULL; }
|
||||||
|
|
||||||
|
|
||||||
wxSizer *m_sizerText;
|
wxSizer *m_sizerText;
|
||||||
};
|
};
|
||||||
|
@ -51,6 +51,10 @@
|
|||||||
|
|
||||||
#if wxUSE_ABOUTDLG
|
#if wxUSE_ABOUTDLG
|
||||||
#include "wx/aboutdlg.h"
|
#include "wx/aboutdlg.h"
|
||||||
|
|
||||||
|
// these headers are only needed for custom about dialog
|
||||||
|
#include "wx/statline.h"
|
||||||
|
#include "wx/generic/aboutdlgg.h"
|
||||||
#endif // wxUSE_ABOUTDLG
|
#endif // wxUSE_ABOUTDLG
|
||||||
|
|
||||||
#if wxUSE_BUSYINFO
|
#if wxUSE_BUSYINFO
|
||||||
@ -186,6 +190,8 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
|||||||
#if wxUSE_ABOUTDLG
|
#if wxUSE_ABOUTDLG
|
||||||
EVT_MENU(DIALOGS_ABOUTDLG_SIMPLE, MyFrame::ShowSimpleAboutDialog)
|
EVT_MENU(DIALOGS_ABOUTDLG_SIMPLE, MyFrame::ShowSimpleAboutDialog)
|
||||||
EVT_MENU(DIALOGS_ABOUTDLG_FANCY, MyFrame::ShowFancyAboutDialog)
|
EVT_MENU(DIALOGS_ABOUTDLG_FANCY, MyFrame::ShowFancyAboutDialog)
|
||||||
|
EVT_MENU(DIALOGS_ABOUTDLG_FULL, MyFrame::ShowFullAboutDialog)
|
||||||
|
EVT_MENU(DIALOGS_ABOUTDLG_CUSTOM, MyFrame::ShowCustomAboutDialog)
|
||||||
#endif // wxUSE_ABOUTDLG
|
#endif // wxUSE_ABOUTDLG
|
||||||
|
|
||||||
#if wxUSE_BUSYINFO
|
#if wxUSE_BUSYINFO
|
||||||
@ -396,8 +402,10 @@ bool MyApp::OnInit()
|
|||||||
|
|
||||||
#if wxUSE_ABOUTDLG
|
#if wxUSE_ABOUTDLG
|
||||||
wxMenu *menuHelp = new wxMenu;
|
wxMenu *menuHelp = new wxMenu;
|
||||||
menuHelp->Append(DIALOGS_ABOUTDLG_SIMPLE, _T("&About (simple)..."));
|
menuHelp->Append(DIALOGS_ABOUTDLG_SIMPLE, _T("&About (simple)...\tF1"));
|
||||||
menuHelp->Append(DIALOGS_ABOUTDLG_FANCY, _T("About (&fancy)..."));
|
menuHelp->Append(DIALOGS_ABOUTDLG_FANCY, _T("About (&fancy)...\tShift-F1"));
|
||||||
|
menuHelp->Append(DIALOGS_ABOUTDLG_FULL, _T("About (f&ull)...\tCtrl-F1"));
|
||||||
|
menuHelp->Append(DIALOGS_ABOUTDLG_CUSTOM, _T("About (&custom)...\tCtrl-Shift-F1"));
|
||||||
#endif // wxUSE_ABOUTDLG
|
#endif // wxUSE_ABOUTDLG
|
||||||
|
|
||||||
wxMenuBar *menubar = new wxMenuBar;
|
wxMenuBar *menubar = new wxMenuBar;
|
||||||
@ -1174,7 +1182,7 @@ void MyFrame::ShowProgress( wxCommandEvent& WXUNUSED(event) )
|
|||||||
|
|
||||||
#if wxUSE_ABOUTDLG
|
#if wxUSE_ABOUTDLG
|
||||||
|
|
||||||
static void CommonAboutInfoInit(wxAboutDialogInfo& info)
|
static void InitAboutInfoMinimal(wxAboutDialogInfo& info)
|
||||||
{
|
{
|
||||||
info.SetName(_T("Dialogs Sample"));
|
info.SetName(_T("Dialogs Sample"));
|
||||||
info.SetVersion(wxVERSION_NUM_DOT_STRING_T);
|
info.SetVersion(wxVERSION_NUM_DOT_STRING_T);
|
||||||
@ -1183,10 +1191,48 @@ static void CommonAboutInfoInit(wxAboutDialogInfo& info)
|
|||||||
info.AddDeveloper(_T("Vadim Zeitlin"));
|
info.AddDeveloper(_T("Vadim Zeitlin"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void InitAboutInfoWebsite(wxAboutDialogInfo& info)
|
||||||
|
{
|
||||||
|
InitAboutInfoMinimal(info);
|
||||||
|
|
||||||
|
info.SetWebSite(_T("http://www.wxwidgets.org/"), _T("wxWidgets web site"));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void InitAboutInfoAll(wxAboutDialogInfo& info)
|
||||||
|
{
|
||||||
|
InitAboutInfoMinimal(info);
|
||||||
|
|
||||||
|
// we can add a second developer
|
||||||
|
info.AddDeveloper(_T("A.N. Other"));
|
||||||
|
|
||||||
|
// or we can add several persons at once like this
|
||||||
|
static const wxChar *docwriters[] =
|
||||||
|
{
|
||||||
|
_T("First D. Writer"),
|
||||||
|
_T("Second One"),
|
||||||
|
};
|
||||||
|
|
||||||
|
info.SetDocWriters(wxArrayString(WXSIZEOF(docwriters), docwriters));
|
||||||
|
info.SetLicence(wxString::FromAscii(
|
||||||
|
" wxWindows Library Licence, Version 3.1\n"
|
||||||
|
" ======================================\n"
|
||||||
|
"\n"
|
||||||
|
" Copyright (c) 1998-2005 Julian Smart, Robert Roebling et al\n"
|
||||||
|
"\n"
|
||||||
|
" Everyone is permitted to copy and distribute verbatim copies\n"
|
||||||
|
" of this licence document, but changing it is not allowed.\n"
|
||||||
|
"\n"
|
||||||
|
" WXWINDOWS LIBRARY LICENCE\n"
|
||||||
|
" TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n"
|
||||||
|
"\n"
|
||||||
|
" ...and so on and so forth...\n"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
void MyFrame::ShowSimpleAboutDialog(wxCommandEvent& WXUNUSED(event))
|
void MyFrame::ShowSimpleAboutDialog(wxCommandEvent& WXUNUSED(event))
|
||||||
{
|
{
|
||||||
wxAboutDialogInfo info;
|
wxAboutDialogInfo info;
|
||||||
CommonAboutInfoInit(info);
|
InitAboutInfoMinimal(info);
|
||||||
|
|
||||||
wxAboutBox(info);
|
wxAboutBox(info);
|
||||||
}
|
}
|
||||||
@ -1194,12 +1240,45 @@ void MyFrame::ShowSimpleAboutDialog(wxCommandEvent& WXUNUSED(event))
|
|||||||
void MyFrame::ShowFancyAboutDialog(wxCommandEvent& WXUNUSED(event))
|
void MyFrame::ShowFancyAboutDialog(wxCommandEvent& WXUNUSED(event))
|
||||||
{
|
{
|
||||||
wxAboutDialogInfo info;
|
wxAboutDialogInfo info;
|
||||||
CommonAboutInfoInit(info);
|
InitAboutInfoWebsite(info);
|
||||||
info.SetWebSite(_T("http://www.wxwidgets.org/"), _T("wxWidgets web site"));
|
|
||||||
|
|
||||||
wxAboutBox(info);
|
wxAboutBox(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MyFrame::ShowFullAboutDialog(wxCommandEvent& WXUNUSED(event))
|
||||||
|
{
|
||||||
|
wxAboutDialogInfo info;
|
||||||
|
InitAboutInfoAll(info);
|
||||||
|
|
||||||
|
wxAboutBox(info);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyFrame::ShowCustomAboutDialog(wxCommandEvent& WXUNUSED(event))
|
||||||
|
{
|
||||||
|
class MyAboutDialog : public wxGenericAboutDialog
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MyAboutDialog(const wxAboutDialogInfo& info)
|
||||||
|
{
|
||||||
|
Create(info);
|
||||||
|
}
|
||||||
|
|
||||||
|
// add some custom controls
|
||||||
|
virtual void DoAddCustomControls()
|
||||||
|
{
|
||||||
|
AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
|
||||||
|
AddText(_T("Some custom text"));
|
||||||
|
AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
wxAboutDialogInfo info;
|
||||||
|
InitAboutInfoAll(info);
|
||||||
|
|
||||||
|
MyAboutDialog dlg(info);
|
||||||
|
dlg.ShowModal();
|
||||||
|
}
|
||||||
|
|
||||||
#endif // wxUSE_ABOUTDLG
|
#endif // wxUSE_ABOUTDLG
|
||||||
|
|
||||||
#if wxUSE_BUSYINFO
|
#if wxUSE_BUSYINFO
|
||||||
|
@ -247,6 +247,8 @@ public:
|
|||||||
#if wxUSE_ABOUTDLG
|
#if wxUSE_ABOUTDLG
|
||||||
void ShowSimpleAboutDialog(wxCommandEvent& event);
|
void ShowSimpleAboutDialog(wxCommandEvent& event);
|
||||||
void ShowFancyAboutDialog(wxCommandEvent& event);
|
void ShowFancyAboutDialog(wxCommandEvent& event);
|
||||||
|
void ShowFullAboutDialog(wxCommandEvent& event);
|
||||||
|
void ShowCustomAboutDialog(wxCommandEvent& event);
|
||||||
#endif // wxUSE_ABOUTDLG
|
#endif // wxUSE_ABOUTDLG
|
||||||
|
|
||||||
#if wxUSE_BUSYINFO
|
#if wxUSE_BUSYINFO
|
||||||
@ -337,6 +339,8 @@ enum
|
|||||||
DIALOGS_PROGRESS,
|
DIALOGS_PROGRESS,
|
||||||
DIALOGS_ABOUTDLG_SIMPLE,
|
DIALOGS_ABOUTDLG_SIMPLE,
|
||||||
DIALOGS_ABOUTDLG_FANCY,
|
DIALOGS_ABOUTDLG_FANCY,
|
||||||
|
DIALOGS_ABOUTDLG_FULL,
|
||||||
|
DIALOGS_ABOUTDLG_CUSTOM,
|
||||||
DIALOGS_BUSYINFO,
|
DIALOGS_BUSYINFO,
|
||||||
DIALOGS_FIND,
|
DIALOGS_FIND,
|
||||||
DIALOGS_REPLACE,
|
DIALOGS_REPLACE,
|
||||||
|
@ -95,10 +95,10 @@ wxIcon wxAboutDialogInfo::GetIcon() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxAboutDialog
|
// wxGenericAboutDialog
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool wxAboutDialog::Create(const wxAboutDialogInfo& info)
|
bool wxGenericAboutDialog::Create(const wxAboutDialogInfo& info)
|
||||||
{
|
{
|
||||||
// TODO: should we use main frame as parent by default here?
|
// TODO: should we use main frame as parent by default here?
|
||||||
if ( !wxDialog::Create(NULL, wxID_ANY, _("About ") + info.GetName()) )
|
if ( !wxDialog::Create(NULL, wxID_ANY, _("About ") + info.GetName()) )
|
||||||
@ -135,6 +135,8 @@ bool wxAboutDialog::Create(const wxAboutDialogInfo& info)
|
|||||||
|
|
||||||
// TODO: add credits (developers, artists, doc writers, translators)
|
// TODO: add credits (developers, artists, doc writers, translators)
|
||||||
|
|
||||||
|
DoAddCustomControls();
|
||||||
|
|
||||||
|
|
||||||
wxSizer *sizerIconAndText = new wxBoxSizer(wxHORIZONTAL);
|
wxSizer *sizerIconAndText = new wxBoxSizer(wxHORIZONTAL);
|
||||||
#if wxUSE_STATBMP
|
#if wxUSE_STATBMP
|
||||||
@ -156,15 +158,20 @@ bool wxAboutDialog::Create(const wxAboutDialogInfo& info)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxAboutDialog::AddControl(wxWindow *win)
|
void wxGenericAboutDialog::AddControl(wxWindow *win, const wxSizerFlags& flags)
|
||||||
{
|
{
|
||||||
wxCHECK_RET( m_sizerText, _T("can only be called after Create()") );
|
wxCHECK_RET( m_sizerText, _T("can only be called after Create()") );
|
||||||
wxASSERT_MSG( win, _T("can't add NULL window to about dialog") );
|
wxASSERT_MSG( win, _T("can't add NULL window to about dialog") );
|
||||||
|
|
||||||
m_sizerText->Add(win, wxSizerFlags().Border(wxDOWN).Centre());
|
m_sizerText->Add(win, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxAboutDialog::AddText(const wxString& text)
|
void wxGenericAboutDialog::AddControl(wxWindow *win)
|
||||||
|
{
|
||||||
|
AddControl(win, wxSizerFlags().Border(wxDOWN).Centre());
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxGenericAboutDialog::AddText(const wxString& text)
|
||||||
{
|
{
|
||||||
if ( !text.empty() )
|
if ( !text.empty() )
|
||||||
AddControl(new wxStaticText(this, wxID_ANY, text));
|
AddControl(new wxStaticText(this, wxID_ANY, text));
|
||||||
@ -176,7 +183,7 @@ void wxAboutDialog::AddText(const wxString& text)
|
|||||||
|
|
||||||
void wxGenericAboutBox(const wxAboutDialogInfo& info)
|
void wxGenericAboutBox(const wxAboutDialogInfo& info)
|
||||||
{
|
{
|
||||||
wxAboutDialog dlg(info);
|
wxGenericAboutDialog dlg(info);
|
||||||
dlg.ShowModal();
|
dlg.ShowModal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user