]>
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;
49 // Unlike most controls, we don't want to adjust the min size
50 // when we set the font, since the page size is not related to
52 m_adjustMinSize
= false;
56 wxBookCtrl::Create(wxWindow
*parent
,
63 return wxControl::Create
75 wxBookCtrl::~wxBookCtrl()
77 if ( m_ownsImageList
)
84 // ----------------------------------------------------------------------------
86 // ----------------------------------------------------------------------------
88 void wxBookCtrl::SetImageList(wxImageList
*imageList
)
90 if ( m_ownsImageList
)
95 m_ownsImageList
= false;
98 m_imageList
= imageList
;
101 void wxBookCtrl::AssignImageList(wxImageList
* imageList
)
103 SetImageList(imageList
);
105 m_ownsImageList
= true;
108 // ----------------------------------------------------------------------------
110 // ----------------------------------------------------------------------------
112 void wxBookCtrl::SetPageSize(const wxSize
& size
)
114 SetClientSize(CalcSizeFromPage(size
));
117 wxSize
wxBookCtrl::DoGetBestSize() const
121 // iterate over all pages, get the largest width and height
122 const size_t nCount
= m_pages
.size();
123 for ( size_t nPage
= 0; nPage
< nCount
; nPage
++ )
125 wxWindow
*pPage
= m_pages
[nPage
];
126 wxSize
childBestSize(pPage
->GetBestSize());
128 if ( childBestSize
.x
> bestSize
.x
)
129 bestSize
.x
= childBestSize
.x
;
131 if ( childBestSize
.y
> bestSize
.y
)
132 bestSize
.y
= childBestSize
.y
;
135 // convert display area to window area, adding the size neccessary for the
137 return CalcSizeFromPage(bestSize
);
140 // ----------------------------------------------------------------------------
142 // ----------------------------------------------------------------------------
145 wxBookCtrl::InsertPage(size_t nPage
,
147 const wxString
& WXUNUSED(text
),
148 bool WXUNUSED(bSelect
),
149 int WXUNUSED(imageId
))
151 wxCHECK_MSG( page
, false, _T("NULL page in wxBookCtrl::InsertPage()") );
152 wxCHECK_MSG( nPage
<= m_pages
.size(), false,
153 _T("invalid page index in wxBookCtrl::InsertPage()") );
155 m_pages
.Insert(page
, nPage
);
160 bool wxBookCtrl::DeletePage(size_t nPage
)
162 wxWindow
*page
= DoRemovePage(nPage
);
171 wxWindow
*wxBookCtrl::DoRemovePage(size_t nPage
)
173 wxCHECK_MSG( nPage
< m_pages
.size(), NULL
,
174 _T("invalid page index in wxBookCtrl::DoRemovePage()") );
176 wxWindow
*pageRemoved
= m_pages
[nPage
];
177 m_pages
.RemoveAt(nPage
);
182 int wxBookCtrl::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