]>
Commit | Line | Data |
---|---|---|
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 | 41 | void wxBookCtrlBase::Init() |
15aad3b9 VZ |
42 | { |
43 | m_imageList = NULL; | |
44 | m_ownsImageList = false; | |
45 | } | |
46 | ||
47 | bool | |
61c083e7 | 48 | wxBookCtrlBase::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 | 67 | wxBookCtrlBase::~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 | 80 | void 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 | 93 | void wxBookCtrlBase::AssignImageList(wxImageList* imageList) |
15aad3b9 VZ |
94 | { |
95 | SetImageList(imageList); | |
96 | ||
97 | m_ownsImageList = true; | |
98 | } | |
99 | ||
100 | // ---------------------------------------------------------------------------- | |
101 | // geometry | |
102 | // ---------------------------------------------------------------------------- | |
103 | ||
61c083e7 | 104 | void wxBookCtrlBase::SetPageSize(const wxSize& size) |
15aad3b9 VZ |
105 | { |
106 | SetClientSize(CalcSizeFromPage(size)); | |
107 | } | |
108 | ||
61c083e7 | 109 | wxSize 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 | { | |
eca15c0d VZ |
117 | const wxWindow * const pPage = m_pages[nPage]; |
118 | if( pPage ) | |
119 | { | |
120 | wxSize childBestSize(pPage->GetBestSize()); | |
15aad3b9 | 121 | |
eca15c0d VZ |
122 | if ( childBestSize.x > bestSize.x ) |
123 | bestSize.x = childBestSize.x; | |
15aad3b9 | 124 | |
eca15c0d VZ |
125 | if ( childBestSize.y > bestSize.y ) |
126 | bestSize.y = childBestSize.y; | |
127 | } | |
15aad3b9 VZ |
128 | } |
129 | ||
3103e8a9 | 130 | // convert display area to window area, adding the size necessary for the |
15aad3b9 | 131 | // tabs |
9f884528 RD |
132 | wxSize best = CalcSizeFromPage(bestSize); |
133 | CacheBestSize(best); | |
134 | return best; | |
15aad3b9 VZ |
135 | } |
136 | ||
137 | // ---------------------------------------------------------------------------- | |
138 | // pages management | |
139 | // ---------------------------------------------------------------------------- | |
140 | ||
141 | bool | |
61c083e7 WS |
142 | wxBookCtrlBase::InsertPage(size_t nPage, |
143 | wxWindow *page, | |
144 | const wxString& WXUNUSED(text), | |
145 | bool WXUNUSED(bSelect), | |
146 | int WXUNUSED(imageId)) | |
15aad3b9 | 147 | { |
eca15c0d | 148 | wxCHECK_MSG( page || AllowNullPage(), false, _T("NULL page in wxBookCtrlBase::InsertPage()") ); |
712f40ca | 149 | wxCHECK_MSG( nPage <= m_pages.size(), false, |
61c083e7 | 150 | _T("invalid page index in wxBookCtrlBase::InsertPage()") ); |
15aad3b9 VZ |
151 | |
152 | m_pages.Insert(page, nPage); | |
37144cf0 | 153 | InvalidateBestSize(); |
c9d59ee7 | 154 | |
15aad3b9 VZ |
155 | return true; |
156 | } | |
157 | ||
61c083e7 | 158 | bool wxBookCtrlBase::DeletePage(size_t nPage) |
15aad3b9 VZ |
159 | { |
160 | wxWindow *page = DoRemovePage(nPage); | |
eca15c0d | 161 | if ( !(page || AllowNullPage()) ) |
15aad3b9 VZ |
162 | return false; |
163 | ||
eca15c0d | 164 | // delete NULL is harmless |
15aad3b9 VZ |
165 | delete page; |
166 | ||
167 | return true; | |
168 | } | |
169 | ||
61c083e7 | 170 | wxWindow *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 | 182 | int 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 |