From d3c0d0c064ee0bf31d937739f45451e5fd3cf71b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 25 Feb 2022 03:59:56 +0000 Subject: [PATCH] Move wxBookCtrlXmlHandlerBase::PageWithAttrs into the header This struct is finally going to have to be declared in the header as it will be needed by wxTreebookXmlHandler when it's modified to derive from wxBookCtrlXmlHandlerBase too. Also add GetImageId() function to the struct while moving it. --- include/wx/xrc/xh_bookctrlbase.h | 15 +++++++++++- src/xrc/xh_bookctrlbase.cpp | 41 +++++++++++--------------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/include/wx/xrc/xh_bookctrlbase.h b/include/wx/xrc/xh_bookctrlbase.h index f4dc9ae309..8784a80340 100644 --- a/include/wx/xrc/xh_bookctrlbase.h +++ b/include/wx/xrc/xh_bookctrlbase.h @@ -43,7 +43,20 @@ protected: private: // This struct contains the actual page, created by DoCreatePage(), and all // its attributes read from wxXmlNode. - struct PageWithAttrs; + struct PageWithAttrs + { + PageWithAttrs(); + + // Returns bmpId if it's valid or imgId (which can still be invalid) + // otherwise. + int GetImageId() const; + + wxWindow* wnd; + wxString label; + bool selected; + int imgId; // index in the image list + int bmpId; // index in m_bookImages vector + }; // And this vector contains all the pages created so far. wxVector m_bookPages; diff --git a/src/xrc/xh_bookctrlbase.cpp b/src/xrc/xh_bookctrlbase.cpp index 93b08132dc..4782534a4d 100644 --- a/src/xrc/xh_bookctrlbase.cpp +++ b/src/xrc/xh_bookctrlbase.cpp @@ -24,31 +24,23 @@ #include "wx/bookctrl.h" -// ---------------------------------------------------------------------------- -// private types -// ---------------------------------------------------------------------------- - -struct wxBookCtrlXmlHandlerBase::PageWithAttrs -{ - PageWithAttrs() - { - wnd = NULL; - selected = false; - imgId = - bmpId = wxWithImages::NO_IMAGE; - } - - wxWindow* wnd; - wxString label; - bool selected; - int imgId; // index in the image list - int bmpId; // index in m_bookImages vector -}; - // ============================================================================ // wxBookCtrlXmlHandlerBase implementation // ============================================================================ +wxBookCtrlXmlHandlerBase::PageWithAttrs::PageWithAttrs() +{ + wnd = NULL; + selected = false; + imgId = + bmpId = wxWithImages::NO_IMAGE; +} + +int wxBookCtrlXmlHandlerBase::PageWithAttrs::GetImageId() const +{ + return bmpId != wxWithImages::NO_IMAGE ? bmpId : imgId; +} + wxBookCtrlXmlHandlerBase::wxBookCtrlXmlHandlerBase() : m_isInside(false) { @@ -83,16 +75,11 @@ void wxBookCtrlXmlHandlerBase::DoCreatePages(wxBookCtrlBase* book) for ( size_t i = 0; i < m_bookPages.size(); ++i ) { const PageWithAttrs& currentPage = m_bookPages.at(i); - int imgId = currentPage.bmpId; - if ( imgId == -1 ) - { - imgId = currentPage.imgId; - } book->AddPage(currentPage.wnd, currentPage.label, currentPage.selected, - imgId); + currentPage.GetImageId()); } m_bookImages.swap(imagesSave);