[evolution/gtk3: 2/10] Adapt GnomeCanvas to latest gtk+-3.0 API.



commit 616b9db80005a0dd4eb0c03dfd25f8120d165246
Author: Matthew Barnes <mbarnes redhat com>
Date:   Tue Nov 9 08:41:52 2010 -0500

    Adapt GnomeCanvas to latest gtk+-3.0 API.

 libgnomecanvas/gnome-canvas-marshal.list |    2 +-
 libgnomecanvas/gnome-canvas-rich-text.c  |   29 ++--
 libgnomecanvas/gnome-canvas.c            |  296 ++++++++++++++----------------
 libgnomecanvas/gnome-canvas.h            |    4 +-
 4 files changed, 156 insertions(+), 175 deletions(-)
---
diff --git a/libgnomecanvas/gnome-canvas-marshal.list b/libgnomecanvas/gnome-canvas-marshal.list
index 5ad61bf..c2f9657 100644
--- a/libgnomecanvas/gnome-canvas-marshal.list
+++ b/libgnomecanvas/gnome-canvas-marshal.list
@@ -1,2 +1,2 @@
-VOID:OBJECT,INT,INT,INT,INT
+VOID:BOXED,INT,INT,INT,INT
 BOOLEAN:BOXED
diff --git a/libgnomecanvas/gnome-canvas-rich-text.c b/libgnomecanvas/gnome-canvas-rich-text.c
index 16fa5dc..cdfc5f0 100644
--- a/libgnomecanvas/gnome-canvas-rich-text.c
+++ b/libgnomecanvas/gnome-canvas-rich-text.c
@@ -125,7 +125,7 @@ static GnomeCanvasItem * gnome_canvas_rich_text_point (GnomeCanvasItem *item,
                                                        gdouble x, gdouble y,
                                                        gint cx, gint cy);
 static void gnome_canvas_rich_text_draw (GnomeCanvasItem *item,
-					GdkDrawable *drawable,
+					cairo_t *cr,
 					gint x, gint y, gint width, gint height);
 static gint gnome_canvas_rich_text_event (GnomeCanvasItem *item,
 					 GdkEvent *event);
@@ -2032,25 +2032,29 @@ gnome_canvas_rich_text_point (GnomeCanvasItem *item, gdouble x, gdouble y,
 } /* gnome_canvas_rich_text_point */
 
 static void
-gnome_canvas_rich_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
-			    gint x, gint y, gint width, gint height)
+gnome_canvas_rich_text_draw (GnomeCanvasItem *item,
+                             cairo_t *cr,
+                             gint x,
+                             gint y,
+                             gint width,
+                             gint height)
 {
 	GnomeCanvasRichText *text = GNOME_CANVAS_RICH_TEXT (item);
 	GtkStyle *style;
 	GtkWidget *widget;
-        cairo_matrix_t i2c;
+	cairo_matrix_t i2c;
 	gdouble ax, ay, ax2, ay2;
 	gint x1, y1, x2, y2;
 
-        gnome_canvas_item_i2c_matrix (item, &i2c);
+	gnome_canvas_item_i2c_matrix (item, &i2c);
 
 	ax = text->_priv->x;
 	ay = text->_priv->y;
 	ax2 = ax + text->_priv->width;
 	ay2 = ay + text->_priv->height;
 
-        cairo_matrix_transform_point (&i2c, &ax, &ay);
-        cairo_matrix_transform_point (&i2c, &ax2, &ay2);
+	cairo_matrix_transform_point (&i2c, &ax, &ay);
+	cairo_matrix_transform_point (&i2c, &ax2, &ay2);
 
 	x1 = ax;
 	y1 = ay;
@@ -2062,15 +2066,8 @@ gnome_canvas_rich_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
 	widget = GTK_WIDGET (item->canvas);
 	style = gtk_widget_get_style (widget);
 
-        /* FIXME: should last arg be NULL? */
-	gtk_text_layout_draw (
-		text->_priv->layout,
-		widget,
-		drawable,
-		style->text_gc[GTK_STATE_NORMAL],
-		x - x1, y - y1,
-		0, 0, (x2 - x1) - (x - x1), (y2 - y1) - (y - y1),
-		NULL);
+	/* FIXME: should last arg be NULL? */
+	gtk_text_layout_draw (text->_priv->layout, widget, cr, NULL);
 } /* gnome_canvas_rich_text_draw */
 
 #if 0
diff --git a/libgnomecanvas/gnome-canvas.c b/libgnomecanvas/gnome-canvas.c
index cd2ffaa..a03cf0f 100644
--- a/libgnomecanvas/gnome-canvas.c
+++ b/libgnomecanvas/gnome-canvas.c
@@ -84,6 +84,7 @@
 #include <stdio.h>
 #include <gdk/gdkprivate.h>
 #include <gtk/gtk.h>
+#include <cairo/cairo-gobject.h>
 #include "gailcanvas.h"
 #include "gnome-canvas.h"
 #include "gnome-canvas-i18n.h"
@@ -1200,7 +1201,7 @@ static void   gnome_canvas_group_unrealize   (GnomeCanvasItem *item);
 static void   gnome_canvas_group_map         (GnomeCanvasItem *item);
 static void   gnome_canvas_group_unmap       (GnomeCanvasItem *item);
 static void   gnome_canvas_group_draw        (GnomeCanvasItem *item,
-					      GdkDrawable *drawable,
+					      cairo_t *cr,
 					      gint x, gint y,
 					      gint width, gint height);
 static GnomeCanvasItem *gnome_canvas_group_point (GnomeCanvasItem *item,
@@ -1487,8 +1488,12 @@ gnome_canvas_group_unmap (GnomeCanvasItem *item)
 
 /* Draw handler for canvas groups */
 static void
-gnome_canvas_group_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
-			 gint x, gint y, gint width, gint height)
+gnome_canvas_group_draw (GnomeCanvasItem *item,
+                         cairo_t *cr,
+                         gint x,
+                         gint y,
+                         gint width,
+                         gint height)
 {
 	GnomeCanvasGroup *group;
 	GList *list;
@@ -1509,9 +1514,8 @@ gnome_canvas_group_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
 			&& (child->y1 < child->canvas->redraw_y2)
 			&& (child->x2 > child->canvas->redraw_x1)
 			&& (child->y2 > child->canvas->redraw_y2)))
-			if (GNOME_CANVAS_ITEM_GET_CLASS (child)->draw)
-				(* GNOME_CANVAS_ITEM_GET_CLASS (child)->draw) (
-					child, drawable, x, y, width, height);
+			GNOME_CANVAS_ITEM_GET_CLASS (child)->draw (
+				child, cr, x, y, width, height);
 	}
 }
 
@@ -1687,12 +1691,12 @@ static void gnome_canvas_realize             (GtkWidget        *widget);
 static void gnome_canvas_unrealize           (GtkWidget        *widget);
 static void gnome_canvas_size_allocate       (GtkWidget        *widget,
 					      GtkAllocation    *allocation);
+static gint gnome_canvas_draw                (GtkWidget        *widget,
+					      cairo_t          *cr);
 static gint gnome_canvas_button              (GtkWidget        *widget,
 					      GdkEventButton   *event);
 static gint gnome_canvas_motion              (GtkWidget        *widget,
 					      GdkEventMotion   *event);
-static gint gnome_canvas_expose              (GtkWidget        *widget,
-					      GdkEventExpose   *event);
 static gboolean gnome_canvas_key             (GtkWidget        *widget,
 					      GdkEventKey      *event);
 static gint gnome_canvas_crossing            (GtkWidget        *widget,
@@ -1703,11 +1707,11 @@ static gint gnome_canvas_focus_out           (GtkWidget        *widget,
 					      GdkEventFocus    *event);
 static void gnome_canvas_request_update_real (GnomeCanvas      *canvas);
 static void gnome_canvas_draw_background     (GnomeCanvas      *canvas,
-					      GdkDrawable      *drawable,
-					      gint               x,
-					      gint               y,
-					      gint               width,
-					      gint               height);
+					      cairo_t          *cr,
+					      gint              x,
+					      gint              y,
+					      gint              width,
+					      gint              height);
 
 static GtkLayoutClass *canvas_parent_class;
 
@@ -1718,6 +1722,68 @@ enum {
 	PROP_FOCUSED_ITEM,
 };
 
+static void
+gnome_canvas_paint_rect (GnomeCanvas *canvas,
+                         cairo_t *cr,
+                         gint x0,
+                         gint y0,
+                         gint x1,
+                         gint y1)
+{
+	GtkWidget *widget;
+	GtkLayout *layout;
+	GdkWindow *bin_window;
+	GtkAllocation allocation;
+	GtkAdjustment *hadjustment;
+	GtkAdjustment *vadjustment;
+	gint draw_x1, draw_y1;
+	gint draw_x2, draw_y2;
+	gint draw_width, draw_height;
+	gdouble hadjustment_value;
+	gdouble vadjustment_value;
+
+	g_return_if_fail (!canvas->need_update);
+
+	widget = GTK_WIDGET (canvas);
+	gtk_widget_get_allocation (widget, &allocation);
+
+	layout = GTK_LAYOUT (canvas);
+	bin_window = gtk_layout_get_bin_window (layout);
+	hadjustment = gtk_layout_get_hadjustment (layout);
+	vadjustment = gtk_layout_get_vadjustment (layout);
+
+	hadjustment_value = gtk_adjustment_get_value (hadjustment);
+	vadjustment_value = gtk_adjustment_get_value (vadjustment);
+
+	draw_x1 = MAX (x0, hadjustment_value - canvas->zoom_xofs);
+	draw_y1 = MAX (y0, vadjustment_value - canvas->zoom_yofs);
+	draw_x2 = MIN (draw_x1 + allocation.width, x1);
+	draw_y2 = MIN (draw_y1 + allocation.height, y1);
+
+	draw_width = draw_x2 - draw_x1;
+	draw_height = draw_y2 - draw_y1;
+
+	if (draw_width < 1 || draw_height < 1)
+		return;
+
+	canvas->redraw_x1 = draw_x1;
+	canvas->redraw_y1 = draw_y1;
+	canvas->redraw_x2 = draw_x2;
+	canvas->redraw_y2 = draw_y2;
+	canvas->draw_xofs = draw_x1;
+	canvas->draw_yofs = draw_y1;
+
+	g_signal_emit (
+		canvas, canvas_signals[DRAW_BACKGROUND], 0, cr,
+		draw_x1, draw_y1, draw_width, draw_height);
+
+	if (canvas->root->flags & GNOME_CANVAS_ITEM_VISIBLE)
+		(* GNOME_CANVAS_ITEM_GET_CLASS (canvas->root)->draw) (
+			canvas->root, cr,
+			draw_x1, draw_y1,
+			draw_width, draw_height);
+}
+
 /**
  * gnome_canvas_get_type:
  *
@@ -1805,10 +1871,10 @@ gnome_canvas_class_init (GnomeCanvasClass *klass)
 	widget_class->realize = gnome_canvas_realize;
 	widget_class->unrealize = gnome_canvas_unrealize;
 	widget_class->size_allocate = gnome_canvas_size_allocate;
+	widget_class->draw = gnome_canvas_draw;
 	widget_class->button_press_event = gnome_canvas_button;
 	widget_class->button_release_event = gnome_canvas_button;
 	widget_class->motion_notify_event = gnome_canvas_motion;
-	widget_class->expose_event = gnome_canvas_expose;
 	widget_class->key_press_event = gnome_canvas_key;
 	widget_class->key_release_event = gnome_canvas_key;
 	widget_class->enter_notify_event = gnome_canvas_crossing;
@@ -1830,8 +1896,8 @@ gnome_canvas_class_init (GnomeCanvasClass *klass)
 			      G_SIGNAL_RUN_LAST,
 			      G_STRUCT_OFFSET (GnomeCanvasClass, draw_background),
 			      NULL, NULL,
-			      gnome_canvas_marshal_VOID__OBJECT_INT_INT_INT_INT,
-			      G_TYPE_NONE, 5, GDK_TYPE_DRAWABLE,
+			      gnome_canvas_marshal_VOID__BOXED_INT_INT_INT_INT,
+			      G_TYPE_NONE, 5, CAIRO_GOBJECT_TYPE_CONTEXT,
 			      G_TYPE_INT, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT);
 
 	gail_canvas_init ();
@@ -2196,6 +2262,56 @@ gnome_canvas_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
 	g_object_thaw_notify (G_OBJECT (vadjustment));
 }
 
+static gboolean
+gnome_canvas_draw (GtkWidget *widget,
+                   cairo_t *cr)
+{
+	GnomeCanvas *canvas;
+	cairo_rectangle_list_t *list;
+	gint i;
+
+	canvas = GNOME_CANVAS (widget);
+
+	if (!gtk_widget_is_drawable (widget))
+		return FALSE;
+
+#ifdef VERBOSE
+	g_print ("Expose\n");
+#endif
+
+	list = cairo_copy_clip_rectangle_list (cr);
+
+	for (i = 0; i < list->num_rectangles; i++) {
+		cairo_rectangle_t rect;
+
+		rect.x = list->rectangles[i].x - canvas->zoom_xofs;
+		rect.y = list->rectangles[i].y - canvas->zoom_yofs;
+		rect.width = list->rectangles[i].width;
+		rect.height = list->rectangles[i].height;
+
+		if (canvas->need_update) {
+			gnome_canvas_request_redraw (canvas,
+                                                     rect.x, rect.y,
+                                                     rect.x + rect.width,
+                                                     rect.y + rect.height);
+		} else {
+			/* No pending updates, draw exposed area immediately */
+			gnome_canvas_paint_rect (canvas, cr,
+                                                 rect.x, rect.y,
+                                                 rect.x + rect.width,
+                                                 rect.y + rect.height);
+
+			/* And call expose on parent container class */
+			GTK_WIDGET_CLASS (canvas_parent_class)->
+				draw (widget, cr);
+		}
+	}
+
+	cairo_rectangle_list_destroy (list);
+
+	return FALSE;
+}
+
 /* Emits an event for an item in the canvas, be it the current item, grabbed
  * item, or focused item, as appropriate.
  */
@@ -2664,151 +2780,19 @@ gnome_canvas_focus_out (GtkWidget *widget, GdkEventFocus *event)
 		return FALSE;
 }
 
-#define REDRAW_QUANTUM_SIZE 512
-
-static void
-gnome_canvas_paint_rect (GnomeCanvas *canvas, gint x0, gint y0, gint x1, gint y1)
-{
-	GtkWidget *widget;
-	GtkLayout *layout;
-	GdkWindow *bin_window;
-	GtkAllocation allocation;
-	GtkAdjustment *hadjustment;
-	GtkAdjustment *vadjustment;
-	gint draw_x1, draw_y1;
-	gint draw_x2, draw_y2;
-	gint draw_width, draw_height;
-	gdouble hadjustment_value;
-	gdouble vadjustment_value;
-        GdkPixmap *pixmap;
-        cairo_t *cr;
-
-	g_return_if_fail (!canvas->need_update);
-
-	widget = GTK_WIDGET (canvas);
-	gtk_widget_get_allocation (widget, &allocation);
-
-	layout = GTK_LAYOUT (canvas);
-	bin_window = gtk_layout_get_bin_window (layout);
-	hadjustment = gtk_layout_get_hadjustment (layout);
-	vadjustment = gtk_layout_get_vadjustment (layout);
-
-	hadjustment_value = gtk_adjustment_get_value (hadjustment);
-	vadjustment_value = gtk_adjustment_get_value (vadjustment);
-
-	draw_x1 = MAX (x0, hadjustment_value - canvas->zoom_xofs);
-	draw_y1 = MAX (y0, vadjustment_value - canvas->zoom_yofs);
-	draw_x2 = MIN (draw_x1 + allocation.width, x1);
-	draw_y2 = MIN (draw_y1 + allocation.height, y1);
-
-	draw_width = draw_x2 - draw_x1;
-	draw_height = draw_y2 - draw_y1;
-
-	if (draw_width < 1 || draw_height < 1)
-		return;
-
-	canvas->redraw_x1 = draw_x1;
-	canvas->redraw_y1 = draw_y1;
-	canvas->redraw_x2 = draw_x2;
-	canvas->redraw_y2 = draw_y2;
-	canvas->draw_xofs = draw_x1;
-	canvas->draw_yofs = draw_y1;
-
-        pixmap = gdk_pixmap_new (bin_window,
-                                 draw_width, draw_height, -1);
-
-        g_signal_emit (G_OBJECT (canvas), canvas_signals[DRAW_BACKGROUND], 0, pixmap,
-                       draw_x1, draw_y1, draw_width, draw_height);
-
-        if (canvas->root->flags & GNOME_CANVAS_ITEM_VISIBLE)
-                (* GNOME_CANVAS_ITEM_GET_CLASS (canvas->root)->draw) (
-                        canvas->root, pixmap,
-                        draw_x1, draw_y1,
-                        draw_width, draw_height);
-
-        /* Copy the pixmap to the window and clean up */
-        cr = gdk_cairo_create (bin_window);
-
-        gdk_cairo_set_source_pixmap (cr, pixmap,
-                                     draw_x1 + canvas->zoom_xofs,
-                                     draw_y1 + canvas->zoom_yofs);
-        cairo_paint (cr);
-
-        cairo_destroy (cr);
-        g_object_unref (pixmap);
-}
-
-/* Expose handler for the canvas */
-static gint
-gnome_canvas_expose (GtkWidget *widget, GdkEventExpose *event)
-{
-	GnomeCanvas *canvas;
-	GtkLayout *layout;
-	GdkWindow *bin_window;
-	GdkRectangle *rects;
-	gint n_rects;
-	gint i;
-
-	canvas = GNOME_CANVAS (widget);
-
-	layout = GTK_LAYOUT (canvas);
-	bin_window = gtk_layout_get_bin_window (layout);
-
-	if (!gtk_widget_is_drawable (widget) || (event->window != bin_window))
-		return FALSE;
-
-#ifdef VERBOSE
-	g_print ("Expose\n");
-#endif
-
-	gdk_region_get_rectangles (event->region, &rects, &n_rects);
-
-	for (i = 0; i < n_rects; i++) {
-		GdkRectangle rect;
-
-		rect.x = rects[i].x - canvas->zoom_xofs;
-		rect.y = rects[i].y - canvas->zoom_yofs;
-		rect.width = rects[i].width;
-		rect.height = rects[i].height;
-
-		if (canvas->need_update) {
-			gnome_canvas_request_redraw (canvas,
-                                                     rect.x, rect.y,
-                                                     rect.x + rect.width,
-                                                     rect.y + rect.height);
-		} else {
-			/* No pending updates, draw exposed area immediately */
-			gnome_canvas_paint_rect (canvas,
-                                                 rect.x, rect.y,
-                                                 rect.x + rect.width,
-                                                 rect.y + rect.height);
-
-			/* And call expose on parent container class */
-			if (GTK_WIDGET_CLASS (canvas_parent_class)->expose_event)
-				(* GTK_WIDGET_CLASS (canvas_parent_class)->expose_event) (
-					widget, event);
-		}
-	}
-
-	g_free (rects);
-
-	return FALSE;
-}
-
 static void
-gnome_canvas_draw_background (GnomeCanvas *canvas, GdkDrawable *drawable,
-			      gint x, gint y, gint width, gint height)
+gnome_canvas_draw_background (GnomeCanvas *canvas,
+                              cairo_t *cr,
+                              gint x,
+                              gint y,
+                              gint width,
+                              gint height)
 {
 	GtkStyle *style;
-        cairo_t *cr;
 
 	style = gtk_widget_get_style (GTK_WIDGET (canvas));
-        cr = gdk_cairo_create (drawable);
-
-        gdk_cairo_set_source_color (cr, &style->bg[GTK_STATE_NORMAL]);
-        cairo_paint (cr);
-
-        cairo_destroy (cr);
+	gdk_cairo_set_source_color (cr, &style->bg[GTK_STATE_NORMAL]);
+	cairo_paint (cr);
 }
 
 static void
diff --git a/libgnomecanvas/gnome-canvas.h b/libgnomecanvas/gnome-canvas.h
index 3236e20..a239675 100644
--- a/libgnomecanvas/gnome-canvas.h
+++ b/libgnomecanvas/gnome-canvas.h
@@ -158,7 +158,7 @@ struct _GnomeCanvasItemClass {
 	 * coordinates of the drawable, a temporary pixmap, where things get
 	 * drawn.  (width, height) are the dimensions of the drawable.
 	 */
-	void (* draw) (GnomeCanvasItem *item, GdkDrawable *drawable,
+	void (* draw) (GnomeCanvasItem *item, cairo_t *cr,
 		       gint x, gint y, gint width, gint height);
 
         /* Returns the canvas item which is at the given location. This is the
@@ -421,7 +421,7 @@ struct _GnomeCanvasClass {
 	/* Draw the background for the area given. This method is only used
 	 * for non-antialiased canvases.
 	 */
-	void (* draw_background) (GnomeCanvas *canvas, GdkDrawable *drawable,
+	void (* draw_background) (GnomeCanvas *canvas, cairo_t *cr,
 				  gint x, gint y, gint width, gint height);
 
 	/* Private Virtual methods for groping the canvas inside bonobo */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]