add set_scroll_thickness to provide a way to "zoom" the scrollbar

Change-Id: I551112fb097a6ac2b442cd37d1a16bd2b34ecc54
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137932
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
This commit is contained in:
Caolán McNamara 2022-08-07 19:39:17 +01:00
parent 70015759e2
commit a56705efdb
5 changed files with 60 additions and 0 deletions

View File

@ -68,6 +68,8 @@ public:
bool HasGrab() const { return m_xScrollBar->has_grab(); }
void SetThickness(int nThickness);
ScrollAdaptor(vcl::Window* pParent, bool bHori);
virtual void dispose() override;
};

View File

@ -2517,6 +2517,9 @@ public:
virtual int adjustment_get_lower() const = 0;
virtual void adjustment_set_lower(int upper) = 0;
virtual int get_scroll_thickness() const = 0;
virtual void set_scroll_thickness(int nThickness) = 0;
virtual ScrollType get_scroll_type() const = 0;
void connect_adjustment_changed(const Link<Scrollbar&, void>& rLink) { m_aChangeHdl = rLink; }

View File

@ -114,4 +114,6 @@ tools::Long ScrollAdaptor::DoScroll(tools::Long nNewPos)
return m_xScrollBar->adjustment_get_value() - nOrig;
}
void ScrollAdaptor::SetThickness(int nThickness) { m_xScrollBar->set_scroll_thickness(nThickness); }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -2554,6 +2554,21 @@ public:
}
virtual ScrollType get_scroll_type() const override { return m_xScrollBar->GetType(); }
virtual int get_scroll_thickness() const override
{
if (m_xScrollBar->GetStyle() & WB_HORZ)
return m_xScrollBar->get_preferred_size().Height();
return m_xScrollBar->get_preferred_size().Width();
}
virtual void set_scroll_thickness(int nThickness) override
{
if (m_xScrollBar->GetStyle() & WB_HORZ)
m_xScrollBar->set_height_request(nThickness);
else
m_xScrollBar->set_width_request(nThickness);
}
};
}

View File

@ -8411,6 +8411,7 @@ class GtkInstanceScrollbar final : public GtkInstanceWidget, public virtual weld
private:
GtkScrollbar* m_pScrollbar;
GtkAdjustment* m_pAdjustment;
GtkCssProvider* m_pThicknessCssProvider;
gulong m_nAdjustChangedSignalId;
static void signalAdjustValueChanged(GtkAdjustment*, gpointer widget)
@ -8456,6 +8457,7 @@ public:
#else
, m_pAdjustment(gtk_range_get_adjustment(GTK_RANGE(m_pScrollbar)))
#endif
, m_pThicknessCssProvider(nullptr)
, m_nAdjustChangedSignalId(g_signal_connect(m_pAdjustment, "value-changed", G_CALLBACK(signalAdjustValueChanged), this))
{
#if GTK_CHECK_VERSION(4, 0, 0)
@ -8560,9 +8562,45 @@ public:
return ScrollType::Drag;
}
virtual int get_scroll_thickness() const override
{
if (gtk_orientable_get_orientation(GTK_ORIENTABLE(m_pScrollbar)) == GTK_ORIENTATION_HORIZONTAL)
return gtk_widget_get_allocated_height(GTK_WIDGET(m_pScrollbar));
return gtk_widget_get_allocated_width(GTK_WIDGET(m_pScrollbar));
}
virtual void set_scroll_thickness(int nThickness) override
{
GtkStyleContext *pStyleContext = gtk_widget_get_style_context(GTK_WIDGET(m_pScrollbar));
if (m_pThicknessCssProvider)
{
gtk_style_context_remove_provider(pStyleContext, GTK_STYLE_PROVIDER(m_pThicknessCssProvider));
m_pThicknessCssProvider = nullptr;
}
m_pThicknessCssProvider = gtk_css_provider_new();
int nSlider = nThickness > 6 ? nThickness - 6 : 1;
const OString sData = "slider { min-height: " + OString::number(nSlider) + "px;"
" min-width: " + OString::number(nSlider) + "px; }";
css_provider_load_from_data(m_pThicknessCssProvider, sData.getStr(), sData.getLength());
gtk_style_context_add_provider(pStyleContext, GTK_STYLE_PROVIDER(m_pThicknessCssProvider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
if (gtk_orientable_get_orientation(GTK_ORIENTABLE(m_pScrollbar)) == GTK_ORIENTATION_HORIZONTAL)
gtk_widget_set_size_request(GTK_WIDGET(m_pScrollbar), -1, nThickness);
else
gtk_widget_set_size_request(GTK_WIDGET(m_pScrollbar), nThickness, -1);
}
virtual ~GtkInstanceScrollbar() override
{
g_signal_handler_disconnect(m_pAdjustment, m_nAdjustChangedSignalId);
if (m_pThicknessCssProvider)
{
GtkStyleContext *pStyleContext = gtk_widget_get_style_context(GTK_WIDGET(m_pScrollbar));
gtk_style_context_remove_provider(pStyleContext, GTK_STYLE_PROVIDER(m_pThicknessCssProvider));
}
}
};