fix invisible multi-line wxTextCtrl selection when custom foreground/background color is used with GTK3
closes #16176 git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_3_0_BRANCH@76308 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1801,6 +1801,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);
|
||||
}
|
||||
|
||||
|
@@ -4323,37 +4323,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;
|
||||
|
Reference in New Issue
Block a user