XRC: use wxBitmapBundle in wxBookCtrl-related controls.

This commit is contained in:
Alexander Koshelev
2022-02-22 13:50:20 +01:00
committed by Vadim Zeitlin
parent ca1eefdba2
commit 93b4478992
10 changed files with 125 additions and 48 deletions

View File

@@ -27,6 +27,8 @@ public:
private:
bool m_isInside;
wxChoicebook *m_choicebook;
wxVector<wxBitmapBundle> m_bookImages;
wxVector<size_t> m_bookImagesIdx;
};
#endif // wxUSE_XRC && wxUSE_CHOICEBOOK

View File

@@ -27,6 +27,8 @@ public:
private:
bool m_isInside;
wxListbook *m_listbook;
wxVector<wxBitmapBundle> m_bookImages;
wxVector<size_t> m_bookImagesIdx;
};
#endif // wxUSE_XRC && wxUSE_LISTBOOK

View File

@@ -27,6 +27,8 @@ public:
private:
bool m_isInside;
wxNotebook *m_notebook;
wxVector<wxBitmapBundle> m_bookImages;
wxVector<size_t> m_bookImagesIdx;
};
#endif // wxUSE_XRC && wxUSE_NOTEBOOK

View File

@@ -28,6 +28,8 @@ public:
private:
bool m_isInside;
wxPropertySheetDialog *m_dialog;
wxVector<wxBitmapBundle> m_bookImages;
wxVector<size_t> m_bookImagesIdx;
};
#endif // wxUSE_XRC

View File

@@ -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<wxBitmapBundle>
};
bool m_isInside;
wxToolbook *m_toolbook;
wxVector<newPage> m_bookPages;
wxVector<wxBitmapBundle> m_bookImages;
wxDECLARE_DYNAMIC_CLASS(wxToolbookXmlHandler);
};

View File

@@ -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<wxBitmapBundle> old_images = m_bookImages;
m_bookImages.clear();
wxVector<size_t> 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;
}

View File

@@ -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<wxBitmapBundle> old_images = m_bookImages;
m_bookImages.clear();
wxVector<size_t> 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;
}

View File

@@ -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<wxBitmapBundle> old_images = m_bookImages;
m_bookImages.clear();
wxVector<size_t> 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;
}

View File

@@ -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<wxBitmapBundle> old_images = m_bookImages;
m_bookImages.clear();
wxVector<size_t> 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"));

View File

@@ -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<newPage> old_pages = m_bookPages;
m_bookPages.clear();
wxVector<wxBitmapBundle> 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;
}