mirror of
https://github.com/wxWidgets/wxWidgets.git
synced 2026-08-17 17:02:51 +08:00
Add and use new wxCheckedStaticCast helper
This commit is contained in:
@@ -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
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user