Merge pull request #414 from sevoku/fix-treeview-background-color

[GTK] fix treeview background setting
This commit is contained in:
Lluis Sanchez 2015-01-17 09:23:36 +01:00
Родитель 0c1bcf5d0f 2bf3d42249
Коммит cf8fa466fe
4 изменённых файлов: 46 добавлений и 1 удалений

Просмотреть файл

@ -16,6 +16,7 @@ namespace Samples
{
PackStart (new Label ("The listview should have a red background"));
ListView list = new ListView ();
list.BackgroundColor = Colors.Red;
list.GridLinesVisible = GridLines.Both;
ListStore store = new ListStore (name, icon, text, icon2, progress);
list.DataSource = store;

Просмотреть файл

@ -113,9 +113,24 @@ namespace Xwt.GtkBackend
GtkWorkarounds.FixContainerLeak (c);
}
public static Xwt.Drawing.Color GetBackgroundColor (this Gtk.Widget widget)
{
return widget.GetBackgroundColor (Gtk.StateType.Normal);
}
public static Xwt.Drawing.Color GetBackgroundColor (this Gtk.Widget widget, Gtk.StateType state)
{
return widget.Style.Background (state).ToXwtValue ();
}
public static void SetBackgroundColor (this Gtk.Widget widget, Xwt.Drawing.Color color)
{
widget.ModifyBg (Gtk.StateType.Normal, color.ToGtkValue ());
widget.SetBackgroundColor (Gtk.StateType.Normal, color);
}
public static void SetBackgroundColor (this Gtk.Widget widget, Gtk.StateType state, Xwt.Drawing.Color color)
{
widget.ModifyBg (state, color.ToGtkValue ());
}
public static void SetChildBackgroundColor (this Gtk.Container container, Xwt.Drawing.Color color)

Просмотреть файл

@ -110,6 +110,21 @@ namespace Xwt.GtkBackend
return;
}
public static Xwt.Drawing.Color GetBackgroundColor (this Gtk.Widget widget)
{
return widget.GetBackgroundColor (Gtk.StateFlags.Normal);
}
public static Xwt.Drawing.Color GetBackgroundColor (this Gtk.Widget widget, Gtk.StateType state)
{
return widget.GetBackgroundColor (state.ToGtk3StateFlags ());
}
public static Xwt.Drawing.Color GetBackgroundColor (this Gtk.Widget widget, Gtk.StateFlags state)
{
return widget.StyleContext.GetBackgroundColor (state).ToXwtValue ();
}
public static void SetBackgroundColor (this Gtk.Widget widget, Xwt.Drawing.Color color)
{
widget.SetBackgroundColor (Gtk.StateFlags.Normal, color);

Просмотреть файл

@ -44,6 +44,15 @@ namespace Xwt.GtkBackend
public Gtk.TreeViewColumn Column;
}
protected override void OnSetBackgroundColor (Xwt.Drawing.Color color)
{
// Gtk3 workaround (by rpc-scandinavia, see https://github.com/mono/xwt/pull/411)
var selectedColor = Widget.GetBackgroundColor(StateType.Selected);
Widget.SetBackgroundColor (StateType.Normal, Xwt.Drawing.Colors.Transparent);
Widget.SetBackgroundColor (StateType.Selected, selectedColor);
base.OnSetBackgroundColor (color);
}
public TableViewBackend ()
{
var sw = new Gtk.ScrolledWindow ();
@ -225,6 +234,11 @@ namespace Xwt.GtkBackend
#region ICellRendererTarget implementation
public void PackStart (object target, Gtk.CellRenderer cr, bool expand)
{
#if !XWT_GTK3
// Gtk2 tree background color workaround
if (UsingCustomBackgroundColor)
cr.CellBackgroundGdk = BackgroundColor.ToGtkValue ();
#endif
((Gtk.TreeViewColumn)target).PackStart (cr, expand);
}