Stop using wxList in wxGTK wxNotebook

Use a vector of objects instead.
This commit is contained in:
Vadim Zeitlin 2023-04-12 00:39:06 +02:00
parent bd3ed34736
commit c237d9ee49
2 changed files with 12 additions and 18 deletions

View file

@ -10,14 +10,13 @@
#ifndef _WX_GTKNOTEBOOK_H_
#define _WX_GTKNOTEBOOK_H_
#include <vector>
//-----------------------------------------------------------------------------
// internal class
//-----------------------------------------------------------------------------
class WXDLLIMPEXP_FWD_CORE wxGtkNotebookPage;
#include "wx/list.h"
WX_DECLARE_LIST(wxGtkNotebookPage, wxGtkNotebookPagesList);
class wxGtkNotebookPage;
//-----------------------------------------------------------------------------
// wxNotebook
@ -112,9 +111,6 @@ public:
// helper function
wxGtkNotebookPage* GetNotebookPage(int page) const;
// the additional page data (the pages themselves are in m_pages array)
wxGtkNotebookPagesList m_pagesData;
// we need to store the old selection since there
// is no other way to know about it at the time
// of the change selection event
@ -134,6 +130,9 @@ private:
// the padding set by SetPadding()
int m_padding;
// the additional page data (the pages themselves are in m_pages array)
std::vector<wxGtkNotebookPage> m_pagesData;
void Init();
virtual void AddChildGTK(wxWindowGTK* child) override;

View file

@ -40,7 +40,7 @@
// class which explains it but it still would be nice to do something
// about this one day
class wxGtkNotebookPage: public wxObject
class wxGtkNotebookPage
{
public:
GtkWidget* m_box;
@ -50,9 +50,6 @@ public:
};
#include "wx/listimpl.cpp"
WX_DEFINE_LIST(wxGtkNotebookPagesList)
extern "C" {
static void event_after(GtkNotebook*, GdkEvent*, wxNotebook*);
}
@ -231,7 +228,7 @@ int wxNotebook::GetPageImage( size_t page ) const
wxGtkNotebookPage* wxNotebook::GetNotebookPage( int page ) const
{
return m_pagesData.Item(page)->GetData();
return const_cast<wxGtkNotebookPage*>(&m_pagesData.at(page));
}
int wxNotebook::DoSetSelection( size_t page, int flags )
@ -445,9 +442,7 @@ wxNotebookPage *wxNotebook::DoRemovePage( size_t page )
wxASSERT_MSG(GetPage(page) == client, wxT("pages changed during delete"));
wxNotebookBase::DoRemovePage(page);
wxGtkNotebookPage* p = GetNotebookPage(page);
m_pagesData.DeleteObject(p);
delete p;
m_pagesData.erase(m_pagesData.begin() + page);
return client;
}
@ -475,10 +470,10 @@ bool wxNotebook::InsertPage( size_t position,
GtkNotebook *notebook = GTK_NOTEBOOK(m_widget);
wxGtkNotebookPage* pageData = new wxGtkNotebookPage;
m_pages.insert(m_pages.begin() + position, win);
m_pagesData.Insert(position, pageData);
m_pagesData.insert(m_pagesData.begin() + position, wxGtkNotebookPage());
wxGtkNotebookPage* const pageData = &m_pagesData[position];
// set the label image and text
// this must be done before adding the page, as GetPageText