1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/simplebook.h
3 // Purpose: wxBookCtrlBase-derived class without any controller.
4 // Author: Vadim Zeitlin
6 // Copyright: (c) 2012 Vadim Zeitlin <vadim@wxwidgets.org>
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
10 #ifndef _WX_SIMPLEBOOK_H_
11 #define _WX_SIMPLEBOOK_H_
13 #include "wx/bookctrl.h"
17 #include "wx/vector.h"
19 // ----------------------------------------------------------------------------
20 // wxSimplebook: a book control without any user-actionable controller.
21 // ----------------------------------------------------------------------------
23 // NB: This class doesn't use DLL export declaration as it's fully inline.
25 class wxSimplebook
: public wxBookCtrlBase
33 wxSimplebook(wxWindow
*parent
,
34 wxWindowID winid
= wxID_ANY
,
35 const wxPoint
& pos
= wxDefaultPosition
,
36 const wxSize
& size
= wxDefaultSize
,
38 const wxString
& name
= wxEmptyString
)
39 : wxBookCtrlBase(parent
, winid
, pos
, size
, style
| wxBK_TOP
, name
)
45 // Methods specific to this class.
47 // A method allowing to add a new page without any label (which is unused
48 // by this control) and show it immediately.
49 bool ShowNewPage(wxWindow
* page
)
51 return AddPage(page
, wxString(), true /* select it */);
55 // Set effect to use for showing/hiding pages.
56 void SetEffects(wxShowEffect showEffect
, wxShowEffect hideEffect
)
58 m_showEffect
= showEffect
;
59 m_hideEffect
= hideEffect
;
62 // Or the same effect for both of them.
63 void SetEffect(wxShowEffect effect
)
65 SetEffects(effect
, effect
);
68 // And the same for time outs.
69 void SetEffectsTimeouts(unsigned showTimeout
, unsigned hideTimeout
)
71 m_showTimeout
= showTimeout
;
72 m_hideTimeout
= hideTimeout
;
75 void SetEffectTimeout(unsigned timeout
)
77 SetEffectsTimeouts(timeout
, timeout
);
81 // Implement base class pure virtual methods.
84 virtual bool InsertPage(size_t n
,
88 int imageId
= NO_IMAGE
)
90 if ( !wxBookCtrlBase::InsertPage(n
, page
, text
, bSelect
, imageId
) )
93 m_pageTexts
.insert(m_pageTexts
.begin() + n
, text
);
95 if ( !DoSetSelectionAfterInsertion(n
, bSelect
) )
101 virtual int SetSelection(size_t n
)
103 return DoSetSelection(n
, SetSelection_SendEvent
);
106 virtual int ChangeSelection(size_t n
)
108 return DoSetSelection(n
);
111 // Neither labels nor images are supported but we still store the labels
112 // just in case the user code attaches some importance to them.
113 virtual bool SetPageText(size_t n
, const wxString
& strText
)
115 wxCHECK_MSG( n
< GetPageCount(), false, wxS("Invalid page") );
117 m_pageTexts
[n
] = strText
;
122 virtual wxString
GetPageText(size_t n
) const
124 wxCHECK_MSG( n
< GetPageCount(), wxString(), wxS("Invalid page") );
126 return m_pageTexts
[n
];
129 virtual bool SetPageImage(size_t WXUNUSED(n
), int WXUNUSED(imageId
))
134 virtual int GetPageImage(size_t WXUNUSED(n
)) const
140 virtual void UpdateSelectedPage(size_t newsel
)
142 m_selection
= newsel
;
145 virtual wxBookCtrlEvent
* CreatePageChangingEvent() const
147 return new wxBookCtrlEvent(wxEVT_BOOKCTRL_PAGE_CHANGING
,
151 virtual void MakeChangedEvent(wxBookCtrlEvent
& event
)
153 event
.SetEventType(wxEVT_BOOKCTRL_PAGE_CHANGED
);
156 virtual wxWindow
*DoRemovePage(size_t page
)
158 wxWindow
* const win
= wxBookCtrlBase::DoRemovePage(page
);
161 m_pageTexts
.erase(m_pageTexts
.begin() + page
);
163 DoSetSelectionAfterRemoval(page
);
169 virtual void DoSize()
171 wxWindow
* const page
= GetCurrentPage();
173 page
->SetSize(GetPageRect());
176 virtual void DoShowPage(wxWindow
* page
, bool show
)
179 page
->ShowWithEffect(m_showEffect
, m_showTimeout
);
181 page
->HideWithEffect(m_hideEffect
, m_hideTimeout
);
187 // We don't need any border as we don't have anything to separate the
188 // page contents from.
189 SetInternalBorder(0);
191 // No effects by default.
193 m_hideEffect
= wxSHOW_EFFECT_NONE
;
199 wxVector
<wxString
> m_pageTexts
;
201 wxShowEffect m_showEffect
,
204 unsigned m_showTimeout
,
207 wxDECLARE_NO_COPY_CLASS(wxSimplebook
);
210 #endif // wxUSE_BOOKCTRL
212 #endif // _WX_SIMPLEBOOK_H_