diff options
author | Caolán McNamara <caolanm@redhat.com> | 2019-01-24 09:14:59 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2019-01-29 11:02:08 +0100 |
commit | 36d5fd037439f84a688b96ec5af9e47d4a58712e (patch) | |
tree | 48aed258ecf578c0c4851f556143dd68acb0799c | |
parent | 13d62e9c6dec6ea90bb34b1dc4cc2aa52c4bea36 (diff) |
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/66849
Tested-by: Jenkins
Tested-by: Xisco Faulí <xiscofauli@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r-- | vcl/unx/gtk3/gtk3salnativewidgets-gtk.cxx | 53 |
1 files changed, 47 insertions, 6 deletions
diff --git a/vcl/unx/gtk3/gtk3salnativewidgets-gtk.cxx b/vcl/unx/gtk3/gtk3salnativewidgets-gtk.cxx index 9ed8d7c96dc3..ac3ab4f2975a 100644 --- a/vcl/unx/gtk3/gtk3salnativewidgets-gtk.cxx +++ b/vcl/unx/gtk3/gtk3salnativewidgets-gtk.cxx @@ -384,19 +384,37 @@ static GtkWidget* gTreeViewWidget; namespace { - void parent_styles_context_set_state(GtkStyleContext* context, GtkStateFlags flags) + void style_context_set_state(GtkStyleContext* context, GtkStateFlags flags) { - while ((context = gtk_style_context_get_parent(context))) + do { gtk_style_context_set_state(context, flags); } + while ((context = gtk_style_context_get_parent(context))); } - void style_context_set_state(GtkStyleContext* context, GtkStateFlags flags) + class StyleContextSave { - gtk_style_context_set_state(context, flags); - parent_styles_context_set_state(context, flags); - } + private: + std::vector<std::pair<GtkStyleContext*, GtkStateFlags>> m_aStates; + public: + void save(GtkStyleContext* context) + { + do + { + m_aStates.emplace_back(context, gtk_style_context_get_state(context)); + } + while ((context = gtk_style_context_get_parent(context))); + } + void restore() + { + for (auto a = m_aStates.rbegin(); a != m_aStates.rend(); ++a) + { + gtk_style_context_set_state(a->first, a->second); + } + m_aStates.clear(); + } + }; tools::Rectangle render_common(GtkStyleContext *pContext, cairo_t *cr, const tools::Rectangle &rIn, GtkStateFlags flags) { @@ -2406,6 +2424,8 @@ bool GtkSalGraphics::drawNativeControl( ControlType nType, ControlPart nPart, co long nWidth = rControlRegion.GetWidth(); long nHeight = rControlRegion.GetHeight(); + StyleContextSave aContextState; + aContextState.save(context); style_context_set_state(context, flags); if (styleClass) @@ -2561,6 +2581,7 @@ bool GtkSalGraphics::drawNativeControl( ControlType nType, ControlPart nPart, co { gtk_style_context_remove_class(context, styleClass); } + aContextState.restore(); cairo_destroy(cr); // unref @@ -2852,6 +2873,8 @@ vcl::Font pango_to_vcl(const PangoFontDescription* font, const css::lang::Locale void GtkSalGraphics::updateSettings( AllSettings& rSettings ) { GtkStyleContext* pStyle = gtk_widget_get_style_context( mpWindow ); + StyleContextSave aContextState; + aContextState.save(pStyle); GtkSettings* pSettings = gtk_widget_get_settings( mpWindow ); StyleSettings aStyleSet = rSettings.GetStyleSettings(); GdkRGBA color; @@ -2891,9 +2914,12 @@ void GtkSalGraphics::updateSettings( AllSettings& rSettings ) aTextColor = getColor( text_color ); aStyleSet.SetFieldRolloverTextColor( aTextColor ); + aContextState.restore(); + // button mouse over colors { GdkRGBA normal_button_rollover_text_color, pressed_button_rollover_text_color; + aContextState.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); @@ -2903,6 +2929,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 ); + aContextState.restore(); } // tooltip colors @@ -2987,6 +3014,8 @@ void GtkSalGraphics::updateSettings( AllSettings& rSettings ) aStyleSet.SetSkipDisabledInMenus( true ); aStyleSet.SetPreferredContextMenuShortcuts( false ); + aContextState.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 ); @@ -3026,47 +3055,59 @@ void GtkSalGraphics::updateSettings( AllSettings& rSettings ) ::Color aHighlightTextColor = getColor( color ); aStyleSet.SetMenuHighlightTextColor( aHighlightTextColor ); + aContextState.restore(); + // hyperlink colors + aContextState.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)); + aContextState.restore(); { GtkStyleContext *pCStyle = mpNotebookHeaderTabsTabLabelStyle; + aContextState.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())); + aContextState.restore(); } { GtkStyleContext *pCStyle = mpToolButtonStyle; + aContextState.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())); + aContextState.restore(); } // mouse over text colors { GtkStyleContext *pCStyle = mpNotebookHeaderTabsTabHoverLabelStyle; + aContextState.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); + aContextState.restore(); } { GtkStyleContext *pCStyle = mpNotebookHeaderTabsTabActiveLabelStyle; + aContextState.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); + aContextState.restore(); } // get cursor blink time |