Resolves: tdf#162093 TableRef item specifier may occur standalone
[LibreOffice.git] / sc / qa / unit / ucalc_DocumentThemes.cxx
blob83878d02186d5647c7c5c92c9fc78baccfb1693e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include "helper/qahelper.hxx"
12 #include <docmodel/theme/Theme.hxx>
13 #include <editeng/brushitem.hxx>
14 #include <editeng/colritem.hxx>
16 #include <patattr.hxx>
17 #include <scitems.hxx>
18 #include <undomanager.hxx>
19 #include <ThemeColorChanger.hxx>
21 using namespace css;
23 class DocumentThemesTest : public ScUcalcTestBase
27 namespace
29 CPPUNIT_TEST_FIXTURE(DocumentThemesTest, testGetTheme)
31 m_pDoc->InitDrawLayer();
32 m_pDoc->InsertTab(0, u"Test"_ustr);
34 ScDrawLayer* pDrawLayer = m_pDoc->GetDrawLayer();
35 CPPUNIT_ASSERT(pDrawLayer);
36 auto const& pTheme = pDrawLayer->getTheme();
37 CPPUNIT_ASSERT(pTheme);
40 CPPUNIT_TEST_FIXTURE(DocumentThemesTest, testChangeTheme)
42 m_pDoc->InitDrawLayer();
43 m_pDoc->InsertTab(0, u"Test"_ustr);
45 ScDrawLayer* pDrawLayer = m_pDoc->GetDrawLayer();
46 CPPUNIT_ASSERT(pDrawLayer);
47 auto const& pTheme = pDrawLayer->getTheme();
48 CPPUNIT_ASSERT(pTheme);
50 Color aBackgroundThemeColor(0xc99c00);
51 Color aCellTextThemeColor(0x0369a3);
53 auto eBackgroundThemeType = model::ThemeColorType::Accent5;
54 auto eCellTextThemeType = model::ThemeColorType::Accent2;
56 ScPatternAttr aNewPattern(m_pDoc->getCellAttributeHelper());
58 model::ComplexColor aComplexColor;
59 aComplexColor.setThemeColor(eBackgroundThemeType);
60 Color aColor = pTheme->getColorSet()->resolveColor(aComplexColor);
61 aNewPattern.GetItemSet().Put(SvxBrushItem(aColor, aComplexColor, ATTR_BACKGROUND));
64 model::ComplexColor aComplexColor;
65 aComplexColor.setThemeColor(eCellTextThemeType);
66 Color aColor = pTheme->getColorSet()->resolveColor(aComplexColor);
67 aNewPattern.GetItemSet().Put(SvxColorItem(aColor, aComplexColor, ATTR_FONT_COLOR));
70 // Apply the pattern to cells C3:E5 (2,2 - 4,4) on the first sheet
71 m_pDoc->ApplyPatternAreaTab(2, 2, 4, 4, 0, aNewPattern);
74 const SfxPoolItem* pItem = nullptr;
75 auto* pPattern = m_pDoc->GetPattern(ScAddress(3, 3, 0));
76 CPPUNIT_ASSERT(pPattern);
78 pPattern->GetItemSet().HasItem(ATTR_BACKGROUND, &pItem);
79 auto pBrushItem = static_cast<const SvxBrushItem*>(pItem);
80 CPPUNIT_ASSERT_EQUAL(aBackgroundThemeColor, pBrushItem->GetColor());
81 pPattern->GetItemSet().HasItem(ATTR_FONT_COLOR, &pItem);
82 auto pColorItem = static_cast<const SvxColorItem*>(pItem);
83 CPPUNIT_ASSERT_EQUAL(aCellTextThemeColor, pColorItem->getColor());
86 auto pColorSet = std::make_shared<model::ColorSet>("TestColorScheme");
87 pColorSet->add(model::ThemeColorType::Dark1, 0x000000);
88 pColorSet->add(model::ThemeColorType::Light1, 0x111111);
89 pColorSet->add(model::ThemeColorType::Dark2, 0x222222);
90 pColorSet->add(model::ThemeColorType::Light2, 0x333333);
91 pColorSet->add(model::ThemeColorType::Accent1, 0x444444);
92 pColorSet->add(model::ThemeColorType::Accent2, 0x555555);
93 pColorSet->add(model::ThemeColorType::Accent3, 0x666666);
94 pColorSet->add(model::ThemeColorType::Accent4, 0x777777);
95 pColorSet->add(model::ThemeColorType::Accent5, 0x888888);
96 pColorSet->add(model::ThemeColorType::Accent6, 0x999999);
97 pColorSet->add(model::ThemeColorType::Hyperlink, 0xaaaaaa);
98 pColorSet->add(model::ThemeColorType::FollowedHyperlink, 0xbbbbbb);
100 sc::ThemeColorChanger aChanger(*m_xDocShell);
101 aChanger.apply(pColorSet);
104 const SfxPoolItem* pItem = nullptr;
105 auto* pPattern = m_pDoc->GetPattern(ScAddress(3, 3, 0));
106 CPPUNIT_ASSERT(pPattern);
108 pPattern->GetItemSet().HasItem(ATTR_BACKGROUND, &pItem);
109 auto pBrushItem = static_cast<const SvxBrushItem*>(pItem);
110 CPPUNIT_ASSERT_EQUAL(pColorSet->getColor(eBackgroundThemeType), pBrushItem->GetColor());
111 pPattern->GetItemSet().HasItem(ATTR_FONT_COLOR, &pItem);
112 auto pColorItem = static_cast<const SvxColorItem*>(pItem);
113 CPPUNIT_ASSERT_EQUAL(pColorSet->getColor(eCellTextThemeType), pColorItem->getColor());
116 // Undo / Redo
118 m_pDoc->GetUndoManager()->Undo();
121 const SfxPoolItem* pItem = nullptr;
122 auto* pPattern = m_pDoc->GetPattern(ScAddress(3, 3, 0));
123 CPPUNIT_ASSERT(pPattern);
125 pPattern->GetItemSet().HasItem(ATTR_BACKGROUND, &pItem);
126 auto pBrushItem = static_cast<const SvxBrushItem*>(pItem);
127 CPPUNIT_ASSERT_EQUAL(aBackgroundThemeColor, pBrushItem->GetColor());
128 pPattern->GetItemSet().HasItem(ATTR_FONT_COLOR, &pItem);
129 auto pColorItem = static_cast<const SvxColorItem*>(pItem);
130 CPPUNIT_ASSERT_EQUAL(aCellTextThemeColor, pColorItem->getColor());
133 m_pDoc->GetUndoManager()->Redo();
136 const SfxPoolItem* pItem = nullptr;
137 auto* pPattern = m_pDoc->GetPattern(ScAddress(3, 3, 0));
138 CPPUNIT_ASSERT(pPattern);
140 pPattern->GetItemSet().HasItem(ATTR_BACKGROUND, &pItem);
141 auto pBrushItem = static_cast<const SvxBrushItem*>(pItem);
142 CPPUNIT_ASSERT_EQUAL(pColorSet->getColor(eBackgroundThemeType), pBrushItem->GetColor());
143 pPattern->GetItemSet().HasItem(ATTR_FONT_COLOR, &pItem);
144 auto pColorItem = static_cast<const SvxColorItem*>(pItem);
145 CPPUNIT_ASSERT_EQUAL(pColorSet->getColor(eCellTextThemeType), pColorItem->getColor());
149 } // end anonymous namespace
151 CPPUNIT_PLUGIN_IMPLEMENT();
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */