include/svx/xcolit.hxx | 25 ++++++++---------- include/svx/xflclit.hxx | 31 +++++++--------------- include/svx/xit.hxx | 52 +++++++++++++++++++++---------------- svx/source/xoutdev/xattr.cxx | 59 ++++++++++++++++++++++++++----------------- 4 files changed, 87 insertions(+), 80 deletions(-)
New commits: commit 68ecab2225bd3ca098a0b26819e2b85d05fa0ed2 Author: Tomaž Vajngerl <[email protected]> AuthorDate: Sat Dec 6 23:00:57 2025 +0900 Commit: Tomaž Vajngerl <[email protected]> CommitDate: Mon Dec 8 04:15:38 2025 +0100 svx: clean-up NameOrIndex and XColorItem and XFillColorItem Change-Id: I40ef3e6826857f465a7e0c1643536b99cc32e778 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/195168 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <[email protected]> diff --git a/include/svx/xcolit.hxx b/include/svx/xcolit.hxx index 7336d0bc62a2..5cd3c6cbd993 100644 --- a/include/svx/xcolit.hxx +++ b/include/svx/xcolit.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_SVX_XCOLIT_HXX -#define INCLUDED_SVX_XCOLIT_HXX +#pragma once #include <tools/color.hxx> #include <docmodel/color/ComplexColor.hxx> @@ -32,21 +31,21 @@ class SVXCORE_DLLPUBLIC XColorItem : public NameOrIndex model::ComplexColor maComplexColor; public: - static SfxPoolItem* CreateDefault(); - DECLARE_ITEM_TYPE_FUNCTION(XColorItem) - XColorItem() : NameOrIndex() {} - XColorItem(TypedWhichId<XColorItem> nWhich, sal_Int32 nIndex, const Color& rTheColor); - XColorItem(TypedWhichId<XColorItem> nWhich, const Color& rTheColor); - XColorItem(TypedWhichId<XColorItem> nWhich, const OUString& rName, const Color& rTheColor); - XColorItem(const XColorItem& rItem); + static SfxPoolItem* CreateDefault(); + DECLARE_ITEM_TYPE_FUNCTION(XColorItem) + XColorItem(); + XColorItem(TypedWhichId<XColorItem> nWhich, sal_Int32 nIndex, const Color& rTheColor); + XColorItem(TypedWhichId<XColorItem> nWhich, const Color& rTheColor); + XColorItem(TypedWhichId<XColorItem> nWhich, const OUString& rName, const Color& rTheColor); + XColorItem(const XColorItem& rItem); virtual bool QueryValue( css::uno::Any& rVal, sal_uInt8 nMemberId = 0 ) const override; virtual bool PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId ) override; - virtual bool operator==(const SfxPoolItem& rItem) const override; + virtual bool operator==(const SfxPoolItem& rItem) const override; virtual XColorItem* Clone(SfxItemPool* pPool = nullptr) const override; - const Color& GetColorValue() const; - void SetColorValue(const Color& rNew) { m_aColor = rNew; Detach(); } + Color const& GetColorValue() const; + void SetColorValue(const Color& rNew); void setComplexColor(model::ComplexColor const& rComplexColor) { maComplexColor = rComplexColor; } const model::ComplexColor& getComplexColor() const { return maComplexColor; } @@ -55,6 +54,4 @@ public: virtual void dumpAsXml(xmlTextWriterPtr pWriter) const override; }; -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/svx/xflclit.hxx b/include/svx/xflclit.hxx index ea2908e6ee71..706a73b5ae46 100644 --- a/include/svx/xflclit.hxx +++ b/include/svx/xflclit.hxx @@ -17,41 +17,30 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_SVX_XFLCLIT_HXX -#define INCLUDED_SVX_XFLCLIT_HXX +#pragma once #include <svx/xcolit.hxx> #include <svx/svxdllapi.h> -//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -// Fuellattribute -//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - - - class SVXCORE_DLLPUBLIC XFillColorItem final : public XColorItem { public: - static SfxPoolItem* CreateDefault(); - DECLARE_ITEM_TYPE_FUNCTION(XFillColorItem) - XFillColorItem() : XColorItem() {} - XFillColorItem(sal_Int32 nIndex, const Color& rTheColor); - XFillColorItem(const OUString& rName, const Color& rTheColor); + static SfxPoolItem* CreateDefault(); + DECLARE_ITEM_TYPE_FUNCTION(XFillColorItem) + XFillColorItem(); + XFillColorItem(sal_Int32 nIndex, const Color& rTheColor); + XFillColorItem(const OUString& rName, const Color& rTheColor); virtual XFillColorItem* Clone(SfxItemPool* pPool = nullptr) const override; - virtual bool QueryValue( css::uno::Any& rVal, sal_uInt8 nMemberId = 0 ) const override; - virtual bool PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId ) override; + virtual bool QueryValue( css::uno::Any& rVal, sal_uInt8 nMemberId = 0 ) const override; + virtual bool PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId ) override; - virtual bool GetPresentation( SfxItemPresentation ePres, - MapUnit eCoreMetric, - MapUnit ePresMetric, - OUString &rText, const IntlWrapper& ) const override; + virtual bool GetPresentation(SfxItemPresentation ePres, MapUnit eCoreMetric, MapUnit ePresMetric, + OUString &rText, const IntlWrapper& rWrapper) const override; void dumpAsXml(xmlTextWriterPtr pWriter) const override; virtual boost::property_tree::ptree dumpAsJSON() const override; }; -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/svx/xit.hxx b/include/svx/xit.hxx index db639a9284d1..1188db6206cd 100644 --- a/include/svx/xit.hxx +++ b/include/svx/xit.hxx @@ -17,47 +17,55 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_SVX_XIT_HXX -#define INCLUDED_SVX_XIT_HXX +#pragma once #include <svl/stritem.hxx> #include <svx/xtable.hxx> #include <svx/svxdllapi.h> #include <unotools/resmgr.hxx> -/************************************************************************/ - class SfxItemPool; class NameOrIndex; -typedef bool (*SvxCompareValueFunc)( const NameOrIndex* p1, const NameOrIndex* p2 ); - - +typedef std::function<bool(const NameOrIndex*, const NameOrIndex*)> SvxCompareValueFunc; class SVXCORE_DLLPUBLIC NameOrIndex : public SfxStringItem { - sal_Int32 m_nPalIndex; + sal_Int32 m_nPalIndex; protected: - void Detach() { m_nPalIndex = -1; } + void Detach() + { + m_nPalIndex = -1; + } public: - DECLARE_ITEM_TYPE_FUNCTION(NameOrIndex) - NameOrIndex() : SfxStringItem(0) { m_nPalIndex = -1; } - NameOrIndex(TypedWhichId<NameOrIndex> nWhich, sal_Int32 nIndex); - NameOrIndex(TypedWhichId<NameOrIndex> nWhich, const OUString& rName); - NameOrIndex(const NameOrIndex& rNameOrIndex); + DECLARE_ITEM_TYPE_FUNCTION(NameOrIndex) + NameOrIndex(); + NameOrIndex(TypedWhichId<NameOrIndex> nWhich, sal_Int32 nIndex); + NameOrIndex(TypedWhichId<NameOrIndex> nWhich, const OUString& rName); + NameOrIndex(const NameOrIndex& rNameOrIndex); - virtual bool operator==(const SfxPoolItem& rItem) const override; + virtual bool operator==(const SfxPoolItem& rItem) const override; virtual NameOrIndex* Clone(SfxItemPool* pPool = nullptr) const override; + // Marked as false since the SfxStringItem superclass supports hashing, but // this class has not been checked for safety under hashing yet. - virtual bool supportsHashCode() const override { return false; } - - OUString const & GetName() const { return GetValue(); } - void SetName(const OUString& rName) { SetValue(rName); } - bool IsIndex() const { return (m_nPalIndex >= 0); } - sal_Int32 GetPalIndex() const { return m_nPalIndex; } + virtual bool supportsHashCode() const override { return false; } + + OUString const & GetName() const + { + return GetValue(); + } + void SetName(const OUString& rName) + { + SetValue(rName); + } + bool IsIndex() const + { + return (m_nPalIndex >= 0); + } + sal_Int32 GetPalIndex() const { return m_nPalIndex; } /** this checks if the given NameOrIndex item has a unique name for its value. The returned String is a unique name for an item with this value in both given pools. @@ -68,6 +76,4 @@ public: void dumpAsXml(xmlTextWriterPtr pWriter) const override; }; -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/xoutdev/xattr.cxx b/svx/source/xoutdev/xattr.cxx index 39dc2e26370c..84468622d9f3 100644 --- a/svx/source/xoutdev/xattr.cxx +++ b/svx/source/xoutdev/xattr.cxx @@ -97,6 +97,12 @@ using namespace ::com::sun::star; typedef std::map<OUString, OUString> StringMap; +NameOrIndex::NameOrIndex() + : SfxStringItem(0) +{ + m_nPalIndex = -1; +} + NameOrIndex::NameOrIndex(TypedWhichId<NameOrIndex> _nWhich, sal_Int32 nIndex) : SfxStringItem(_nWhich, OUString()), m_nPalIndex(nIndex) @@ -270,15 +276,19 @@ void NameOrIndex::dumpAsXml(xmlTextWriterPtr pWriter) const SfxPoolItem* XColorItem::CreateDefault() { return new XColorItem(); } -XColorItem::XColorItem(TypedWhichId<XColorItem> _nWhich, sal_Int32 nIndex, const Color& rTheColor) : - NameOrIndex(_nWhich, nIndex), - m_aColor(rTheColor) +XColorItem::XColorItem() + : NameOrIndex() +{} + +XColorItem::XColorItem(TypedWhichId<XColorItem> _nWhich, sal_Int32 nIndex, const Color& rTheColor) + : NameOrIndex(_nWhich, nIndex) + , m_aColor(rTheColor) { } -XColorItem::XColorItem(TypedWhichId<XColorItem> _nWhich, const OUString& rName, const Color& rTheColor) : - NameOrIndex(_nWhich, rName), - m_aColor(rTheColor) +XColorItem::XColorItem(TypedWhichId<XColorItem> _nWhich, const OUString& rName, const Color& rTheColor) + : NameOrIndex(_nWhich, rName) + , m_aColor(rTheColor) { } @@ -288,10 +298,10 @@ XColorItem::XColorItem(TypedWhichId<XColorItem> _nWhich, const Color& rTheColor) { } -XColorItem::XColorItem(const XColorItem& rItem) : - NameOrIndex(rItem), - m_aColor(rItem.m_aColor), - maComplexColor(rItem.maComplexColor) +XColorItem::XColorItem(const XColorItem& rItem) + : NameOrIndex(rItem) + , m_aColor(rItem.m_aColor) + , maComplexColor(rItem.maComplexColor) { } @@ -307,13 +317,19 @@ bool XColorItem::operator==(const SfxPoolItem& rItem) const static_cast<const XColorItem&>(rItem).maComplexColor == maComplexColor; } -const Color& XColorItem::GetColorValue() const +Color const& XColorItem::GetColorValue() const { assert(!IsIndex()); return m_aColor; } +void XColorItem::SetColorValue(const Color& rNew) +{ + m_aColor = rNew; + Detach(); +} + bool XColorItem::QueryValue( css::uno::Any& rVal, sal_uInt8 nMemberId) const { nMemberId &= ~CONVERT_TWIPS; @@ -1814,13 +1830,17 @@ boost::property_tree::ptree XFillStyleItem::dumpAsJSON() const SfxPoolItem* XFillColorItem::CreateDefault() { return new XFillColorItem; } -XFillColorItem::XFillColorItem(sal_Int32 nIndex, const Color& rTheColor) : - XColorItem(XATTR_FILLCOLOR, nIndex, rTheColor) +XFillColorItem::XFillColorItem() + : XColorItem() +{} + +XFillColorItem::XFillColorItem(sal_Int32 nIndex, const Color& rTheColor) + : XColorItem(XATTR_FILLCOLOR, nIndex, rTheColor) { } -XFillColorItem::XFillColorItem(const OUString& rName, const Color& rTheColor) : - XColorItem(XATTR_FILLCOLOR, rName, rTheColor) +XFillColorItem::XFillColorItem(const OUString& rName, const Color& rTheColor) + : XColorItem(XATTR_FILLCOLOR, rName, rTheColor) { } @@ -1829,13 +1849,8 @@ XFillColorItem* XFillColorItem::Clone(SfxItemPool* /*pPool*/) const return new XFillColorItem(*this); } -bool XFillColorItem::GetPresentation -( - SfxItemPresentation /*ePres*/, - MapUnit /*eCoreUnit*/, - MapUnit /*ePresUnit*/, - OUString& rText, const IntlWrapper& -) const +bool XFillColorItem::GetPresentation(SfxItemPresentation /*ePres*/, MapUnit /*eCoreUnit*/, MapUnit /*ePresUnit*/, + OUString& rText, const IntlWrapper& /*rWrapper*/) const { rText = GetName(); return true;
