summaryrefslogtreecommitdiff
path: root/svx
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2022-02-23 20:54:01 +0100
committerMiklos Vajna <vmiklos@collabora.com>2022-06-30 16:27:03 +0200
commitba896488b49f5bb9982ac704a0a0697d88435731 (patch)
treeafea9acf740ac02bab2e3a7c7af0ec84f781235f /svx
parent75c6459d568744f4d69fead25adc1763d80878d4 (diff)
sd theme: add UNO API for shape fill color
In preparation of adding import/export for this. (cherry picked from commit 0e083387551acc677efc903bffc866f5aadb3642) Conflicts: include/editeng/unoprnms.hxx include/svx/unoshprp.hxx Change-Id: I195be9e9ccdbb25fa41878a2858c22ee11d189a0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136670 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'svx')
-rw-r--r--svx/qa/unit/xoutdev.cxx63
-rw-r--r--svx/source/xoutdev/xattr.cxx43
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 4096fe0c12bd..b53cd8a25d21 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;
}