[evolution/webkit] Adapt GnomeCanvas to latest gtk+-3.0 API.
- From: Dan VrÃtil <dvratil src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/webkit] Adapt GnomeCanvas to latest gtk+-3.0 API.
- Date: Mon, 11 Jul 2011 14:05:45 +0000 (UTC)
commit 8c35fa41089b9db7396eb0b441821c5024c1d443
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-pixbuf.c | 15 +-
libgnomecanvas/gnome-canvas-rect.c | 37 ++--
libgnomecanvas/gnome-canvas-rich-text.c | 34 ++--
libgnomecanvas/gnome-canvas-text.c | 10 +-
libgnomecanvas/gnome-canvas-widget.c | 4 +-
libgnomecanvas/gnome-canvas.c | 326 +++++++++++++++---------------
libgnomecanvas/gnome-canvas.h | 21 +--
8 files changed, 213 insertions(+), 236 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-pixbuf.c b/libgnomecanvas/gnome-canvas-pixbuf.c
index ea331c6..6fc3e44 100644
--- a/libgnomecanvas/gnome-canvas-pixbuf.c
+++ b/libgnomecanvas/gnome-canvas-pixbuf.c
@@ -50,7 +50,7 @@ static void gnome_canvas_pixbuf_get_property (GObject *object,
GParamSpec *pspec);
static void gnome_canvas_pixbuf_update (GnomeCanvasItem *item, const cairo_matrix_t *i2c, gint flags);
-static void gnome_canvas_pixbuf_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
+static void gnome_canvas_pixbuf_draw (GnomeCanvasItem *item, cairo_t *cr,
gint x, gint y, gint width, gint height);
static GnomeCanvasItem *gnome_canvas_pixbuf_point (GnomeCanvasItem *item,
gdouble x,
@@ -264,13 +264,12 @@ gnome_canvas_pixbuf_update (GnomeCanvasItem *item,
/* Draw handler for the pixbuf canvas item */
static void
-gnome_canvas_pixbuf_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
+gnome_canvas_pixbuf_draw (GnomeCanvasItem *item, cairo_t *cr,
gint x, gint y, gint width, gint height)
{
GnomeCanvasPixbuf *gcp;
GnomeCanvasPixbufPrivate *priv;
cairo_matrix_t matrix;
- cairo_t *cr;
gcp = GNOME_CANVAS_PIXBUF (item);
priv = gcp->priv;
@@ -278,18 +277,14 @@ gnome_canvas_pixbuf_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
if (!priv->pixbuf)
return;
- cr = gdk_cairo_create (drawable);
gnome_canvas_item_i2c_matrix (item, &matrix);
- if (cairo_matrix_invert (&matrix)) {
- cairo_destroy (cr);
- return;
- }
+
+ cairo_save (cr);
cairo_transform (cr, &matrix);
gdk_cairo_set_source_pixbuf (cr, priv->pixbuf, 0, 0);
cairo_paint (cr);
-
- cairo_destroy (cr);
+ cairo_restore (cr);
}
diff --git a/libgnomecanvas/gnome-canvas-rect.c b/libgnomecanvas/gnome-canvas-rect.c
index 1e44aa8..853992e 100644
--- a/libgnomecanvas/gnome-canvas-rect.c
+++ b/libgnomecanvas/gnome-canvas-rect.c
@@ -392,7 +392,7 @@ gnome_canvas_rect_update (GnomeCanvasItem *item,
static void
gnome_canvas_rect_draw (GnomeCanvasItem *item,
- GdkDrawable *drawable,
+ cairo_t *cr,
gint x,
gint y,
gint width,
@@ -400,28 +400,35 @@ gnome_canvas_rect_draw (GnomeCanvasItem *item,
{
GnomeCanvasRect *rect;
cairo_matrix_t matrix;
- cairo_t *cr;
rect = GNOME_CANVAS_RECT (item);
- cr = gdk_cairo_create (drawable);
+
+ cairo_save (cr);
gnome_canvas_item_i2c_matrix (item, &matrix);
cairo_transform (cr, &matrix);
- cairo_rectangle (
- cr,
- rect->priv->x1 - x,
- rect->priv->y1 - y,
- rect->priv->x2 - rect->priv->x1,
- rect->priv->y2 - rect->priv->y1);
-
- if (gnome_canvas_rect_setup_for_fill (rect, cr))
- cairo_fill_preserve (cr);
+ if (gnome_canvas_rect_setup_for_fill (rect, cr)) {
+ cairo_rectangle (
+ cr,
+ rect->priv->x1 - x,
+ rect->priv->y1 - y,
+ rect->priv->x2 - rect->priv->x1,
+ rect->priv->y2 - rect->priv->y1);
+ cairo_fill (cr);
+ }
- if (gnome_canvas_rect_setup_for_stroke (rect, cr))
- cairo_stroke_preserve (cr);
+ if (gnome_canvas_rect_setup_for_stroke (rect, cr)) {
+ cairo_rectangle (
+ cr,
+ rect->priv->x1 - x,
+ rect->priv->y1 - y,
+ rect->priv->x2 - rect->priv->x1,
+ rect->priv->y2 - rect->priv->y1);
+ cairo_stroke (cr);
+ }
- cairo_destroy (cr);
+ cairo_restore (cr);
}
static GnomeCanvasItem *
diff --git a/libgnomecanvas/gnome-canvas-rich-text.c b/libgnomecanvas/gnome-canvas-rich-text.c
index d58bc43..f252266 100644
--- a/libgnomecanvas/gnome-canvas-rich-text.c
+++ b/libgnomecanvas/gnome-canvas-rich-text.c
@@ -122,7 +122,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);
@@ -385,11 +385,6 @@ gnome_canvas_rich_text_class_init (GnomeCanvasRichTextClass *klass)
static void
gnome_canvas_rich_text_init (GnomeCanvasRichText *text)
{
-#if 0
- GObject *object = G_OBJECT (text);
-
- object->flags |= GNOME_CANVAS_ITEM_ALWAYS_REDRAW;
-#endif
text->_priv = g_new0 (GnomeCanvasRichTextPrivate, 1);
/* Try to set some sane defaults */
@@ -2025,25 +2020,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;
@@ -2055,15 +2054,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-text.c b/libgnomecanvas/gnome-canvas-text.c
index a2dce90..a012c76 100644
--- a/libgnomecanvas/gnome-canvas-text.c
+++ b/libgnomecanvas/gnome-canvas-text.c
@@ -106,7 +106,7 @@ static void gnome_canvas_text_get_property (GObject *object,
GParamSpec *pspec);
static void gnome_canvas_text_update (GnomeCanvasItem *item, const cairo_matrix_t *matrix, gint flags);
-static void gnome_canvas_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
+static void gnome_canvas_text_draw (GnomeCanvasItem *item, cairo_t *cr,
gint x, gint y, gint width, gint height);
static GnomeCanvasItem *gnome_canvas_text_point (GnomeCanvasItem *item,
gdouble x,
@@ -1189,16 +1189,16 @@ gnome_canvas_text_update (GnomeCanvasItem *item,
/* Draw handler for the text item */
static void
-gnome_canvas_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
+gnome_canvas_text_draw (GnomeCanvasItem *item, cairo_t *cr,
gint x, gint y, gint width, gint height)
{
GnomeCanvasText *text = GNOME_CANVAS_TEXT (item);
- cairo_t *cr;
if (!text->text)
return;
- cr = gdk_cairo_create (drawable);
+ cairo_save (cr);
+
if (text->clip) {
cairo_rectangle (cr,
text->clip_cx - x,
@@ -1217,7 +1217,7 @@ gnome_canvas_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
cairo_move_to (cr, text->cx - x, text->cy - y);
pango_cairo_show_layout (cr, text->layout);
- cairo_destroy (cr);
+ cairo_restore (cr);
}
/* Point handler for the text item */
diff --git a/libgnomecanvas/gnome-canvas-widget.c b/libgnomecanvas/gnome-canvas-widget.c
index b979102..c6dd99f 100644
--- a/libgnomecanvas/gnome-canvas-widget.c
+++ b/libgnomecanvas/gnome-canvas-widget.c
@@ -73,7 +73,7 @@ static void gnome_canvas_widget_bounds (GnomeCanvasItem *item,
gdouble *y2);
static void gnome_canvas_widget_draw (GnomeCanvasItem *item,
- GdkDrawable *drawable,
+ cairo_t *cr,
gint x,
gint y,
gint width,
@@ -402,7 +402,7 @@ gnome_canvas_widget_update (GnomeCanvasItem *item,
static void
gnome_canvas_widget_draw (GnomeCanvasItem *item,
- GdkDrawable *drawable,
+ cairo_t *cr,
gint x, gint y,
gint width, gint height)
{
diff --git a/libgnomecanvas/gnome-canvas.c b/libgnomecanvas/gnome-canvas.c
index 7c17283..c28bc82 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"
@@ -1197,7 +1198,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,
@@ -1484,8 +1485,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;
@@ -1496,19 +1501,18 @@ gnome_canvas_group_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
for (list = group->item_list; list; list = list->next) {
child = list->data;
- if (((child->flags & GNOME_CANVAS_ITEM_VISIBLE)
- && ((child->x1 < (x + width))
- && (child->y1 < (y + height))
- && (child->x2 > x)
- && (child->y2 > y)))
- || ((child->flags & GNOME_CANVAS_ITEM_ALWAYS_REDRAW)
- && (child->x1 < child->canvas->redraw_x2)
- && (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);
+ if ((child->flags & GNOME_CANVAS_ITEM_VISIBLE)
+ && ((child->x1 < (x + width))
+ && (child->y1 < (y + height))
+ && (child->x2 > x)
+ && (child->y2 > y))) {
+ cairo_save (cr);
+
+ GNOME_CANVAS_ITEM_GET_CLASS (child)->draw (
+ child, cr, x, y, width, height);
+
+ cairo_restore (cr);
+ }
}
}
@@ -1684,12 +1688,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,
@@ -1700,11 +1704,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;
@@ -1715,6 +1719,73 @@ 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;
+ GdkWindow *bin_window;
+ GtkAllocation allocation;
+ GtkScrollable *scrollable;
+ 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);
+ bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (canvas));
+
+ scrollable = GTK_SCROLLABLE (canvas);
+ hadjustment = gtk_scrollable_get_hadjustment (scrollable);
+ vadjustment = gtk_scrollable_get_vadjustment (scrollable);
+
+ 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->draw_xofs = draw_x1;
+ canvas->draw_yofs = draw_y1;
+
+ cairo_save (cr);
+
+ g_signal_emit (
+ canvas, canvas_signals[DRAW_BACKGROUND], 0, cr,
+ draw_x1, draw_y1, draw_width, draw_height);
+
+ cairo_restore (cr);
+
+ if (canvas->root->flags & GNOME_CANVAS_ITEM_VISIBLE) {
+ cairo_save (cr);
+
+ (* GNOME_CANVAS_ITEM_GET_CLASS (canvas->root)->draw) (
+ canvas->root, cr,
+ draw_x1, draw_y1,
+ draw_width, draw_height);
+
+ cairo_restore (cr);
+ }
+}
+
/**
* gnome_canvas_get_type:
*
@@ -1802,10 +1873,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;
@@ -1827,8 +1898,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 ();
@@ -1870,9 +1941,6 @@ gnome_canvas_init (GnomeCanvas *canvas)
gtk_scrollable_set_hadjustment (GTK_SCROLLABLE (canvas), NULL);
gtk_scrollable_set_vadjustment (GTK_SCROLLABLE (canvas), NULL);
- /* Disable the gtk+ gdouble buffering since the canvas uses it's own. */
- gtk_widget_set_double_buffered (GTK_WIDGET (canvas), FALSE);
-
/* Create the root item as a special case */
canvas->root = GNOME_CANVAS_ITEM (
@@ -2177,6 +2245,57 @@ 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 = GNOME_CANVAS (widget);
+ cairo_rectangle_int_t rect;
+
+ gdk_cairo_get_clip_rectangle (cr, &rect);
+
+ if (canvas->need_update) {
+ gnome_canvas_request_redraw (canvas,
+ rect.x, rect.y,
+ rect.x + rect.width,
+ rect.y + rect.height);
+ } else {
+ GtkLayout *layout;
+ GtkAdjustment *hadjustment;
+ GtkAdjustment *vadjustment;
+ gdouble hadjustment_value;
+ gdouble vadjustment_value;
+
+ layout = GTK_LAYOUT (canvas);
+ hadjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (layout));
+ vadjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (layout));
+
+ hadjustment_value = gtk_adjustment_get_value (hadjustment);
+ vadjustment_value = gtk_adjustment_get_value (vadjustment);
+
+ cairo_save (cr);
+ cairo_translate (cr,
+ -canvas->zoom_xofs + rect.x,
+ -canvas->zoom_yofs + rect.y);
+
+ rect.x += hadjustment_value;
+ rect.y += vadjustment_value;
+
+ /* 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);
+ cairo_restore (cr);
+
+ /* And call expose on parent container class */
+ GTK_WIDGET_CLASS (canvas_parent_class)->
+ draw (widget, cr);
+ }
+
+ return FALSE;
+}
+
/* Emits an event for an item in the canvas, be it the current item, grabbed
* item, or focused item, as appropriate.
*/
@@ -2645,151 +2764,22 @@ 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;
- GdkWindow *bin_window;
- GtkAllocation allocation;
- GtkScrollable *scrollable;
- 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);
- bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (canvas));
-
- scrollable = GTK_SCROLLABLE (canvas);
- hadjustment = gtk_scrollable_get_hadjustment (scrollable);
- vadjustment = gtk_scrollable_get_vadjustment (scrollable);
-
- 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);
+ cairo_save (cr);
+ gdk_cairo_set_source_color (cr, &style->bg[GTK_STATE_NORMAL]);
+ cairo_paint (cr);
+ cairo_restore (cr);
}
static void
diff --git a/libgnomecanvas/gnome-canvas.h b/libgnomecanvas/gnome-canvas.h
index 5c46464..603ebfe 100644
--- a/libgnomecanvas/gnome-canvas.h
+++ b/libgnomecanvas/gnome-canvas.h
@@ -84,12 +84,11 @@ typedef struct _GnomeCanvasGroupClass GnomeCanvasGroupClass;
typedef enum {
GNOME_CANVAS_ITEM_REALIZED = 1 << 0,
GNOME_CANVAS_ITEM_MAPPED = 1 << 1,
- GNOME_CANVAS_ITEM_ALWAYS_REDRAW = 1 << 2,
- GNOME_CANVAS_ITEM_VISIBLE = 1 << 3,
- GNOME_CANVAS_ITEM_NEED_UPDATE = 1 << 4,
- GNOME_CANVAS_ITEM_NEED_AFFINE = 1 << 5,
- GNOME_CANVAS_ITEM_NEED_CLIP = 1 << 6,
- GNOME_CANVAS_ITEM_NEED_VIS = 1 << 7
+ GNOME_CANVAS_ITEM_VISIBLE = 1 << 2,
+ GNOME_CANVAS_ITEM_NEED_UPDATE = 1 << 3,
+ GNOME_CANVAS_ITEM_NEED_AFFINE = 1 << 4,
+ GNOME_CANVAS_ITEM_NEED_CLIP = 1 << 5,
+ GNOME_CANVAS_ITEM_NEED_VIS = 1 << 6
} GnomeCanvasItemFlags;
/* Update flags for items */
@@ -158,7 +157,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
@@ -376,12 +375,6 @@ struct _GnomeCanvas {
/* Idle handler ID */
guint idle_id;
- /* Area that is being redrawn. Contains (x1, y1) but not (x2, y2).
- * Specified in canvas pixel coordinates.
- */
- gint redraw_x1, redraw_y1;
- gint redraw_x2, redraw_y2;
-
/* Offsets of the temprary drawing pixmap */
gint draw_xofs, draw_yofs;
@@ -413,7 +406,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]