]>
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 #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 wxBookCtrlBase::Init()
48 m_ownsImageList
= false;
52 wxBookCtrlBase::Create(wxWindow
*parent
,
59 return wxControl::Create
71 wxBookCtrlBase::~wxBookCtrlBase()
73 if ( m_ownsImageList
)
80 // ----------------------------------------------------------------------------
82 // ----------------------------------------------------------------------------
84 void wxBookCtrlBase::SetImageList(wxImageList
*imageList
)
86 if ( m_ownsImageList
)
91 m_ownsImageList
= false;
94 m_imageList
= imageList
;
97 void wxBookCtrlBase::AssignImageList(wxImageList
* imageList
)
99 SetImageList(imageList
);
101 m_ownsImageList
= true;
104 // ----------------------------------------------------------------------------
106 // ----------------------------------------------------------------------------
108 void wxBookCtrlBase::SetPageSize(const wxSize
& size
)
110 SetClientSize(CalcSizeFromPage(size
));
113 wxSize
wxBookCtrlBase::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 necessary for the
133 wxSize best
= CalcSizeFromPage(bestSize
);
138 // ----------------------------------------------------------------------------
140 // ----------------------------------------------------------------------------
143 wxBookCtrlBase::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 wxBookCtrlBase::InsertPage()") );
150 wxCHECK_MSG( nPage
<= m_pages
.size(), false,
151 _T("invalid page index in wxBookCtrlBase::InsertPage()") );
153 m_pages
.Insert(page
, nPage
);
154 InvalidateBestSize();
159 bool wxBookCtrlBase::DeletePage(size_t nPage
)
161 wxWindow
*page
= DoRemovePage(nPage
);
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