]>
git.saurik.com Git - wxWidgets.git/blob - src/common/bookctrl.cpp
b04136183e26f69943df4b3cc2a638dd66e55c05
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 return CalcSizeFromPage(bestSize
);
136 // ----------------------------------------------------------------------------
138 // ----------------------------------------------------------------------------
141 wxBookCtrl::InsertPage(size_t nPage
,
143 const wxString
& WXUNUSED(text
),
144 bool WXUNUSED(bSelect
),
145 int WXUNUSED(imageId
))
147 wxCHECK_MSG( page
, false, _T("NULL page in wxBookCtrl::InsertPage()") );
148 wxCHECK_MSG( nPage
<= m_pages
.size(), false,
149 _T("invalid page index in wxBookCtrl::InsertPage()") );
151 m_pages
.Insert(page
, nPage
);
156 bool wxBookCtrl::DeletePage(size_t nPage
)
158 wxWindow
*page
= DoRemovePage(nPage
);
167 wxWindow
*wxBookCtrl::DoRemovePage(size_t nPage
)
169 wxCHECK_MSG( nPage
< m_pages
.size(), NULL
,
170 _T("invalid page index in wxBookCtrl::DoRemovePage()") );
172 wxWindow
*pageRemoved
= m_pages
[nPage
];
173 m_pages
.RemoveAt(nPage
);
178 int wxBookCtrl::GetNextPage(bool forward
) const
182 int nMax
= GetPageCount();
183 if ( nMax
-- ) // decrement it to get the last valid index
185 int nSel
= GetSelection();
187 // change selection wrapping if it becomes invalid
188 nPage
= forward
? nSel
== nMax
? 0
193 else // notebook is empty, no next page
201 #endif // wxUSE_BOOKCTRL