From e631e7da627936c8099d1032bbe9a2e0046082a7 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 10 Jul 2021 22:32:24 +0100 Subject: [PATCH] Avoid using wxDynamicCast() with wxComboCtrl-derived object In wxUniv wxComboBox does derive from wxComboCtrl, but its wxRTTI doesn't use wxComboCtrl as the base class for consistency with the other ports, meaning that wxDynamicCast() to wxComboCtrl fails. Avoid this problem by storing wxComboCtrl in wxComboPopupWindow, as then we can just use it later without any casts -- at the price of storing an extra pointer in a transient object, i.e. without any real cost. See https://github.com/wxWidgets/wxWidgets/pull/2418 --- src/common/combocmn.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/common/combocmn.cpp b/src/common/combocmn.cpp index 9da9bee49f..5b9bf49c40 100644 --- a/src/common/combocmn.cpp +++ b/src/common/combocmn.cpp @@ -339,6 +339,7 @@ public: wxSize(20,20), style) #endif + , m_combo(parent) { m_inShow = 0; } @@ -351,7 +352,13 @@ protected: #endif private: + // This is the same as our parent, but has the right type, so that we can + // avoid using casts later. + wxComboCtrlBase* const m_combo; + wxByte m_inShow; + + wxDECLARE_NO_COPY_CLASS(wxComboPopupWindow); }; @@ -391,11 +398,7 @@ bool wxComboPopupWindow::ProcessLeftDown(wxMouseEvent& event) // First thing that happens when a transient popup closes is that this method gets called. void wxComboPopupWindow::OnDismiss() { - wxComboCtrlBase* combo = (wxComboCtrlBase*) GetParent(); - wxASSERT_MSG( wxDynamicCast(combo, wxComboCtrlBase), - wxT("parent might not be wxComboCtrl, but check wxIMPLEMENT_DYNAMIC_CLASS2() macro for correctness") ); - - combo->OnPopupDismiss(true); + m_combo->OnPopupDismiss(true); } #endif // wxUSE_POPUPWIN