include/svx/dialog/ThemeColorValueSet.hxx  |   38 ++
 svx/Library_svx.mk                         |    1 
 svx/source/dialog/ThemeColorValueSet.cxx   |   98 ++++++
 sw/Library_sw.mk                           |    1 
 sw/inc/swtypes.hxx                         |    6 
 sw/source/core/inc/ThemeColorChanger.hxx   |   33 ++
 sw/source/core/inc/UndoAttribute.hxx       |    2 
 sw/source/core/model/ThemeColorChanger.cxx |  271 ++++++++++++++++++
 sw/source/core/undo/unattr.cxx             |   21 +
 sw/source/uibase/sidebar/ThemePanel.cxx    |  436 -----------------------------
 sw/source/uibase/sidebar/ThemePanel.hxx    |    7 
 sw/uiconfig/swriter/ui/sidebartheme.ui     |  164 ++--------
 12 files changed, 529 insertions(+), 549 deletions(-)

New commits:
commit 1af58b5acec4a2de095d86feef05ac4aed3edb8f
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Fri Jan 6 17:28:49 2023 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Sat Jan 14 07:52:46 2023 +0000

    sw: add ThemeColorChanger that sweeps the model and changes colors
    
    The ThemeColorChanger responisiblity is to recalculate and change
    all the theme colors in the model. This includes styles and direct
    formatting changes. It uses ModelTraverser for direct formatting
    changes as it already implements traversing through nodes.
    
    The ThemeColorChanger replaces the code to change the colors in
    ThemePanel.
    
    Also modify undo/redo for changing of attributes to not move
    the cursor and selection when undoing and redoing (new flag
    NO_CURSOR_CHANGE), as in this case it is very distrcting.
    
    Change-Id: Ida1912bd0697307daad9244d474862830ab2686f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145263
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/sw/Library_sw.mk b/sw/Library_sw.mk
index 478136e50f54..fa2ca1663512 100644
--- a/sw/Library_sw.mk
+++ b/sw/Library_sw.mk
@@ -366,6 +366,7 @@ $(eval $(call gb_Library_add_exception_objects,sw,\
     sw/source/core/layout/wsfrm \
     sw/source/core/model/ModelTraverser \
     sw/source/core/model/SearchResultLocator \
+    sw/source/core/model/ThemeColorChanger \
     sw/source/core/objectpositioning/anchoredobjectposition \
     sw/source/core/objectpositioning/ascharanchoredobjectposition \
     sw/source/core/objectpositioning/environmentofanchoredobject \
diff --git a/sw/inc/swtypes.hxx b/sw/inc/swtypes.hxx
index 96c0fb5008c3..b3cdfa531074 100644
--- a/sw/inc/swtypes.hxx
+++ b/sw/inc/swtypes.hxx
@@ -143,17 +143,19 @@ enum class SetAttrMode
     NOHINTADJUST    = 0x0008,  // No merging of ranges.
     NOFORMATATTR    = 0x0010,  // Do not change into format attribute.
     APICALL         = 0x0020,  // Called from API (all UI related
-                                                        // functionality will 
be disabled).
+                               // functionality will be disabled).
     /// Force hint expand (only matters for hints with CH_TXTATR).
     FORCEHINTEXPAND = 0x0040,
     /// The inserted item is a copy -- intended for use in ndtxt.cxx.
     IS_COPY         = 0x0080,
     /// for Undo, translated to SwInsertFlags::NOHINTEXPAND
     NOHINTEXPAND    = 0x0100,
+    /// don't change the cursor position
+    NO_CURSOR_CHANGE = 0x0200
 };
 namespace o3tl
 {
-    template<> struct typed_flags<SetAttrMode> : is_typed_flags<SetAttrMode, 
0x1ff> {};
+    template<> struct typed_flags<SetAttrMode> : is_typed_flags<SetAttrMode, 
0x3ff> {};
 }
 
 namespace sw {
diff --git a/sw/source/core/inc/ThemeColorChanger.hxx 
b/sw/source/core/inc/ThemeColorChanger.hxx
new file mode 100644
index 000000000000..0698126da3e9
--- /dev/null
+++ b/sw/source/core/inc/ThemeColorChanger.hxx
@@ -0,0 +1,33 @@
+/* -*- 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 <docsh.hxx>
+#include <svx/ColorSets.hxx>
+
+namespace sw
+{
+class ThemeColorChanger
+{
+private:
+    SwDocShell* mpDocSh;
+
+public:
+    ThemeColorChanger(SwDocShell* pDocSh)
+        : mpDocSh(pDocSh)
+    {
+    }
+
+    void apply(svx::ColorSet const& rColorSet);
+};
+
+} // end sw namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/inc/UndoAttribute.hxx 
b/sw/source/core/inc/UndoAttribute.hxx
index c3cf4925d95a..e3c40b7f0e87 100644
--- a/sw/source/core/inc/UndoAttribute.hxx
+++ b/sw/source/core/inc/UndoAttribute.hxx
@@ -45,7 +45,7 @@ class SwUndoAttr final : public SwUndo, private SwUndRng
     OUString m_aChrFormatName;
 
     void RemoveIdx( SwDoc& rDoc );
-
+    void redoAttribute(SwPaM& rPam, sw::UndoRedoContext& rContext);
 public:
     SwUndoAttr( const SwPaM&, SfxItemSet, const SetAttrMode nFlags );
     SwUndoAttr( const SwPaM&, const SfxPoolItem&, const SetAttrMode nFlags );
diff --git a/sw/source/core/model/ThemeColorChanger.cxx 
b/sw/source/core/model/ThemeColorChanger.cxx
new file mode 100644
index 000000000000..ff59c474748b
--- /dev/null
+++ b/sw/source/core/model/ThemeColorChanger.cxx
@@ -0,0 +1,271 @@
+/* -*- 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/.
+ *
+ */
+
+#include <ThemeColorChanger.hxx>
+#include <ModelTraverser.hxx>
+#include <txtftn.hxx>
+#include <txtfrm.hxx>
+#include <docstyle.hxx>
+#include <drawdoc.hxx>
+#include <ndnotxt.hxx>
+#include <ndtxt.hxx>
+#include <format.hxx>
+#include <charatr.hxx>
+#include <DocumentContentOperationsManager.hxx>
+#include <IDocumentUndoRedo.hxx>
+
+#include <sal/config.h>
+#include <svx/svdpage.hxx>
+#include <svx/svditer.hxx>
+#include <docmodel/uno/UnoThemeColor.hxx>
+#include <editeng/unoprnms.hxx>
+#include <com/sun/star/text/XTextRange.hpp>
+#include <com/sun/star/container/XEnumerationAccess.hpp>
+#include <com/sun/star/container/XEnumeration.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+
+namespace sw
+{
+namespace
+{
+/** Handler for ModelTraverser that recalculates and updates the theme colors.
+ *
+ * It checks all the SdrObjects and updates fill, line and text theme colors.
+ * For writer nodes it checks all the text nodes and updates the direct
+ * formatting in all hints.
+ *
+ */
+class ThemeColorHandler : public sw::ModelTraverseHandler
+{
+    SwDoc& mrDocument;
+    svx::ColorSet const& mrColorSet;
+
+public:
+    ThemeColorHandler(SwDoc& rDocument, svx::ColorSet const& rColorSet)
+        : mrDocument(rDocument)
+        , mrColorSet(rColorSet)
+    {
+    }
+
+    /// Updates hints for a text node
+    void updateHints(SwTextNode* pTextNode)
+    {
+        if (!pTextNode->HasHints())
+            return;
+
+        SwpHints& rHints = pTextNode->GetSwpHints();
+        for (size_t i = 0; i < rHints.Count(); ++i)
+        {
+            const SwTextAttr* pTextAttr = rHints.Get(i);
+            if (pTextAttr->Which() == RES_TXTATR_AUTOFMT)
+            {
+                SwFormatAutoFormat const& 
rAutoFormatPool(pTextAttr->GetAutoFormat());
+                std::shared_ptr<SfxItemSet> 
pStyleHandle(rAutoFormatPool.GetStyleHandle());
+                if (const SvxColorItem* pItem = 
pStyleHandle->GetItemIfSet(RES_CHRATR_COLOR))
+                {
+                    model::ThemeColor const& rThemeColor = 
pItem->GetThemeColor();
+                    auto eThemeType = rThemeColor.getType();
+                    if (eThemeType != model::ThemeColorType::Unknown)
+                    {
+                        Color aNewColor = mrColorSet.resolveColor(rThemeColor);
+                        auto pNew = pItem->Clone();
+                        pNew->SetValue(aNewColor);
+
+                        SwPaM aPam(*pTextNode, pTextAttr->GetStart(), 
*pTextNode,
+                                   pTextAttr->GetAnyEnd());
+                        
mrDocument.GetDocumentContentOperationsManager().InsertPoolItem(
+                            aPam, *pNew, SetAttrMode::APICALL | 
SetAttrMode::NO_CURSOR_CHANGE);
+                    }
+                }
+            }
+        }
+    }
+
+    void handleNode(SwNode* pNode) override
+    {
+        if (!pNode->IsTextNode())
+            return;
+
+        updateHints(pNode->GetTextNode());
+    }
+
+    /// Updates text portion property colors
+    void updateTextPortionColorSet(const uno::Reference<beans::XPropertySet>& 
xPortion)
+    {
+        if (!xPortion->getPropertySetInfo()->hasPropertyByName(
+                UNO_NAME_EDIT_CHAR_COLOR_THEME_REFERENCE))
+            return;
+
+        uno::Reference<util::XThemeColor> xThemeColor;
+        xPortion->getPropertyValue(UNO_NAME_EDIT_CHAR_COLOR_THEME_REFERENCE) 
>>= xThemeColor;
+        if (!xThemeColor.is())
+            return;
+
+        model::ThemeColor aThemeColor;
+        model::theme::setFromXThemeColor(aThemeColor, xThemeColor);
+
+        if (aThemeColor.getType() == model::ThemeColorType::Unknown)
+            return;
+
+        Color aColor = mrColorSet.resolveColor(aThemeColor);
+        xPortion->setPropertyValue(UNO_NAME_EDIT_CHAR_COLOR,
+                                   uno::Any(static_cast<sal_Int32>(aColor)));
+    }
+
+    /// Updates the fill property colors
+    void updateFillColorSet(const uno::Reference<beans::XPropertySet>& xShape)
+    {
+        if 
(!xShape->getPropertySetInfo()->hasPropertyByName(UNO_NAME_FILLCOLOR_THEME_REFERENCE))
+            return;
+
+        uno::Reference<util::XThemeColor> xThemeColor;
+        xShape->getPropertyValue(UNO_NAME_FILLCOLOR_THEME_REFERENCE) >>= 
xThemeColor;
+        if (!xThemeColor.is())
+            return;
+
+        model::ThemeColor aThemeColor;
+        model::theme::setFromXThemeColor(aThemeColor, xThemeColor);
+
+        if (aThemeColor.getType() == model::ThemeColorType::Unknown)
+            return;
+
+        Color aColor = mrColorSet.resolveColor(aThemeColor);
+        xShape->setPropertyValue(UNO_NAME_FILLCOLOR, 
uno::Any(static_cast<sal_Int32>(aColor)));
+    }
+
+    /// Updates the line property colors
+    void updateLineColorSet(const uno::Reference<beans::XPropertySet>& xShape)
+    {
+        if 
(!xShape->getPropertySetInfo()->hasPropertyByName(UNO_NAME_LINECOLOR_THEME_REFERENCE))
+            return;
+
+        uno::Reference<util::XThemeColor> xThemeColor;
+        xShape->getPropertyValue(UNO_NAME_LINECOLOR_THEME_REFERENCE) >>= 
xThemeColor;
+        if (!xThemeColor.is())
+            return;
+
+        model::ThemeColor aThemeColor;
+        model::theme::setFromXThemeColor(aThemeColor, xThemeColor);
+
+        if (aThemeColor.getType() == model::ThemeColorType::Unknown)
+            return;
+
+        Color aColor = mrColorSet.resolveColor(aThemeColor);
+        xShape->setPropertyValue(UNO_NAME_LINECOLOR, 
uno::Any(static_cast<sal_Int32>(aColor)));
+    }
+
+    /// Updates properties of the SdrObject
+    void updateSdrObject(SdrObject* pObject)
+    {
+        uno::Reference<drawing::XShape> xShape = pObject->getUnoShape();
+        uno::Reference<text::XTextRange> xShapeText(xShape, uno::UNO_QUERY);
+        if (xShapeText.is())
+        {
+            // 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())
+            {
+                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(xPortion);
+                }
+            }
+        }
+
+        uno::Reference<beans::XPropertySet> xShapeProps(xShape, 
uno::UNO_QUERY);
+        updateFillColorSet(xShapeProps);
+        updateLineColorSet(xShapeProps);
+    }
+
+    void handleSdrObject(SdrObject* pObject) override
+    {
+        // update current object
+        updateSdrObject(pObject);
+
+        // update child objects
+        SdrObjList* pList = pObject->GetSubList();
+        if (pList)
+        {
+            SdrObjListIter aIter(pList, SdrIterMode::DeepWithGroups);
+            while (aIter.IsMore())
+            {
+                updateSdrObject(aIter.Next());
+            }
+        }
+    }
+};
+
+void changeColor(SwFormat* pFormat, svx::ColorSet const& rColorSet, SwDoc* 
pDocument)
+{
+    const SwAttrSet& rAttrSet = pFormat->GetAttrSet();
+    std::unique_ptr<SfxItemSet> pNewSet = rAttrSet.Clone();
+
+    SvxColorItem aColorItem(rAttrSet.GetColor());
+    model::ThemeColor const& rThemeColor = aColorItem.GetThemeColor();
+    auto eThemeType = rThemeColor.getType();
+    if (eThemeType != model::ThemeColorType::Unknown)
+    {
+        Color aColor = rColorSet.getColor(eThemeType);
+        aColor = rThemeColor.applyTransformations(aColor);
+        aColorItem.SetValue(aColor);
+        pNewSet->Put(aColorItem);
+        pDocument->ChgFormat(*pFormat, *pNewSet);
+    }
+}
+
+} // end anonymous namespace
+
+void ThemeColorChanger::apply(svx::ColorSet const& rColorSet)
+{
+    SwDoc* pDocument = mpDocSh->GetDoc();
+    pDocument->GetIDocumentUndoRedo().StartUndo(SwUndoId::EMPTY, nullptr);
+
+    SfxStyleSheetBasePool* pPool = mpDocSh->GetStyleSheetPool();
+    SwDocStyleSheet* pStyle;
+
+    // Paragraph style color change
+    pStyle = static_cast<SwDocStyleSheet*>(pPool->First(SfxStyleFamily::Para));
+    while (pStyle)
+    {
+        SwTextFormatColl* pTextFormatCollection = pStyle->GetCollection();
+        if (pTextFormatCollection)
+            changeColor(pTextFormatCollection, rColorSet, pDocument);
+        pStyle = static_cast<SwDocStyleSheet*>(pPool->Next());
+    }
+
+    // Character style color change
+    pStyle = static_cast<SwDocStyleSheet*>(pPool->First(SfxStyleFamily::Char));
+    while (pStyle)
+    {
+        SwCharFormat* pCharFormat = pStyle->GetCharFormat();
+        if (pCharFormat)
+            changeColor(pCharFormat, rColorSet, pDocument);
+        pStyle = static_cast<SwDocStyleSheet*>(pPool->Next());
+    }
+
+    // Direct format change
+    auto pHandler = std::make_shared<ThemeColorHandler>(*pDocument, rColorSet);
+    sw::ModelTraverser aModelTraverser(pDocument);
+    aModelTraverser.addNodeHandler(pHandler);
+    aModelTraverser.traverse();
+
+    pDocument->GetIDocumentUndoRedo().EndUndo(SwUndoId::EMPTY, nullptr);
+}
+
+} // end sw namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/undo/unattr.cxx b/sw/source/core/undo/unattr.cxx
index d8dc236c92e2..60df048d22b3 100644
--- a/sw/source/core/undo/unattr.cxx
+++ b/sw/source/core/undo/unattr.cxx
@@ -770,7 +770,8 @@ void SwUndoAttr::UndoImpl(::sw::UndoRedoContext & rContext)
     m_pHistory->SetTmpEnd( m_pHistory->Count() );
 
     // set cursor onto Undo area
-    AddUndoRedoPaM(rContext);
+    if (!(m_nInsertFlags & SetAttrMode::NO_CURSOR_CHANGE))
+        AddUndoRedoPaM(rContext);
 }
 
 void SwUndoAttr::RepeatImpl(::sw::RepeatContext & rContext)
@@ -787,10 +788,9 @@ void SwUndoAttr::RepeatImpl(::sw::RepeatContext & rContext)
     }
 }
 
-void SwUndoAttr::RedoImpl(::sw::UndoRedoContext & rContext)
+void SwUndoAttr::redoAttribute(SwPaM& rPam, sw::UndoRedoContext & rContext)
 {
     SwDoc & rDoc = rContext.GetDoc();
-    SwPaM & rPam = AddUndoRedoPaM(rContext);
 
     // Restore pointer to char format from name
     if (!m_aChrFormatName.isEmpty())
@@ -826,6 +826,21 @@ void SwUndoAttr::RedoImpl(::sw::UndoRedoContext & rContext)
     }
 }
 
+void SwUndoAttr::RedoImpl(sw::UndoRedoContext & rContext)
+{
+    if (m_nInsertFlags & SetAttrMode::NO_CURSOR_CHANGE)
+    {
+        SwPaM aPam(rContext.GetDoc().GetNodes().GetEndOfContent());
+        SetPaM(aPam, false);
+        redoAttribute(aPam, rContext);
+    }
+    else
+    {
+        SwPaM& rPam = AddUndoRedoPaM(rContext);
+        redoAttribute(rPam, rContext);
+    }
+}
+
 void SwUndoAttr::RemoveIdx( SwDoc& rDoc )
 {
     if ( SfxItemState::SET != m_AttrSet.GetItemState( RES_TXTATR_FTN, false ))
diff --git a/sw/source/uibase/sidebar/ThemePanel.cxx 
b/sw/source/uibase/sidebar/ThemePanel.cxx
index 5c1f9238dc43..76fd5e59870b 100644
--- a/sw/source/uibase/sidebar/ThemePanel.cxx
+++ b/sw/source/uibase/sidebar/ThemePanel.cxx
@@ -13,55 +13,16 @@
 
 #include <doc.hxx>
 #include <docsh.hxx>
-#include <docstyle.hxx>
 #include <drawdoc.hxx>
-#include <ndnotxt.hxx>
-#include <ndtxt.hxx>
-#include <fmtcol.hxx>
-#include <format.hxx>
-#include <charatr.hxx>
 #include <IDocumentDrawModelAccess.hxx>
+#include <ThemeColorChanger.hxx>
 #include <vcl/settings.hxx>
 #include <vcl/svapp.hxx>
 #include <svx/svdpage.hxx>
 #include <svx/ColorSets.hxx>
 #include <svx/dialog/ThemeColorValueSet.hxx>
-#include <sfx2/objsh.hxx>
-#include <editeng/colritem.hxx>
 #include <com/sun/star/lang/IllegalArgumentException.hpp>
 
-namespace
-{
-
-void changeColor(SwTextFormatColl* pCollection, svx::ColorSet const& rColorSet)
-{
-    SvxColorItem aColorItem(pCollection->GetColor());
-    model::ThemeColor const& rThemeColor = aColorItem.GetThemeColor();
-    auto eThemeType = rThemeColor.getType();
-    if (eThemeType != model::ThemeColorType::Unknown)
-    {
-        Color aColor = rColorSet.getColor(eThemeType);
-        aColor = rThemeColor.applyTransformations(aColor);
-        aColorItem.SetValue(aColor);
-        pCollection->SetFormatAttr(aColorItem);
-    }
-}
-
-void applyTheme(SfxStyleSheetBasePool* pPool, svx::ColorSet const& rColorSet)
-{
-    SwDocStyleSheet* pStyle;
-
-    pStyle = static_cast<SwDocStyleSheet*>(pPool->First(SfxStyleFamily::Para));
-    while (pStyle)
-    {
-        SwTextFormatColl* pCollection = pStyle->GetCollection();
-        changeColor(pCollection, rColorSet);
-        pStyle = static_cast<SwDocStyleSheet*>(pPool->Next());
-    }
-}
-
-} // end anonymous namespace
-
 namespace sw::sidebar
 {
 
@@ -147,7 +108,8 @@ void ThemePanel::DoubleClickHdl()
 
     svx::ColorSet const& rColorSet = maColorSets.getColorSet(nIndex);
 
-    applyTheme(pDocSh->GetStyleSheetPool(), rColorSet);
+    ThemeColorChanger aChanger(pDocSh);
+    aChanger.apply(rColorSet);
 }
 
 void ThemePanel::NotifyItemUpdate(const sal_uInt16 /*nSId*/,
commit 8bc22ed6899bcbafc3020f0af6c939019506a5fd
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Thu Jan 5 23:58:50 2023 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Sat Jan 14 07:52:37 2023 +0000

    sw: rework ThemePanel, theme color ValueSet drawing as custom draw
    
    Rework the ThemePanel to only work with theme colors, as fonts
    are uing an old mock implemntation of themes. To do this properly
    it is needed to remove the implementation for now.
    
    The theme colors entries were rendered as a bitmap and then shown
    in the ValueSet. This has the problem that it doesn't look sharp
    on a HiDPI screen, so replace that with a ThemeColorValueSet, which
    uses custom draw to render the theme color entries directly.
    
    The ThemeColorValueSet was added to th svx component as it will be
    used in other components as well.
    
    Change-Id: I1a727ef4cf4be4e215db57ac33f571f43aaddc15
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145087
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/include/svx/dialog/ThemeColorValueSet.hxx 
b/include/svx/dialog/ThemeColorValueSet.hxx
new file mode 100644
index 000000000000..4b70ed0f56db
--- /dev/null
+++ b/include/svx/dialog/ThemeColorValueSet.hxx
@@ -0,0 +1,38 @@
+/* -*- 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 <svx/svxdllapi.h>
+#include <sal/config.h>
+#include <svtools/valueset.hxx>
+#include <svx/ColorSets.hxx>
+
+namespace svx
+{
+class SVX_DLLPUBLIC ThemeColorValueSet final : public ValueSet
+{
+    std::vector<std::reference_wrapper<const svx::ColorSet>> maColorSets;
+
+public:
+    ThemeColorValueSet()
+        : ValueSet(nullptr)
+    {
+    }
+
+    void SetDrawingArea(weld::DrawingArea* pDrawingArea) override;
+    void UserDraw(const UserDrawEvent& rUserDrawEvent) override;
+    void StyleUpdated() override;
+
+    void insert(svx::ColorSet const& rColorSet);
+};
+
+} // end svx namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/Library_svx.mk b/svx/Library_svx.mk
index 29f8d16454c7..9021b46d7f1b 100644
--- a/svx/Library_svx.mk
+++ b/svx/Library_svx.mk
@@ -174,6 +174,7 @@ $(eval $(call gb_Library_add_exception_objects,svx,\
     svx/source/dialog/svxruler \
     svx/source/dialog/swframeexample \
     svx/source/dialog/swframeposstrings \
+    svx/source/dialog/ThemeColorValueSet \
     svx/source/dialog/txencbox \
     svx/source/dialog/txenctab \
     svx/source/dialog/weldeditview \
diff --git a/svx/source/dialog/ThemeColorValueSet.cxx 
b/svx/source/dialog/ThemeColorValueSet.cxx
new file mode 100644
index 000000000000..204a37ba72de
--- /dev/null
+++ b/svx/source/dialog/ThemeColorValueSet.cxx
@@ -0,0 +1,98 @@
+/* -*- 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/.
+ */
+
+#include <svx/dialog/ThemeColorValueSet.hxx>
+#include <docmodel/uno/UnoThemeColor.hxx>
+#include <vcl/event.hxx>
+
+namespace svx
+{
+constexpr tools::Long BORDER = 3;
+constexpr tools::Long SIZE = 14;
+constexpr tools::Long LABEL_HEIGHT = 16;
+constexpr tools::Long LABEL_TEXT_HEIGHT = 14;
+constexpr tools::Long constElementNumber = 8;
+
+void ThemeColorValueSet::insert(svx::ColorSet const& rColorSet)
+{
+    maColorSets.push_back(std::cref(rColorSet));
+    InsertItem(maColorSets.size());
+}
+
+void ThemeColorValueSet::SetDrawingArea(weld::DrawingArea* pDrawingArea)
+{
+    ValueSet::SetDrawingArea(pDrawingArea);
+    SetStyle(WB_TABSTOP | WB_ITEMBORDER | WB_DOUBLEBORDER);
+    Size aSize(BORDER * 7 + SIZE * 6 + BORDER * 2, BORDER * 3 + SIZE * 2 + 
LABEL_HEIGHT);
+    SetItemWidth(aSize.Width());
+    SetItemHeight(aSize.Height());
+}
+
+void ThemeColorValueSet::UserDraw(const UserDrawEvent& rUserDrawEvent)
+{
+    vcl::RenderContext* pDev = rUserDrawEvent.GetRenderContext();
+    tools::Rectangle aRect = rUserDrawEvent.GetRect();
+    const Point aPosition = aRect.GetPos();
+    const sal_uInt16 nItemId = rUserDrawEvent.GetItemId();
+    svx::ColorSet const& rColorSet = maColorSets[nItemId - 1];
+
+    Size aSize = aRect.GetSize();
+    Size aMin(BORDER * 7 + SIZE * constElementNumber / 2 + BORDER * 2,
+              BORDER * 3 + SIZE * 2 + LABEL_HEIGHT);
+    tools::Long startX = (aSize.Width() / 2.0) - (aMin.Width() / 2.0);
+    tools::Long x = BORDER;
+    tools::Long y1 = BORDER + LABEL_HEIGHT;
+    tools::Long y2 = y1 + SIZE + BORDER;
+
+    pDev->SetLineColor(COL_LIGHTGRAY);
+    pDev->SetFillColor(COL_LIGHTGRAY);
+    tools::Rectangle aNameRect(aPosition, Size(aSize.Width(), LABEL_HEIGHT));
+    pDev->DrawRect(aNameRect);
+
+    vcl::Font aFont;
+    OUString aName = rColorSet.getName();
+    aFont.SetFontHeight(LABEL_TEXT_HEIGHT);
+    pDev->SetFont(aFont);
+
+    Size aTextSize(pDev->GetTextWidth(aName), pDev->GetTextHeight());
+
+    Point aPoint(aPosition.X() + (aNameRect.GetWidth() / 2.0) - 
(aTextSize.Width() / 2.0),
+                 aPosition.Y() + (aNameRect.GetHeight() / 2.0) - 
(aTextSize.Height() / 2.0));
+
+    pDev->DrawText(aPoint, aName);
+
+    pDev->SetLineColor(COL_LIGHTGRAY);
+    pDev->SetFillColor();
+
+    for (sal_uInt32 i = 2; i < 10; i += 2)
+    {
+        
pDev->SetFillColor(rColorSet.getColor(model::convertToThemeColorType(i)));
+        pDev->DrawRect(tools::Rectangle(Point(aPosition.X() + x + startX, 
aPosition.Y() + y1),
+                                        Size(SIZE, SIZE)));
+
+        pDev->SetFillColor(rColorSet.getColor(model::convertToThemeColorType(i 
+ 1)));
+        pDev->DrawRect(tools::Rectangle(Point(aPosition.X() + x + startX, 
aPosition.Y() + y2),
+                                        Size(SIZE, SIZE)));
+
+        x += SIZE + BORDER;
+        if (i == 2 || i == 8)
+            x += BORDER;
+    }
+}
+
+void ThemeColorValueSet::StyleUpdated()
+{
+    SetFormat();
+    Invalidate();
+    ValueSet::StyleUpdated();
+}
+
+} // end svx namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/sidebar/ThemePanel.cxx 
b/sw/source/uibase/sidebar/ThemePanel.cxx
index 83a09d092dbf..5c1f9238dc43 100644
--- a/sw/source/uibase/sidebar/ThemePanel.cxx
+++ b/sw/source/uibase/sidebar/ThemePanel.cxx
@@ -8,219 +8,32 @@
  *
  */
 
-#include <sal/config.h>
-
 #include "ThemePanel.hxx"
+#include <sal/config.h>
 
-#include <sfx2/objsh.hxx>
-
-#include <com/sun/star/lang/IllegalArgumentException.hpp>
-
-#include <editeng/fontitem.hxx>
-#include <utility>
-#include <vcl/bitmapex.hxx>
-#include <vcl/image.hxx>
-#include <vcl/settings.hxx>
-#include <vcl/svapp.hxx>
-#include <vcl/virdev.hxx>
-#include <charatr.hxx>
-#include <charfmt.hxx>
+#include <doc.hxx>
 #include <docsh.hxx>
 #include <docstyle.hxx>
+#include <drawdoc.hxx>
+#include <ndnotxt.hxx>
+#include <ndtxt.hxx>
 #include <fmtcol.hxx>
 #include <format.hxx>
-#include <svx/ColorSets.hxx>
-#include <doc.hxx>
+#include <charatr.hxx>
 #include <IDocumentDrawModelAccess.hxx>
+#include <vcl/settings.hxx>
+#include <vcl/svapp.hxx>
 #include <svx/svdpage.hxx>
-#include <drawdoc.hxx>
-
+#include <svx/ColorSets.hxx>
+#include <svx/dialog/ThemeColorValueSet.hxx>
+#include <sfx2/objsh.hxx>
+#include <editeng/colritem.hxx>
+#include <com/sun/star/lang/IllegalArgumentException.hpp>
 
 namespace
 {
 
-class FontSet
-{
-public:
-    OUString maName;
-    OUString msMonoFont;
-    OUString msHeadingFont;
-    OUString msBaseFont;
-};
-
-class ColorVariable
-{
-public:
-    tools::Long mnIndex;
-    sal_Int16 mnTintShade;
-
-    ColorVariable()
-        : mnIndex(-1)
-        , mnTintShade()
-    {}
-
-    ColorVariable(tools::Long nIndex, sal_Int16 nTintShade)
-        : mnIndex(nIndex)
-        , mnTintShade(nTintShade)
-    {}
-};
-
-class StyleRedefinition
-{
-    ColorVariable maVariable;
-
-public:
-    OUString maElementName;
-
-public:
-    explicit StyleRedefinition(OUString aElementName)
-        : maElementName(std::move(aElementName))
-    {}
-
-    void setColorVariable(ColorVariable aVariable)
-    {
-        maVariable = aVariable;
-    }
-};
-
-class StyleSet
-{
-    std::vector<StyleRedefinition> maStyles;
-
-public:
-    explicit StyleSet()
-    {}
-
-    void add(StyleRedefinition const & aRedefinition)
-    {
-        maStyles.push_back(aRedefinition);
-    }
-
-    StyleRedefinition* get(std::u16string_view aString)
-    {
-        for (StyleRedefinition & rStyle : maStyles)
-        {
-            if (rStyle.maElementName == aString)
-            {
-                return &rStyle;
-            }
-        }
-        return nullptr;
-    }
-};
-
-StyleSet setupThemes()
-{
-    StyleSet aSet;
-
-    {
-        StyleRedefinition aRedefinition("Heading 1");
-        aRedefinition.setColorVariable(ColorVariable(10, -1000));
-        aSet.add(aRedefinition);
-    }
-
-    {
-        StyleRedefinition aRedefinition("Heading 2");
-        aRedefinition.setColorVariable(ColorVariable(7, -500));
-        aSet.add(aRedefinition);
-    }
-
-    {
-        StyleRedefinition aRedefinition("Heading 3");
-        aRedefinition.setColorVariable(ColorVariable(5, 0));
-        aSet.add(aRedefinition);
-    }
-
-    {
-        StyleRedefinition aRedefinition("Heading 4");
-        aRedefinition.setColorVariable(ColorVariable(6, -1000));
-        aSet.add(aRedefinition);
-    }
-
-    {
-        StyleRedefinition aRedefinition("Heading 5");
-        aRedefinition.setColorVariable(ColorVariable(4, -1500));
-        aSet.add(aRedefinition);
-    }
-
-    {
-        StyleRedefinition aRedefinition("Heading 6");
-        aRedefinition.setColorVariable(ColorVariable(3, -2500));
-        aSet.add(aRedefinition);
-    }
-
-    {
-        StyleRedefinition aRedefinition("Heading 7");
-        aRedefinition.setColorVariable(ColorVariable(3, -2500));
-        aSet.add(aRedefinition);
-    }
-
-    {
-        StyleRedefinition aRedefinition("Heading 8");
-        aRedefinition.setColorVariable(ColorVariable(2, 0));
-        aSet.add(aRedefinition);
-    }
-
-    {
-        StyleRedefinition aRedefinition("Heading 9");
-        aRedefinition.setColorVariable(ColorVariable(2, 0));
-        aSet.add(aRedefinition);
-    }
-
-    {
-        StyleRedefinition aRedefinition("Heading 10");
-        aRedefinition.setColorVariable(ColorVariable(0, 0));
-        aSet.add(aRedefinition);
-    }
-
-    return aSet;
-}
-
-void changeFont(SwFormat* pFormat, SwDocStyleSheet const * pStyle, FontSet 
const & rFontSet)
-{
-    if (pStyle->GetName() != "Default Style" && 
pFormat->GetAttrSet().GetItem(RES_CHRATR_FONT, false) == nullptr)
-    {
-        return;
-    }
-
-    SvxFontItem aFontItem(pFormat->GetFont(false));
-
-    FontPitch ePitch = aFontItem.GetPitch();
-
-    if (ePitch == PITCH_FIXED)
-    {
-        aFontItem.SetFamilyName(rFontSet.msMonoFont);
-    }
-    else
-    {
-        if (pStyle->GetName() == "Heading")
-        {
-            aFontItem.SetFamilyName(rFontSet.msHeadingFont);
-        }
-        else
-        {
-            aFontItem.SetFamilyName(rFontSet.msBaseFont);
-        }
-    }
-
-    pFormat->SetFormatAttr(aFontItem);
-}
-
-/*void changeBorder(SwTextFormatColl* pCollection, SwDocStyleSheet* pStyle, 
StyleSet& rStyleSet)
-{
-    if (pStyle->GetName() == "Heading")
-    {
-        SvxBoxItem aBoxItem(pCollection->GetBox());
-        editeng::SvxBorderLine aBorderLine;
-        aBorderLine.SetWidth(40); //20 = 1pt
-        aBorderLine.SetColor(rColorSet.mBaseColors[0]);
-        aBoxItem.SetLine(&aBorderLine, SvxBoxItemLine::BOTTOM);
-
-        pCollection->SetFormatAttr(aBoxItem);
-    }
-}*/
-
-void changeColor(SwTextFormatColl* pCollection, svx::ColorSet const& 
rColorSet, StyleRedefinition* /*pRedefinition*/)
+void changeColor(SwTextFormatColl* pCollection, svx::ColorSet const& rColorSet)
 {
     SvxColorItem aColorItem(pCollection->GetColor());
     model::ThemeColor const& rThemeColor = aColorItem.GetThemeColor();
@@ -234,189 +47,23 @@ void changeColor(SwTextFormatColl* pCollection, 
svx::ColorSet const& rColorSet,
     }
 }
 
-std::vector<FontSet> initFontSets()
-{
-    std::vector<FontSet> aFontSets;
-    {
-        FontSet aFontSet;
-        aFontSet.maName = "Liberation Family";
-        aFontSet.msHeadingFont = "Liberation Sans";
-        aFontSet.msBaseFont = "Liberation Serif";
-        aFontSet.msMonoFont = "Liberation Mono";
-        aFontSets.push_back(aFontSet);
-    }
-    {
-        FontSet aFontSet;
-        aFontSet.maName = "DejaVu Family";
-        aFontSet.msHeadingFont = "DejaVu Sans";
-        aFontSet.msBaseFont = "DejaVu Serif";
-        aFontSet.msMonoFont = "DejaVu Sans Mono";
-        aFontSets.push_back(aFontSet);
-    }
-    {
-        FontSet aFontSet;
-        aFontSet.maName = "Croscore Modern";
-        aFontSet.msHeadingFont = "Caladea";
-        aFontSet.msBaseFont = "Carlito";
-        aFontSet.msMonoFont = "Liberation Mono";
-        aFontSets.push_back(aFontSet);
-    }
-    {
-        FontSet aFontSet;
-        aFontSet.maName = "Carlito";
-        aFontSet.msHeadingFont = "Carlito";
-        aFontSet.msBaseFont = "Carlito";
-        aFontSet.msMonoFont = "Liberation Mono";
-        aFontSets.push_back(aFontSet);
-    }
-    {
-        FontSet aFontSet;
-        aFontSet.maName = "Source Sans Family";
-        aFontSet.msHeadingFont = "Source Sans Pro";
-        aFontSet.msBaseFont = "Source Sans Pro";
-        aFontSet.msMonoFont = "Source Code Pro";
-        aFontSets.push_back(aFontSet);
-    }
-    {
-        FontSet aFontSet;
-        aFontSet.maName = "Source Sans Family 2";
-        aFontSet.msHeadingFont = "Source Sans Pro";
-        aFontSet.msBaseFont = "Source Sans Pro Light";
-        aFontSet.msMonoFont = "Source Code Pro";
-        aFontSets.push_back(aFontSet);
-    }
-    {
-        FontSet aFontSet;
-        aFontSet.maName = "Libertine Family";
-        aFontSet.msHeadingFont = "Linux Biolinum G";
-        aFontSet.msBaseFont = "Linux Libertine G";
-        aFontSet.msMonoFont = "Liberation Mono";
-        aFontSets.push_back(aFontSet);
-    }
-    {
-        FontSet aFontSet;
-        aFontSet.maName = "Noto Sans";
-        aFontSet.msHeadingFont = "Noto Sans";
-        aFontSet.msBaseFont = "Noto Sans";
-        aFontSet.msMonoFont = "Noto Mono";
-        aFontSets.push_back(aFontSet);
-    }
-    {
-        FontSet aFontSet;
-        aFontSet.maName = "Droid Sans";
-        aFontSet.msHeadingFont = "Droid Sans";
-        aFontSet.msBaseFont = "Droid Sans";
-        aFontSet.msMonoFont = "Droid Sans Mono";
-        aFontSets.push_back(aFontSet);
-    }
-    return aFontSets;
-}
-
-FontSet getFontSet(std::u16string_view rFontVariant, std::vector<FontSet>& 
aFontSets)
-{
-    for (const FontSet & rFontSet : aFontSets)
-    {
-        if (rFontSet.maName == rFontVariant)
-            return rFontSet;
-    }
-    return aFontSets[0];
-}
-
-void applyTheme(SfxStyleSheetBasePool* pPool, std::u16string_view 
sFontSetName, std::u16string_view sColorSetName,
-                StyleSet& rStyleSet, svx::ColorSets& rColorSets)
+void applyTheme(SfxStyleSheetBasePool* pPool, svx::ColorSet const& rColorSet)
 {
     SwDocStyleSheet* pStyle;
 
-    std::vector<FontSet> aFontSets = initFontSets();
-    FontSet aFontSet = getFontSet(sFontSetName, aFontSets);
-
-    svx::ColorSet aColorSet = rColorSets.getColorSet(sColorSetName);
-
     pStyle = static_cast<SwDocStyleSheet*>(pPool->First(SfxStyleFamily::Para));
     while (pStyle)
     {
         SwTextFormatColl* pCollection = pStyle->GetCollection();
-
-        changeFont(pCollection, pStyle, aFontSet);
-
-        StyleRedefinition* pRedefinition = rStyleSet.get(pStyle->GetName());
-
-        if (pRedefinition)
-        {
-            changeColor(pCollection, aColorSet, pRedefinition);
-        }
-
-        pStyle = static_cast<SwDocStyleSheet*>(pPool->Next());
-    }
-
-    pStyle = static_cast<SwDocStyleSheet*>(pPool->First(SfxStyleFamily::Char));
-    while (pStyle)
-    {
-        SwCharFormat* pCharFormat = pStyle->GetCharFormat();
-
-        changeFont(static_cast<SwFormat*>(pCharFormat), pStyle, aFontSet);
-
+        changeColor(pCollection, rColorSet);
         pStyle = static_cast<SwDocStyleSheet*>(pPool->Next());
     }
 }
 
-BitmapEx GenerateColorPreview(const svx::ColorSet& rColorSet)
-{
-    ScopedVclPtrInstance<VirtualDevice> 
pVirtualDev(*Application::GetDefaultDevice());
-    float fScaleFactor = pVirtualDev->GetDPIScaleFactor();
-    tools::Long BORDER = 3 * fScaleFactor;
-    tools::Long SIZE = 14 * fScaleFactor;
-    tools::Long LABEL_HEIGHT = 16 * fScaleFactor;
-    tools::Long LABEL_TEXT_HEIGHT = 14 * fScaleFactor;
-
-    Size aSize(BORDER * 7 + SIZE * 6 + BORDER * 2, BORDER * 3 + SIZE * 2 + 
LABEL_HEIGHT);
-    pVirtualDev->SetOutputSizePixel(aSize);
-    
pVirtualDev->SetBackground(Wallpaper(Application::GetSettings().GetStyleSettings().GetFaceColor()));
-    pVirtualDev->Erase();
-
-    tools::Long x = BORDER;
-    tools::Long y1 = BORDER + LABEL_HEIGHT;
-    tools::Long y2 = y1 + SIZE + BORDER;
-
-    pVirtualDev->SetLineColor(COL_LIGHTGRAY);
-    pVirtualDev->SetFillColor(COL_LIGHTGRAY);
-    tools::Rectangle aNameRect(Point(0, 0), Size(aSize.Width(), LABEL_HEIGHT));
-    pVirtualDev->DrawRect(aNameRect);
-
-    vcl::Font aFont;
-    OUString aName = rColorSet.getName();
-    aFont.SetFontHeight(LABEL_TEXT_HEIGHT);
-    pVirtualDev->SetFont(aFont);
-
-    Size aTextSize(pVirtualDev->GetTextWidth(aName), 
pVirtualDev->GetTextHeight());
-
-    Point aPoint((aNameRect.GetWidth()  / 2.0) - (aTextSize.Width()  / 2.0),
-                 (aNameRect.GetHeight() / 2.0) - (aTextSize.Height() / 2.0));
-
-    pVirtualDev->DrawText(aPoint, aName);
-
-    pVirtualDev->SetLineColor(COL_LIGHTGRAY);
-    pVirtualDev->SetFillColor();
-
-    for (sal_uInt32 i = 0; i < 12; i += 2)
-    {
-        
pVirtualDev->SetFillColor(rColorSet.getColor(model::convertToThemeColorType(i)));
-        pVirtualDev->DrawRect(tools::Rectangle(x, y1, x + SIZE, y1 + SIZE));
-
-        
pVirtualDev->SetFillColor(rColorSet.getColor(model::convertToThemeColorType(i + 
1)));
-        pVirtualDev->DrawRect(tools::Rectangle(x, y2, x + SIZE, y2 + SIZE));
-
-        x += SIZE + BORDER;
-        if (i == 2 || i == 8)
-            x += BORDER;
-    }
-
-    return pVirtualDev->GetBitmapEx(Point(), aSize);
-}
-
 } // end anonymous namespace
 
-namespace sw::sidebar {
+namespace sw::sidebar
+{
 
 std::unique_ptr<PanelLayout> ThemePanel::Create(weld::Widget* pParent)
 {
@@ -428,8 +75,7 @@ std::unique_ptr<PanelLayout> 
ThemePanel::Create(weld::Widget* pParent)
 
 ThemePanel::ThemePanel(weld::Widget* pParent)
     : PanelLayout(pParent, "ThemePanel", "modules/swriter/ui/sidebartheme.ui")
-    , mxListBoxFonts(m_xBuilder->weld_tree_view("listbox_fonts"))
-    , mxValueSetColors(new ValueSet(nullptr))
+    , mxValueSetColors(new svx::ThemeColorValueSet)
     , mxValueSetColorsWin(new weld::CustomWeld(*m_xBuilder, "valueset_colors", 
*mxValueSetColors))
     , mxApplyButton(m_xBuilder->weld_button("apply"))
 {
@@ -438,14 +84,8 @@ ThemePanel::ThemePanel(weld::Widget* pParent)
     
mxValueSetColors->SetColor(Application::GetSettings().GetStyleSettings().GetFaceColor());
 
     mxApplyButton->connect_clicked(LINK(this, ThemePanel, ClickHdl));
-    mxListBoxFonts->connect_row_activated(LINK(this, ThemePanel, 
DoubleClickHdl));
     mxValueSetColors->SetDoubleClickHdl(LINK(this, ThemePanel, 
DoubleClickValueSetHdl));
 
-    std::vector<FontSet> aFontSets = initFontSets();
-    for (const FontSet & rFontSet : aFontSets)
-        mxListBoxFonts->append_text(rFontSet.maName);
-    mxListBoxFonts->set_size_request(-1, 
mxListBoxFonts->get_height_rows(aFontSets.size()));
-
     maColorSets.init();
 
     SwDocShell* pDocSh = static_cast<SwDocShell*>(SfxObjectShell::Current());
@@ -462,12 +102,7 @@ ThemePanel::ThemePanel(weld::Widget* pParent)
     for (size_t i = 0; i < aColorSets.size(); ++i)
     {
         const svx::ColorSet& rColorSet = aColorSets[i];
-
-        const OUString& aName = rColorSet.getName();
-        BitmapEx aPreview = GenerateColorPreview(rColorSet);
-
-        sal_uInt16 nId = i + 1;
-        mxValueSetColors->InsertItem(nId, Image(aPreview), aName);
+        mxValueSetColors->insert(rColorSet);
     }
 
     mxValueSetColors->SetOptimalSize();
@@ -478,7 +113,6 @@ ThemePanel::ThemePanel(weld::Widget* pParent)
 
 ThemePanel::~ThemePanel()
 {
-    mxListBoxFonts.reset();
     mxValueSetColorsWin.reset();
     mxValueSetColors.reset();
     mxApplyButton.reset();
@@ -509,13 +143,11 @@ void ThemePanel::DoubleClickHdl()
     sal_uInt32 nItemId = mxValueSetColors->GetSelectedItemId();
     if (!nItemId)
         return;
-    OUString sEntryFonts = mxListBoxFonts->get_selected_text();
     sal_uInt32 nIndex = nItemId - 1;
-    OUString sEntryColors = maColorSets.getColorSet(nIndex).getName();
 
-    StyleSet aStyleSet = setupThemes();
+    svx::ColorSet const& rColorSet = maColorSets.getColorSet(nIndex);
 
-    applyTheme(pDocSh->GetStyleSheetPool(), sEntryFonts, sEntryColors, 
aStyleSet, maColorSets);
+    applyTheme(pDocSh->GetStyleSheetPool(), rColorSet);
 }
 
 void ThemePanel::NotifyItemUpdate(const sal_uInt16 /*nSId*/,
diff --git a/sw/source/uibase/sidebar/ThemePanel.hxx 
b/sw/source/uibase/sidebar/ThemePanel.hxx
index 14af479e664a..848d022ee0c6 100644
--- a/sw/source/uibase/sidebar/ThemePanel.hxx
+++ b/sw/source/uibase/sidebar/ThemePanel.hxx
@@ -15,7 +15,10 @@
 #include <svtools/valueset.hxx>
 #include <svx/ColorSets.hxx>
 
-namespace sw::sidebar {
+namespace svx { class ThemeColorValueSet; }
+
+namespace sw::sidebar
+{
 
 class ThemePanel : public PanelLayout,
                        public 
sfx2::sidebar::ControllerItem::ItemUpdateReceiverInterface
@@ -36,7 +39,7 @@ public:
 
 private:
     std::unique_ptr<weld::TreeView> mxListBoxFonts;
-    std::unique_ptr<ValueSet> mxValueSetColors;
+    std::unique_ptr<svx::ThemeColorValueSet> mxValueSetColors;
     std::unique_ptr<weld::CustomWeld> mxValueSetColorsWin;
     std::unique_ptr<weld::Button> mxApplyButton;
 
diff --git a/sw/uiconfig/swriter/ui/sidebartheme.ui 
b/sw/uiconfig/swriter/ui/sidebartheme.ui
index fd436e149e43..4af29d4d7b64 100644
--- a/sw/uiconfig/swriter/ui/sidebartheme.ui
+++ b/sw/uiconfig/swriter/ui/sidebartheme.ui
@@ -1,144 +1,68 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.22.1 -->
+<!-- Generated with glade 3.40.0 -->
 <interface domain="sw">
   <requires lib="gtk+" version="3.20"/>
-  <object class="GtkTreeStore" id="liststore1">
-    <columns>
-      <!-- column-name text -->
-      <column type="gchararray"/>
-      <!-- column-name id -->
-      <column type="gchararray"/>
-    </columns>
-  </object>
-  <!-- n-columns=1 n-rows=1 -->
+  <!-- n-columns=1 n-rows=3 -->
   <object class="GtkGrid" id="ThemePanel">
     <property name="visible">True</property>
-    <property name="can_focus">False</property>
-    <property name="row_spacing">6</property>
-    <property name="column_spacing">6</property>
+    <property name="can-focus">True</property>
+    <property name="row-spacing">6</property>
+    <property name="column-spacing">6</property>
     <child>
-      <!-- n-columns=1 n-rows=1 -->
-      <object class="GtkGrid" id="grid1">
+      <object class="GtkLabel" id="label2">
         <property name="visible">True</property>
-        <property name="can_focus">False</property>
+        <property name="can-focus">False</property>
+        <property name="label" translatable="yes" 
context="sidebartheme|label2">Colors</property>
+        <property name="use-underline">True</property>
+        <property name="mnemonic-widget">valueset_colors</property>
+        <property name="xalign">0</property>
+      </object>
+      <packing>
+        <property name="left-attach">0</property>
+        <property name="top-attach">0</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkButton" id="apply">
+        <property name="label" translatable="yes" 
context="stock">_Apply</property>
+        <property name="visible">True</property>
+        <property name="can-focus">True</property>
+        <property name="receives-default">True</property>
+        <property name="use-underline">True</property>
+      </object>
+      <packing>
+        <property name="left-attach">0</property>
+        <property name="top-attach">2</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkScrolledWindow" id="valuesetwin">
+        <property name="visible">True</property>
+        <property name="can-focus">True</property>
         <property name="hexpand">True</property>
         <property name="vexpand">True</property>
-        <property name="row_spacing">6</property>
-        <property name="column_spacing">6</property>
-        <child>
-          <object class="GtkLabel" id="label1">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="label" translatable="yes" 
context="sidebartheme|label1">Fonts</property>
-            <property name="use_underline">True</property>
-            <property name="mnemonic_widget">listbox_fonts</property>
-            <property name="xalign">0</property>
-          </object>
-          <packing>
-            <property name="left_attach">0</property>
-            <property name="top_attach">0</property>
-          </packing>
-        </child>
+        <property name="hscrollbar-policy">never</property>
+        <property name="vscrollbar-policy">never</property>
+        <property name="shadow-type">in</property>
         <child>
-          <object class="GtkScrolledWindow">
+          <object class="GtkViewport">
             <property name="visible">True</property>
-            <property name="can_focus">True</property>
-            <property name="hexpand">True</property>
-            <property name="vexpand">True</property>
-            <property name="shadow_type">in</property>
+            <property name="can-focus">False</property>
             <child>
-              <object class="GtkTreeView" id="listbox_fonts">
+              <object class="GtkDrawingArea" id="valueset_colors">
                 <property name="visible">True</property>
-                <property name="can_focus">True</property>
+                <property name="can-focus">True</property>
+                <property name="events">GDK_BUTTON_PRESS_MASK | 
GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | 
GDK_STRUCTURE_MASK</property>
                 <property name="hexpand">True</property>
                 <property name="vexpand">True</property>
-                <property name="model">liststore1</property>
-                <property name="headers_visible">False</property>
-                <property name="headers_clickable">False</property>
-                <property name="search_column">0</property>
-                <property name="show_expanders">False</property>
-                <child internal-child="selection">
-                  <object class="GtkTreeSelection"/>
-                </child>
-                <child>
-                  <object class="GtkTreeViewColumn" id="treeviewcolumn1">
-                    <child>
-                      <object class="GtkCellRendererText" 
id="cellrenderertext1"/>
-                      <attributes>
-                        <attribute name="text">0</attribute>
-                      </attributes>
-                    </child>
-                  </object>
-                </child>
-              </object>
-            </child>
-          </object>
-          <packing>
-            <property name="left_attach">0</property>
-            <property name="top_attach">1</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkLabel" id="label2">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="label" translatable="yes" 
context="sidebartheme|label2">Colors</property>
-            <property name="use_underline">True</property>
-            <property name="mnemonic_widget">valueset_colors</property>
-            <property name="xalign">0</property>
-          </object>
-          <packing>
-            <property name="left_attach">0</property>
-            <property name="top_attach">2</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkButton" id="apply">
-            <property name="label" translatable="yes" 
context="stock">_Apply</property>
-            <property name="visible">True</property>
-            <property name="can_focus">True</property>
-            <property name="receives_default">True</property>
-            <property name="use-underline">True</property>
-          </object>
-          <packing>
-            <property name="left_attach">0</property>
-            <property name="top_attach">4</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkScrolledWindow" id="valuesetwin">
-            <property name="visible">True</property>
-            <property name="can_focus">True</property>
-            <property name="hexpand">True</property>
-            <property name="vexpand">True</property>
-            <property name="hscrollbar_policy">never</property>
-            <property name="vscrollbar_policy">never</property>
-            <property name="shadow_type">in</property>
-            <child>
-              <object class="GtkViewport">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <child>
-                  <object class="GtkDrawingArea" id="valueset_colors">
-                    <property name="visible">True</property>
-                    <property name="can_focus">True</property>
-                    <property name="events">GDK_BUTTON_PRESS_MASK | 
GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | 
GDK_STRUCTURE_MASK</property>
-                    <property name="hexpand">True</property>
-                    <property name="vexpand">True</property>
-                  </object>
-                </child>
               </object>
             </child>
           </object>
-          <packing>
-            <property name="left_attach">0</property>
-            <property name="top_attach">3</property>
-          </packing>
         </child>
       </object>
       <packing>
-        <property name="left_attach">0</property>
-        <property name="top_attach">0</property>
+        <property name="left-attach">0</property>
+        <property name="top-attach">1</property>
       </packing>
     </child>
   </object>

Reply via email to