include/svx/DocumentColorHelper.hxx | 41 ------------------------------------ sc/source/core/data/document10.cxx | 22 ++++++++++++++++--- sw/inc/doc.hxx | 5 +++- sw/source/core/doc/doc.cxx | 10 +++++++- sw/source/core/doc/docfmt.cxx | 31 ++++++++++++++++++++++----- sw/source/filter/ww8/rtfexport.cxx | 2 - 6 files changed, 58 insertions(+), 53 deletions(-)
New commits: commit c4d627643df612641ec8ffeab8b42b63bd8dab6b Author: Noel Grandin <[email protected]> AuthorDate: Mon Sep 22 10:56:54 2025 +0200 Commit: Noel Grandin <[email protected]> CommitDate: Mon Sep 22 16:00:38 2025 +0200 move DocumentColorHelper code to sc/ since that is the only place using it now. Also makes it more obvious which code needs fixing when I do more ItemSurrogate removal. Change-Id: I28fed90db81cc7831852f19b090fa8a60b5bdaf1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191318 Tested-by: Jenkins Reviewed-by: Noel Grandin <[email protected]> diff --git a/include/svx/DocumentColorHelper.hxx b/include/svx/DocumentColorHelper.hxx deleted file mode 100644 index 9388b7cba815..000000000000 --- a/include/svx/DocumentColorHelper.hxx +++ /dev/null @@ -1,41 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - */ - -#pragma once - -#include <editeng/brushitem.hxx> -#include <editeng/colritem.hxx> -#include <set> -#include <svl/itempool.hxx> - -namespace svx -{ -namespace DocumentColorHelper -{ -inline Color getColorFromItem(const SvxColorItem* pItem) { return pItem->GetValue(); } - -inline Color getColorFromItem(const SvxBrushItem* pItem) { return pItem->GetColor(); } - -template <class T> -void queryColors(const sal_uInt16 nAttrib, const SfxItemPool* pPool, std::set<Color>& rOutput) -{ - for (const SfxPoolItem* pItem : pPool->GetItemSurrogates(nAttrib)) - { - auto pColorItem = static_cast<const T*>(pItem); - Color aColor(getColorFromItem(pColorItem)); - if (COL_AUTO != aColor) - rOutput.insert(aColor); - } -} -} - -} // end of namespace svx - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/core/data/document10.cxx b/sc/source/core/data/document10.cxx index 51308e4981db..614624048d9f 100644 --- a/sc/source/core/data/document10.cxx +++ b/sc/source/core/data/document10.cxx @@ -22,13 +22,14 @@ #include <refupdatecontext.hxx> #include <sal/log.hxx> -#include <svx/DocumentColorHelper.hxx> #include <scitems.hxx> #include <datamapper.hxx> #include <docsh.hxx> #include <bcaslot.hxx> #include <broadcast.hxx> #include <SheetViewManager.hxx> +#include <editeng/brushitem.hxx> +#include <editeng/colritem.hxx> // Add totally brand-new methods to this source file. @@ -185,13 +186,28 @@ void ScDocument::CopyCellValuesFrom( const ScAddress& rTopPos, const sc::CellVal pTab->CopyCellValuesFrom(rTopPos.Col(), rTopPos.Row(), rSrc); } +static Color getColorFromItem(const SvxColorItem* pItem) { return pItem->GetValue(); } +static Color getColorFromItem(const SvxBrushItem* pItem) { return pItem->GetColor(); } + +template <class T> +static void queryColors(const sal_uInt16 nAttrib, const SfxItemPool* pPool, std::set<Color>& rOutput) +{ + for (const SfxPoolItem* pItem : pPool->GetItemSurrogates(nAttrib)) + { + auto pColorItem = static_cast<const T*>(pItem); + Color aColor(getColorFromItem(pColorItem)); + if (COL_AUTO != aColor) + rOutput.insert(aColor); + } +} + std::set<Color> ScDocument::GetDocColors() { std::set<Color> aDocColors; ScDocumentPool *pPool = GetPool(); - svx::DocumentColorHelper::queryColors<SvxBrushItem>(ATTR_BACKGROUND, pPool, aDocColors); - svx::DocumentColorHelper::queryColors<SvxColorItem>(ATTR_FONT_COLOR, pPool, aDocColors); + queryColors<SvxBrushItem>(ATTR_BACKGROUND, pPool, aDocColors); + queryColors<SvxColorItem>(ATTR_FONT_COLOR, pPool, aDocColors); return aDocColors; } commit 50099a54cd32afd361810e3059af3b420741d41b Author: Noel Grandin <[email protected]> AuthorDate: Mon Sep 22 10:51:21 2025 +0200 Commit: Noel Grandin <[email protected]> CommitDate: Mon Sep 22 16:00:25 2025 +0200 tdf#166895 Document Colors do not appear anymore in the color selection missed a spot where we are using surrogate functionality. Also rename ForEachCharacterBrushItem->ForEachCharacterBackgroundBrushItem to make it more obvious. Regression from commit 56d35ad0eaccd353c8acd2a259293199e233e8ec Author: Noel Grandin <[email protected]> Date: Mon Sep 9 17:14:43 2024 +0200 RES_CHRATR_HIGHLIGHT does not need surrogate support and commit 08c58ac51962b65b57c5b76a45467d45807ef02d Author: Noel Grandin <[email protected]> Date: Mon Sep 16 21:04:59 2024 +0200 dont use GetItemSurrogates for gathering SvxColorItem and commit b6a5cdc0f753c8ed6ed080f9189ac2e2601dce9d Author: Noel Grandin <[email protected]> Date: Tue Sep 17 20:19:06 2024 +020 dont use GetItemSurrogates for gathering SvxBrushItem Change-Id: Id67d78aa82f8731555f06b23760c4ea8f0d8eeb5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191317 Tested-by: Jenkins Reviewed-by: Noel Grandin <[email protected]> diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx index 0c9a77bd3cac..3ee03fbe31f1 100644 --- a/sw/inc/doc.hxx +++ b/sw/inc/doc.hxx @@ -1455,7 +1455,7 @@ public: SW_DLLPUBLIC void ForEachCharacterUnderlineItem(const std::function<bool(const SvxUnderlineItem&)>& ) const; /// Iterate over all RES_CHRATR_BACKGROUND SvxBrushItem, if the function returns false, iteration is stopped - SW_DLLPUBLIC void ForEachCharacterBrushItem(const std::function<bool(const SvxBrushItem&)>& ) const; + SW_DLLPUBLIC void ForEachCharacterBackgroundBrushItem(const std::function<bool(const SvxBrushItem&)>& ) const; /// Iterate over all RES_CHRATR_FONT/RES_CHRATR_CJK_FONT/RES_CHRATR_CTL_FONT SvxFontItem, if the function returns false, iteration is stopped SW_DLLPUBLIC void ForEachCharacterFontItem(TypedWhichId<SvxFontItem> nWhich, bool bIgnoreAutoStyles, const std::function<bool(const SvxFontItem&)>& ); @@ -1478,6 +1478,9 @@ public: /// Iterate over all RES_BACKGROUND SvxBrushItem, if the function returns false, iteration is stopped SW_DLLPUBLIC void ForEachBackgroundBrushItem(const std::function<bool(const SvxBrushItem&)>& ) const; + /// Iterate over all RES_CHRATR_HIGHLIGHT SvxBrushItem, if the function returns false, iteration is stopped + SW_DLLPUBLIC void ForEachCharacterHighlightBrushItem(const std::function<bool(const SvxBrushItem&)>& ) const; + // Call into intransparent Basic; expect possible Return String. void ExecMacro( const SvxMacro& rMacro, OUString* pRet, SbxArray* pArgs ); diff --git a/sw/source/core/doc/doc.cxx b/sw/source/core/doc/doc.cxx index 271cc11980ec..af082369e402 100644 --- a/sw/source/core/doc/doc.cxx +++ b/sw/source/core/doc/doc.cxx @@ -1449,12 +1449,18 @@ void SwDoc::ForEachCharacterUnderlineItem( const std::function<bool(const SvxUnd ForEachCharacterItem(this, RES_CHRATR_UNDERLINE, rFunc); } -/// Iterate over all SvxBrushItem, if the function returns false, iteration is stopped -void SwDoc::ForEachCharacterBrushItem( const std::function<bool(const SvxBrushItem&)>& rFunc ) const +/// Iterate over all RES_CHRATR_BACKGROUND SvxBrushItem, if the function returns false, iteration is stopped +void SwDoc::ForEachCharacterBackgroundBrushItem( const std::function<bool(const SvxBrushItem&)>& rFunc ) const { ForEachCharacterItem(this, RES_CHRATR_BACKGROUND, rFunc); } +/// Iterate over all RES_CHRATR_HIGHLIGHT SvxBrushItem, if the function returns false, iteration is stopped +void SwDoc::ForEachCharacterHighlightBrushItem( const std::function<bool(const SvxBrushItem&)>& rFunc ) const +{ + ForEachCharacterItem(this, RES_CHRATR_HIGHLIGHT, rFunc); +} + /// Iterate over all RES_TXTATR_UNKNOWN_CONTAINER SvXMLAttrContainerItem, if the function returns false, iteration is stopped void SwDoc::ForEachTxtAtrContainerItem(const std::function<bool(const SvXMLAttrContainerItem&)>& rFunc ) const { diff --git a/sw/source/core/doc/docfmt.cxx b/sw/source/core/doc/docfmt.cxx index 6c69ac91129f..a7ab0692d0fc 100644 --- a/sw/source/core/doc/docfmt.cxx +++ b/sw/source/core/doc/docfmt.cxx @@ -19,6 +19,8 @@ #include <libxml/xmlwriter.h> #include <hintids.hxx> +#include <editeng/brushitem.hxx> +#include <editeng/colritem.hxx> #include <svl/itemiter.hxx> #include <svl/numformat.hxx> #include <editeng/tstpitem.hxx> @@ -28,7 +30,6 @@ #include <officecfg/Office/Common.hxx> #include <osl/diagnose.h> #include <svl/zforlist.hxx> -#include <svx/DocumentColorHelper.hxx> #include <comphelper/processfactory.hxx> #include <unotools/configmgr.hxx> #include <sal/log.hxx> @@ -2056,11 +2057,31 @@ void SwDBData::dumpAsXml(xmlTextWriterPtr pWriter) const std::set<Color> SwDoc::GetDocColors() { std::set<Color> aDocColors; - SwAttrPool& rPool = GetAttrPool(); - svx::DocumentColorHelper::queryColors<SvxColorItem>(RES_CHRATR_COLOR, &rPool, aDocColors); - svx::DocumentColorHelper::queryColors<SvxBrushItem>(RES_CHRATR_HIGHLIGHT, &rPool, aDocColors); - svx::DocumentColorHelper::queryColors<SvxBrushItem>(RES_CHRATR_BACKGROUND, &rPool, aDocColors); + ForEachCharacterColorItem( + [&aDocColors] (const SvxColorItem& rColorItem) -> bool + { + Color aColor(rColorItem.GetValue()); + if (COL_AUTO != aColor) + aDocColors.insert(aColor); + return true; + }); + ForEachCharacterHighlightBrushItem( + [&aDocColors] (const SvxBrushItem& rColorItem) -> bool + { + Color aColor(rColorItem.GetColor()); + if (COL_AUTO != aColor) + aDocColors.insert(aColor); + return true; + }); + ForEachCharacterBackgroundBrushItem( + [&aDocColors] (const SvxBrushItem& rColorItem) -> bool + { + Color aColor(rColorItem.GetColor()); + if (COL_AUTO != aColor) + aDocColors.insert(aColor); + return true; + }); return aDocColors; } diff --git a/sw/source/filter/ww8/rtfexport.cxx b/sw/source/filter/ww8/rtfexport.cxx index c12f528e43db..1bc1e77c53e2 100644 --- a/sw/source/filter/ww8/rtfexport.cxx +++ b/sw/source/filter/ww8/rtfexport.cxx @@ -1379,7 +1379,7 @@ void RtfExport::OutColorTable() { InsColor(pBackground->GetColor()); } - m_rDoc.ForEachCharacterBrushItem([this](const SvxBrushItem& rBrush) -> bool { + m_rDoc.ForEachCharacterBackgroundBrushItem([this](const SvxBrushItem& rBrush) -> bool { InsColor(rBrush.GetColor()); return true; });
