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