diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2018-01-09 22:54:21 +0300 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2018-02-07 14:13:19 +0100 |
commit | da0815e8a2e89c02c530fe6fcf7233f241e529c6 (patch) | |
tree | 9a86432850ed0a84e11969d05f7926ab6c0f1aee /sw | |
parent | 6394c89fbb07713ce04608ffd031f91a890bb853 (diff) |
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@libreoffice.org>
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/inc/unotxdoc.hxx | 5 | ||||
-rw-r--r-- | sw/qa/extras/uiwriter/uiwriter.cxx | 21 | ||||
-rw-r--r-- | sw/source/uibase/uno/unotxdoc.cxx | 64 |
3 files changed, 90 insertions, 0 deletions
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; |