diff options
-rw-r--r-- | include/svx/ColorSets.hxx | 3 | ||||
-rw-r--r-- | svx/CppunitTest_svx_styles.mk | 44 | ||||
-rw-r--r-- | svx/Module_svx.mk | 1 | ||||
-rw-r--r-- | svx/qa/unit/data/theme.pptx | bin | 0 -> 25742 bytes | |||
-rw-r--r-- | svx/qa/unit/styles.cxx | 100 | ||||
-rw-r--r-- | svx/source/styles/ColorSets.cxx | 59 | ||||
-rw-r--r-- | svx/source/svdraw/svdpage.cxx | 21 |
7 files changed, 227 insertions, 1 deletions
diff --git a/include/svx/ColorSets.hxx b/include/svx/ColorSets.hxx index e6c9f1b4e7ee..c4aa0ae2b9bc 100644 --- a/include/svx/ColorSets.hxx +++ b/include/svx/ColorSets.hxx @@ -19,6 +19,7 @@ #include <tools/color.hxx> typedef struct _xmlTextWriter* xmlTextWriterPtr; +class SdrPage; namespace svx { @@ -89,6 +90,8 @@ public: void ToAny(css::uno::Any& rVal) const; static std::unique_ptr<Theme> FromAny(const css::uno::Any& rVal); + + void UpdateSdrPage(SdrPage* pPage); }; } // end of namespace svx diff --git a/svx/CppunitTest_svx_styles.mk b/svx/CppunitTest_svx_styles.mk new file mode 100644 index 000000000000..f617668ad705 --- /dev/null +++ b/svx/CppunitTest_svx_styles.mk @@ -0,0 +1,44 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +#************************************************************************* +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +#************************************************************************* + +$(eval $(call gb_CppunitTest_CppunitTest,svx_styles)) + +$(eval $(call gb_CppunitTest_use_externals,svx_styles,\ + boost_headers \ +)) + +$(eval $(call gb_CppunitTest_add_exception_objects,svx_styles, \ + svx/qa/unit/styles \ +)) + +$(eval $(call gb_CppunitTest_use_libraries,svx_styles, \ + comphelper \ + cppu \ + svx \ + sal \ + test \ + unotest \ +)) + +$(eval $(call gb_CppunitTest_use_sdk_api,svx_styles)) + +$(eval $(call gb_CppunitTest_use_ure,svx_styles)) +$(eval $(call gb_CppunitTest_use_vcl,svx_styles)) + +$(eval $(call gb_CppunitTest_use_rdb,svx_styles,services)) + +$(eval $(call gb_CppunitTest_use_custom_headers,svx_styles,\ + officecfg/registry \ +)) + +$(eval $(call gb_CppunitTest_use_configuration,svx_styles)) + +# vim: set noet sw=4 ts=4: diff --git a/svx/Module_svx.mk b/svx/Module_svx.mk index 3891829c8108..3fc4e889173e 100644 --- a/svx/Module_svx.mk +++ b/svx/Module_svx.mk @@ -39,6 +39,7 @@ $(eval $(call gb_Module_add_check_targets,svx,\ CppunitTest_svx_unit \ CppunitTest_svx_gallery_test \ CppunitTest_svx_removewhichrange \ + CppunitTest_svx_styles \ )) # screenshots diff --git a/svx/qa/unit/data/theme.pptx b/svx/qa/unit/data/theme.pptx Binary files differnew file mode 100644 index 000000000000..397b6706ffa4 --- /dev/null +++ b/svx/qa/unit/data/theme.pptx diff --git a/svx/qa/unit/styles.cxx b/svx/qa/unit/styles.cxx new file mode 100644 index 000000000000..9cbae8f997ba --- /dev/null +++ b/svx/qa/unit/styles.cxx @@ -0,0 +1,100 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <test/bootstrapfixture.hxx> +#include <unotest/macros_test.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/frame/Desktop.hpp> +#include <com/sun/star/drawing/XDrawPagesSupplier.hpp> +#include <com/sun/star/drawing/XMasterPageTarget.hpp> +#include <com/sun/star/text/XTextRange.hpp> + +using namespace ::com::sun::star; + +namespace +{ +/// Tests for svx/source/styles/ code. +class Test : public test::BootstrapFixture, public unotest::MacrosTest +{ +private: + uno::Reference<lang::XComponent> mxComponent; + +public: + void setUp() override; + void tearDown() override; + uno::Reference<lang::XComponent>& getComponent() { return mxComponent; } +}; + +void Test::setUp() +{ + test::BootstrapFixture::setUp(); + + mxDesktop.set(frame::Desktop::create(mxComponentContext)); +} + +void Test::tearDown() +{ + if (mxComponent.is()) + mxComponent->dispose(); + + test::BootstrapFixture::tearDown(); +} + +constexpr OUStringLiteral DATA_DIRECTORY = u"/svx/qa/unit/data/"; + +CPPUNIT_TEST_FIXTURE(Test, testThemeChange) +{ + // Given a document, with a first slide and blue shape text from theme: + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "theme.pptx"; + getComponent() = loadFromDesktop(aURL); + uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(getComponent(), uno::UNO_QUERY); + uno::Reference<drawing::XMasterPageTarget> xDrawPage( + xDrawPagesSupplier->getDrawPages()->getByIndex(0), uno::UNO_QUERY); + uno::Reference<drawing::XShapes> xDrawPageShapes(xDrawPage, uno::UNO_QUERY); + uno::Reference<text::XTextRange> xShape(xDrawPageShapes->getByIndex(0), uno::UNO_QUERY); + { + uno::Reference<container::XEnumerationAccess> xText(xShape->getText(), uno::UNO_QUERY); + uno::Reference<container::XEnumerationAccess> xPara( + xText->createEnumeration()->nextElement(), uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xPortion(xPara->createEnumeration()->nextElement(), + uno::UNO_QUERY); + sal_Int32 nColor{}; + xPortion->getPropertyValue("CharColor") >>= nColor; + // Blue. + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0x4472c4), nColor); + } + + // When changing the master slide of slide 1 to use the theme of the second master slide: + uno::Reference<drawing::XMasterPageTarget> xDrawPage2( + xDrawPagesSupplier->getDrawPages()->getByIndex(1), uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xMasterPage2(xDrawPage2->getMasterPage(), uno::UNO_QUERY); + uno::Any aTheme = xMasterPage2->getPropertyValue("Theme"); + uno::Reference<beans::XPropertySet> xMasterPage(xDrawPage->getMasterPage(), uno::UNO_QUERY); + xMasterPage->setPropertyValue("Theme", aTheme); + + // Then make sure the shape text color is now green: + uno::Reference<container::XEnumerationAccess> xText(xShape->getText(), uno::UNO_QUERY); + uno::Reference<container::XEnumerationAccess> xPara(xText->createEnumeration()->nextElement(), + uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xPortion(xPara->createEnumeration()->nextElement(), + uno::UNO_QUERY); + sal_Int32 nColor{}; + xPortion->getPropertyValue("CharColor") >>= nColor; + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 9486886 (#90c226, green) + // - Actual : 4485828 (#4472c4, blue) + // i.e. shape text was not updated on theme change. + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0x90c226), nColor); +} +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/styles/ColorSets.cxx b/svx/source/styles/ColorSets.cxx index 773e7c414ef3..a5f8c6e7c548 100644 --- a/svx/source/styles/ColorSets.cxx +++ b/svx/source/styles/ColorSets.cxx @@ -16,14 +16,55 @@ #include <com/sun/star/beans/PropertyValues.hpp> #include <com/sun/star/util/Color.hpp> +#include <com/sun/star/text/XTextRange.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/container/XEnumeration.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> #include <comphelper/propertyvalue.hxx> #include <comphelper/sequenceashashmap.hxx> #include <comphelper/sequence.hxx> #include <sal/log.hxx> +#include <svx/svdpage.hxx> +#include <svx/svditer.hxx> +#include <editeng/unoprnms.hxx> using namespace com::sun::star; +namespace +{ +void UpdateSdrObject(svx::Theme* pTheme, SdrObject* pObject) +{ + svx::ColorSet* pColorSet = pTheme->GetColorSet(); + if (!pColorSet) + { + return; + } + + uno::Reference<text::XTextRange> xShape(pObject->getUnoShape(), uno::UNO_QUERY); + uno::Reference<container::XEnumerationAccess> xText(xShape->getText(), uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xParagraphs = xText->createEnumeration(); + while (xParagraphs->hasMoreElements()) + { + uno::Reference<container::XEnumerationAccess> xParagraph(xParagraphs->nextElement(), uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xPortions = xParagraph->createEnumeration(); + while (xPortions->hasMoreElements()) + { + uno::Reference<beans::XPropertySet> xPortion(xPortions->nextElement(), uno::UNO_QUERY); + sal_Int16 nCharColorTheme = -1; + xPortion->getPropertyValue(UNO_NAME_EDIT_CHAR_COLOR_THEME) >>= nCharColorTheme; + if (nCharColorTheme < 0 || nCharColorTheme > 11) + { + continue; + } + + Color aColor = pColorSet->getColor(nCharColorTheme); + xPortion->setPropertyValue(UNO_NAME_EDIT_CHAR_COLOR, uno::makeAny(static_cast<sal_Int32>(aColor))); + } + } +} +} + namespace svx { @@ -229,6 +270,24 @@ std::unique_ptr<Theme> Theme::FromAny(const css::uno::Any& rVal) return pTheme; } +void Theme::UpdateSdrPage(SdrPage* pPage) +{ + for (size_t nObject = 0; nObject < pPage->GetObjCount(); ++nObject) + { + SdrObject* pObject = pPage->GetObj(nObject); + UpdateSdrObject(this, pObject); + SdrObjList* pList = pObject->GetSubList(); + if (pList) + { + SdrObjListIter aIter(pList, SdrIterMode::DeepWithGroups); + while (aIter.IsMore()) + { + UpdateSdrObject(this, aIter.Next()); + } + } + } +} + } // end of namespace svx /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/svdraw/svdpage.cxx b/svx/source/svdraw/svdpage.cxx index 1ebfe6cad4ac..7167f69c5c12 100644 --- a/svx/source/svdraw/svdpage.cxx +++ b/svx/source/svdraw/svdpage.cxx @@ -1287,7 +1287,26 @@ void SdrPageProperties::SetStyleSheet(SfxStyleSheet* pStyleSheet) ImpPageChange(*mpSdrPage); } -void SdrPageProperties::SetTheme(std::unique_ptr<svx::Theme> pTheme) { mpTheme = std::move(pTheme); } +void SdrPageProperties::SetTheme(std::unique_ptr<svx::Theme> pTheme) +{ + mpTheme = std::move(pTheme); + + if (mpTheme && mpSdrPage->IsMasterPage()) + { + SdrModel& rModel = mpSdrPage->getSdrModelFromSdrPage(); + sal_uInt16 nPageCount = rModel.GetPageCount(); + for (sal_uInt16 nPage = 0; nPage < nPageCount; ++nPage) + { + SdrPage* pPage = rModel.GetPage(nPage); + if (!pPage->TRG_HasMasterPage() || &pPage->TRG_GetMasterPage() != mpSdrPage) + { + continue; + } + + mpTheme->UpdateSdrPage(pPage); + } + } +} svx::Theme* SdrPageProperties::GetTheme() { return mpTheme.get(); } |