]>
git.saurik.com Git - wxWidgets.git/blob - src/common/bookctrl.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/bookctrl.cpp
3 // Purpose: wxBookCtrlBase implementation
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
29 #include "wx/imaglist.h"
31 #include "wx/bookctrl.h"
33 // ============================================================================
35 // ============================================================================
37 // ----------------------------------------------------------------------------
39 // ----------------------------------------------------------------------------
41 IMPLEMENT_ABSTRACT_CLASS(wxBookCtrlBase
, wxControl
)
43 BEGIN_EVENT_TABLE(wxBookCtrlBase
, wxControl
)
44 EVT_SIZE(wxBookCtrlBase::OnSize
)
47 // ----------------------------------------------------------------------------
48 // constructors and destructors
49 // ----------------------------------------------------------------------------
51 void wxBookCtrlBase::Init()
55 m_ownsImageList
= false;
56 m_fitToCurrentPage
= false;
58 #if defined(__WXWINCE__)
65 m_controlSizer
= NULL
;
69 wxBookCtrlBase::Create(wxWindow
*parent
,
76 return wxControl::Create
88 wxBookCtrlBase::~wxBookCtrlBase()
90 if ( m_ownsImageList
)
97 // ----------------------------------------------------------------------------
99 // ----------------------------------------------------------------------------
101 void wxBookCtrlBase::SetImageList(wxImageList
*imageList
)
103 if ( m_ownsImageList
)
108 m_ownsImageList
= false;
111 m_imageList
= imageList
;
114 void wxBookCtrlBase::AssignImageList(wxImageList
* imageList
)
116 SetImageList(imageList
);
118 m_ownsImageList
= true;
121 // ----------------------------------------------------------------------------
123 // ----------------------------------------------------------------------------
125 void wxBookCtrlBase::SetPageSize(const wxSize
& size
)
127 SetClientSize(CalcSizeFromPage(size
));
130 wxSize
wxBookCtrlBase::DoGetBestSize() const
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
++ )
138 const wxWindow
* const pPage
= m_pages
[nPage
];
141 wxSize
childBestSize(pPage
->GetBestSize());
143 if ( childBestSize
.x
> bestSize
.x
)
144 bestSize
.x
= childBestSize
.x
;
146 if ( childBestSize
.y
> bestSize
.y
)
147 bestSize
.y
= childBestSize
.y
;
151 if (m_fitToCurrentPage
&& GetCurrentPage())
152 bestSize
= GetCurrentPage()->GetBestSize();
154 // convert display area to window area, adding the size necessary for the
156 wxSize best
= CalcSizeFromPage(bestSize
);
161 // ----------------------------------------------------------------------------
163 // ----------------------------------------------------------------------------
166 wxBookCtrlBase::InsertPage(size_t nPage
,
168 const wxString
& WXUNUSED(text
),
169 bool WXUNUSED(bSelect
),
170 int WXUNUSED(imageId
))
172 wxCHECK_MSG( page
|| AllowNullPage(), false,
173 _T("NULL page in wxBookCtrlBase::InsertPage()") );
174 wxCHECK_MSG( nPage
<= m_pages
.size(), false,
175 _T("invalid page index in wxBookCtrlBase::InsertPage()") );
177 m_pages
.Insert(page
, nPage
);
178 InvalidateBestSize();
183 bool wxBookCtrlBase::DeletePage(size_t nPage
)
185 wxWindow
*page
= DoRemovePage(nPage
);
186 if ( !(page
|| AllowNullPage()) )
189 // delete NULL is harmless
195 wxWindow
*wxBookCtrlBase::DoRemovePage(size_t nPage
)
197 wxCHECK_MSG( nPage
< m_pages
.size(), NULL
,
198 _T("invalid page index in wxBookCtrlBase::DoRemovePage()") );
200 wxWindow
*pageRemoved
= m_pages
[nPage
];
201 m_pages
.RemoveAt(nPage
);
202 InvalidateBestSize();
207 int wxBookCtrlBase::GetNextPage(bool forward
) const
211 int nMax
= GetPageCount();
212 if ( nMax
-- ) // decrement it to get the last valid index
214 int nSel
= GetSelection();
216 // change selection wrapping if it becomes invalid
217 nPage
= forward
? nSel
== nMax
? 0
222 else // notebook is empty, no next page
230 wxRect
wxBookCtrlBase::GetPageRect() const
232 const wxSize size
= GetControllerSize();
235 wxRect
rectPage(pt
, GetClientSize());
236 switch ( GetWindowStyle() & wxBK_ALIGN_MASK
)
239 wxFAIL_MSG( _T("unexpected alignment") );
243 rectPage
.y
= size
.y
+ GetInternalBorder();
247 rectPage
.height
-= size
.y
+ GetInternalBorder();
251 rectPage
.x
= size
.x
+ GetInternalBorder();
255 rectPage
.width
-= size
.x
+ GetInternalBorder();
263 void wxBookCtrlBase::DoSize()
267 // we're not fully created yet or OnSize() should be hidden by derived class
275 // resize controller and the page area to fit inside our new size
276 const wxSize
sizeClient( GetClientSize() ),
277 sizeBorder( m_bookctrl
->GetSize() - m_bookctrl
->GetClientSize() ),
278 sizeCtrl( GetControllerSize() );
280 m_bookctrl
->SetClientSize( sizeCtrl
.x
- sizeBorder
.x
, sizeCtrl
.y
- sizeBorder
.y
);
282 const wxSize sizeNew
= m_bookctrl
->GetSize();
284 switch ( GetWindowStyle() & wxBK_ALIGN_MASK
)
287 wxFAIL_MSG( _T("unexpected alignment") );
292 // posCtrl is already ok
296 posCtrl
.y
= sizeClient
.y
- sizeNew
.y
;
300 posCtrl
.x
= sizeClient
.x
- sizeNew
.x
;
304 if ( m_bookctrl
->GetPosition() != posCtrl
)
305 m_bookctrl
->Move(posCtrl
);
308 // resize the currently shown page
309 if (GetSelection() != wxNOT_FOUND
)
311 wxWindow
*page
= m_pages
[GetSelection()];
312 wxCHECK_RET( page
, _T("NULL page?") );
313 page
->SetSize(GetPageRect());
317 void wxBookCtrlBase::OnSize(wxSizeEvent
& event
)
324 wxSize
wxBookCtrlBase::GetControllerSize() const
329 const wxSize sizeClient
= GetClientSize(),
330 sizeBorder
= m_bookctrl
->GetSize() - m_bookctrl
->GetClientSize(),
331 sizeCtrl
= m_bookctrl
->GetBestSize() + sizeBorder
;
337 size
.x
= sizeClient
.x
;
340 else // left/right aligned
343 size
.y
= sizeClient
.y
;
349 #endif // wxUSE_BOOKCTRL