]> git.saurik.com Git - wxWidgets.git/blob - include/wx/simplebook.h
Better name for wxXmlResource::GetDirection() argument.
[wxWidgets.git] / include / wx / simplebook.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/simplebook.h
3 // Purpose: wxBookCtrlBase-derived class without any controller.
4 // Author: Vadim Zeitlin
5 // Created: 2012-08-21
6 // Copyright: (c) 2012 Vadim Zeitlin <vadim@wxwidgets.org>
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
9
10 #ifndef _WX_SIMPLEBOOK_H_
11 #define _WX_SIMPLEBOOK_H_
12
13 #include "wx/bookctrl.h"
14
15 #if wxUSE_BOOKCTRL
16
17 #include "wx/vector.h"
18
19 // ----------------------------------------------------------------------------
20 // wxSimplebook: a book control without any user-actionable controller.
21 // ----------------------------------------------------------------------------
22
23 // NB: This class doesn't use DLL export declaration as it's fully inline.
24
25 class wxSimplebook : public wxBookCtrlBase
26 {
27 public:
28 wxSimplebook()
29 {
30 Init();
31 }
32
33 wxSimplebook(wxWindow *parent,
34 wxWindowID winid = wxID_ANY,
35 const wxPoint& pos = wxDefaultPosition,
36 const wxSize& size = wxDefaultSize,
37 long style = 0,
38 const wxString& name = wxEmptyString)
39 : wxBookCtrlBase(parent, winid, pos, size, style | wxBK_TOP, name)
40 {
41 Init();
42 }
43
44
45 // Methods specific to this class.
46
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)
50 {
51 return AddPage(page, wxString(), true /* select it */);
52 }
53
54
55 // Set effect to use for showing/hiding pages.
56 void SetEffects(wxShowEffect showEffect, wxShowEffect hideEffect)
57 {
58 m_showEffect = showEffect;
59 m_hideEffect = hideEffect;
60 }
61
62 // Or the same effect for both of them.
63 void SetEffect(wxShowEffect effect)
64 {
65 SetEffects(effect, effect);
66 }
67
68 // And the same for time outs.
69 void SetEffectsTimeouts(unsigned showTimeout, unsigned hideTimeout)
70 {
71 m_showTimeout = showTimeout;
72 m_hideTimeout = hideTimeout;
73 }
74
75 void SetEffectTimeout(unsigned timeout)
76 {
77 SetEffectsTimeouts(timeout, timeout);
78 }
79
80
81 // Implement base class pure virtual methods.
82
83 // Page management
84 virtual bool InsertPage(size_t n,
85 wxWindow *page,
86 const wxString& text,
87 bool bSelect = false,
88 int imageId = NO_IMAGE)
89 {
90 if ( !wxBookCtrlBase::InsertPage(n, page, text, bSelect, imageId) )
91 return false;
92
93 m_pageTexts.insert(m_pageTexts.begin() + n, text);
94
95 if ( !DoSetSelectionAfterInsertion(n, bSelect) )
96 page->Hide();
97
98 return true;
99 }
100
101 virtual int SetSelection(size_t n)
102 {
103 return DoSetSelection(n, SetSelection_SendEvent);
104 }
105
106 virtual int ChangeSelection(size_t n)
107 {
108 return DoSetSelection(n);
109 }
110
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)
114 {
115 wxCHECK_MSG( n < GetPageCount(), false, wxS("Invalid page") );
116
117 m_pageTexts[n] = strText;
118
119 return true;
120 }
121
122 virtual wxString GetPageText(size_t n) const
123 {
124 wxCHECK_MSG( n < GetPageCount(), wxString(), wxS("Invalid page") );
125
126 return m_pageTexts[n];
127 }
128
129 virtual bool SetPageImage(size_t WXUNUSED(n), int WXUNUSED(imageId))
130 {
131 return false;
132 }
133
134 virtual int GetPageImage(size_t WXUNUSED(n)) const
135 {
136 return NO_IMAGE;
137 }
138
139 protected:
140 virtual void UpdateSelectedPage(size_t newsel)
141 {
142 m_selection = newsel;
143 }
144
145 virtual wxBookCtrlEvent* CreatePageChangingEvent() const
146 {
147 return new wxBookCtrlEvent(wxEVT_BOOKCTRL_PAGE_CHANGING,
148 GetId());
149 }
150
151 virtual void MakeChangedEvent(wxBookCtrlEvent& event)
152 {
153 event.SetEventType(wxEVT_BOOKCTRL_PAGE_CHANGED);
154 }
155
156 virtual wxWindow *DoRemovePage(size_t page)
157 {
158 wxWindow* const win = wxBookCtrlBase::DoRemovePage(page);
159 if ( win )
160 {
161 m_pageTexts.erase(m_pageTexts.begin() + page);
162
163 DoSetSelectionAfterRemoval(page);
164 }
165
166 return win;
167 }
168
169 virtual void DoSize()
170 {
171 wxWindow* const page = GetCurrentPage();
172 if ( page )
173 page->SetSize(GetPageRect());
174 }
175
176 virtual void DoShowPage(wxWindow* page, bool show)
177 {
178 if ( show )
179 page->ShowWithEffect(m_showEffect, m_showTimeout);
180 else
181 page->HideWithEffect(m_hideEffect, m_hideTimeout);
182 }
183
184 private:
185 void Init()
186 {
187 // We don't need any border as we don't have anything to separate the
188 // page contents from.
189 SetInternalBorder(0);
190
191 // No effects by default.
192 m_showEffect =
193 m_hideEffect = wxSHOW_EFFECT_NONE;
194
195 m_showTimeout =
196 m_hideTimeout = 0;
197 }
198
199 wxVector<wxString> m_pageTexts;
200
201 wxShowEffect m_showEffect,
202 m_hideEffect;
203
204 unsigned m_showTimeout,
205 m_hideTimeout;
206
207 wxDECLARE_NO_COPY_CLASS(wxSimplebook);
208 };
209
210 #endif // wxUSE_BOOKCTRL
211
212 #endif // _WX_SIMPLEBOOK_H_