include/svx/dialog/ThemeColorValueSet.hxx |   38 -----------
 svx/Library_svx.mk                        |    1 
 svx/source/dialog/ThemeColorValueSet.cxx  |   97 ------------------------------
 sw/source/uibase/sidebar/ThemePanel.cxx   |   88 ++++++++++++++++++++-------
 sw/source/uibase/sidebar/ThemePanel.hxx   |   10 ---
 sw/uiconfig/swriter/ui/sidebartheme.ui    |   36 ++++-------
 6 files changed, 84 insertions(+), 186 deletions(-)

New commits:
commit 556ba8b0cbcc2b2fd55cd8611812af3c1fbb6f2d
Author:     Michael Weghorn <[email protected]>
AuthorDate: Tue Dec 9 18:43:39 2025 +0100
Commit:     Michael Weghorn <[email protected]>
CommitDate: Wed Dec 10 17:40:34 2025 +0100

    sw: Use weld::IconView in ThemePanel
    
    Replace the use of a custom ValueSet subclass
    ThemeColorValueSet to display the themes to choose
    with a more standard weld::IconView.
    
    Besides reducing custom logic, it also ensures
    that theming/styling adheres better to the rest
    of the application, e.g. the way that the currently
    selected theme in the sidebar is highlighted.
    
    In this case, it also makes sure that actually
    all themes are shown: Previously, only 6 of them
    instead of all 7 were displayed, due to hard-coding
    the number of rows and columns in the ThemePanel ctor
    
        mxValueSetColors->SetColCount(2);
        mxValueSetColors->SetLineCount(3);
    
    Now, all 7 themes are shown and can be selected.
    
    The newly introduced helper method ThemePanel::CreateImage
    mostly takes over the existing logic from the (now dropped)
    ThemeColorValueSet::UserDraw.
    
    Drop the now no longer used ThemeColorValueSet.
    
    An upcoming commit will also set accessible
    names for the themes, which wasn't previously
    done either.
    
    The theme panel can be reached as follows:
    
    * start Writer
    * in "Tools" -> "Options" -> "Advanced", enable
      "Enable experimental features (may be unstable)",
      press "OK" button, restart LO to apply those changes
    * open the "Design" sidebar panel in Writer
    
    The list of theme colors in the "Themes" section
    is the one that was switched to weld::IconView
    by this commit.
    
    The "Format" -> "Themes" dialog shows the same
    set of color themes and can also be used while testing
    that a change to the color theme in the sidebar
    was actually applied as expected.
    
    Change-Id: I77b7b12d0087eac8afeb88d4847a95ed268bfc5f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/195324
    Reviewed-by: Michael Weghorn <[email protected]>
    Tested-by: Jenkins

diff --git a/include/svx/dialog/ThemeColorValueSet.hxx 
b/include/svx/dialog/ThemeColorValueSet.hxx
deleted file mode 100644
index ee73275c4d41..000000000000
--- a/include/svx/dialog/ThemeColorValueSet.hxx
+++ /dev/null
@@ -1,38 +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 <svx/svxdllapi.h>
-#include <sal/config.h>
-#include <svtools/valueset.hxx>
-#include <docmodel/theme/ColorSet.hxx>
-
-namespace svx
-{
-class SVX_DLLPUBLIC ThemeColorValueSet final : public ValueSet
-{
-    std::vector<std::reference_wrapper<const model::ColorSet>> maColorSets;
-
-public:
-    ThemeColorValueSet()
-        : ValueSet(nullptr)
-    {
-    }
-
-    void SetDrawingArea(weld::DrawingArea* pDrawingArea) override;
-    void UserDraw(const UserDrawEvent& rUserDrawEvent) override;
-    void StyleUpdated() override;
-
-    void insert(model::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 e0fe649db132..677522593a25 100644
--- a/svx/Library_svx.mk
+++ b/svx/Library_svx.mk
@@ -176,7 +176,6 @@ $(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/ThemeDialog \
     svx/source/dialog/ThemeColorEditDialog \
     svx/source/dialog/txencbox \
diff --git a/svx/source/dialog/ThemeColorValueSet.cxx 
b/svx/source/dialog/ThemeColorValueSet.cxx
deleted file mode 100644
index b63703e27c10..000000000000
--- a/svx/source/dialog/ThemeColorValueSet.cxx
+++ /dev/null
@@ -1,97 +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/.
- */
-
-#include <svx/dialog/ThemeColorValueSet.hxx>
-#include <vcl/event.hxx>
-
-namespace svx
-{
-constexpr tools::Long BORDER = 4;
-constexpr tools::Long SIZE = 16;
-constexpr tools::Long LABEL_HEIGHT = 16;
-constexpr tools::Long LABEL_TEXT_HEIGHT = 14;
-constexpr tools::Long constElementNumber = 8;
-
-void ThemeColorValueSet::insert(model::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();
-    model::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 690906b1893c..0a7170a447d1 100644
--- a/sw/source/uibase/sidebar/ThemePanel.cxx
+++ b/sw/source/uibase/sidebar/ThemePanel.cxx
@@ -18,9 +18,9 @@
 #include <ThemeColorChanger.hxx>
 #include <vcl/settings.hxx>
 #include <vcl/svapp.hxx>
+#include <vcl/virdev.hxx>
 #include <docmodel/theme/Theme.hxx>
 #include <svx/svdpage.hxx>
-#include <svx/dialog/ThemeColorValueSet.hxx>
 #include <com/sun/star/lang/IllegalArgumentException.hpp>
 
 namespace sw::sidebar
@@ -36,33 +36,28 @@ std::unique_ptr<PanelLayout> 
ThemePanel::Create(weld::Widget* pParent)
 
 ThemePanel::ThemePanel(weld::Widget* pParent)
     : PanelLayout(pParent, u"ThemePanel"_ustr, 
u"modules/swriter/ui/sidebartheme.ui"_ustr)
-    , mxValueSetColors(new svx::ThemeColorValueSet)
-    , mxValueSetColorsWin(new weld::CustomWeld(*m_xBuilder, 
u"valueset_colors"_ustr, *mxValueSetColors))
+    , mxIconViewColors(m_xBuilder->weld_icon_view(u"iconview_colors"_ustr))
     , mxApplyButton(m_xBuilder->weld_button(u"apply"_ustr))
 {
-    mxValueSetColors->SetColCount(2);
-    mxValueSetColors->SetLineCount(3);
-    
mxValueSetColors->SetColor(Application::GetSettings().GetStyleSettings().GetFaceColor());
-
     mxApplyButton->connect_clicked(LINK(this, ThemePanel, ClickHdl));
-    mxValueSetColors->SetDoubleClickHdl(LINK(this, ThemePanel, 
DoubleClickValueSetHdl));
+    mxIconViewColors->connect_item_activated(LINK(this, ThemePanel, 
ItemActivatedHdl));
 
     auto const& rColorSets = svx::ColorSets::get();
     for (model::ColorSet const& rColorSet : rColorSets.getColorSetVector())
     {
-        mxValueSetColors->insert(rColorSet);
+        ScopedVclPtr<VirtualDevice> pDev = CreateImage(rColorSet);
+        const Bitmap aBitmap = pDev->GetBitmap(Point(0, 0), 
pDev->GetOutputSize());
+        const int nIndex = mxIconViewColors->n_children();
+        const OUString sId = OUString::number(nIndex);
+        mxIconViewColors->insert(nIndex, nullptr, &sId, &aBitmap, nullptr);
     }
 
-    mxValueSetColors->SetOptimalSize();
-
     if (!rColorSets.getColorSetVector().empty())
-        mxValueSetColors->SelectItem(1); // ItemId 1, position 0
+        mxIconViewColors->select(0);
 }
 
 ThemePanel::~ThemePanel()
 {
-    mxValueSetColorsWin.reset();
-    mxValueSetColors.reset();
     mxApplyButton.reset();
 }
 
@@ -71,9 +66,66 @@ IMPL_LINK_NOARG(ThemePanel, ClickHdl, weld::Button&, void)
     DoubleClickHdl();
 }
 
-IMPL_LINK_NOARG(ThemePanel, DoubleClickValueSetHdl, ValueSet*, void)
+IMPL_LINK_NOARG(ThemePanel, ItemActivatedHdl, weld::IconView&, bool)
 {
     DoubleClickHdl();
+    return true;
+}
+
+VclPtr<VirtualDevice> ThemePanel::CreateImage(const model::ColorSet& rColorSet)
+{
+    constexpr tools::Long BORDER = 4;
+    constexpr tools::Long SIZE = 16;
+    constexpr tools::Long LABEL_HEIGHT = 16;
+    constexpr tools::Long LABEL_TEXT_HEIGHT = 14;
+    constexpr tools::Long constElementNumber = 8;
+
+    const Size aMin(BORDER * 7 + SIZE * constElementNumber / 2 + BORDER * 2,
+                    BORDER * 3 + SIZE * 2 + LABEL_HEIGHT);
+
+    const Size aSize(aMin.Width() + 40, aMin.Height());
+    VclPtr<VirtualDevice> pDev = mxIconViewColors->create_virtual_device();
+    pDev->SetOutputSizePixel(aSize);
+
+    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(Point(0, 0), 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((aNameRect.GetWidth() / 2.0) - (aTextSize.Width() / 2.0),
+                 (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(x + startX, y1), Size(SIZE, 
SIZE)));
+
+        pDev->SetFillColor(rColorSet.getColor(model::convertToThemeColorType(i 
+ 1)));
+        pDev->DrawRect(tools::Rectangle(Point(x + startX, y2), Size(SIZE, 
SIZE)));
+
+        x += SIZE + BORDER;
+        if (i == 2 || i == 8)
+            x += BORDER;
+    }
+
+    return pDev;
 }
 
 void ThemePanel::DoubleClickHdl()
@@ -82,10 +134,10 @@ void ThemePanel::DoubleClickHdl()
     if (!pDocSh)
         return;
 
-    sal_uInt32 nItemId = mxValueSetColors->GetSelectedItemId();
-    if (!nItemId)
+    const OUString sId = mxIconViewColors->get_selected_id();
+    if (sId.isEmpty())
         return;
-    sal_uInt32 nIndex = nItemId - 1;
+    const sal_uInt32 nIndex = sId.toUInt32();
 
     auto const& rColorSets = svx::ColorSets::get();
     model::ColorSet const& rColorSet = rColorSets.getColorSet(nIndex);
diff --git a/sw/source/uibase/sidebar/ThemePanel.hxx 
b/sw/source/uibase/sidebar/ThemePanel.hxx
index e536faaf3858..513778525f67 100644
--- a/sw/source/uibase/sidebar/ThemePanel.hxx
+++ b/sw/source/uibase/sidebar/ThemePanel.hxx
@@ -15,8 +15,6 @@
 #include <svtools/valueset.hxx>
 #include <svx/ColorSets.hxx>
 
-namespace svx { class ThemeColorValueSet; }
-
 namespace sw::sidebar
 {
 
@@ -38,14 +36,14 @@ public:
         boost::property_tree::ptree& /*rState*/) override {};
 
 private:
-    std::unique_ptr<svx::ThemeColorValueSet> mxValueSetColors;
-    std::unique_ptr<weld::CustomWeld> mxValueSetColorsWin;
+    std::unique_ptr<weld::IconView> mxIconViewColors;
     std::unique_ptr<weld::Button> mxApplyButton;
 
     DECL_LINK(ClickHdl, weld::Button&, void);
+    DECL_LINK(ItemActivatedHdl, weld::IconView&, bool);
     DECL_LINK(DoubleClickValueSetHdl, ValueSet*, void);
     void DoubleClickHdl();
-
+    VclPtr<VirtualDevice> CreateImage(const model::ColorSet& rColorSet);
 };
 
 } // end of namespace sw::sidebar
diff --git a/sw/uiconfig/swriter/ui/sidebartheme.ui 
b/sw/uiconfig/swriter/ui/sidebartheme.ui
index dd464e0c259e..ed0cc6603d83 100644
--- a/sw/uiconfig/swriter/ui/sidebartheme.ui
+++ b/sw/uiconfig/swriter/ui/sidebartheme.ui
@@ -2,6 +2,14 @@
 <!-- Generated with glade 3.40.0 -->
 <interface domain="sw">
   <requires lib="gtk+" version="3.24"/>
+  <object class="GtkTreeStore" id="colorsliststore">
+    <columns>
+      <!-- column-name pixbuf -->
+      <column type="GdkPixbuf"/>
+      <!-- column-name id -->
+      <column type="gchararray"/>
+    </columns>
+  </object>
   <!-- n-columns=1 n-rows=3 -->
   <object class="GtkGrid" id="ThemePanel">
     <property name="visible">True</property>
@@ -14,7 +22,7 @@
         <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="mnemonic-widget">iconview_colors</property>
         <property name="xalign">0</property>
       </object>
       <packing>
@@ -36,29 +44,13 @@
       </packing>
     </child>
     <child>
-      <object class="GtkScrolledWindow" id="valuesetwin">
+      <object class="GtkIconView" id="iconview_colors">
         <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>
+        <property name="margin">6</property>
+        <property name="model">colorsliststore</property>
+        <property name="pixbuf-column">0</property>
+        <property name="columns">2</property>
       </object>
       <packing>
         <property name="left-attach">0</property>
commit c749b94b9a71c1a735f3524bfa310b481684eea6
Author:     Michael Weghorn <[email protected]>
AuthorDate: Tue Dec 9 18:01:43 2025 +0100
Commit:     Michael Weghorn <[email protected]>
CommitDate: Wed Dec 10 17:40:24 2025 +0100

    sw: Drop unused ThemePanel members
    
    Unused since
    
        commit 8bc22ed6899bcbafc3020f0af6c939019506a5fd
        Date:   Thu Jan 5 23:58:50 2023 +0900
    
            sw: rework ThemePanel, theme color ValueSet drawing as custom draw
    
    Change-Id: Ifb3c4f01dacf6cb2c997b693cee0797730531cb4
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/195321
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <[email protected]>

diff --git a/sw/source/uibase/sidebar/ThemePanel.cxx 
b/sw/source/uibase/sidebar/ThemePanel.cxx
index f73ca7bbc8a0..690906b1893c 100644
--- a/sw/source/uibase/sidebar/ThemePanel.cxx
+++ b/sw/source/uibase/sidebar/ThemePanel.cxx
@@ -76,12 +76,6 @@ IMPL_LINK_NOARG(ThemePanel, DoubleClickValueSetHdl, 
ValueSet*, void)
     DoubleClickHdl();
 }
 
-IMPL_LINK_NOARG(ThemePanel, DoubleClickHdl, weld::TreeView&, bool)
-{
-    DoubleClickHdl();
-    return true;
-}
-
 void ThemePanel::DoubleClickHdl()
 {
     SwDocShell* pDocSh = static_cast<SwDocShell*>(SfxObjectShell::Current());
diff --git a/sw/source/uibase/sidebar/ThemePanel.hxx 
b/sw/source/uibase/sidebar/ThemePanel.hxx
index 12285286f546..e536faaf3858 100644
--- a/sw/source/uibase/sidebar/ThemePanel.hxx
+++ b/sw/source/uibase/sidebar/ThemePanel.hxx
@@ -38,13 +38,11 @@ public:
         boost::property_tree::ptree& /*rState*/) override {};
 
 private:
-    std::unique_ptr<weld::TreeView> mxListBoxFonts;
     std::unique_ptr<svx::ThemeColorValueSet> mxValueSetColors;
     std::unique_ptr<weld::CustomWeld> mxValueSetColorsWin;
     std::unique_ptr<weld::Button> mxApplyButton;
 
     DECL_LINK(ClickHdl, weld::Button&, void);
-    DECL_LINK(DoubleClickHdl, weld::TreeView&, bool);
     DECL_LINK(DoubleClickValueSetHdl, ValueSet*, void);
     void DoubleClickHdl();
 

Reply via email to