]>
git.saurik.com Git - wxWidgets.git/blob - src/common/bookctrl.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: common/bookctrl.cpp
3 // Purpose: wxBookCtrl implementation
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "bookctrl.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
33 #include "wx/imaglist.h"
35 #include "wx/bookctrl.h"
37 // ============================================================================
39 // ============================================================================
41 // ----------------------------------------------------------------------------
42 // constructors and destructors
43 // ----------------------------------------------------------------------------
45 wxBookCtrl::wxBookCtrl()
50 wxBookCtrl::wxBookCtrl(wxWindow
*parent
,
59 (void)Create(parent
, id
, pos
, size
, style
, name
);
62 void wxBookCtrl::Init()
65 m_ownsImageList
= false;
69 wxBookCtrl::Create(wxWindow
*parent
,
76 return wxControl::Create
88 wxBookCtrl::~wxBookCtrl()
90 if ( m_ownsImageList
)
97 // ----------------------------------------------------------------------------
99 // ----------------------------------------------------------------------------
101 void wxBookCtrl::SetImageList(wxImageList
*imageList
)
103 if ( m_ownsImageList
)
108 m_ownsImageList
= false;
111 m_imageList
= imageList
;
114 void wxBookCtrl::AssignImageList(wxImageList
* imageList
)
116 SetImageList(imageList
);
118 m_ownsImageList
= true;
121 // ----------------------------------------------------------------------------
123 // ----------------------------------------------------------------------------
125 void wxBookCtrl::SetPageSize(const wxSize
& size
)
127 SetClientSize(CalcSizeFromPage(size
));
130 wxSize
wxBookCtrl::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 wxWindow
*pPage
= m_pages
[nPage
];
139 wxSize
childBestSize(pPage
->GetBestSize());
141 if ( childBestSize
.x
> bestSize
.x
)
142 bestSize
.x
= childBestSize
.x
;
144 if ( childBestSize
.y
> bestSize
.y
)
145 bestSize
.y
= childBestSize
.y
;
148 // convert display area to window area, adding the size neccessary for the
150 return CalcSizeFromPage(bestSize
);
153 // ----------------------------------------------------------------------------
155 // ----------------------------------------------------------------------------
158 wxBookCtrl::InsertPage(size_t nPage
,
160 const wxString
& WXUNUSED(text
),
161 bool WXUNUSED(bSelect
),
162 int WXUNUSED(imageId
))
164 wxCHECK_MSG( page
, false, _T("NULL page in wxBookCtrl::InsertPage()") );
165 wxCHECK_MSG( nPage
<= m_pages
.size(), false,
166 _T("invalid page index in wxBookCtrl::InsertPage()") );
168 m_pages
.Insert(page
, nPage
);
173 bool wxBookCtrl::DeletePage(size_t nPage
)
175 wxWindow
*page
= DoRemovePage(nPage
);
184 wxWindow
*wxBookCtrl::DoRemovePage(size_t nPage
)
186 wxCHECK_MSG( nPage
< m_pages
.size(), NULL
,
187 _T("invalid page index in wxBookCtrl::DoRemovePage()") );
189 wxWindow
*pageRemoved
= m_pages
[nPage
];
190 m_pages
.RemoveAt(nPage
);
195 int wxBookCtrl::GetNextPage(bool forward
) const
199 int nMax
= GetPageCount();
200 if ( nMax
-- ) // decrement it to get the last valid index
202 int nSel
= GetSelection();
204 // change selection wrapping if it becomes invalid
205 nPage
= forward
? nSel
== nMax
? 0
210 else // notebook is empty, no next page
218 #endif // wxUSE_BOOKCTRL