tdf#145614 Convert #define to enum class and o3tl::typed_flags

Converted #define to enum class and o3tl::typed_flags to handle bitwise
operations in the code.

Added a zero flag to PortionAttribute as previous implementation was
comparing with integer value of zero.

Change-Id: I5dc1b06c4c5cb7d59f3dcf9e8b86561280974ef6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/208879
Reviewed-by: Hossein <hossein@libreoffice.org>
Tested-by: Jenkins
This commit is contained in:
ApurvR20
2026-08-26 23:26:13 +02:00
committed by Hossein
parent 9d36b250d9
commit 2c5bbfa3e6
2 changed files with 23 additions and 17 deletions
+12 -15
View File
@@ -25,6 +25,7 @@
#include <com/sun/star/i18n/Boundary.hpp>
#include <i18npool/breakiterator.hxx>
#include <txttypes.hxx>
#include <o3tl/typed_flags_set.hxx>
// for portion replacement in Special()
#include <viewopt.hxx>
@@ -43,11 +44,7 @@ using i18n::Boundary;
// 'portion type' for terminating portions
#define POR_TERMINATE PortionType::NONE
// portion attributes
#define PORATTR_SPECIAL 1
#define PORATTR_READONLY 2
#define PORATTR_GRAY 4
#define PORATTR_TERM 128
template<> struct o3tl::typed_flags<PortionAttribute> : o3tl::is_typed_flags<PortionAttribute, 135> {};
/// returns the index of the first position whose value is smaller
/// or equal, and whose following value is equal or larger
@@ -98,7 +95,7 @@ void SwAccessiblePortionData::Text(TextFrameIndex const nLength,
m_aAccessiblePositions.push_back( m_aBuffer.getLength() );
// store portion attributes
sal_uInt8 nAttr = IsGrayPortionType(nType) ? PORATTR_GRAY : 0;
PortionAttribute nAttr = IsGrayPortionType(nType) ? PortionAttribute::Gray : PortionAttribute::Zero;
m_aPortionAttrs.push_back( nAttr );
// update buffer + nViewPosition
@@ -182,10 +179,10 @@ void SwAccessiblePortionData::Special(
m_aAccessiblePositions.push_back( m_aBuffer.getLength() );
// store portion attributes
sal_uInt8 nAttr = PORATTR_SPECIAL;
if( IsGrayPortionType(nType) ) nAttr |= PORATTR_GRAY;
if (nLength == TextFrameIndex(0)) nAttr |= PORATTR_READONLY;
if( nType == POR_TERMINATE ) nAttr |= PORATTR_TERM;
PortionAttribute nAttr = PortionAttribute::Special;
if( IsGrayPortionType(nType) ) nAttr |= PortionAttribute::Gray;
if (nLength == TextFrameIndex(0)) nAttr |= PortionAttribute::Readonly;
if( nType == POR_TERMINATE ) nAttr |= PortionAttribute::Term;
m_aPortionAttrs.push_back( nAttr );
// update buffer + nViewPosition
@@ -227,16 +224,16 @@ void SwAccessiblePortionData::Finish()
}
bool SwAccessiblePortionData::IsPortionAttrSet(
size_t nPortionNo, sal_uInt8 nAttr ) const
size_t nPortionNo, PortionAttribute nAttr ) const
{
OSL_ENSURE( nPortionNo < m_aPortionAttrs.size(),
"Illegal portion number" );
return (m_aPortionAttrs[nPortionNo] & nAttr) != 0;
return (m_aPortionAttrs[nPortionNo] & nAttr) != PortionAttribute::Zero;
}
bool SwAccessiblePortionData::IsSpecialPortion( size_t nPortionNo ) const
{
return IsPortionAttrSet(nPortionNo, PORATTR_SPECIAL);
return IsPortionAttrSet(nPortionNo, PortionAttribute::Special);
}
bool SwAccessiblePortionData::IsGrayPortionType( PortionType nType ) const
@@ -679,7 +676,7 @@ bool SwAccessiblePortionData::GetEditableRange(
for( size_t nPor = nStartPortion; nPor <= nLastPortion; nPor++ )
{
bIsEditable &= ! IsPortionAttrSet(nPor, PORATTR_READONLY);
bIsEditable &= ! IsPortionAttrSet(nPor, PortionAttribute::Readonly);
}
return bIsEditable;
@@ -709,7 +706,7 @@ bool SwAccessiblePortionData::IsInGrayPortion( sal_Int32 nPos )
{
// return IsGrayPortion( FindBreak( aAccessiblePositions, nPos ) );
return IsPortionAttrSet( FindBreak( m_aAccessiblePositions, nPos ),
PORATTR_GRAY );
PortionAttribute::Gray);
}
sal_Int32 SwAccessiblePortionData::GetFieldIndex(sal_Int32 nPos) const
+11 -2
View File
@@ -33,6 +33,15 @@ namespace com::sun::star {
namespace i18n { struct Boundary; }
}
//portion attributes
enum class PortionAttribute {
Zero = 0,
Special = 1,
Readonly = 2,
Gray = 4,
Term = 128
};
/**
* collect text portion data from the layout through SwPortionHandler interface
*/
@@ -64,7 +73,7 @@ class SwAccessiblePortionData : public SwPortionHandler
AccessiblePositions m_aAccessiblePositions; /// portion breaks in m_sAccessibleString
AccessiblePositions m_aFieldPosition;
std::vector<sal_uInt8> m_aPortionAttrs; /// additional portion attributes
std::vector<PortionAttribute> m_aPortionAttrs; /// additional portion attributes
AccessiblePositions m_aSentences; /// positions of sentence breaks
@@ -77,7 +86,7 @@ class SwAccessiblePortionData : public SwPortionHandler
size_t nPos );
/// Access to portion attributes
bool IsPortionAttrSet( size_t nPortionNo, sal_uInt8 nAttr ) const;
bool IsPortionAttrSet( size_t nPortionNo, PortionAttribute nAttr ) const;
bool IsSpecialPortion( size_t nPortionNo ) const;
bool IsGrayPortionType( PortionType nType ) const;