From 4f347ebabad6355014889f0a81b107dc774590fe Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Sat, 25 Feb 2023 19:12:23 +0900 Subject: use shared_ptr for model::Theme instead of unique_ptr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also change other cases to use the shared_ptr so there is no need to do copies and replace some of docmodel/theme/Theme.hxximports with forward declarations. Change-Id: I4588cb25e05e5f3e535011fffb68a8075b05aecc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147691 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl --- docmodel/source/uno/UnoTheme.cxx | 9 +++++---- include/docmodel/uno/UnoTheme.hxx | 17 +++++++++++------ include/oox/drawingml/theme.hxx | 2 +- include/oox/export/ThemeExport.hxx | 7 ++++++- include/svx/dialog/ThemeDialog.hxx | 6 +++++- include/svx/svdmodel.hxx | 4 ++-- include/svx/svdpage.hxx | 8 ++++---- oox/qa/unit/drawingml.cxx | 9 +++++---- oox/source/drawingml/shape.cxx | 1 + oox/source/drawingml/theme.cxx | 9 ++++----- oox/source/export/ThemeExport.cxx | 1 + sd/qa/filter/eppt/eppt.cxx | 7 ++++--- sd/qa/unit/uiimpress.cxx | 7 ++++--- sd/source/filter/eppt/pptx-epptooxml.cxx | 1 + sd/source/ui/docshell/docshell.cxx | 1 + sd/source/ui/func/fuconstr.cxx | 1 + sd/source/ui/func/fupage.cxx | 5 +++-- sd/source/ui/unoidl/unomodel.cxx | 5 +++-- sd/source/ui/unoidl/unopage.cxx | 16 +++++++--------- svx/source/svdraw/svdmodel.cxx | 8 ++++---- svx/source/svdraw/svdpage.cxx | 7 ++++--- sw/qa/core/theme/ThemeTest.cxx | 1 + sw/source/core/model/ThemeColorChanger.cxx | 1 + sw/source/core/unocore/unodraw.cxx | 7 +++---- xmloff/inc/XMLThemeContext.hxx | 8 ++++++-- xmloff/qa/unit/draw.cxx | 16 +++++++++------- xmloff/qa/unit/text.cxx | 7 ++++--- xmloff/source/draw/sdxmlexp.cxx | 9 +++++---- xmloff/source/style/XMLThemeContext.cxx | 8 +++++--- 29 files changed, 111 insertions(+), 77 deletions(-) diff --git a/docmodel/source/uno/UnoTheme.cxx b/docmodel/source/uno/UnoTheme.cxx index 80d2735be47b..30d3f827fea2 100644 --- a/docmodel/source/uno/UnoTheme.cxx +++ b/docmodel/source/uno/UnoTheme.cxx @@ -13,15 +13,16 @@ #include #include #include +#include using namespace css; -OUString UnoTheme::getName() { return maTheme.GetName(); } +OUString UnoTheme::getName() { return mpTheme->GetName(); } css::uno::Sequence UnoTheme::getColorSet() { std::vector aColorScheme(12); - auto* pColorSet = maTheme.GetColorSet(); + auto* pColorSet = mpTheme->GetColorSet(); if (pColorSet) { size_t i = 0; @@ -40,9 +41,9 @@ css::uno::Sequence UnoTheme::getColorSet() namespace model::theme { -uno::Reference createXTheme(model::Theme const& rTheme) +uno::Reference createXTheme(std::shared_ptr const& pTheme) { - return new UnoTheme(rTheme); + return new UnoTheme(pTheme); } } // end model::theme diff --git a/include/docmodel/uno/UnoTheme.hxx b/include/docmodel/uno/UnoTheme.hxx index f1abc4ccaede..4ca033b8e9c4 100644 --- a/include/docmodel/uno/UnoTheme.hxx +++ b/include/docmodel/uno/UnoTheme.hxx @@ -19,20 +19,24 @@ #include #include -#include + +namespace model +{ +class Theme; +} class DOCMODEL_DLLPUBLIC UnoTheme final : public cppu::WeakImplHelper { private: - model::Theme maTheme; + std::shared_ptr mpTheme; public: - UnoTheme(model::Theme const& rTheme) - : maTheme(rTheme) + UnoTheme(std::shared_ptr const& pTheme) + : mpTheme(pTheme) { } - model::Theme const& getTheme() const { return maTheme; } + std::shared_ptr const& getTheme() const { return mpTheme; } // XTheme OUString SAL_CALL getName() override; @@ -41,6 +45,7 @@ public: namespace model::theme { -DOCMODEL_DLLPUBLIC css::uno::Reference createXTheme(model::Theme const& rTheme); +DOCMODEL_DLLPUBLIC css::uno::Reference +createXTheme(std::shared_ptr const& pTheme); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/oox/drawingml/theme.hxx b/include/oox/drawingml/theme.hxx index a779472b5331..c2408ec1c015 100644 --- a/include/oox/drawingml/theme.hxx +++ b/include/oox/drawingml/theme.hxx @@ -107,7 +107,7 @@ public: const css::uno::Reference& getFragment() const { return mxFragment; } void setFragment( const css::uno::Reference< css::xml::dom::XDocument>& xRef ) { mxFragment=xRef; } - std::unique_ptr createSvxTheme() const; + std::shared_ptr createSvxTheme() const; void addTheme(const css::uno::Reference& xDrawPage) const; private: diff --git a/include/oox/export/ThemeExport.hxx b/include/oox/export/ThemeExport.hxx index 69f048afbaa0..1889709ab352 100644 --- a/include/oox/export/ThemeExport.hxx +++ b/include/oox/export/ThemeExport.hxx @@ -12,7 +12,12 @@ #include #include #include -#include + +namespace model +{ +class Theme; +class FontScheme; +} namespace oox { diff --git a/include/svx/dialog/ThemeDialog.hxx b/include/svx/dialog/ThemeDialog.hxx index 5d3fdc70f250..aa068f9528c1 100644 --- a/include/svx/dialog/ThemeDialog.hxx +++ b/include/svx/dialog/ThemeDialog.hxx @@ -11,11 +11,15 @@ #include #include -#include #include #include #include +namespace model +{ +class Theme; +} + namespace svx { class SVX_DLLPUBLIC ThemeDialog final : public weld::GenericDialogController diff --git a/include/svx/svdmodel.hxx b/include/svx/svdmodel.hxx index fe216d569919..69beb4646175 100644 --- a/include/svx/svdmodel.hxx +++ b/include/svx/svdmodel.hxx @@ -538,8 +538,8 @@ public: SfxStyleSheetBasePool* GetStyleSheetPool() const { return mxStyleSheetPool.get(); } void SetStyleSheetPool(SfxStyleSheetBasePool* pPool) { mxStyleSheetPool=pPool; } - void setTheme(std::unique_ptr pTheme); - std::unique_ptr const& getTheme() const; + void setTheme(std::shared_ptr const& pTheme); + std::shared_ptr const& getTheme() const; void SetStarDrawPreviewMode(bool bPreview); bool IsStarDrawPreviewMode() const { return m_bStarDrawPreviewMode; } diff --git a/include/svx/svdpage.hxx b/include/svx/svdpage.hxx index fde15ccedcd9..7443c408814d 100644 --- a/include/svx/svdpage.hxx +++ b/include/svx/svdpage.hxx @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include @@ -39,6 +38,7 @@ // predefines +namespace model { class Theme; } namespace reportdesign { class OSection; } namespace sdr::contact { class ViewContact; } class SdrPage; @@ -317,7 +317,7 @@ private: // data SdrPage* mpSdrPage; SfxStyleSheet* mpStyleSheet; - std::unique_ptr mpTheme; + std::shared_ptr mpTheme; SfxItemSet maProperties; // internal helpers @@ -346,8 +346,8 @@ public: void SetStyleSheet(SfxStyleSheet* pStyleSheet); SfxStyleSheet* GetStyleSheet() const { return mpStyleSheet;} - void SetTheme(std::unique_ptr pTheme); - std::unique_ptr const& GetTheme() const; + void SetTheme(std::shared_ptr const& pTheme); + std::shared_ptr const& GetTheme() const; void dumpAsXml(xmlTextWriterPtr pWriter) const; }; diff --git a/oox/qa/unit/drawingml.cxx b/oox/qa/unit/drawingml.cxx index 994006e76113..c468fd126584 100644 --- a/oox/qa/unit/drawingml.cxx +++ b/oox/qa/unit/drawingml.cxx @@ -32,6 +32,7 @@ #include #include +#include #include @@ -383,13 +384,13 @@ CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testPptxTheme) CPPUNIT_ASSERT(xTheme.is()); auto* pUnoTheme = dynamic_cast(xTheme.get()); CPPUNIT_ASSERT(pUnoTheme); - auto const& rTheme = pUnoTheme->getTheme(); + auto pTheme = pUnoTheme->getTheme(); - CPPUNIT_ASSERT_EQUAL(OUString("Office Theme"), rTheme.GetName()); - CPPUNIT_ASSERT_EQUAL(OUString("Office"), rTheme.GetColorSet()->getName()); + CPPUNIT_ASSERT_EQUAL(OUString("Office Theme"), pTheme->GetName()); + CPPUNIT_ASSERT_EQUAL(OUString("Office"), pTheme->GetColorSet()->getName()); CPPUNIT_ASSERT_EQUAL(Color(0x954F72), - rTheme.GetColorSet()->getColor(model::ThemeColorType::FollowedHyperlink)); + pTheme->GetColorSet()->getColor(model::ThemeColorType::FollowedHyperlink)); // Check the reference to that theme: uno::Reference xDrawPageShapes(xDrawPage, uno::UNO_QUERY); diff --git a/oox/source/drawingml/shape.cxx b/oox/source/drawingml/shape.cxx index e3923c1b647d..41d2befad1a7 100644 --- a/oox/source/drawingml/shape.cxx +++ b/oox/source/drawingml/shape.cxx @@ -110,6 +110,7 @@ #include #include #include +#include #include #include diff --git a/oox/source/drawingml/theme.cxx b/oox/source/drawingml/theme.cxx index f4ebe63e00e2..b108d8106322 100644 --- a/oox/source/drawingml/theme.cxx +++ b/oox/source/drawingml/theme.cxx @@ -109,9 +109,10 @@ const TextFont* Theme::resolveFont( std::u16string_view rName ) const return nullptr; } -std::unique_ptr Theme::createSvxTheme() const +std::shared_ptr Theme::createSvxTheme() const { - auto pTheme = std::make_unique(maThemeName); + auto pTheme = std::make_shared(maThemeName); + auto pColorSet = std::make_unique(maClrScheme.GetName()); maClrScheme.fill(*pColorSet); pTheme->SetColorSet(std::move(pColorSet)); @@ -184,9 +185,7 @@ void Theme::addTheme(const css::uno::Reference& xDrawPa if (!pPage) return; - std::unique_ptr pTheme = createSvxTheme(); - - pPage->getSdrPageProperties().SetTheme(std::move(pTheme)); + pPage->getSdrPageProperties().SetTheme(createSvxTheme()); } } // namespace oox::drawingml diff --git a/oox/source/export/ThemeExport.cxx b/oox/source/export/ThemeExport.cxx index 6733a70b2057..3abc2cb1adb6 100644 --- a/oox/source/export/ThemeExport.cxx +++ b/oox/source/export/ThemeExport.cxx @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include diff --git a/sd/qa/filter/eppt/eppt.cxx b/sd/qa/filter/eppt/eppt.cxx index 738539c5eff7..6c73ccec5c2b 100644 --- a/sd/qa/filter/eppt/eppt.cxx +++ b/sd/qa/filter/eppt/eppt.cxx @@ -16,6 +16,7 @@ #include #include +#include using namespace ::com::sun::star; @@ -61,7 +62,7 @@ CPPUNIT_TEST_FIXTURE(Test, testThemeExport) xDrawPagesSupplier->getDrawPages()->getByIndex(0), uno::UNO_QUERY); uno::Reference xMasterPage(xDrawPage->getMasterPage(), uno::UNO_QUERY); - model::Theme aTheme("mytheme"); + auto pTheme = std::make_shared("mytheme"); std::unique_ptr pColorSet(new model::ColorSet("mycolorscheme")); pColorSet->add(model::ThemeColorType::Dark1, 0x1); pColorSet->add(model::ThemeColorType::Light1, 0x2); @@ -75,9 +76,9 @@ CPPUNIT_TEST_FIXTURE(Test, testThemeExport) pColorSet->add(model::ThemeColorType::Accent6, 0xa); pColorSet->add(model::ThemeColorType::Hyperlink, 0xb); pColorSet->add(model::ThemeColorType::FollowedHyperlink, 0xc); - aTheme.SetColorSet(std::move(pColorSet)); + pTheme->SetColorSet(std::move(pColorSet)); - xMasterPage->setPropertyValue("Theme", uno::Any(model::theme::createXTheme(aTheme))); + xMasterPage->setPropertyValue("Theme", uno::Any(model::theme::createXTheme(pTheme))); // When exporting to PPTX: save("Impress Office Open XML"); diff --git a/sd/qa/unit/uiimpress.cxx b/sd/qa/unit/uiimpress.cxx index d9f71fcbb7a1..9c295a531b8c 100644 --- a/sd/qa/unit/uiimpress.cxx +++ b/sd/qa/unit/uiimpress.cxx @@ -46,6 +46,7 @@ #include #include #include +#include #include #include @@ -1151,7 +1152,7 @@ CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testThemeShapeInsert) uno::Reference xMasterPage(xMasterPageTarget->getMasterPage(), uno::UNO_QUERY); - model::Theme aTheme("mytheme"); + auto pTheme = std::make_shared("mytheme"); std::unique_ptr pColorSet(new model::ColorSet("mycolorscheme")); pColorSet->add(model::ThemeColorType::Dark1, 0x0); pColorSet->add(model::ThemeColorType::Light1, 0x1); @@ -1165,9 +1166,9 @@ CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testThemeShapeInsert) pColorSet->add(model::ThemeColorType::Accent6, 0x9); pColorSet->add(model::ThemeColorType::Hyperlink, 0xa); pColorSet->add(model::ThemeColorType::FollowedHyperlink, 0xb); - aTheme.SetColorSet(std::move(pColorSet)); + pTheme->SetColorSet(std::move(pColorSet)); - xMasterPage->setPropertyValue("Theme", uno::Any(model::theme::createXTheme(aTheme))); + xMasterPage->setPropertyValue("Theme", uno::Any(model::theme::createXTheme(pTheme))); // When inserting a shape: uno::Sequence aArgs = { diff --git a/sd/source/filter/eppt/pptx-epptooxml.cxx b/sd/source/filter/eppt/pptx-epptooxml.cxx index f857f10bec7f..dd555514650a 100644 --- a/sd/source/filter/eppt/pptx-epptooxml.cxx +++ b/sd/source/filter/eppt/pptx-epptooxml.cxx @@ -56,6 +56,7 @@ #include #include +#include #include "pptx-animations.hxx" #include "../ppt/pptanimations.hxx" diff --git a/sd/source/ui/docshell/docshell.cxx b/sd/source/ui/docshell/docshell.cxx index 3aacb189f826..fd564bcc8f4a 100644 --- a/sd/source/ui/docshell/docshell.cxx +++ b/sd/source/ui/docshell/docshell.cxx @@ -61,6 +61,7 @@ #include #include #include +#include using namespace sd; #define ShellClass_DrawDocShell diff --git a/sd/source/ui/func/fuconstr.cxx b/sd/source/ui/func/fuconstr.cxx index eee7094a78f8..3f3085b60d20 100644 --- a/sd/source/ui/func/fuconstr.cxx +++ b/sd/source/ui/func/fuconstr.cxx @@ -29,6 +29,7 @@ #include #include #include +#include #include #include diff --git a/sd/source/ui/func/fupage.cxx b/sd/source/ui/func/fupage.cxx index 7416916f01e7..27a794124b0c 100644 --- a/sd/source/ui/func/fupage.cxx +++ b/sd/source/ui/func/fupage.cxx @@ -48,6 +48,7 @@ #include #include #include +#include #include #include @@ -573,8 +574,8 @@ void FuPage::ApplyItemSet( const SfxItemSet* pArgs ) auto it = pGrabBag->GetGrabBag().find("Theme"); if (it != pGrabBag->GetGrabBag().end()) { - std::unique_ptr pTheme = model::Theme::FromAny(it->second); - pMasterPage->getSdrPageProperties().SetTheme(std::move(pTheme)); + std::shared_ptr pTheme = model::Theme::FromAny(it->second); + pMasterPage->getSdrPageProperties().SetTheme(pTheme); } else { diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx index ca741e9bb53f..e5a231d4d405 100644 --- a/sd/source/ui/unoidl/unomodel.cxx +++ b/sd/source/ui/unoidl/unomodel.cxx @@ -131,6 +131,7 @@ #include #include #include +#include #include @@ -1283,8 +1284,8 @@ void SAL_CALL SdXImpressDocument::setPropertyValue( const OUString& aPropertyNam case WID_MODEL_THEME: { SdrModel& rModel = getSdrModelFromUnoModel(); - std::unique_ptr pTheme = model::Theme::FromAny(aValue); - rModel.setTheme(std::move(pTheme)); + std::shared_ptr pTheme = model::Theme::FromAny(aValue); + rModel.setTheme(pTheme); } break; default: diff --git a/sd/source/ui/unoidl/unopage.cxx b/sd/source/ui/unoidl/unopage.cxx index 65008effaa12..87508052da87 100644 --- a/sd/source/ui/unoidl/unopage.cxx +++ b/sd/source/ui/unoidl/unopage.cxx @@ -76,6 +76,7 @@ #include #include #include +#include #include using ::com::sun::star::animations::XAnimationNode; @@ -984,8 +985,7 @@ void SAL_CALL SdGenericDrawPage::setPropertyValue( const OUString& aPropertyName if (aValue >>= xTheme) { auto& rUnoTheme = dynamic_cast(*xTheme); - std::unique_ptr pTheme(new model::Theme(rUnoTheme.getTheme())); - pPage->getSdrPageProperties().SetTheme(std::move(pTheme)); + pPage->getSdrPageProperties().SetTheme(rUnoTheme.getTheme()); } break; } @@ -993,8 +993,8 @@ void SAL_CALL SdGenericDrawPage::setPropertyValue( const OUString& aPropertyName case WID_PAGE_THEME_UNO_REPRESENTATION: { SdrPage* pPage = GetPage(); - std::unique_ptr pTheme = model::Theme::FromAny(aValue); - pPage->getSdrPageProperties().SetTheme(std::move(pTheme)); + std::shared_ptr pTheme = model::Theme::FromAny(aValue); + pPage->getSdrPageProperties().SetTheme(pTheme); break; } @@ -1316,9 +1316,9 @@ Any SAL_CALL SdGenericDrawPage::getPropertyValue( const OUString& PropertyName ) { SdrPage* pPage = GetPage(); css::uno::Reference xTheme; - auto const& pTheme = pPage->getSdrPageProperties().GetTheme(); + auto pTheme = pPage->getSdrPageProperties().GetTheme(); if (pTheme) - xTheme = new UnoTheme(*pTheme); + xTheme = model::theme::createXTheme(pTheme); aAny <<= xTheme; break; } @@ -1326,11 +1326,9 @@ Any SAL_CALL SdGenericDrawPage::getPropertyValue( const OUString& PropertyName ) case WID_PAGE_THEME_UNO_REPRESENTATION: { SdrPage* pPage = GetPage(); - auto const& pTheme = pPage->getSdrPageProperties().GetTheme(); + auto pTheme = pPage->getSdrPageProperties().GetTheme(); if (pTheme) - { pTheme->ToAny(aAny); - } else { beans::PropertyValues aValues; diff --git a/svx/source/svdraw/svdmodel.cxx b/svx/source/svdraw/svdmodel.cxx index 6f243113c0e1..c3716a4a3efa 100644 --- a/svx/source/svdraw/svdmodel.cxx +++ b/svx/source/svdraw/svdmodel.cxx @@ -88,7 +88,7 @@ struct SdrModelImpl bool mbLegacySingleLineFontwork; // tdf#148000 compatibility flag bool mbConnectorUseSnapRect; // tdf#149756 compatibility flag bool mbIgnoreBreakAfterMultilineField; ///< tdf#148966 compatibility flag - std::unique_ptr mpTheme; + std::shared_ptr mpTheme; SdrModelImpl() : mpUndoManager(nullptr) @@ -1563,12 +1563,12 @@ void SdrModel::SetStarDrawPreviewMode(bool bPreview) } } -void SdrModel::setTheme(std::unique_ptr pTheme) +void SdrModel::setTheme(std::shared_ptr const& pTheme) { - mpImpl->mpTheme = std::move(pTheme); + mpImpl->mpTheme = pTheme; } -std::unique_ptr const& SdrModel::getTheme() const +std::shared_ptr const& SdrModel::getTheme() const { return mpImpl->mpTheme; } diff --git a/svx/source/svdraw/svdpage.cxx b/svx/source/svdraw/svdpage.cxx index 280e5d2f8c70..235fc58da508 100644 --- a/svx/source/svdraw/svdpage.cxx +++ b/svx/source/svdraw/svdpage.cxx @@ -54,6 +54,7 @@ #include #include #include +#include #include @@ -1300,9 +1301,9 @@ void SdrPageProperties::SetStyleSheet(SfxStyleSheet* pStyleSheet) ImpPageChange(*mpSdrPage); } -void SdrPageProperties::SetTheme(std::unique_ptr pTheme) +void SdrPageProperties::SetTheme(std::shared_ptr const& pTheme) { - mpTheme = std::move(pTheme); + mpTheme = pTheme; if (mpTheme && mpTheme->GetColorSet() && mpSdrPage->IsMasterPage()) { @@ -1322,7 +1323,7 @@ void SdrPageProperties::SetTheme(std::unique_ptr pTheme) } } -std::unique_ptr const& SdrPageProperties::GetTheme() const +std::shared_ptr const& SdrPageProperties::GetTheme() const { return mpTheme; } diff --git a/sw/qa/core/theme/ThemeTest.cxx b/sw/qa/core/theme/ThemeTest.cxx index 5c95de1e7c38..f13063bc30ac 100644 --- a/sw/qa/core/theme/ThemeTest.cxx +++ b/sw/qa/core/theme/ThemeTest.cxx @@ -17,6 +17,7 @@ #include #include #include +#include using namespace css; diff --git a/sw/source/core/model/ThemeColorChanger.cxx b/sw/source/core/model/ThemeColorChanger.cxx index 9424e016ab72..dd198c14723e 100644 --- a/sw/source/core/model/ThemeColorChanger.cxx +++ b/sw/source/core/model/ThemeColorChanger.cxx @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include diff --git a/sw/source/core/unocore/unodraw.cxx b/sw/source/core/unocore/unodraw.cxx index 90536712cb7e..7337ce297895 100644 --- a/sw/source/core/unocore/unodraw.cxx +++ b/sw/source/core/unocore/unodraw.cxx @@ -406,8 +406,7 @@ void SwFmDrawPage::setPropertyValue(const OUString& rPropertyName, const uno::An if (aValue >>= xTheme) { auto& rUnoTheme = dynamic_cast(*xTheme); - std::unique_ptr pTheme(new model::Theme(rUnoTheme.getTheme())); - pPage->getSdrPageProperties().SetTheme(std::move(pTheme)); + pPage->getSdrPageProperties().SetTheme(rUnoTheme.getTheme()); } } break; @@ -443,9 +442,9 @@ uno::Any SwFmDrawPage::getPropertyValue(const OUString& rPropertyName) { css::uno::Reference xTheme; - auto const& pTheme = GetSdrPage()->getSdrPageProperties().GetTheme(); + auto pTheme = GetSdrPage()->getSdrPageProperties().GetTheme(); if (pTheme) - xTheme = new UnoTheme(*pTheme); + xTheme = model::theme::createXTheme(pTheme); aAny <<= xTheme; } break; diff --git a/xmloff/inc/XMLThemeContext.hxx b/xmloff/inc/XMLThemeContext.hxx index 50889a0ddf98..b85932d4cb41 100644 --- a/xmloff/inc/XMLThemeContext.hxx +++ b/xmloff/inc/XMLThemeContext.hxx @@ -14,14 +14,18 @@ #include #include -#include #include +namespace model +{ +class Theme; +} + /// Imports the theme class XMLThemeContext : public SvXMLImportContext { css::uno::Reference m_xPage; - model::Theme maTheme; + std::shared_ptr mpTheme; public: XMLThemeContext(SvXMLImport& rImport, diff --git a/xmloff/qa/unit/draw.cxx b/xmloff/qa/unit/draw.cxx index 74a62edbd35f..ba68685d094a 100644 --- a/xmloff/qa/unit/draw.cxx +++ b/xmloff/qa/unit/draw.cxx @@ -31,6 +31,7 @@ #include #include #include +#include using namespace ::com::sun::star; @@ -126,7 +127,7 @@ CPPUNIT_TEST_FIXTURE(XmloffDrawTest, testThemeExport) xDrawPagesSupplier->getDrawPages()->getByIndex(0), uno::UNO_QUERY); uno::Reference xMasterPage(xDrawPage->getMasterPage(), uno::UNO_QUERY); - model::Theme aTheme("mytheme"); + auto pTheme = std::make_shared("mytheme"); std::unique_ptr pColorSet(new model::ColorSet("mycolorscheme")); pColorSet->add(model::ThemeColorType::Dark1, 0x0); pColorSet->add(model::ThemeColorType::Light1, 0x1); @@ -140,9 +141,9 @@ CPPUNIT_TEST_FIXTURE(XmloffDrawTest, testThemeExport) pColorSet->add(model::ThemeColorType::Accent6, 0x9); pColorSet->add(model::ThemeColorType::Hyperlink, 0xa); pColorSet->add(model::ThemeColorType::FollowedHyperlink, 0xb); - aTheme.SetColorSet(std::move(pColorSet)); + pTheme->SetColorSet(std::move(pColorSet)); - uno::Reference xTheme = model::theme::createXTheme(aTheme); + uno::Reference xTheme = model::theme::createXTheme(pTheme); xMasterPage->setPropertyValue("Theme", uno::Any(xTheme)); // Export to ODP: @@ -219,13 +220,14 @@ CPPUNIT_TEST_FIXTURE(XmloffDrawTest, testThemeImport) CPPUNIT_ASSERT(xTheme.is()); auto* pUnoTheme = dynamic_cast(xTheme.get()); CPPUNIT_ASSERT(pUnoTheme); - auto const& rTheme = pUnoTheme->getTheme(); + auto pTheme = pUnoTheme->getTheme(); + CPPUNIT_ASSERT(pTheme); - CPPUNIT_ASSERT_EQUAL(OUString("Office Theme"), rTheme.GetName()); - CPPUNIT_ASSERT_EQUAL(OUString("Office"), rTheme.GetColorSet()->getName()); + CPPUNIT_ASSERT_EQUAL(OUString("Office Theme"), pTheme->GetName()); + CPPUNIT_ASSERT_EQUAL(OUString("Office"), pTheme->GetColorSet()->getName()); CPPUNIT_ASSERT_EQUAL(Color(0x954F72), - rTheme.GetColorSet()->getColor(model::ThemeColorType::FollowedHyperlink)); + pTheme->GetColorSet()->getColor(model::ThemeColorType::FollowedHyperlink)); } CPPUNIT_TEST_FIXTURE(XmloffDrawTest, testThemeColorExportImport) diff --git a/xmloff/qa/unit/text.cxx b/xmloff/qa/unit/text.cxx index 5d3a9cf4ac99..532d97774e2f 100644 --- a/xmloff/qa/unit/text.cxx +++ b/xmloff/qa/unit/text.cxx @@ -25,6 +25,7 @@ #include #include #include +#include using namespace ::com::sun::star; @@ -959,7 +960,7 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testThemeExport) uno::Reference xDrawPage = xDrawPageSupplier->getDrawPage(); uno::Reference xPageProps(xDrawPage, uno::UNO_QUERY); - model::Theme aTheme("My Theme"); + auto pTheme = std::make_shared("My Theme"); std::unique_ptr pColorSet(new model::ColorSet("My Color Scheme")); pColorSet->add(model::ThemeColorType::Dark1, 0x101010); pColorSet->add(model::ThemeColorType::Light1, 0x202020); @@ -973,9 +974,9 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testThemeExport) pColorSet->add(model::ThemeColorType::Accent6, 0xa0a0a0); pColorSet->add(model::ThemeColorType::Hyperlink, 0xb0b0b0); pColorSet->add(model::ThemeColorType::FollowedHyperlink, 0xc0c0c0); - aTheme.SetColorSet(std::move(pColorSet)); + pTheme->SetColorSet(std::move(pColorSet)); - uno::Reference xTheme = model::theme::createXTheme(aTheme); + uno::Reference xTheme = model::theme::createXTheme(pTheme); xPageProps->setPropertyValue("Theme", uno::Any(xTheme)); // Export to ODT: diff --git a/xmloff/source/draw/sdxmlexp.cxx b/xmloff/source/draw/sdxmlexp.cxx index bc7d5e6ad35d..c237fe12470b 100644 --- a/xmloff/source/draw/sdxmlexp.cxx +++ b/xmloff/source/draw/sdxmlexp.cxx @@ -74,6 +74,7 @@ #include #include #include +#include #include using namespace ::com::sun::star; @@ -2383,13 +2384,13 @@ void SdXMLExport::ExportThemeElement(const uno::Reference& x if (!pUnoTheme) return; - auto const& rTheme = pUnoTheme->getTheme(); + auto pTheme = pUnoTheme->getTheme(); - if (!rTheme.GetName().isEmpty()) - AddAttribute(XML_NAMESPACE_LO_EXT, XML_NAME, rTheme.GetName()); + if (!pTheme->GetName().isEmpty()) + AddAttribute(XML_NAMESPACE_LO_EXT, XML_NAME, pTheme->GetName()); SvXMLElementExport aTheme(*this, XML_NAMESPACE_LO_EXT, XML_THEME, true, true); - auto* pColorSet = rTheme.GetColorSet(); + auto* pColorSet = pTheme->GetColorSet(); if (!pColorSet->getName().isEmpty()) AddAttribute(XML_NAMESPACE_LO_EXT, XML_NAME, pColorSet->getName()); SvXMLElementExport aColorTable(*this, XML_NAMESPACE_LO_EXT, XML_COLOR_TABLE, true, true); diff --git a/xmloff/source/style/XMLThemeContext.cxx b/xmloff/source/style/XMLThemeContext.cxx index 8a9a5cdbc558..e35aed99c46f 100644 --- a/xmloff/source/style/XMLThemeContext.cxx +++ b/xmloff/source/style/XMLThemeContext.cxx @@ -26,6 +26,7 @@ #include #include +#include using namespace css; using namespace xmloff::token; @@ -35,6 +36,7 @@ XMLThemeContext::XMLThemeContext(SvXMLImport& rImport, css::uno::Reference const& xPage) : SvXMLImportContext(rImport) , m_xPage(xPage) + , mpTheme(new model::Theme) { for (const auto& rAttribute : sax_fastparser::castToFastAttributeList(xAttrList)) { @@ -43,7 +45,7 @@ XMLThemeContext::XMLThemeContext(SvXMLImport& rImport, case XML_ELEMENT(LO_EXT, XML_NAME): { OUString aName = rAttribute.toString(); - maTheme.SetName(aName); + mpTheme->SetName(aName); break; } } @@ -53,7 +55,7 @@ XMLThemeContext::XMLThemeContext(SvXMLImport& rImport, XMLThemeContext::~XMLThemeContext() { uno::Reference xPropertySet(m_xPage, uno::UNO_QUERY); - uno::Reference xTheme(new UnoTheme(maTheme)); + auto xTheme = model::theme::createXTheme(mpTheme); xPropertySet->setPropertyValue("Theme", uno::Any(xTheme)); } @@ -62,7 +64,7 @@ uno::Reference SAL_CALL XMLThemeContext::createFa { if (nElement == XML_ELEMENT(LO_EXT, XML_COLOR_TABLE)) { - return new XMLColorTableContext(GetImport(), xAttribs, maTheme); + return new XMLColorTableContext(GetImport(), xAttribs, *mpTheme); } return nullptr; -- cgit