Kaydet (Commit) da0815e8 authored tarafından Mike Kaganski's avatar Mike Kaganski Kaydeden (comit) Miklos Vajna

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/47681Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
üst 6394c89f
......@@ -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;
......
......@@ -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();
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment