sw/inc/fldbas.hxx | 10 ++++++---- sw/inc/flddat.hxx | 8 ++++---- sw/source/core/access/accpara.cxx | 2 +- sw/source/core/fields/fldbas.cxx | 16 ++++++++-------- sw/source/core/fields/flddat.cxx | 22 +++++++++++----------- sw/source/core/unocore/unofield.cxx | 8 ++++---- sw/source/filter/html/htmlfld.cxx | 20 ++++++++++---------- sw/source/filter/ww8/docxattributeoutput.cxx | 2 +- sw/source/filter/ww8/rtfattributeoutput.cxx | 3 ++- sw/source/filter/ww8/ww8atr.cxx | 8 ++++---- sw/source/filter/ww8/ww8par5.cxx | 4 ++-- sw/source/ui/fldui/fldpage.cxx | 7 +++++-- sw/source/uibase/fldui/fldmgr.cxx | 5 +++-- 13 files changed, 61 insertions(+), 54 deletions(-)
New commits: commit 0ab2da12fb6ea515339b113f622720b11c65afca Author: Noel Grandin <noelgran...@gmail.com> AuthorDate: Sat Jul 5 19:43:30 2025 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Wed Jul 9 13:52:20 2025 +0200 Convert SwDateTimeSubType to scoped enum Change-Id: I37570dc608046b398d9567a114149ee2c4e89763 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/187532 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sw/inc/fldbas.hxx b/sw/inc/fldbas.hxx index d0cbf509cda9..7334bce5ff90 100644 --- a/sw/inc/fldbas.hxx +++ b/sw/inc/fldbas.hxx @@ -188,11 +188,13 @@ enum SwUserType { UF_EXPR = 0x02 }; -enum SwDateTimeSubType { - FIXEDFLD = 1, - DATEFLD = 2, - TIMEFLD = 4 +enum class SwDateTimeSubType : sal_uInt16 { + None = 0, + Fixed = 1, + Date = 2, + Time = 4 }; +namespace o3tl { template<> struct typed_flags<SwDateTimeSubType> : is_typed_flags<SwDateTimeSubType, 0x0007> {}; } /// General tools. OUString FormatNumber(sal_uInt32 nNum, SvxNumType nFormat, LanguageType nLang = LANGUAGE_NONE); diff --git a/sw/inc/flddat.hxx b/sw/inc/flddat.hxx index 4b8cafdb4056..f79801af968c 100644 --- a/sw/inc/flddat.hxx +++ b/sw/inc/flddat.hxx @@ -44,18 +44,18 @@ public: class SW_DLLPUBLIC SwDateTimeField final : public SwValueField { - sal_uInt16 m_nSubType; + SwDateTimeSubType m_nSubType; tools::Long m_nOffset; // Offset in minutes. virtual OUString ExpandImpl(SwRootFrame const* pLayout) const override; virtual std::unique_ptr<SwField> Copy() const override; public: - SwDateTimeField(SwDateTimeFieldType* pType, sal_uInt16 nSubType = DATEFLD, + SwDateTimeField(SwDateTimeFieldType* pType, SwDateTimeSubType nSubType = SwDateTimeSubType::Date, sal_uLong nFormat = 0, LanguageType nLng = LANGUAGE_SYSTEM); - sal_uInt16 GetSubType() const; - void SetSubType(sal_uInt16 nSub); + SwDateTimeSubType GetSubType() const; + void SetSubType(SwDateTimeSubType nSub); virtual double GetValue() const override; diff --git a/sw/source/core/access/accpara.cxx b/sw/source/core/access/accpara.cxx index 5224d473baa0..ab90efdc0f05 100644 --- a/sw/source/core/access/accpara.cxx +++ b/sw/source/core/access/accpara.cxx @@ -1070,7 +1070,7 @@ OUString SwAccessibleParagraph::GetFieldTypeNameAtIndex(sal_Int32 nIndex) } break; case SwFieldIds::DateTime: - subType = static_cast<const SwDateTimeField*>(pField)->GetSubType(); + subType = static_cast<sal_uInt16>(static_cast<const SwDateTimeField*>(pField)->GetSubType()); break; case SwFieldIds::JumpEdit: { diff --git a/sw/source/core/fields/fldbas.cxx b/sw/source/core/fields/fldbas.cxx index a65df203158e..c3938eeb8fc6 100644 --- a/sw/source/core/fields/fldbas.cxx +++ b/sw/source/core/fields/fldbas.cxx @@ -269,11 +269,11 @@ SwFieldTypesEnum SwField::GetTypeId() const case SwFieldIds::DateTime: { auto pDateTimeField = static_cast<const SwDateTimeField*>(this); - sal_uInt16 nSubType = pDateTimeField->GetSubType(); - if (nSubType & FIXEDFLD) - nRet = nSubType & DATEFLD ? SwFieldTypesEnum::FixedDate : SwFieldTypesEnum::FixedTime; + SwDateTimeSubType nSubType = pDateTimeField->GetSubType(); + if (nSubType & SwDateTimeSubType::Fixed) + nRet = nSubType & SwDateTimeSubType::Date ? SwFieldTypesEnum::FixedDate : SwFieldTypesEnum::FixedTime; else - nRet = nSubType & DATEFLD ? SwFieldTypesEnum::Date : SwFieldTypesEnum::Time; + nRet = nSubType & SwDateTimeSubType::Date ? SwFieldTypesEnum::Date : SwFieldTypesEnum::Time; } break; case SwFieldIds::GetExp: @@ -329,7 +329,7 @@ OUString SwField::GetFieldName() const { auto pDateTimeField = static_cast<const SwDateTimeField*>(this); nTypeId = - ((pDateTimeField->GetSubType() & DATEFLD) != 0) ? SwFieldTypesEnum::Date : SwFieldTypesEnum::Time; + (pDateTimeField->GetSubType() & SwDateTimeSubType::Date) ? SwFieldTypesEnum::Date : SwFieldTypesEnum::Time; } OUString sRet = SwFieldType::GetTypeStr( nTypeId ); if (IsFixed()) @@ -455,7 +455,7 @@ sal_uInt16 SwField::GetUntypedSubType() const case SwFieldIds::GetRef: return static_cast<const SwGetRefField*>(this)->GetSubType(); case SwFieldIds::DateTime: - return static_cast<const SwDateTimeField*>(this)->GetSubType(); + return static_cast<sal_uInt16>(static_cast<const SwDateTimeField*>(this)->GetSubType()); case SwFieldIds::Table: return static_cast<const SwTableField*>(this)->GetSubType(); case SwFieldIds::Input: @@ -497,7 +497,7 @@ void SwField::SetUntypedSubType(sal_uInt16 n) static_cast<SwGetRefField*>(this)->SetSubType(n); break; case SwFieldIds::DateTime: - static_cast<SwDateTimeField*>(this)->SetSubType(n); + static_cast<SwDateTimeField*>(this)->SetSubType(static_cast<SwDateTimeSubType>(n)); break; case SwFieldIds::Table: static_cast<SwTableField*>(this)->SetSubType(n); @@ -642,7 +642,7 @@ bool SwField::IsFixed() const break; case SwFieldIds::DateTime: - bRet = 0 != (static_cast<const SwDateTimeField*>(this)->GetSubType() & FIXEDFLD); + bRet = bool(static_cast<const SwDateTimeField*>(this)->GetSubType() & SwDateTimeSubType::Fixed); break; case SwFieldIds::ExtUser: diff --git a/sw/source/core/fields/flddat.cxx b/sw/source/core/fields/flddat.cxx index 2049125c4ca1..941552d8847a 100644 --- a/sw/source/core/fields/flddat.cxx +++ b/sw/source/core/fields/flddat.cxx @@ -41,7 +41,7 @@ std::unique_ptr<SwFieldType> SwDateTimeFieldType::Copy() const return std::make_unique<SwDateTimeFieldType>(GetDoc()); } -SwDateTimeField::SwDateTimeField(SwDateTimeFieldType* pInitType, sal_uInt16 nSub, sal_uLong nFormat, LanguageType nLng) +SwDateTimeField::SwDateTimeField(SwDateTimeFieldType* pInitType, SwDateTimeSubType nSub, sal_uLong nFormat, LanguageType nLng) : SwValueField(pInitType, nFormat, nLng, 0.0), m_nSubType(nSub), m_nOffset(0) @@ -49,7 +49,7 @@ SwDateTimeField::SwDateTimeField(SwDateTimeFieldType* pInitType, sal_uInt16 nSub if (!nFormat) { SvNumberFormatter* pFormatter = GetDoc()->GetNumberFormatter(); - if (m_nSubType & DATEFLD) + if (m_nSubType & SwDateTimeSubType::Date) SetFormat(pFormatter->GetFormatIndex(NF_DATE_SYSTEM_SHORT, GetLanguage())); else SetFormat(pFormatter->GetFormatIndex(NF_TIME_HHMMSS, GetLanguage())); @@ -65,7 +65,7 @@ OUString SwDateTimeField::ExpandImpl(SwRootFrame const*const) const { if (getenv("STABLE_FIELDS_HACK")) { - const_cast<SwDateTimeField*>(this)->m_nSubType |= FIXEDFLD; //HACK + const_cast<SwDateTimeField*>(this)->m_nSubType |= SwDateTimeSubType::Fixed; //HACK } double fVal; @@ -97,12 +97,12 @@ std::unique_ptr<SwField> SwDateTimeField::Copy() const return std::unique_ptr<SwField>(pTmp.release()); } -sal_uInt16 SwDateTimeField::GetSubType() const +SwDateTimeSubType SwDateTimeField::GetSubType() const { return m_nSubType; } -void SwDateTimeField::SetSubType(sal_uInt16 nType) +void SwDateTimeField::SetSubType(SwDateTimeSubType nType) { m_nSubType = nType; } @@ -138,7 +138,7 @@ double SwDateTimeField::GetValue() const { if (getenv("STABLE_FIELDS_HACK")) { - const_cast<SwDateTimeField*>(this)->m_nSubType |= FIXEDFLD; //HACK + const_cast<SwDateTimeField*>(this)->m_nSubType |= SwDateTimeSubType::Fixed; //HACK } if (IsFixed()) @@ -175,7 +175,7 @@ bool SwDateTimeField::QueryValue( uno::Any& rVal, sal_uInt16 nWhichId ) const rVal <<= IsFixed(); break; case FIELD_PROP_BOOL2: - rVal <<= (m_nSubType & DATEFLD) != 0; + rVal <<= bool(m_nSubType & SwDateTimeSubType::Date); break; case FIELD_PROP_FORMAT: rVal <<= static_cast<sal_Int32>(GetFormat()); @@ -202,13 +202,13 @@ bool SwDateTimeField::PutValue( const uno::Any& rVal, sal_uInt16 nWhichId ) { case FIELD_PROP_BOOL1: if(*o3tl::doAccess<bool>(rVal)) - m_nSubType |= FIXEDFLD; + m_nSubType |= SwDateTimeSubType::Fixed; else - m_nSubType &= ~FIXEDFLD; + m_nSubType &= ~SwDateTimeSubType::Fixed; break; case FIELD_PROP_BOOL2: - m_nSubType &= ~(DATEFLD|TIMEFLD); - m_nSubType |= *o3tl::doAccess<bool>(rVal) ? DATEFLD : TIMEFLD; + m_nSubType &= ~SwDateTimeSubType(SwDateTimeSubType::Date | SwDateTimeSubType::Time); + m_nSubType |= *o3tl::doAccess<bool>(rVal) ? SwDateTimeSubType::Date : SwDateTimeSubType::Time; break; case FIELD_PROP_FORMAT: rVal >>= nTmp; diff --git a/sw/source/core/unocore/unofield.cxx b/sw/source/core/unocore/unofield.cxx index b53df2ca82c9..809e761e0193 100644 --- a/sw/source/core/unocore/unofield.cxx +++ b/sw/source/core/unocore/unofield.cxx @@ -1417,13 +1417,13 @@ void SAL_CALL SwXTextField::attach( break; case SwServiceType::FieldTypeDateTime: { - sal_uInt16 nSub = 0; + SwDateTimeSubType nSub = SwDateTimeSubType::None; if (m_pImpl->m_pProps->bBool1) - nSub |= FIXEDFLD; + nSub |= SwDateTimeSubType::Fixed; if (m_pImpl->m_pProps->bBool2) - nSub |= DATEFLD; + nSub |= SwDateTimeSubType::Date; else - nSub |= TIMEFLD; + nSub |= SwDateTimeSubType::Time; SwFieldType* pFieldType = pDoc->getIDocumentFieldsAccess().GetSysFieldType(SwFieldIds::DateTime); SwDateTimeField *const pDTField = new SwDateTimeField( static_cast<SwDateTimeFieldType*>(pFieldType), diff --git a/sw/source/filter/html/htmlfld.cxx b/sw/source/filter/html/htmlfld.cxx index 1d85c4966cea..1c41564b5242 100644 --- a/sw/source/filter/html/htmlfld.cxx +++ b/sw/source/filter/html/htmlfld.cxx @@ -321,26 +321,26 @@ void SwHTMLParser::NewField() DateTime aDateTime( DateTime::SYSTEM ); sal_Int64 nTime = aDateTime.GetTime(); sal_Int32 nDate = aDateTime.GetDate(); - sal_uInt16 nSub = 0; + SwDateTimeSubType nSub = SwDateTimeSubType::None; bool bValidFormat = false; HTMLNumFormatTableEntry const * pFormatTable; if( SwFieldIds::Date==nType ) { - nSub = DATEFLD; + nSub = SwDateTimeSubType::Date; pFormatTable = aHTMLDateFieldFormatTable; if( !aValue.isEmpty() ) nDate = aValue.toInt32(); } else { - nSub = TIMEFLD; + nSub = SwDateTimeSubType::Time; pFormatTable = aHTMLTimeFieldFormatTable; if( !aValue.isEmpty() ) nTime = static_cast<sal_uLong>(aValue.toInt32()); // Is this OK? 32-bit encoded time? } if( !aValue.isEmpty() ) - nSub |= FIXEDFLD; + nSub |= SwDateTimeSubType::Fixed; SvNumberFormatter *pFormatter = m_xDoc->GetNumberFormatter(); if( pFormatOption ) @@ -363,7 +363,7 @@ void SwHTMLParser::NewField() xNewField.reset(new SwDateTimeField(static_cast<SwDateTimeFieldType *>(pType), nSub, nNumFormat)); - if (nSub & FIXEDFLD) + if (nSub & SwDateTimeSubType::Fixed) static_cast<SwDateTimeField *>(xNewField.get())->SetDateTime(DateTime(Date(nDate), tools::Time::fromEncodedTime(nTime))); } break; @@ -371,7 +371,7 @@ void SwHTMLParser::NewField() case SwFieldIds::DateTime: if( bHasNumFormat ) { - sal_uInt16 nSub = 0; + SwDateTimeSubType nSub = SwDateTimeSubType::None; SvNumberFormatter *pFormatter = m_xDoc->GetNumberFormatter(); sal_uInt32 nNumFormat; @@ -382,15 +382,15 @@ void SwHTMLParser::NewField() SvNumFormatType nFormatType = pFormatter->GetType( nNumFormat ); switch( nFormatType ) { - case SvNumFormatType::DATE: nSub = DATEFLD; break; - case SvNumFormatType::TIME: nSub = TIMEFLD; break; + case SvNumFormatType::DATE: nSub = SwDateTimeSubType::Date; break; + case SvNumFormatType::TIME: nSub = SwDateTimeSubType::Time; break; default: break; } - if( nSub ) + if( nSub != SwDateTimeSubType::None ) { if( bHasNumValue ) - nSub |= FIXEDFLD; + nSub |= SwDateTimeSubType::Fixed; xNewField.reset(new SwDateTimeField(static_cast<SwDateTimeFieldType *>(pType), nSub, nNumFormat)); if (bHasNumValue) diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index 94417461faee..e5447609345a 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -2971,7 +2971,7 @@ void DocxAttributeOutput::StartField_Impl( const SwTextNode* pNode, sal_Int32 nP { // Write the field start if ( rInfos.pField && (rInfos.pField->Which() == SwFieldIds::DateTime) - && (static_cast<const SwDateTimeField*>(rInfos.pField.get())->GetSubType() & FIXEDFLD) ) + && (static_cast<const SwDateTimeField*>(rInfos.pField.get())->GetSubType() & SwDateTimeSubType::Fixed) ) { m_pSerializer->startElementNS( XML_w, XML_fldChar, FSNS( XML_w, XML_fldCharType ), "begin", diff --git a/sw/source/filter/ww8/rtfattributeoutput.cxx b/sw/source/filter/ww8/rtfattributeoutput.cxx index a73a4e9d8ffb..73af2f9c94bb 100644 --- a/sw/source/filter/ww8/rtfattributeoutput.cxx +++ b/sw/source/filter/ww8/rtfattributeoutput.cxx @@ -1887,7 +1887,8 @@ void RtfAttributeOutput::WriteField_Impl(const SwField* const pField, ww::eField { m_aRunText->append("{" OOO_STRING_SVTOOLS_RTF_FIELD); if (pField && pField->GetTyp()->Which() == SwFieldIds::DateTime - && (static_cast<const SwDateTimeField*>(pField)->GetSubType() & FIXEDFLD)) + && (static_cast<const SwDateTimeField*>(pField)->GetSubType() + & SwDateTimeSubType::Fixed)) m_aRunText->append(OOO_STRING_SVTOOLS_RTF_FLDLOCK); m_aRunText->append("{" OOO_STRING_SVTOOLS_RTF_IGNORE OOO_STRING_SVTOOLS_RTF_FLDINST " "); diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx index 45115c1c3387..6e8478807b82 100644 --- a/sw/source/filter/ww8/ww8atr.cxx +++ b/sw/source/filter/ww8/ww8atr.cxx @@ -2036,8 +2036,8 @@ void WW8Export::OutputField( const SwField* pField, ww::eField eFieldType, // This ought to apply to any field, but just to be safe, start off with DATE/TIME only. if (pField->GetTyp()->Which() == SwFieldIds::DateTime) { - sal_uInt16 nSubType = static_cast<const SwDateTimeField*>(pField)->GetSubType(); - if (nSubType & FIXEDFLD) + SwDateTimeSubType nSubType = static_cast<const SwDateTimeField*>(pField)->GetSubType(); + if (nSubType & SwDateTimeSubType::Fixed) //bit 5 - Locked: do not recalculate field aField15[1] |= 0x10; } @@ -3129,13 +3129,13 @@ void AttributeOutputBase::TextField( const SwFormatField& rField ) case SwFieldIds::DateTime: { auto pDateTimeField = static_cast<const SwDateTimeField*>(pField); - const sal_uInt16 nSubType = pDateTimeField->GetSubType(); + const SwDateTimeSubType nSubType = pDateTimeField->GetSubType(); OUString sStr; if (!GetExport().GetNumberFormat(*pField, sStr)) bWriteExpand = true; else { - ww::eField eField = (DATEFLD & nSubType) ? ww::eDATE : ww::eTIME; + ww::eField eField = (SwDateTimeSubType::Date & nSubType) ? ww::eDATE : ww::eTIME; GetExport().OutputField(pField, eField, FieldString(eField) + sStr); } } diff --git a/sw/source/filter/ww8/ww8par5.cxx b/sw/source/filter/ww8/ww8par5.cxx index e0975e461e7d..2b2b63ae4f49 100644 --- a/sw/source/filter/ww8/ww8par5.cxx +++ b/sw/source/filter/ww8/ww8par5.cxx @@ -1930,14 +1930,14 @@ eF_ResT SwWW8ImplReader::Read_F_DateTime( WW8FieldDesc*pF, OUString& rStr ) { SwDateTimeField aField(static_cast<SwDateTimeFieldType*>( m_rDoc.getIDocumentFieldsAccess().GetSysFieldType(SwFieldIds::DateTime)), - nDT & SvNumFormatType::DATE ? DATEFLD : TIMEFLD, nFormat); + nDT & SvNumFormatType::DATE ? SwDateTimeSubType::Date : SwDateTimeSubType::Time, nFormat); if (pF->nOpt & 0x10) // Fixed field { double fSerial; if (!m_rDoc.GetNumberFormatter()->IsNumberFormat(GetFieldResult(pF), nFormat, fSerial, SvNumInputOptions::LAX_TIME)) return eF_ResT::TEXT; // just drop the field and insert the plain text. - aField.SetSubType(aField.GetSubType() | FIXEDFLD); + aField.SetSubType(aField.GetSubType() | SwDateTimeSubType::Fixed); DateTime aSetDateTime(m_rDoc.GetNumberFormatter()->GetNullDate()); aSetDateTime.AddTime(fSerial); aField.SetDateTime(aSetDateTime); diff --git a/sw/source/ui/fldui/fldpage.cxx b/sw/source/ui/fldui/fldpage.cxx index bd17a35ac69b..312ce2ba85d2 100644 --- a/sw/source/ui/fldui/fldpage.cxx +++ b/sw/source/ui/fldui/fldpage.cxx @@ -179,9 +179,12 @@ void SwFieldPage::InsertField(SwFieldTypesEnum nTypeId, sal_uInt16 nSubType, con switch( nTypeId ) { case SwFieldTypesEnum::Date: + nSubType = static_cast< sal_uInt16 >(SwDateTimeSubType::Date | + ((nSubType == DATE_VAR) ? SwDateTimeSubType::None : SwDateTimeSubType::Fixed)); + break; case SwFieldTypesEnum::Time: - nSubType = static_cast< sal_uInt16 >(((nTypeId == SwFieldTypesEnum::Date) ? DATEFLD : TIMEFLD) | - ((nSubType == DATE_VAR) ? 0 : FIXEDFLD)); + nSubType = static_cast< sal_uInt16 >(SwDateTimeSubType::Time | + ((nSubType == DATE_VAR) ? SwDateTimeSubType::None : SwDateTimeSubType::Fixed)); break; case SwFieldTypesEnum::DatabaseName: diff --git a/sw/source/uibase/fldui/fldmgr.cxx b/sw/source/uibase/fldui/fldmgr.cxx index adb7a5362fa2..75cf04cfdb43 100644 --- a/sw/source/uibase/fldui/fldmgr.cxx +++ b/sw/source/uibase/fldui/fldmgr.cxx @@ -966,8 +966,9 @@ bool SwFieldMgr::InsertField( case SwFieldTypesEnum::Time: { sal_uInt16 nSubType = rData.m_nSubType; - sal_uInt16 nSub = static_cast< sal_uInt16 >(rData.m_nTypeId == SwFieldTypesEnum::Date ? DATEFLD : TIMEFLD); - nSub |= nSubType == DATE_VAR ? 0 : FIXEDFLD; + SwDateTimeSubType nSub = (rData.m_nTypeId == SwFieldTypesEnum::Date ? SwDateTimeSubType::Date : SwDateTimeSubType::Time); + if (nSubType != DATE_VAR) + nSub |= SwDateTimeSubType::Fixed; SwDateTimeFieldType* pTyp = static_cast<SwDateTimeFieldType*>( pCurShell->GetFieldType(0, SwFieldIds::DateTime) );