]>
git.saurik.com Git - wxWidgets.git/blob - src/common/bookctrl.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: 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 // ----------------------------------------------------------------------------
38 // constructors and destructors
39 // ----------------------------------------------------------------------------
41 void wxBookCtrlBase::Init()
44 m_ownsImageList
= false;
48 wxBookCtrlBase::Create(wxWindow
*parent
,
55 return wxControl::Create
67 wxBookCtrlBase::~wxBookCtrlBase()
69 if ( m_ownsImageList
)
76 // ----------------------------------------------------------------------------
78 // ----------------------------------------------------------------------------
80 void wxBookCtrlBase::SetImageList(wxImageList
*imageList
)
82 if ( m_ownsImageList
)
87 m_ownsImageList
= false;
90 m_imageList
= imageList
;
93 void wxBookCtrlBase::AssignImageList(wxImageList
* imageList
)
95 SetImageList(imageList
);
97 m_ownsImageList
= true;
100 // ----------------------------------------------------------------------------
102 // ----------------------------------------------------------------------------
104 void wxBookCtrlBase::SetPageSize(const wxSize
& size
)
106 SetClientSize(CalcSizeFromPage(size
));
109 wxSize
wxBookCtrlBase::DoGetBestSize() const
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
++ )
117 const wxWindow
* const pPage
= m_pages
[nPage
];
120 wxSize
childBestSize(pPage
->GetBestSize());
122 if ( childBestSize
.x
> bestSize
.x
)
123 bestSize
.x
= childBestSize
.x
;
125 if ( childBestSize
.y
> bestSize
.y
)
126 bestSize
.y
= childBestSize
.y
;
130 // convert display area to window area, adding the size necessary for the
132 wxSize best
= CalcSizeFromPage(bestSize
);
137 // ----------------------------------------------------------------------------
139 // ----------------------------------------------------------------------------
142 wxBookCtrlBase::InsertPage(size_t nPage
,
144 const wxString
& WXUNUSED(text
),
145 bool WXUNUSED(bSelect
),
146 int WXUNUSED(imageId
))
148 wxCHECK_MSG( page
|| AllowNullPage(), false, _T("NULL page in wxBookCtrlBase::InsertPage()") );
149 wxCHECK_MSG( nPage
<= m_pages
.size(), false,
150 _T("invalid page index in wxBookCtrlBase::InsertPage()") );
152 m_pages
.Insert(page
, nPage
);
153 InvalidateBestSize();
158 bool wxBookCtrlBase::DeletePage(size_t nPage
)
160 wxWindow
*page
= DoRemovePage(nPage
);
161 if ( !(page
|| AllowNullPage()) )
164 // delete NULL is harmless
170 wxWindow
*wxBookCtrlBase::DoRemovePage(size_t nPage
)
172 wxCHECK_MSG( nPage
< m_pages
.size(), NULL
,
173 _T("invalid page index in wxBookCtrlBase::DoRemovePage()") );
175 wxWindow
*pageRemoved
= m_pages
[nPage
];
176 m_pages
.RemoveAt(nPage
);
177 InvalidateBestSize();
182 int wxBookCtrlBase::GetNextPage(bool forward
) const
186 int nMax
= GetPageCount();
187 if ( nMax
-- ) // decrement it to get the last valid index
189 int nSel
= GetSelection();
191 // change selection wrapping if it becomes invalid
192 nPage
= forward
? nSel
== nMax
? 0
197 else // notebook is empty, no next page
205 #endif // wxUSE_BOOKCTRL