[Libreoffice-commits] core.git: 5 commits - sw/source

Bjoern Michaelsen bjoern.michaelsen at canonical.com
Fri Jan 1 16:45:22 PST 2016


 sw/source/core/unocore/unostyle.cxx |  163 ++++++++++++++++--------------------
 1 file changed, 73 insertions(+), 90 deletions(-)

New commits:
commit b4082bed2de12cd576a06a9f456a71101809f3ed
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date:   Sat Jan 2 01:12:51 2016 +0100

    make this temp override of ItemSet more explicit and scoped
    
    Change-Id: I8a02be2772b8f7c0d1b13556d0c49f1b00bcc1aa

diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx
index 42a8f11..8caa0dd 100644
--- a/sw/source/core/unocore/unostyle.cxx
+++ b/sw/source/core/unocore/unostyle.cxx
@@ -1320,7 +1320,6 @@ private:
     std::unique_ptr<SfxItemSet> m_pMyItemSet;
     OUString m_rStyleName;
     const SwAttrSet* m_pParentStyle;
-
 public:
     SwStyleBase_Impl(SwDoc& rSwDoc, const OUString& rName, const SwAttrSet* pParentStyle)
         : m_rDoc(rSwDoc)
@@ -1346,13 +1345,6 @@ public:
         return m_xNewBase.is();
     }
 
-    SfxItemSet* replaceItemSet(SfxItemSet* pNew)
-    {
-        SfxItemSet* pRetval = m_pItemSet;
-        m_pItemSet = pNew;
-        return pRetval;
-    }
-
     SfxItemSet& GetItemSet()
     {
         assert(m_xNewBase.is());
@@ -1369,6 +1361,19 @@ public:
     }
 
     const SwPageDesc* GetOldPageDesc();
+
+    // still a hack, but a bit more explicit and with a proper scope
+    struct ItemSetOverrider
+    {
+        SwStyleBase_Impl& m_rStyleBase;
+        SfxItemSet* m_pOldSet;
+        ItemSetOverrider(SwStyleBase_Impl& rStyleBase, SfxItemSet* pTemp)
+                : m_rStyleBase(rStyleBase)
+                , m_pOldSet(m_rStyleBase.m_pItemSet)
+        { m_rStyleBase.m_pItemSet = pTemp; }
+        ~ItemSetOverrider()
+        { m_rStyleBase.m_pItemSet = m_pOldSet; };
+    };
 };
 
 const SwPageDesc* SwStyleBase_Impl::GetOldPageDesc()
@@ -1394,6 +1399,7 @@ const SwPageDesc* SwStyleBase_Impl::GetOldPageDesc()
     return m_pOldPageDesc;
 }
 
+
 static void lcl_SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry,
                         const SfxItemPropertySet& rPropSet,
                         const uno::Any& rValue,
@@ -3058,9 +3064,10 @@ static void lcl_putItemToSet(const SvxSetItem* pSetItem, const SfxItemPropertySe
 
     // replace the used SfxItemSet at the SwStyleBase_Impl temporarily and use the
     // default method to set the property
-    SfxItemSet* pRememberItemSet = rBaseImpl.replaceItemSet(&rSetSet);
-    lcl_SetStyleProperty(rEntry, rPropSet, rVal, rBaseImpl, pPool, pDoc, eFamily);
-    rBaseImpl.replaceItemSet(pRememberItemSet);
+    {
+        SwStyleBase_Impl::ItemSetOverrider o(rBaseImpl, &rSetSet);
+        lcl_SetStyleProperty(rEntry, rPropSet, rVal, rBaseImpl, pPool, pDoc, eFamily);
+    }
 
     // reset paret at ItemSet from SetItem
     rSetSet.SetParent(nullptr);
@@ -3261,9 +3268,10 @@ void SAL_CALL SwXPageStyle::SetPropertyValues_Impl(
 
                             // replace the used SfxItemSet at the SwStyleBase_Impl temporarily and use the
                             // default method to set the property
-                            SfxItemSet* pRememberItemSet = aBaseImpl.replaceItemSet(&rSetSet);
-                            lcl_SetStyleProperty(*pEntry, *pPropSet, pValues[nProp], aBaseImpl, m_pBasePool, GetDoc(), GetFamily());
-                            aBaseImpl.replaceItemSet(pRememberItemSet);
+                            {
+                                SwStyleBase_Impl::ItemSetOverrider o(aBaseImpl, &rSetSet);
+                                lcl_SetStyleProperty(*pEntry, *pPropSet, pValues[nProp], aBaseImpl, m_pBasePool, GetDoc(), GetFamily());
+                            }
 
                             // reset paret at ItemSet from SetItem
                             rSetSet.SetParent(nullptr);
@@ -3452,9 +3460,10 @@ uno::Sequence< uno::Any > SAL_CALL SwXPageStyle::GetPropertyValues_Impl(
                         {
                             // get from SfxItemSet of the corresponding SfxSetItem
                             const SfxItemSet& rSetSet = pSetItem->GetItemSet();
-                            SfxItemSet* pRememberItemSet = aBase.replaceItemSet(&const_cast< SfxItemSet& >(rSetSet));
-                            pRet[nProp] = lcl_GetStyleProperty(*pEntry, *pPropSet, aBase, pBase, GetFamily(), GetDoc() );
-                            aBase.replaceItemSet(pRememberItemSet);
+                            {
+                                SwStyleBase_Impl::ItemSetOverrider o(aBase, &const_cast< SfxItemSet& >(rSetSet));
+                                pRet[nProp] = lcl_GetStyleProperty(*pEntry, *pPropSet, aBase, pBase, GetFamily(), GetDoc());
+                            }
                         }
                         else if(pEntry->nWID == SID_ATTR_PAGE_ON)
                         {
@@ -3522,9 +3531,10 @@ uno::Sequence< uno::Any > SAL_CALL SwXPageStyle::GetPropertyValues_Impl(
                         {
                             // set at SfxItemSet of the corresponding SfxSetItem
                             const SfxItemSet& rSetSet = pSetItem->GetItemSet();
-                            SfxItemSet* pRememberItemSet = aBase.replaceItemSet(&const_cast< SfxItemSet& >(rSetSet));
-                            pRet[nProp] = lcl_GetStyleProperty(*pEntry, *pPropSet, aBase, pBase, GetFamily(), GetDoc() );
-                            aBase.replaceItemSet(pRememberItemSet);
+                            {
+                                SwStyleBase_Impl::ItemSetOverrider o(aBase, &const_cast<SfxItemSet&>(rSetSet));
+                                pRet[nProp] = lcl_GetStyleProperty(*pEntry, *pPropSet, aBase, pBase, GetFamily(), GetDoc());
+                            }
                         }
                     }
                     else
commit 952f41ed0806cd8bfbd568a7c87df7f6368fdca9
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date:   Sat Jan 2 00:53:13 2016 +0100

    trying to chip away some of the memory mgmt madness here
    
    - mpItemSet is assumed to be owned by SwStyleBase_Impl
    - yet it can be external set to any naked pointer
    - ... and is (temporary, at least that is the hope) set to ItemSets
      owned by others
    
    Change-Id: I0cd56f5bb9f58a2e5ab09f49f66faf8a63c69f37

diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx
index 88a7df4..42a8f11 100644
--- a/sw/source/core/unocore/unostyle.cxx
+++ b/sw/source/core/unocore/unostyle.cxx
@@ -1317,6 +1317,7 @@ private:
     const SwPageDesc* m_pOldPageDesc;
     rtl::Reference<SwDocStyleSheet> m_xNewBase;
     SfxItemSet* m_pItemSet;
+    std::unique_ptr<SfxItemSet> m_pMyItemSet;
     OUString m_rStyleName;
     const SwAttrSet* m_pParentStyle;
 
@@ -1325,15 +1326,10 @@ public:
         : m_rDoc(rSwDoc)
         , m_pOldPageDesc(nullptr)
         , m_pItemSet(nullptr)
+        , m_pMyItemSet(nullptr)
         , m_rStyleName(rName)
         , m_pParentStyle(pParentStyle)
-    {
-    }
-
-    ~SwStyleBase_Impl()
-    {
-        delete m_pItemSet;
-    }
+    { }
 
     rtl::Reference<SwDocStyleSheet>& getNewBase()
     {
@@ -1359,16 +1355,15 @@ public:
 
     SfxItemSet& GetItemSet()
     {
-        OSL_ENSURE(m_xNewBase.is(), "no SwDocStyleSheet available");
+        assert(m_xNewBase.is());
         if(!m_pItemSet)
         {
-            m_pItemSet = new SfxItemSet(m_xNewBase->GetItemSet());
+            m_pMyItemSet.reset(new SfxItemSet(m_xNewBase->GetItemSet()));
+            m_pItemSet = m_pMyItemSet.get();
 
             //UUUU set parent style to have the correct XFillStyle setting as XFILL_NONE
             if(!m_pItemSet->GetParent() && m_pParentStyle)
-            {
                 m_pItemSet->SetParent(m_pParentStyle);
-            }
         }
         return *m_pItemSet;
     }
commit bcf90db8c57fc48d20ee2d2cdec8666c214fe525
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date:   Sat Jan 2 00:43:16 2016 +0100

    code conventions: member prefix
    
    ... also kill some plenking
    
    Change-Id: I03c0669239bba5f63a7dc5a078f5b4c4f2a51386

diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx
index 386d93c..88a7df4 100644
--- a/sw/source/core/unocore/unostyle.cxx
+++ b/sw/source/core/unocore/unostyle.cxx
@@ -1313,64 +1313,64 @@ void SwXStyle::ApplyDescriptorProperties()
 class SwStyleBase_Impl
 {
 private:
-    SwDoc& mrDoc;
-    const SwPageDesc* mpOldPageDesc;
-    rtl::Reference< SwDocStyleSheet > mxNewBase;
-    SfxItemSet* mpItemSet;
-    OUString mrStyleName;
-    const SwAttrSet*                    mpParentStyle;
+    SwDoc& m_rDoc;
+    const SwPageDesc* m_pOldPageDesc;
+    rtl::Reference<SwDocStyleSheet> m_xNewBase;
+    SfxItemSet* m_pItemSet;
+    OUString m_rStyleName;
+    const SwAttrSet* m_pParentStyle;
 
 public:
     SwStyleBase_Impl(SwDoc& rSwDoc, const OUString& rName, const SwAttrSet* pParentStyle)
-        : mrDoc(rSwDoc)
-        , mpOldPageDesc(nullptr)
-        , mpItemSet(nullptr)
-        , mrStyleName(rName)
-        , mpParentStyle(pParentStyle)
+        : m_rDoc(rSwDoc)
+        , m_pOldPageDesc(nullptr)
+        , m_pItemSet(nullptr)
+        , m_rStyleName(rName)
+        , m_pParentStyle(pParentStyle)
     {
     }
 
     ~SwStyleBase_Impl()
     {
-        delete mpItemSet;
+        delete m_pItemSet;
     }
 
-    rtl::Reference< SwDocStyleSheet >& getNewBase()
+    rtl::Reference<SwDocStyleSheet>& getNewBase()
     {
-        return mxNewBase;
+        return m_xNewBase;
     }
 
     void setNewBase(SwDocStyleSheet* pNew)
     {
-        mxNewBase = pNew;
+        m_xNewBase = pNew;
     }
 
     bool HasItemSet() const
     {
-        return mxNewBase.is();
+        return m_xNewBase.is();
     }
 
     SfxItemSet* replaceItemSet(SfxItemSet* pNew)
     {
-        SfxItemSet* pRetval = mpItemSet;
-        mpItemSet = pNew;
+        SfxItemSet* pRetval = m_pItemSet;
+        m_pItemSet = pNew;
         return pRetval;
     }
 
     SfxItemSet& GetItemSet()
     {
-        OSL_ENSURE(mxNewBase.is(), "no SwDocStyleSheet available");
-        if (!mpItemSet)
+        OSL_ENSURE(m_xNewBase.is(), "no SwDocStyleSheet available");
+        if(!m_pItemSet)
         {
-            mpItemSet = new SfxItemSet(mxNewBase->GetItemSet());
+            m_pItemSet = new SfxItemSet(m_xNewBase->GetItemSet());
 
             //UUUU set parent style to have the correct XFillStyle setting as XFILL_NONE
-            if(!mpItemSet->GetParent() && mpParentStyle)
+            if(!m_pItemSet->GetParent() && m_pParentStyle)
             {
-                mpItemSet->SetParent(mpParentStyle);
+                m_pItemSet->SetParent(m_pParentStyle);
             }
         }
-        return *mpItemSet;
+        return *m_pItemSet;
     }
 
     const SwPageDesc* GetOldPageDesc();
@@ -1378,25 +1378,25 @@ public:
 
 const SwPageDesc* SwStyleBase_Impl::GetOldPageDesc()
 {
-    if(!mpOldPageDesc)
+    if(!m_pOldPageDesc)
     {
-        SwPageDesc *pd = mrDoc.FindPageDesc( mrStyleName );
-        if( pd )
-            mpOldPageDesc = pd;
+        SwPageDesc *pd = m_rDoc.FindPageDesc(m_rStyleName);
+        if(pd)
+            m_pOldPageDesc = pd;
 
-        if(!mpOldPageDesc)
+        if(!m_pOldPageDesc)
         {
             for(sal_uInt16 i = RC_POOLPAGEDESC_BEGIN; i <= STR_POOLPAGE_LANDSCAPE; ++i)
             {
-                if(SW_RESSTR(i) == mrStyleName)
+                if(SW_RESSTR(i) == m_rStyleName)
                 {
-                    mpOldPageDesc = mrDoc.getIDocumentStylePoolAccess().GetPageDescFromPool( static_cast< sal_uInt16 >(RES_POOLPAGE_BEGIN + i - RC_POOLPAGEDESC_BEGIN) );
+                    m_pOldPageDesc = m_rDoc.getIDocumentStylePoolAccess().GetPageDescFromPool( static_cast<sal_uInt16>(RES_POOLPAGE_BEGIN + i - RC_POOLPAGEDESC_BEGIN));
                     break;
                 }
             }
         }
     }
-    return mpOldPageDesc;
+    return m_pOldPageDesc;
 }
 
 static void lcl_SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry,
commit c0de4c077c4e445a4c8e85eec05b866a41b7d405
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date:   Fri Jan 1 23:29:17 2016 +0100

    refactor SwXStyle::SetPropertyValues_Impl
    
    - reduce scope of getConstArray variables
    - use m_nPropMapType directly
    - remove some plenking
    
    Change-Id: Id507cffe2563bf078fe5e3e2a8267f352533844e

diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx
index 00f61cb..386d93c 100644
--- a/sw/source/core/unocore/unostyle.cxx
+++ b/sw/source/core/unocore/unostyle.cxx
@@ -1982,29 +1982,12 @@ void SAL_CALL SwXStyle::SetPropertyValues_Impl(
            lang::IllegalArgumentException, lang::WrappedTargetException,
            uno::RuntimeException, std::exception)
 {
-    if ( !m_pDoc )
+    if(!m_pDoc)
         throw uno::RuntimeException();
-
-    sal_Int8 nPropSetId = PROPERTY_MAP_CHAR_STYLE;
-
-    switch(m_rEntry.m_eFamily)
-    {
-        case SFX_STYLE_FAMILY_PARA  : nPropSetId = m_bIsConditional ? PROPERTY_MAP_CONDITIONAL_PARA_STYLE : PROPERTY_MAP_PARA_STYLE; break;
-        case SFX_STYLE_FAMILY_FRAME : nPropSetId = PROPERTY_MAP_FRAME_STYLE ;break;
-        case SFX_STYLE_FAMILY_PAGE  : nPropSetId = PROPERTY_MAP_PAGE_STYLE  ;break;
-        case SFX_STYLE_FAMILY_PSEUDO: nPropSetId = PROPERTY_MAP_NUM_STYLE   ;break;
-        default: ;
-    }
-    const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(nPropSetId);
+    const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(m_rEntry.m_nPropMapType);
     const SfxItemPropertyMap &rMap = pPropSet->getPropertyMap();
-
     if(rPropertyNames.getLength() != rValues.getLength())
-    {
         throw lang::IllegalArgumentException();
-    }
-
-    const OUString* pNames = rPropertyNames.getConstArray();
-    const uno::Any* pValues = rValues.getConstArray();
 
     SwStyleBase_Impl aBaseImpl(*m_pDoc, m_sStyleName, &GetDoc()->GetDfltTextFormatColl()->GetAttrSet()); //UUUU add pDfltTextFormatColl as parent
     if(m_pBasePool)
@@ -2012,23 +1995,23 @@ void SAL_CALL SwXStyle::SetPropertyValues_Impl(
         const sal_uInt16 nSaveMask = m_pBasePool->GetSearchMask();
         m_pBasePool->SetSearchMask(m_rEntry.m_eFamily);
         SfxStyleSheetBase* pBase = m_pBasePool->Find(m_sStyleName);
-        m_pBasePool->SetSearchMask(m_rEntry.m_eFamily, nSaveMask );
-        OSL_ENSURE(pBase, "where is the style?" );
+        m_pBasePool->SetSearchMask(m_rEntry.m_eFamily, nSaveMask);
+        OSL_ENSURE(pBase, "where is the style?");
         if(pBase)
             aBaseImpl.setNewBase(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase)));
         else
             throw uno::RuntimeException();
     }
 
+    const OUString* pNames = rPropertyNames.getConstArray();
+    const uno::Any* pValues = rValues.getConstArray();
     for(sal_Int32 nProp = 0; nProp < rPropertyNames.getLength(); ++nProp)
     {
         const SfxItemPropertySimpleEntry* pEntry = rMap.getByName(pNames[nProp]);
-
-        if(!pEntry ||
-           (!m_bIsConditional && pNames[nProp] == UNO_NAME_PARA_STYLE_CONDITIONS))
-            throw beans::UnknownPropertyException("Unknown property: " + pNames[nProp], static_cast < cppu::OWeakObject * > ( this ) );
-        if ( pEntry->nFlags & beans::PropertyAttribute::READONLY)
-            throw beans::PropertyVetoException ("Property is read-only: " + pNames[nProp], static_cast < cppu::OWeakObject * > ( this ) );
+        if(!pEntry || (!m_bIsConditional && pNames[nProp] == UNO_NAME_PARA_STYLE_CONDITIONS))
+            throw beans::UnknownPropertyException("Unknown property: " + pNames[nProp], static_cast<cppu::OWeakObject*>(this));
+        if(pEntry->nFlags & beans::PropertyAttribute::READONLY)
+            throw beans::PropertyVetoException ("Property is read-only: " + pNames[nProp], static_cast<cppu::OWeakObject*>(this));
         if(aBaseImpl.getNewBase().is())
         {
             lcl_SetStyleProperty(*pEntry, *pPropSet, pValues[nProp], aBaseImpl, m_pBasePool, m_pDoc, m_rEntry.m_eFamily);
commit fc73c5a3ee32e7e4c80381d74d4bfc74ca3489a5
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date:   Fri Jan 1 23:18:58 2016 +0100

    remove desd code
    
    Change-Id: Ifc81677eb3331a786a964f89aa425916df6364b4

diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx
index ffb0f0f..00f61cb 100644
--- a/sw/source/core/unocore/unostyle.cxx
+++ b/sw/source/core/unocore/unostyle.cxx
@@ -359,11 +359,6 @@ public:
     void Invalidate();
     void ApplyDescriptorProperties();
     void SetStyleName(const OUString& rSet){ m_sStyleName = rSet;}
-    virtual const SwTextFormatColl* GetFormatColl() const
-    {
-        assert(m_rEntry.m_eFamily == SFX_STYLE_FAMILY_PARA);
-        return m_pDoc->FindTextFormatCollByName(GetStyleName());
-    }
 };
 
 class SwXFrameStyle


More information about the Libreoffice-commits mailing list