From 453c9e3b0bad19ff91fb280183c34e5df7e24011 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 8 Oct 2006 14:12:59 +0000 Subject: [PATCH] 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 --- include/wx/generic/aboutdlgg.h | 32 ++++++++---- samples/dialogs/dialogs.cpp | 91 +++++++++++++++++++++++++++++++--- samples/dialogs/dialogs.h | 4 ++ src/generic/aboutdlgg.cpp | 19 ++++--- 4 files changed, 125 insertions(+), 21 deletions(-) diff --git a/include/wx/generic/aboutdlgg.h b/include/wx/generic/aboutdlgg.h index d5bf6f8b69..681cc987df 100644 --- a/include/wx/generic/aboutdlgg.h +++ b/include/wx/generic/aboutdlgg.h @@ -1,6 +1,6 @@ /////////////////////////////////////////////////////////////////////////////// // Name: wx/generic/aboutdlgg.h -// Purpose: generic wxAboutDialog implementation +// Purpose: generic wxAboutBox() implementation // Author: Vadim Zeitlin // Created: 2006-10-07 // RCS-ID: $Id$ @@ -19,22 +19,23 @@ class WXDLLIMPEXP_CORE wxAboutDialogInfo; 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: // constructors and Create() method // -------------------------------- // default ctor, you must use Create() to really initialize the dialog - wxAboutDialog() { Init(); } + wxGenericAboutDialog() { Init(); } // ctor which fully initializes the object - wxAboutDialog(const wxAboutDialogInfo& info) + wxGenericAboutDialog(const wxAboutDialogInfo& info) { Init(); @@ -45,15 +46,28 @@ public: bool Create(const wxAboutDialogInfo& info); protected: - // common part of all ctors - void Init() { m_sizerText = NULL; } - - // add arbitrary control to the text sizer contents + // this virtual method may be overridden to add some more controls to the + // 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 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); // add the text, if it's not empty, to the text sizer contents void AddText(const wxString& text); +private: + // common part of all ctors + void Init() { m_sizerText = NULL; } + wxSizer *m_sizerText; }; diff --git a/samples/dialogs/dialogs.cpp b/samples/dialogs/dialogs.cpp index c1d4d1fca6..70eb2b3488 100644 --- a/samples/dialogs/dialogs.cpp +++ b/samples/dialogs/dialogs.cpp @@ -51,6 +51,10 @@ #if wxUSE_ABOUTDLG #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 #if wxUSE_BUSYINFO @@ -186,6 +190,8 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) #if wxUSE_ABOUTDLG EVT_MENU(DIALOGS_ABOUTDLG_SIMPLE, MyFrame::ShowSimpleAboutDialog) EVT_MENU(DIALOGS_ABOUTDLG_FANCY, MyFrame::ShowFancyAboutDialog) + EVT_MENU(DIALOGS_ABOUTDLG_FULL, MyFrame::ShowFullAboutDialog) + EVT_MENU(DIALOGS_ABOUTDLG_CUSTOM, MyFrame::ShowCustomAboutDialog) #endif // wxUSE_ABOUTDLG #if wxUSE_BUSYINFO @@ -396,8 +402,10 @@ bool MyApp::OnInit() #if wxUSE_ABOUTDLG wxMenu *menuHelp = new wxMenu; - menuHelp->Append(DIALOGS_ABOUTDLG_SIMPLE, _T("&About (simple)...")); - menuHelp->Append(DIALOGS_ABOUTDLG_FANCY, _T("About (&fancy)...")); + menuHelp->Append(DIALOGS_ABOUTDLG_SIMPLE, _T("&About (simple)...\tF1")); + 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 wxMenuBar *menubar = new wxMenuBar; @@ -1174,7 +1182,7 @@ void MyFrame::ShowProgress( wxCommandEvent& WXUNUSED(event) ) #if wxUSE_ABOUTDLG -static void CommonAboutInfoInit(wxAboutDialogInfo& info) +static void InitAboutInfoMinimal(wxAboutDialogInfo& info) { info.SetName(_T("Dialogs Sample")); info.SetVersion(wxVERSION_NUM_DOT_STRING_T); @@ -1183,10 +1191,48 @@ static void CommonAboutInfoInit(wxAboutDialogInfo& info) 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)) { wxAboutDialogInfo info; - CommonAboutInfoInit(info); + InitAboutInfoMinimal(info); wxAboutBox(info); } @@ -1194,12 +1240,45 @@ void MyFrame::ShowSimpleAboutDialog(wxCommandEvent& WXUNUSED(event)) void MyFrame::ShowFancyAboutDialog(wxCommandEvent& WXUNUSED(event)) { wxAboutDialogInfo info; - CommonAboutInfoInit(info); - info.SetWebSite(_T("http://www.wxwidgets.org/"), _T("wxWidgets web site")); + InitAboutInfoWebsite(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 #if wxUSE_BUSYINFO diff --git a/samples/dialogs/dialogs.h b/samples/dialogs/dialogs.h index 23fa45fc0c..12a64d9a63 100644 --- a/samples/dialogs/dialogs.h +++ b/samples/dialogs/dialogs.h @@ -247,6 +247,8 @@ public: #if wxUSE_ABOUTDLG void ShowSimpleAboutDialog(wxCommandEvent& event); void ShowFancyAboutDialog(wxCommandEvent& event); + void ShowFullAboutDialog(wxCommandEvent& event); + void ShowCustomAboutDialog(wxCommandEvent& event); #endif // wxUSE_ABOUTDLG #if wxUSE_BUSYINFO @@ -337,6 +339,8 @@ enum DIALOGS_PROGRESS, DIALOGS_ABOUTDLG_SIMPLE, DIALOGS_ABOUTDLG_FANCY, + DIALOGS_ABOUTDLG_FULL, + DIALOGS_ABOUTDLG_CUSTOM, DIALOGS_BUSYINFO, DIALOGS_FIND, DIALOGS_REPLACE, diff --git a/src/generic/aboutdlgg.cpp b/src/generic/aboutdlgg.cpp index 25a324e74b..4543ada040 100644 --- a/src/generic/aboutdlgg.cpp +++ b/src/generic/aboutdlgg.cpp @@ -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? 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) + DoAddCustomControls(); + wxSizer *sizerIconAndText = new wxBoxSizer(wxHORIZONTAL); #if wxUSE_STATBMP @@ -156,15 +158,20 @@ bool wxAboutDialog::Create(const wxAboutDialogInfo& info) 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()") ); 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 wxGenericAboutDialog::AddControl(wxWindow *win) +{ + AddControl(win, wxSizerFlags().Border(wxDOWN).Centre()); } -void wxAboutDialog::AddText(const wxString& text) +void wxGenericAboutDialog::AddText(const wxString& text) { if ( !text.empty() ) AddControl(new wxStaticText(this, wxID_ANY, text)); @@ -176,7 +183,7 @@ void wxAboutDialog::AddText(const wxString& text) void wxGenericAboutBox(const wxAboutDialogInfo& info) { - wxAboutDialog dlg(info); + wxGenericAboutDialog dlg(info); dlg.ShowModal(); } -- 2.47.2