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