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