include/svx/xfltrit.hxx       |   28 +++++++++++++++---
 svx/source/xoutdev/xattr2.cxx |   65 +++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 88 insertions(+), 5 deletions(-)

New commits:
commit 953219b81126f5c092bf5375c0abe2a7afce40d2
Author:     Noel Grandin <[email protected]>
AuthorDate: Wed Dec 3 21:34:19 2025 +0200
Commit:     Noel Grandin <[email protected]>
CommitDate: Thu Dec 4 17:44:53 2025 +0100

    make XFillTransparenceItem extend SfxPoolItem
    
    so that we can assert when its value is out of range
    
    Change-Id: Icfca58777af4f03bc996630e0702d5ce4196e1fd
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/194964
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <[email protected]>

diff --git a/include/svx/xfltrit.hxx b/include/svx/xfltrit.hxx
index 1f2a9b08052b..68c5b81dc9ac 100644
--- a/include/svx/xfltrit.hxx
+++ b/include/svx/xfltrit.hxx
@@ -20,8 +20,9 @@
 #ifndef INCLUDED_SVX_XFLTRIT_HXX
 #define INCLUDED_SVX_XFLTRIT_HXX
 
-#include <svl/intitem.hxx>
+#include <svl/poolitem.hxx>
 #include <svx/svxdllapi.h>
+#include <boost/property_tree/ptree_fwd.hpp>
 
 /*************************************************************************
 |*
@@ -29,17 +30,36 @@
 |*
 \************************************************************************/
 
-class SVXCORE_DLLPUBLIC XFillTransparenceItem final : public SfxUInt16Item
+class SVXCORE_DLLPUBLIC XFillTransparenceItem final : public SfxPoolItem
 {
+    sal_uInt16 m_nValue;
 public:
-                            DECLARE_ITEM_TYPE_FUNCTION(XFillTransparenceItem)
-                            XFillTransparenceItem(sal_uInt16 nFillTransparence 
= 0);
+//    static SfxPoolItem* CreateDefault();
+
+    DECLARE_ITEM_TYPE_FUNCTION(XFillTransparenceItem)
+    XFillTransparenceItem(sal_uInt16 nFillTransparence = 0);
     virtual XFillTransparenceItem* Clone(SfxItemPool* pPool = nullptr) const 
override;
     virtual bool GetPresentation( SfxItemPresentation ePres,
                                   MapUnit eCoreMetric,
                                   MapUnit ePresMetric,
                                   OUString &rText, const IntlWrapper& ) const 
override;
     void dumpAsXml(xmlTextWriterPtr pWriter) const override;
+    virtual boost::property_tree::ptree dumpAsJSON() const override;
+
+    sal_uInt16 GetValue() const { return m_nValue; }
+    void SetValue(sal_uInt16 nTheValue) { ASSERT_CHANGE_REFCOUNTED_ITEM; 
assert(nTheValue <= 100); m_nValue = nTheValue; }
+
+    virtual bool operator ==(const SfxPoolItem & rItem) const override;
+
+    virtual bool supportsHashCode() const override final;
+    virtual size_t hashCode() const override final;
+
+    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;
+
 };
 
 #endif
diff --git a/svx/source/xoutdev/xattr2.cxx b/svx/source/xoutdev/xattr2.cxx
index 47bc2ecc9587..1131408e4bf5 100644
--- a/svx/source/xoutdev/xattr2.cxx
+++ b/svx/source/xoutdev/xattr2.cxx
@@ -22,7 +22,9 @@
 #include <com/sun/star/uno/Any.hxx>
 
 #include <osl/diagnose.h>
+#include <o3tl/hash_combine.hxx>
 #include <i18nutil/unicode.hxx>
+#include <sal/log.hxx>
 #include <svx/strings.hrc>
 #include <svx/svxids.hrc>
 #include <svx/xlinjoit.hxx>
@@ -49,6 +51,7 @@
 #include <comphelper/lok.hxx>
 
 #include <libxml/xmlwriter.h>
+#include <boost/property_tree/ptree.hpp>
 
 XLineTransparenceItem::XLineTransparenceItem(sal_uInt16 nLineTransparence) :
     SfxUInt16Item(XATTR_LINETRANSPARENCE, nLineTransparence)
@@ -317,8 +320,9 @@ css::drawing::LineCap XLineCapItem::GetValue() const
 }
 
 XFillTransparenceItem::XFillTransparenceItem(sal_uInt16 nFillTransparence) :
-    SfxUInt16Item(XATTR_FILLTRANSPARENCE, nFillTransparence)
+    SfxPoolItem(XATTR_FILLTRANSPARENCE), m_nValue(nFillTransparence)
 {
+    assert(m_nValue <= 100);
 }
 
 XFillTransparenceItem* XFillTransparenceItem::Clone(SfxItemPool* /*pPool*/) 
const
@@ -358,6 +362,65 @@ void XFillTransparenceItem::dumpAsXml(xmlTextWriterPtr 
pWriter) const
     (void)xmlTextWriterEndElement(pWriter);
 }
 
+boost::property_tree::ptree XFillTransparenceItem::dumpAsJSON() const
+{
+    boost::property_tree::ptree aTree = SfxPoolItem::dumpAsJSON();
+    aTree.put("state", GetValue());
+    return aTree;
+}
+
+// virtual
+bool XFillTransparenceItem::operator ==(const SfxPoolItem & rItem) const
+{
+    assert(SfxPoolItem::operator==(rItem));
+    return m_nValue == static_cast<const XFillTransparenceItem 
*>(&rItem)->m_nValue;
+}
+
+// virtual
+bool XFillTransparenceItem::supportsHashCode() const
+{
+    return true;
+}
+
+// virtual
+bool XFillTransparenceItem::QueryValue(css::uno::Any& rVal, sal_uInt8) const
+{
+    rVal <<= m_nValue;
+    return true;
+}
+
+// virtual
+bool XFillTransparenceItem::PutValue(const css::uno::Any& rVal, sal_uInt8)
+{
+    if (rVal >>= m_nValue)
+    {
+        assert(m_nValue <= 100);
+        return true;
+    }
+    // Legacy: for a long time, XFillTransparenceItem::PutValue accepted 
sal_Int32; play safe and accept
+    // if someone passes that
+    if (sal_Int32 nValue; rVal >>= nValue)
+    {
+        SAL_WARN("svl.items", "Passing sal_uInt16 in sal_Int32!");
+        SAL_WARN_IF(nValue < 0 || nValue > SAL_MAX_UINT16, "svl.items",
+                    "Overflow in UInt16 value!");
+        m_nValue = static_cast<sal_uInt16>(nValue);
+        assert(m_nValue <= 100);
+        return true;
+    }
+    SAL_WARN("svl.items", "XFillTransparenceItem::PutValue - Wrong type!");
+    return false;
+}
+
+
+// virtual
+size_t XFillTransparenceItem::hashCode() const
+{
+    std::size_t seed(0);
+    o3tl::hash_combine(seed, Which());
+    o3tl::hash_combine(seed, m_nValue);
+    return seed;
+}
 
 XFormTextShadowTranspItem::XFormTextShadowTranspItem(sal_uInt16 
nShdwTransparence) :
     SfxUInt16Item(XATTR_FORMTXTSHDWTRANSP, nShdwTransparence)

Reply via email to