Change wxSizer::Detach(wxWindow*) to take wxWindowBase* instead

This function is called from wxWindowBase dtor to detach the window
being destroyed from the containing sizer and casting the pointer to the
object to wxWindow is UB because the object is not actually a wxWindow
any more by then.

Remove the cast and pass wxWindowBase pointer to wxSizer::Detach()
instead, as it doesn't need the full wxWindow anyhow.

Also document that any wxSizer-derived classes overriding Detach() will
need to be modified to follow this change.
This commit is contained in:
Vadim Zeitlin
2024-10-21 21:23:07 +02:00
parent a0cf2f4b6c
commit f6b4acf283
4 changed files with 10 additions and 5 deletions
+5
View File
@@ -186,6 +186,11 @@ Changes in behaviour which may result in build errors
override these functions must be updated to use the new argument type too.
Simply replacing wxDC with wxReadOnlyDC should be sufficient.
- wxSizer::Detach() takes wxWindowBase pointer now instead of wxWindow.
This only matters if you override this virtual function in your own classes
deriving from wxSizer, please change the function in the derived class to
take wxWindowBase pointer too in this case.
3.3.0: (released 2022-??-??)
----------------------------
+2 -2
View File
@@ -613,7 +613,7 @@ public:
virtual bool Remove( wxSizer *sizer );
virtual bool Remove( int index );
virtual bool Detach( wxWindow *window );
virtual bool Detach( wxWindowBase *window );
virtual bool Detach( wxSizer *sizer );
virtual bool Detach( int index );
@@ -1070,7 +1070,7 @@ public:
virtual void ShowItems (bool show) override;
virtual bool AreAnyItemsShown() const override;
virtual bool Detach( wxWindow *window ) override;
virtual bool Detach( wxWindowBase *window ) override;
virtual bool Detach( wxSizer *sizer ) override { return wxBoxSizer::Detach(sizer); }
virtual bool Detach( int index ) override { return wxBoxSizer::Detach(index); }
+2 -2
View File
@@ -964,7 +964,7 @@ bool wxSizer::Detach( wxSizer *sizer )
return false;
}
bool wxSizer::Detach( wxWindow *window )
bool wxSizer::Detach( wxWindowBase *window )
{
wxASSERT_MSG( window, wxT("Detaching null window") );
@@ -2901,7 +2901,7 @@ bool wxStaticBoxSizer::AreAnyItemsShown() const
return m_staticBox->IsShown();
}
bool wxStaticBoxSizer::Detach( wxWindow *window )
bool wxStaticBoxSizer::Detach( wxWindowBase *window )
{
// avoid deleting m_staticBox in our dtor if it's being detached from the
// sizer (which can happen because it's being already destroyed for
+1 -1
View File
@@ -506,7 +506,7 @@ wxWindowBase::~wxWindowBase()
#endif // wxUSE_CONSTRAINTS
if ( m_containingSizer )
m_containingSizer->Detach( (wxWindow*)this );
m_containingSizer->Detach(this);
delete m_windowSizer;