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

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Mon Oct 4 10:43:02 UTC 2021


 include/svtools/editbrowsebox.hxx     |    8 +++-
 include/vcl/weld.hxx                  |    3 +
 svtools/source/brwbox/ebbcontrols.cxx |   18 +++++++--
 vcl/inc/salvtables.hxx                |    4 ++
 vcl/source/app/salvtables.cxx         |   27 +++++++++-----
 vcl/unx/gtk3/gtkinst.cxx              |   65 ++++++++++++++++++++++++++++++----
 6 files changed, 106 insertions(+), 19 deletions(-)

New commits:
commit 952a678634461f741ee4ef2082d591a162a7f71c
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Mon Oct 4 10:35:34 2021 +0100
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Mon Oct 4 12:42:27 2021 +0200

    Related: tdf#141633 similiarly support match combo/listbox font sizes
    
    to the desired zoomed font size in the table control
    
    Change-Id: Iaf3b004544fdb0311b6c67baad612ba648e8c546
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123043
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/include/svtools/editbrowsebox.hxx b/include/svtools/editbrowsebox.hxx
index 9ebbb3a2696b..199173a390cf 100644
--- a/include/svtools/editbrowsebox.hxx
+++ b/include/svtools/editbrowsebox.hxx
@@ -172,7 +172,7 @@ namespace svt
 
         virtual bool ProcessKey(const KeyEvent& rKEvt);
 
-        virtual void SetPointFont(const vcl::Font& rFont);
+        virtual void SetPointFont(const vcl::Font& rFont) = 0;
 
         // chain after the FocusInHdl
         void SetFocusInHdl(const Link<LinkParamNone*,void>& rHdl)
@@ -564,6 +564,8 @@ namespace svt
         virtual ~CheckBoxControl() override;
         virtual void dispose() override;
 
+        virtual void SetPointFont(const vcl::Font& rFont) override;
+
         void SetToggleHdl(const Link<weld::CheckButton&,void>& rHdl) {m_aToggleLink = rHdl;}
 
         // sets a link to call when the text is changed by the user
@@ -629,6 +631,8 @@ namespace svt
     public:
         ComboBoxControl(BrowserDataWin* pParent);
 
+        virtual void SetPointFont(const vcl::Font& rFont) override;
+
         virtual void SetEditableReadOnly(bool bReadOnly) override
         {
             m_xWidget->set_entry_editable(!bReadOnly);
@@ -695,6 +699,8 @@ namespace svt
     public:
         ListBoxControl(BrowserDataWin* pParent);
 
+        virtual void SetPointFont(const vcl::Font& rFont) override;
+
         weld::ComboBox& get_widget() { return *m_xWidget; }
 
         // sets a link to call when the selection is changed by the user
diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx
index 5ca6a468e33c..df036c8fde1a 100644
--- a/include/vcl/weld.hxx
+++ b/include/vcl/weld.hxx
@@ -786,6 +786,9 @@ public:
     virtual void copy_entry_clipboard() = 0;
     virtual void paste_entry_clipboard() = 0;
 
+    // font size is in points, not pixels, e.g. see Window::[G]etPointFont
+    virtual void set_font(const vcl::Font& rFont) = 0;
+
     // font size is in points, not pixels, e.g. see Window::[G]etPointFont
     virtual void set_entry_font(const vcl::Font& rFont) = 0;
     virtual vcl::Font get_entry_font() = 0;
diff --git a/svtools/source/brwbox/ebbcontrols.cxx b/svtools/source/brwbox/ebbcontrols.cxx
index 9c1b438bb129..9980d1ae469b 100644
--- a/svtools/source/brwbox/ebbcontrols.cxx
+++ b/svtools/source/brwbox/ebbcontrols.cxx
@@ -37,6 +37,11 @@ namespace svt
         m_xWidget->connect_mouse_move(LINK(this, ControlBase, MouseMoveHdl));
     }
 
+    void ComboBoxControl::SetPointFont(const vcl::Font& rFont)
+    {
+        m_xWidget->set_entry_font(rFont);
+    }
+
     void ComboBoxControl::dispose()
     {
         m_xWidget.reset();
@@ -127,6 +132,11 @@ namespace svt
         m_xWidget->connect_mouse_move(LINK(this, ControlBase, MouseMoveHdl));
     }
 
+    void ListBoxControl::SetPointFont(const vcl::Font& rFont)
+    {
+        m_xWidget->set_font(rFont);
+    }
+
     void ListBoxControl::dispose()
     {
         m_xWidget.reset();
@@ -201,6 +211,10 @@ namespace svt
         m_xBox->connect_toggled(LINK(this, CheckBoxControl, OnToggle));
     }
 
+    void CheckBoxControl::SetPointFont(const vcl::Font& /*rFont*/)
+    {
+    }
+
     void CheckBoxControl::EnableTriState( bool bTriState )
     {
         if (m_aModeState.bTriStateEnabled != bTriState)
@@ -361,10 +375,6 @@ namespace svt
         return static_cast<BrowserDataWin*>(GetParent())->GetParent()->ProcessKey(rKEvt);
     }
 
-    void ControlBase::SetPointFont(const vcl::Font& /*rFont*/)
-    {
-    }
-
     IMPL_LINK(ControlBase, KeyInputHdl, const KeyEvent&, rKEvt, bool)
     {
         return ProcessKey(rKEvt);
diff --git a/vcl/inc/salvtables.hxx b/vcl/inc/salvtables.hxx
index 2bd066180965..c77528a3635b 100644
--- a/vcl/inc/salvtables.hxx
+++ b/vcl/inc/salvtables.hxx
@@ -911,6 +911,8 @@ public:
 
     virtual void paste_entry_clipboard() override;
 
+    virtual void set_font(const vcl::Font& rFont) override;
+
     virtual void set_entry_font(const vcl::Font&) override;
 
     virtual vcl::Font get_entry_font() override;
@@ -981,6 +983,8 @@ public:
 
     virtual bool get_entry_selection_bounds(int& rStartPos, int& rEndPos) override;
 
+    virtual void set_font(const vcl::Font& rFont) override;
+
     virtual void set_entry_font(const vcl::Font& rFont) override;
 
     virtual vcl::Font get_entry_font() override;
diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx
index 855012c327ab..58e1cba83ad6 100644
--- a/vcl/source/app/salvtables.cxx
+++ b/vcl/source/app/salvtables.cxx
@@ -6226,6 +6226,12 @@ void SalInstanceComboBoxWithoutEdit::copy_entry_clipboard() { assert(false); }
 
 void SalInstanceComboBoxWithoutEdit::paste_entry_clipboard() { assert(false); }
 
+void SalInstanceComboBoxWithoutEdit::set_font(const vcl::Font& rFont)
+{
+    m_xComboBox->SetControlFont(rFont);
+    m_xComboBox->Invalidate();
+}
+
 void SalInstanceComboBoxWithoutEdit::set_entry_font(const vcl::Font&) { assert(false); }
 
 vcl::Font SalInstanceComboBoxWithoutEdit::get_entry_font()
@@ -6387,12 +6393,20 @@ bool SalInstanceComboBoxWithEdit::get_entry_selection_bounds(int& rStartPos, int
     return rSelection.Len();
 }
 
-void SalInstanceComboBoxWithEdit::set_entry_font(const vcl::Font& rFont)
+void SalInstanceComboBoxWithEdit::set_font(const vcl::Font& rFont)
 {
-    m_xComboBox->SetControlFont(rFont); // tdf#134601 set it as control font to take effect properly
+    m_xComboBox->SetControlFont(rFont);
     m_xComboBox->Invalidate();
 }
 
+void SalInstanceComboBoxWithEdit::set_entry_font(const vcl::Font& rFont)
+{
+    Edit* pEdit = m_xComboBox->GetSubEdit();
+    assert(pEdit);
+    pEdit->SetControlFont(rFont); // tdf#134601 set it as control font to take effect properly
+    pEdit->Invalidate();
+}
+
 vcl::Font SalInstanceComboBoxWithEdit::get_entry_font()
 {
     Edit* pEdit = m_xComboBox->GetSubEdit();
@@ -6521,12 +6535,9 @@ public:
         rEntry.SetAutocompleteHdl(Link<Edit&, void>());
     }
 
-    virtual void set_entry_font(const vcl::Font& rFont) override
-    {
-        Edit& rEntry = m_pEntry->getEntry();
-        rEntry.SetControlFont(rFont);
-        rEntry.Invalidate();
-    }
+    virtual void set_font(const vcl::Font&) override { assert(false && "not implemented"); }
+
+    virtual void set_entry_font(const vcl::Font& rFont) override { m_pEntry->set_font(rFont); }
 
     virtual vcl::Font get_entry_font() override
     {
diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx
index b05cc4747caf..95c54ef3f669 100644
--- a/vcl/unx/gtk3/gtkinst.cxx
+++ b/vcl/unx/gtk3/gtkinst.cxx
@@ -17604,12 +17604,14 @@ private:
     GtkWidget* m_pEntry;
     GtkEditable* m_pEditable;
 //    GtkCellView* m_pCellView;
+    GtkCssProvider* m_pFontCssProvider;
     GtkEventController* m_pKeyController;
     GtkEventController* m_pEntryKeyController;
     GtkEventController* m_pMenuKeyController;
     GtkEventController* m_pEntryFocusController;
 //    std::unique_ptr<CustomRenderMenuButtonHelper> m_xCustomMenuButtonHelper;
     std::optional<vcl::Font> m_xFont;
+    std::optional<vcl::Font> m_xEntryFont;
     std::unique_ptr<comphelper::string::NaturalStringSorter> m_xSorter;
     vcl::QuickSelectionEngine m_aQuickSelectionEngine;
     std::vector<std::unique_ptr<GtkTreeRowReference, GtkTreeRowReferenceDeleter>> m_aSeparatorRows;
@@ -18646,6 +18648,7 @@ public:
 //        , m_pToggleButton(GTK_WIDGET(gtk_builder_get_object(pComboBuilder, "button")))
         , m_pEntry(GTK_IS_ENTRY(gtk_combo_box_get_child(pComboBox)) ? gtk_combo_box_get_child(pComboBox) : nullptr)
         , m_pEditable(GTK_EDITABLE(m_pEntry))
+        , m_pFontCssProvider(nullptr)
 //        , m_pCellView(nullptr)
         , m_aQuickSelectionEngine(*this)
 //        , m_bHoverSelection(false)
@@ -19026,9 +19029,30 @@ public:
         gtk_widget_activate_action(m_pEntry, "paste.clipboard", nullptr);
     }
 
-    virtual void set_entry_font(const vcl::Font& rFont) override
+    virtual void set_font(const vcl::Font& rFont) override
     {
         m_xFont = rFont;
+        GtkStyleContext *pWidgetContext = gtk_widget_get_style_context(GTK_WIDGET(m_pComboBox));
+        if (m_pFontCssProvider)
+            gtk_style_context_remove_provider(pWidgetContext, GTK_STYLE_PROVIDER(m_pFontCssProvider));
+        m_pFontCssProvider = gtk_css_provider_new();
+        OUString aBuffer = "combobox { " + vcl_font_to_css(rFont) +  "}";
+        OString aResult = OUStringToOString(aBuffer, RTL_TEXTENCODING_UTF8);
+        css_provider_load_from_data(m_pFontCssProvider, aResult.getStr(), aResult.getLength());
+        gtk_style_context_add_provider(pWidgetContext, GTK_STYLE_PROVIDER(m_pFontCssProvider),
+                                       GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+    }
+
+    virtual vcl::Font get_font() override
+    {
+        if (m_xFont)
+            return *m_xFont;
+        return GtkInstanceWidget::get_font();
+    }
+
+    virtual void set_entry_font(const vcl::Font& rFont) override
+    {
+        m_xEntryFont = rFont;
         assert(m_pEntry);
         PangoAttrList* pOrigList = gtk_entry_get_attributes(GTK_ENTRY(m_pEntry));
         PangoAttrList* pAttrList = pOrigList ? pango_attr_list_copy(pOrigList) : pango_attr_list_new();
@@ -19039,8 +19063,8 @@ public:
 
     virtual vcl::Font get_entry_font() override
     {
-        if (m_xFont)
-            return *m_xFont;
+        if (m_xEntryFont)
+            return *m_xEntryFont;
         assert(m_pEntry);
         PangoContext* pContext = gtk_widget_get_pango_context(m_pEntry);
         return pango_to_vcl(pango_context_get_font_description(pContext),
@@ -19357,8 +19381,10 @@ private:
     GtkWidget* m_pToggleButton;
     GtkWidget* m_pEntry;
     GtkCellView* m_pCellView;
+    GtkCssProvider* m_pFontCssProvider;
     std::unique_ptr<CustomRenderMenuButtonHelper> m_xCustomMenuButtonHelper;
     std::optional<vcl::Font> m_xFont;
+    std::optional<vcl::Font> m_xEntryFont;
     std::unique_ptr<comphelper::string::NaturalStringSorter> m_xSorter;
     vcl::QuickSelectionEngine m_aQuickSelectionEngine;
     std::vector<std::unique_ptr<GtkTreeRowReference, GtkTreeRowReferenceDeleter>> m_aSeparatorRows;
@@ -20395,6 +20421,7 @@ public:
         , m_pToggleButton(GTK_WIDGET(gtk_builder_get_object(pComboBuilder, "button")))
         , m_pEntry(GTK_WIDGET(gtk_builder_get_object(pComboBuilder, "entry")))
         , m_pCellView(nullptr)
+        , m_pFontCssProvider(nullptr)
         , m_aQuickSelectionEngine(*this)
         , m_bHoverSelection(false)
         , m_bMouseInOverlayButton(false)
@@ -20811,9 +20838,30 @@ public:
         gtk_editable_paste_clipboard(GTK_EDITABLE(m_pEntry));
     }
 
-    virtual void set_entry_font(const vcl::Font& rFont) override
+    virtual void set_font(const vcl::Font& rFont) override
     {
         m_xFont = rFont;
+        GtkStyleContext *pWidgetContext = gtk_widget_get_style_context(GTK_WIDGET(getContainer()));
+        if (m_pFontCssProvider)
+            gtk_style_context_remove_provider(pWidgetContext, GTK_STYLE_PROVIDER(m_pFontCssProvider));
+        m_pFontCssProvider = gtk_css_provider_new();
+        OUString aBuffer = "box#combobox { " + vcl_font_to_css(rFont) +  "}";
+        OString aResult = OUStringToOString(aBuffer, RTL_TEXTENCODING_UTF8);
+        css_provider_load_from_data(m_pFontCssProvider, aResult.getStr(), aResult.getLength());
+        gtk_style_context_add_provider(pWidgetContext, GTK_STYLE_PROVIDER(m_pFontCssProvider),
+                                       GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+    }
+
+    virtual vcl::Font get_font() override
+    {
+        if (m_xFont)
+            return *m_xFont;
+        return GtkInstanceContainer::get_font();
+    }
+
+    virtual void set_entry_font(const vcl::Font& rFont) override
+    {
+        m_xEntryFont = rFont;
         assert(m_pEntry);
         PangoAttrList* pOrigList = gtk_entry_get_attributes(GTK_ENTRY(m_pEntry));
         PangoAttrList* pAttrList = pOrigList ? pango_attr_list_copy(pOrigList) : pango_attr_list_new();
@@ -20824,8 +20872,8 @@ public:
 
     virtual vcl::Font get_entry_font() override
     {
-        if (m_xFont)
-            return *m_xFont;
+        if (m_xEntryFont)
+            return *m_xEntryFont;
         assert(m_pEntry);
         PangoContext* pContext = gtk_widget_get_pango_context(m_pEntry);
         return pango_to_vcl(pango_context_get_font_description(pContext),
@@ -21365,6 +21413,11 @@ public:
         m_xEntry->paste_clipboard();
     }
 
+    virtual void set_font(const vcl::Font&) override
+    {
+        assert(false && "not implemented");
+    }
+
     virtual void set_entry_font(const vcl::Font& rFont) override
     {
         m_xEntry->set_font(rFont);


More information about the Libreoffice-commits mailing list