]> git.saurik.com Git - wxWidgets.git/blob - src/common/bookctrl.cpp
cleanup in toplevel activation, and switching to native carbon event notification...
[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 void wxBookCtrl::Init()
46 {
47 m_imageList = NULL;
48 m_ownsImageList = false;
49 }
50
51 bool
52 wxBookCtrl::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
71 wxBookCtrl::~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
84 void 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
97 void wxBookCtrl::AssignImageList(wxImageList* imageList)
98 {
99 SetImageList(imageList);
100
101 m_ownsImageList = true;
102 }
103
104 // ----------------------------------------------------------------------------
105 // geometry
106 // ----------------------------------------------------------------------------
107
108 void wxBookCtrl::SetPageSize(const wxSize& size)
109 {
110 SetClientSize(CalcSizeFromPage(size));
111 }
112
113 wxSize 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
133 return CalcSizeFromPage(bestSize);
134 }
135
136 // ----------------------------------------------------------------------------
137 // pages management
138 // ----------------------------------------------------------------------------
139
140 bool
141 wxBookCtrl::InsertPage(size_t nPage,
142 wxWindow *page,
143 const wxString& WXUNUSED(text),
144 bool WXUNUSED(bSelect),
145 int WXUNUSED(imageId))
146 {
147 wxCHECK_MSG( page, false, _T("NULL page in wxBookCtrl::InsertPage()") );
148 wxCHECK_MSG( nPage <= m_pages.size(), false,
149 _T("invalid page index in wxBookCtrl::InsertPage()") );
150
151 m_pages.Insert(page, nPage);
152
153 return true;
154 }
155
156 bool wxBookCtrl::DeletePage(size_t nPage)
157 {
158 wxWindow *page = DoRemovePage(nPage);
159 if ( !page )
160 return false;
161
162 delete page;
163
164 return true;
165 }
166
167 wxWindow *wxBookCtrl::DoRemovePage(size_t nPage)
168 {
169 wxCHECK_MSG( nPage < m_pages.size(), NULL,
170 _T("invalid page index in wxBookCtrl::DoRemovePage()") );
171
172 wxWindow *pageRemoved = m_pages[nPage];
173 m_pages.RemoveAt(nPage);
174
175 return pageRemoved;
176 }
177
178 int wxBookCtrl::GetNextPage(bool forward) const
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