[Libreoffice-commits] core.git: Branch 'libreoffice-6-2' - vcl/unx

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Jan 25 08:31:00 UTC 2019


 vcl/unx/gtk3/gtk3salnativewidgets-gtk.cxx |   55 ++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)

New commits:
commit c7d36095c8e7205d9b9ef3e43728c36f027b457c
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Thu Jan 24 09:14:59 2019 +0000
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Fri Jan 25 09:30:24 2019 +0100

    Resolves: tdf#122662 restore context after changing state
    
    otherwise we may change a context which get reused by gtk for rendering
    something we don't ourselves draw directly
    
    Change-Id: I814140cd63489f7e4fac47a7486a006a4aa1fac5
    Reviewed-on: https://gerrit.libreoffice.org/66848
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>

diff --git a/vcl/unx/gtk3/gtk3salnativewidgets-gtk.cxx b/vcl/unx/gtk3/gtk3salnativewidgets-gtk.cxx
index 769cba86243d..e31f647ae471 100644
--- a/vcl/unx/gtk3/gtk3salnativewidgets-gtk.cxx
+++ b/vcl/unx/gtk3/gtk3salnativewidgets-gtk.cxx
@@ -395,12 +395,40 @@ namespace
         }
     }
 
+    void parent_styles_context_save(GtkStyleContext* context)
+    {
+        while ((context = gtk_style_context_get_parent(context)))
+        {
+            gtk_style_context_save(context);
+        }
+    }
+
+    void parent_styles_context_restore(GtkStyleContext* context)
+    {
+        while ((context = gtk_style_context_get_parent(context)))
+        {
+            gtk_style_context_restore(context);
+        }
+    }
+
     void style_context_set_state(GtkStyleContext* context, GtkStateFlags flags)
     {
         gtk_style_context_set_state(context, flags);
         parent_styles_context_set_state(context, flags);
     }
 
+    void style_context_save(GtkStyleContext* context)
+    {
+        gtk_style_context_save(context);
+        parent_styles_context_save(context);
+    }
+
+    void style_context_restore(GtkStyleContext* context)
+    {
+        gtk_style_context_restore(context);
+        parent_styles_context_restore(context);
+    }
+
     tools::Rectangle render_common(GtkStyleContext *pContext, cairo_t *cr, const tools::Rectangle &rIn, GtkStateFlags flags)
     {
         if (!pContext)
@@ -2491,6 +2519,7 @@ bool GtkSalGraphics::drawNativeControl( ControlType nType, ControlPart nPart, co
     long nWidth = rControlRegion.GetWidth();
     long nHeight = rControlRegion.GetHeight();
 
+    style_context_save(context);
     style_context_set_state(context, flags);
 
     if (styleClass)
@@ -2625,6 +2654,7 @@ bool GtkSalGraphics::drawNativeControl( ControlType nType, ControlPart nPart, co
     {
         gtk_style_context_remove_class(context, styleClass);
     }
+    style_context_restore(context);
 
     cairo_destroy(cr); // unref
 
@@ -2929,6 +2959,7 @@ void GtkSalGraphics::updateSettings(AllSettings& rSettings)
     }
 
     GtkStyleContext* pStyle = gtk_widget_get_style_context( mpWindow );
+    style_context_save(pStyle);
     GtkSettings* pSettings = gtk_widget_get_settings( mpWindow );
     StyleSettings aStyleSet = rSettings.GetStyleSettings();
     GdkRGBA color;
@@ -2968,9 +2999,12 @@ void GtkSalGraphics::updateSettings(AllSettings& rSettings)
     aTextColor = getColor( text_color );
     aStyleSet.SetFieldRolloverTextColor( aTextColor );
 
+    style_context_restore(pStyle);
+
     // button mouse over colors
     {
         GdkRGBA normal_button_rollover_text_color, pressed_button_rollover_text_color;
+        style_context_save(mpButtonStyle);
         style_context_set_state(mpButtonStyle, GTK_STATE_FLAG_PRELIGHT);
         gtk_style_context_get_color(mpButtonStyle, gtk_style_context_get_state(mpButtonStyle), &normal_button_rollover_text_color);
         aTextColor = getColor(normal_button_rollover_text_color);
@@ -2980,6 +3014,7 @@ void GtkSalGraphics::updateSettings(AllSettings& rSettings)
         aTextColor = getColor(pressed_button_rollover_text_color);
         style_context_set_state(mpButtonStyle, GTK_STATE_FLAG_NORMAL);
         aStyleSet.SetButtonPressedRolloverTextColor( aTextColor );
+        style_context_restore(mpButtonStyle);
     }
 
     // tooltip colors
@@ -3064,6 +3099,11 @@ void GtkSalGraphics::updateSettings(AllSettings& rSettings)
     aStyleSet.SetSkipDisabledInMenus( true );
     aStyleSet.SetPreferredContextMenuShortcuts( false );
 
+    style_context_save(mpMenuStyle);
+    style_context_save(mpMenuBarStyle);
+    style_context_save(mpMenuBarItemStyle);
+    style_context_save(mpMenuItemLabelStyle);
+
     // menu colors
     style_context_set_state(mpMenuStyle, GTK_STATE_FLAG_NORMAL);
     gtk_style_context_get_background_color( mpMenuStyle, gtk_style_context_get_state(mpMenuStyle), &background_color );
@@ -3103,47 +3143,62 @@ void GtkSalGraphics::updateSettings(AllSettings& rSettings)
     ::Color aHighlightTextColor = getColor( color );
     aStyleSet.SetMenuHighlightTextColor( aHighlightTextColor );
 
+    style_context_restore(mpMenuItemLabelStyle);
+    style_context_restore(mpMenuBarItemStyle);
+    style_context_restore(mpMenuBarStyle);
+    style_context_restore(mpMenuStyle);
+
     // hyperlink colors
+    style_context_save(mpLinkButtonStyle);
     style_context_set_state(mpLinkButtonStyle, GTK_STATE_FLAG_LINK);
     gtk_style_context_get_color(mpLinkButtonStyle, gtk_style_context_get_state(mpLinkButtonStyle), &text_color);
     aStyleSet.SetLinkColor(getColor(text_color));
     style_context_set_state(mpLinkButtonStyle, GTK_STATE_FLAG_VISITED);
     gtk_style_context_get_color(mpLinkButtonStyle, gtk_style_context_get_state(mpLinkButtonStyle), &text_color);
     aStyleSet.SetVisitedLinkColor(getColor(text_color));
+    style_context_restore(mpLinkButtonStyle);
 
     {
         GtkStyleContext *pCStyle = mpNotebookHeaderTabsTabLabelStyle;
+        style_context_save(pCStyle);
         style_context_set_state(pCStyle, GTK_STATE_FLAG_NORMAL);
         gtk_style_context_get_color(pCStyle, gtk_style_context_get_state(pCStyle), &text_color);
         aTextColor = getColor( text_color );
         aStyleSet.SetTabTextColor(aTextColor);
         aStyleSet.SetTabFont(getFont(mpNotebookHeaderTabsTabLabelStyle, rSettings.GetUILanguageTag().getLocale()));
+        style_context_restore(pCStyle);
     }
 
     {
         GtkStyleContext *pCStyle = mpToolButtonStyle;
+        style_context_save(pCStyle);
         style_context_set_state(pCStyle, GTK_STATE_FLAG_NORMAL);
         gtk_style_context_get_color(pCStyle, gtk_style_context_get_state(pCStyle), &text_color);
         aTextColor = getColor( text_color );
         aStyleSet.SetToolTextColor(aTextColor);
         aStyleSet.SetToolFont(getFont(mpToolButtonStyle, rSettings.GetUILanguageTag().getLocale()));
+        style_context_restore(pCStyle);
     }
 
     // mouse over text colors
     {
         GtkStyleContext *pCStyle = mpNotebookHeaderTabsTabHoverLabelStyle;
+        style_context_save(pCStyle);
         style_context_set_state(pCStyle, GTK_STATE_FLAG_PRELIGHT);
         gtk_style_context_get_color(pCStyle, gtk_style_context_get_state(pCStyle), &text_color);
         aTextColor = getColor( text_color );
         aStyleSet.SetTabRolloverTextColor(aTextColor);
+        style_context_restore(pCStyle);
     }
 
     {
         GtkStyleContext *pCStyle = mpNotebookHeaderTabsTabActiveLabelStyle;
+        style_context_save(pCStyle);
         style_context_set_state(pCStyle, ACTIVE_TAB());
         gtk_style_context_get_color(pCStyle, gtk_style_context_get_state(pCStyle), &text_color);
         aTextColor = getColor( text_color );
         aStyleSet.SetTabHighlightTextColor(aTextColor);
+        style_context_restore(pCStyle);
     }
 
     // get cursor blink time


More information about the Libreoffice-commits mailing list