Added wxSimplebook class: a wxBookCtrl without controller.

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
This commit is contained in:
Vadim Zeitlin
2012-08-30 20:21:54 +00:00
parent 2e18fe7139
commit cc699de848
13 changed files with 372 additions and 4 deletions

View File

@@ -4214,6 +4214,7 @@ COND_USE_GUI_1_ALL_GUI_HEADERS = \
wx/rawbmp.h \ wx/rawbmp.h \
wx/region.h \ wx/region.h \
wx/scopeguard.h \ wx/scopeguard.h \
wx/simplebook.h \
wx/spinbutt.h \ wx/spinbutt.h \
wx/spinctrl.h \ wx/spinctrl.h \
wx/splitter.h \ wx/splitter.h \

View File

@@ -988,6 +988,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
wx/rawbmp.h wx/rawbmp.h
wx/region.h wx/region.h
wx/scopeguard.h wx/scopeguard.h
wx/simplebook.h
wx/spinbutt.h wx/spinbutt.h
wx/spinctrl.h wx/spinctrl.h
wx/splitter.h wx/splitter.h

View File

@@ -6867,6 +6867,10 @@ SOURCE=..\..\include\wx\settings.h
# End Source File # End Source File
# Begin Source File # Begin Source File
SOURCE=..\..\include\wx\simplebook.h
# End Source File
# Begin Source File
SOURCE=..\..\include\wx\sizer.h SOURCE=..\..\include\wx\sizer.h
# End Source File # End Source File
# Begin Source File # Begin Source File

View File

@@ -5714,6 +5714,9 @@
<File <File
RelativePath="..\..\include\wx\settings.h"> RelativePath="..\..\include\wx\settings.h">
</File> </File>
<File
RelativePath="..\..\include\wx\simplebook.h">
</File>
<File <File
RelativePath="..\..\include\wx\sizer.h"> RelativePath="..\..\include\wx\sizer.h">
</File> </File>

View File

@@ -7639,6 +7639,10 @@
RelativePath="..\..\include\wx\settings.h" RelativePath="..\..\include\wx\settings.h"
> >
</File> </File>
<File
RelativePath="..\..\include\wx\simplebook.h"
>
</File>
<File <File
RelativePath="..\..\include\wx\sizer.h" RelativePath="..\..\include\wx\sizer.h"
> >

View File

@@ -7635,6 +7635,10 @@
RelativePath="..\..\include\wx\settings.h" RelativePath="..\..\include\wx\settings.h"
> >
</File> </File>
<File
RelativePath="..\..\include\wx\simplebook.h"
>
</File>
<File <File
RelativePath="..\..\include\wx\sizer.h" RelativePath="..\..\include\wx\sizer.h"
> >

View File

@@ -535,8 +535,9 @@ All:
All (GUI): 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). - 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 possibility to hide and show again wxRibbonBar pages (wxBen).
- Add wxRibbonBar pages highlighting (wxBen). - Add wxRibbonBar pages highlighting (wxBen).
- Add expand/collapse button to wxRibbonBar (rakeshthp). - Add expand/collapse button to wxRibbonBar (rakeshthp).

View 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 wxSashWindow: Window with four optional sashes that can be dragged
@li wxSashLayoutWindow: Window that can be involved in an IDE-like layout @li wxSashLayoutWindow: Window that can be involved in an IDE-like layout
arrangement 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 wxWizardPage: A base class for the page in wizard dialog.
@li wxWizardPageSimple: A page in wizard dialog. @li wxWizardPageSimple: A page in wizard dialog.
@li wxCustomBackgroundWindow: A window allowing to set a custom bitmap. @li wxCustomBackgroundWindow: A window allowing to set a custom bitmap.

View File

@@ -15,6 +15,7 @@ Classes:
@li wxChoicebook @li wxChoicebook
@li wxListbook @li wxListbook
@li wxNotebook @li wxNotebook
@li wxSimplebook
@li wxTreebook @li wxTreebook
@li wxToolbook @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 wxChoicebook: controlled by a wxChoice
@li wxListbook: controlled by a wxListCtrl @li wxListbook: controlled by a wxListCtrl
@li wxNotebook: uses a row of tabs @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 wxTreebook: controlled by a wxTreeCtrl
@li wxToolbook: controlled by a wxToolBar @li wxToolbook: controlled by a wxToolBar
See the @ref page_samples_notebook for an example of wxBookCtrl usage. 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 @section overview_bookctrl_bestbookctrl Best Book

206
include/wx/simplebook.h Normal file
View File

@@ -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_

129
interface/wx/simplebook.h Normal file
View File

@@ -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);
};

View File

@@ -302,7 +302,7 @@ MyFrame::MyFrame()
#elif wxUSE_AUI #elif wxUSE_AUI
m_type = Type_Aui; m_type = Type_Aui;
#else #else
#error "Don't use Notebook sample without any book enabled in wxWidgets build!" m_type = Type_Simplebook;
#endif #endif
m_orient = ID_ORIENT_DEFAULT; m_orient = ID_ORIENT_DEFAULT;
@@ -335,6 +335,7 @@ MyFrame::MyFrame()
#if wxUSE_AUI #if wxUSE_AUI
menuType->AppendRadioItem(ID_BOOK_AUINOTEBOOK, wxT("&AuiNotebook\tCtrl-6")); menuType->AppendRadioItem(ID_BOOK_AUINOTEBOOK, wxT("&AuiNotebook\tCtrl-6"));
#endif #endif
menuType->AppendRadioItem(ID_BOOK_SIMPLEBOOK, "&Simple book\tCtrl-7");
menuType->Check(ID_BOOK_NOTEBOOK + m_type, true); menuType->Check(ID_BOOK_NOTEBOOK + m_type, true);
@@ -489,7 +490,9 @@ MyFrame::~MyFrame()
#define CASE_AUINOTEBOOK(x) #define CASE_AUINOTEBOOK(x)
#endif #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 ) \ switch ( m_type ) \
{ \ { \
CASE_NOTEBOOK(before nb after) \ CASE_NOTEBOOK(before nb after) \
@@ -498,6 +501,7 @@ MyFrame::~MyFrame()
CASE_TREEBOOK(before tb after) \ CASE_TREEBOOK(before tb after) \
CASE_TOOLBOOK(before toolb after) \ CASE_TOOLBOOK(before toolb after) \
CASE_AUINOTEBOOK(before aui after) \ CASE_AUINOTEBOOK(before aui after) \
CASE_SIMPLEBOOK(before sb after) \
\ \
default: \ default: \
wxFAIL_MSG( wxT("unknown book control type") ); \ wxFAIL_MSG( wxT("unknown book control type") ); \
@@ -554,6 +558,7 @@ void MyFrame::RecreateBook()
wxTreebook, wxTreebook,
wxToolbook, wxToolbook,
wxAuiNotebook, wxAuiNotebook,
wxSimplebook,
(m_panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, flags)); (m_panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, flags));
if ( !m_bookCtrl ) if ( !m_bookCtrl )

View File

@@ -13,6 +13,7 @@
#include "wx/listbook.h" #include "wx/listbook.h"
#include "wx/treebook.h" #include "wx/treebook.h"
#include "wx/notebook.h" #include "wx/notebook.h"
#include "wx/simplebook.h"
#include "wx/toolbook.h" #include "wx/toolbook.h"
#include "wx/aui/auibook.h" #include "wx/aui/auibook.h"
@@ -108,6 +109,7 @@ private:
Type_Treebook, Type_Treebook,
Type_Toolbook, Type_Toolbook,
Type_AuiNotebook, Type_AuiNotebook,
Type_Simplebook,
Type_Max Type_Max
} m_type; } m_type;
int m_orient; int m_orient;
@@ -144,6 +146,7 @@ enum ID_COMMANDS
ID_BOOK_TREEBOOK, ID_BOOK_TREEBOOK,
ID_BOOK_TOOLBOOK, ID_BOOK_TOOLBOOK,
ID_BOOK_AUINOTEBOOK, ID_BOOK_AUINOTEBOOK,
ID_BOOK_SIMPLEBOOK,
ID_BOOK_MAX, ID_BOOK_MAX,
ID_ORIENT_DEFAULT, ID_ORIENT_DEFAULT,