summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sw/CppunitTest_sw_apitests.mk1
-rw-r--r--sw/inc/unoframe.hxx15
-rw-r--r--sw/qa/api/SwXTextFrame.cxx107
-rw-r--r--sw/source/core/unocore/unoframe.cxx45
4 files changed, 145 insertions, 23 deletions
diff --git a/sw/CppunitTest_sw_apitests.mk b/sw/CppunitTest_sw_apitests.mk
index 370ed779d8b9..6f73e8406421 100644
--- a/sw/CppunitTest_sw_apitests.mk
+++ b/sw/CppunitTest_sw_apitests.mk
@@ -16,6 +16,7 @@ $(eval $(call gb_CppunitTest_use_external,sw_apitests,boost_headers))
$(eval $(call gb_CppunitTest_add_exception_objects,sw_apitests, \
sw/qa/api/SwXDocumentIndex \
sw/qa/api/SwXDocumentSettings \
+ sw/qa/api/SwXTextFrame \
sw/qa/api/SwXTextField \
sw/qa/api/SwXTextTable \
))
diff --git a/sw/inc/unoframe.hxx b/sw/inc/unoframe.hxx
index 207fbaac7414..c7e432a075ba 100644
--- a/sw/inc/unoframe.hxx
+++ b/sw/inc/unoframe.hxx
@@ -54,11 +54,12 @@ class SwXFrame : public cppu::WeakImplHelper
css::container::XNamed,
css::text::XTextContent
>,
- public SwClient
+ public SvtListener
{
private:
class Impl;
::sw::UnoImplPtr<Impl> m_pImpl;
+ SwFrameFormat* m_pFrameFormat;
const SfxItemPropertySet* m_pPropSet;
SwDoc* m_pDoc;
@@ -76,11 +77,12 @@ private:
sal_Int64 m_nVisibleAreaWidth;
sal_Int64 m_nVisibleAreaHeight;
css::uno::Reference<css::text::XText> m_xParentText;
+ void DisposeInternal();
protected:
css::uno::Reference< css::beans::XPropertySet > mxStyleData;
css::uno::Reference< css::container::XNameAccess > mxStyleFamily;
- virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew) override;
+ virtual void Notify(const SfxHint&) override;
virtual ~SwXFrame() override;
@@ -149,13 +151,10 @@ public:
void attachToRange(const css::uno::Reference< css::text::XTextRange > & xTextRange);
const SwFrameFormat* GetFrameFormat() const
- {
- return dynamic_cast<const SwFrameFormat*>( GetRegisteredIn() );
- }
+ { return m_pFrameFormat; }
SwFrameFormat* GetFrameFormat()
- {
- return dynamic_cast< SwFrameFormat*>( GetRegisteredIn() );
- }
+ { return m_pFrameFormat; }
+
FlyCntType GetFlyCntType()const {return eType;}
bool IsDescriptor() const {return bIsDescriptor;}
diff --git a/sw/qa/api/SwXTextFrame.cxx b/sw/qa/api/SwXTextFrame.cxx
new file mode 100644
index 000000000000..546823b5dbe2
--- /dev/null
+++ b/sw/qa/api/SwXTextFrame.cxx
@@ -0,0 +1,107 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <test/bootstrapfixture.hxx>
+#include <test/lang/xserviceinfo.hxx>
+#include <test/lang/xcomponent.hxx>
+#include <test/text/baseindex.hxx>
+#include <test/text/textdocumentindex.hxx>
+#include <test/text/xdocumentindex.hxx>
+#include <test/text/xtextcontent.hxx>
+#include <unotest/macros_test.hxx>
+
+#include <com/sun/star/frame/Desktop.hpp>
+
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+
+#include <com/sun/star/text/XTextDocument.hpp>
+#include <com/sun/star/text/XTextContent.hpp>
+#include <com/sun/star/text/XText.hpp>
+#include <com/sun/star/text/XTextCursor.hpp>
+#include <com/sun/star/text/XTextRange.hpp>
+#include <com/sun/star/text/XTextFrame.hpp>
+
+#include <comphelper/processfactory.hxx>
+
+using namespace css;
+
+namespace
+{
+/**
+ * Test for Java API test of file com.sun.star.comp.office.SwXTextFrame.csv
+ */
+class SwXTextFrame final : public test::BootstrapFixture,
+ public unotest::MacrosTest,
+ public apitest::XServiceInfo,
+ public apitest::XComponent
+{
+ uno::Reference<uno::XComponentContext> mxComponentContext;
+ uno::Reference<text::XTextDocument> mxTextDocument;
+ uno::Reference<text::XTextRange> mxTextRange;
+ uno::Reference<text::XTextContent> mxTextContent;
+
+public:
+ virtual void setUp() override;
+ virtual void tearDown() override;
+
+ SwXTextFrame()
+ : apitest::XServiceInfo("SwXTextFrame", "com.sun.star.text.TextFrame"){};
+ uno::Reference<uno::XInterface> init() override;
+ uno::Reference<text::XTextDocument> getTextDocument() { return mxTextDocument; }
+ void triggerDesktopTerminate() override { mxDesktop->terminate(); }
+
+ CPPUNIT_TEST_SUITE(SwXTextFrame);
+ CPPUNIT_TEST(testGetImplementationName);
+ CPPUNIT_TEST(testGetSupportedServiceNames);
+ CPPUNIT_TEST(testSupportsService);
+ CPPUNIT_TEST(testAddEventListener);
+ CPPUNIT_TEST(testRemoveEventListener);
+ CPPUNIT_TEST_SUITE_END();
+};
+
+void SwXTextFrame::setUp()
+{
+ test::BootstrapFixture::setUp();
+
+ mxComponentContext.set(comphelper::getComponentContext(getMultiServiceFactory()));
+ mxDesktop.set(frame::Desktop::create(mxComponentContext));
+ mxTextDocument = uno::Reference<text::XTextDocument>(
+ loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument"),
+ uno::UNO_QUERY_THROW);
+ CPPUNIT_ASSERT(mxTextDocument.is());
+}
+
+void SwXTextFrame::tearDown()
+{
+ if (mxTextDocument.is())
+ mxTextDocument->dispose();
+
+ test::BootstrapFixture::tearDown();
+}
+
+uno::Reference<uno::XInterface> SwXTextFrame::init()
+{
+ uno::Reference<lang::XMultiServiceFactory> xMSF(mxTextDocument, uno::UNO_QUERY_THROW);
+ uno::Reference<text::XTextFrame> xTextFrame(xMSF->createInstance("com.sun.star.text.TextFrame"),
+ uno::UNO_QUERY_THROW);
+ auto xText = getTextDocument()->getText();
+ auto xTextCursor = xText->createTextCursor();
+ CPPUNIT_ASSERT(xTextCursor.is());
+ xText->insertTextContent(xTextCursor, xTextFrame, false);
+ xTextCursor->gotoEnd(false);
+ mxTextRange = uno::Reference<text::XTextRange>(xTextCursor, uno::UNO_QUERY_THROW);
+ mxTextContent = uno::Reference<text::XTextContent>(
+ xMSF->createInstance("com.sun.star.text.TextFrame"), uno::UNO_QUERY_THROW);
+ return xTextFrame;
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(SwXTextFrame);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/unocore/unoframe.cxx b/sw/source/core/unocore/unoframe.cxx
index b9fe6fb8deba..77eeb295e189 100644
--- a/sw/source/core/unocore/unoframe.cxx
+++ b/sw/source/core/unocore/unoframe.cxx
@@ -1203,6 +1203,7 @@ uno::Sequence< OUString > SwXFrame::getSupportedServiceNames()
SwXFrame::SwXFrame(FlyCntType eSet, const ::SfxItemPropertySet* pSet, SwDoc *pDoc)
: m_pImpl(new Impl)
+ , m_pFrameFormat(nullptr)
, m_pPropSet(pSet)
, m_pDoc(pDoc)
, eType(eSet)
@@ -1212,7 +1213,7 @@ SwXFrame::SwXFrame(FlyCntType eSet, const ::SfxItemPropertySet* pSet, SwDoc *pDo
, m_nVisibleAreaHeight(0)
{
// Register ourselves as a listener to the document (via the page descriptor)
- pDoc->getIDocumentStylePoolAccess().GetPageDescFromPool(RES_POOLPAGE_STANDARD)->Add(this);
+ StartListening(pDoc->getIDocumentStylePoolAccess().GetPageDescFromPool(RES_POOLPAGE_STANDARD)->GetNotifier());
// get the property set for the default style data
// First get the model
uno::Reference < XModel > xModel = pDoc->GetDocShell()->GetBaseModel();
@@ -1256,8 +1257,8 @@ SwXFrame::SwXFrame(FlyCntType eSet, const ::SfxItemPropertySet* pSet, SwDoc *pDo
}
SwXFrame::SwXFrame(SwFrameFormat& rFrameFormat, FlyCntType eSet, const ::SfxItemPropertySet* pSet)
- : SwClient(&rFrameFormat)
- , m_pImpl(new Impl)
+ : m_pImpl(new Impl)
+ , m_pFrameFormat(&rFrameFormat)
, m_pPropSet(pSet)
, m_pDoc(nullptr)
, eType(eSet)
@@ -1266,6 +1267,7 @@ SwXFrame::SwXFrame(SwFrameFormat& rFrameFormat, FlyCntType eSet, const ::SfxItem
, m_nVisibleAreaWidth(0)
, m_nVisibleAreaHeight(0)
{
+ StartListening(rFrameFormat.GetNotifier());
}
SwXFrame::~SwXFrame()
@@ -2595,13 +2597,8 @@ void SAL_CALL SwXFrame::removeEventListener(
m_pImpl->m_EventListeners.removeInterface(xListener);
}
-void SwXFrame::Modify(const SfxPoolItem* pOld, const SfxPoolItem *pNew)
+void SwXFrame::DisposeInternal()
{
- ClientModify(this, pOld, pNew);
- if (GetRegisteredIn())
- {
- return; // core object still alive
- }
mxStyleData.clear();
mxStyleFamily.clear();
m_pDoc = nullptr;
@@ -2612,14 +2609,22 @@ void SwXFrame::Modify(const SfxPoolItem* pOld, const SfxPoolItem *pNew)
}
lang::EventObject const ev(xThis);
m_pImpl->m_EventListeners.disposeAndClear(ev);
+ m_pFrameFormat = nullptr;
+ EndListeningAll();
+}
+void SwXFrame::Notify(const SfxHint& rHint)
+{
+ if(rHint.GetId() == SfxHintId::Dying)
+ DisposeInternal();
}
void SwXFrame::dispose()
{
SolarMutexGuard aGuard;
SwFrameFormat* pFormat = GetFrameFormat();
- if ( pFormat )
+ if (pFormat)
{
+ DisposeInternal();
SdrObject* pObj = pFormat->FindSdrObject();
// OD 11.09.2003 #112039# - add condition to perform delete of
// format/anchor sign, not only if the object is inserted, but also
@@ -2797,7 +2802,9 @@ void SwXFrame::attachToRange(const uno::Reference< text::XTextRange > & xTextRan
}
if(pFormat)
{
- pFormat->Add(this);
+ EndListeningAll();
+ m_pFrameFormat = pFormat;
+ StartListening(pFormat->GetNotifier());
if(!m_sName.isEmpty())
pDoc->SetFlyName(*pFormat, m_sName);
}
@@ -2849,7 +2856,9 @@ void SwXFrame::attachToRange(const uno::Reference< text::XTextRange > & xTextRan
->GetIndex()+1 ]->GetGrfNode();
if (pGrfNd)
pGrfNd->SetChgTwipSize( !bSizeFound );
- pFormat->Add(this);
+ m_pFrameFormat = pFormat;
+ EndListeningAll();
+ StartListening(m_pFrameFormat->GetNotifier());
if(!m_sName.isEmpty())
pDoc->SetFlyName(*pFormat, m_sName);
@@ -2975,7 +2984,9 @@ void SwXFrame::attachToRange(const uno::Reference< text::XTextRange > & xTextRan
assert(pFormat2 && "Doc->Insert(notxt) failed.");
pDoc->GetIDocumentUndoRedo().EndUndo(SwUndoId::INSERT, nullptr);
- pFormat2->Add(this);
+ m_pFrameFormat = pFormat2;
+ EndListeningAll();
+ StartListening(m_pFrameFormat->GetNotifier());
if(!m_sName.isEmpty())
pDoc->SetFlyName(*pFormat2, m_sName);
}
@@ -3010,7 +3021,9 @@ void SwXFrame::attachToRange(const uno::Reference< text::XTextRange > & xTextRan
}
pDoc->GetIDocumentUndoRedo().EndUndo(SwUndoId::INSERT, nullptr);
- pFrameFormat->Add(this);
+ m_pFrameFormat = pFrameFormat;
+ EndListeningAll();
+ StartListening(m_pFrameFormat->GetNotifier());
if(!m_sName.isEmpty())
pDoc->SetFlyName(*pFrameFormat, m_sName);
}
@@ -3036,7 +3049,9 @@ void SwXFrame::attachToRange(const uno::Reference< text::XTextRange > & xTextRan
SwFlyFrameFormat* pFrameFormat
= pDoc->getIDocumentContentOperations().InsertEmbObject(aPam, xObj, &aFrameSet);
pDoc->GetIDocumentUndoRedo().EndUndo(SwUndoId::INSERT, nullptr);
- pFrameFormat->Add(this);
+ m_pFrameFormat = pFrameFormat;
+ EndListeningAll();
+ StartListening(m_pFrameFormat->GetNotifier());
if(!m_sName.isEmpty())
pDoc->SetFlyName(*pFrameFormat, m_sName);
}