include/svx/theme/ThemeColorChangerCommon.hxx | 5 sc/source/ui/theme/ThemeColorChanger.cxx | 21 +- sd/source/core/ThemeColorChanger.cxx | 29 +++ svx/source/theme/ThemeColorChangerCommon.cxx | 192 ++++++++++++++++---------- sw/source/core/model/ThemeColorChanger.cxx | 19 ++ 5 files changed, 175 insertions(+), 91 deletions(-)
New commits: commit 151e55ba811a4fddcefe26601c26447f7085b359 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Thu Aug 17 22:35:26 2023 +0200 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Mon Aug 28 12:44:30 2023 +0200 svx: refactor text color theme changing and add undo support This refactors text theme color changing to use editeng directly and also makes it possible to add undo support. Some refactoring changes were also needed in Writer and Calc ThemeColorChanger implementations. Change-Id: I5cc21205aa3866f65f5b2132ecaa760292401263 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155819 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> (cherry picked from commit 32400a791522d90c3b9b731b73c751b7967f660c) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156165 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/include/svx/theme/ThemeColorChangerCommon.hxx b/include/svx/theme/ThemeColorChangerCommon.hxx index 235648df2cab..d60d9c1ba7fb 100644 --- a/include/svx/theme/ThemeColorChangerCommon.hxx +++ b/include/svx/theme/ThemeColorChangerCommon.hxx @@ -14,12 +14,15 @@ #include <docmodel/theme/ColorSet.hxx> #include <svx/svdpage.hxx> #include <svx/svdobj.hxx> +#include <svx/svdview.hxx> +#include <svl/undo.hxx> namespace svx { namespace theme { -SVXCORE_DLLPUBLIC void updateSdrObject(model::ColorSet const& rColorSet, SdrObject* pObject); +SVXCORE_DLLPUBLIC void updateSdrObject(model::ColorSet const& rColorSet, SdrObject* pObject, + SdrView* pView, SfxUndoManager* pUndoManager = nullptr); } } // end svx namespace diff --git a/sc/source/ui/theme/ThemeColorChanger.cxx b/sc/source/ui/theme/ThemeColorChanger.cxx index acef84f89fa0..4b1b555ec647 100644 --- a/sc/source/ui/theme/ThemeColorChanger.cxx +++ b/sc/source/ui/theme/ThemeColorChanger.cxx @@ -151,7 +151,7 @@ bool changeStyles(ScDocShell& rDocShell, std::shared_ptr<model::ColorSet> const& return bChanged; } -bool changeSheets(ScDocShell& rDocShell, ScDrawLayer* pModel, +bool changeSheets(ScDocShell& rDocShell, ScTabViewShell* pViewShell, ScDrawLayer* pModel, std::shared_ptr<model::ColorSet> const& pColorSet) { ScDocument& rDocument = rDocShell.GetDocument(); @@ -209,14 +209,15 @@ bool changeSheets(ScDocShell& rDocShell, ScDrawLayer* pModel, // Change all SdrObjects { pModel->BeginCalcUndo(true); + SdrView* pView = nullptr; + if (pViewShell) + pView = pViewShell->GetScDrawView(); SdrPage* pPage = pModel->GetPage(static_cast<sal_uInt16>(nTab)); SdrObjListIter aIter(pPage, SdrIterMode::DeepNoGroups); - SdrObject* pObject = aIter.Next(); - while (pObject) + for (SdrObject* pObject = aIter.Next(); pObject; pObject = aIter.Next()) { - svx::theme::updateSdrObject(*pColorSet, pObject); - pObject = aIter.Next(); + svx::theme::updateSdrObject(*pColorSet, pObject, pView, rDocShell.GetUndoManager()); } std::unique_ptr<SdrUndoGroup> pUndo = pModel->GetCalcUndo(); @@ -224,7 +225,6 @@ bool changeSheets(ScDocShell& rDocShell, ScDrawLayer* pModel, if (pUndo) { bChanged = true; - pUndo->SetComment("Hi!"); auto pUndoDraw = std::make_unique<ScUndoDraw>(std::move(pUndo), &rDocShell); rDocShell.GetUndoManager()->AddUndoAction(std::move(pUndoDraw)); } @@ -316,9 +316,11 @@ void ThemeColorChanger::apply(std::shared_ptr<model::ColorSet> const& pColorSet) const bool bUndo(rDocument.IsUndoEnabled()); + ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); + ViewShellId nViewShellId(-1); - if (ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell()) - nViewShellId = pViewSh->GetViewShellId(); + if (pViewShell) + nViewShellId = pViewShell->GetViewShellId(); if (bUndo) { @@ -328,7 +330,8 @@ void ThemeColorChanger::apply(std::shared_ptr<model::ColorSet> const& pColorSet) bool bChanged = false; bChanged = changeStyles(m_rDocShell, pColorSet) || bChanged; - bChanged = changeSheets(m_rDocShell, rDocument.GetDrawLayer(), pColorSet) || bChanged; + bChanged + = changeSheets(m_rDocShell, pViewShell, rDocument.GetDrawLayer(), pColorSet) || bChanged; changeSparklines(m_rDocShell, pColorSet); changeTheTheme(m_rDocShell, pColorSet); diff --git a/sd/source/core/ThemeColorChanger.cxx b/sd/source/core/ThemeColorChanger.cxx index 01215f789fc2..163e51e091f9 100644 --- a/sd/source/core/ThemeColorChanger.cxx +++ b/sd/source/core/ThemeColorChanger.cxx @@ -122,10 +122,15 @@ bool changeStyles(sd::DrawDocShell* pDocShell, std::shared_ptr<model::ColorSet> void ThemeColorChanger::apply(std::shared_ptr<model::ColorSet> const& pColorSet) { auto* pUndoManager = mpDocShell->GetUndoManager(); + sd::ViewShell* pViewShell = mpDocShell->GetViewShell(); + if (!pViewShell) + return; - ViewShellId nViewShellId(-1); - if (sd::ViewShell* pViewShell = mpDocShell->GetViewShell()) - nViewShellId = pViewShell->GetViewShellBase().GetViewShellId(); + SdrView* pView = pViewShell->GetView(); + if (!pView) + return; + + ViewShellId nViewShellId = pViewShell->GetViewShellBase().GetViewShellId(); pUndoManager->EnterListAction(SvxResId(RID_SVXSTR_UNDO_THEME_COLOR_CHANGE), "", 0, nViewShellId); @@ -135,6 +140,8 @@ void ThemeColorChanger::apply(std::shared_ptr<model::ColorSet> const& pColorSet) for (sal_uInt16 nPage = 0; nPage < rModel.GetPageCount(); ++nPage) { SdrPage* pCurrentPage = rModel.GetPage(nPage); + + // Skip pages that are usign a different master page if (!pCurrentPage->TRG_HasMasterPage() || &pCurrentPage->TRG_GetMasterPage() != mpMasterPage) continue; @@ -142,7 +149,7 @@ void ThemeColorChanger::apply(std::shared_ptr<model::ColorSet> const& pColorSet) for (size_t nObject = 0; nObject < pCurrentPage->GetObjCount(); ++nObject) { SdrObject* pObject = pCurrentPage->GetObj(nObject); - svx::theme::updateSdrObject(*pColorSet, pObject); + svx::theme::updateSdrObject(*pColorSet, pObject, pView, pUndoManager); // update child objects SdrObjList* pList = pObject->GetSubList(); @@ -151,7 +158,7 @@ void ThemeColorChanger::apply(std::shared_ptr<model::ColorSet> const& pColorSet) SdrObjListIter aIter(pList, SdrIterMode::DeepWithGroups); while (aIter.IsMore()) { - svx::theme::updateSdrObject(*pColorSet, aIter.Next()); + svx::theme::updateSdrObject(*pColorSet, aIter.Next(), pView, pUndoManager); } } } diff --git a/svx/source/theme/ThemeColorChangerCommon.cxx b/svx/source/theme/ThemeColorChangerCommon.cxx index db78e1c343b1..29d65cdda960 100644 --- a/svx/source/theme/ThemeColorChangerCommon.cxx +++ b/svx/source/theme/ThemeColorChangerCommon.cxx @@ -20,106 +20,154 @@ #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/util/XComplexColor.hpp> +#include <svx/xlnclit.hxx> +#include <svx/xflclit.hxx> +#include <svx/xdef.hxx> +#include <editeng/eeitem.hxx> +#include <svx/svdundo.hxx> +#include <svx/svdmodel.hxx> +#include <svx/svdotext.hxx> + +#include <editeng/editeng.hxx> +#include <editeng/section.hxx> +#include <editeng/eeitem.hxx> + using namespace css; namespace svx::theme { namespace { -/// Updates text portion property colors -void updateTextPortionColorSet(model::ColorSet const& rColorSet, - const uno::Reference<beans::XPropertySet>& xPortion) +const SvxColorItem* getColorItem(const editeng::Section& rSection) { - if (!xPortion->getPropertySetInfo()->hasPropertyByName(UNO_NAME_EDIT_CHAR_COMPLEX_COLOR)) - { - return; - } - - uno::Reference<util::XComplexColor> xComplexColor; - xPortion->getPropertyValue(UNO_NAME_EDIT_CHAR_COMPLEX_COLOR) >>= xComplexColor; - if (!xComplexColor.is()) - return; + auto iterator = std::find_if( + rSection.maAttributes.begin(), rSection.maAttributes.end(), + [](const SfxPoolItem* pPoolItem) { return pPoolItem->Which() == EE_CHAR_COLOR; }); - auto aComplexColor = model::color::getFromXComplexColor(xComplexColor); - - if (!aComplexColor.isValidThemeType()) - return; - - Color aColor = rColorSet.resolveColor(aComplexColor); - xPortion->setPropertyValue(UNO_NAME_EDIT_CHAR_COLOR, uno::Any(static_cast<sal_Int32>(aColor))); + if (iterator != rSection.maAttributes.end()) + return static_cast<const SvxColorItem*>(*iterator); + return nullptr; } -/// Updates the fill property colors -void updateFillColorSet(model::ColorSet const& rColorSet, - const uno::Reference<beans::XPropertySet>& xShape) +bool updateEditEngTextSections(model::ColorSet const& rColorSet, SdrObject* pObject, SdrView* pView) { - if (!xShape->getPropertySetInfo()->hasPropertyByName(UNO_NAME_FILL_COMPLEX_COLOR)) - return; + SdrTextObj* pTextObject = DynCastSdrTextObj(pObject); - uno::Reference<util::XComplexColor> xComplexColor; - xShape->getPropertyValue(UNO_NAME_FILL_COMPLEX_COLOR) >>= xComplexColor; - if (!xComplexColor.is()) - return; + if (!pTextObject) + return false; - auto aComplexColor = model::color::getFromXComplexColor(xComplexColor); + pView->SdrBeginTextEdit(pTextObject); - if (!aComplexColor.isValidThemeType()) - return; + auto* pOutlinerView = pView->GetTextEditOutlinerView(); + if (!pOutlinerView) + return false; - Color aColor = rColorSet.resolveColor(aComplexColor); - xShape->setPropertyValue(UNO_NAME_FILLCOLOR, uno::Any(static_cast<sal_Int32>(aColor))); -} + auto* pEditEngine = pOutlinerView->GetEditView().GetEditEngine(); + if (!pEditEngine) + return false; -/// Updates the line property colors -void updateLineColorSet(model::ColorSet const& rColorSet, - const uno::Reference<beans::XPropertySet>& xShape) -{ - if (!xShape->getPropertySetInfo()->hasPropertyByName(UNO_NAME_LINE_COMPLEX_COLOR)) - return; + OutlinerParaObject* pOutlinerParagraphObject = pTextObject->GetOutlinerParaObject(); + if (pOutlinerParagraphObject) + { + const EditTextObject& rEditText = pOutlinerParagraphObject->GetTextObject(); + std::vector<editeng::Section> aSections; + rEditText.GetAllSections(aSections); - uno::Reference<util::XComplexColor> xComplexColor; - xShape->getPropertyValue(UNO_NAME_LINE_COMPLEX_COLOR) >>= xComplexColor; - if (!xComplexColor.is()) - return; + for (editeng::Section const& rSection : aSections) + { + const SvxColorItem* pItem = getColorItem(rSection); + if (!pItem) + continue; - auto aComplexColor = model::color::getFromXComplexColor(xComplexColor); + model::ComplexColor const& rComplexColor = pItem->getComplexColor(); + if (rComplexColor.isValidThemeType()) + { + SfxItemSet aSet(pEditEngine->GetAttribs(rSection.mnParagraph, rSection.mnStart, + rSection.mnEnd, + GetAttribsFlags::CHARATTRIBS)); + Color aNewColor = rColorSet.resolveColor(rComplexColor); + std::unique_ptr<SvxColorItem> pNewItem(pItem->Clone()); + pNewItem->setColor(aNewColor); + aSet.Put(*pNewItem); + + ESelection aSelection(rSection.mnParagraph, rSection.mnStart, rSection.mnParagraph, + rSection.mnEnd); + pEditEngine->QuickSetAttribs(aSet, aSelection); + } + } + } - if (!aComplexColor.isValidThemeType()) - return; + pView->SdrEndTextEdit(); - Color aColor = rColorSet.resolveColor(aComplexColor); - xShape->setPropertyValue(UNO_NAME_LINECOLOR, uno::Any(static_cast<sal_Int32>(aColor))); + return true; } -} // end anonymous namespace - -/// Updates properties of the SdrObject -void updateSdrObject(model::ColorSet const& rColorSet, SdrObject* pObject) +bool updateObjectAttributes(model::ColorSet const& rColorSet, SdrObject& rObject, + SfxUndoManager* pUndoManager) { - uno::Reference<drawing::XShape> xShape = pObject->getUnoShape(); - uno::Reference<text::XTextRange> xShapeText(xShape, uno::UNO_QUERY); - if (xShapeText.is()) + if (pUndoManager) + { + pUndoManager->AddUndoAction( + rObject.getSdrModelFromSdrObject().GetSdrUndoFactory().CreateUndoAttrObject( + rObject, true, true)); + } + bool bChanged = false; + auto aItemSet = rObject.GetMergedItemSet(); + + if (const XFillColorItem* pItem = aItemSet.GetItemIfSet(XATTR_FILLCOLOR, false)) { - // E.g. group shapes have no text. - uno::Reference<container::XEnumerationAccess> xText(xShapeText->getText(), uno::UNO_QUERY); - uno::Reference<container::XEnumeration> xParagraphs = xText->createEnumeration(); - while (xParagraphs->hasMoreElements()) + model::ComplexColor const& rComplexColor = pItem->getComplexColor(); + if (rComplexColor.isValidThemeType()) { - uno::Reference<container::XEnumerationAccess> xParagraph(xParagraphs->nextElement(), - uno::UNO_QUERY); - uno::Reference<container::XEnumeration> xPortions = xParagraph->createEnumeration(); - while (xPortions->hasMoreElements()) - { - uno::Reference<beans::XPropertySet> xPortion(xPortions->nextElement(), - uno::UNO_QUERY); - updateTextPortionColorSet(rColorSet, xPortion); - } + Color aNewColor = rColorSet.resolveColor(rComplexColor); + std::unique_ptr<XFillColorItem> pNewItem(pItem->Clone()); + pNewItem->SetColorValue(aNewColor); + aItemSet.Put(*pNewItem); + bChanged = true; + } + } + if (const XLineColorItem* pItem = aItemSet.GetItemIfSet(XATTR_LINECOLOR, false)) + { + model::ComplexColor const& rComplexColor = pItem->getComplexColor(); + if (rComplexColor.isValidThemeType()) + { + Color aNewColor = rColorSet.resolveColor(rComplexColor); + std::unique_ptr<XLineColorItem> pNewItem(pItem->Clone()); + pNewItem->SetColorValue(aNewColor); + aItemSet.Put(*pNewItem); + bChanged = true; + } + } + if (const SvxColorItem* pItem = aItemSet.GetItemIfSet(EE_CHAR_COLOR, false)) + { + model::ComplexColor const& rComplexColor = pItem->getComplexColor(); + if (rComplexColor.isValidThemeType()) + { + Color aNewColor = rColorSet.resolveColor(rComplexColor); + std::unique_ptr<SvxColorItem> pNewItem(pItem->Clone()); + pNewItem->setColor(aNewColor); + aItemSet.Put(*pNewItem); + bChanged = true; } } + if (bChanged) + { + rObject.SetMergedItemSetAndBroadcast(aItemSet); + } + return bChanged; +} + +} // end anonymous namespace + +/// Updates properties of the SdrObject +void updateSdrObject(model::ColorSet const& rColorSet, SdrObject* pObject, SdrView* pView, + SfxUndoManager* pUndoManager) +{ + if (!pObject) + return; - uno::Reference<beans::XPropertySet> xShapeProps(xShape, uno::UNO_QUERY); - updateFillColorSet(rColorSet, xShapeProps); - updateLineColorSet(rColorSet, xShapeProps); + updateEditEngTextSections(rColorSet, pObject, pView); + updateObjectAttributes(rColorSet, *pObject, pUndoManager); } } // end svx::theme namespace diff --git a/sw/source/core/model/ThemeColorChanger.cxx b/sw/source/core/model/ThemeColorChanger.cxx index 6eb840436755..9b85db154d13 100644 --- a/sw/source/core/model/ThemeColorChanger.cxx +++ b/sw/source/core/model/ThemeColorChanger.cxx @@ -20,13 +20,17 @@ #include <charatr.hxx> #include <paratr.hxx> #include <frmatr.hxx> +#include <wrtsh.hxx> + #include <DocumentContentOperationsManager.hxx> #include <IDocumentDrawModelAccess.hxx> #include <IDocumentUndoRedo.hxx> #include <UndoThemeChange.hxx> +#include <UndoManager.hxx> #include <svx/xflclit.hxx> +#include <svl/undo.hxx> #include <sal/config.h> #include <svx/svdpage.hxx> #include <svx/svditer.hxx> @@ -69,11 +73,13 @@ bool changeBorderLine(editeng::SvxBorderLine* pBorderLine, model::ColorSet const class ThemeColorHandler : public sw::ModelTraverseHandler { SwDoc& mrDocument; + SwDocShell* mpDocShell; model::ColorSet const& mrColorSet; public: - ThemeColorHandler(SwDoc& rDocument, model::ColorSet const& rColorSet) + ThemeColorHandler(SwDoc& rDocument, SwDocShell* pDocShell, model::ColorSet const& rColorSet) : mrDocument(rDocument) + , mpDocShell(pDocShell) , mrColorSet(rColorSet) { } @@ -221,8 +227,13 @@ public: void handleSdrObject(SdrObject* pObject) override { + SwWrtShell* pWrtShell = mpDocShell->GetWrtShell(); + SdrView* pView = pWrtShell->GetDrawView(); + + SfxUndoManager* pManager = &mrDocument.GetUndoManager(); + // update current object - svx::theme::updateSdrObject(mrColorSet, pObject); + svx::theme::updateSdrObject(mrColorSet, pObject, pView, pManager); // update child objects SdrObjList* pList = pObject->GetSubList(); @@ -231,7 +242,7 @@ public: SdrObjListIter aIter(pList, SdrIterMode::DeepWithGroups); while (aIter.IsMore()) { - svx::theme::updateSdrObject(mrColorSet, aIter.Next()); + svx::theme::updateSdrObject(mrColorSet, aIter.Next(), pView, pManager); } } } @@ -422,7 +433,7 @@ void ThemeColorChanger::apply(std::shared_ptr<model::ColorSet> const& pColorSet) } // Direct format change - auto pHandler = std::make_shared<ThemeColorHandler>(*pDocument, *pColorSet); + auto pHandler = std::make_shared<ThemeColorHandler>(*pDocument, mpDocSh, *pColorSet); sw::ModelTraverser aModelTraverser(pDocument); aModelTraverser.addNodeHandler(pHandler); aModelTraverser.traverse(); commit f2f221d66c99650e43369029e101b03abe9783f6 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Tue Aug 15 17:38:03 2023 +0200 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Mon Aug 28 12:44:17 2023 +0200 sd: change text theme colors for graphic styles on theme change Change-Id: I6703c01999663c38d8e75654dcc308c49e014175 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155818 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> (cherry picked from commit a29d4aba60f9e0e7e8d34f8973a351f75a114426) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156164 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/sd/source/core/ThemeColorChanger.cxx b/sd/source/core/ThemeColorChanger.cxx index 84a00527069c..01215f789fc2 100644 --- a/sd/source/core/ThemeColorChanger.cxx +++ b/sd/source/core/ThemeColorChanger.cxx @@ -80,6 +80,18 @@ bool changeStyle(sd::DrawDocShell* pDocShell, SdStyleSheet* pStyle, bChanged = true; } } + if (const SvxColorItem* pItem = aItemSet.GetItemIfSet(EE_CHAR_COLOR, false)) + { + model::ComplexColor const& rComplexColor = pItem->getComplexColor(); + if (rComplexColor.isValidThemeType()) + { + Color aNewColor = pColorSet->resolveColor(rComplexColor); + std::unique_ptr<SvxColorItem> pNewItem(pItem->Clone()); + pNewItem->setColor(aNewColor); + aItemSet.Put(*pNewItem); + bChanged = true; + } + } if (bChanged) { pDocShell->GetUndoManager()->AddUndoAction(