]> git.saurik.com Git - wxWidgets.git/blame - src/common/bookctrl.cpp
Restored code uglies
[wxWidgets.git] / src / common / bookctrl.cpp
CommitLineData
15aad3b9
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: common/bookctrl.cpp
61c083e7 3// Purpose: wxBookCtrlBase implementation
15aad3b9
VZ
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>
65571936 9// Licence: wxWindows licence
15aad3b9
VZ
10///////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
15aad3b9
VZ
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
61c083e7 41void wxBookCtrlBase::Init()
15aad3b9
VZ
42{
43 m_imageList = NULL;
44 m_ownsImageList = false;
159e6235
WS
45
46#if defined(__WXWINCE__)
47 m_internalBorder = 1;
48#else
49 m_internalBorder = 5;
50#endif
15aad3b9
VZ
51}
52
53bool
61c083e7 54wxBookCtrlBase::Create(wxWindow *parent,
15aad3b9
VZ
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
61c083e7 73wxBookCtrlBase::~wxBookCtrlBase()
15aad3b9
VZ
74{
75 if ( m_ownsImageList )
76 {
77 // may be NULL, ok
78 delete m_imageList;
79 }
80}
81
82// ----------------------------------------------------------------------------
83// image list
84// ----------------------------------------------------------------------------
85
61c083e7 86void wxBookCtrlBase::SetImageList(wxImageList *imageList)
15aad3b9
VZ
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
61c083e7 99void wxBookCtrlBase::AssignImageList(wxImageList* imageList)
15aad3b9
VZ
100{
101 SetImageList(imageList);
102
103 m_ownsImageList = true;
104}
105
106// ----------------------------------------------------------------------------
107// geometry
108// ----------------------------------------------------------------------------
109
61c083e7 110void wxBookCtrlBase::SetPageSize(const wxSize& size)
15aad3b9
VZ
111{
112 SetClientSize(CalcSizeFromPage(size));
113}
114
61c083e7 115wxSize wxBookCtrlBase::DoGetBestSize() const
15aad3b9
VZ
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 {
eca15c0d
VZ
123 const wxWindow * const pPage = m_pages[nPage];
124 if( pPage )
125 {
126 wxSize childBestSize(pPage->GetBestSize());
15aad3b9 127
eca15c0d
VZ
128 if ( childBestSize.x > bestSize.x )
129 bestSize.x = childBestSize.x;
15aad3b9 130
eca15c0d
VZ
131 if ( childBestSize.y > bestSize.y )
132 bestSize.y = childBestSize.y;
133 }
15aad3b9
VZ
134 }
135
3103e8a9 136 // convert display area to window area, adding the size necessary for the
15aad3b9 137 // tabs
9f884528
RD
138 wxSize best = CalcSizeFromPage(bestSize);
139 CacheBestSize(best);
140 return best;
15aad3b9
VZ
141}
142
143// ----------------------------------------------------------------------------
144// pages management
145// ----------------------------------------------------------------------------
146
147bool
61c083e7
WS
148wxBookCtrlBase::InsertPage(size_t nPage,
149 wxWindow *page,
150 const wxString& WXUNUSED(text),
151 bool WXUNUSED(bSelect),
152 int WXUNUSED(imageId))
15aad3b9 153{
eca15c0d 154 wxCHECK_MSG( page || AllowNullPage(), false, _T("NULL page in wxBookCtrlBase::InsertPage()") );
712f40ca 155 wxCHECK_MSG( nPage <= m_pages.size(), false,
61c083e7 156 _T("invalid page index in wxBookCtrlBase::InsertPage()") );
15aad3b9
VZ
157
158 m_pages.Insert(page, nPage);
37144cf0 159 InvalidateBestSize();
c9d59ee7 160
15aad3b9
VZ
161 return true;
162}
163
61c083e7 164bool wxBookCtrlBase::DeletePage(size_t nPage)
15aad3b9
VZ
165{
166 wxWindow *page = DoRemovePage(nPage);
eca15c0d 167 if ( !(page || AllowNullPage()) )
15aad3b9
VZ
168 return false;
169
eca15c0d 170 // delete NULL is harmless
15aad3b9
VZ
171 delete page;
172
173 return true;
174}
175
61c083e7 176wxWindow *wxBookCtrlBase::DoRemovePage(size_t nPage)
15aad3b9
VZ
177{
178 wxCHECK_MSG( nPage < m_pages.size(), NULL,
61c083e7 179 _T("invalid page index in wxBookCtrlBase::DoRemovePage()") );
15aad3b9
VZ
180
181 wxWindow *pageRemoved = m_pages[nPage];
182 m_pages.RemoveAt(nPage);
37144cf0 183 InvalidateBestSize();
15aad3b9
VZ
184
185 return pageRemoved;
186}
187
61c083e7 188int wxBookCtrlBase::GetNextPage(bool forward) const
15aad3b9
VZ
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 {
159e6235 205 nPage = wxNOT_FOUND;
15aad3b9
VZ
206 }
207
208 return nPage;
209}
210
211#endif // wxUSE_BOOKCTRL