]> git.saurik.com Git - wxWidgets.git/commitdiff
added example of customizing the generic about dialog and renamed wxAboutDialog to...
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 8 Oct 2006 14:12:59 +0000 (14:12 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 8 Oct 2006 14:12:59 +0000 (14:12 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41713 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/generic/aboutdlgg.h
samples/dialogs/dialogs.cpp
samples/dialogs/dialogs.h
src/generic/aboutdlgg.cpp

index d5bf6f8b69e598fdda4fe1ed73336675acc295b9..681cc987df62a1862bc191fd68da6b9f8901ae18 100644 (file)
@@ -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$
 
 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;
 };
index c1d4d1fca66807a7447f753cb4f48c961b9e1ed9..70eb2b34886ebdbdee71291ffe8229992422b609 100644 (file)
 
 #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
index 23fa45fc0cf81b9f0b3f01a5309ea0683d5a545c..12a64d9a63fdc5d939858435c43e21490ab1ccac 100644 (file)
@@ -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,
index 25a324e74ba952d5bce0260bf76f1f05e970779e..4543ada040583e50825e789f90144218913c0609 100644 (file)
@@ -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();
 }