include/svx/dialog/ThemeColorValueSet.hxx |   38 ++
 svx/Library_svx.mk                        |    1 
 svx/source/dialog/ThemeColorValueSet.cxx  |   98 +++++++
 svx/source/styles/ColorSets.cxx           |  100 +++++++
 sw/source/uibase/sidebar/ThemePanel.cxx   |  412 +-----------------------------
 sw/source/uibase/sidebar/ThemePanel.hxx   |    7 
 sw/uiconfig/swriter/ui/sidebartheme.ui    |  164 +++--------
 7 files changed, 306 insertions(+), 514 deletions(-)

New commits:
commit 733a7bf52296e941cd77c9bf7a4ff64e69b57879
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Thu Jan 5 23:58:50 2023 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Fri Jan 20 07:14:58 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>
    (cherry picked from commit 8bc22ed6899bcbafc3020f0af6c939019506a5fd)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145853
    Tested-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 7f7b6db0b074..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 = "Liberation Mono";
-        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 = "Liberation Mono";
-        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>
commit 6956fbce8626abc8b9d9fc3ab3c606a6edc85946
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Thu Jan 5 23:37:18 2023 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Fri Jan 20 07:14:44 2023 +0000

    svx: add UX defined theme color sets
    
    Change-Id: I82cbe16fcfaa8367dacda7ff977e18b0ed39ec2f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145086
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>
    (cherry picked from commit 2ec4a66b6d049f5d11f4ceb993ed907c790ed592)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145852
    Tested-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/svx/source/styles/ColorSets.cxx b/svx/source/styles/ColorSets.cxx
index cf634b735c37..439c63d1ee35 100644
--- a/svx/source/styles/ColorSets.cxx
+++ b/svx/source/styles/ColorSets.cxx
@@ -171,7 +171,103 @@ ColorSets::~ColorSets()
 
 void ColorSets::init()
 {
-    //{
+    {
+        ColorSet aColorSet("LibreOffice");
+        aColorSet.add(model::ThemeColorType::Dark1, 0x000000);
+        aColorSet.add(model::ThemeColorType::Light1, 0xFFFFFF);
+        aColorSet.add(model::ThemeColorType::Dark2, 0x000000);
+        aColorSet.add(model::ThemeColorType::Light2, 0xFFFFFF);
+        aColorSet.add(model::ThemeColorType::Accent1, 0x18A303);
+        aColorSet.add(model::ThemeColorType::Accent2, 0x0369A3);
+        aColorSet.add(model::ThemeColorType::Accent3, 0xA33E03);
+        aColorSet.add(model::ThemeColorType::Accent4, 0x8E03A3);
+        aColorSet.add(model::ThemeColorType::Accent5, 0xC99C00);
+        aColorSet.add(model::ThemeColorType::Accent6, 0xC9211E);
+        aColorSet.add(model::ThemeColorType::Hyperlink, 0x0000EE);
+        aColorSet.add(model::ThemeColorType::FollowedHyperlink, 0x551A8B);
+        maColorSets.push_back(aColorSet);
+    }
+    {
+        ColorSet aColorSet("Rainbow");
+        aColorSet.add(model::ThemeColorType::Dark1, 0x000000);
+        aColorSet.add(model::ThemeColorType::Light1, 0xFFFFFF);
+        aColorSet.add(model::ThemeColorType::Dark2, 0x1C1C1C);
+        aColorSet.add(model::ThemeColorType::Light2, 0xDDDDDD);
+        aColorSet.add(model::ThemeColorType::Accent1, 0xFF0000);
+        aColorSet.add(model::ThemeColorType::Accent2, 0xFF8000);
+        aColorSet.add(model::ThemeColorType::Accent3, 0xFFFF00);
+        aColorSet.add(model::ThemeColorType::Accent4, 0x00A933);
+        aColorSet.add(model::ThemeColorType::Accent5, 0x2A6099);
+        aColorSet.add(model::ThemeColorType::Accent6, 0x800080);
+        aColorSet.add(model::ThemeColorType::Hyperlink, 0x0000EE);
+        aColorSet.add(model::ThemeColorType::FollowedHyperlink, 0x551A8B);
+        maColorSets.push_back(aColorSet);
+    }
+    {
+        ColorSet aColorSet("Beach");
+        aColorSet.add(model::ThemeColorType::Dark1, 0x000000);
+        aColorSet.add(model::ThemeColorType::Light1, 0xFFFFFF);
+        aColorSet.add(model::ThemeColorType::Dark2, 0xFFBF00);
+        aColorSet.add(model::ThemeColorType::Light2, 0x333333);
+        aColorSet.add(model::ThemeColorType::Accent1, 0xFFF5CE);
+        aColorSet.add(model::ThemeColorType::Accent2, 0xDEE6EF);
+        aColorSet.add(model::ThemeColorType::Accent3, 0xE8F2A1);
+        aColorSet.add(model::ThemeColorType::Accent4, 0xFFD7D7);
+        aColorSet.add(model::ThemeColorType::Accent5, 0xDEE7E5);
+        aColorSet.add(model::ThemeColorType::Accent6, 0xDDDBB6);
+        aColorSet.add(model::ThemeColorType::Hyperlink, 0x7777EE);
+        aColorSet.add(model::ThemeColorType::FollowedHyperlink, 0xEE77D7);
+        maColorSets.push_back(aColorSet);
+    }
+    {
+        ColorSet aColorSet("Sunset");
+        aColorSet.add(model::ThemeColorType::Dark1, 0x000000);
+        aColorSet.add(model::ThemeColorType::Light1, 0xFFFFFF);
+        aColorSet.add(model::ThemeColorType::Dark2, 0x492300);
+        aColorSet.add(model::ThemeColorType::Light2, 0xF6F9D4);
+        aColorSet.add(model::ThemeColorType::Accent1, 0xFFFF00);
+        aColorSet.add(model::ThemeColorType::Accent2, 0xFFBF00);
+        aColorSet.add(model::ThemeColorType::Accent3, 0xFF8000);
+        aColorSet.add(model::ThemeColorType::Accent4, 0xFF4000);
+        aColorSet.add(model::ThemeColorType::Accent5, 0xBF0041);
+        aColorSet.add(model::ThemeColorType::Accent6, 0x800080);
+        aColorSet.add(model::ThemeColorType::Hyperlink, 0x0000EE);
+        aColorSet.add(model::ThemeColorType::FollowedHyperlink, 0x551A8B);
+        maColorSets.push_back(aColorSet);
+    }
+    {
+        ColorSet aColorSet("Ocean");
+        aColorSet.add(model::ThemeColorType::Dark1, 0x000000);
+        aColorSet.add(model::ThemeColorType::Light1, 0xFFFFFF);
+        aColorSet.add(model::ThemeColorType::Dark2, 0x2A6099);
+        aColorSet.add(model::ThemeColorType::Light2, 0xCCCCCC);
+        aColorSet.add(model::ThemeColorType::Accent1, 0x800080);
+        aColorSet.add(model::ThemeColorType::Accent2, 0x55308D);
+        aColorSet.add(model::ThemeColorType::Accent3, 0x2A6099);
+        aColorSet.add(model::ThemeColorType::Accent4, 0x158466);
+        aColorSet.add(model::ThemeColorType::Accent5, 0x00A933);
+        aColorSet.add(model::ThemeColorType::Accent6, 0x81D41A);
+        aColorSet.add(model::ThemeColorType::Hyperlink, 0x0000EE);
+        aColorSet.add(model::ThemeColorType::FollowedHyperlink, 0x551A8B);
+        maColorSets.push_back(aColorSet);
+    }
+    {
+        ColorSet aColorSet("Forrest");
+        aColorSet.add(model::ThemeColorType::Dark1, 0x000000);
+        aColorSet.add(model::ThemeColorType::Light1, 0xFFFFFF);
+        aColorSet.add(model::ThemeColorType::Dark2, 0x000000);
+        aColorSet.add(model::ThemeColorType::Light2, 0xFFFFFF);
+        aColorSet.add(model::ThemeColorType::Accent1, 0x813709);
+        aColorSet.add(model::ThemeColorType::Accent2, 0x224B12);
+        aColorSet.add(model::ThemeColorType::Accent3, 0x706E0C);
+        aColorSet.add(model::ThemeColorType::Accent4, 0x355269);
+        aColorSet.add(model::ThemeColorType::Accent5, 0xBE480A);
+        aColorSet.add(model::ThemeColorType::Accent6, 0xBE480A);
+        aColorSet.add(model::ThemeColorType::Hyperlink, 0x2A6099);
+        aColorSet.add(model::ThemeColorType::FollowedHyperlink, 0x800080);
+        maColorSets.push_back(aColorSet);
+    }
+    {
         ColorSet aColorSet("Breeze");
         aColorSet.add(model::ThemeColorType::Dark1, 0x232629);
         aColorSet.add(model::ThemeColorType::Light1, 0xFCFCFC);
@@ -186,7 +282,7 @@ void ColorSets::init()
         aColorSet.add(model::ThemeColorType::Hyperlink, 0x1D99F3);
         aColorSet.add(model::ThemeColorType::FollowedHyperlink, 0x3DAEE9);
         maColorSets.push_back(aColorSet);
-    //}
+    }
 }
 
 const ColorSet& ColorSets::getColorSet(std::u16string_view rName)

Reply via email to