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

Bjoern Michaelsen bjoern.michaelsen at canonical.com
Sat Dec 24 12:09:30 UTC 2016


 sw/inc/dcontact.hxx              |    5 ++---
 sw/inc/frmfmt.hxx                |   35 +++++++++++++++++++++++++++--------
 sw/source/core/draw/dcontact.cxx |   31 ++++++++++++++++++++++++++-----
 sw/source/core/layout/atrfrm.cxx |   15 ++-------------
 sw/source/core/text/itrform2.cxx |    2 +-
 sw/source/core/text/porfly.cxx   |   16 +++++-----------
 sw/source/core/text/porfly.hxx   |    4 ++--
 7 files changed, 65 insertions(+), 43 deletions(-)

New commits:
commit 4280607328c1c46b566719212ae3f802d511493b
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date:   Sat Dec 24 03:02:26 2016 +0100

    kill FindContactObject and adapt FindSdrObject
    
    - the latter is cheating for now, the FrameFormat should really actively bookkeep
      those
    
    Change-Id: Icf64256ba5277dc4d1ec9ac8858bdc014b3f95f5
    Reviewed-on: https://gerrit.libreoffice.org/32392
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Björn Michaelsen <bjoern.michaelsen at canonical.com>

diff --git a/sw/inc/dcontact.hxx b/sw/inc/dcontact.hxx
index 9c2b628..ae84eee 100644
--- a/sw/inc/dcontact.hxx
+++ b/sw/inc/dcontact.hxx
@@ -66,7 +66,7 @@ SwContact* GetUserCall( const SdrObject* );
 bool IsMarqueeTextObj( const SdrObject& rObj );
 
 /// Base class for the following contact objects (frame + draw objects).
-class SwContact : public SdrObjUserCall, public SwClient
+class SW_DLLPUBLIC SwContact : public SdrObjUserCall, public SwClient
 {
     /** boolean, indicating destruction of contact object
      important note: boolean has to be set at the beginning of each destructor
@@ -100,6 +100,7 @@ class SwContact : public SdrObjUserCall, public SwClient
 
 protected:
     void SetInDTOR();
+    virtual void SwClientNotify(const SwModify&, const SfxHint& rHint) override;
 
 public:
 
@@ -190,8 +191,6 @@ class SW_DLLPUBLIC SwFlyDrawContact : public SwContact
 private:
     SwFlyDrawObj* mpMasterObj;
 
-protected:
-    virtual void SwClientNotify(const SwModify&, const SfxHint& rHint) override;
 
 public:
 
diff --git a/sw/inc/frmfmt.hxx b/sw/inc/frmfmt.hxx
index f1ebc09..fafa003 100644
--- a/sw/inc/frmfmt.hxx
+++ b/sw/inc/frmfmt.hxx
@@ -33,7 +33,19 @@ class IMapObject;
 class SwRect;
 class SwContact;
 class SdrObject;
-namespace sw { class DocumentLayoutManager; }
+namespace sw
+{
+    class DocumentLayoutManager;
+    // This is cheating: we are not really decoupling much with this hint.
+    // SwDrawFrameFormat should probably bookkeep its SdrObject (and
+    // SwDrawFrameFormat too) as members
+    struct SW_DLLPUBLIC FindSdrObjectHint final : SfxHint
+    {
+        SdrObject** m_ppObject;
+        FindSdrObjectHint(SdrObject** ppObject) : m_ppObject(ppObject) {};
+        virtual ~FindSdrObjectHint() override;
+    };
+}
 class SwFrameFormats;
 
 /// Style of a layout element.
@@ -106,17 +118,16 @@ public:
     SwRect FindLayoutRect( const bool bPrtArea = false,
                            const Point* pPoint = nullptr ) const;
 
-    /** Searches SdrObject. SdrObjUserCall is client of the format.
-       The UserCall knows its SdrObject. */
-          SwContact *FindContactObj();
-    const SwContact *FindContactObj() const
-        { return const_cast<SwFrameFormat*>(this)->FindContactObj(); }
-
     /** @return the SdrObject, that is connected to the ContactObject.
        Only DrawFrameFormats are connected to the "real SdrObject". FlyFrameFormats
        are connected to a Master and all FlyFrames has the "real SdrObject".
        "Real SdrObject" has position and a Z-order. */
-          SdrObject *FindSdrObject();
+    SdrObject* FindSdrObject()
+    {
+        SdrObject* pObject(nullptr);
+        CallSwClientNotify(sw::FindSdrObjectHint(&pObject));
+        return pObject;
+    }
     const SdrObject *FindSdrObject() const
         { return const_cast<SwFrameFormat*>(this)->FindSdrObject(); }
 
diff --git a/sw/source/core/draw/dcontact.cxx b/sw/source/core/draw/dcontact.cxx
index 0b08435..d014583 100644
--- a/sw/source/core/draw/dcontact.cxx
+++ b/sw/source/core/draw/dcontact.cxx
@@ -378,6 +378,17 @@ sal_uInt32 SwContact::GetMaxOrdNum() const
     return nMaxOrdNum;
 }
 
+void SwContact::SwClientNotify(const SwModify&, const SfxHint& rHint)
+{
+    // this does not call SwClient::SwClientNotify and thus doesnt handle RES_OBJECTDYING as usual. Is this intentional?
+    if (auto pFindSdrObjectHint = dynamic_cast<const sw::FindSdrObjectHint*>(&rHint))
+    {
+        if(!*pFindSdrObjectHint->m_ppObject)
+            *pFindSdrObjectHint->m_ppObject = GetMaster();
+    }
+}
+
+
 SwFlyDrawContact::SwFlyDrawContact( SwFlyFrameFormat *pToRegisterIn, SdrModel * ) :
     SwContact( pToRegisterIn )
 {
@@ -434,10 +445,6 @@ void SwFlyDrawContact::SetMaster( SdrObject* _pNewMaster )
     mpMasterObj = static_cast<SwFlyDrawObj *>(_pNewMaster);
 }
 
-void SwFlyDrawContact::SwClientNotify(const SwModify&, const SfxHint&)
-{
-}
-
 /**
  * @note Overriding method to control Writer fly frames, which are linked, and
  *       to assure that all objects anchored at/inside the Writer fly frame are
@@ -1382,7 +1389,8 @@ namespace
 
 void SwDrawContact::SwClientNotify(const SwModify& rMod, const SfxHint& rHint)
 {
-    SwClient::SwClientNotify(rMod, rHint);
+    SwClient::SwClientNotify(rMod, rHint); // needed as SwContact::SwClientNotify doesnt explicitly call SwClient::SwClientNotify
+    SwContact::SwClientNotify(rMod, rHint);
     if (auto pLegacyHint = dynamic_cast<const sw::LegacyModifyHint*>(&rHint))
     {
         SAL_WARN_IF(mbDisconnectInProgress, "sw.core", "<SwDrawContact::Modify(..)> called during disconnection.");
diff --git a/sw/source/core/layout/atrfrm.cxx b/sw/source/core/layout/atrfrm.cxx
index 37996b2..ee141ab 100644
--- a/sw/source/core/layout/atrfrm.cxx
+++ b/sw/source/core/layout/atrfrm.cxx
@@ -2739,19 +2739,6 @@ SwRect SwFrameFormat::FindLayoutRect( const bool bPrtArea, const Point* pPoint )
     return aRet;
 }
 
-SwContact* SwFrameFormat::FindContactObj()
-{
-    return SwIterator<SwContact,SwFormat>( *this ).First();
-}
-
-SdrObject* SwFrameFormat::FindSdrObject()
-{
-    // #i30669# - use method <FindContactObj()> instead of
-    // duplicated code.
-    SwContact* pFoundContact = FindContactObj();
-    return pFoundContact ? pFoundContact->GetMaster() : nullptr;
-}
-
 SdrObject* SwFrameFormat::FindRealSdrObject()
 {
     if( RES_FLYFRMFMT == Which() )
@@ -3335,6 +3322,7 @@ namespace sw
     WW8AnchorConvHint::~WW8AnchorConvHint() {}
     RestoreFlyAnchorHint::~RestoreFlyAnchorHint() {}
     CreatePortionHint::~CreatePortionHint() {}
+    FindSdrObjectHint::~FindSdrObjectHint() {}
 }
 
 SwDrawFrameFormat::~SwDrawFrameFormat()
commit 09a0a1d760c9786c0cfb0911244892538838a284
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date:   Sat Dec 24 02:10:25 2016 +0100

    use proper message passing
    
    Change-Id: I00b0446b1e5a1226566f4520ea45773251d61265
    Reviewed-on: https://gerrit.libreoffice.org/32391
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Björn Michaelsen <bjoern.michaelsen at canonical.com>

diff --git a/sw/inc/frmfmt.hxx b/sw/inc/frmfmt.hxx
index b24536e..f1ebc09 100644
--- a/sw/inc/frmfmt.hxx
+++ b/sw/inc/frmfmt.hxx
@@ -236,6 +236,8 @@ public:
 
 
 class SwDrawFrameFormat;
+class SwDrawContact;
+
 namespace sw
 {
     enum class DrawFrameFormatHintId {
@@ -302,6 +304,12 @@ namespace sw
         RestoreFlyAnchorHint(Point aPos) : m_aPos(aPos) {};
         virtual ~RestoreFlyAnchorHint() override;
     };
+    struct SW_DLLPUBLIC CreatePortionHint final : SfxHint
+    {
+        SwDrawContact** m_ppContact;
+        CreatePortionHint(SwDrawContact** ppContact) : m_ppContact(ppContact) {};
+        virtual ~CreatePortionHint() override;
+    };
 }
 
 class SW_DLLPUBLIC SwDrawFrameFormat: public SwFrameFormat
diff --git a/sw/source/core/draw/dcontact.cxx b/sw/source/core/draw/dcontact.cxx
index b3b5ad1..0b08435 100644
--- a/sw/source/core/draw/dcontact.cxx
+++ b/sw/source/core/draw/dcontact.cxx
@@ -1572,6 +1572,19 @@ void SwDrawContact::SwClientNotify(const SwModify& rMod, const SfxHint& rHint)
         }
         pObj->SetRelativePos(pRestoreFlyAnchorHint->m_aPos);
     }
+    else if (auto pCreatePortionHint = dynamic_cast<const sw::CreatePortionHint*>(&rHint))
+    {
+        if(*pCreatePortionHint->m_ppContact)
+            return;
+        *pCreatePortionHint->m_ppContact = this; // This is kind of rediculous: the FrameFormat doesnt even hold a pointer to the contact itself,  but here we are leaking it out randomly
+        if(!GetAnchorFrame())
+        {
+            // No direct positioning needed any more
+            ConnectToLayout();
+            // Move object to visible layer
+            MoveObjToVisibleLayer(GetMaster());
+        }
+    }
 }
 
 // #i26791#
diff --git a/sw/source/core/layout/atrfrm.cxx b/sw/source/core/layout/atrfrm.cxx
index 9c1d17a..37996b2 100644
--- a/sw/source/core/layout/atrfrm.cxx
+++ b/sw/source/core/layout/atrfrm.cxx
@@ -3334,6 +3334,7 @@ namespace sw
     DrawFormatLayoutCopyHint::~DrawFormatLayoutCopyHint() {}
     WW8AnchorConvHint::~WW8AnchorConvHint() {}
     RestoreFlyAnchorHint::~RestoreFlyAnchorHint() {}
+    CreatePortionHint::~CreatePortionHint() {}
 }
 
 SwDrawFrameFormat::~SwDrawFrameFormat()
diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx
index 667b457..32c5035 100644
--- a/sw/source/core/text/itrform2.cxx
+++ b/sw/source/core/text/itrform2.cxx
@@ -2562,7 +2562,7 @@ SwFlyCntPortion *SwTextFormatter::NewFlyCntPortion( SwTextFormatInfo &rInf,
     }
     else
     {
-        pRet = sw::DrawFlyCntPortion::Create(*rInf.GetTextFrame(), static_cast<SwDrawContact*>(pFrameFormat->FindContactObj()), aTmpBase, nTmpAscent, nTmpDescent, nFlyAsc, nFlyDesc, nMode);
+        pRet = sw::DrawFlyCntPortion::Create(*rInf.GetTextFrame(), *pFrameFormat, aTmpBase, nTmpAscent, nTmpDescent, nFlyAsc, nFlyDesc, nMode);
     }
     return pRet;
 }
diff --git a/sw/source/core/text/porfly.cxx b/sw/source/core/text/porfly.cxx
index 7cf1f9e..5386a50 100644
--- a/sw/source/core/text/porfly.cxx
+++ b/sw/source/core/text/porfly.cxx
@@ -267,17 +267,11 @@ sw::FlyContentPortion::FlyContentPortion(SwFlyInContentFrame* pFly)
     SAL_WARN_IF(!pFly, "sw.core", "SwFlyCntPortion::SwFlyCntPortion: no SwFlyInContentFrame!");
 }
 
-sw::DrawFlyCntPortion::DrawFlyCntPortion(SwDrawContact* pContact)
-    : m_pContact(pContact)
+sw::DrawFlyCntPortion::DrawFlyCntPortion(SwFrameFormat& rFormat)
+    : m_pContact(nullptr)
 {
+    rFormat.CallSwClientNotify(sw::CreatePortionHint(&m_pContact));
     assert(m_pContact);
-    if(!m_pContact->GetAnchorFrame())
-    {
-        // No direct positioning needed any more
-        m_pContact->ConnectToLayout();
-        // Move object to visible layer
-        m_pContact->MoveObjToVisibleLayer(m_pContact->GetMaster());
-    }
 }
 
 sw::FlyContentPortion* sw::FlyContentPortion::Create(const SwTextFrame& rFrame, SwFlyInContentFrame* pFly, const Point& rBase, long nLnAscent, long nLnDescent, long nFlyAsc, long nFlyDesc, AsCharFlags nFlags)
@@ -287,9 +281,9 @@ sw::FlyContentPortion* sw::FlyContentPortion::Create(const SwTextFrame& rFrame,
     return pNew;
 }
 
-sw::DrawFlyCntPortion* sw::DrawFlyCntPortion::Create(const SwTextFrame& rFrame, SwDrawContact* pContact, const Point& rBase, long nLnAscent, long nLnDescent, long nFlyAsc, long nFlyDesc, AsCharFlags nFlags)
+sw::DrawFlyCntPortion* sw::DrawFlyCntPortion::Create(const SwTextFrame& rFrame, SwFrameFormat& rFormat, const Point& rBase, long nLnAscent, long nLnDescent, long nFlyAsc, long nFlyDesc, AsCharFlags nFlags)
 {
-    auto pNew(new DrawFlyCntPortion(pContact));
+    auto pNew(new DrawFlyCntPortion(rFormat));
     pNew->SetBase(rFrame, rBase, nLnAscent, nLnDescent, nFlyAsc, nFlyDesc, nFlags | AsCharFlags::UlSpace | AsCharFlags::Init);
     return pNew;
 }
diff --git a/sw/source/core/text/porfly.hxx b/sw/source/core/text/porfly.hxx
index 090ee7f..1434b5e 100644
--- a/sw/source/core/text/porfly.hxx
+++ b/sw/source/core/text/porfly.hxx
@@ -83,8 +83,8 @@ namespace sw
             SwDrawContact* m_pContact;
             virtual SdrObject* GetSdrObj(const SwTextFrame&) override;
         public:
-            DrawFlyCntPortion(SwDrawContact* pDrawContact);
-            static DrawFlyCntPortion* Create(const SwTextFrame& rFrame, SwDrawContact* pDrawContact, const Point& rBase, long nAsc, long nDescent, long nFlyAsc, long nFlyDesc, AsCharFlags nFlags);
+            DrawFlyCntPortion(SwFrameFormat& rFormat);
+            static DrawFlyCntPortion* Create(const SwTextFrame& rFrame, SwFrameFormat& rFormat, const Point& rBase, long nAsc, long nDescent, long nFlyAsc, long nFlyDesc, AsCharFlags nFlags);
             virtual void Paint(const SwTextPaintInfo& rInf) const override;
             virtual ~DrawFlyCntPortion() override;
     };


More information about the Libreoffice-commits mailing list