summaryrefslogtreecommitdiff
path: root/xmloff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2023-02-25 19:12:23 +0900
committerTomaž Vajngerl <quikee@gmail.com>2023-04-08 07:56:19 +0200
commit4f347ebabad6355014889f0a81b107dc774590fe (patch)
tree377e010ec06cf3aed7caf5d04cddf28518fbc676 /xmloff
parentad5756f0529a80fbb537979bcfd9de7a83a69805 (diff)
use shared_ptr for model::Theme instead of unique_ptr
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 <quikee@gmail.com>
Diffstat (limited to 'xmloff')
-rw-r--r--xmloff/inc/XMLThemeContext.hxx8
-rw-r--r--xmloff/qa/unit/draw.cxx16
-rw-r--r--xmloff/qa/unit/text.cxx7
-rw-r--r--xmloff/source/draw/sdxmlexp.cxx9
-rw-r--r--xmloff/source/style/XMLThemeContext.cxx8
5 files changed, 29 insertions, 19 deletions
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 <com/sun/star/util/Color.hpp>
#include <com/sun/star/container/XNameContainer.hpp>
-#include <docmodel/theme/Theme.hxx>
#include <docmodel/theme/ColorSet.hxx>
+namespace model
+{
+class Theme;
+}
+
/// Imports the theme
class XMLThemeContext : public SvXMLImportContext
{
css::uno::Reference<css::drawing::XDrawPage> m_xPage;
- model::Theme maTheme;
+ std::shared_ptr<model::Theme> 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 <svx/svdomedia.hxx>
#include <docmodel/uno/UnoThemeColor.hxx>
#include <docmodel/uno/UnoTheme.hxx>
+#include <docmodel/theme/Theme.hxx>
using namespace ::com::sun::star;
@@ -126,7 +127,7 @@ CPPUNIT_TEST_FIXTURE(XmloffDrawTest, testThemeExport)
xDrawPagesSupplier->getDrawPages()->getByIndex(0), uno::UNO_QUERY);
uno::Reference<beans::XPropertySet> xMasterPage(xDrawPage->getMasterPage(), uno::UNO_QUERY);
- model::Theme aTheme("mytheme");
+ auto pTheme = std::make_shared<model::Theme>("mytheme");
std::unique_ptr<model::ColorSet> 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<util::XTheme> xTheme = model::theme::createXTheme(aTheme);
+ uno::Reference<util::XTheme> 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<UnoTheme*>(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 <comphelper/sequenceashashmap.hxx>
#include <unotools/tempfile.hxx>
#include <docmodel/uno/UnoTheme.hxx>
+#include <docmodel/theme/Theme.hxx>
using namespace ::com::sun::star;
@@ -959,7 +960,7 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testThemeExport)
uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage();
uno::Reference<beans::XPropertySet> xPageProps(xDrawPage, uno::UNO_QUERY);
- model::Theme aTheme("My Theme");
+ auto pTheme = std::make_shared<model::Theme>("My Theme");
std::unique_ptr<model::ColorSet> 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<util::XTheme> xTheme = model::theme::createXTheme(aTheme);
+ uno::Reference<util::XTheme> 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 <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
#include <com/sun/star/util/Color.hpp>
#include <docmodel/uno/UnoTheme.hxx>
+#include <docmodel/theme/Theme.hxx>
#include <o3tl/enumrange.hxx>
using namespace ::com::sun::star;
@@ -2383,13 +2384,13 @@ void SdXMLExport::ExportThemeElement(const uno::Reference<drawing::XDrawPage>& 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 <comphelper/sequence.hxx>
#include <docmodel/uno/UnoTheme.hxx>
+#include <docmodel/theme/Theme.hxx>
using namespace css;
using namespace xmloff::token;
@@ -35,6 +36,7 @@ XMLThemeContext::XMLThemeContext(SvXMLImport& rImport,
css::uno::Reference<css::drawing::XDrawPage> 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<beans::XPropertySet> xPropertySet(m_xPage, uno::UNO_QUERY);
- uno::Reference<util::XTheme> xTheme(new UnoTheme(maTheme));
+ auto xTheme = model::theme::createXTheme(mpTheme);
xPropertySet->setPropertyValue("Theme", uno::Any(xTheme));
}
@@ -62,7 +64,7 @@ uno::Reference<xml::sax::XFastContextHandler> 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;