diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index 4d55279e38..914612edfc 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -1800,6 +1800,39 @@ bool wxTextCtrl::GetStyle(long position, wxTextAttr& style) void wxTextCtrl::DoApplyWidgetStyle(GtkRcStyle *style) { +#ifdef __WXGTK3__ + // Preserve selection colors, otherwise the GTK_STATE_FLAG_NORMAL override + // will be used, and the selection is invisible + const GtkStateFlags selectedFocused = + GtkStateFlags(GTK_STATE_FLAG_SELECTED | GTK_STATE_FLAG_FOCUSED); + // remove any previous override + gtk_widget_override_color(m_text, GTK_STATE_FLAG_NORMAL, NULL); + gtk_widget_override_color(m_text, selectedFocused, NULL); + gtk_widget_override_background_color(m_text, GTK_STATE_FLAG_NORMAL, NULL); + gtk_widget_override_background_color(m_text, selectedFocused, NULL); + const bool fg_ok = m_foregroundColour.IsOk(); + const bool bg_ok = m_backgroundColour.IsOk(); + if (fg_ok || bg_ok) + { + GdkRGBA fg_orig, bg_orig; + GtkStyleContext* context = gtk_widget_get_style_context(m_text); + if (IsMultiLine()) + { + gtk_style_context_save(context); + gtk_style_context_add_class(context, GTK_STYLE_CLASS_VIEW); + } + gtk_style_context_get_color(context, selectedFocused, &fg_orig); + gtk_style_context_get_background_color(context, selectedFocused, &bg_orig); + if (IsMultiLine()) + gtk_style_context_restore(context); + + if (fg_ok) + gtk_widget_override_color(m_text, selectedFocused, &fg_orig); + if (bg_ok) + gtk_widget_override_background_color(m_text, selectedFocused, &bg_orig); + } +#endif // __WXGTK3__ + GTKApplyStyle(m_text, style); } diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 895f1bb21d..b108b6929e 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -4310,37 +4310,13 @@ void wxWindowGTK::GTKApplyStyle(GtkWidget* widget, GtkRcStyle* WXUNUSED_IN_GTK3( if (m_font.IsOk()) pfd = m_font.GetNativeFontInfo()->description; gtk_widget_override_font(widget, pfd); - - const GdkRGBA* fg = m_foregroundColour; - const GdkRGBA* bg = m_backgroundColour; - GtkStyleContext* context = gtk_widget_get_style_context(widget); - // Preserve selection colors for GtkEntry, otherwise the - // GTK_STATE_FLAG_NORMAL override will be used, and the selection is invisible - if (GTK_IS_ENTRY(widget)) - { - const GtkStateFlags selectedFocused = - GtkStateFlags(GTK_STATE_FLAG_SELECTED | GTK_STATE_FLAG_FOCUSED); - // remove any previous override - gtk_widget_override_color(widget, selectedFocused, NULL); - gtk_widget_override_background_color(widget, selectedFocused, NULL); - GdkRGBA c; - if (fg) - { - gtk_style_context_get_color(context, selectedFocused, &c); - gtk_widget_override_color(widget, selectedFocused, &c); - } - if (bg) - { - gtk_style_context_get_background_color(context, selectedFocused, &c); - gtk_widget_override_background_color(widget, selectedFocused, &c); - } - } - gtk_widget_override_color(widget, GTK_STATE_FLAG_NORMAL, fg); - gtk_widget_override_background_color(widget, GTK_STATE_FLAG_NORMAL, bg); + gtk_widget_override_color(widget, GTK_STATE_FLAG_NORMAL, m_foregroundColour); + gtk_widget_override_background_color(widget, GTK_STATE_FLAG_NORMAL, m_backgroundColour); // setting background color has no effect with some themes when the widget style // has a "background-image" property, so we need to override that as well + GtkStyleContext* context = gtk_widget_get_style_context(widget); if (m_styleProvider) gtk_style_context_remove_provider(context, m_styleProvider); cairo_pattern_t* pattern = NULL;