1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/simplebook.h
3 // Purpose: wxBookCtrlBase-derived class without any controller.
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2012 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_SIMPLEBOOK_H_
12 #define _WX_SIMPLEBOOK_H_
14 #include "wx/bookctrl.h"
18 #include "wx/vector.h"
20 // ----------------------------------------------------------------------------
21 // wxSimplebook: a book control without any user-actionable controller.
22 // ----------------------------------------------------------------------------
24 // NB: This class doesn't use DLL export declaration as it's fully inline.
26 class wxSimplebook
: public wxBookCtrlBase
34 wxSimplebook(wxWindow
*parent
,
35 wxWindowID winid
= wxID_ANY
,
36 const wxPoint
& pos
= wxDefaultPosition
,
37 const wxSize
& size
= wxDefaultSize
,
39 const wxString
& name
= wxEmptyString
)
40 : wxBookCtrlBase(parent
, winid
, pos
, size
, style
| wxBK_TOP
, name
)
46 // Methods specific to this class.
48 // A method allowing to add a new page without any label (which is unused
49 // by this control) and show it immediately.
50 bool ShowNewPage(wxWindow
* page
)
52 return AddPage(page
, wxString(), true /* select it */);
56 // Set effect to use for showing/hiding pages.
57 void SetEffects(wxShowEffect showEffect
, wxShowEffect hideEffect
)
59 m_showEffect
= showEffect
;
60 m_hideEffect
= hideEffect
;
63 // Or the same effect for both of them.
64 void SetEffect(wxShowEffect effect
)
66 SetEffects(effect
, effect
);
69 // And the same for time outs.
70 void SetEffectsTimeouts(unsigned showTimeout
, unsigned hideTimeout
)
72 m_showTimeout
= showTimeout
;
73 m_hideTimeout
= hideTimeout
;
76 void SetEffectTimeout(unsigned timeout
)
78 SetEffectsTimeouts(timeout
, timeout
);
82 // Implement base class pure virtual methods.
85 virtual bool InsertPage(size_t n
,
89 int imageId
= NO_IMAGE
)
91 if ( !wxBookCtrlBase::InsertPage(n
, page
, text
, bSelect
, imageId
) )
94 m_pageTexts
.insert(m_pageTexts
.begin() + n
, text
);
96 if ( !DoSetSelectionAfterInsertion(n
, bSelect
) )
102 virtual int SetSelection(size_t n
)
104 return DoSetSelection(n
, SetSelection_SendEvent
);
107 virtual int ChangeSelection(size_t n
)
109 return DoSetSelection(n
);
112 // Neither labels nor images are supported but we still store the labels
113 // just in case the user code attaches some importance to them.
114 virtual bool SetPageText(size_t n
, const wxString
& strText
)
116 wxCHECK_MSG( n
< GetPageCount(), false, wxS("Invalid page") );
118 m_pageTexts
[n
] = strText
;
123 virtual wxString
GetPageText(size_t n
) const
125 wxCHECK_MSG( n
< GetPageCount(), wxString(), wxS("Invalid page") );
127 return m_pageTexts
[n
];
130 virtual bool SetPageImage(size_t WXUNUSED(n
), int WXUNUSED(imageId
))
135 virtual int GetPageImage(size_t WXUNUSED(n
)) const
141 virtual void UpdateSelectedPage(size_t newsel
)
143 m_selection
= newsel
;
146 virtual wxBookCtrlEvent
* CreatePageChangingEvent() const
148 return new wxBookCtrlEvent(wxEVT_BOOKCTRL_PAGE_CHANGING
,
152 virtual void MakeChangedEvent(wxBookCtrlEvent
& event
)
154 event
.SetEventType(wxEVT_BOOKCTRL_PAGE_CHANGED
);
157 virtual wxWindow
*DoRemovePage(size_t page
)
159 m_pageTexts
.erase(m_pageTexts
.begin() + page
);
160 return wxBookCtrlBase::DoRemovePage(page
);
163 virtual void DoSize()
165 wxWindow
* const page
= GetCurrentPage();
167 page
->SetSize(GetPageRect());
170 virtual void DoShowPage(wxWindow
* page
, bool show
)
173 page
->ShowWithEffect(m_showEffect
, m_showTimeout
);
175 page
->HideWithEffect(m_hideEffect
, m_hideTimeout
);
181 // We don't need any border as we don't have anything to separate the
182 // page contents from.
183 SetInternalBorder(0);
185 // No effects by default.
187 m_hideEffect
= wxSHOW_EFFECT_NONE
;
193 wxVector
<wxString
> m_pageTexts
;
195 wxShowEffect m_showEffect
,
198 unsigned m_showTimeout
,
201 wxDECLARE_NO_COPY_CLASS(wxSimplebook
);
204 #endif // wxUSE_BOOKCTRL
206 #endif // _WX_SIMPLEBOOK_H_