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

Bjoern Michaelsen (via logerrit) logerrit at kemper.freedesktop.org
Sat Sep 7 06:23:43 UTC 2019


 sw/inc/unodraw.hxx                  |   31 +++++++---
 sw/source/core/unocore/unodraw.cxx  |  106 ++++++++++++++++++------------------
 sw/source/core/unocore/unofield.cxx |    1 
 sw/source/core/unocore/unoframe.cxx |    1 
 sw/source/uibase/uno/unotxvw.cxx    |    3 -
 5 files changed, 78 insertions(+), 64 deletions(-)

New commits:
commit f2bc27972c13f54c4860a3ca995017bc5ad84e6e
Author:     Bjoern Michaelsen <bjoern.michaelsen at libreoffice.org>
AuthorDate: Fri Sep 6 23:36:23 2019 +0200
Commit:     Björn Michaelsen <bjoern.michaelsen at libreoffice.org>
CommitDate: Sat Sep 7 08:23:17 2019 +0200

    kill SwXShape SwClient
    
    this completely removes calbck.hxx from sw/source/core/unocore -- may it
    never return.
    
    Change-Id: Ie4c8b3a29fd4038a19c34116d47672b504ee9f2c
    Reviewed-on: https://gerrit.libreoffice.org/78735
    Tested-by: Jenkins
    Reviewed-by: Björn Michaelsen <bjoern.michaelsen at libreoffice.org>

diff --git a/sw/inc/unodraw.hxx b/sw/inc/unodraw.hxx
index 6bfa4839eba7..2938e7a79114 100644
--- a/sw/inc/unodraw.hxx
+++ b/sw/inc/unodraw.hxx
@@ -20,6 +20,7 @@
 #define INCLUDED_SW_INC_UNODRAW_HXX
 
 #include <svl/itemprop.hxx>
+#include <svl/listener.hxx>
 #include <svx/fmdpage.hxx>
 #include "calbck.hxx"
 #include "frmfmt.hxx"
@@ -130,12 +131,13 @@ cppu::WeakAggImplHelper6
     css::drawing::XShape
 >
 SwXShapeBaseClass;
-class SwXShape : public SwXShapeBaseClass, public SwClient
+class SwXShape : public SwXShapeBaseClass, public SvtListener
 {
     friend class SwXGroupShape;
     friend class SwXDrawPage;
     friend class SwFmDrawPage;
     const SwFmDrawPage* m_pPage;
+    SwFrameFormat* m_pFormat;
 
     css::uno::Reference< css::uno::XAggregation > xShapeAgg;
     // reference to <XShape>, determined in the
@@ -197,13 +199,19 @@ class SwXShape : public SwXShapeBaseClass, public SwClient
         @throws css::uno::RuntimeException
     */
     css::uno::Any _getPropAtAggrObj( const OUString& _rPropertyName );
+    void SetFrameFormat(SwFrameFormat* pFormat)
+    {
+        EndListeningAll();
+        StartListening(pFormat->GetNotifier());
+        m_pFormat = pFormat;
+    }
 
 protected:
     virtual ~SwXShape() override;
-    void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew) override;
 public:
     SwXShape(css::uno::Reference<css::uno::XInterface> & xShape, SwDoc const*const pDoc);
 
+    virtual void Notify(const SfxHint&) override;
     static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId();
     virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override;
     virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes(  ) override;
@@ -248,7 +256,7 @@ public:
     virtual OUString SAL_CALL getShapeType(  ) override;
 
     SwShapeDescriptor_Impl*     GetDescImpl() {return pImpl.get();}
-    SwFrameFormat*               GetFrameFormat() const { return const_cast<SwFrameFormat*>(static_cast<const SwFrameFormat*>(GetRegisteredIn())); }
+    SwFrameFormat* GetFrameFormat() const { return m_pFormat; }
     const css::uno::Reference< css::uno::XAggregation >& GetAggregationInterface() {return xShapeAgg;}
 
     // helper
diff --git a/sw/source/core/unocore/unodraw.cxx b/sw/source/core/unocore/unodraw.cxx
index e91e4168c7fb..be29668a6b40 100644
--- a/sw/source/core/unocore/unodraw.cxx
+++ b/sw/source/core/unocore/unodraw.cxx
@@ -72,7 +72,6 @@
 #include <basegfx/matrix/b2dhommatrixtools.hxx>
 #include <com/sun/star/drawing/PointSequence.hpp>
 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
-#include <calbck.hxx>
 
 using namespace ::com::sun::star;
 
@@ -575,7 +574,7 @@ void SwXDrawPage::add(const uno::Reference< drawing::XShape > & xShape)
                                     static_cast< cppu::OWeakObject * > ( this ) );
 
     // we're already registered in the model / SwXDrawPage::add() already called
-    if(pShape->m_pPage || pShape->GetRegisteredIn() || !pShape->m_bDescriptor )
+    if(pShape->m_pPage || pShape->m_pFormat || !pShape->m_bDescriptor )
         return;
 
     // we're inserted elsewhere already
@@ -711,7 +710,7 @@ void SwXDrawPage::add(const uno::Reference< drawing::XShape > & xShape)
     pDoc->getIDocumentContentOperations().InsertDrawObj( *pTemp, *pObj, aSet );
     SwFrameFormat* pFormat = ::FindFrameFormat( pObj );
     if(pFormat)
-        pFormat->Add(pShape);
+        pShape->SetFrameFormat(pFormat);
     pShape->m_bDescriptor = false;
 
     pPam.reset();
@@ -871,6 +870,7 @@ SwXShape::SwXShape(
         uno::Reference<uno::XInterface> & xShape,
         SwDoc const*const pDoc)
     : m_pPage(nullptr)
+    , m_pFormat(nullptr)
     , m_pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXT_SHAPE))
     , m_pPropertyMapEntries(aSwMapProvider.GetPropertyMapEntries(PROPERTY_MAP_TEXT_SHAPE))
     , pImpl(new SwShapeDescriptor_Impl(pDoc))
@@ -907,9 +907,9 @@ SwXShape::SwXShape(
     SdrObject* pObj = pShape ? pShape->GetSdrObject() : nullptr;
     if(pObj)
     {
-        SwFrameFormat* pFormat = ::FindFrameFormat( pObj );
+        auto pFormat = ::FindFrameFormat( pObj );
         if(pFormat)
-            pFormat->Add(this);
+            SetFrameFormat(pFormat);
 
         lcl_addShapePropertyEventFactories( *pObj, *this );
         pImpl->bInitializedPropertyNotifier = true;
@@ -936,9 +936,9 @@ void SwXShape::AddExistingShapeToFormat( SdrObject const & _rObj )
         {
             if ( pSwShape->m_bDescriptor )
             {
-                SwFrameFormat* pFormat = ::FindFrameFormat( pCurrent );
+                auto pFormat = ::FindFrameFormat( pCurrent );
                 if ( pFormat )
-                    pFormat->Add( pSwShape );
+                    pSwShape->SetFrameFormat(pFormat);
                 pSwShape->m_bDescriptor = false;
             }
 
@@ -1984,9 +1984,13 @@ void SwXShape::removeVetoableChangeListener(
     OSL_FAIL("not implemented");
 }
 
-void SwXShape::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew)
+void SwXShape::Notify(const SfxHint& rHint)
 {
-    ClientModify(this, pOld, pNew);
+    if(rHint.GetId() == SfxHintId::Dying)
+    {
+        m_pFormat = nullptr;
+        EndListeningAll();
+    }
 }
 
 void SwXShape::attach(const uno::Reference< text::XTextRange > & xTextRange)
@@ -2754,8 +2758,9 @@ void SwXGroupShape::add( const uno::Reference< XShape >& xShape )
         pSwShape->m_bDescriptor = false;
         //add the group member to the format of the group
         SwFrameFormat* pShapeFormat = ::FindFrameFormat( pSvxShape->GetSdrObject() );
+
         if(pShapeFormat)
-            pFormat->Add(pSwShape);
+            pSwShape->SetFrameFormat(pShapeFormat);
     }
 
 }
diff --git a/sw/source/core/unocore/unofield.cxx b/sw/source/core/unocore/unofield.cxx
index 729bc6ecb1e3..a23a88b85121 100644
--- a/sw/source/core/unocore/unofield.cxx
+++ b/sw/source/core/unocore/unofield.cxx
@@ -96,7 +96,6 @@
 #include <editeng/outliner.hxx>
 #include <docsh.hxx>
 #include <fmtmeta.hxx>
-#include <calbck.hxx>
 #include <rtl/strbuf.hxx>
 #include <editeng/outlobj.hxx>
 #include <vector>
diff --git a/sw/source/core/unocore/unoframe.cxx b/sw/source/core/unocore/unoframe.cxx
index 5ed7b51c6cc6..aa978f2962ea 100644
--- a/sw/source/core/unocore/unoframe.cxx
+++ b/sw/source/core/unocore/unoframe.cxx
@@ -125,7 +125,6 @@
 #include <fmtfollowtextflow.hxx>
 #include <fmtwrapinfluenceonobjpos.hxx>
 #include <toolkit/helper/vclunohelper.hxx>
-#include <calbck.hxx>
 #include <comphelper/servicehelper.hxx>
 #include <cppuhelper/supportsservice.hxx>
 #include <sal/log.hxx>
commit 8ac6d2e7e7293e7c5f4bb79ab7b36a843b2c3175
Author:     Bjoern Michaelsen <bjoern.michaelsen at libreoffice.org>
AuthorDate: Thu Sep 5 01:17:47 2019 +0200
Commit:     Björn Michaelsen <bjoern.michaelsen at libreoffice.org>
CommitDate: Sat Sep 7 08:23:08 2019 +0200

    make page bookkeep the SwXShapes
    
    - and remove SwClient/Modify between SwXShape and Page
    
    Change-Id: I482f5357dbd361e957fef54b5cbc594351c70b96
    Reviewed-on: https://gerrit.libreoffice.org/78734
    Tested-by: Jenkins
    Reviewed-by: Björn Michaelsen <bjoern.michaelsen at libreoffice.org>

diff --git a/sw/inc/unodraw.hxx b/sw/inc/unodraw.hxx
index b3013e4da610..6bfa4839eba7 100644
--- a/sw/inc/unodraw.hxx
+++ b/sw/inc/unodraw.hxx
@@ -38,10 +38,12 @@
 class SdrMarkList;
 class SdrView;
 class SwDoc;
+class SwXShape;
 
 class SwFmDrawPage : public SvxFmDrawPage
 {
     SdrPageView*        pPageView;
+    std::vector<SwXShape*> m_vShapes;
 public:
     SwFmDrawPage( SdrPage* pPage );
     virtual ~SwFmDrawPage() throw () override;
@@ -52,12 +54,19 @@ public:
     SdrView*            GetDrawView() {return mpView.get();}
     SdrPageView*        GetPageView();
     void                RemovePageView();
-    static css::uno::Reference< css::uno::XInterface >       GetInterface( SdrObject* pObj );
+    static css::uno::Reference<css::drawing::XShape> GetShape(SdrObject* pObj);
+    static css::uno::Reference<css::drawing::XShapeGroup> GetShapeGroup(SdrObject* pObj);
 
     // The following method is called when a SvxShape-object is to be created.
     // Derived classes may obtain at this point a derivation or an object
     // that is aggregating a SvxShape.
     virtual css::uno::Reference< css::drawing::XShape >  CreateShape( SdrObject *pObj ) const override;
+    void RemoveShape(const SwXShape* pShape)
+    {
+        auto ppShape = find(m_vShapes.begin(), m_vShapes.end(), pShape);
+        if(ppShape != m_vShapes.end())
+            m_vShapes.erase(ppShape);
+    };
 };
 
 typedef cppu::WeakAggImplHelper4
@@ -121,12 +130,12 @@ cppu::WeakAggImplHelper6
     css::drawing::XShape
 >
 SwXShapeBaseClass;
-class SwXShape : public SwXShapeBaseClass,
-    public SwClient
+class SwXShape : public SwXShapeBaseClass, public SwClient
 {
     friend class SwXGroupShape;
     friend class SwXDrawPage;
     friend class SwFmDrawPage;
+    const SwFmDrawPage* m_pPage;
 
     css::uno::Reference< css::uno::XAggregation > xShapeAgg;
     // reference to <XShape>, determined in the
@@ -191,11 +200,9 @@ class SwXShape : public SwXShapeBaseClass,
 
 protected:
     virtual ~SwXShape() override;
-    //SwClient
-    virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew) override;
-
+    void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew) override;
 public:
-    SwXShape(css::uno::Reference<css::uno::XInterface> & xShape, SwDoc const* pDoc);
+    SwXShape(css::uno::Reference<css::uno::XInterface> & xShape, SwDoc const*const pDoc);
 
     static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId();
     virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override;
diff --git a/sw/source/core/unocore/unodraw.cxx b/sw/source/core/unocore/unodraw.cxx
index 69eefbb45a06..e91e4168c7fb 100644
--- a/sw/source/core/unocore/unodraw.cxx
+++ b/sw/source/core/unocore/unodraw.cxx
@@ -255,6 +255,8 @@ SwFmDrawPage::SwFmDrawPage( SdrPage* pPage ) :
 
 SwFmDrawPage::~SwFmDrawPage() throw ()
 {
+    while (!m_vShapes.empty())
+        m_vShapes.back()->dispose();
     RemovePageView();
 }
 
@@ -284,37 +286,26 @@ void    SwFmDrawPage::RemovePageView()
     pPageView = nullptr;
 }
 
-uno::Reference< uno::XInterface >   SwFmDrawPage::GetInterface( SdrObject* pObj )
+uno::Reference<drawing::XShape> SwFmDrawPage::GetShape(SdrObject* pObj)
 {
-    uno::Reference< XInterface >  xShape;
-    if( pObj )
+    if(!pObj)
+        return nullptr;
+    SwFrameFormat* pFormat = ::FindFrameFormat( pObj );
+    SwFmDrawPage* pPage = dynamic_cast<SwFmDrawPage*>(pFormat);
+    if(!pPage || pPage->m_vShapes.empty())
+        return uno::Reference<drawing::XShape>(pObj->getUnoShape(), uno::UNO_QUERY);
+    for(auto pShape : pPage->m_vShapes)
     {
-        SwFrameFormat* pFormat = ::FindFrameFormat( pObj );
-
-        SwIterator<SwXShape,SwFormat> aIter(*pFormat);
-        SwXShape* pxShape = aIter.First();
-        if (pxShape)
-        {
-            //tdf#113615 when mapping from SdrObject to XShape via
-            //SwFrameFormat check all the SdrObjects belonging to this
-            //SwFrameFormat to find the right one. In the case of Grouped
-            //objects there can be both the group and the elements of the group
-            //registered here so the first one isn't necessarily the right one
-            while (SwXShape* pNext = aIter.Next())
-            {
-                SvxShape* pSvxShape = pNext->GetSvxShape();
-                if (pSvxShape && pSvxShape->GetSdrObject() == pObj)
-                {
-                    pxShape = pNext;
-                    break;
-                }
-            }
-            xShape =  *static_cast<cppu::OWeakObject*>(pxShape);
-        }
-        else
-            xShape = pObj->getUnoShape();
+        SvxShape* pSvxShape = pShape->GetSvxShape();
+        if (pSvxShape && pSvxShape->GetSdrObject() == pObj)
+            return uno::Reference<drawing::XShape>(static_cast<::cppu::OWeakObject*>(pShape), uno::UNO_QUERY);
     }
-    return xShape;
+    return nullptr;
+}
+
+uno::Reference<drawing::XShapeGroup> SwFmDrawPage::GetShapeGroup(SdrObject* pObj)
+{
+    return uno::Reference<drawing::XShapeGroup>(GetShape(pObj), uno::UNO_QUERY);
 }
 
 uno::Reference< drawing::XShape > SwFmDrawPage::CreateShape( SdrObject *pObj ) const
@@ -375,13 +366,15 @@ uno::Reference< drawing::XShape > SwFmDrawPage::CreateShape( SdrObject *pObj ) c
             xShapeTunnel = nullptr;
             uno::Reference< uno::XInterface > xCreate(xRet, uno::UNO_QUERY);
             xRet = nullptr;
-            uno::Reference< beans::XPropertySet >  xPrSet;
             if ( pObj->IsGroupObject() && (!pObj->Is3DObj() || (dynamic_cast<const E3dScene*>( pObj) !=  nullptr)) )
-                xPrSet = new SwXGroupShape(xCreate, nullptr);
+                pShape = new SwXGroupShape(xCreate, nullptr);
             else
-                xPrSet = new SwXShape(xCreate, nullptr);
+                pShape = new SwXShape(xCreate, nullptr);
+            uno::Reference<beans::XPropertySet> xPrSet = pShape;
             xRet.set(xPrSet, uno::UNO_QUERY);
         }
+        const_cast<std::vector<SwXShape*>*>(&m_vShapes)->push_back(pShape);
+        pShape->m_pPage = this;
     }
     return xRet;
 }
@@ -582,7 +575,7 @@ void SwXDrawPage::add(const uno::Reference< drawing::XShape > & xShape)
                                     static_cast< cppu::OWeakObject * > ( this ) );
 
     // we're already registered in the model / SwXDrawPage::add() already called
-    if(pShape->GetRegisteredIn() || !pShape->m_bDescriptor )
+    if(pShape->m_pPage || pShape->GetRegisteredIn() || !pShape->m_bDescriptor )
         return;
 
     // we're inserted elsewhere already
@@ -771,10 +764,7 @@ uno::Reference< drawing::XShapeGroup >  SwXDrawPage::group(const uno::Reference<
 
                 pPage->GetDrawView()->UnmarkAll();
                 if(pContact)
-                {
-                    uno::Reference< uno::XInterface >  xInt = SwFmDrawPage::GetInterface( pContact->GetMaster() );
-                    xRet.set(xInt, uno::UNO_QUERY);
-                }
+                    xRet = SwFmDrawPage::GetShapeGroup( pContact->GetMaster() );
                 pDoc->GetIDocumentUndoRedo().EndUndo( SwUndoId::END, nullptr );
             }
             pPage->RemovePageView();
@@ -877,13 +867,14 @@ namespace
     }
 }
 
-SwXShape::SwXShape(uno::Reference<uno::XInterface> & xShape,
-                   SwDoc const*const pDoc)
-    :
-    m_pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXT_SHAPE)),
-    m_pPropertyMapEntries(aSwMapProvider.GetPropertyMapEntries(PROPERTY_MAP_TEXT_SHAPE)),
-    pImpl(new SwShapeDescriptor_Impl(pDoc)),
-    m_bDescriptor(true)
+SwXShape::SwXShape(
+        uno::Reference<uno::XInterface> & xShape,
+        SwDoc const*const pDoc)
+    : m_pPage(nullptr)
+    , m_pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXT_SHAPE))
+    , m_pPropertyMapEntries(aSwMapProvider.GetPropertyMapEntries(PROPERTY_MAP_TEXT_SHAPE))
+    , pImpl(new SwShapeDescriptor_Impl(pDoc))
+    , m_bDescriptor(true)
 {
     if(!xShape.is())  // default Ctor
         return;
@@ -970,6 +961,9 @@ SwXShape::~SwXShape()
     }
     pImpl.reset();
     EndListeningAll();
+    if(m_pPage)
+       const_cast<SwFmDrawPage*>(m_pPage)->RemoveShape(this);
+    m_pPage = nullptr;
 }
 
 uno::Any SwXShape::queryInterface( const uno::Type& aType )
@@ -2124,6 +2118,9 @@ void SwXShape::dispose()
         if(xComp.is())
             xComp->dispose();
     }
+    if(m_pPage)
+        const_cast<SwFmDrawPage*>(m_pPage)->RemoveShape(this);
+    m_pPage = nullptr;
 }
 
 void SwXShape::addEventListener(
diff --git a/sw/source/uibase/uno/unotxvw.cxx b/sw/source/uibase/uno/unotxvw.cxx
index dd04e6f53a5f..1842b90cd497 100644
--- a/sw/source/uibase/uno/unotxvw.cxx
+++ b/sw/source/uibase/uno/unotxvw.cxx
@@ -416,8 +416,7 @@ uno::Any SwXTextView::getSelection()
                 for(size_t i = 0; i < rMarkList.GetMarkCount(); ++i)
                 {
                     SdrObject* pObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
-                    uno::Reference< uno::XInterface >  xInt = SwFmDrawPage::GetInterface( pObj );
-                    uno::Reference< drawing::XShape >  xShape(xInt, uno::UNO_QUERY);
+                    uno::Reference<drawing::XShape> xShape = SwFmDrawPage::GetShape( pObj );
                     xShCol->add(xShape);
                 }
                 aRef.set(xShCol, uno::UNO_QUERY);


More information about the Libreoffice-commits mailing list