]> git.saurik.com Git - wxWidgets.git/commitdiff
Added wxSimplebook class: a wxBookCtrl without controller.
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 30 Aug 2012 20:21:54 +0000 (20:21 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 30 Aug 2012 20:21:54 +0000 (20:21 +0000)
This new control allows the program to show one of the several pages without
allowing the user to change them (or even see that there are several of them)
himself.

This class is fully inline, so it doesn't add anything to the library and
hence doesn't need neither wxUSE_SIMPLEBOOK nor the corresponding configure
option.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72407 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

13 files changed:
Makefile.in
build/bakefiles/files.bkl
build/msw/wx_core.dsp
build/msw/wx_vc7_core.vcproj
build/msw/wx_vc8_core.vcproj
build/msw/wx_vc9_core.vcproj
docs/changes.txt
docs/doxygen/mainpages/cat_classes.h
docs/doxygen/overviews/bookctrl.h
include/wx/simplebook.h [new file with mode: 0644]
interface/wx/simplebook.h [new file with mode: 0644]
samples/notebook/notebook.cpp
samples/notebook/notebook.h

index 2186b07fb2a67e44d5509ee3f86ed157befb2121..c42923b8228b5a90933648bc89cb9b2502625b5b 100644 (file)
@@ -4214,6 +4214,7 @@ COND_USE_GUI_1_ALL_GUI_HEADERS =  \
        wx/rawbmp.h \
        wx/region.h \
        wx/scopeguard.h \
+       wx/simplebook.h \
        wx/spinbutt.h \
        wx/spinctrl.h \
        wx/splitter.h \
index 2743fc28ad3913a3d7568c12330268fefe37b387..68b17dfa2f36680b12697b562977b9f04e4fbf63 100644 (file)
@@ -988,6 +988,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
     wx/rawbmp.h
     wx/region.h
     wx/scopeguard.h
+    wx/simplebook.h
     wx/spinbutt.h
     wx/spinctrl.h
     wx/splitter.h
index fcb212d7ddfbac858e1f886af443086ed149052e..0081ea80843df77d6b23be81b313a3572735fa30 100644 (file)
@@ -6867,6 +6867,10 @@ SOURCE=..\..\include\wx\settings.h
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=..\..\include\wx\simplebook.h
+# End Source File
+# Begin Source File
+
 SOURCE=..\..\include\wx\sizer.h\r
 # End Source File\r
 # Begin Source File\r
index 8a487e1b3ffe384f2bae1391d4350ebc77a703e2..3830b5e547185195b9d0d0c8cef06d8e00ede5cf 100644 (file)
                        <File\r
                                RelativePath="..\..\include\wx\settings.h">\r
                        </File>\r
+                       <File\r
+                               RelativePath="..\..\include\wx\simplebook.h">\r
+                       </File>\r
                        <File\r
                                RelativePath="..\..\include\wx\sizer.h">\r
                        </File>\r
index effbc7b4e0afd457a8715fc1761ebf4eabf210c6..065ed13c3e44a5549aed121a24c3e21b1c2db248 100644 (file)
                                RelativePath="..\..\include\wx\settings.h"\r
                                >\r
                        </File>\r
+                       <File\r
+                               RelativePath="..\..\include\wx\simplebook.h"\r
+                               >\r
+                       </File>\r
                        <File\r
                                RelativePath="..\..\include\wx\sizer.h"\r
                                >\r
index fcd0fbf4ae57337b05fdbc25333ba5d726e3a928..26126cba07ddddeb456c62cc1096bb5133511302 100644 (file)
                                RelativePath="..\..\include\wx\settings.h"\r
                                >\r
                        </File>\r
+                       <File\r
+                               RelativePath="..\..\include\wx\simplebook.h"\r
+                               >\r
+                       </File>\r
                        <File\r
                                RelativePath="..\..\include\wx\sizer.h"\r
                                >\r
index 119b685d34b7721145dacb37e33b6795dc86fbc5..3d6053886ddd1ccff9b7af4524fcd9cc5ae892d0 100644 (file)
@@ -535,8 +535,9 @@ All:
 
 All (GUI):
 
-- Add support for searching in wxWebView for MSW and GTK (Allonii).
+- Add new wxSimplebook class.
 - Respect window max size in wxBoxSizer (Nathan Ridge).
+- Add support for searching in wxWebView for MSW and GTK (Allonii).
 - Add possibility to hide and show again wxRibbonBar pages (wxBen).
 - Add wxRibbonBar pages highlighting (wxBen).
 - Add expand/collapse button to wxRibbonBar (rakeshthp).
index fd4c127f376182774c2f4ccd0bca6a9f6774cc67..539ea9b10ffea1470fb4b5d666dd354d2ff41a55 100644 (file)
@@ -254,6 +254,8 @@ The following are a variety of classes that are derived from wxWindow.
 @li wxSashWindow: Window with four optional sashes that can be dragged
 @li wxSashLayoutWindow: Window that can be involved in an IDE-like layout
     arrangement
+@li wxSimplebook: Another book control but one allowing only the program, not
+    the user, to change its current page.
 @li wxWizardPage: A base class for the page in wizard dialog.
 @li wxWizardPageSimple: A page in wizard dialog.
 @li wxCustomBackgroundWindow: A window allowing to set a custom bitmap.
index f71f17275793f9ce7649a6e88b61a77457bc4467..9b4677e4ee509469ed2ae39762f46852280d52fb 100644 (file)
@@ -15,6 +15,7 @@ Classes:
 @li wxChoicebook
 @li wxListbook
 @li wxNotebook
+@li wxSimplebook
 @li wxTreebook
 @li wxToolbook
 
@@ -35,11 +36,15 @@ displayed one page at a time. wxWidgets has five variants of this control:
 @li wxChoicebook: controlled by a wxChoice
 @li wxListbook: controlled by a wxListCtrl
 @li wxNotebook: uses a row of tabs
+@li wxSimplebook: doesn't allow the user to change the page at all.
 @li wxTreebook: controlled by a wxTreeCtrl
 @li wxToolbook: controlled by a wxToolBar
 
 See the @ref page_samples_notebook for an example of wxBookCtrl usage.
 
+Notice that wxSimplebook is special in that it only allows the program to
+change the selection, thus it's usually used in slightly different
+circumstances than the other variants.
 
 @section overview_bookctrl_bestbookctrl Best Book
 
diff --git a/include/wx/simplebook.h b/include/wx/simplebook.h
new file mode 100644 (file)
index 0000000..e99f44d
--- /dev/null
@@ -0,0 +1,206 @@
+///////////////////////////////////////////////////////////////////////////////
+// Name:        wx/simplebook.h
+// Purpose:     wxBookCtrlBase-derived class without any controller.
+// Author:      Vadim Zeitlin
+// Created:     2012-08-21
+// RCS-ID:      $Id$
+// Copyright:   (c) 2012 Vadim Zeitlin <vadim@wxwidgets.org>
+// Licence:     wxWindows licence
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef _WX_SIMPLEBOOK_H_
+#define _WX_SIMPLEBOOK_H_
+
+#include "wx/bookctrl.h"
+
+#if wxUSE_BOOKCTRL
+
+#include "wx/vector.h"
+
+// ----------------------------------------------------------------------------
+// wxSimplebook: a book control without any user-actionable controller.
+// ----------------------------------------------------------------------------
+
+// NB: This class doesn't use DLL export declaration as it's fully inline.
+
+class wxSimplebook : public wxBookCtrlBase
+{
+public:
+    wxSimplebook()
+    {
+        Init();
+    }
+
+    wxSimplebook(wxWindow *parent,
+                 wxWindowID winid = wxID_ANY,
+                 const wxPoint& pos = wxDefaultPosition,
+                 const wxSize& size = wxDefaultSize,
+                 long style = 0,
+                 const wxString& name = wxEmptyString)
+        : wxBookCtrlBase(parent, winid, pos, size, style | wxBK_TOP, name)
+    {
+        Init();
+    }
+
+
+    // Methods specific to this class.
+
+    // A method allowing to add a new page without any label (which is unused
+    // by this control) and show it immediately.
+    bool ShowNewPage(wxWindow* page)
+    {
+        return AddPage(page, wxString(), true /* select it */);
+    }
+
+
+    // Set effect to use for showing/hiding pages.
+    void SetEffects(wxShowEffect showEffect, wxShowEffect hideEffect)
+    {
+        m_showEffect = showEffect;
+        m_hideEffect = hideEffect;
+    }
+
+    // Or the same effect for both of them.
+    void SetEffect(wxShowEffect effect)
+    {
+        SetEffects(effect, effect);
+    }
+
+    // And the same for time outs.
+    void SetEffectsTimeouts(unsigned showTimeout, unsigned hideTimeout)
+    {
+        m_showTimeout = showTimeout;
+        m_hideTimeout = hideTimeout;
+    }
+
+    void SetEffectTimeout(unsigned timeout)
+    {
+        SetEffectsTimeouts(timeout, timeout);
+    }
+
+
+    // Implement base class pure virtual methods.
+
+    // Page management
+    virtual bool InsertPage(size_t n,
+                            wxWindow *page,
+                            const wxString& text,
+                            bool bSelect = false,
+                            int imageId = NO_IMAGE)
+    {
+        if ( !wxBookCtrlBase::InsertPage(n, page, text, bSelect, imageId) )
+            return false;
+
+        m_pageTexts.insert(m_pageTexts.begin() + n, text);
+
+        if ( !DoSetSelectionAfterInsertion(n, bSelect) )
+            page->Hide();
+
+        return true;
+    }
+
+    virtual int SetSelection(size_t n)
+    {
+        return DoSetSelection(n, SetSelection_SendEvent);
+    }
+
+    virtual int ChangeSelection(size_t n)
+    {
+        return DoSetSelection(n);
+    }
+
+    // Neither labels nor images are supported but we still store the labels
+    // just in case the user code attaches some importance to them.
+    virtual bool SetPageText(size_t n, const wxString& strText)
+    {
+        wxCHECK_MSG( n < GetPageCount(), false, wxS("Invalid page") );
+
+        m_pageTexts[n] = strText;
+
+        return true;
+    }
+
+    virtual wxString GetPageText(size_t n) const
+    {
+        wxCHECK_MSG( n < GetPageCount(), wxString(), wxS("Invalid page") );
+
+        return m_pageTexts[n];
+    }
+
+    virtual bool SetPageImage(size_t WXUNUSED(n), int WXUNUSED(imageId))
+    {
+        return false;
+    }
+
+    virtual int GetPageImage(size_t WXUNUSED(n)) const
+    {
+        return NO_IMAGE;
+    }
+
+protected:
+    virtual void UpdateSelectedPage(size_t newsel)
+    {
+        m_selection = newsel;
+    }
+
+    virtual wxBookCtrlEvent* CreatePageChangingEvent() const
+    {
+        return new wxBookCtrlEvent(wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGING,
+                                   GetId());
+    }
+
+    virtual void MakeChangedEvent(wxBookCtrlEvent& event)
+    {
+        event.SetEventType(wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGED);
+    }
+
+    virtual wxWindow *DoRemovePage(size_t page)
+    {
+        m_pageTexts.erase(m_pageTexts.begin() + page);
+        return wxBookCtrlBase::DoRemovePage(page);
+    }
+
+    virtual void DoSize()
+    {
+        wxWindow* const page = GetCurrentPage();
+        if ( page )
+            page->SetSize(GetPageRect());
+    }
+
+    virtual void DoShowPage(wxWindow* page, bool show)
+    {
+        if ( show )
+            page->ShowWithEffect(m_showEffect, m_showTimeout);
+        else
+            page->HideWithEffect(m_hideEffect, m_hideTimeout);
+    }
+
+private:
+    void Init()
+    {
+        // We don't need any border as we don't have anything to separate the
+        // page contents from.
+        SetInternalBorder(0);
+
+        // No effects by default.
+        m_showEffect =
+        m_hideEffect = wxSHOW_EFFECT_NONE;
+
+        m_showTimeout =
+        m_hideTimeout = 0;
+    }
+
+    wxVector<wxString> m_pageTexts;
+
+    wxShowEffect m_showEffect,
+                 m_hideEffect;
+
+    unsigned m_showTimeout,
+             m_hideTimeout;
+
+    wxDECLARE_NO_COPY_CLASS(wxSimplebook);
+};
+
+#endif // wxUSE_BOOKCTRL
+
+#endif // _WX_SIMPLEBOOK_H_
diff --git a/interface/wx/simplebook.h b/interface/wx/simplebook.h
new file mode 100644 (file)
index 0000000..2fe9c5f
--- /dev/null
@@ -0,0 +1,129 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name:        wx/simplebook.h
+// Purpose:     wxSimplebook public API documentation.
+// Author:      wxWidgets team
+// RCS-ID:      $Id$
+// Licence:     wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+/**
+    @class wxSimplebook
+
+    wxSimplebook is a control showing exactly one of its several pages.
+
+    It implements wxBookCtrlBase class interface but doesn't allow the user to
+    change the page being displayed, unlike all the other book control classes,
+    only the program can do it.
+
+    This class is created in the same manner as any other wxBookCtrl but then
+    the program will typically call ChangeSelection() to show different pages.
+    See the @ref page_samples_notebook for an example of wxSimplebook in
+    action.
+
+    Notice that is often convenient to use ShowNewPage() instead of the base
+    class AddPage().
+
+    There are no special styles defined for this class as it has no visual
+    appearance of its own.
+
+    There are also no special events, this class reuses
+    @c wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGING and @c
+    wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGED events for the events it generates if
+    the program calls SetSelection().
+
+    @library{none}
+    @category{bookctrl}
+
+    @see wxBookCtrl, wxNotebook, @ref page_samples_notebook
+
+    @since 2.9.5
+*/
+class wxSimplebook : public wxBookCtrlBase
+{
+public:
+    /**
+        Default constructor.
+
+        Use Create() (inherited from the base class) later to really create the
+        control.
+    */
+    wxSimplebook();
+
+    /**
+        Constructs a simple book control.
+    */
+    wxSimplebook(wxWindow* parent,
+                 wxWindowID id = wxID_ANY,
+                 const wxPoint& pos = wxDefaultPosition,
+                 const wxSize& size = wxDefaultSize,
+                 long style = 0,
+                 const wxString& name = wxEmptyString);
+
+
+    /**
+        Set the effects to use for showing and hiding the pages.
+
+        This method allows to specify the effects passed to
+        wxWindow::ShowWithEffect() and wxWindow::HideWithEffect() respectively
+        when the pages need to be shown or hidden.
+
+        By default, no effects are used, but as the pages are only changed
+        by the program and not the user himself, it may be useful to use some
+        visual effects to make the changes more noticeable.
+
+        @param showEffect
+            The effect to use for showing the newly selected page.
+        @param hideEffect
+            The effect to use for hiding the previously selected page.
+
+        @see SetEffectsTimeouts()
+     */
+    void SetEffects(wxShowEffect showEffect, wxShowEffect hideEffect);
+
+    /**
+        Set the same effect to use for both showing and hiding the pages.
+
+        This is the same as <code>SetEffects(effect, effect)</code>.
+
+        @see SetEffectTimeout()
+     */
+    void SetEffect(wxShowEffect effect);
+
+    /**
+        Set the effect timeout to use for showing and hiding the pages.
+
+        This method allows to configure the timeout arguments passed to
+        wxWindow::ShowWithEffect() and wxWindow::HideWithEffect() if a
+        non-default effect is used.
+
+        If this method is not called, default, system-dependent timeout is
+        used.
+
+        @param showTimeout
+            Timeout of the show effect, in milliseconds.
+        @param hideTimeout
+            Timeout of the hide effect, in milliseconds.
+
+        @see SetEffects()
+     */
+    void SetEffectsTimeouts(unsigned showTimeout, unsigned hideTimeout);
+
+    /**
+        Set the same effect timeout to use for both showing and hiding the
+        pages.
+
+        This is the same as <code>SetEffectsTimeouts(timeout, timeout)</code>.
+
+        @see SetEffect()
+     */
+    void SetEffectTimeout(unsigned timeout);
+
+    /**
+        Add a new page and show it immediately.
+
+        This is simply a thin wrapper around the base class
+        wxBookCtrlBase::AddPage() method using empty label (which is unused by
+        this class anyhow) and selecting the new page immediately.
+     */
+    bool ShowNewPage(wxWindow* page);
+};
index 1ddbfbbe171ec7c33181a632f32f9c1e1175978b..46da69e90f8fc8ba68527189ca89768f019cf322 100644 (file)
@@ -302,7 +302,7 @@ MyFrame::MyFrame()
 #elif wxUSE_AUI
     m_type = Type_Aui;
 #else
-    #error "Don't use Notebook sample without any book enabled in wxWidgets build!"
+    m_type = Type_Simplebook;
 #endif
 
     m_orient = ID_ORIENT_DEFAULT;
@@ -335,6 +335,7 @@ MyFrame::MyFrame()
 #if wxUSE_AUI
     menuType->AppendRadioItem(ID_BOOK_AUINOTEBOOK,   wxT("&AuiNotebook\tCtrl-6"));
 #endif
+    menuType->AppendRadioItem(ID_BOOK_SIMPLEBOOK, "&Simple book\tCtrl-7");
 
     menuType->Check(ID_BOOK_NOTEBOOK + m_type, true);
 
@@ -489,7 +490,9 @@ MyFrame::~MyFrame()
     #define CASE_AUINOTEBOOK(x)
 #endif
 
-#define DISPATCH_ON_TYPE(before, nb, lb, cb, tb, toolb, aui, after)           \
+#define CASE_SIMPLEBOOK(x) case Type_Simplebook: x; break;
+
+#define DISPATCH_ON_TYPE(before, nb, lb, cb, tb, toolb, aui, sb, after)       \
     switch ( m_type )                                                         \
     {                                                                         \
         CASE_NOTEBOOK(before nb after)                                        \
@@ -498,9 +501,10 @@ MyFrame::~MyFrame()
         CASE_TREEBOOK(before tb after)                                        \
         CASE_TOOLBOOK(before toolb after)                                     \
         CASE_AUINOTEBOOK(before aui after)                                    \
+        CASE_SIMPLEBOOK(before sb after)                                      \
                                                                               \
         default:                                                              \
-            wxFAIL_MSG( wxT("unknown book control type") );                    \
+            wxFAIL_MSG( wxT("unknown book control type") );                   \
     }
 
 void MyFrame::RecreateBook()
@@ -554,6 +558,7 @@ void MyFrame::RecreateBook()
                          wxTreebook,
                          wxToolbook,
                          wxAuiNotebook,
+                         wxSimplebook,
                      (m_panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, flags));
 
     if ( !m_bookCtrl )
index 914535986e2badfa1ec11bce634f28be707f1916..416e31918cdc4bc12e25535387bf4d47eafb224f 100644 (file)
@@ -13,6 +13,7 @@
 #include "wx/listbook.h"
 #include "wx/treebook.h"
 #include "wx/notebook.h"
+#include "wx/simplebook.h"
 #include "wx/toolbook.h"
 #include "wx/aui/auibook.h"
 
@@ -108,6 +109,7 @@ private:
         Type_Treebook,
         Type_Toolbook,
         Type_AuiNotebook,
+        Type_Simplebook,
         Type_Max
     } m_type;
     int m_orient;
@@ -144,6 +146,7 @@ enum ID_COMMANDS
     ID_BOOK_TREEBOOK,
     ID_BOOK_TOOLBOOK,
     ID_BOOK_AUINOTEBOOK,
+    ID_BOOK_SIMPLEBOOK,
     ID_BOOK_MAX,
 
     ID_ORIENT_DEFAULT,