From 93b4478992c827f76bb43e48026893f142b8d864 Mon Sep 17 00:00:00 2001 From: Alexander Koshelev Date: Tue, 22 Feb 2022 13:50:20 +0100 Subject: [PATCH] XRC: use wxBitmapBundle in wxBookCtrl-related controls. --- include/wx/xrc/xh_choicbk.h | 2 ++ include/wx/xrc/xh_listbk.h | 2 ++ include/wx/xrc/xh_notbk.h | 2 ++ include/wx/xrc/xh_propdlg.h | 2 ++ include/wx/xrc/xh_toolbk.h | 11 +++++++++ src/xrc/xh_choicbk.cpp | 27 ++++++++++++++-------- src/xrc/xh_listbk.cpp | 27 ++++++++++++++-------- src/xrc/xh_notbk.cpp | 27 ++++++++++++++-------- src/xrc/xh_propdlg.cpp | 28 +++++++++++++++-------- src/xrc/xh_toolbk.cpp | 45 +++++++++++++++++++++++++++---------- 10 files changed, 125 insertions(+), 48 deletions(-) diff --git a/include/wx/xrc/xh_choicbk.h b/include/wx/xrc/xh_choicbk.h index e464139c39..b383001842 100644 --- a/include/wx/xrc/xh_choicbk.h +++ b/include/wx/xrc/xh_choicbk.h @@ -27,6 +27,8 @@ public: private: bool m_isInside; wxChoicebook *m_choicebook; + wxVector m_bookImages; + wxVector m_bookImagesIdx; }; #endif // wxUSE_XRC && wxUSE_CHOICEBOOK diff --git a/include/wx/xrc/xh_listbk.h b/include/wx/xrc/xh_listbk.h index d4916cb0b5..7b99952f25 100644 --- a/include/wx/xrc/xh_listbk.h +++ b/include/wx/xrc/xh_listbk.h @@ -27,6 +27,8 @@ public: private: bool m_isInside; wxListbook *m_listbook; + wxVector m_bookImages; + wxVector m_bookImagesIdx; }; #endif // wxUSE_XRC && wxUSE_LISTBOOK diff --git a/include/wx/xrc/xh_notbk.h b/include/wx/xrc/xh_notbk.h index 0cd2a253f1..9ada21c1e5 100644 --- a/include/wx/xrc/xh_notbk.h +++ b/include/wx/xrc/xh_notbk.h @@ -27,6 +27,8 @@ public: private: bool m_isInside; wxNotebook *m_notebook; + wxVector m_bookImages; + wxVector m_bookImagesIdx; }; #endif // wxUSE_XRC && wxUSE_NOTEBOOK diff --git a/include/wx/xrc/xh_propdlg.h b/include/wx/xrc/xh_propdlg.h index b4e742e9e9..5d3a16c7d0 100644 --- a/include/wx/xrc/xh_propdlg.h +++ b/include/wx/xrc/xh_propdlg.h @@ -28,6 +28,8 @@ public: private: bool m_isInside; wxPropertySheetDialog *m_dialog; + wxVector m_bookImages; + wxVector m_bookImagesIdx; }; #endif // wxUSE_XRC diff --git a/include/wx/xrc/xh_toolbk.h b/include/wx/xrc/xh_toolbk.h index 0d3516f93a..5d342bd6db 100644 --- a/include/wx/xrc/xh_toolbk.h +++ b/include/wx/xrc/xh_toolbk.h @@ -25,8 +25,19 @@ public: virtual bool CanHandle(wxXmlNode *node) wxOVERRIDE; private: + struct newPage + { + wxWindow* wnd; + wxString label; + bool selected; + int imgId; // index in image list + int bmpId; // index in wxVector + }; + bool m_isInside; wxToolbook *m_toolbook; + wxVector m_bookPages; + wxVector m_bookImages; wxDECLARE_DYNAMIC_CLASS(wxToolbookXmlHandler); }; diff --git a/src/xrc/xh_choicbk.cpp b/src/xrc/xh_choicbk.cpp index 63098db231..c19b32f64e 100644 --- a/src/xrc/xh_choicbk.cpp +++ b/src/xrc/xh_choicbk.cpp @@ -68,15 +68,8 @@ wxObject *wxChoicebookXmlHandler::DoCreateResource() GetBool(wxT("selected"))); if ( HasParam(wxT("bitmap")) ) { - wxBitmap bmp = GetBitmap(wxT("bitmap"), wxART_OTHER); - wxImageList *imgList = m_choicebook->GetImageList(); - if ( imgList == NULL ) - { - imgList = new wxImageList( bmp.GetWidth(), bmp.GetHeight() ); - m_choicebook->AssignImageList( imgList ); - } - int imgIndex = imgList->Add(bmp); - m_choicebook->SetPageImage(m_choicebook->GetPageCount()-1, imgIndex ); + m_bookImages.push_back( GetBitmapBundle(wxT("bitmap"), wxART_OTHER) ); + m_bookImagesIdx.push_back( m_choicebook->GetPageCount()-1 ); } else if ( HasParam(wxT("image")) ) { @@ -123,9 +116,25 @@ wxObject *wxChoicebookXmlHandler::DoCreateResource() m_choicebook = nb; bool old_ins = m_isInside; m_isInside = true; + wxVector old_images = m_bookImages; + m_bookImages.clear(); + wxVector old_imageIdx = m_bookImagesIdx; + m_bookImagesIdx.clear(); CreateChildren(m_choicebook, true/*only this handler*/); + + if ( !m_bookImages.empty() ) + { + m_choicebook->SetImages(m_bookImages); + for ( size_t i = 0; i < m_bookImagesIdx.size(); ++i ) + { + m_choicebook->SetPageImage( m_bookImagesIdx[i], i ); + } + } + m_isInside = old_ins; m_choicebook = old_par; + m_bookImages = old_images; + m_bookImagesIdx = old_imageIdx; return nb; } diff --git a/src/xrc/xh_listbk.cpp b/src/xrc/xh_listbk.cpp index 625246d05a..f275bd6322 100644 --- a/src/xrc/xh_listbk.cpp +++ b/src/xrc/xh_listbk.cpp @@ -68,15 +68,8 @@ wxObject *wxListbookXmlHandler::DoCreateResource() GetBool(wxT("selected"))); if ( HasParam(wxT("bitmap")) ) { - wxBitmap bmp = GetBitmap(wxT("bitmap"), wxART_OTHER); - wxImageList *imgList = m_listbook->GetImageList(); - if ( imgList == NULL ) - { - imgList = new wxImageList( bmp.GetWidth(), bmp.GetHeight() ); - m_listbook->AssignImageList( imgList ); - } - int imgIndex = imgList->Add(bmp); - m_listbook->SetPageImage(m_listbook->GetPageCount()-1, imgIndex ); + m_bookImages.push_back( GetBitmapBundle(wxT("bitmap"), wxART_OTHER) ); + m_bookImagesIdx.push_back( m_listbook->GetPageCount()-1 ); } else if ( HasParam(wxT("image")) ) { @@ -123,9 +116,25 @@ wxObject *wxListbookXmlHandler::DoCreateResource() m_listbook = nb; bool old_ins = m_isInside; m_isInside = true; + wxVector old_images = m_bookImages; + m_bookImages.clear(); + wxVector old_imageIdx = m_bookImagesIdx; + m_bookImagesIdx.clear(); CreateChildren(m_listbook, true/*only this handler*/); + + if ( !m_bookImages.empty() ) + { + m_listbook->SetImages(m_bookImages); + for ( size_t i = 0; i < m_bookImagesIdx.size(); ++i ) + { + m_listbook->SetPageImage( m_bookImagesIdx[i], i ); + } + } + m_isInside = old_ins; m_listbook = old_par; + m_bookImages = old_images; + m_bookImagesIdx = old_imageIdx; return nb; } diff --git a/src/xrc/xh_notbk.cpp b/src/xrc/xh_notbk.cpp index 27bef14034..bf0be8aecc 100644 --- a/src/xrc/xh_notbk.cpp +++ b/src/xrc/xh_notbk.cpp @@ -73,15 +73,8 @@ wxObject *wxNotebookXmlHandler::DoCreateResource() GetBool(wxT("selected"))); if ( HasParam(wxT("bitmap")) ) { - wxBitmap bmp = GetBitmap(wxT("bitmap"), wxART_OTHER); - wxImageList *imgList = m_notebook->GetImageList(); - if ( imgList == NULL ) - { - imgList = new wxImageList( bmp.GetWidth(), bmp.GetHeight() ); - m_notebook->AssignImageList( imgList ); - } - int imgIndex = imgList->Add(bmp); - m_notebook->SetPageImage(m_notebook->GetPageCount()-1, imgIndex ); + m_bookImages.push_back( GetBitmapBundle(wxT("bitmap"), wxART_OTHER) ); + m_bookImagesIdx.push_back( m_notebook->GetPageCount()-1 ); } else if ( HasParam(wxT("image")) ) { @@ -130,9 +123,25 @@ wxObject *wxNotebookXmlHandler::DoCreateResource() m_notebook = nb; bool old_ins = m_isInside; m_isInside = true; + wxVector old_images = m_bookImages; + m_bookImages.clear(); + wxVector old_imageIdx = m_bookImagesIdx; + m_bookImagesIdx.clear(); CreateChildren(m_notebook, true/*only this handler*/); + + if ( !m_bookImages.empty() ) + { + m_notebook->SetImages(m_bookImages); + for ( size_t i = 0; i < m_bookImagesIdx.size(); ++i ) + { + m_notebook->SetPageImage( m_bookImagesIdx[i], i ); + } + } + m_isInside = old_ins; m_notebook = old_par; + m_bookImages = old_images; + m_bookImagesIdx = old_imageIdx; return nb; } diff --git a/src/xrc/xh_propdlg.cpp b/src/xrc/xh_propdlg.cpp index 2d4630ef9c..cefaff8fbc 100644 --- a/src/xrc/xh_propdlg.cpp +++ b/src/xrc/xh_propdlg.cpp @@ -73,15 +73,8 @@ wxObject *wxPropertySheetDialogXmlHandler::DoCreateResource() bookctrl->AddPage(wnd, GetText(wxT("label")), GetBool(wxT("selected"))); if (HasParam(wxT("bitmap"))) { - wxBitmap bmp = GetBitmap(wxT("bitmap"), wxART_OTHER); - wxImageList *imgList = bookctrl->GetImageList(); - if (imgList == NULL) - { - imgList = new wxImageList(bmp.GetWidth(), bmp.GetHeight()); - bookctrl->AssignImageList(imgList); - } - int imgIndex = imgList->Add(bmp); - bookctrl->SetPageImage(bookctrl->GetPageCount()-1, imgIndex); + m_bookImages.push_back( GetBitmapBundle(wxT("bitmap"), wxART_OTHER) ); + m_bookImagesIdx.push_back( bookctrl->GetPageCount()-1 ); } } else @@ -118,9 +111,26 @@ wxObject *wxPropertySheetDialogXmlHandler::DoCreateResource() m_dialog = dlg; bool old_ins = m_isInside; m_isInside = true; + wxVector old_images = m_bookImages; + m_bookImages.clear(); + wxVector old_imageIdx = m_bookImagesIdx; + m_bookImagesIdx.clear(); CreateChildren(m_dialog, true/*only this handler*/); + + wxBookCtrlBase *bookctrl = m_dialog->GetBookCtrl(); + if ( !m_bookImages.empty() ) + { + bookctrl->SetImages(m_bookImages); + for ( size_t i = 0; i < m_bookImagesIdx.size(); ++i ) + { + bookctrl->SetPageImage( m_bookImagesIdx[i], i ); + } + } + m_isInside = old_ins; m_dialog = old_par; + m_bookImages = old_images; + m_bookImagesIdx = old_imageIdx; if (GetBool(wxT("centered"), false)) dlg->Centre(); wxString buttons = GetText(wxT("buttons")); diff --git a/src/xrc/xh_toolbk.cpp b/src/xrc/xh_toolbk.cpp index beeda073c2..d8ae013fca 100644 --- a/src/xrc/xh_toolbk.cpp +++ b/src/xrc/xh_toolbk.cpp @@ -63,24 +63,20 @@ wxObject *wxToolbookXmlHandler::DoCreateResource() if (wnd) { - int imgId = -1; + newPage currentPage; + currentPage.imgId = -1; + currentPage.bmpId = -1; if ( HasParam(wxT("bitmap")) ) { - wxBitmap bmp = GetBitmap(wxT("bitmap"), wxART_OTHER); - wxImageList *imgList = m_toolbook->GetImageList(); - if ( imgList == NULL ) - { - imgList = new wxImageList( bmp.GetWidth(), bmp.GetHeight() ); - m_toolbook->AssignImageList( imgList ); - } - imgId = imgList->Add(bmp); + m_bookImages.push_back( GetBitmapBundle(wxT("bitmap"), wxART_OTHER) ); + currentPage.bmpId = m_bookImages.size() - 1; } else if ( HasParam(wxT("image")) ) { if ( m_toolbook->GetImageList() ) { - imgId = (int)GetLong(wxT("image")); + currentPage.imgId = (int)GetLong(wxT("image")); } else // image without image list? { @@ -89,8 +85,10 @@ wxObject *wxToolbookXmlHandler::DoCreateResource() } } - m_toolbook->AddPage(wnd, GetText(wxT("label")), - GetBool(wxT("selected")), imgId ); + currentPage.wnd = wnd; + currentPage.label = GetText(wxT("label")); + currentPage.selected = GetBool(wxT("selected")); + m_bookPages.push_back(currentPage); } else { @@ -123,9 +121,32 @@ wxObject *wxToolbookXmlHandler::DoCreateResource() m_toolbook = nb; bool old_ins = m_isInside; m_isInside = true; + wxVector old_pages = m_bookPages; + m_bookPages.clear(); + wxVector old_images = m_bookImages; + m_bookImages.clear(); CreateChildren(m_toolbook, true/*only this handler*/); + + if ( !m_bookImages.empty() ) + { + m_toolbook->SetImages(m_bookImages); + } + for ( size_t i = 0; i < m_bookPages.size(); ++i ) + { + const newPage& currentPage = m_bookPages.at(i); + int imgId = currentPage.bmpId; + if ( imgId == -1 ) + { + imgId = currentPage.imgId; + } + m_toolbook->AddPage(currentPage.wnd, currentPage.label, + currentPage.selected, imgId ); + } + m_isInside = old_ins; m_toolbook = old_par; + m_bookPages = old_pages; + m_bookImages = old_images; return nb; }