From 5725f0be4151f7ac3086e0535750c1114dbb8daa Mon Sep 17 00:00:00 2001 From: Artur Wieczorek <7330332+a-wi@users.noreply.github.com> Date: Sat, 23 Dec 2023 22:23:10 +0100 Subject: [PATCH] Replace macro with inline function in wxPGPropertyGridIterator-related code Replace wxPG_ITERATOR_CREATE_MASKS macro with inline function to ensure type safety. --- include/wx/propgrid/propgridpagestate.h | 19 ++++++++++++++----- src/propgrid/propgridpagestate.cpp | 6 ++++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/include/wx/propgrid/propgridpagestate.h b/include/wx/propgrid/propgridpagestate.h index da63e0d754..7c0576543c 100644 --- a/include/wx/propgrid/propgridpagestate.h +++ b/include/wx/propgrid/propgridpagestate.h @@ -276,12 +276,21 @@ wxPG_ITERATE_DEFAULT = wxPG_ITERATE_NORMAL }; - -#define wxPG_ITERATOR_CREATE_MASKS(FLAGS, A, B) \ - A = static_cast((FLAGS ^ wxPG_ITERATOR_MASK_OP_ITEM) & \ - wxPG_ITERATOR_MASK_OP_ITEM & 0xFFFF); \ - B = static_cast(((FLAGS>>16) ^ wxPG_ITERATOR_MASK_OP_PARENT) & \ +inline void wxPGCreateIteratorMasks(int flags, wxPGPropertyFlags& itemExMask, wxPGPropertyFlags& parentExMask) +{ + itemExMask = static_cast((flags ^ wxPG_ITERATOR_MASK_OP_ITEM) & + wxPG_ITERATOR_MASK_OP_ITEM & 0xFFFF); + parentExMask = static_cast(((flags >> 16) ^ wxPG_ITERATOR_MASK_OP_PARENT) & wxPG_ITERATOR_MASK_OP_PARENT & 0xFFFF); +} + +#if WXWIN_COMPATIBILITY_3_2 +#ifdef wxPG_MUST_DEPRECATE_MACRO_NAME +#pragma deprecated(wxPG_ITERATOR_CREATE_MASKS) +#endif +#define wxPG_ITERATOR_CREATE_MASKS wxPG_DEPRECATED_MACRO_VALUE(wxPGCreateIteratorMasks,\ + "wxPG_ITERATOR_CREATE_MASKS is deprecated. Call wxPGCreateIteratorMasks instead.") +#endif // WXWIN_COMPATIBILITY_3_2 // Base for wxPropertyGridIterator classes. class WXDLLIMPEXP_PROPGRID wxPropertyGridIteratorBase diff --git a/src/propgrid/propgridpagestate.cpp b/src/propgrid/propgridpagestate.cpp index 27b93ffdca..c45c1b1e65 100644 --- a/src/propgrid/propgridpagestate.cpp +++ b/src/propgrid/propgridpagestate.cpp @@ -47,7 +47,7 @@ void wxPropertyGridIteratorBase::Init( wxPropertyGridPageState* state, int flags m_property = property; - wxPG_ITERATOR_CREATE_MASKS(flags, m_itemExMask, m_parentExMask) + wxPGCreateIteratorMasks(flags, m_itemExMask, m_parentExMask); // Need to skip first? if ( property && property->HasFlag(m_itemExMask) ) @@ -401,7 +401,9 @@ wxPGProperty* wxPropertyGridPageState::GetLastItem( int flags ) if ( !m_properties->HasAnyChild() ) return nullptr; - wxPG_ITERATOR_CREATE_MASKS(flags, wxPGPropertyFlags itemExMask, wxPGPropertyFlags parentExMask) + wxPGPropertyFlags itemExMask; + wxPGPropertyFlags parentExMask; + wxPGCreateIteratorMasks(flags, itemExMask, parentExMask); // First, get last child of last parent if children of 'pwc' should be iterated through wxPGProperty* pwc = m_properties->Last();