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

Julien Nabet (via logerrit) logerrit at kemper.freedesktop.org
Thu Sep 10 18:52:16 UTC 2020


 include/vcl/weld.hxx                 |   13 +++++++++-
 sfx2/source/appl/helpinterceptor.cxx |    7 ++---
 vcl/inc/salvtables.hxx               |    4 +++
 vcl/source/app/salvtables.cxx        |   16 +++++++++++++
 vcl/unx/gtk3/gtk3gtkinst.cxx         |   43 +++++++++++++++++++++++++++++++----
 5 files changed, 74 insertions(+), 9 deletions(-)

New commits:
commit ac240585063b3b74d062e3ce5384ac0705f51425
Author:     Julien Nabet <serval2412 at yahoo.fr>
AuthorDate: Wed Sep 9 11:07:33 2020 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Thu Sep 10 20:51:26 2020 +0200

    micro-optim we just want to remove all urls after m_nCurPos (sfx2)
    
    Change-Id: Ib27386baa81ee912ebb5112d721610c5fc3c708b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102287
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sfx2/source/appl/helpinterceptor.cxx b/sfx2/source/appl/helpinterceptor.cxx
index b69ca9fedd5f..75755ecbe640 100644
--- a/sfx2/source/appl/helpinterceptor.cxx
+++ b/sfx2/source/appl/helpinterceptor.cxx
@@ -50,10 +50,9 @@ void HelpInterceptor_Impl::addURL( const OUString& rURL )
     size_t nCount = m_vHistoryUrls.size();
     if ( nCount && m_nCurPos < ( nCount - 1 ) )
     {
-        for ( size_t i = nCount - 1; i > m_nCurPos; i-- )
-        {
-            m_vHistoryUrls.erase( m_vHistoryUrls.begin() + i );
-        }
+        m_vHistoryUrls.erase(
+            m_vHistoryUrls.begin() + m_nCurPos + 1,
+            m_vHistoryUrls.end());
     }
     Reference<XFrame> xFrame(m_xIntercepted, UNO_QUERY);
     Reference<XController> xController;
commit 265f95d9a316b1ecfee21a01d46d04cc6eadee7b
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Thu Sep 3 16:24:33 2020 +0100
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Thu Sep 10 20:51:10 2020 +0200

    support attempting to set a foreground color for labels and textviews
    
    but try to discourage use of random colors
    
    Change-Id: I1a67956846b8bd056180b37547ca7d206970c0e5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102014
    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 9d68d839f641..5508246e0c1c 100644
--- a/include/vcl/weld.hxx
+++ b/include/vcl/weld.hxx
@@ -1926,9 +1926,14 @@ public:
     virtual void set_label(const OUString& rText) = 0;
     virtual OUString get_label() const = 0;
     virtual void set_mnemonic_widget(Widget* pTarget) = 0;
-    virtual void set_label_type(LabelType eType) = 0;
     // font size is in points, not pixels, e.g. see Window::[G]etPointFont
     virtual void set_font(const vcl::Font& rFont) = 0;
+    virtual void set_label_type(LabelType eType) = 0;
+    /*
+       If you want to set a warning or error state, see set_label_type
+       instead.
+    */
+    virtual void set_font_color(const Color& rColor) = 0;
 };
 
 class VCL_DLLPUBLIC TextView : virtual public Container
@@ -1966,6 +1971,12 @@ public:
         return get_text_height() * nRows;
     }
 
+    /*
+       Typically you want to avoid the temptation of customizing
+       font colors
+    */
+    virtual void set_font_color(const Color& rColor) = 0;
+
     void save_value() { m_sSavedValue = get_text(); }
     bool get_value_changed_from_saved() const { return m_sSavedValue != get_text(); }
 
diff --git a/vcl/inc/salvtables.hxx b/vcl/inc/salvtables.hxx
index d82e1e5087f6..ac856598768e 100644
--- a/vcl/inc/salvtables.hxx
+++ b/vcl/inc/salvtables.hxx
@@ -407,6 +407,8 @@ public:
     virtual void set_label_type(weld::LabelType eType) override;
 
     virtual void set_font(const vcl::Font& rFont) override;
+
+    virtual void set_font_color(const Color& rColor) override;
 };
 
 class SalInstanceContainer : public SalInstanceWidget, public virtual weld::Container
@@ -1276,6 +1278,8 @@ public:
 
     virtual void set_monospace(bool bMonospace) override;
 
+    virtual void set_font_color(const Color& rColor) override;
+
     virtual void connect_cursor_position(const Link<TextView&, void>& rLink) override;
 
     virtual bool can_move_cursor_with_up() const override;
diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx
index 16436ad0a666..0343347cde96 100644
--- a/vcl/source/app/salvtables.cxx
+++ b/vcl/source/app/salvtables.cxx
@@ -5547,6 +5547,14 @@ void SalInstanceLabel::set_label_type(weld::LabelType eType)
     }
 }
 
+void SalInstanceLabel::set_font_color(const Color& rColor)
+{
+    if (rColor != COL_AUTO)
+        m_xLabel->SetControlForeground(rColor);
+    else
+        m_xLabel->SetControlForeground();
+}
+
 void SalInstanceLabel::set_font(const vcl::Font& rFont)
 {
     m_xLabel->SetPointFont(*m_xLabel, rFont);
@@ -5623,6 +5631,14 @@ void SalInstanceTextView::set_monospace(bool bMonospace)
     m_xTextView->SetControlFont(aFont);
 }
 
+void SalInstanceTextView::set_font_color(const Color& rColor)
+{
+    if (rColor != COL_AUTO)
+        m_xTextView->SetControlForeground(rColor);
+    else
+        m_xTextView->SetControlForeground();
+}
+
 void SalInstanceTextView::connect_cursor_position(const Link<TextView&, void>& rLink)
 {
     assert(!m_aCursorPositionHdl.IsSet());
diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx
index 5e7f09c22a76..693200c6349a 100644
--- a/vcl/unx/gtk3/gtk3gtkinst.cxx
+++ b/vcl/unx/gtk3/gtk3gtkinst.cxx
@@ -12556,7 +12556,7 @@ private:
         pango_attr_list_unref(pAttrs);
     }
 
-    void set_bold_text_foreground_color(const Color& rColor)
+    void set_text_foreground_color(const Color& rColor, bool bSetBold)
     {
         guint16 nRed = rColor.GetRed() << 8;
         guint16 nGreen = rColor.GetRed() << 8;
@@ -12564,14 +12564,19 @@ private:
 
         PangoAttrType aFilterAttrs[] = {PANGO_ATTR_FOREGROUND, PANGO_ATTR_WEIGHT, PANGO_ATTR_INVALID};
 
+        if (!bSetBold)
+            aFilterAttrs[1] = PANGO_ATTR_INVALID;
+
         PangoAttrList* pOrigList = gtk_label_get_attributes(m_pLabel);
         PangoAttrList* pAttrs = pOrigList
             ? pango_attr_list_filter(pOrigList, filter_pango_attrs, &aFilterAttrs)
             : nullptr;
         if (!pAttrs)
             pAttrs = pango_attr_list_new();
-        pango_attr_list_insert(pAttrs, pango_attr_foreground_new(nRed, nGreen, nBlue));
-        pango_attr_list_insert(pAttrs, pango_attr_weight_new(PANGO_WEIGHT_BOLD));
+        if (rColor != COL_AUTO)
+            pango_attr_list_insert(pAttrs, pango_attr_foreground_new(nRed, nGreen, nBlue));
+        if (bSetBold)
+            pango_attr_list_insert(pAttrs, pango_attr_weight_new(PANGO_WEIGHT_BOLD));
         gtk_label_set_attributes(m_pLabel, pAttrs);
         pango_attr_list_unref(pAttrs);
     }
@@ -12614,17 +12619,23 @@ public:
                 set_text_background_color(Application::GetSettings().GetStyleSettings().GetHighlightColor());
                 break;
             case weld::LabelType::Title:
-                set_bold_text_foreground_color(Application::GetSettings().GetStyleSettings().GetLightColor());
+                set_text_foreground_color(Application::GetSettings().GetStyleSettings().GetLightColor(), true);
                 break;
         }
     }
 
     virtual void set_font(const vcl::Font& rFont) override
     {
+        // TODO, clear old props like set_text_foreground_color does
         PangoAttrList* pAttrList = create_attr_list(rFont);
         gtk_label_set_attributes(m_pLabel, pAttrList);
         pango_attr_list_unref(pAttrList);
     }
+
+    virtual void set_font_color(const Color& rColor) override
+    {
+        set_text_foreground_color(rColor, false);
+    }
 };
 
 }
@@ -12645,6 +12656,7 @@ private:
     GtkTextView* m_pTextView;
     GtkTextBuffer* m_pTextBuffer;
     GtkAdjustment* m_pVAdjustment;
+    GtkCssProvider* m_pFgCssProvider;
     int m_nMaxTextLength;
     gulong m_nChangedSignalId; // we don't disable/enable this one, it's to implement max-length
     gulong m_nInsertTextSignalId;
@@ -12733,6 +12745,7 @@ public:
         , m_pTextView(pTextView)
         , m_pTextBuffer(gtk_text_view_get_buffer(pTextView))
         , m_pVAdjustment(gtk_scrollable_get_vadjustment(GTK_SCROLLABLE(pTextView)))
+        , m_pFgCssProvider(nullptr)
         , m_nMaxTextLength(0)
         , m_nChangedSignalId(g_signal_connect(m_pTextBuffer, "changed", G_CALLBACK(signalChanged), this))
         , m_nInsertTextSignalId(g_signal_connect_after(m_pTextBuffer, "insert-text", G_CALLBACK(signalInserText), this))
@@ -12823,6 +12836,28 @@ public:
         gtk_text_view_set_monospace(m_pTextView, bMonospace);
     }
 
+    virtual void set_font_color(const Color& rColor) override
+    {
+        const bool bRemoveColor = rColor == COL_AUTO;
+        if (bRemoveColor && !m_pFgCssProvider)
+            return;
+        GtkStyleContext *pWidgetContext = gtk_widget_get_style_context(GTK_WIDGET(m_pTextView));
+        if (m_pFgCssProvider)
+        {
+            gtk_style_context_remove_provider(pWidgetContext, GTK_STYLE_PROVIDER(m_pFgCssProvider));
+            m_pFgCssProvider = nullptr;
+        }
+        if (bRemoveColor)
+            return;
+        OUString sColor = rColor.AsRGBHexString();
+        m_pFgCssProvider = gtk_css_provider_new();
+        OUString aBuffer = "textview text { color: #" + sColor + "; }";
+        OString aResult = OUStringToOString(aBuffer, RTL_TEXTENCODING_UTF8);
+        gtk_css_provider_load_from_data(m_pFgCssProvider, aResult.getStr(), aResult.getLength(), nullptr);
+        gtk_style_context_add_provider(pWidgetContext, GTK_STYLE_PROVIDER(m_pFgCssProvider),
+                                       GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+    }
+
     virtual void disable_notify_events() override
     {
         g_signal_handler_block(m_pVAdjustment, m_nVAdjustChangedSignalId);


More information about the Libreoffice-commits mailing list