Add and use new wxCheckedStaticCast helper

This commit is contained in:
Blake-Madden
2025-10-27 12:18:32 -04:00
parent 8a8bbbe5cf
commit fec49ff9ea
3 changed files with 15 additions and 6 deletions
+9
View File
@@ -415,6 +415,15 @@ inline wxObject *wxCheckDynamicCast(wxObject *obj, wxClassInfo *classInfo)
return obj && obj->GetClassInfo()->IsKindOf(classInfo) ? obj : nullptr;
}
// ensure that an object that should be a particular type is what it should be,
// then static cast it
template <class T>
inline T* wxCheckedStaticCast(wxObject* obj)
{
wxCHECK_MSG(wxDynamicCast(obj, T), nullptr, "Pointer of wrong type?");
return static_cast<T*>(obj);
}
#include "wx/xti2.h"
// ----------------------------------------------------------------------------
+4 -4
View File
@@ -204,8 +204,8 @@ void wxRibbonPage::CommonInit(const wxString& label, const wxBitmap& icon)
SetBackgroundStyle(wxBG_STYLE_PAINT);
wxCHECK_RET(wxDynamicCast(GetParent(), wxRibbonBar), "pointer of wrong type?");
static_cast<wxRibbonBar*>(GetParent())->AddPage(this);
if (auto* const bar = wxCheckedStaticCast<wxRibbonBar>(GetParent()))
bar->AddPage(this);
}
void wxRibbonPage::SetArtProvider(wxRibbonArtProvider* art)
@@ -1277,8 +1277,8 @@ wxSize wxRibbonPage::DoGetBestSize() const
void wxRibbonPage::HideIfExpanded()
{
wxCHECK_RET(wxDynamicCast(GetParent(), wxRibbonBar), "pointer of wrong type?");
static_cast<wxRibbonBar*>(GetParent())->HideIfExpanded();
if (auto* const bar = wxCheckedStaticCast<wxRibbonBar>(GetParent()))
bar->HideIfExpanded();
}
#endif // wxUSE_RIBBON
+2 -2
View File
@@ -1184,8 +1184,8 @@ void wxRibbonToolBar::OnMouseUp(wxMouseEvent& WXUNUSED(evt))
notification.SetBar(this);
ProcessEvent(notification);
wxCHECK_RET(wxDynamicCast(GetParent(), wxRibbonPanel), "pointer of wrong type?");
static_cast<wxRibbonPanel*>(GetParent())->HideIfExpanded();
if (auto* const panel = wxCheckedStaticCast<wxRibbonPanel>(GetParent()))
panel->HideIfExpanded();
}
// Notice that m_active_tool could have been reset by the event handler