]>
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 wxWindow
*pPage
= m_pages
[nPage
];
118 wxSize
childBestSize(pPage
->GetBestSize());
120 if ( childBestSize
.x
> bestSize
.x
)
121 bestSize
.x
= childBestSize
.x
;
123 if ( childBestSize
.y
> bestSize
.y
)
124 bestSize
.y
= childBestSize
.y
;
127 // convert display area to window area, adding the size necessary for the
129 wxSize best
= CalcSizeFromPage(bestSize
);
134 // ----------------------------------------------------------------------------
136 // ----------------------------------------------------------------------------
139 wxBookCtrlBase::InsertPage(size_t nPage
,
141 const wxString
& WXUNUSED(text
),
142 bool WXUNUSED(bSelect
),
143 int WXUNUSED(imageId
))
145 wxCHECK_MSG( page
, false, _T("NULL page in wxBookCtrlBase::InsertPage()") );
146 wxCHECK_MSG( nPage
<= m_pages
.size(), false,
147 _T("invalid page index in wxBookCtrlBase::InsertPage()") );
149 m_pages
.Insert(page
, nPage
);
150 InvalidateBestSize();
155 bool wxBookCtrlBase::DeletePage(size_t nPage
)
157 wxWindow
*page
= DoRemovePage(nPage
);
166 wxWindow
*wxBookCtrlBase::DoRemovePage(size_t nPage
)
168 wxCHECK_MSG( nPage
< m_pages
.size(), NULL
,
169 _T("invalid page index in wxBookCtrlBase::DoRemovePage()") );
171 wxWindow
*pageRemoved
= m_pages
[nPage
];
172 m_pages
.RemoveAt(nPage
);
173 InvalidateBestSize();
178 int wxBookCtrlBase::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