sw/inc/dbfld.hxx | 14 ++++++------ sw/inc/fldbas.hxx | 12 +++++----- sw/source/core/fields/dbfld.cxx | 42 ++++++++++++++++++------------------ sw/source/core/fields/fldbas.cxx | 8 +++--- sw/source/core/unocore/unofield.cxx | 18 +++++++-------- sw/source/ui/dbui/dbinsdlg.cxx | 4 +-- sw/source/ui/fldui/flddb.cxx | 4 +-- sw/source/uibase/fldui/fldmgr.cxx | 6 ++--- 8 files changed, 54 insertions(+), 54 deletions(-)
New commits: commit e4f8581f7de466aa2f0854ee65d2b7af4ce9d07c Author: Noel Grandin <noelgran...@gmail.com> AuthorDate: Sun Jul 6 20:28:57 2025 +0200 Commit: Noel Grandin <noelgran...@gmail.com> CommitDate: Thu Jul 10 11:02:02 2025 +0200 make scoped enum for dbfield subtype Change-Id: I58243747eb317578c6f32a064921453bf742d2ac Reviewed-on: https://gerrit.libreoffice.org/c/core/+/187595 Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> Tested-by: Jenkins diff --git a/sw/inc/dbfld.hxx b/sw/inc/dbfld.hxx index 04f4a2783372..867804802806 100644 --- a/sw/inc/dbfld.hxx +++ b/sw/inc/dbfld.hxx @@ -57,7 +57,7 @@ class SW_DLLPUBLIC SwDBField final : public SwValueField { OUString m_aContent; OUString m_sFieldCode; ///< contains Word's field code - sal_uInt16 m_nSubType; + SwDBFieldSubType m_nSubType; bool m_bIsInBodyText : 1; bool m_bValidValue : 1; bool m_bInitialized : 1; @@ -66,7 +66,7 @@ class SW_DLLPUBLIC SwDBField final : public SwValueField virtual std::unique_ptr<SwField> Copy() const override; public: - SwDBField(SwDBFieldType*, sal_uInt32 nFormat = 0, sal_uInt16 nSubType = 0); + SwDBField(SwDBFieldType*, sal_uInt32 nFormat = 0, SwDBFieldSubType nSubType = SwDBFieldSubType::None); virtual ~SwDBField() override; virtual SwFieldType* ChgTyp( SwFieldType* ) override; @@ -74,8 +74,8 @@ public: /// Current text. inline void SetExpansion(const OUString& rStr); - sal_uInt16 GetSubType() const; - void SetSubType(sal_uInt16 nType); + SwDBFieldSubType GetSubType() const; + void SetSubType(SwDBFieldSubType nType); virtual OUString GetFieldName() const override; @@ -121,7 +121,7 @@ inline void SwDBField::ChgBodyTextFlag( bool bIsInBody ) class SW_DLLPUBLIC SwDBNameInfField : public SwField { SwDBData m_aDBData; - sal_uInt16 m_nSubType; + SwDBFieldSubType m_nSubType; sal_uInt32 m_nFormat; protected: @@ -145,8 +145,8 @@ public: virtual bool QueryValue( css::uno::Any& rVal, sal_uInt16 nWhich ) const override; virtual bool PutValue( const css::uno::Any& rVal, sal_uInt16 nWhich ) override; - sal_uInt16 GetSubType() const; - void SetSubType(sal_uInt16 nType); + SwDBFieldSubType GetSubType() const; + void SetSubType(SwDBFieldSubType nType); }; // Database field next record. diff --git a/sw/inc/fldbas.hxx b/sw/inc/fldbas.hxx index afcaded28c8f..124a9062317e 100644 --- a/sw/inc/fldbas.hxx +++ b/sw/inc/fldbas.hxx @@ -182,13 +182,13 @@ enum class SwGetSetExpType : sal_uInt16 }; namespace o3tl { template<> struct typed_flags<SwGetSetExpType> : is_typed_flags<SwGetSetExpType, 0x031f> {}; } -typedef sal_uInt16 SwExtendedSubType; -namespace nsSwExtendedSubType +enum class SwDBFieldSubType : sal_uInt16 { -const SwExtendedSubType SUB_CMD = 0x0100; ///< Show command. -const SwExtendedSubType SUB_INVISIBLE = 0x0200; ///< Invisible. -const SwExtendedSubType SUB_OWN_FMT = 0x0400; ///< SwDBField: Don't accept formatting from database. -} + None = 0x0000, + Invisible = 0x0200, ///< Invisible. + OwnFormat = 0x0400 ///< SwDBField: Don't accept formatting from database. +}; +namespace o3tl { template<> struct typed_flags<SwDBFieldSubType> : is_typed_flags<SwDBFieldSubType, 0x0600> {}; } enum class SwInputFieldSubType : sal_uInt16 { diff --git a/sw/source/core/fields/dbfld.cxx b/sw/source/core/fields/dbfld.cxx index f730628e6701..700864f16818 100644 --- a/sw/source/core/fields/dbfld.cxx +++ b/sw/source/core/fields/dbfld.cxx @@ -157,7 +157,7 @@ void SwDBFieldType::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId ) // database field -SwDBField::SwDBField(SwDBFieldType* pTyp, sal_uInt32 nFormat, sal_uInt16 nSubType) +SwDBField::SwDBField(SwDBFieldType* pTyp, sal_uInt32 nFormat, SwDBFieldSubType nSubType) : SwValueField(pTyp, nFormat), m_nSubType(nSubType), m_bIsInBodyText(true), @@ -200,7 +200,7 @@ void SwDBField::InitContent(const OUString& rExpansion) OUString SwDBField::ExpandImpl(SwRootFrame const*const) const { - if(0 ==(GetSubType() & nsSwExtendedSubType::SUB_INVISIBLE)) + if(!(GetSubType() & SwDBFieldSubType::Invisible)) return lcl_DBSeparatorConvert(m_aContent); return OUString(); } @@ -320,7 +320,7 @@ void SwDBField::Evaluate() SvNumberFormatter* pDocFormatter = GetDoc()->GetNumberFormatter(); pMgr->GetMergeColumnCnt(aColNm, GetLanguage(), m_aContent, &nValue); - if( !( m_nSubType & nsSwExtendedSubType::SUB_OWN_FMT ) ) + if( !( m_nSubType & SwDBFieldSubType::OwnFormat ) ) { nFormat = pMgr->GetColumnFormat( aTmpData.sDataSource, aTmpData.sCommand, aColNm, pDocFormatter, GetLanguage() ); @@ -345,12 +345,12 @@ OUString SwDBField::GetPar1() const return static_cast<const SwDBFieldType*>(GetTyp())->GetName().toString(); } -sal_uInt16 SwDBField::GetSubType() const +SwDBFieldSubType SwDBField::GetSubType() const { return m_nSubType; } -void SwDBField::SetSubType(sal_uInt16 nType) +void SwDBField::SetSubType(SwDBFieldSubType nType) { m_nSubType = nType; } @@ -360,10 +360,10 @@ bool SwDBField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const switch( nWhichId ) { case FIELD_PROP_BOOL1: - rAny <<= 0 == (GetSubType()&nsSwExtendedSubType::SUB_OWN_FMT); + rAny <<= !(GetSubType() & SwDBFieldSubType::OwnFormat); break; case FIELD_PROP_BOOL2: - rAny <<= 0 == (GetSubType() & nsSwExtendedSubType::SUB_INVISIBLE); + rAny <<= !(GetSubType() & SwDBFieldSubType::Invisible); break; case FIELD_PROP_FORMAT: rAny <<= static_cast<sal_Int32>(GetFormat()); @@ -386,20 +386,20 @@ bool SwDBField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId ) { case FIELD_PROP_BOOL1: if( *o3tl::doAccess<bool>(rAny) ) - SetSubType(GetSubType()&~nsSwExtendedSubType::SUB_OWN_FMT); + SetSubType(GetSubType() & ~SwDBFieldSubType::OwnFormat); else - SetSubType(GetSubType()|nsSwExtendedSubType::SUB_OWN_FMT); + SetSubType(GetSubType() | SwDBFieldSubType::OwnFormat); break; case FIELD_PROP_BOOL2: { - sal_uInt16 nSubTyp = GetSubType(); + SwDBFieldSubType nSubTyp = GetSubType(); bool bVisible = false; if(!(rAny >>= bVisible)) return false; if(bVisible) - nSubTyp &= ~nsSwExtendedSubType::SUB_INVISIBLE; + nSubTyp &= ~SwDBFieldSubType::Invisible; else - nSubTyp |= nsSwExtendedSubType::SUB_INVISIBLE; + nSubTyp |= SwDBFieldSubType::Invisible; SetSubType(nSubTyp); //invalidate text node auto pType = GetTyp(); @@ -443,7 +443,7 @@ bool SwDBField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId ) SwDBNameInfField::SwDBNameInfField(SwFieldType* pTyp, SwDBData aDBData, sal_uInt32 nFormat) : SwField(pTyp), m_aDBData(std::move(aDBData)), - m_nSubType(0), + m_nSubType(SwDBFieldSubType::None), m_nFormat(nFormat) { } @@ -490,7 +490,7 @@ bool SwDBNameInfField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const rAny <<= m_aDBData.nCommandType; break; case FIELD_PROP_BOOL2: - rAny <<= 0 == (GetSubType() & nsSwExtendedSubType::SUB_INVISIBLE); + rAny <<= !(GetSubType() & SwDBFieldSubType::Invisible); break; default: assert(false); @@ -513,14 +513,14 @@ bool SwDBNameInfField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId ) break; case FIELD_PROP_BOOL2: { - sal_uInt16 nSubTyp = GetSubType(); + SwDBFieldSubType nSubTyp = GetSubType(); bool bVisible = false; if(!(rAny >>= bVisible)) return false; if(bVisible) - nSubTyp &= ~nsSwExtendedSubType::SUB_INVISIBLE; + nSubTyp &= ~SwDBFieldSubType::Invisible; else - nSubTyp |= nsSwExtendedSubType::SUB_INVISIBLE; + nSubTyp |= SwDBFieldSubType::Invisible; SetSubType(nSubTyp); } break; @@ -530,12 +530,12 @@ bool SwDBNameInfField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId ) return true; } -sal_uInt16 SwDBNameInfField::GetSubType() const +SwDBFieldSubType SwDBNameInfField::GetSubType() const { return m_nSubType; } -void SwDBNameInfField::SetSubType(sal_uInt16 nType) +void SwDBNameInfField::SetSubType(SwDBFieldSubType nType) { m_nSubType = nType; } @@ -759,7 +759,7 @@ SwDBNameField::SwDBNameField(SwDBNameFieldType* pTyp, const SwDBData& rDBData, s OUString SwDBNameField::ExpandImpl(SwRootFrame const*const) const { - if(0 ==(GetSubType() & nsSwExtendedSubType::SUB_INVISIBLE)) + if(!(GetSubType() & SwDBFieldSubType::Invisible)) return static_cast<SwDBNameFieldType*>(GetTyp())->Expand(); return OUString(); } @@ -802,7 +802,7 @@ SwDBSetNumberField::SwDBSetNumberField(SwDBSetNumberFieldType* pTyp, OUString SwDBSetNumberField::ExpandImpl(SwRootFrame const*const) const { - if(0 !=(GetSubType() & nsSwExtendedSubType::SUB_INVISIBLE) || m_nNumber == 0) + if((GetSubType() & SwDBFieldSubType::Invisible) || m_nNumber == 0) return OUString(); return FormatNumber(m_nNumber, static_cast<SvxNumType>(GetFormat())); } diff --git a/sw/source/core/fields/fldbas.cxx b/sw/source/core/fields/fldbas.cxx index a1fb16a3c838..efd9259e7ba7 100644 --- a/sw/source/core/fields/fldbas.cxx +++ b/sw/source/core/fields/fldbas.cxx @@ -478,9 +478,9 @@ sal_uInt16 SwField::GetUntypedSubType() const case SwFieldIds::DbNumSet: case SwFieldIds::DatabaseName: case SwFieldIds::DbSetNumber: - return static_cast<const SwDBNameInfField*>(this)->GetSubType(); + return static_cast<sal_uInt16>(static_cast<const SwDBNameInfField*>(this)->GetSubType()); case SwFieldIds::Database: - return static_cast<const SwDBField*>(this)->GetSubType(); + return static_cast<sal_uInt16>(static_cast<const SwDBField*>(this)->GetSubType()); default: break; } return 0; @@ -530,10 +530,10 @@ void SwField::SetUntypedSubType(sal_uInt16 n) case SwFieldIds::DbNumSet: case SwFieldIds::DatabaseName: case SwFieldIds::DbSetNumber: - static_cast<SwDBNameInfField*>(this)->SetSubType(n); + static_cast<SwDBNameInfField*>(this)->SetSubType(static_cast<SwDBFieldSubType>(n)); break; case SwFieldIds::Database: - static_cast<SwDBField*>(this)->SetSubType(n); + static_cast<SwDBField*>(this)->SetSubType(static_cast<SwDBFieldSubType>(n)); break; default: assert(n == 0 && "trying to set a subtype on something I don't know about"); diff --git a/sw/source/core/unocore/unofield.cxx b/sw/source/core/unocore/unofield.cxx index 687ce6b68c95..a1a5a3858faf 100644 --- a/sw/source/core/unocore/unofield.cxx +++ b/sw/source/core/unocore/unofield.cxx @@ -1680,11 +1680,11 @@ void SAL_CALL SwXTextField::attach( aData.sCommand = m_pImpl->m_pProps->sPar2; aData.nCommandType = m_pImpl->m_pProps->nSHORT1; xField.reset(new SwDBNameField(static_cast<SwDBNameFieldType*>(pFieldType), aData)); - sal_uInt16 nSubType = static_cast<SwDBNameField*>(xField.get())->GetSubType(); + SwDBFieldSubType nSubType = static_cast<SwDBNameField*>(xField.get())->GetSubType(); if (m_pImpl->m_pProps->bBool2) - nSubType &= ~nsSwExtendedSubType::SUB_INVISIBLE; + nSubType &= ~SwDBFieldSubType::Invisible; else - nSubType |= nsSwExtendedSubType::SUB_INVISIBLE; + nSubType |= SwDBFieldSubType::Invisible; static_cast<SwDBNameField*>(xField.get())->SetSubType(nSubType); } break; @@ -1724,11 +1724,11 @@ void SAL_CALL SwXTextField::attach( m_pImpl->m_pProps->nUSHORT1); xField.reset(pDBSNField); pDBSNField->SetSetNumber(m_pImpl->m_pProps->nFormat); - sal_uInt16 nSubType = pDBSNField->GetSubType(); + SwDBFieldSubType nSubType = pDBSNField->GetSubType(); if (m_pImpl->m_pProps->bBool2) - nSubType &= ~nsSwExtendedSubType::SUB_INVISIBLE; + nSubType &= ~SwDBFieldSubType::Invisible; else - nSubType |= nsSwExtendedSubType::SUB_INVISIBLE; + nSubType |= SwDBFieldSubType::Invisible; pDBSNField->SetSubType(nSubType); } break; @@ -1741,11 +1741,11 @@ void SAL_CALL SwXTextField::attach( xField.reset(new SwDBField(static_cast<SwDBFieldType*>(pFieldType), m_pImpl->m_pProps->nFormat)); static_cast<SwDBField*>(xField.get())->InitContent(m_pImpl->m_pProps->sPar1); - sal_uInt16 nSubType = static_cast<SwDBField*>(xField.get())->GetSubType(); + SwDBFieldSubType nSubType = static_cast<SwDBField*>(xField.get())->GetSubType(); if (m_pImpl->m_pProps->bBool2) - nSubType &= ~nsSwExtendedSubType::SUB_INVISIBLE; + nSubType &= ~SwDBFieldSubType::Invisible; else - nSubType |= nsSwExtendedSubType::SUB_INVISIBLE; + nSubType |= SwDBFieldSubType::Invisible; static_cast<SwDBField*>(xField.get())->SetSubType(nSubType); } break; diff --git a/sw/source/ui/dbui/dbinsdlg.cxx b/sw/source/ui/dbui/dbinsdlg.cxx index 9ce7d10a4cc1..d12c56c8d287 100644 --- a/sw/source/ui/dbui/dbinsdlg.cxx +++ b/sw/source/ui/dbui/dbinsdlg.cxx @@ -881,7 +881,7 @@ bool SwInsertDBColAutoPilot::SplitTextToColArr( const OUString& rText, sText = sText.copy( rFndCol.sColumn.getLength() + 2 ); nSttPos = 0; - sal_uInt16 nSubType = 0; + SwDBFieldSubType nSubType = SwDBFieldSubType::None; sal_uInt32 nFormat; if( rFndCol.bHasFormat ) { @@ -890,7 +890,7 @@ bool SwInsertDBColAutoPilot::SplitTextToColArr( const OUString& rText, else { nFormat = rFndCol.nUsrNumFormat; - nSubType = nsSwExtendedSubType::SUB_OWN_FMT; + nSubType = SwDBFieldSubType::OwnFormat; } } else diff --git a/sw/source/ui/fldui/flddb.cxx b/sw/source/ui/fldui/flddb.cxx index 6b6919099c26..bd14ffc5ab2f 100644 --- a/sw/source/ui/fldui/flddb.cxx +++ b/sw/source/ui/fldui/flddb.cxx @@ -230,7 +230,7 @@ bool SwFieldDBPage::FillItemSet(SfxItemSet* ) case SwFieldTypesEnum::Database: nFormat = m_xNumFormatLB->GetFormat(); if (m_xNewFormatRB->get_sensitive() && m_xNewFormatRB->get_active()) - nSubType = nsSwExtendedSubType::SUB_OWN_FMT; + nSubType = static_cast<sal_uInt16>(SwDBFieldSubType::OwnFormat); aName = sDBName; break; @@ -342,7 +342,7 @@ void SwFieldDBPage::TypeHdl(const weld::TreeView* pBox) if (nFormat != 0 && nFormat != SAL_MAX_UINT32) m_xNumFormatLB->SetDefFormat(nFormat); - if (pDBField->GetSubType() & nsSwExtendedSubType::SUB_OWN_FMT) + if (pDBField->GetSubType() & SwDBFieldSubType::OwnFormat) m_xNewFormatRB->set_active(true); else m_xDBFormatRB->set_active(true); diff --git a/sw/source/uibase/fldui/fldmgr.cxx b/sw/source/uibase/fldui/fldmgr.cxx index 3e679bb83553..6fd712bf5817 100644 --- a/sw/source/uibase/fldui/fldmgr.cxx +++ b/sw/source/uibase/fldui/fldmgr.cxx @@ -1229,7 +1229,7 @@ bool SwFieldMgr::InsertField( #if HAVE_FEATURE_DBCONNECTIVITY && !ENABLE_FUZZERS SwDBData aDBData; OUString sPar1; - sal_uInt16 nSubType = rData.m_nSubType; + SwDBFieldSubType nSubType = static_cast<SwDBFieldSubType>(rData.m_nSubType); if (rData.m_sPar1.indexOf(DB_DELIM)<0) { @@ -1250,9 +1250,9 @@ bool SwFieldMgr::InsertField( SwDBFieldType* pTyp = static_cast<SwDBFieldType*>(pCurShell->InsertFieldType( SwDBFieldType(pCurShell->GetDoc(), sPar1, aDBData) ) ); - pField.reset(new SwDBField(pTyp, nSubType)); + pField.reset(new SwDBField(pTyp, 0, nSubType)); - if( !(nSubType & nsSwExtendedSubType::SUB_OWN_FMT) ) // determine database format + if( !(nSubType & SwDBFieldSubType::OwnFormat) ) // determine database format { Reference< XDataSource> xSource; rData.m_aDBDataSource >>= xSource;