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