]>
Commit | Line | Data |
---|---|---|
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 | ||
45 | void wxBookCtrl::Init() | |
46 | { | |
47 | m_imageList = NULL; | |
48 | m_ownsImageList = false; | |
0335f6f7 JS |
49 | // Unlike most controls, we don't want to adjust the min size |
50 | // when we set the font, since the page size is not related to | |
51 | // the font size. | |
52 | m_adjustMinSize = false; | |
15aad3b9 VZ |
53 | } |
54 | ||
55 | bool | |
56 | wxBookCtrl::Create(wxWindow *parent, | |
57 | wxWindowID id, | |
58 | const wxPoint& pos, | |
59 | const wxSize& size, | |
60 | long style, | |
61 | const wxString& name) | |
62 | { | |
63 | return wxControl::Create | |
64 | ( | |
65 | parent, | |
66 | id, | |
67 | pos, | |
68 | size, | |
69 | style, | |
70 | wxDefaultValidator, | |
71 | name | |
72 | ); | |
73 | } | |
74 | ||
75 | wxBookCtrl::~wxBookCtrl() | |
76 | { | |
77 | if ( m_ownsImageList ) | |
78 | { | |
79 | // may be NULL, ok | |
80 | delete m_imageList; | |
81 | } | |
82 | } | |
83 | ||
84 | // ---------------------------------------------------------------------------- | |
85 | // image list | |
86 | // ---------------------------------------------------------------------------- | |
87 | ||
88 | void wxBookCtrl::SetImageList(wxImageList *imageList) | |
89 | { | |
90 | if ( m_ownsImageList ) | |
91 | { | |
92 | // may be NULL, ok | |
93 | delete m_imageList; | |
94 | ||
95 | m_ownsImageList = false; | |
96 | } | |
97 | ||
98 | m_imageList = imageList; | |
99 | } | |
100 | ||
101 | void wxBookCtrl::AssignImageList(wxImageList* imageList) | |
102 | { | |
103 | SetImageList(imageList); | |
104 | ||
105 | m_ownsImageList = true; | |
106 | } | |
107 | ||
108 | // ---------------------------------------------------------------------------- | |
109 | // geometry | |
110 | // ---------------------------------------------------------------------------- | |
111 | ||
112 | void wxBookCtrl::SetPageSize(const wxSize& size) | |
113 | { | |
114 | SetClientSize(CalcSizeFromPage(size)); | |
115 | } | |
116 | ||
117 | wxSize wxBookCtrl::DoGetBestSize() const | |
118 | { | |
119 | wxSize bestSize; | |
120 | ||
121 | // iterate over all pages, get the largest width and height | |
122 | const size_t nCount = m_pages.size(); | |
123 | for ( size_t nPage = 0; nPage < nCount; nPage++ ) | |
124 | { | |
125 | wxWindow *pPage = m_pages[nPage]; | |
126 | wxSize childBestSize(pPage->GetBestSize()); | |
127 | ||
128 | if ( childBestSize.x > bestSize.x ) | |
129 | bestSize.x = childBestSize.x; | |
130 | ||
131 | if ( childBestSize.y > bestSize.y ) | |
132 | bestSize.y = childBestSize.y; | |
133 | } | |
134 | ||
135 | // convert display area to window area, adding the size neccessary for the | |
136 | // tabs | |
137 | return CalcSizeFromPage(bestSize); | |
138 | } | |
139 | ||
140 | // ---------------------------------------------------------------------------- | |
141 | // pages management | |
142 | // ---------------------------------------------------------------------------- | |
143 | ||
144 | bool | |
145 | wxBookCtrl::InsertPage(size_t nPage, | |
146 | wxWindow *page, | |
f7f97bf3 VZ |
147 | const wxString& WXUNUSED(text), |
148 | bool WXUNUSED(bSelect), | |
149 | int WXUNUSED(imageId)) | |
15aad3b9 VZ |
150 | { |
151 | wxCHECK_MSG( page, false, _T("NULL page in wxBookCtrl::InsertPage()") ); | |
712f40ca | 152 | wxCHECK_MSG( nPage <= m_pages.size(), false, |
15aad3b9 VZ |
153 | _T("invalid page index in wxBookCtrl::InsertPage()") ); |
154 | ||
155 | m_pages.Insert(page, nPage); | |
156 | ||
157 | return true; | |
158 | } | |
159 | ||
160 | bool wxBookCtrl::DeletePage(size_t nPage) | |
161 | { | |
162 | wxWindow *page = DoRemovePage(nPage); | |
163 | if ( !page ) | |
164 | return false; | |
165 | ||
166 | delete page; | |
167 | ||
168 | return true; | |
169 | } | |
170 | ||
171 | wxWindow *wxBookCtrl::DoRemovePage(size_t nPage) | |
172 | { | |
173 | wxCHECK_MSG( nPage < m_pages.size(), NULL, | |
174 | _T("invalid page index in wxBookCtrl::DoRemovePage()") ); | |
175 | ||
176 | wxWindow *pageRemoved = m_pages[nPage]; | |
177 | m_pages.RemoveAt(nPage); | |
178 | ||
179 | return pageRemoved; | |
180 | } | |
181 | ||
182 | int wxBookCtrl::GetNextPage(bool forward) const | |
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 |