Add virtual wxBookCtrlXmlHandlerBase::DoAddPage()

This will allow customizing the way pages are added to the book control
and will also be used in wxTreebookXmlHandler soon.
This commit is contained in:
Vadim Zeitlin 2022-02-25 04:03:58 +00:00
parent d3c0d0c064
commit 2e27c12e56
2 changed files with 17 additions and 7 deletions

View file

@ -40,7 +40,6 @@ protected:
// Return true if we're parsing the book control node itself.
bool IsInside() const { return m_isInside; }
private:
// This struct contains the actual page, created by DoCreatePage(), and all
// its attributes read from wxXmlNode.
struct PageWithAttrs
@ -58,6 +57,14 @@ private:
int bmpId; // index in m_bookImages vector
};
private:
// This function is implemented by just calling AddPage() in the base
// class, but can be overridden if something else is needed, as is e.g. the
// case for wxTreebookXmlHandler.
virtual void
DoAddPage(wxBookCtrlBase* book, size_t n, const PageWithAttrs& page);
// And this vector contains all the pages created so far.
wxVector<PageWithAttrs> m_bookPages;

View file

@ -52,6 +52,14 @@ wxBookCtrlXmlHandlerBase::~wxBookCtrlXmlHandlerBase()
// PageWithAttrs which is not fully declared in the header.
}
void
wxBookCtrlXmlHandlerBase::DoAddPage(wxBookCtrlBase* book,
size_t WXUNUSED(n),
const PageWithAttrs& page)
{
book->AddPage(page.wnd, page.label, page.selected, page.GetImageId());
}
void wxBookCtrlXmlHandlerBase::DoCreatePages(wxBookCtrlBase* book)
{
bool old_ins = m_isInside;
@ -74,12 +82,7 @@ void wxBookCtrlXmlHandlerBase::DoCreatePages(wxBookCtrlBase* book)
for ( size_t i = 0; i < m_bookPages.size(); ++i )
{
const PageWithAttrs& currentPage = m_bookPages.at(i);
book->AddPage(currentPage.wnd,
currentPage.label,
currentPage.selected,
currentPage.GetImageId());
DoAddPage(book, i, m_bookPages[i]);
}
m_bookImages.swap(imagesSave);