[Libreoffice-commits] core.git: editeng/source include/editeng

Gülşah Köse (via logerrit) logerrit at kemper.freedesktop.org
Wed May 26 07:05:18 UTC 2021


 editeng/source/items/textitem.cxx |   66 ++++++++++++++++++++++++++++++++------
 include/editeng/colritem.hxx      |   24 ++++++++++++-
 2 files changed, 78 insertions(+), 12 deletions(-)

New commits:
commit 350d40417fe2cb56e16116f12216d08b9f2705b0
Author:     Gülşah Köse <gulsah.kose at collabora.com>
AuthorDate: Wed May 26 08:47:38 2021 +0300
Commit:     Gülşah Köse <gulsah.kose at collabora.com>
CommitDate: Wed May 26 09:04:37 2021 +0200

    Seperate SvxBackgroundColorItem from SvxColorItem
    
    SvxBackgroundColorItem derivated from SfxPoolItem instead of
    SvxColorItem.
    
    Casting is common usage to control if object is this or not.
    When we can cast SvxBackgroundColorItem to SvxColorItem we can not
    seperate them anymore.
    
    eg: Char color is a SvxColorItem and char background color is a
    SvxBackgroundColorItem. They can be hold together and we should
    understand they are different types.
    
    Change-Id: I7b1879a1b00de26c0b8a2d9f8d658aa3aef75ecb
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116135
    Tested-by: Jenkins
    Reviewed-by: Gülşah Köse <gulsah.kose at collabora.com>

diff --git a/editeng/source/items/textitem.cxx b/editeng/source/items/textitem.cxx
index ed4806159a04..d67bd02df5c1 100644
--- a/editeng/source/items/textitem.cxx
+++ b/editeng/source/items/textitem.cxx
@@ -1313,26 +1313,32 @@ bool SvxContourItem::GetPresentation
 // class SvxBackgroundColorItem -----------------------------------------
 
 SvxBackgroundColorItem::SvxBackgroundColorItem( const sal_uInt16 nId ) :
-    SvxColorItem( nId )
+    SfxPoolItem( nId ),
+    mColor( COL_WHITE )
 {
 }
 
+SvxBackgroundColorItem::SvxBackgroundColorItem( const Color& rCol, const sal_uInt16 nId ) :
+    SfxPoolItem( nId ),
+    mColor( rCol )
+{
+}
 
-SvxBackgroundColorItem::SvxBackgroundColorItem( const Color& rCol,
-                                                const sal_uInt16 nId ) :
-    SvxColorItem( rCol, nId )
+SvxBackgroundColorItem::~SvxBackgroundColorItem()
 {
 }
 
-SvxBackgroundColorItem* SvxBackgroundColorItem::Clone( SfxItemPool * ) const
+bool SvxBackgroundColorItem::operator==( const SfxPoolItem& rAttr ) const
 {
-    return new SvxBackgroundColorItem(*this);
+    assert(SfxPoolItem::operator==(rAttr));
+
+    return  mColor == static_cast<const SvxBackgroundColorItem&>( rAttr ).mColor;
 }
 
 bool SvxBackgroundColorItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
 {
     nMemberId &= ~CONVERT_TWIPS;
-    Color aColor = SvxColorItem::GetValue();
+    Color aColor = SvxBackgroundColorItem::GetValue();
 
     switch( nMemberId )
     {
@@ -1354,27 +1360,67 @@ bool SvxBackgroundColorItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId
 {
     nMemberId &= ~CONVERT_TWIPS;
     Color nColor;
-    Color aColor = SvxColorItem::GetValue();
+    Color aColor = SvxBackgroundColorItem::GetValue();
 
     switch( nMemberId )
     {
         case MID_GRAPHIC_TRANSPARENT:
         {
             aColor.SetAlpha( Any2Bool( rVal ) ? 0 : 255 );
-            SvxColorItem::SetValue( aColor );
+            SvxBackgroundColorItem::SetValue( aColor );
             break;
         }
         default:
         {
             if(!(rVal >>= nColor))
                 return false;
-            SvxColorItem::SetValue( nColor );
+            SvxBackgroundColorItem::SetValue( nColor );
             break;
         }
     }
     return true;
 }
 
+SvxBackgroundColorItem* SvxBackgroundColorItem::Clone( SfxItemPool * ) const
+{
+    return new SvxBackgroundColorItem(*this);
+}
+
+
+bool SvxBackgroundColorItem::GetPresentation
+(
+    SfxItemPresentation /*ePres*/,
+    MapUnit             /*eCoreUnit*/,
+    MapUnit             /*ePresUnit*/,
+    OUString&           rText, const IntlWrapper& /*rIntl*/
+)   const
+{
+    rText = ::GetColorString( mColor );
+    return true;
+}
+
+void SvxBackgroundColorItem::dumpAsXml(xmlTextWriterPtr pWriter) const
+{
+    (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SvxBackgroundColorItem"));
+    (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
+
+    std::stringstream ss;
+    ss << mColor;
+    (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"), BAD_CAST(ss.str().c_str()));
+
+    OUString aStr;
+    IntlWrapper aIntlWrapper(SvtSysLocale().GetUILanguageTag());
+    GetPresentation( SfxItemPresentation::Complete, MapUnit::Map100thMM, MapUnit::Map100thMM, aStr, aIntlWrapper);
+    (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("presentation"), BAD_CAST(OUStringToOString(aStr, RTL_TEXTENCODING_UTF8).getStr()));
+    (void)xmlTextWriterEndElement(pWriter);
+}
+
+void SvxBackgroundColorItem::SetValue( const Color& rNewCol )
+{
+    mColor = rNewCol;
+}
+
+
 // class SvxColorItem ----------------------------------------------------
 SvxColorItem::SvxColorItem( const sal_uInt16 nId ) :
     SfxPoolItem( nId ),
diff --git a/include/editeng/colritem.hxx b/include/editeng/colritem.hxx
index 1eab79723577..8e081fc6aab1 100644
--- a/include/editeng/colritem.hxx
+++ b/include/editeng/colritem.hxx
@@ -61,17 +61,37 @@ public:
 };
 
 // XXX: to be moved in a separate header.
-class EDITENG_DLLPUBLIC SvxBackgroundColorItem final : public SvxColorItem
+class EDITENG_DLLPUBLIC SvxBackgroundColorItem final : public SfxPoolItem
 {
+private:
+    Color mColor;
+
 public:
     static SfxPoolItem* CreateDefault();
 
     SvxBackgroundColorItem(const sal_uInt16 nId);
     SvxBackgroundColorItem(const Color& rCol, const sal_uInt16 nId);
+    virtual ~SvxBackgroundColorItem() override;
 
-    virtual SvxBackgroundColorItem* Clone(SfxItemPool* pPool = nullptr) const override;
+    virtual bool operator==(const SfxPoolItem& rPoolItem) 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 GetPresentation(SfxItemPresentation ePres,
+                                 MapUnit eCoreMetric, MapUnit ePresMetric,
+                                 OUString &rText, const IntlWrapper& rIntlWrapper) const override;
+
+    virtual SvxBackgroundColorItem* Clone(SfxItemPool* pPool = nullptr) const override;
+    SvxBackgroundColorItem(SvxBackgroundColorItem const &) = default; // SfxPoolItem copy function dichotomy
+
+    const Color& GetValue() const
+    {
+        return mColor;
+    }
+
+    void SetValue(const Color& rNewColor);
+
+    void dumpAsXml(xmlTextWriterPtr pWriter) const override;
 };
 
 #endif


More information about the Libreoffice-commits mailing list