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 /svx | |
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 'svx')
-rw-r--r-- | svx/source/dialog/ThemeDialog.cxx | 19 | ||||
-rw-r--r-- | svx/source/styles/ColorSets.cxx | 34 | ||||
-rw-r--r-- | svx/source/svdraw/svdmodel.cxx | 24 | ||||
-rw-r--r-- | svx/source/svdraw/svdpage.cxx | 25 |
4 files changed, 80 insertions, 22 deletions
diff --git a/svx/source/dialog/ThemeDialog.cxx b/svx/source/dialog/ThemeDialog.cxx index 842a40203efa..9da0e48bf13b 100644 --- a/svx/source/dialog/ThemeDialog.cxx +++ b/svx/source/dialog/ThemeDialog.cxx @@ -11,6 +11,7 @@ #include <docmodel/theme/ThemeColor.hxx> #include <docmodel/theme/ColorSet.hxx> #include <docmodel/theme/Theme.hxx> +#include <svx/ColorSets.hxx> #include <vcl/svapp.hxx> namespace svx @@ -29,17 +30,19 @@ ThemeDialog::ThemeDialog(weld::Window* pParent, model::Theme* pTheme, mxValueSetThemeColors->SetColor(Application::GetSettings().GetStyleSettings().GetFaceColor()); mxValueSetThemeColors->SetDoubleClickHdl(LINK(this, ThemeDialog, DoubleClickValueSetHdl)); - maColorSets.init(); - maColorSets.insert(*mpTheme->GetColorSet()); + if (mpTheme) + maColorSets.push_back(*mpTheme->GetColorSet()); + auto const& rColorSetVector = ColorSets::get().getColorSetVector(); + maColorSets.insert(maColorSets.end(), rColorSetVector.begin(), rColorSetVector.end()); - for (auto const& rColorSet : maColorSets.getColorSets()) + for (auto const& rColorSet : maColorSets) { mxValueSetThemeColors->insert(rColorSet); } mxValueSetThemeColors->SetOptimalSize(); - if (!maColorSets.getColorSets().empty()) + if (!rColorSetVector.empty()) mxValueSetThemeColors->SelectItem(1); // ItemId 1, position 0 } @@ -55,9 +58,11 @@ void ThemeDialog::DoubleClickHdl() sal_uInt32 nIndex = nItemId - 1; - model::ColorSet const& rColorSet = maColorSets.getColorSet(nIndex); - - mpChanger->apply(rColorSet); + if (nIndex < maColorSets.size()) + { + model::ColorSet const& rColorSet = maColorSets[nIndex]; + mpChanger->apply(rColorSet); + } } } // end svx namespace diff --git a/svx/source/styles/ColorSets.cxx b/svx/source/styles/ColorSets.cxx index 145babb7d98d..438a9a36b01c 100644 --- a/svx/source/styles/ColorSets.cxx +++ b/svx/source/styles/ColorSets.cxx @@ -19,10 +19,18 @@ namespace svx { ColorSets::ColorSets() -{} +{ + init(); +} + +ColorSets& ColorSets::get() +{ + static std::optional<ColorSets> sColorSet; + if (!sColorSet) + sColorSet = ColorSets(); + return *sColorSet; +} -ColorSets::~ColorSets() -{} void ColorSets::init() { @@ -140,19 +148,29 @@ void ColorSets::init() } } -const model::ColorSet& ColorSets::getColorSet(std::u16string_view rName) +model::ColorSet const* ColorSets::getColorSet(std::u16string_view rName) const { for (const model::ColorSet & rColorSet : maColorSets) { if (rColorSet.getName() == rName) - return rColorSet; + return &rColorSet; } - return maColorSets[0]; + return nullptr; } -void ColorSets::insert(model::ColorSet const& rColorSet) +void ColorSets::insert(model::ColorSet const& rNewColorSet) { - maColorSets.push_back(rColorSet); + for (model::ColorSet& rColorSet : maColorSets) + { + if (rColorSet.getName() == rNewColorSet.getName()) + { + rColorSet = rNewColorSet; + return; + } + } + + // color set not found, so insert it + maColorSets.push_back(rNewColorSet); } } // end of namespace svx diff --git a/svx/source/svdraw/svdmodel.cxx b/svx/source/svdraw/svdmodel.cxx index 47f2b517bf5e..5a577da212b3 100644 --- a/svx/source/svdraw/svdmodel.cxx +++ b/svx/source/svdraw/svdmodel.cxx @@ -73,6 +73,7 @@ #include <comphelper/diagnose_ex.hxx> #include <tools/UnitConversion.hxx> #include <docmodel/theme/Theme.hxx> +#include <svx/ColorSets.hxx> #include <svx/svditer.hxx> #include <svx/svdoashp.hxx> @@ -96,7 +97,18 @@ struct SdrModelImpl , mbLegacySingleLineFontwork(false) , mbConnectorUseSnapRect(false) , mbIgnoreBreakAfterMultilineField(false) + , mpTheme(new model::Theme("Office")) {} + + void initTheme() + { + auto const* pColorSet = svx::ColorSets::get().getColorSet(u"LibreOffice"); + if (pColorSet) + { + std::unique_ptr<model::ColorSet> pDefaultColorSet(new model::ColorSet(*pColorSet)); + mpTheme->SetColorSet(std::move(pDefaultColorSet)); + } + } }; @@ -182,6 +194,8 @@ SdrModel::SdrModel(SfxItemPool* pPool, comphelper::IEmbeddedHelper* pEmbeddedHel ImpSetOutlinerDefaults(m_pChainingOutliner.get(), true); ImpCreateTables(bDisablePropertyFiles || utl::ConfigManager::IsFuzzing()); + + mpImpl->initTheme(); } SdrModel::~SdrModel() @@ -1550,9 +1564,15 @@ void SdrModel::SetStarDrawPreviewMode(bool bPreview) } } -void SdrModel::SetTheme(std::unique_ptr<model::Theme> pTheme) { mpImpl->mpTheme = std::move(pTheme); } +void SdrModel::setTheme(std::unique_ptr<model::Theme> pTheme) +{ + mpImpl->mpTheme = std::move(pTheme); +} -model::Theme* SdrModel::GetTheme() { return mpImpl->mpTheme.get(); } +std::unique_ptr<model::Theme> const& SdrModel::getTheme() const +{ + return mpImpl->mpTheme; +} uno::Reference< uno::XInterface > const & SdrModel::getUnoModel() { diff --git a/svx/source/svdraw/svdpage.cxx b/svx/source/svdraw/svdpage.cxx index cb2fb64e7e80..8a3c4049f7bf 100644 --- a/svx/source/svdraw/svdpage.cxx +++ b/svx/source/svdraw/svdpage.cxx @@ -45,6 +45,7 @@ #include <svx/xfillit0.hxx> #include <svx/fmdpage.hxx> #include <svx/theme/ThemeColorChanger.hxx> +#include <svx/ColorSets.hxx> #include <sdr/contact/viewcontactofsdrpage.hxx> #include <svx/sdr/contact/viewobjectcontact.hxx> @@ -1210,16 +1211,27 @@ static void ImpPageChange(SdrPage& rSdrPage) } SdrPageProperties::SdrPageProperties(SdrPage& rSdrPage) -: mpSdrPage(&rSdrPage), - mpStyleSheet(nullptr), - maProperties( + : mpSdrPage(&rSdrPage) + , mpStyleSheet(nullptr) + , maProperties( mpSdrPage->getSdrModelFromSdrPage().GetItemPool(), svl::Items<XATTR_FILL_FIRST, XATTR_FILL_LAST>) { - if(!rSdrPage.IsMasterPage()) + if (!rSdrPage.IsMasterPage()) { maProperties.Put(XFillStyleItem(drawing::FillStyle_NONE)); } + + if (rSdrPage.getSdrModelFromSdrPage().IsWriter()) + { + mpTheme.reset(new model::Theme("Office")); + auto const* pColorSet = svx::ColorSets::get().getColorSet(u"LibreOffice"); + if (pColorSet) + { + std::unique_ptr<model::ColorSet> pDefaultColorSet(new model::ColorSet(*pColorSet)); + mpTheme->SetColorSet(std::move(pDefaultColorSet)); + } + } } SdrPageProperties::~SdrPageProperties() @@ -1310,7 +1322,10 @@ void SdrPageProperties::SetTheme(std::unique_ptr<model::Theme> pTheme) } } -model::Theme* SdrPageProperties::GetTheme() { return mpTheme.get(); } +std::unique_ptr<model::Theme> const& SdrPageProperties::GetTheme() const +{ + return mpTheme; +} void SdrPageProperties::dumpAsXml(xmlTextWriterPtr pWriter) const { |