diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2023-02-07 16:13:27 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2023-03-01 00:29:23 +0000 |
commit | 4a7a89b97b0b6464f8375926d98044634d06b4ee (patch) | |
tree | 669bc858797ac675acebd6ee526dd5ef9213df9e /sw/source | |
parent | 1309e6332d7ff2bd1f9b6bf87385b8b570e59158 (diff) |
create a default theme when SdrPage and SdrModel are created
For a document it is expected that it always has a theme available
so we need to create a theme with some default attributes set (a
default color scheme for now) when we create a SdrModel and SdrPage
(only for Writer currently).
This also changes some ColorSets, SdrPage, SdrModel methods, to use
better return types (cost& instead of raw pointers and vice versa
depending on the use case).
Change-Id: I874247784b845109e42567e3f45647dda46ccf3b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146816
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'sw/source')
-rw-r--r-- | sw/source/core/model/ThemeColorChanger.cxx | 4 | ||||
-rw-r--r-- | sw/source/core/unocore/unodraw.cxx | 2 | ||||
-rw-r--r-- | sw/source/filter/xml/xmlfmte.cxx | 2 | ||||
-rw-r--r-- | sw/source/uibase/app/docst.cxx | 2 | ||||
-rw-r--r-- | sw/source/uibase/shells/basesh.cxx | 6 | ||||
-rw-r--r-- | sw/source/uibase/sidebar/ThemePanel.cxx | 22 | ||||
-rw-r--r-- | sw/source/uibase/sidebar/ThemePanel.hxx | 2 |
7 files changed, 13 insertions, 27 deletions
diff --git a/sw/source/core/model/ThemeColorChanger.cxx b/sw/source/core/model/ThemeColorChanger.cxx index 589ca7e8cc17..9424e016ab72 100644 --- a/sw/source/core/model/ThemeColorChanger.cxx +++ b/sw/source/core/model/ThemeColorChanger.cxx @@ -151,7 +151,7 @@ void ThemeColorChanger::apply(model::ColorSet const& rColorSet) pDocument->GetIDocumentUndoRedo().StartUndo(SwUndoId::EMPTY, nullptr); SdrPage* pPage = pDocument->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0); - model::Theme* pTheme = pPage->getSdrPageProperties().GetTheme(); + model::Theme* pTheme = pPage->getSdrPageProperties().GetTheme().get(); if (pTheme) { pTheme->SetColorSet(std::make_unique<model::ColorSet>(rColorSet)); @@ -159,7 +159,7 @@ void ThemeColorChanger::apply(model::ColorSet const& rColorSet) else { pPage->getSdrPageProperties().SetTheme(std::make_unique<model::Theme>("Office")); - pTheme = pPage->getSdrPageProperties().GetTheme(); + pTheme = pPage->getSdrPageProperties().GetTheme().get(); pTheme->SetColorSet(std::make_unique<model::ColorSet>(rColorSet)); } diff --git a/sw/source/core/unocore/unodraw.cxx b/sw/source/core/unocore/unodraw.cxx index af4502e7449f..90536712cb7e 100644 --- a/sw/source/core/unocore/unodraw.cxx +++ b/sw/source/core/unocore/unodraw.cxx @@ -443,7 +443,7 @@ uno::Any SwFmDrawPage::getPropertyValue(const OUString& rPropertyName) { css::uno::Reference<css::util::XTheme> xTheme; - auto* pTheme = GetSdrPage()->getSdrPageProperties().GetTheme(); + auto const& pTheme = GetSdrPage()->getSdrPageProperties().GetTheme(); if (pTheme) xTheme = new UnoTheme(*pTheme); aAny <<= xTheme; diff --git a/sw/source/filter/xml/xmlfmte.cxx b/sw/source/filter/xml/xmlfmte.cxx index 4392158ebccd..b219071a77e5 100644 --- a/sw/source/filter/xml/xmlfmte.cxx +++ b/sw/source/filter/xml/xmlfmte.cxx @@ -205,7 +205,7 @@ void SwXMLExport::ExportThemeElement(const uno::Reference<drawing::XDrawPage>& x if (!pPage) return; - auto* pTheme = pPage->getSdrPageProperties().GetTheme(); + auto const& pTheme = pPage->getSdrPageProperties().GetTheme(); if (!pTheme) return; diff --git a/sw/source/uibase/app/docst.cxx b/sw/source/uibase/app/docst.cxx index 84aacfa1d47d..cd1e3dcde925 100644 --- a/sw/source/uibase/app/docst.cxx +++ b/sw/source/uibase/app/docst.cxx @@ -1585,7 +1585,7 @@ std::vector<Color> SwDocShell::GetThemeColors() SdrPage* pPage = m_xDoc->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0); if (!pPage) return {}; - model::Theme* pTheme = pPage->getSdrPageProperties().GetTheme(); + auto const& pTheme = pPage->getSdrPageProperties().GetTheme(); if (!pTheme) return {}; return pTheme->GetColors(); diff --git a/sw/source/uibase/shells/basesh.cxx b/sw/source/uibase/shells/basesh.cxx index 0006596a87fb..5e5d07565b5d 100644 --- a/sw/source/uibase/shells/basesh.cxx +++ b/sw/source/uibase/shells/basesh.cxx @@ -2217,7 +2217,7 @@ void SwBaseShell::GetState( SfxItemSet &rSet ) SdrPage* pPage = pDocument->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0); if (pPage) { - model::Theme* pTheme = pPage->getSdrPageProperties().GetTheme(); + auto const& pTheme = pPage->getSdrPageProperties().GetTheme(); if (pTheme) bDisable = false; } @@ -3058,11 +3058,11 @@ void SwBaseShell::ExecDlg(SfxRequest &rReq) if (pDocumentShell) { SdrPage* pPage = pDocument->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0); - model::Theme* pTheme = pPage->getSdrPageProperties().GetTheme(); + auto const& pTheme = pPage->getSdrPageProperties().GetTheme(); if (pTheme) { std::shared_ptr<svx::IThemeColorChanger> pChanger(new sw::ThemeColorChanger(pDocumentShell)); - auto pDialog = std::make_shared<svx::ThemeDialog>(pMDI, pTheme, pChanger); + auto pDialog = std::make_shared<svx::ThemeDialog>(pMDI, pTheme.get(), pChanger); weld::DialogController::runAsync(pDialog, [](int) {}); } } diff --git a/sw/source/uibase/sidebar/ThemePanel.cxx b/sw/source/uibase/sidebar/ThemePanel.cxx index 6a2647ebbbee..2dabadbba545 100644 --- a/sw/source/uibase/sidebar/ThemePanel.cxx +++ b/sw/source/uibase/sidebar/ThemePanel.cxx @@ -47,28 +47,15 @@ ThemePanel::ThemePanel(weld::Widget* pParent) mxApplyButton->connect_clicked(LINK(this, ThemePanel, ClickHdl)); mxValueSetColors->SetDoubleClickHdl(LINK(this, ThemePanel, DoubleClickValueSetHdl)); - maColorSets.init(); - - SwDocShell* pDocSh = static_cast<SwDocShell*>(SfxObjectShell::Current()); - SwDoc* pDocument = pDocSh->GetDoc(); - if (pDocument) - { - SdrPage* pPage = pDocument->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0); - model::Theme* pTheme = pPage->getSdrPageProperties().GetTheme(); - if (pTheme) - maColorSets.insert(*pTheme->GetColorSet()); - } - - const std::vector<model::ColorSet>& aColorSets = maColorSets.getColorSets(); - for (size_t i = 0; i < aColorSets.size(); ++i) + auto const& rColorSets = svx::ColorSets::get(); + for (model::ColorSet const& rColorSet : rColorSets.getColorSetVector()) { - const model::ColorSet& rColorSet = aColorSets[i]; mxValueSetColors->insert(rColorSet); } mxValueSetColors->SetOptimalSize(); - if (!aColorSets.empty()) + if (!rColorSets.getColorSetVector().empty()) mxValueSetColors->SelectItem(1); // ItemId 1, position 0 } @@ -106,7 +93,8 @@ void ThemePanel::DoubleClickHdl() return; sal_uInt32 nIndex = nItemId - 1; - model::ColorSet const& rColorSet = maColorSets.getColorSet(nIndex); + auto const& rColorSets = svx::ColorSets::get(); + model::ColorSet const& rColorSet = rColorSets.getColorSet(nIndex); ThemeColorChanger aChanger(pDocSh); aChanger.apply(rColorSet); diff --git a/sw/source/uibase/sidebar/ThemePanel.hxx b/sw/source/uibase/sidebar/ThemePanel.hxx index 848d022ee0c6..12285286f546 100644 --- a/sw/source/uibase/sidebar/ThemePanel.hxx +++ b/sw/source/uibase/sidebar/ThemePanel.hxx @@ -43,8 +43,6 @@ private: std::unique_ptr<weld::CustomWeld> mxValueSetColorsWin; std::unique_ptr<weld::Button> mxApplyButton; - svx::ColorSets maColorSets; - DECL_LINK(ClickHdl, weld::Button&, void); DECL_LINK(DoubleClickHdl, weld::TreeView&, bool); DECL_LINK(DoubleClickValueSetHdl, ValueSet*, void); |