treeview: Draw lines with Cairo

This commit is contained in:
Benjamin Otte 2010-07-15 05:04:46 +02:00
parent 8dd3317502
commit da426ec97c
2 changed files with 62 additions and 51 deletions

View File

@ -245,10 +245,12 @@ struct _GtkTreeViewPrivate
/* Grid and tree lines */ /* Grid and tree lines */
GtkTreeViewGridLines grid_lines; GtkTreeViewGridLines grid_lines;
GdkGC *grid_line_gc; double grid_line_dashes[2];
int grid_line_width;
gboolean tree_lines_enabled; gboolean tree_lines_enabled;
GdkGC *tree_line_gc; double tree_line_dashes[2];
int tree_line_width;
/* Row separators */ /* Row separators */
GtkTreeViewRowSeparatorFunc row_separator_func; GtkTreeViewRowSeparatorFunc row_separator_func;

View File

@ -1944,18 +1944,6 @@ gtk_tree_view_unrealize (GtkWidget *widget)
priv->drag_highlight_window = NULL; priv->drag_highlight_window = NULL;
} }
if (priv->tree_line_gc)
{
g_object_unref (priv->tree_line_gc);
priv->tree_line_gc = NULL;
}
if (priv->grid_line_gc)
{
g_object_unref (priv->grid_line_gc);
priv->grid_line_gc = NULL;
}
GTK_WIDGET_CLASS (gtk_tree_view_parent_class)->unrealize (widget); GTK_WIDGET_CLASS (gtk_tree_view_parent_class)->unrealize (widget);
} }
@ -4236,27 +4224,44 @@ gtk_tree_view_draw_line (GtkTreeView *tree_view,
int x2, int x2,
int y2) int y2)
{ {
GdkGC *gc; cairo_t *cr;
int line_width;
cr = gdk_cairo_create (window);
switch (type) switch (type)
{ {
case GTK_TREE_VIEW_TREE_LINE: case GTK_TREE_VIEW_TREE_LINE:
gc = tree_view->priv->tree_line_gc; cairo_set_source_rgb (cr, 0, 0, 0);
cairo_set_line_width (cr, tree_view->priv->tree_line_width);
if (tree_view->priv->tree_line_dashes[0])
cairo_set_dash (cr,
tree_view->priv->tree_line_dashes,
2, 0.5);
break; break;
case GTK_TREE_VIEW_GRID_LINE: case GTK_TREE_VIEW_GRID_LINE:
gc = tree_view->priv->grid_line_gc; cairo_set_source_rgb (cr, 0, 0, 0);
cairo_set_line_width (cr, tree_view->priv->grid_line_width);
if (tree_view->priv->grid_line_dashes[0])
cairo_set_dash (cr,
tree_view->priv->grid_line_dashes,
2, 0.5);
break; break;
default: default:
g_assert_not_reached (); g_assert_not_reached ();
/* fall through */ /* fall through */
case GTK_TREE_VIEW_FOREGROUND_LINE: case GTK_TREE_VIEW_FOREGROUND_LINE:
gc = GTK_WIDGET (tree_view)->style->fg_gc[gtk_widget_get_state (GTK_WIDGET (tree_view))]; cairo_set_line_width (cr, 1.0);
gdk_cairo_set_source_color (cr,
&GTK_WIDGET (tree_view)->style->fg[gtk_widget_get_state (GTK_WIDGET (tree_view))]);
break; break;
} }
gdk_draw_line (window, gc, cairo_move_to (cr, x1 + 0.5, y1 + 0.5);
x1, y1, cairo_line_to (cr, x2 + 0.5, y2 + 0.5);
x2, y2); cairo_stroke (cr);
cairo_destroy (cr);
} }
static void static void
@ -15166,32 +15171,34 @@ gtk_tree_view_set_grid_lines (GtkTreeView *tree_view,
if (gtk_widget_get_realized (widget)) if (gtk_widget_get_realized (widget))
{ {
if (grid_lines == GTK_TREE_VIEW_GRID_LINES_NONE && if (grid_lines == GTK_TREE_VIEW_GRID_LINES_NONE &&
priv->grid_line_gc) priv->grid_line_width)
{ {
g_object_unref (priv->grid_line_gc); priv->grid_line_width = 0;
priv->grid_line_gc = NULL;
} }
if (grid_lines != GTK_TREE_VIEW_GRID_LINES_NONE && if (grid_lines != GTK_TREE_VIEW_GRID_LINES_NONE &&
!priv->grid_line_gc) !priv->grid_line_width)
{ {
gint line_width;
gint8 *dash_list; gint8 *dash_list;
gtk_widget_style_get (widget, gtk_widget_style_get (widget,
"grid-line-width", &line_width, "grid-line-width", &priv->grid_line_width,
"grid-line-pattern", (gchar *)&dash_list, "grid-line-pattern", (gchar *)&dash_list,
NULL); NULL);
priv->grid_line_gc = gdk_gc_new (widget->window); if (dash_list)
gdk_gc_copy (priv->grid_line_gc, widget->style->black_gc); {
priv->grid_line_dashes[0] = dash_list[0];
gdk_gc_set_line_attributes (priv->grid_line_gc, line_width, if (dash_list[0])
GDK_LINE_ON_OFF_DASH, priv->grid_line_dashes[1] = dash_list[1];
GDK_CAP_BUTT, GDK_JOIN_MITER);
gdk_gc_set_dashes (priv->grid_line_gc, 0, dash_list, 2); g_free (dash_list);
}
g_free (dash_list); else
{
priv->grid_line_dashes[0] = 1;
priv->grid_line_dashes[1] = 1;
}
} }
} }
@ -15253,30 +15260,32 @@ gtk_tree_view_set_enable_tree_lines (GtkTreeView *tree_view,
if (gtk_widget_get_realized (widget)) if (gtk_widget_get_realized (widget))
{ {
if (!enabled && priv->tree_line_gc) if (!enabled && priv->tree_line_width)
{ {
g_object_unref (priv->tree_line_gc); priv->tree_line_width = 0;
priv->tree_line_gc = NULL;
} }
if (enabled && !priv->tree_line_gc) if (enabled && !priv->tree_line_width)
{ {
gint line_width;
gint8 *dash_list; gint8 *dash_list;
gtk_widget_style_get (widget, gtk_widget_style_get (widget,
"tree-line-width", &line_width, "tree-line-width", &priv->tree_line_width,
"tree-line-pattern", (gchar *)&dash_list, "tree-line-pattern", (gchar *)&dash_list,
NULL); NULL);
priv->tree_line_gc = gdk_gc_new (widget->window); if (dash_list)
gdk_gc_copy (priv->tree_line_gc, widget->style->black_gc); {
priv->tree_line_dashes[0] = dash_list[0];
gdk_gc_set_line_attributes (priv->tree_line_gc, line_width, if (dash_list[0])
GDK_LINE_ON_OFF_DASH, priv->tree_line_dashes[1] = dash_list[1];
GDK_CAP_BUTT, GDK_JOIN_MITER);
gdk_gc_set_dashes (priv->tree_line_gc, 0, dash_list, 2); g_free (dash_list);
}
g_free (dash_list); else
{
priv->tree_line_dashes[0] = 1;
priv->tree_line_dashes[1] = 1;
}
} }
} }