Set/get for internal border in book based controls.
[wxWidgets.git] / src / common / bookctrl.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: common/bookctrl.cpp
3 // Purpose: wxBookCtrlBase implementation
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 19.08.03
7 // RCS-ID: $Id$
8 // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #if wxUSE_BOOKCTRL
28
29 #include "wx/imaglist.h"
30
31 #include "wx/bookctrl.h"
32
33 // ============================================================================
34 // implementation
35 // ============================================================================
36
37 // ----------------------------------------------------------------------------
38 // constructors and destructors
39 // ----------------------------------------------------------------------------
40
41 void wxBookCtrlBase::Init()
42 {
43 m_imageList = NULL;
44 m_ownsImageList = false;
45
46 #if defined(__WXWINCE__)
47 m_internalBorder = 1;
48 #else
49 m_internalBorder = 5;
50 #endif
51 }
52
53 bool
54 wxBookCtrlBase::Create(wxWindow *parent,
55 wxWindowID id,
56 const wxPoint& pos,
57 const wxSize& size,
58 long style,
59 const wxString& name)
60 {
61 return wxControl::Create
62 (
63 parent,
64 id,
65 pos,
66 size,
67 style,
68 wxDefaultValidator,
69 name
70 );
71 }
72
73 wxBookCtrlBase::~wxBookCtrlBase()
74 {
75 if ( m_ownsImageList )
76 {
77 // may be NULL, ok
78 delete m_imageList;
79 }
80 }
81
82 // ----------------------------------------------------------------------------
83 // image list
84 // ----------------------------------------------------------------------------
85
86 void wxBookCtrlBase::SetImageList(wxImageList *imageList)
87 {
88 if ( m_ownsImageList )
89 {
90 // may be NULL, ok
91 delete m_imageList;
92
93 m_ownsImageList = false;
94 }
95
96 m_imageList = imageList;
97 }
98
99 void wxBookCtrlBase::AssignImageList(wxImageList* imageList)
100 {
101 SetImageList(imageList);
102
103 m_ownsImageList = true;
104 }
105
106 // ----------------------------------------------------------------------------
107 // geometry
108 // ----------------------------------------------------------------------------
109
110 void wxBookCtrlBase::SetPageSize(const wxSize& size)
111 {
112 SetClientSize(CalcSizeFromPage(size));
113 }
114
115 wxSize wxBookCtrlBase::DoGetBestSize() const
116 {
117 wxSize bestSize;
118
119 // iterate over all pages, get the largest width and height
120 const size_t nCount = m_pages.size();
121 for ( size_t nPage = 0; nPage < nCount; nPage++ )
122 {
123 const wxWindow * const pPage = m_pages[nPage];
124 if( pPage )
125 {
126 wxSize childBestSize(pPage->GetBestSize());
127
128 if ( childBestSize.x > bestSize.x )
129 bestSize.x = childBestSize.x;
130
131 if ( childBestSize.y > bestSize.y )
132 bestSize.y = childBestSize.y;
133 }
134 }
135
136 // convert display area to window area, adding the size necessary for the
137 // tabs
138 wxSize best = CalcSizeFromPage(bestSize);
139 CacheBestSize(best);
140 return best;
141 }
142
143 // ----------------------------------------------------------------------------
144 // pages management
145 // ----------------------------------------------------------------------------
146
147 bool
148 wxBookCtrlBase::InsertPage(size_t nPage,
149 wxWindow *page,
150 const wxString& WXUNUSED(text),
151 bool WXUNUSED(bSelect),
152 int WXUNUSED(imageId))
153 {
154 wxCHECK_MSG( page || AllowNullPage(), false, _T("NULL page in wxBookCtrlBase::InsertPage()") );
155 wxCHECK_MSG( nPage <= m_pages.size(), false,
156 _T("invalid page index in wxBookCtrlBase::InsertPage()") );
157
158 m_pages.Insert(page, nPage);
159 InvalidateBestSize();
160
161 return true;
162 }
163
164 bool wxBookCtrlBase::DeletePage(size_t nPage)
165 {
166 wxWindow *page = DoRemovePage(nPage);
167 if ( !(page || AllowNullPage()) )
168 return false;
169
170 // delete NULL is harmless
171 delete page;
172
173 return true;
174 }
175
176 wxWindow *wxBookCtrlBase::DoRemovePage(size_t nPage)
177 {
178 wxCHECK_MSG( nPage < m_pages.size(), NULL,
179 _T("invalid page index in wxBookCtrlBase::DoRemovePage()") );
180
181 wxWindow *pageRemoved = m_pages[nPage];
182 m_pages.RemoveAt(nPage);
183 InvalidateBestSize();
184
185 return pageRemoved;
186 }
187
188 int wxBookCtrlBase::GetNextPage(bool forward) const
189 {
190 int nPage;
191
192 int nMax = GetPageCount();
193 if ( nMax-- ) // decrement it to get the last valid index
194 {
195 int nSel = GetSelection();
196
197 // change selection wrapping if it becomes invalid
198 nPage = forward ? nSel == nMax ? 0
199 : nSel + 1
200 : nSel == 0 ? nMax
201 : nSel - 1;
202 }
203 else // notebook is empty, no next page
204 {
205 nPage = wxNOT_FOUND;
206 }
207
208 return nPage;
209 }
210
211 #endif // wxUSE_BOOKCTRL