]> git.saurik.com Git - wxWidgets.git/blame - include/wx/simplebook.h
Applied rowspan patch #15276 (dghart)
[wxWidgets.git] / include / wx / simplebook.h
CommitLineData
cc699de8
VZ
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
26class wxSimplebook : public wxBookCtrlBase
27{
28public:
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
140protected:
141 virtual void UpdateSelectedPage(size_t newsel)
142 {
143 m_selection = newsel;
144 }
145
146 virtual wxBookCtrlEvent* CreatePageChangingEvent() const
147 {
ce7fe42e 148 return new wxBookCtrlEvent(wxEVT_BOOKCTRL_PAGE_CHANGING,
cc699de8
VZ
149 GetId());
150 }
151
152 virtual void MakeChangedEvent(wxBookCtrlEvent& event)
153 {
ce7fe42e 154 event.SetEventType(wxEVT_BOOKCTRL_PAGE_CHANGED);
cc699de8
VZ
155 }
156
157 virtual wxWindow *DoRemovePage(size_t page)
158 {
4f9ccec5
VZ
159 wxWindow* const win = wxBookCtrlBase::DoRemovePage(page);
160 if ( win )
161 {
162 m_pageTexts.erase(m_pageTexts.begin() + page);
163
164 DoSetSelectionAfterRemoval(page);
165 }
166
167 return win;
cc699de8
VZ
168 }
169
170 virtual void DoSize()
171 {
172 wxWindow* const page = GetCurrentPage();
173 if ( page )
174 page->SetSize(GetPageRect());
175 }
176
177 virtual void DoShowPage(wxWindow* page, bool show)
178 {
179 if ( show )
180 page->ShowWithEffect(m_showEffect, m_showTimeout);
181 else
182 page->HideWithEffect(m_hideEffect, m_hideTimeout);
183 }
184
185private:
186 void Init()
187 {
188 // We don't need any border as we don't have anything to separate the
189 // page contents from.
190 SetInternalBorder(0);
191
192 // No effects by default.
193 m_showEffect =
194 m_hideEffect = wxSHOW_EFFECT_NONE;
195
196 m_showTimeout =
197 m_hideTimeout = 0;
198 }
199
200 wxVector<wxString> m_pageTexts;
201
202 wxShowEffect m_showEffect,
203 m_hideEffect;
204
205 unsigned m_showTimeout,
206 m_hideTimeout;
207
208 wxDECLARE_NO_COPY_CLASS(wxSimplebook);
209};
210
211#endif // wxUSE_BOOKCTRL
212
213#endif // _WX_SIMPLEBOOK_H_