From 67090e61d2fbaf1cb3f17d1c7f11b67eb5e710b4 Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Wed, 15 Nov 2023 20:31:24 -0800 Subject: [PATCH] Improve wxSystemSettings::GetMetric() scrollbar width calculation for GTK3 See #24057 --- src/gtk/settings.cpp | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/src/gtk/settings.cpp b/src/gtk/settings.cpp index d9245f9df5..e607474937 100644 --- a/src/gtk/settings.cpp +++ b/src/gtk/settings.cpp @@ -949,33 +949,45 @@ static GdkRectangle GetMonitorGeom(GdkWindow* window) } #endif +#ifdef __WXGTK3__ +static int GetNodeWidth(wxGtkStyleContext& sc) +{ + int width; + gtk_style_context_get(sc, GTK_STATE_FLAG_NORMAL, "min-width", &width, nullptr); + GtkBorder border; + gtk_style_context_get_padding(sc, GTK_STATE_FLAG_NORMAL, &border); + width += border.left + border.right; + gtk_style_context_get_border(sc, GTK_STATE_FLAG_NORMAL, &border); + width += border.left + border.right; + gtk_style_context_get_margin(sc, GTK_STATE_FLAG_NORMAL, &border); + width += border.left + border.right; + + return width < 0 ? 0 : width; +} +#endif // __WXGTK3__ + static int GetScrollbarWidth() { int width; #ifdef __WXGTK3__ if (wx_is_at_least_gtk3(20)) { - GtkBorder border; #if GTK_CHECK_VERSION(3,10,0) wxGtkStyleContext sc(gtk_widget_get_scale_factor(ScrollBarWidget())); #else wxGtkStyleContext sc; #endif sc.Add(GTK_TYPE_SCROLLBAR, "scrollbar", "scrollbar", "vertical", "right", nullptr); + width = GetNodeWidth(sc); - gtk_style_context_get_border(sc, GTK_STATE_FLAG_NORMAL, &border); + sc.Add("contents"); + width += GetNodeWidth(sc); - sc.Add("contents").Add("trough").Add("slider"); + sc.Add("trough"); + width += GetNodeWidth(sc); - gtk_style_context_get(sc, GTK_STATE_FLAG_NORMAL, "min-width", &width, nullptr); - width += border.left + border.right; - - gtk_style_context_get_border(sc, GTK_STATE_FLAG_NORMAL, &border); - width += border.left + border.right; - gtk_style_context_get_padding(sc, GTK_STATE_FLAG_NORMAL, &border); - width += border.left + border.right; - gtk_style_context_get_margin(sc, GTK_STATE_FLAG_NORMAL, &border); - width += border.left + border.right; + sc.Add("slider"); + width += GetNodeWidth(sc); } else #endif