cellview: Port to draw vfunc

This commit is contained in:
Benjamin Otte 2010-09-03 18:41:52 +02:00
parent 0a6b7e5759
commit ed996bcd68

View File

@ -73,8 +73,8 @@ static void gtk_cell_view_set_property (GObject *obj
static void gtk_cell_view_finalize (GObject *object); static void gtk_cell_view_finalize (GObject *object);
static void gtk_cell_view_size_allocate (GtkWidget *widget, static void gtk_cell_view_size_allocate (GtkWidget *widget,
GtkAllocation *allocation); GtkAllocation *allocation);
static gboolean gtk_cell_view_expose (GtkWidget *widget, static gboolean gtk_cell_view_draw (GtkWidget *widget,
GdkEventExpose *event); cairo_t *cr);
static void gtk_cell_view_set_value (GtkCellView *cell_view, static void gtk_cell_view_set_value (GtkCellView *cell_view,
GtkCellRenderer *renderer, GtkCellRenderer *renderer,
gchar *property, gchar *property,
@ -168,7 +168,7 @@ gtk_cell_view_class_init (GtkCellViewClass *klass)
gobject_class->set_property = gtk_cell_view_set_property; gobject_class->set_property = gtk_cell_view_set_property;
gobject_class->finalize = gtk_cell_view_finalize; gobject_class->finalize = gtk_cell_view_finalize;
widget_class->expose_event = gtk_cell_view_expose; widget_class->draw = gtk_cell_view_draw;
widget_class->size_allocate = gtk_cell_view_size_allocate; widget_class->size_allocate = gtk_cell_view_size_allocate;
/* properties */ /* properties */
@ -426,36 +426,30 @@ gtk_cell_view_size_allocate (GtkWidget *widget,
} }
static gboolean static gboolean
gtk_cell_view_expose (GtkWidget *widget, gtk_cell_view_draw (GtkWidget *widget,
GdkEventExpose *event) cairo_t *cr)
{ {
GtkAllocation allocation;
GList *list; GList *list;
GtkCellView *cellview; GtkCellView *cellview;
GdkRectangle area; GdkRectangle area;
GtkCellRendererState state; GtkCellRendererState state;
gboolean rtl = (gtk_widget_get_direction(widget) == GTK_TEXT_DIR_RTL); gboolean rtl = (gtk_widget_get_direction(widget) == GTK_TEXT_DIR_RTL);
GtkPackType packing; GtkPackType packing;
cairo_t *cr; int width;
cellview = GTK_CELL_VIEW (widget); cellview = GTK_CELL_VIEW (widget);
if (!gtk_widget_is_drawable (widget)) /* render cells */
return FALSE; area.x = 0;
area.y = 0;
gtk_widget_get_allocation (widget, &allocation); area.width = width = gtk_widget_get_allocated_width (widget);
cr = gdk_cairo_create (event->window); area.height = gtk_widget_get_allocated_height (widget);
gdk_cairo_region (cr, event->region);
cairo_clip (cr);
/* "blank" background */ /* "blank" background */
if (cellview->priv->background_set) if (cellview->priv->background_set)
{ {
gdk_cairo_rectangle (cr, &allocation); gdk_cairo_rectangle (cr, &area);
cairo_set_source_rgb (cr, gdk_cairo_set_source_color (cr, &cellview->priv->background);
cellview->priv->background.red / 65535.,
cellview->priv->background.green / 65535.,
cellview->priv->background.blue / 65535.);
cairo_fill (cr); cairo_fill (cr);
} }
@ -463,16 +457,7 @@ gtk_cell_view_expose (GtkWidget *widget,
if (cellview->priv->displayed_row) if (cellview->priv->displayed_row)
gtk_cell_view_set_cell_data (cellview); gtk_cell_view_set_cell_data (cellview);
else if (cellview->priv->model) else if (cellview->priv->model)
{
cairo_destroy (cr);
return FALSE; return FALSE;
}
/* render cells */
area = allocation;
/* we draw on our very own window, initialize x and y to zero */
area.y = allocation.y;
if (gtk_widget_get_state (widget) == GTK_STATE_PRELIGHT) if (gtk_widget_get_state (widget) == GTK_STATE_PRELIGHT)
state = GTK_CELL_RENDERER_PRELIT; state = GTK_CELL_RENDERER_PRELIT;
@ -484,9 +469,9 @@ gtk_cell_view_expose (GtkWidget *widget,
for (packing = GTK_PACK_START; packing <= GTK_PACK_END; ++packing) for (packing = GTK_PACK_START; packing <= GTK_PACK_END; ++packing)
{ {
if (packing == GTK_PACK_START) if (packing == GTK_PACK_START)
area.x = allocation.x + (rtl ? allocation.width : 0); area.x = rtl ? width : 0;
else else
area.x = rtl ? allocation.x : (allocation.x + allocation.width); area.x = rtl ? 0 : width;
for (list = cellview->priv->cell_list; list; list = list->next) for (list = cellview->priv->cell_list; list; list = list->next)
{ {
@ -521,8 +506,6 @@ gtk_cell_view_expose (GtkWidget *widget,
} }
} }
cairo_destroy (cr);
return FALSE; return FALSE;
} }