]> git.saurik.com Git - wxWidgets.git/blame - src/common/bookctrl.cpp
implemented wxSS::GetMetric on wxGTK2 (patch 950618)
[wxWidgets.git] / src / common / bookctrl.cpp
CommitLineData
15aad3b9
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: common/bookctrl.cpp
3// Purpose: wxBookCtrl 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>
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
45void wxBookCtrl::Init()
46{
47 m_imageList = NULL;
48 m_ownsImageList = false;
49}
50
51bool
52wxBookCtrl::Create(wxWindow *parent,
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
71wxBookCtrl::~wxBookCtrl()
72{
73 if ( m_ownsImageList )
74 {
75 // may be NULL, ok
76 delete m_imageList;
77 }
78}
79
80// ----------------------------------------------------------------------------
81// image list
82// ----------------------------------------------------------------------------
83
84void wxBookCtrl::SetImageList(wxImageList *imageList)
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
97void wxBookCtrl::AssignImageList(wxImageList* imageList)
98{
99 SetImageList(imageList);
100
101 m_ownsImageList = true;
102}
103
104// ----------------------------------------------------------------------------
105// geometry
106// ----------------------------------------------------------------------------
107
108void wxBookCtrl::SetPageSize(const wxSize& size)
109{
110 SetClientSize(CalcSizeFromPage(size));
111}
112
113wxSize wxBookCtrl::DoGetBestSize() const
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
143wxBookCtrl::InsertPage(size_t nPage,
144 wxWindow *page,
f7f97bf3
VZ
145 const wxString& WXUNUSED(text),
146 bool WXUNUSED(bSelect),
147 int WXUNUSED(imageId))
15aad3b9
VZ
148{
149 wxCHECK_MSG( page, false, _T("NULL page in wxBookCtrl::InsertPage()") );
712f40ca 150 wxCHECK_MSG( nPage <= m_pages.size(), false,
15aad3b9
VZ
151 _T("invalid page index in wxBookCtrl::InsertPage()") );
152
153 m_pages.Insert(page, nPage);
154
155 return true;
156}
157
158bool wxBookCtrl::DeletePage(size_t nPage)
159{
160 wxWindow *page = DoRemovePage(nPage);
161 if ( !page )
162 return false;
163
164 delete page;
165
166 return true;
167}
168
169wxWindow *wxBookCtrl::DoRemovePage(size_t nPage)
170{
171 wxCHECK_MSG( nPage < m_pages.size(), NULL,
172 _T("invalid page index in wxBookCtrl::DoRemovePage()") );
173
174 wxWindow *pageRemoved = m_pages[nPage];
175 m_pages.RemoveAt(nPage);
176
177 return pageRemoved;
178}
179
180int wxBookCtrl::GetNextPage(bool forward) const
181{
182 int nPage;
183
184 int nMax = GetPageCount();
185 if ( nMax-- ) // decrement it to get the last valid index
186 {
187 int nSel = GetSelection();
188
189 // change selection wrapping if it becomes invalid
190 nPage = forward ? nSel == nMax ? 0
191 : nSel + 1
192 : nSel == 0 ? nMax
193 : nSel - 1;
194 }
195 else // notebook is empty, no next page
196 {
197 nPage = -1;
198 }
199
200 return nPage;
201}
202
203#endif // wxUSE_BOOKCTRL
204