diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2022-02-23 20:54:01 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2022-02-24 08:43:12 +0100 |
commit | 0e083387551acc677efc903bffc866f5aadb3642 (patch) | |
tree | 0f12adf2149436ccb6cea5168a687ce9a88b9748 /svx | |
parent | fe5d3fbfe63fe8b433776bd3a0508dd712b868b0 (diff) |
sd theme: add UNO API for shape fill color
In preparation of adding import/export for this.
Change-Id: I195be9e9ccdbb25fa41878a2858c22ee11d189a0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130467
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'svx')
-rw-r--r-- | svx/qa/unit/xoutdev.cxx | 63 | ||||
-rw-r--r-- | svx/source/xoutdev/xattr.cxx | 43 |
2 files changed, 89 insertions, 17 deletions
diff --git a/svx/qa/unit/xoutdev.cxx b/svx/qa/unit/xoutdev.cxx index 35eac21cda72..ed5b75189c3a 100644 --- a/svx/qa/unit/xoutdev.cxx +++ b/svx/qa/unit/xoutdev.cxx @@ -7,10 +7,12 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include <cppunit/TestAssert.h> -#include <cppunit/TestFixture.h> -#include <cppunit/extensions/HelperMacros.h> -#include <unotest/bootstrapfixturebase.hxx> +#include <test/bootstrapfixture.hxx> +#include <unotest/macros_test.hxx> + +#include <com/sun/star/frame/Desktop.hpp> +#include <com/sun/star/drawing/XDrawPagesSupplier.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> #include <sal/types.h> #include <sfx2/app.hxx> @@ -22,16 +24,33 @@ #include <svx/xoutbmp.hxx> #include <vcl/filter/PDFiumLibrary.hxx> -class XOutdevTest : public CppUnit::TestFixture +using namespace com::sun::star; + +class XOutdevTest : public test::BootstrapFixture, public unotest::MacrosTest { + uno::Reference<lang::XComponent> mxComponent; + public: - virtual void setUp() override - { - CppUnit::TestFixture::setUp(); - SfxApplication::GetOrCreate(); - } + virtual void setUp() override; + void tearDown() override; + uno::Reference<lang::XComponent>& getComponent() { return mxComponent; } }; +void XOutdevTest::setUp() +{ + test::BootstrapFixture::setUp(); + + mxDesktop.set(frame::Desktop::create(mxComponentContext)); +} + +void XOutdevTest::tearDown() +{ + if (mxComponent.is()) + mxComponent->dispose(); + + test::BootstrapFixture::tearDown(); +} + CPPUNIT_TEST_FIXTURE(XOutdevTest, testPdfGraphicExport) { auto pPdfium = vcl::pdf::PDFiumLibrary::get(); @@ -96,4 +115,28 @@ CPPUNIT_TEST_FIXTURE(XOutdevTest, testTdf60684) CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8>('G'), sFirstBytes[3]); } +CPPUNIT_TEST_FIXTURE(XOutdevTest, testFillColorThemeUnoApi) +{ + // Given an empty Impress document with a (title) shape: + getComponent() = loadFromDesktop("private:factory/simpress", + "com.sun.star.presentation.PresentationDocument"); + + // When setting the theme index of the shape's fill color: + uno::Reference<drawing::XDrawPagesSupplier> xPagesSupplier(getComponent(), uno::UNO_QUERY); + uno::Reference<drawing::XDrawPage> xPage(xPagesSupplier->getDrawPages()->getByIndex(0), + uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xShape(xPage->getByIndex(0), uno::UNO_QUERY); + sal_Int16 nExpected = 4; // Accent 1 + xShape->setPropertyValue("FillColorTheme", uno::makeAny(nExpected)); + + // Then make sure the value we read back is the expected one: + sal_Int16 nActual = -1; + xShape->getPropertyValue("FillColorTheme") >>= nActual; + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 4 + // - Actual : -1 + // i.e. setting the value was broken. + CPPUNIT_ASSERT_EQUAL(nExpected, nActual); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/xoutdev/xattr.cxx b/svx/source/xoutdev/xattr.cxx index 81d10a97061c..e28c85b4a70b 100644 --- a/svx/source/xoutdev/xattr.cxx +++ b/svx/source/xoutdev/xattr.cxx @@ -1900,20 +1900,49 @@ bool XFillColorItem::GetPresentation return true; } -bool XFillColorItem::QueryValue( css::uno::Any& rVal, sal_uInt8 /*nMemberId*/) const +bool XFillColorItem::QueryValue( css::uno::Any& rVal, sal_uInt8 nMemberId ) const { - rVal <<= GetColorValue().GetRGBColor(); + nMemberId &= ~CONVERT_TWIPS; + switch (nMemberId) + { + case MID_COLOR_THEME_INDEX: + { + rVal <<= GetThemeColor().GetThemeIndex(); + break; + } + default: + { + rVal <<= GetColorValue().GetRGBColor(); + break; + } + } return true; } -bool XFillColorItem::PutValue( const css::uno::Any& rVal, sal_uInt8 /*nMemberId*/) +bool XFillColorItem::PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId ) { - Color nValue; - if(!(rVal >>= nValue )) - return false; + nMemberId &= ~CONVERT_TWIPS; + switch(nMemberId) + { + case MID_COLOR_THEME_INDEX: + { + sal_Int16 nIndex = -1; + if (!(rVal >>= nIndex)) + return false; + GetThemeColor().SetThemeIndex(nIndex); + break; + } + default: + { + Color nValue; + if(!(rVal >>= nValue )) + return false; - SetColorValue( nValue ); + SetColorValue( nValue ); + break; + } + } return true; } |