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

Mike Kaganski mike.kaganski at collabora.com
Wed Feb 7 13:13:42 UTC 2018


 sw/inc/unotxdoc.hxx                |    5 ++
 sw/qa/extras/uiwriter/uiwriter.cxx |   21 ++++++++++++
 sw/source/uibase/uno/unotxdoc.cxx  |   64 +++++++++++++++++++++++++++++++++++++
 3 files changed, 90 insertions(+)

New commits:
commit da0815e8a2e89c02c530fe6fcf7233f241e529c6
Author: Mike Kaganski <mike.kaganski at collabora.com>
Date:   Tue Jan 9 22:54:21 2018 +0300

    Implement XDrawPagesSupplier in SwXTextDocument
    
    Text documents only exposed deprecated XDrawPageSupplier interface
    (see https://api.libreoffice.org/docs/idl/ref/deprecated.html).
    Other documents (spreadsheets, Draw and Impress documents) only
    expose XDrawPagesSupplier interface. Implementing the latter for text
    documents (which would only provide a single page) allows for uniform
    handling of draw pages across all modules.
    
    Change-Id: Ib9e719c6130bc3c968d92c6864fa413ad2c0e3b9
    Reviewed-on: https://gerrit.libreoffice.org/47681
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>

diff --git a/sw/inc/unotxdoc.hxx b/sw/inc/unotxdoc.hxx
index 4e2161af805b..770cf0c1d1d0 100644
--- a/sw/inc/unotxdoc.hxx
+++ b/sw/inc/unotxdoc.hxx
@@ -45,6 +45,7 @@
 #include <com/sun/star/text/XReferenceMarksSupplier.hpp>
 #include <com/sun/star/text/XTextFramesSupplier.hpp>
 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
+#include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
 #include <com/sun/star/util/XReplaceable.hpp>
 #include <com/sun/star/util/XReplaceDescriptor.hpp>
 #include <com/sun/star/util/XRefreshable.hpp>
@@ -112,6 +113,7 @@ typedef cppu::WeakImplHelper
     css::style::XAutoStylesSupplier,
     css::lang::XServiceInfo,
     css::drawing::XDrawPageSupplier,
+    css::drawing::XDrawPagesSupplier,
     css::text::XDocumentIndexesSupplier,
     css::beans::XPropertySet,
     css::beans::XPropertyState,
@@ -325,6 +327,9 @@ public:
     // css::drawing::XDrawPageSupplier
     virtual css::uno::Reference< css::drawing::XDrawPage >  SAL_CALL getDrawPage() override;
 
+    // css::drawing::XDrawPagesSupplier
+    virtual css::uno::Reference< css::drawing::XDrawPages > SAL_CALL getDrawPages() override;
+
     // css::text::XDocumentIndexesSupplier
     virtual css::uno::Reference< css::container::XIndexAccess >  SAL_CALL getDocumentIndexes() override;
 
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index 37bd5e2b2ca0..8dee21388fbe 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -301,6 +301,7 @@ public:
     void testTdf114536();
     void testTdf115065();
     void testTdf115132();
+    void testXDrawPagesSupplier();
 
     CPPUNIT_TEST_SUITE(SwUiWriterTest);
     CPPUNIT_TEST(testReplaceForward);
@@ -481,6 +482,7 @@ public:
     CPPUNIT_TEST(testTdf114536);
     CPPUNIT_TEST(testTdf115065);
     CPPUNIT_TEST(testTdf115132);
+    CPPUNIT_TEST(testXDrawPagesSupplier);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -5943,6 +5945,25 @@ void SwUiWriterTest::testTdf115132()
     }
 }
 
+void SwUiWriterTest::testXDrawPagesSupplier()
+{
+    createDoc();
+    uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent, uno::UNO_QUERY);
+    CPPUNIT_ASSERT_MESSAGE("XDrawPagesSupplier interface is unavailable", xDrawPagesSupplier.is());
+    uno::Reference<drawing::XDrawPages> xDrawPages = xDrawPagesSupplier->getDrawPages();
+    CPPUNIT_ASSERT(xDrawPages.is());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("There must be only a single DrawPage in Writer documents",
+        sal_Int32(1), xDrawPages->getCount());
+    uno::Any aDrawPage = xDrawPages->getByIndex(0);
+    uno::Reference<drawing::XDrawPage> xDrawPageFromXDrawPages(aDrawPage, uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xDrawPageFromXDrawPages.is());
+
+    uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
+    uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage();
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("The DrawPage accessed using XDrawPages must be the same as using XDrawPageSupplier",
+        xDrawPage.get(), xDrawPageFromXDrawPages.get());
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest);
 CPPUNIT_PLUGIN_IMPLEMENT();
 
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx
index 950973c58555..aa6e3395270b 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -91,6 +91,8 @@
 #include <unotools/printwarningoptions.hxx>
 #include <com/sun/star/lang/ServiceNotRegisteredException.hpp>
 #include <com/sun/star/lang/DisposedException.hpp>
+#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
+#include <com/sun/star/lang/NoSupportException.hpp>
 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
 #include <com/sun/star/beans/PropertyAttribute.hpp>
 #include <com/sun/star/beans/XFastPropertySet.hpp>
@@ -1378,6 +1380,68 @@ Reference< drawing::XDrawPage >  SwXTextDocument::getDrawPage()
     return mxXDrawPage;
 }
 
+class SwDrawPagesObj : public cppu::WeakImplHelper<
+    css::drawing::XDrawPages,
+    css::lang::XServiceInfo>
+{
+private:
+    css::uno::Reference< css::drawing::XDrawPageSupplier > m_xDoc;
+public:
+    SwDrawPagesObj(const css::uno::Reference< css::drawing::XDrawPageSupplier >& rxDoc) : m_xDoc(rxDoc) {}
+
+    // XDrawPages
+    virtual css::uno::Reference< css::drawing::XDrawPage > SAL_CALL
+        insertNewByIndex(sal_Int32 /*nIndex*/) override { throw css::lang::NoSupportException(); }
+
+    virtual void SAL_CALL remove(const css::uno::Reference< css::drawing::XDrawPage >& /*xPage*/) override
+    {
+        throw css::lang::NoSupportException();
+    }
+
+    // XIndexAccess
+    virtual sal_Int32 SAL_CALL getCount() override { return 1; }
+
+    virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 Index) override
+    {
+        if (Index != 0)
+            throw css::lang::IndexOutOfBoundsException("Writer documents have only one DrawPage!");
+        return css::uno::Any(m_xDoc->getDrawPage());
+    }
+
+    // XElementAccess
+    virtual css::uno::Type SAL_CALL getElementType() override
+    {
+        SolarMutexGuard aGuard;
+        return cppu::UnoType<drawing::XDrawPage>::get();
+    }
+
+    virtual sal_Bool SAL_CALL hasElements() override { return true; }
+
+    // XServiceInfo
+    virtual OUString SAL_CALL getImplementationName() override
+    {
+        return OUString("SwDrawPagesObj");
+    }
+
+    virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override
+    {
+        return cppu::supportsService(this, ServiceName);
+    }
+
+    virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
+    {
+        return { "com.sun.star.drawing.DrawPages" };
+    }
+};
+
+// XDrawPagesSupplier
+
+uno::Reference<drawing::XDrawPages> SAL_CALL SwXTextDocument::getDrawPages()
+{
+    SolarMutexGuard aGuard;
+    return new SwDrawPagesObj(this);
+}
+
 void SwXTextDocument::Invalidate()
 {
     bObjectValid = false;


More information about the Libreoffice-commits mailing list