[Libreoffice-commits] core.git: include/vcl vcl/source vcl/unx

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Sat Jan 30 10:39:09 UTC 2021


 include/vcl/weld.hxx          |    5 ++++
 vcl/source/app/salvtables.cxx |   28 +++++++++++++++++++++++++++
 vcl/unx/gtk3/gtk3gtkinst.cxx  |   43 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 76 insertions(+)

New commits:
commit 6aa18a840cc205b430999e4243d9ee4b9091432d
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Fri Jan 29 13:00:17 2021 +0000
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Sat Jan 30 11:38:24 2021 +0100

    add something to override scrollbar colors
    
    Change-Id: Ibc2e428fcda41f4e9150f3e5029ba346c459c4b7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110159
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx
index 00afd2fc45b9..70a340c85b30 100644
--- a/include/vcl/weld.hxx
+++ b/include/vcl/weld.hxx
@@ -399,6 +399,11 @@ public:
         m_aVChangeHdl = rLink;
     }
     virtual int get_vscroll_width() const = 0;
+
+    //trying to use custom color for a scrollbar is generally a bad idea.
+    virtual void customize_scrollbars(const Color& rBackgroundColor, const Color& rShadowColor,
+                                      const Color& rFaceColor, int nMaxThickness)
+        = 0;
 };
 
 class Label;
diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx
index fe93e637a823..e9e675e1645b 100644
--- a/vcl/source/app/salvtables.cxx
+++ b/vcl/source/app/salvtables.cxx
@@ -1969,6 +1969,21 @@ private:
     DECL_LINK(VscrollHdl, ScrollBar*, void);
     DECL_LINK(HscrollHdl, ScrollBar*, void);
 
+    static void customize_scrollbars(ScrollBar& rScrollBar, const Color& rButtonTextColor,
+                                     const Color& rBackgroundColor, const Color& rShadowColor,
+                                     const Color& rFaceColor)
+    {
+        rScrollBar.EnableNativeWidget(false);
+        AllSettings aSettings = rScrollBar.GetSettings();
+        StyleSettings aStyleSettings = aSettings.GetStyleSettings();
+        aStyleSettings.SetButtonTextColor(rButtonTextColor);
+        aStyleSettings.SetCheckedColor(rBackgroundColor); // background
+        aStyleSettings.SetShadowColor(rShadowColor);
+        aStyleSettings.SetFaceColor(rFaceColor);
+        aSettings.SetStyleSettings(aStyleSettings);
+        rScrollBar.SetSettings(aSettings);
+    }
+
 public:
     SalInstanceScrolledWindow(VclScrolledWindow* pScrolledWindow, SalInstanceBuilder* pBuilder,
                               bool bTakeOwnership, bool bUserManagedScrolling)
@@ -2173,6 +2188,19 @@ public:
         return m_xScrolledWindow->getVertScrollBar().get_preferred_size().Width();
     }
 
+    virtual void customize_scrollbars(const Color& rBackgroundColor, const Color& rShadowColor,
+                                      const Color& rFaceColor, int nThickness) override
+    {
+        ScrollBar& rHorzScrollBar = m_xScrolledWindow->getHorzScrollBar();
+        ScrollBar& rVertScrollBar = m_xScrolledWindow->getVertScrollBar();
+        customize_scrollbars(rHorzScrollBar, Color(0, 0, 0), rBackgroundColor, rShadowColor,
+                             rFaceColor);
+        customize_scrollbars(rVertScrollBar, Color(0, 0, 0), rBackgroundColor, rShadowColor,
+                             rFaceColor);
+        rHorzScrollBar.set_height_request(nThickness);
+        rVertScrollBar.set_width_request(nThickness);
+    }
+
     virtual ~SalInstanceScrolledWindow() override
     {
         ScrollBar& rVertScrollBar = m_xScrolledWindow->getVertScrollBar();
diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx
index 38708be5d273..735a8fd24e68 100644
--- a/vcl/unx/gtk3/gtk3gtkinst.cxx
+++ b/vcl/unx/gtk3/gtk3gtkinst.cxx
@@ -5768,6 +5768,7 @@ class GtkInstanceScrolledWindow final : public GtkInstanceContainer, public virt
 private:
     GtkScrolledWindow* m_pScrolledWindow;
     GtkWidget *m_pOrigViewport;
+    GtkCssProvider* m_pScrollBarCssProvider;
     GtkAdjustment* m_pVAdjustment;
     GtkAdjustment* m_pHAdjustment;
     gulong m_nVAdjustChangedSignalId;
@@ -5792,6 +5793,7 @@ public:
         : GtkInstanceContainer(GTK_CONTAINER(pScrolledWindow), pBuilder, bTakeOwnership)
         , m_pScrolledWindow(pScrolledWindow)
         , m_pOrigViewport(nullptr)
+        , m_pScrollBarCssProvider(nullptr)
         , m_pVAdjustment(gtk_scrolled_window_get_vadjustment(m_pScrolledWindow))
         , m_pHAdjustment(gtk_scrolled_window_get_hadjustment(m_pScrolledWindow))
         , m_nVAdjustChangedSignalId(g_signal_connect(m_pVAdjustment, "value-changed", G_CALLBACK(signalVAdjustValueChanged), this))
@@ -6018,6 +6020,38 @@ public:
         g_signal_handler_unblock(m_pHAdjustment, m_nHAdjustChangedSignalId);
     }
 
+    virtual void customize_scrollbars(const Color& rBackgroundColor,
+                                      const Color& rShadowColor,
+                                      const Color& rFaceColor, int nThickness) override
+    {
+        GtkWidget *pHorzBar = gtk_scrolled_window_get_hscrollbar(m_pScrolledWindow);
+        GtkWidget *pVertBar = gtk_scrolled_window_get_vscrollbar(m_pScrolledWindow);
+        GtkStyleContext *pHorzContext = gtk_widget_get_style_context(pHorzBar);
+        GtkStyleContext *pVertContext = gtk_widget_get_style_context(pVertBar);
+        if (m_pScrollBarCssProvider)
+        {
+            gtk_style_context_remove_provider(pHorzContext, GTK_STYLE_PROVIDER(m_pScrollBarCssProvider));
+            gtk_style_context_remove_provider(pVertContext, GTK_STYLE_PROVIDER(m_pScrollBarCssProvider));
+        }
+
+        m_pScrollBarCssProvider = gtk_css_provider_new();
+        OUString aBuffer = "scrollbar contents trough { background-color: #" + rBackgroundColor.AsRGBHexString() + "; } "
+                           "scrollbar contents trough slider { background-color: #" + rShadowColor.AsRGBHexString() + "; } "
+                           "scrollbar contents button { background-color: #" + rFaceColor.AsRGBHexString() + "; } "
+                           "scrollbar contents button { color: #000000; } "
+                           "scrollbar contents button:disabled { color: #7f7f7f; }";
+        OString aResult = OUStringToOString(aBuffer, RTL_TEXTENCODING_UTF8);
+        gtk_css_provider_load_from_data(m_pScrollBarCssProvider, aResult.getStr(), aResult.getLength(), nullptr);
+
+        gtk_style_context_add_provider(pHorzContext, GTK_STYLE_PROVIDER(m_pScrollBarCssProvider),
+                                       GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+        gtk_style_context_add_provider(pVertContext, GTK_STYLE_PROVIDER(m_pScrollBarCssProvider),
+                                       GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+
+        gtk_widget_set_size_request(pHorzBar, -1, nThickness);
+        gtk_widget_set_size_request(pVertBar, nThickness, -1);
+    }
+
     virtual ~GtkInstanceScrolledWindow() override
     {
         // we use GtkInstanceContainer::[disable|enable]_notify_events later on
@@ -6025,6 +6059,15 @@ public:
         g_signal_handler_disconnect(m_pVAdjustment, m_nVAdjustChangedSignalId);
         g_signal_handler_disconnect(m_pHAdjustment, m_nHAdjustChangedSignalId);
 
+        if (m_pScrollBarCssProvider)
+        {
+            GtkStyleContext *pHorzContext = gtk_widget_get_style_context(gtk_scrolled_window_get_hscrollbar(m_pScrolledWindow));
+            GtkStyleContext *pVertContext = gtk_widget_get_style_context(gtk_scrolled_window_get_vscrollbar(m_pScrolledWindow));
+            gtk_style_context_remove_provider(pHorzContext, GTK_STYLE_PROVIDER(m_pScrollBarCssProvider));
+            gtk_style_context_remove_provider(pVertContext, GTK_STYLE_PROVIDER(m_pScrollBarCssProvider));
+            m_pScrollBarCssProvider = nullptr;
+        }
+
         //put it back the way it was
         if (!m_pOrigViewport)
             return;


More information about the Libreoffice-commits mailing list