]>
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 void wxBookCtrl::Init()
48 m_ownsImageList
= false;
52 wxBookCtrl::Create(wxWindow
*parent
,
59 return wxControl::Create
71 wxBookCtrl::~wxBookCtrl()
73 if ( m_ownsImageList
)
80 // ----------------------------------------------------------------------------
82 // ----------------------------------------------------------------------------
84 void wxBookCtrl::SetImageList(wxImageList
*imageList
)
86 if ( m_ownsImageList
)
91 m_ownsImageList
= false;
94 m_imageList
= imageList
;
97 void wxBookCtrl::AssignImageList(wxImageList
* imageList
)
99 SetImageList(imageList
);
101 m_ownsImageList
= true;
104 // ----------------------------------------------------------------------------
106 // ----------------------------------------------------------------------------
108 void wxBookCtrl::SetPageSize(const wxSize
& size
)
110 SetClientSize(CalcSizeFromPage(size
));
113 wxSize
wxBookCtrl::DoGetBestSize() const
117 // iterate over all pages, get the largest width and height
118 const size_t nCount
= m_pages
.size();
119 for ( size_t nPage
= 0; nPage
< nCount
; nPage
++ )
121 wxWindow
*pPage
= m_pages
[nPage
];
122 wxSize
childBestSize(pPage
->GetBestSize());
124 if ( childBestSize
.x
> bestSize
.x
)
125 bestSize
.x
= childBestSize
.x
;
127 if ( childBestSize
.y
> bestSize
.y
)
128 bestSize
.y
= childBestSize
.y
;
131 // convert display area to window area, adding the size neccessary for the
133 wxSize best
= CalcSizeFromPage(bestSize
);
138 // ----------------------------------------------------------------------------
140 // ----------------------------------------------------------------------------
143 wxBookCtrl::InsertPage(size_t nPage
,
145 const wxString
& WXUNUSED(text
),
146 bool WXUNUSED(bSelect
),
147 int WXUNUSED(imageId
))
149 wxCHECK_MSG( page
, false, _T("NULL page in wxBookCtrl::InsertPage()") );
150 wxCHECK_MSG( nPage
<= m_pages
.size(), false,
151 _T("invalid page index in wxBookCtrl::InsertPage()") );
153 m_pages
.Insert(page
, nPage
);
158 bool wxBookCtrl::DeletePage(size_t nPage
)
160 wxWindow
*page
= DoRemovePage(nPage
);
169 wxWindow
*wxBookCtrl::DoRemovePage(size_t nPage
)
171 wxCHECK_MSG( nPage
< m_pages
.size(), NULL
,
172 _T("invalid page index in wxBookCtrl::DoRemovePage()") );
174 wxWindow
*pageRemoved
= m_pages
[nPage
];
175 m_pages
.RemoveAt(nPage
);
180 int wxBookCtrl::GetNextPage(bool forward
) const
184 int nMax
= GetPageCount();
185 if ( nMax
-- ) // decrement it to get the last valid index
187 int nSel
= GetSelection();
189 // change selection wrapping if it becomes invalid
190 nPage
= forward
? nSel
== nMax
? 0
195 else // notebook is empty, no next page
203 #endif // wxUSE_BOOKCTRL