[planner: 3/32] libgnomecanvas: Import gtk3 ported version source code from evolution




commit 923f9e9c50b91215bd034d70f083230756a77c72
Author: Mart Raudsepp <leio gentoo org>
Date:   Sun Mar 21 10:55:51 2021 +0200

    libgnomecanvas: Import gtk3 ported version source code from evolution
    
    Code copied from src/libgnomecanvas from evolution of its state at
    evolution commit 4dc54800f385f1dd43b4dad460e1dee8b1c3c502 with last
    change to libgnomecanvas files on 2020-11-04 from
    commit d27a33e55d836a7b5de76ca47e40568a195c395b

 src/libgnomecanvas/gailcanvas.c              |  185 ++
 src/libgnomecanvas/gailcanvas.h              |   55 +
 src/libgnomecanvas/gailcanvasgroup.c         |  100 +
 src/libgnomecanvas/gailcanvasgroup.h         |   52 +
 src/libgnomecanvas/gailcanvasgroupfactory.c  |   76 +
 src/libgnomecanvas/gailcanvasgroupfactory.h  |   49 +
 src/libgnomecanvas/gailcanvasitem.c          |  406 +++
 src/libgnomecanvas/gailcanvasitem.h          |   51 +
 src/libgnomecanvas/gailcanvasitemfactory.c   |   56 +
 src/libgnomecanvas/gailcanvasitemfactory.h   |   49 +
 src/libgnomecanvas/gailcanvastext.c          |  514 ++++
 src/libgnomecanvas/gailcanvastext.h          |   49 +
 src/libgnomecanvas/gailcanvastextfactory.c   |   56 +
 src/libgnomecanvas/gailcanvastextfactory.h   |   49 +
 src/libgnomecanvas/gailcanvaswidget.c        |  114 +
 src/libgnomecanvas/gailcanvaswidget.h        |   52 +
 src/libgnomecanvas/gailcanvaswidgetfactory.c |   55 +
 src/libgnomecanvas/gailcanvaswidgetfactory.h |   49 +
 src/libgnomecanvas/gnome-canvas-i18n.h       |   65 +
 src/libgnomecanvas/gnome-canvas-pixbuf.c     |  345 +++
 src/libgnomecanvas/gnome-canvas-pixbuf.h     |   53 +
 src/libgnomecanvas/gnome-canvas-rect.c       |  718 ++++++
 src/libgnomecanvas/gnome-canvas-rect.h       |   68 +
 src/libgnomecanvas/gnome-canvas-text.c       | 1412 +++++++++++
 src/libgnomecanvas/gnome-canvas-text.h       |  150 ++
 src/libgnomecanvas/gnome-canvas-util.c       |  167 ++
 src/libgnomecanvas/gnome-canvas-util.h       |   53 +
 src/libgnomecanvas/gnome-canvas-widget.c     |  467 ++++
 src/libgnomecanvas/gnome-canvas-widget.h     |   89 +
 src/libgnomecanvas/gnome-canvas.c            | 3501 ++++++++++++++++++++++++++
 src/libgnomecanvas/gnome-canvas.h            |  489 ++++
 src/libgnomecanvas/libgnomecanvas.h          |   33 +
 32 files changed, 9627 insertions(+)
---
diff --git a/src/libgnomecanvas/gailcanvas.c b/src/libgnomecanvas/gailcanvas.c
new file mode 100644
index 00000000..9a424b8c
--- /dev/null
+++ b/src/libgnomecanvas/gailcanvas.c
@@ -0,0 +1,185 @@
+/* GAIL - The GNOME Accessibility Implementation Library
+ * Copyright 2001, 2002, 2003 Sun Microsystems Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "evolution-config.h"
+
+#include <gtk/gtk.h>
+#include <libgnomecanvas/gnome-canvas.h>
+#include <libgnomecanvas/gnome-canvas-text.h>
+#include <libgnomecanvas/gnome-canvas-widget.h>
+#include "gailcanvas.h"
+#include "gailcanvasitem.h"
+#include "gailcanvasgroupfactory.h"
+#include "gailcanvastextfactory.h"
+#include "gailcanvasitemfactory.h"
+#include "gailcanvaswidgetfactory.h"
+
+static void       gail_canvas_real_initialize     (AtkObject       *obj,
+                                                   gpointer        data);
+
+static gint       gail_canvas_get_n_children      (AtkObject       *obj);
+static AtkObject * gail_canvas_ref_child           (AtkObject       *obj,
+                                                   gint            i);
+
+static void       adjustment_changed              (GtkAdjustment   *adjustment,
+                                                   GnomeCanvas     *canvas);
+
+G_DEFINE_TYPE (GailCanvas, gail_canvas, GTK_TYPE_CONTAINER_ACCESSIBLE)
+
+static void
+gail_canvas_init (GailCanvas *canvas)
+{
+}
+
+/**
+ * Tell ATK how to create the appropriate AtkObject peers
+ **/
+void
+gail_canvas_a11y_init (void)
+{
+  atk_registry_set_factory_type (atk_get_default_registry (),
+                                GNOME_TYPE_CANVAS_GROUP,
+                                gail_canvas_group_factory_get_type ());
+  atk_registry_set_factory_type (atk_get_default_registry (),
+                                GNOME_TYPE_CANVAS_TEXT,
+                                gail_canvas_text_factory_get_type ());
+  atk_registry_set_factory_type (atk_get_default_registry (),
+                                GNOME_TYPE_CANVAS_WIDGET,
+                                gail_canvas_widget_factory_get_type ());
+  atk_registry_set_factory_type (atk_get_default_registry (),
+                                GNOME_TYPE_CANVAS_ITEM,
+                                gail_canvas_item_factory_get_type ());
+}
+
+static void
+gail_canvas_class_init (GailCanvasClass *klass)
+{
+  AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
+
+  class->get_n_children = gail_canvas_get_n_children;
+  class->ref_child = gail_canvas_ref_child;
+  class->initialize = gail_canvas_real_initialize;
+}
+
+AtkObject *
+gail_canvas_new (GtkWidget *widget)
+{
+  GObject *object;
+  AtkObject *accessible;
+
+  g_return_val_if_fail (GNOME_IS_CANVAS (widget), NULL);
+
+  object = g_object_new (GAIL_TYPE_CANVAS, NULL);
+
+  accessible = ATK_OBJECT (object);
+  atk_object_initialize (accessible, widget);
+
+  return accessible;
+}
+
+static void
+gail_canvas_real_initialize (AtkObject *obj,
+                             gpointer data)
+{
+       GnomeCanvas *canvas;
+       GtkAdjustment *adj;
+
+       ATK_OBJECT_CLASS (gail_canvas_parent_class)->initialize (obj, data);
+
+       canvas = GNOME_CANVAS (data);
+
+       adj = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (canvas));
+       g_signal_connect_object (
+               adj, "value_changed",
+               G_CALLBACK (adjustment_changed), canvas, 0);
+
+       adj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (canvas));
+       g_signal_connect_object (
+               adj, "value_changed",
+               G_CALLBACK (adjustment_changed), canvas, 0);
+
+       obj->role = ATK_ROLE_LAYERED_PANE;
+}
+
+static gint
+gail_canvas_get_n_children (AtkObject *obj)
+{
+  GtkAccessible *accessible;
+  GtkWidget *widget;
+  GnomeCanvas *canvas;
+  GnomeCanvasGroup *root_group;
+
+  g_return_val_if_fail (GAIL_IS_CANVAS (obj), 0);
+
+  accessible = GTK_ACCESSIBLE (obj);
+  widget = gtk_accessible_get_widget (accessible);
+  if (widget == NULL)
+    /* State is defunct */
+    return 0;
+
+  g_return_val_if_fail (GNOME_IS_CANVAS (widget), 0);
+
+  canvas = GNOME_CANVAS (widget);
+  root_group = gnome_canvas_root (canvas);
+  g_return_val_if_fail (root_group, 0);
+  return 1;
+}
+
+static AtkObject *
+gail_canvas_ref_child (AtkObject *obj,
+                       gint i)
+{
+  GtkAccessible *accessible;
+  GtkWidget *widget;
+  GnomeCanvas *canvas;
+  GnomeCanvasGroup *root_group;
+  AtkObject *atk_object;
+
+  /* Canvas only has one child, so return NULL if anything else is requested */
+  if (i != 0)
+    return NULL;
+  g_return_val_if_fail (GAIL_IS_CANVAS (obj), NULL);
+
+  accessible = GTK_ACCESSIBLE (obj);
+  widget = gtk_accessible_get_widget (accessible);
+  if (widget == NULL)
+    /* State is defunct */
+    return NULL;
+  g_return_val_if_fail (GNOME_IS_CANVAS (widget), NULL);
+
+  canvas = GNOME_CANVAS (widget);
+  root_group = gnome_canvas_root (canvas);
+  g_return_val_if_fail (root_group, NULL);
+
+  atk_object = atk_gobject_accessible_for_object (G_OBJECT (root_group));
+  g_object_ref (atk_object);
+  return atk_object;
+}
+
+static void
+adjustment_changed (GtkAdjustment *adjustment,
+                    GnomeCanvas *canvas)
+{
+  AtkObject *atk_obj;
+
+  /*
+   * The scrollbars have changed
+   */
+  atk_obj = gtk_widget_get_accessible (GTK_WIDGET (canvas));
+
+  g_signal_emit_by_name (atk_obj, "visible_data_changed");
+}
+
diff --git a/src/libgnomecanvas/gailcanvas.h b/src/libgnomecanvas/gailcanvas.h
new file mode 100644
index 00000000..58164da1
--- /dev/null
+++ b/src/libgnomecanvas/gailcanvas.h
@@ -0,0 +1,55 @@
+/* gailcanvas.h - code from GAIL, the
+ * Gnome Accessibility Implementation Library
+ * Copyright 2001-2006 Sun Microsystems Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GAIL_CANVAS_H__
+#define __GAIL_CANVAS_H__
+
+#include <gtk/gtk.h>
+#include <gtk/gtk-a11y.h>
+
+/* This code provides the ATK implementation for gnome-canvas widgets. */
+
+G_BEGIN_DECLS
+
+#define GAIL_TYPE_CANVAS                  (gail_canvas_get_type ())
+#define GAIL_CANVAS(obj)                  (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAIL_TYPE_CANVAS, GailCanvas))
+#define GAIL_CANVAS_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST ((klass), GAIL_TYPE_CANVAS, 
GailCanvasClass))
+#define GAIL_IS_CANVAS(obj)               (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAIL_TYPE_CANVAS))
+#define GAIL_IS_CANVAS_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE ((klass), GAIL_TYPE_CANVAS))
+#define GAIL_CANVAS_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS ((obj), GAIL_TYPE_CANVAS, 
GailCanvasClass))
+
+typedef struct _GailCanvas                 GailCanvas;
+typedef struct _GailCanvasClass            GailCanvasClass;
+GType gail_canvas_get_type (void);
+
+struct _GailCanvas
+{
+  GtkContainerAccessible parent;
+};
+
+struct _GailCanvasClass
+{
+  GtkContainerAccessibleClass parent_class;
+};
+
+AtkObject * gail_canvas_new (GtkWidget *widget);
+
+void gail_canvas_a11y_init (void);
+
+G_END_DECLS
+
+#endif /* __GAIL_CANVAS_H__ */
diff --git a/src/libgnomecanvas/gailcanvasgroup.c b/src/libgnomecanvas/gailcanvasgroup.c
new file mode 100644
index 00000000..c478f6e7
--- /dev/null
+++ b/src/libgnomecanvas/gailcanvasgroup.c
@@ -0,0 +1,100 @@
+/* GAIL - The GNOME Accessibility Implementation Library
+ * Copyright 2001 Sun Microsystems Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "evolution-config.h"
+
+#include <gtk/gtk.h>
+#include <libgnomecanvas/gnome-canvas.h>
+#include "gailcanvasgroup.h"
+
+static gint       gail_canvas_group_get_n_children  (AtkObject            *obj);
+static AtkObject * gail_canvas_group_ref_child       (AtkObject            *obj,
+                                                     gint                 i);
+
+G_DEFINE_TYPE (GailCanvasGroup,
+             gail_canvas_group,
+             GAIL_TYPE_CANVAS_ITEM);
+
+static void
+gail_canvas_group_init (GailCanvasGroup *foo)
+{
+  ;
+}
+
+AtkObject *
+gail_canvas_group_new (GObject *obj)
+{
+  gpointer object;
+  AtkObject *atk_object;
+
+  g_return_val_if_fail (GNOME_IS_CANVAS_GROUP (obj), NULL);
+  object = g_object_new (GAIL_TYPE_CANVAS_GROUP, NULL);
+  atk_object = ATK_OBJECT (object);
+  atk_object_initialize (atk_object, obj);
+  atk_object->role = ATK_ROLE_PANEL;
+  return atk_object;
+}
+
+static void
+gail_canvas_group_class_init (GailCanvasGroupClass *klass)
+{
+  AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
+
+  class->get_n_children = gail_canvas_group_get_n_children;
+  class->ref_child = gail_canvas_group_ref_child;
+}
+
+static gint
+gail_canvas_group_get_n_children (AtkObject *obj)
+{
+  AtkGObjectAccessible *atk_gobject;
+  GnomeCanvasGroup *group;
+  GObject *g_obj;
+
+  g_return_val_if_fail (GAIL_IS_CANVAS_ITEM (obj), 0);
+  atk_gobject = ATK_GOBJECT_ACCESSIBLE (obj);
+  g_obj = atk_gobject_accessible_get_object (atk_gobject);
+  g_return_val_if_fail (GNOME_IS_CANVAS_GROUP (g_obj), 0);
+  group = GNOME_CANVAS_GROUP (g_obj);
+  return g_list_length (group->item_list);
+}
+
+static AtkObject *
+gail_canvas_group_ref_child (AtkObject *obj,
+                             gint i)
+{
+  AtkGObjectAccessible *atk_gobject;
+  GnomeCanvasGroup *group;
+  GnomeCanvasItem *item;
+  AtkObject *accessible;
+  GObject *g_obj;
+  GList *list_item;
+
+  g_return_val_if_fail (GAIL_IS_CANVAS_ITEM (obj), NULL);
+  atk_gobject = ATK_GOBJECT_ACCESSIBLE (obj);
+  g_obj = atk_gobject_accessible_get_object (atk_gobject);
+  g_return_val_if_fail (GNOME_IS_CANVAS_GROUP (g_obj), NULL);
+  group = GNOME_CANVAS_GROUP (g_obj);
+
+  list_item = g_list_nth (group->item_list, i);
+  if (!list_item)
+         return NULL;
+  g_return_val_if_fail (list_item->data, NULL);
+  item = GNOME_CANVAS_ITEM (list_item->data);
+  accessible = atk_gobject_accessible_for_object (G_OBJECT (item));
+  g_object_ref (accessible);
+  return accessible;
+}
diff --git a/src/libgnomecanvas/gailcanvasgroup.h b/src/libgnomecanvas/gailcanvasgroup.h
new file mode 100644
index 00000000..414fd230
--- /dev/null
+++ b/src/libgnomecanvas/gailcanvasgroup.h
@@ -0,0 +1,52 @@
+/* GAIL - The GNOME Accessibility Implementation Library
+ * Copyright 2001 Sun Microsystems Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GAIL_CANVAS_GROUP_H__
+#define __GAIL_CANVAS_GROUP_H__
+
+#include <libgnomecanvas/gnome-canvas.h>
+#include <atk/atk.h>
+#include "gailcanvasitem.h"
+
+G_BEGIN_DECLS
+
+#define GAIL_TYPE_CANVAS_GROUP                  (gail_canvas_group_get_type ())
+#define GAIL_CANVAS_GROUP(obj)                  (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAIL_TYPE_CANVAS_GROUP, 
GailCanvasGroup))
+#define GAIL_CANVAS_GROUP_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST ((klass), GAIL_TYPE_CANVAS_GROUP, 
GailCanvasGroupClass))
+#define GAIL_IS_CANVAS_GROUP(obj)               (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAIL_TYPE_CANVAS_GROUP))
+#define GAIL_IS_CANVAS_GROUP_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE ((klass), GAIL_TYPE_CANVAS_GROUP))
+#define GAIL_CANVAS_GROUP_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS ((obj), GAIL_TYPE_CANVAS_GROUP, 
GailCanvasGroupClass))
+
+typedef struct _GailCanvasGroup                 GailCanvasGroup;
+typedef struct _GailCanvasGroupClass            GailCanvasGroupClass;
+
+struct _GailCanvasGroup
+{
+  GailCanvasItem parent;
+};
+
+GType gail_canvas_group_get_type (void);
+
+struct _GailCanvasGroupClass
+{
+  GailCanvasItemClass parent_class;
+};
+
+AtkObject * gail_canvas_group_new (GObject *obj);
+
+G_END_DECLS
+
+#endif /* __GAIL_CANVAS_GROUP_H__ */
diff --git a/src/libgnomecanvas/gailcanvasgroupfactory.c b/src/libgnomecanvas/gailcanvasgroupfactory.c
new file mode 100644
index 00000000..fb2a49ce
--- /dev/null
+++ b/src/libgnomecanvas/gailcanvasgroupfactory.c
@@ -0,0 +1,76 @@
+/* GAIL - The GNOME Accessibility Implementation Library
+ * Copyright 2001 Sun Microsystems Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "evolution-config.h"
+
+#include <gtk/gtk.h>
+#include "gailcanvasgroupfactory.h"
+#include "gailcanvasgroup.h"
+
+static void gail_canvas_group_factory_class_init (GailCanvasGroupFactoryClass *klass);
+
+static AtkObject * gail_canvas_group_factory_create_accessible (GObject *obj);
+
+static GType gail_canvas_group_factory_get_accessible_type (void);
+
+GType
+gail_canvas_group_factory_get_type (void)
+{
+  static GType type = 0;
+
+  if (!type)
+  {
+    static const GTypeInfo tinfo =
+    {
+      sizeof (GailCanvasGroupFactoryClass),
+      (GBaseInitFunc) NULL, /* base init */
+      (GBaseFinalizeFunc) NULL, /* base finalize */
+      (GClassInitFunc) gail_canvas_group_factory_class_init, /* class init */
+      (GClassFinalizeFunc) NULL, /* class finalize */
+      NULL, /* class data */
+      sizeof (GailCanvasGroupFactory), /* instance size */
+      0, /* nb preallocs */
+      (GInstanceInitFunc) NULL, /* instance init */
+      NULL /* value table */
+    };
+    type = g_type_register_static (
+                          ATK_TYPE_OBJECT_FACTORY,
+                          "GailCanvasGroupFactory" , &tinfo, 0);
+  }
+
+  return type;
+}
+
+static void
+gail_canvas_group_factory_class_init (GailCanvasGroupFactoryClass *klass)
+{
+  AtkObjectFactoryClass *class = ATK_OBJECT_FACTORY_CLASS (klass);
+
+  class->create_accessible = gail_canvas_group_factory_create_accessible;
+  class->get_accessible_type = gail_canvas_group_factory_get_accessible_type;
+}
+
+static AtkObject *
+gail_canvas_group_factory_create_accessible (GObject *obj)
+{
+  return gail_canvas_group_new (obj);
+}
+
+static GType
+gail_canvas_group_factory_get_accessible_type (void)
+{
+  return GAIL_TYPE_CANVAS_GROUP;
+}
diff --git a/src/libgnomecanvas/gailcanvasgroupfactory.h b/src/libgnomecanvas/gailcanvasgroupfactory.h
new file mode 100644
index 00000000..fc4f7983
--- /dev/null
+++ b/src/libgnomecanvas/gailcanvasgroupfactory.h
@@ -0,0 +1,49 @@
+/* GAIL - The GNOME Accessibility Implementation Library
+ * Copyright 2001 Sun Microsystems Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GAIL_CANVAS_GROUP_FACTORY_H__
+#define __GAIL_CANVAS_GROUP_FACTORY_H__
+
+#include <atk/atkobjectfactory.h>
+
+G_BEGIN_DECLS
+
+#define GAIL_TYPE_CANVAS_GROUP_FACTORY                 (gail_canvas_group_factory_get_type ())
+#define GAIL_CANVAS_GROUP_FACTORY(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GAIL_TYPE_CANVAS_GROUP_FACTORY, GailCanvasGroupFactory))
+#define GAIL_CANVAS_GROUP_FACTORY_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), 
GAIL_TYPE_CANVAS_GROUP_FACTORY, GailCanvasGroupFactoryClass))
+#define GAIL_IS_CANVAS_GROUP_FACTORY(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GAIL_TYPE_CANVAS_GROUP_FACTORY))
+#define GAIL_IS_CANVAS_GROUP_FACTORY_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), 
GAIL_TYPE_CANVAS_GROUP_FACTORY))
+#define GAIL_CANVAS_GROUP_FACTORY_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), 
GAIL_TYPE_CANVAS_GROUP_FACTORY, GailCanvasGroupFactoryClass))
+
+typedef struct _GailCanvasGroupFactory                GailCanvasGroupFactory;
+typedef struct _GailCanvasGroupFactoryClass           GailCanvasGroupFactoryClass;
+
+struct _GailCanvasGroupFactory
+{
+  AtkObjectFactory parent;
+};
+
+struct _GailCanvasGroupFactoryClass
+{
+  AtkObjectFactoryClass parent_class;
+};
+
+GType gail_canvas_group_factory_get_type (void);
+
+G_END_DECLS
+
+#endif /* __GAIL_CANVAS_GROUP_FACTORY_H__ */
+
diff --git a/src/libgnomecanvas/gailcanvasitem.c b/src/libgnomecanvas/gailcanvasitem.c
new file mode 100644
index 00000000..e62bdfd2
--- /dev/null
+++ b/src/libgnomecanvas/gailcanvasitem.c
@@ -0,0 +1,406 @@
+/* GAIL - The GNOME Accessibility Implementation Library
+ * Copyright 2001 Sun Microsystems Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "evolution-config.h"
+
+#include <math.h>
+#include <gtk/gtk.h>
+#include <libgnomecanvas/gnome-canvas.h>
+#include <libgnomecanvas/gnome-canvas-util.h>
+#include "gailcanvasitem.h"
+#include <libgail-util/gailmisc.h>
+
+static void       gail_canvas_item_initialize               (AtkObject         *obj,
+                                                            gpointer          data);
+static AtkObject * gail_canvas_item_get_parent               (AtkObject         *obj);
+static gint       gail_canvas_item_get_index_in_parent      (AtkObject         *obj);
+static AtkStateSet * gail_canvas_item_ref_state_set          (AtkObject         *obj);
+
+static void       gail_canvas_item_component_interface_init (AtkComponentIface *iface);
+static guint      gail_canvas_item_add_focus_handler        (AtkComponent *component,
+                                                            AtkFocusHandler   handler);
+static void       gail_canvas_item_get_extents              (AtkComponent *component,
+                                                            gint              *x,
+                                                            gint              *y,
+                                                            gint              *width,
+                                                            gint              *height,
+                                                            AtkCoordType      coord_type);
+static gint       gail_canvas_item_get_mdi_zorder           (AtkComponent *component);
+static gboolean   gail_canvas_item_grab_focus               (AtkComponent *component);
+static void       gail_canvas_item_remove_focus_handler     (AtkComponent *component,
+                                                            guint             handler_id);
+static gboolean   is_item_on_screen                         (GnomeCanvasItem   *item);
+static void       get_item_extents                          (GnomeCanvasItem   *item,
+                                                            GdkRectangle      *extents);
+static gboolean   is_item_in_window                         (GnomeCanvasItem   *item,
+                                                            const GdkRectangle *extents);
+
+G_DEFINE_TYPE_WITH_CODE (GailCanvasItem,
+                        gail_canvas_item,
+                        ATK_TYPE_GOBJECT_ACCESSIBLE,
+                        G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT,
+                                               gail_canvas_item_component_interface_init));
+
+static void
+gail_canvas_item_init (GailCanvasItem *foo)
+{
+  ;
+}
+
+AtkObject *
+gail_canvas_item_new (GObject *obj)
+{
+  gpointer object;
+  AtkObject *atk_object;
+
+  g_return_val_if_fail (GNOME_IS_CANVAS_ITEM (obj), NULL);
+  object = g_object_new (GAIL_TYPE_CANVAS_ITEM, NULL);
+  atk_object = ATK_OBJECT (object);
+  atk_object_initialize (atk_object, obj);
+  atk_object->role = ATK_ROLE_UNKNOWN;
+  return atk_object;
+}
+
+static void
+gail_canvas_item_initialize (AtkObject *obj,
+                             gpointer data)
+{
+  ATK_OBJECT_CLASS (gail_canvas_item_parent_class)->initialize (obj, data);
+
+  g_object_set_data (G_OBJECT (obj), "atk-component-layer",
+                    GINT_TO_POINTER (ATK_LAYER_MDI));
+}
+
+static void
+gail_canvas_item_class_init (GailCanvasItemClass *klass)
+{
+  AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
+
+  class->get_parent = gail_canvas_item_get_parent;
+  class->get_index_in_parent = gail_canvas_item_get_index_in_parent;
+  class->ref_state_set = gail_canvas_item_ref_state_set;
+  class->initialize = gail_canvas_item_initialize;
+}
+
+static AtkObject *
+gail_canvas_item_get_parent (AtkObject *obj)
+{
+  AtkGObjectAccessible *atk_gobj;
+  GObject *g_obj;
+  GnomeCanvasItem *item;
+
+  g_return_val_if_fail (GAIL_IS_CANVAS_ITEM (obj), NULL);
+  if (obj->accessible_parent)
+    return obj->accessible_parent;
+  atk_gobj = ATK_GOBJECT_ACCESSIBLE (obj);
+  g_obj = atk_gobject_accessible_get_object (atk_gobj);
+  if (g_obj == NULL)
+    /* Object is defunct */
+    return NULL;
+
+  item = GNOME_CANVAS_ITEM (g_obj);
+  if (item->parent)
+    return atk_gobject_accessible_for_object (G_OBJECT (item->parent));
+  else
+    return gtk_widget_get_accessible (GTK_WIDGET (item->canvas));
+}
+
+static gint
+gail_canvas_item_get_index_in_parent (AtkObject *obj)
+{
+  AtkGObjectAccessible *atk_gobj;
+  GObject *g_obj;
+  GnomeCanvasItem *item;
+
+  g_return_val_if_fail (GAIL_IS_CANVAS_ITEM (obj), -1);
+  if (obj->accessible_parent)
+    {
+      gint n_children, i;
+      gboolean found = FALSE;
+
+      n_children = atk_object_get_n_accessible_children (obj->accessible_parent);
+      for (i = 0; i < n_children; i++)
+       {
+         AtkObject *child;
+
+         child = atk_object_ref_accessible_child (obj->accessible_parent, i);
+         if (child == obj)
+           found = TRUE;
+
+         g_object_unref (child);
+         if (found)
+           return i;
+       }
+      return -1;
+    }
+
+  atk_gobj = ATK_GOBJECT_ACCESSIBLE (obj);
+  g_obj = atk_gobject_accessible_get_object (atk_gobj);
+  if (g_obj == NULL)
+    /* Object is defunct */
+    return -1;
+
+  item = GNOME_CANVAS_ITEM (g_obj);
+  if (item->parent)
+    {
+      return g_list_index (GNOME_CANVAS_GROUP (item->parent)->item_list, item);
+    }
+  else
+    {
+      g_return_val_if_fail (item->canvas->root == item, -1);
+      return 0;
+    }
+}
+
+static AtkStateSet *
+gail_canvas_item_ref_state_set (AtkObject *obj)
+{
+  AtkGObjectAccessible *atk_gobj;
+  GObject *g_obj;
+  GnomeCanvasItem *item;
+  AtkStateSet *state_set;
+
+  g_return_val_if_fail (GAIL_IS_CANVAS_ITEM (obj), NULL);
+  atk_gobj = ATK_GOBJECT_ACCESSIBLE (obj);
+
+  state_set = ATK_OBJECT_CLASS (gail_canvas_item_parent_class)->ref_state_set (obj);
+
+  g_obj = atk_gobject_accessible_get_object (atk_gobj);
+  if (g_obj == NULL)
+    {
+    /* Object is defunct */
+      atk_state_set_add_state (state_set, ATK_STATE_DEFUNCT);
+    }
+  else
+    {
+      item = GNOME_CANVAS_ITEM (g_obj);
+
+      if (item->flags & GNOME_CANVAS_ITEM_VISIBLE)
+       {
+         atk_state_set_add_state (state_set, ATK_STATE_VISIBLE);
+         if (is_item_on_screen (item))
+           {
+             atk_state_set_add_state (state_set, ATK_STATE_SHOWING);
+           }
+       }
+      if (gtk_widget_get_can_focus (GTK_WIDGET (item->canvas)))
+       {
+         atk_state_set_add_state (state_set, ATK_STATE_FOCUSABLE);
+
+         if (item->canvas->focused_item == item)
+           {
+             atk_state_set_add_state (state_set, ATK_STATE_FOCUSED);
+           }
+       }
+    }
+
+  return state_set;
+}
+
+static void
+gail_canvas_item_component_interface_init (AtkComponentIface *iface)
+{
+  g_return_if_fail (iface != NULL);
+
+  iface->add_focus_handler = gail_canvas_item_add_focus_handler;
+  iface->get_extents = gail_canvas_item_get_extents;
+  iface->get_mdi_zorder = gail_canvas_item_get_mdi_zorder;
+  iface->grab_focus = gail_canvas_item_grab_focus;
+  iface->remove_focus_handler = gail_canvas_item_remove_focus_handler;
+}
+
+static guint
+gail_canvas_item_add_focus_handler (AtkComponent *component,
+                                    AtkFocusHandler handler)
+{
+  GSignalMatchType match_type;
+  gulong ret;
+  guint signal_id;
+
+  match_type = G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC;
+  signal_id = g_signal_lookup ("focus-event", ATK_TYPE_OBJECT);
+
+  ret = g_signal_handler_find (component, match_type, signal_id, 0, NULL,
+                              (gpointer) handler, NULL);
+  if (!ret)
+    {
+      return g_signal_connect_closure_by_id (
+               component, signal_id, 0,
+               g_cclosure_new (
+                       G_CALLBACK (handler), NULL,
+                       (GClosureNotify) NULL),
+                       FALSE);
+    }
+  else
+    {
+      return 0;
+    }
+}
+
+static void
+gail_canvas_item_get_extents (AtkComponent *component,
+                              gint *x,
+                              gint *y,
+                              gint *width,
+                              gint *height,
+                              AtkCoordType coord_type)
+{
+  AtkGObjectAccessible *atk_gobj;
+  GObject *obj;
+  GnomeCanvasItem *item;
+  gint window_x, window_y;
+  gint toplevel_x, toplevel_y;
+  GdkRectangle extents;
+
+  g_return_if_fail (GAIL_IS_CANVAS_ITEM (component));
+  atk_gobj = ATK_GOBJECT_ACCESSIBLE (component);
+  obj = atk_gobject_accessible_get_object (atk_gobj);
+
+  if (obj == NULL)
+    /* item is defunct */
+    return;
+
+  /* Get the GnomeCanvasItem */
+  item = GNOME_CANVAS_ITEM (obj);
+
+  /* If this item has no parent canvas, something's broken */
+  g_return_if_fail (GTK_IS_WIDGET (item->canvas));
+
+  get_item_extents (item, &extents);
+  *width = extents.width;
+  *height = extents.height;
+  if (!is_item_in_window (item, &extents))
+    {
+      *x = G_MININT;
+      *y = G_MININT;
+      return;
+    }
+
+  gail_misc_get_origins (GTK_WIDGET (item->canvas), &window_x, &window_y,
+                        &toplevel_x, &toplevel_y);
+  *x = extents.x + window_x - toplevel_x;
+  *y = extents.y + window_y - toplevel_y;
+
+  /* If screen coordinates are requested, modify x and y appropriately */
+  if (coord_type == ATK_XY_SCREEN)
+    {
+      *x += toplevel_x;
+      *y += toplevel_y;
+    }
+  return;
+}
+
+static gint
+gail_canvas_item_get_mdi_zorder (AtkComponent *component)
+{
+  g_return_val_if_fail (ATK_OBJECT (component), -1);
+
+  return gail_canvas_item_get_index_in_parent (ATK_OBJECT (component));
+}
+
+static gboolean
+gail_canvas_item_grab_focus (AtkComponent *component)
+{
+  AtkGObjectAccessible *atk_gobj;
+  GObject *obj;
+  GnomeCanvasItem *item;
+  GtkWidget *toplevel;
+
+  g_return_val_if_fail (GAIL_IS_CANVAS_ITEM (component), FALSE);
+  atk_gobj = ATK_GOBJECT_ACCESSIBLE (component);
+  obj = atk_gobject_accessible_get_object (atk_gobj);
+
+  /* Get the GnomeCanvasItem */
+  item = GNOME_CANVAS_ITEM (obj);
+  if (item == NULL)
+    /* item is defunct */
+    return FALSE;
+
+  gnome_canvas_item_grab_focus (item);
+  toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->canvas));
+  if (gtk_widget_is_toplevel (toplevel))
+    gtk_window_present (GTK_WINDOW (toplevel));
+
+  return TRUE;
+}
+
+static void
+gail_canvas_item_remove_focus_handler (AtkComponent *component,
+                                       guint handler_id)
+{
+  g_signal_handler_disconnect (ATK_OBJECT (component), handler_id);
+}
+
+static gboolean
+is_item_on_screen (GnomeCanvasItem *item)
+{
+  GdkRectangle extents;
+
+  get_item_extents (item, &extents);
+  return is_item_in_window (item, &extents);
+}
+
+static void
+get_item_extents (GnomeCanvasItem *item,
+                  GdkRectangle *extents)
+{
+  double x1, x2, y1, y2;
+  cairo_matrix_t i2c;
+
+  x1 = y1 = x2 = y2 = 0.0;
+
+  if (GNOME_CANVAS_ITEM_CLASS (G_OBJECT_GET_CLASS (item))->bounds)
+    GNOME_CANVAS_ITEM_CLASS (G_OBJECT_GET_CLASS (item))->bounds (
+      item, &x1, &y1, &x2, &y2);
+
+  /* Get the item coordinates -> canvas pixel coordinates affine */
+
+  gnome_canvas_item_i2c_matrix (item, &i2c);
+  gnome_canvas_matrix_transform_rect (&i2c, &x1, &y1, &x2, &y2);
+
+  extents->x = floor (x1);
+  extents->y = floor (y1);
+  extents->width = ceil (x2) - extents->x;
+  extents->height = ceil (y2) - extents->y;
+}
+
+static gboolean
+is_item_in_window (GnomeCanvasItem *item,
+                   const GdkRectangle *extents)
+{
+  GtkWidget *widget;
+  GdkWindow *window;
+  gboolean retval;
+
+  widget = GTK_WIDGET (item->canvas);
+  window = gtk_widget_get_window (widget);
+  if (window)
+    {
+      GdkRectangle window_rect;
+
+      window_rect.x = 0;
+      window_rect.y = 0;
+      window_rect.width = gdk_window_get_width (window);
+      window_rect.height = gdk_window_get_height (window);
+
+      retval = gdk_rectangle_intersect (extents, &window_rect, NULL);
+    }
+  else
+    {
+      retval = FALSE;
+    }
+  return retval;
+}
diff --git a/src/libgnomecanvas/gailcanvasitem.h b/src/libgnomecanvas/gailcanvasitem.h
new file mode 100644
index 00000000..e931afef
--- /dev/null
+++ b/src/libgnomecanvas/gailcanvasitem.h
@@ -0,0 +1,51 @@
+/* GAIL - The GNOME Accessibility Implementation Library
+ * Copyright 2001 Sun Microsystems Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GAIL_CANVAS_ITEM_H__
+#define __GAIL_CANVAS_ITEM_H__
+
+#include <libgnomecanvas/gnome-canvas.h>
+#include <atk/atk.h>
+
+G_BEGIN_DECLS
+
+#define GAIL_TYPE_CANVAS_ITEM                  (gail_canvas_item_get_type ())
+#define GAIL_CANVAS_ITEM(obj)                  (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAIL_TYPE_CANVAS_ITEM, 
GailCanvasItem))
+#define GAIL_CANVAS_ITEM_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST ((klass), GAIL_TYPE_CANVAS_ITEM, 
GailCanvasItemClass))
+#define GAIL_IS_CANVAS_ITEM(obj)               (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAIL_TYPE_CANVAS_ITEM))
+#define GAIL_IS_CANVAS_ITEM_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE ((klass), GAIL_TYPE_CANVAS_ITEM))
+#define GAIL_CANVAS_ITEM_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS ((obj), GAIL_TYPE_CANVAS_ITEM, 
GailCanvasItemClass))
+
+typedef struct _GailCanvasItem                 GailCanvasItem;
+typedef struct _GailCanvasItemClass            GailCanvasItemClass;
+
+struct _GailCanvasItem
+{
+  AtkGObjectAccessible parent;
+};
+
+GType gail_canvas_item_get_type (void);
+
+struct _GailCanvasItemClass
+{
+  AtkGObjectAccessibleClass parent_class;
+};
+
+AtkObject * gail_canvas_item_new (GObject *obj);
+
+G_END_DECLS
+
+#endif /* __GAIL_CANVAS_ITEM_H__ */
diff --git a/src/libgnomecanvas/gailcanvasitemfactory.c b/src/libgnomecanvas/gailcanvasitemfactory.c
new file mode 100644
index 00000000..71044528
--- /dev/null
+++ b/src/libgnomecanvas/gailcanvasitemfactory.c
@@ -0,0 +1,56 @@
+/* GAIL - The GNOME Accessibility Implementation Library
+ * Copyright 2001 Sun Microsystems Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "evolution-config.h"
+
+#include <gtk/gtk.h>
+#include "gailcanvasitemfactory.h"
+#include "gailcanvasitem.h"
+
+static AtkObject * gail_canvas_item_factory_create_accessible (GObject *obj);
+
+static GType gail_canvas_item_factory_get_accessible_type (void);
+
+G_DEFINE_TYPE (GailCanvasItemFactory,
+              gail_canvas_item_factory,
+              ATK_TYPE_OBJECT_FACTORY);
+
+static void
+gail_canvas_item_factory_init (GailCanvasItemFactory *foo)
+{
+  ;
+}
+
+static void
+gail_canvas_item_factory_class_init (GailCanvasItemFactoryClass *klass)
+{
+  AtkObjectFactoryClass *class = ATK_OBJECT_FACTORY_CLASS (klass);
+
+  class->create_accessible = gail_canvas_item_factory_create_accessible;
+  class->get_accessible_type = gail_canvas_item_factory_get_accessible_type;
+}
+
+static AtkObject *
+gail_canvas_item_factory_create_accessible (GObject *obj)
+{
+  return gail_canvas_item_new (obj);
+}
+
+static GType
+gail_canvas_item_factory_get_accessible_type (void)
+{
+  return GAIL_TYPE_CANVAS_ITEM;
+}
diff --git a/src/libgnomecanvas/gailcanvasitemfactory.h b/src/libgnomecanvas/gailcanvasitemfactory.h
new file mode 100644
index 00000000..180ad94e
--- /dev/null
+++ b/src/libgnomecanvas/gailcanvasitemfactory.h
@@ -0,0 +1,49 @@
+/* GAIL - The GNOME Accessibility Implementation Library
+ * Copyright 2001 Sun Microsystems Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GAIL_CANVAS_ITEM_FACTORY_H__
+#define __GAIL_CANVAS_ITEM_FACTORY_H__
+
+#include <atk/atkobjectfactory.h>
+
+G_BEGIN_DECLS
+
+#define GAIL_TYPE_CANVAS_ITEM_FACTORY                 (gail_canvas_item_factory_get_type ())
+#define GAIL_CANVAS_ITEM_FACTORY(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GAIL_TYPE_CANVAS_ITEM_FACTORY, GailCanvasItemFactory))
+#define GAIL_CANVAS_ITEM_FACTORY_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), 
GAIL_TYPE_CANVAS_ITEM_FACTORY, GailCanvasItemFactoryClass))
+#define GAIL_IS_CANVAS_ITEM_FACTORY(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GAIL_TYPE_CANVAS_ITEM_FACTORY))
+#define GAIL_IS_CANVAS_ITEM_FACTORY_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), 
GAIL_TYPE_CANVAS_ITEM_FACTORY))
+#define GAIL_CANVAS_ITEM_FACTORY_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), 
GAIL_TYPE_CANVAS_ITEM_FACTORY, GailCanvasItemFactoryClass))
+
+typedef struct _GailCanvasItemFactory                GailCanvasItemFactory;
+typedef struct _GailCanvasItemFactoryClass           GailCanvasItemFactoryClass;
+
+struct _GailCanvasItemFactory
+{
+  AtkObjectFactory parent;
+};
+
+struct _GailCanvasItemFactoryClass
+{
+  AtkObjectFactoryClass parent_class;
+};
+
+GType gail_canvas_item_factory_get_type (void);
+
+G_END_DECLS
+
+#endif /* __GAIL_CANVAS_ITEM_FACTORY_H__ */
+
diff --git a/src/libgnomecanvas/gailcanvastext.c b/src/libgnomecanvas/gailcanvastext.c
new file mode 100644
index 00000000..4026bfd5
--- /dev/null
+++ b/src/libgnomecanvas/gailcanvastext.c
@@ -0,0 +1,514 @@
+/* GAIL - The GNOME Accessibility Implementation Library
+ * Copyright 2001 Sun Microsystems Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "evolution-config.h"
+
+#include <gtk/gtk.h>
+#include <libgnomecanvas/libgnomecanvas.h>
+#include "gailcanvasitem.h"
+#include "gailcanvastext.h"
+#include <libgail-util/gail-util.h>
+
+struct _GailCanvasText
+{
+  GailCanvasItem parent;
+  GailTextUtil *textutil;
+};
+
+static void           gail_canvas_text_text_interface_init (AtkTextIface        *iface);
+static gchar *         gail_canvas_text_get_text            (AtkText             *text,
+                                                            gint                start_offset,
+                                                            gint                end_offset);
+static gchar *         gail_canvas_text_get_text_after_offset
+                                                           (AtkText             *text,
+                                                            gint                offset,
+                                                            AtkTextBoundary     boundary_type,
+                                                            gint                *start_offset,
+                                                            gint                *end_offset);
+static gchar *         gail_canvas_text_get_text_at_offset  (AtkText             *text,
+                                                            gint                offset,
+                                                            AtkTextBoundary     boundary_type,
+                                                            gint                *start_offset,
+                                                            gint                *end_offset);
+static gchar *         gail_canvas_text_get_text_before_offset
+                                                           (AtkText             *text,
+                                                            gint                offset,
+                                                            AtkTextBoundary     boundary_type,
+                                                            gint                *start_offset,
+                                                            gint                *end_offset);
+static gunichar       gail_canvas_text_get_character_at_offset
+                                                            (AtkText            *text,
+                                                             gint               offset);
+static gint           gail_canvas_text_get_character_count  (AtkText            *text);
+static gint           gail_canvas_text_get_caret_offset     (AtkText            *text);
+static gboolean       gail_canvas_text_set_caret_offset     (AtkText            *text,
+                                                             gint               offset);
+static gint           gail_canvas_text_get_offset_at_point  (AtkText            *text,
+                                                             gint               x,
+                                                             gint               y,
+                                                             AtkCoordType       coords);
+static void           gail_canvas_text_get_character_extents (AtkText           *text,
+                                                              gint              offset,
+                                                              gint              *x,
+                                                              gint              *y,
+                                                              gint              *width,
+                                                              gint              *height,
+                                                              AtkCoordType      coords);
+static AtkAttributeSet *
+                      gail_canvas_text_get_run_attributes    (AtkText           *text,
+                                                              gint              offset,
+                                                              gint              *start_offset,
+                                                              gint              *end_offset);
+static AtkAttributeSet *
+                      gail_canvas_text_get_default_attributes (AtkText          *text);
+static gint           gail_canvas_text_get_n_selections      (AtkText           *text);
+static gchar *         gail_canvas_text_get_selection         (AtkText           *text,
+                                                              gint              selection_num,
+                                                              gint              *start_pos,
+                                                              gint              *end_pos);
+static gboolean       gail_canvas_text_add_selection         (AtkText           *text,
+                                                              gint              start_pos,
+                                                              gint              end_pos);
+static gboolean       gail_canvas_text_remove_selection      (AtkText           *text,
+                                                              gint              selection_num);
+static gboolean       gail_canvas_text_set_selection         (AtkText           *text,
+                                                              gint              selection_num,
+                                                              gint              start_pos,
+                                                              gint              end_pos);
+static gchar *         get_text_near_offset                   (AtkText           *text,
+                                                              GailOffsetType    function,
+                                                              AtkTextBoundary   boundary_type,
+                                                              gint              offset,
+                                                              gint              *start_offset,
+                                                              gint              *end_offset);
+
+G_DEFINE_TYPE_WITH_CODE (GailCanvasText,
+                       gail_canvas_text,
+                       GAIL_TYPE_CANVAS_ITEM,
+                       G_IMPLEMENT_INTERFACE (ATK_TYPE_TEXT,
+                                              gail_canvas_text_text_interface_init);)
+
+static void
+gail_canvas_text_init (GailCanvasText *foo)
+{
+  ;
+}
+
+AtkObject *
+gail_canvas_text_new (GObject *obj)
+{
+  gpointer object;
+  AtkObject *atk_object;
+  GailCanvasText *gail_text;
+
+  g_return_val_if_fail (GNOME_IS_CANVAS_ITEM (obj), NULL);
+  object = g_object_new (GAIL_TYPE_CANVAS_TEXT, NULL);
+  atk_object = ATK_OBJECT (object);
+  gail_text = GAIL_CANVAS_TEXT (object);
+
+  atk_object_initialize (atk_object, obj);
+  gail_text->textutil = gail_text_util_new ();
+
+  if (GNOME_IS_CANVAS_TEXT (obj))
+    {
+      gail_text_util_text_setup (gail_text->textutil,
+                                  GNOME_CANVAS_TEXT (obj)->text);
+    }
+
+  atk_object->role = ATK_ROLE_TEXT;
+  return atk_object;
+}
+
+static void
+gail_canvas_text_class_init (GailCanvasTextClass *klass)
+{
+}
+
+static void
+gail_canvas_text_text_interface_init (AtkTextIface *iface)
+{
+  g_return_if_fail (iface != NULL);
+
+  iface->get_text = gail_canvas_text_get_text;
+  iface->get_text_after_offset = gail_canvas_text_get_text_after_offset;
+  iface->get_text_at_offset = gail_canvas_text_get_text_at_offset;
+  iface->get_text_before_offset = gail_canvas_text_get_text_before_offset;
+  iface->get_character_at_offset = gail_canvas_text_get_character_at_offset;
+  iface->get_character_count = gail_canvas_text_get_character_count;
+  iface->get_caret_offset = gail_canvas_text_get_caret_offset;
+  iface->set_caret_offset = gail_canvas_text_set_caret_offset;
+  iface->get_offset_at_point = gail_canvas_text_get_offset_at_point;
+  iface->get_character_extents = gail_canvas_text_get_character_extents;
+  iface->get_n_selections = gail_canvas_text_get_n_selections;
+  iface->get_selection = gail_canvas_text_get_selection;
+  iface->add_selection = gail_canvas_text_add_selection;
+  iface->remove_selection = gail_canvas_text_remove_selection;
+  iface->set_selection = gail_canvas_text_set_selection;
+  iface->get_run_attributes = gail_canvas_text_get_run_attributes;
+  iface->get_default_attributes = gail_canvas_text_get_default_attributes;
+}
+
+static gchar *
+gail_canvas_text_get_text (AtkText *text,
+                           gint start_offset,
+                           gint end_offset)
+{
+  GailCanvasText *gail_text;
+  GtkTextBuffer *buffer;
+  GtkTextIter start, end;
+
+  g_return_val_if_fail (GAIL_IS_CANVAS_TEXT (text), NULL);
+  gail_text = GAIL_CANVAS_TEXT (text);
+  g_return_val_if_fail (gail_text->textutil, NULL);
+
+  buffer = gail_text->textutil->buffer;
+  gtk_text_buffer_get_iter_at_offset (buffer, &start, start_offset);
+  gtk_text_buffer_get_iter_at_offset (buffer, &end, end_offset);
+
+  return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
+}
+
+static gchar *
+gail_canvas_text_get_text_after_offset (AtkText *text,
+                                        gint offset,
+                                        AtkTextBoundary boundary_type,
+                                        gint *start_offset,
+                                        gint *end_offset)
+{
+  return get_text_near_offset (text, GAIL_AFTER_OFFSET,
+                              boundary_type, offset,
+                              start_offset, end_offset);
+}
+
+static gchar *
+gail_canvas_text_get_text_at_offset (AtkText *text,
+                                     gint offset,
+                                     AtkTextBoundary boundary_type,
+                                     gint *start_offset,
+                                     gint *end_offset)
+{
+  return get_text_near_offset (text, GAIL_AT_OFFSET,
+                              boundary_type, offset,
+                              start_offset, end_offset);
+}
+
+static gchar *
+gail_canvas_text_get_text_before_offset (AtkText *text,
+                                         gint offset,
+                                         AtkTextBoundary boundary_type,
+                                         gint *start_offset,
+                                         gint *end_offset)
+{
+  return get_text_near_offset (text, GAIL_BEFORE_OFFSET,
+                              boundary_type, offset,
+                              start_offset, end_offset);
+}
+
+static gunichar
+gail_canvas_text_get_character_at_offset (AtkText *text,
+                                          gint offset)
+{
+  GailCanvasText *gail_item;
+  GtkTextIter start, end;
+  GtkTextBuffer *buffer;
+  gchar *string;
+  gchar *index;
+  gunichar unichar;
+
+  g_return_val_if_fail (GAIL_IS_CANVAS_TEXT (text), '\0');
+  gail_item = GAIL_CANVAS_TEXT (text);
+  buffer = gail_item->textutil->buffer;
+  if (offset >= gtk_text_buffer_get_char_count (buffer))
+    return '\0';
+
+  gtk_text_buffer_get_start_iter (buffer, &start);
+  gtk_text_buffer_get_end_iter (buffer, &end);
+  string = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
+  index = g_utf8_offset_to_pointer (string, offset);
+
+  unichar = g_utf8_get_char (index);
+  g_free (string);
+  return unichar;
+}
+
+static gint
+gail_canvas_text_get_character_count (AtkText *text)
+{
+  GtkTextBuffer *buffer;
+  GailCanvasText *gail_text;
+
+  g_return_val_if_fail (GAIL_IS_CANVAS_TEXT (text), 0);
+  gail_text = GAIL_CANVAS_TEXT (text);
+  g_return_val_if_fail (gail_text->textutil, 0);
+  buffer = gail_text->textutil->buffer;
+  return gtk_text_buffer_get_char_count (buffer);
+}
+
+static gint
+gail_canvas_text_get_caret_offset (AtkText *text)
+{
+  GailCanvasText *gail_text;
+  GtkTextBuffer *buffer;
+  GtkTextMark *cursor_mark;
+  GtkTextIter cursor_itr;
+
+  g_return_val_if_fail (GAIL_IS_CANVAS_TEXT (text), 0);
+  gail_text = GAIL_CANVAS_TEXT (text);
+  g_return_val_if_fail (gail_text->textutil, 0);
+  buffer = gail_text->textutil->buffer;
+  cursor_mark = gtk_text_buffer_get_insert (buffer);
+  gtk_text_buffer_get_iter_at_mark (buffer, &cursor_itr, cursor_mark);
+  return gtk_text_iter_get_offset (&cursor_itr);
+}
+
+static gboolean
+gail_canvas_text_set_caret_offset (AtkText *text,
+                                   gint offset)
+{
+  GailCanvasText *gail_text;
+  GtkTextBuffer *buffer;
+  GtkTextIter pos_itr;
+
+  g_return_val_if_fail (GAIL_IS_CANVAS_TEXT (text), FALSE);
+  gail_text = GAIL_CANVAS_TEXT (text);
+  g_return_val_if_fail (gail_text->textutil, FALSE);
+  buffer = gail_text->textutil->buffer;
+  gtk_text_buffer_get_iter_at_offset (buffer,  &pos_itr, offset);
+  gtk_text_buffer_move_mark_by_name (buffer, "insert", &pos_itr);
+  return TRUE;
+}
+
+static gint
+gail_canvas_text_get_offset_at_point (AtkText *text,
+                                      gint x,
+                                      gint y,
+                                      AtkCoordType coords)
+{
+  return -1;
+}
+
+static void
+gail_canvas_text_get_character_extents (AtkText *text,
+                                        gint offset,
+                                        gint *x,
+                                        gint *y,
+                                        gint *width,
+                                        gint *height,
+                                        AtkCoordType coords)
+{
+  return;
+}
+
+static AtkAttributeSet *
+gail_canvas_text_get_run_attributes (AtkText *text,
+                                     gint offset,
+                                     gint *start_offset,
+                                     gint *end_offset)
+{
+  GailCanvasText *gail_text;
+
+  g_return_val_if_fail (GAIL_IS_CANVAS_TEXT (text), NULL);
+  gail_text = GAIL_CANVAS_TEXT (text);
+  g_return_val_if_fail (gail_text->textutil, NULL);
+
+  return gail_misc_buffer_get_run_attributes (gail_text->textutil->buffer,
+                                             offset, start_offset, end_offset);
+}
+
+static AtkAttributeSet *
+gail_canvas_text_get_default_attributes (AtkText *text)
+{
+  return NULL;
+}
+
+static gint
+gail_canvas_text_get_n_selections (AtkText *text)
+{
+  GailCanvasText *gail_text;
+  GtkTextBuffer *buffer;
+  GtkTextIter start, end;
+  gint select_start, select_end;
+
+  g_return_val_if_fail (GAIL_IS_CANVAS_TEXT (text), -1);
+  gail_text = GAIL_CANVAS_TEXT (text);
+  g_return_val_if_fail (gail_text->textutil, -1);
+  buffer = gail_text->textutil->buffer;
+
+  gtk_text_buffer_get_selection_bounds (buffer, &start, &end);
+  select_start = gtk_text_iter_get_offset (&start);
+  select_end = gtk_text_iter_get_offset (&end);
+
+  if (select_start != select_end)
+     return 1;
+  else
+     return 0;
+}
+
+static gchar *
+gail_canvas_text_get_selection (AtkText *text,
+                                gint selection_num,
+                                gint *start_pos,
+                                gint *end_pos)
+{
+  GailCanvasText *gail_text;
+  GtkTextBuffer *buffer;
+  GtkTextIter start, end;
+
+ /* Only let the user get the selection if one is set, and if the
+  * selection_num is 0.
+  */
+  if (selection_num != 0)
+     return NULL;
+
+  g_return_val_if_fail (GAIL_IS_CANVAS_TEXT (text), NULL);
+  gail_text = GAIL_CANVAS_TEXT (text);
+  g_return_val_if_fail (gail_text->textutil, NULL);
+  buffer = gail_text->textutil->buffer;
+
+  gtk_text_buffer_get_selection_bounds (buffer, &start, &end);
+  *start_pos = gtk_text_iter_get_offset (&start);
+  *end_pos = gtk_text_iter_get_offset (&end);
+
+  if (*start_pos != *end_pos)
+    return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
+  else
+    return NULL;
+}
+
+static gboolean
+gail_canvas_text_add_selection (AtkText *text,
+                                gint start_pos,
+                                gint end_pos)
+{
+  GailCanvasText *gail_text;
+  GtkTextBuffer *buffer;
+  GtkTextIter pos_itr;
+  GtkTextIter start, end;
+  gint select_start, select_end;
+
+  g_return_val_if_fail (GAIL_IS_CANVAS_TEXT (text), FALSE);
+  gail_text = GAIL_CANVAS_TEXT (text);
+  g_return_val_if_fail (gail_text->textutil, FALSE);
+  buffer = gail_text->textutil->buffer;
+
+  gtk_text_buffer_get_selection_bounds (buffer, &start, &end);
+  select_start = gtk_text_iter_get_offset (&start);
+  select_end = gtk_text_iter_get_offset (&end);
+
+ /* If there is already a selection, then don't allow another to be added,
+  * since GtkTextView only supports one selected region.
+  */
+  if (select_start == select_end)
+    {
+      gtk_text_buffer_get_iter_at_offset (buffer,  &pos_itr, start_pos);
+      gtk_text_buffer_move_mark_by_name (buffer, "insert", &pos_itr);
+      gtk_text_buffer_get_iter_at_offset (buffer,  &pos_itr, end_pos);
+      gtk_text_buffer_move_mark_by_name (buffer, "selection_bound", &pos_itr);
+      return TRUE;
+    }
+  else
+    return FALSE;
+}
+
+static gboolean
+gail_canvas_text_remove_selection (AtkText *text,
+                                 gint selection_num)
+{
+  GailCanvasText *gail_text;
+  GtkTextBuffer *buffer;
+  GtkTextMark *cursor_mark;
+  GtkTextIter cursor_itr;
+  GtkTextIter start, end;
+  gint select_start, select_end;
+
+  if (selection_num != 0)
+     return FALSE;
+
+  g_return_val_if_fail (GAIL_IS_CANVAS_TEXT (text), FALSE);
+  gail_text = GAIL_CANVAS_TEXT (text);
+  g_return_val_if_fail (gail_text->textutil, FALSE);
+  buffer = gail_text->textutil->buffer;
+
+  gtk_text_buffer_get_selection_bounds (buffer, &start, &end);
+  select_start = gtk_text_iter_get_offset (&start);
+  select_end = gtk_text_iter_get_offset (&end);
+
+  if (select_start != select_end)
+    {
+     /* Setting the start & end of the selected region to the caret position
+      * turns off the selection.
+      */
+      cursor_mark = gtk_text_buffer_get_insert (buffer);
+      gtk_text_buffer_get_iter_at_mark (buffer, &cursor_itr, cursor_mark);
+      gtk_text_buffer_move_mark_by_name (buffer, "insert", &cursor_itr);
+      gtk_text_buffer_move_mark_by_name (buffer, "selection_bound", &cursor_itr);
+      return TRUE;
+    }
+  else
+    return FALSE;
+}
+
+static gboolean
+gail_canvas_text_set_selection (AtkText *text,
+                              gint selection_num,
+                              gint start_pos,
+                              gint end_pos)
+{
+  GailCanvasText *gail_text;
+  GtkTextBuffer *buffer;
+  GtkTextIter pos_itr;
+  GtkTextIter start, end;
+  gint select_start, select_end;
+
+ /* Only let the user move the selection if one is set, and if the
+  * selection_num is 0
+  */
+  if (selection_num != 0)
+     return FALSE;
+
+  g_return_val_if_fail (GAIL_IS_CANVAS_TEXT (text), FALSE);
+  gail_text = GAIL_CANVAS_TEXT (text);
+  g_return_val_if_fail (gail_text->textutil, FALSE);
+  buffer = gail_text->textutil->buffer;
+
+  gtk_text_buffer_get_selection_bounds (buffer, &start, &end);
+  select_start = gtk_text_iter_get_offset (&start);
+  select_end = gtk_text_iter_get_offset (&end);
+
+  if (select_start != select_end)
+    {
+      gtk_text_buffer_get_iter_at_offset (buffer,  &pos_itr, start_pos);
+      gtk_text_buffer_move_mark_by_name (buffer, "insert", &pos_itr);
+      gtk_text_buffer_get_iter_at_offset (buffer,  &pos_itr, end_pos);
+      gtk_text_buffer_move_mark_by_name (buffer, "selection_bound", &pos_itr);
+      return TRUE;
+    }
+  else
+    return FALSE;
+}
+
+static gchar *
+get_text_near_offset (AtkText *text,
+                      GailOffsetType function,
+                      AtkTextBoundary boundary_type,
+                      gint offset,
+                      gint *start_offset,
+                      gint *end_offset)
+{
+  return gail_text_util_get_text (GAIL_CANVAS_TEXT (text)->textutil, NULL,
+                                 function, boundary_type, offset,
+                                 start_offset, end_offset);
+}
diff --git a/src/libgnomecanvas/gailcanvastext.h b/src/libgnomecanvas/gailcanvastext.h
new file mode 100644
index 00000000..b3ef38ae
--- /dev/null
+++ b/src/libgnomecanvas/gailcanvastext.h
@@ -0,0 +1,49 @@
+/* GAIL - The GNOME Accessibility Implementation Library
+ * Copyright 2001 Sun Microsystems Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GAIL_CANVAS_TEXT_H__
+#define __GAIL_CANVAS_TEXT_H__
+
+#include <libgnomecanvas/libgnomecanvas.h>
+#include <atk/atk.h>
+#include "gailcanvasitem.h"
+#include <libgail-util/gailtextutil.h>
+
+G_BEGIN_DECLS
+
+#define GAIL_TYPE_CANVAS_TEXT                  (gail_canvas_text_get_type ())
+#define GAIL_CANVAS_TEXT(obj)                  (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAIL_TYPE_CANVAS_TEXT, 
GailCanvasText))
+#define GAIL_CANVAS_TEXT_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST ((klass), GAIL_TYPE_CANVAS_TEXT, 
GailCanvasTextClass))
+#define GAIL_IS_CANVAS_TEXT(obj)               (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAIL_TYPE_CANVAS_TEXT))
+#define GAIL_IS_CANVAS_TEXT_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE ((klass), GAIL_TYPE_CANVAS_TEXT))
+#define GAIL_CANVAS_TEXT_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS ((obj), GAIL_TYPE_CANVAS_TEXT, 
GailCanvasTextClass))
+
+typedef struct _GailCanvasText                 GailCanvasText;
+typedef struct _GailCanvasTextClass            GailCanvasTextClass;
+
+GType
+gail_canvas_text_get_type (void);
+
+struct _GailCanvasTextClass
+{
+  GailCanvasItemClass parent_class;
+};
+
+AtkObject * gail_canvas_text_new (GObject *obj);
+
+G_END_DECLS
+
+#endif /* __GAIL_CANVAS_TEXT_H__ */
diff --git a/src/libgnomecanvas/gailcanvastextfactory.c b/src/libgnomecanvas/gailcanvastextfactory.c
new file mode 100644
index 00000000..6d0f3bd5
--- /dev/null
+++ b/src/libgnomecanvas/gailcanvastextfactory.c
@@ -0,0 +1,56 @@
+/* GAIL - The GNOME Accessibility Implementation Library
+ * Copyright 2001 Sun Microsystems Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "evolution-config.h"
+
+#include <gtk/gtk.h>
+#include "gailcanvastextfactory.h"
+#include "gailcanvastext.h"
+
+static AtkObject * gail_canvas_text_factory_create_accessible (GObject *obj);
+
+static GType gail_canvas_text_factory_get_accessible_type (void);
+
+G_DEFINE_TYPE (GailCanvasTextFactory,
+              gail_canvas_text_factory,
+              ATK_TYPE_OBJECT_FACTORY);
+
+static void
+gail_canvas_text_factory_init (GailCanvasTextFactory *foo)
+{
+  ;
+}
+
+static void
+gail_canvas_text_factory_class_init (GailCanvasTextFactoryClass *klass)
+{
+  AtkObjectFactoryClass *class = ATK_OBJECT_FACTORY_CLASS (klass);
+
+  class->create_accessible = gail_canvas_text_factory_create_accessible;
+  class->get_accessible_type = gail_canvas_text_factory_get_accessible_type;
+}
+
+static AtkObject *
+gail_canvas_text_factory_create_accessible (GObject *obj)
+{
+  return gail_canvas_text_new (obj);
+}
+
+static GType
+gail_canvas_text_factory_get_accessible_type (void)
+{
+  return GAIL_TYPE_CANVAS_TEXT;
+}
diff --git a/src/libgnomecanvas/gailcanvastextfactory.h b/src/libgnomecanvas/gailcanvastextfactory.h
new file mode 100644
index 00000000..52db7dd2
--- /dev/null
+++ b/src/libgnomecanvas/gailcanvastextfactory.h
@@ -0,0 +1,49 @@
+/* GAIL - The GNOME Accessibility Implementation Library
+ * Copyright 2001 Sun Microsystems Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GAIL_CANVAS_TEXT_FACTORY_H__
+#define __GAIL_CANVAS_TEXT_FACTORY_H__
+
+#include <atk/atkobjectfactory.h>
+
+G_BEGIN_DECLS
+
+#define GAIL_TYPE_CANVAS_TEXT_FACTORY                 (gail_canvas_text_factory_get_type ())
+#define GAIL_CANVAS_TEXT_FACTORY(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GAIL_TYPE_CANVAS_TEXT_FACTORY, GailCanvasTextFactory))
+#define GAIL_CANVAS_TEXT_FACTORY_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), 
GAIL_TYPE_CANVAS_TEXT_FACTORY, GailCanvasTextFactoryClass))
+#define GAIL_IS_CANVAS_TEXT_FACTORY(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GAIL_TYPE_CANVAS_TEXT_FACTORY))
+#define GAIL_IS_CANVAS_TEXT_FACTORY_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), 
GAIL_TYPE_CANVAS_TEXT_FACTORY))
+#define GAIL_CANVAS_TEXT_FACTORY_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), 
GAIL_TYPE_CANVAS_TEXT_FACTORY, GailCanvasTextFactoryClass))
+
+typedef struct _GailCanvasTextFactory                GailCanvasTextFactory;
+typedef struct _GailCanvasTextFactoryClass           GailCanvasTextFactoryClass;
+
+struct _GailCanvasTextFactory
+{
+  AtkObjectFactory parent;
+};
+
+struct _GailCanvasTextFactoryClass
+{
+  AtkObjectFactoryClass parent_class;
+};
+
+GType gail_canvas_text_factory_get_type (void);
+
+G_END_DECLS
+
+#endif /* __GAIL_CANVAS_TEXT_FACTORY_H__ */
+
diff --git a/src/libgnomecanvas/gailcanvaswidget.c b/src/libgnomecanvas/gailcanvaswidget.c
new file mode 100644
index 00000000..4ec3efad
--- /dev/null
+++ b/src/libgnomecanvas/gailcanvaswidget.c
@@ -0,0 +1,114 @@
+/* GAIL - The GNOME Accessibility Implementation Library
+ * Copyright 2001 Sun Microsystems Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "evolution-config.h"
+
+#include <gtk/gtk.h>
+#include <libgnomecanvas/gnome-canvas.h>
+#include <libgnomecanvas/gnome-canvas-widget.h>
+#include "gailcanvaswidget.h"
+
+static gint    gail_canvas_widget_get_n_children
+                                               (AtkObject *obj);
+static AtkObject *
+               gail_canvas_widget_ref_child    (AtkObject *obj,
+                                                 gint i);
+
+G_DEFINE_TYPE (GailCanvasWidget,
+              gail_canvas_widget,
+              GAIL_TYPE_CANVAS_ITEM);
+
+static void
+gail_canvas_widget_init (GailCanvasWidget *foo)
+{
+  ;
+}
+
+AtkObject *
+gail_canvas_widget_new (GObject *obj)
+{
+  gpointer object;
+  AtkObject *atk_object;
+
+  g_return_val_if_fail (GNOME_IS_CANVAS_WIDGET (obj), NULL);
+  object = g_object_new (GAIL_TYPE_CANVAS_WIDGET, NULL);
+  atk_object = ATK_OBJECT (object);
+  atk_object_initialize (atk_object, obj);
+  atk_object->role = ATK_ROLE_PANEL;
+  return atk_object;
+}
+
+static void
+gail_canvas_widget_class_init (GailCanvasWidgetClass *klass)
+{
+  AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
+
+  class->get_n_children = gail_canvas_widget_get_n_children;
+  class->ref_child = gail_canvas_widget_ref_child;
+}
+
+static gint
+gail_canvas_widget_get_n_children (AtkObject *obj)
+{
+  AtkGObjectAccessible *atk_gobj;
+  GnomeCanvasWidget *canvas_widget;
+  GObject *g_obj;
+
+  g_return_val_if_fail (GAIL_IS_CANVAS_WIDGET (obj), 0);
+
+  atk_gobj = ATK_GOBJECT_ACCESSIBLE (obj);
+  g_obj = atk_gobject_accessible_get_object (atk_gobj);
+  if (g_obj == NULL)
+    /* State is defunct */
+    return 0;
+
+  g_return_val_if_fail (GNOME_IS_CANVAS_WIDGET (g_obj), 0);
+
+  canvas_widget = GNOME_CANVAS_WIDGET (g_obj);
+  g_return_val_if_fail (canvas_widget->widget, 0);
+  return 1;
+}
+
+static AtkObject *
+gail_canvas_widget_ref_child (AtkObject *obj,
+                              gint i)
+{
+  AtkGObjectAccessible *atk_gobj;
+  GnomeCanvasWidget *canvas_widget;
+  GObject *g_obj;
+  AtkObject *atk_child;
+
+  g_return_val_if_fail (GAIL_IS_CANVAS_WIDGET (obj), NULL);
+
+  if (i != 0)
+    return NULL;
+
+  atk_gobj = ATK_GOBJECT_ACCESSIBLE (obj);
+  g_obj = atk_gobject_accessible_get_object (atk_gobj);
+  if (g_obj == NULL)
+    /* State is defunct */
+    return NULL;
+
+  g_return_val_if_fail (GNOME_IS_CANVAS_WIDGET (g_obj), NULL);
+
+  canvas_widget = GNOME_CANVAS_WIDGET (g_obj);
+  g_return_val_if_fail (canvas_widget->widget, NULL);
+
+  atk_child = gtk_widget_get_accessible (canvas_widget->widget);
+  g_object_ref (atk_child);
+  atk_object_set_parent (atk_child, obj);
+  return atk_child;
+}
diff --git a/src/libgnomecanvas/gailcanvaswidget.h b/src/libgnomecanvas/gailcanvaswidget.h
new file mode 100644
index 00000000..2351ec5f
--- /dev/null
+++ b/src/libgnomecanvas/gailcanvaswidget.h
@@ -0,0 +1,52 @@
+/* GAIL - The GNOME Accessibility Implementation Library
+ * Copyright 2001 Sun Microsystems Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GAIL_CANVAS_WIDGET_H__
+#define __GAIL_CANVAS_WIDGET_H__
+
+#include <libgnomecanvas/gnome-canvas.h>
+#include <atk/atk.h>
+#include "gailcanvasitem.h"
+
+G_BEGIN_DECLS
+
+#define GAIL_TYPE_CANVAS_WIDGET                  (gail_canvas_widget_get_type ())
+#define GAIL_CANVAS_WIDGET(obj)                  (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GAIL_TYPE_CANVAS_WIDGET, GailCanvasWidget))
+#define GAIL_CANVAS_WIDGET_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST ((klass), GAIL_TYPE_CANVAS_WIDGET, 
GailCanvasWidgetClass))
+#define GAIL_IS_CANVAS_WIDGET(obj)               (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GAIL_TYPE_CANVAS_WIDGET))
+#define GAIL_IS_CANVAS_WIDGET_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE ((klass), GAIL_TYPE_CANVAS_WIDGET))
+#define GAIL_CANVAS_WIDGET_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS ((obj), GAIL_TYPE_CANVAS_WIDGET, 
GailCanvasWidgetClass))
+
+typedef struct _GailCanvasWidget                 GailCanvasWidget;
+typedef struct _GailCanvasWidgetClass            GailCanvasWidgetClass;
+
+struct _GailCanvasWidget
+{
+  GailCanvasItem parent;
+};
+
+GType gail_canvas_widget_get_type (void);
+
+struct _GailCanvasWidgetClass
+{
+  GailCanvasItemClass parent_class;
+};
+
+AtkObject * gail_canvas_widget_new (GObject *obj);
+
+G_END_DECLS
+
+#endif /* __GAIL_CANVAS_WIDGET_H__ */
diff --git a/src/libgnomecanvas/gailcanvaswidgetfactory.c b/src/libgnomecanvas/gailcanvaswidgetfactory.c
new file mode 100644
index 00000000..27b3ca4f
--- /dev/null
+++ b/src/libgnomecanvas/gailcanvaswidgetfactory.c
@@ -0,0 +1,55 @@
+/* GAIL - The GNOME Accessibility Implementation Library
+ * Copyright 2001 Sun Microsystems Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "evolution-config.h"
+
+#include "gailcanvaswidgetfactory.h"
+#include "gailcanvaswidget.h"
+
+static AtkObject * gail_canvas_widget_factory_create_accessible (GObject *obj);
+
+static GType gail_canvas_widget_factory_get_accessible_type (void);
+
+G_DEFINE_TYPE (GailCanvasWidgetFactory,
+              gail_canvas_widget_factory,
+              ATK_TYPE_OBJECT_FACTORY);
+
+static void
+gail_canvas_widget_factory_init (GailCanvasWidgetFactory *foo)
+{
+  ;
+}
+
+static void
+gail_canvas_widget_factory_class_init (GailCanvasWidgetFactoryClass *klass)
+{
+  AtkObjectFactoryClass *class = ATK_OBJECT_FACTORY_CLASS (klass);
+
+  class->create_accessible = gail_canvas_widget_factory_create_accessible;
+  class->get_accessible_type = gail_canvas_widget_factory_get_accessible_type;
+}
+
+static AtkObject *
+gail_canvas_widget_factory_create_accessible (GObject *obj)
+{
+  return gail_canvas_widget_new (obj);
+}
+
+static GType
+gail_canvas_widget_factory_get_accessible_type (void)
+{
+  return GAIL_TYPE_CANVAS_WIDGET;
+}
diff --git a/src/libgnomecanvas/gailcanvaswidgetfactory.h b/src/libgnomecanvas/gailcanvaswidgetfactory.h
new file mode 100644
index 00000000..22ca54f1
--- /dev/null
+++ b/src/libgnomecanvas/gailcanvaswidgetfactory.h
@@ -0,0 +1,49 @@
+/* GAIL - The GNOME Accessibility Implementation Library
+ * Copyright 2001 Sun Microsystems Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GAIL_CANVAS_WIDGET_FACTORY_H__
+#define __GAIL_CANVAS_WIDGET_FACTORY_H__
+
+#include <atk/atkobjectfactory.h>
+
+G_BEGIN_DECLS
+
+#define GAIL_TYPE_CANVAS_WIDGET_FACTORY                 (gail_canvas_widget_factory_get_type ())
+#define GAIL_CANVAS_WIDGET_FACTORY(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GAIL_TYPE_CANVAS_WIDGET_FACTORY, GailCanvasWidgetFactory))
+#define GAIL_CANVAS_WIDGET_FACTORY_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), 
GAIL_TYPE_CANVAS_WIDGET_FACTORY, GailCanvasWidgetFactoryClass))
+#define GAIL_IS_CANVAS_WIDGET_FACTORY(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GAIL_TYPE_CANVAS_WIDGET_FACTORY))
+#define GAIL_IS_CANVAS_WIDGET_FACTORY_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), 
GAIL_TYPE_CANVAS_WIDGET_FACTORY))
+#define GAIL_CANVAS_WIDGET_FACTORY_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), 
GAIL_TYPE_CANVAS_WIDGET_FACTORY, GailCanvasWidgetFactoryClass))
+
+typedef struct _GailCanvasWidgetFactory                GailCanvasWidgetFactory;
+typedef struct _GailCanvasWidgetFactoryClass           GailCanvasWidgetFactoryClass;
+
+struct _GailCanvasWidgetFactory
+{
+  AtkObjectFactory parent;
+};
+
+struct _GailCanvasWidgetFactoryClass
+{
+  AtkObjectFactoryClass parent_class;
+};
+
+GType gail_canvas_widget_factory_get_type (void);
+
+G_END_DECLS
+
+#endif /* __GAIL_CANVAS_WIDGET_FACTORY_H__ */
+
diff --git a/src/libgnomecanvas/gnome-canvas-i18n.h b/src/libgnomecanvas/gnome-canvas-i18n.h
new file mode 100644
index 00000000..27a283cd
--- /dev/null
+++ b/src/libgnomecanvas/gnome-canvas-i18n.h
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation
+ * All rights reserved.
+ *
+ * This file is part of the Gnome Library.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * published by the Free Software Foundation; either the
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * License along with the Gnome Library; see the file COPYING.LIB.  If not,
+ */
+/*
+  @NOTATION@
+ */
+
+/*
+ * Handles all of the internationalization configuration options.
+ * Author: Tom Tromey <tromey creche cygnus com>
+ */
+
+#ifndef __LIBGNOME_CANVAS_I18N_H__
+#define __LIBGNOME_CANVAS_I18N_H__ 
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+#if !defined(__LIBGNOME_CANVAS_I18NP_H__)
+
+#ifdef ENABLE_NLS
+#    include <libintl.h>
+#    ifdef GNOME_EXPLICIT_TRANSLATION_DOMAIN
+#        undef _
+#        define _(String) dgettext (GNOME_EXPLICIT_TRANSLATION_DOMAIN, String)
+#    else
+#        define _(String) gettext (String)
+#    endif
+#    ifdef gettext_noop
+#        define N_(String) gettext_noop (String)
+#    else
+#        define N_(String) (String)
+#    endif
+#else
+/* Stubs that do something close enough.  */
+#    define textdomain(String) (String)
+#    define gettext(String) (String)
+#    define dgettext(Domain,Message) (Message)
+#    define dcgettext(Domain,Message,Type) (Message)
+#    define bindtextdomain(Domain,Directory) (Domain)
+#    define _(String) (String)
+#    define N_(String) (String)
+#endif
+
+#endif
+
+G_END_DECLS
+
+#endif /* __LIBGNOME_CANVAS_I18N_H__ */
diff --git a/src/libgnomecanvas/gnome-canvas-pixbuf.c b/src/libgnomecanvas/gnome-canvas-pixbuf.c
new file mode 100644
index 00000000..651b302c
--- /dev/null
+++ b/src/libgnomecanvas/gnome-canvas-pixbuf.c
@@ -0,0 +1,345 @@
+/* GNOME libraries - GdkPixbuf item for the GNOME canvas
+ *
+ * Copyright (C) 1999 The Free Software Foundation
+ *
+ * Author: Federico Mena-Quintero <federico gimp org>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "evolution-config.h"
+
+#include <math.h>
+#include <libgnomecanvas/gnome-canvas.h>
+#include <libgnomecanvas/gnome-canvas-util.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
+#include "gnome-canvas-pixbuf.h"
+
+#define GNOME_CANVAS_PIXBUF_GET_PRIVATE(obj) \
+       (G_TYPE_INSTANCE_GET_PRIVATE \
+       ((obj), GNOME_TYPE_CANVAS_PIXBUF, GnomeCanvasPixbufPrivate))
+
+/* Private part of the GnomeCanvasPixbuf structure */
+struct _GnomeCanvasPixbufPrivate {
+       /* Our gdk-pixbuf */
+       GdkPixbuf *pixbuf;
+};
+
+/* Object argument IDs */
+enum {
+       PROP_0,
+       PROP_PIXBUF
+};
+
+static void gnome_canvas_pixbuf_dispose (GnomeCanvasItem *object);
+static void gnome_canvas_pixbuf_set_property (GObject *object,
+                                             guint param_id,
+                                             const GValue *value,
+                                             GParamSpec *pspec);
+static void gnome_canvas_pixbuf_get_property (GObject *object,
+                                             guint param_id,
+                                             GValue *value,
+                                             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, cairo_t *cr,
+                                     gint x, gint y, gint width, gint height);
+static GnomeCanvasItem *gnome_canvas_pixbuf_point (GnomeCanvasItem *item,
+                                                   gdouble x,
+                                                   gdouble y,
+                                                   gint cx,
+                                                   gint cy);
+static void gnome_canvas_pixbuf_bounds (GnomeCanvasItem *item,
+                                       gdouble *x1, gdouble *y1, gdouble *x2, gdouble *y2);
+
+G_DEFINE_TYPE (GnomeCanvasPixbuf, gnome_canvas_pixbuf, GNOME_TYPE_CANVAS_ITEM)
+
+/* Class initialization function for the pixbuf canvas item */
+static void
+gnome_canvas_pixbuf_class_init (GnomeCanvasPixbufClass *class)
+{
+       GObjectClass *gobject_class;
+       GnomeCanvasItemClass *item_class;
+
+       gobject_class = (GObjectClass *) class;
+       item_class = (GnomeCanvasItemClass *) class;
+
+       gobject_class->set_property = gnome_canvas_pixbuf_set_property;
+       gobject_class->get_property = gnome_canvas_pixbuf_get_property;
+
+       g_object_class_install_property
+               (gobject_class,
+                PROP_PIXBUF,
+                g_param_spec_object ("pixbuf", NULL, NULL,
+                                     GDK_TYPE_PIXBUF,
+                                     (G_PARAM_READABLE | G_PARAM_WRITABLE)));
+
+       item_class->dispose = gnome_canvas_pixbuf_dispose;
+       item_class->update = gnome_canvas_pixbuf_update;
+       item_class->draw = gnome_canvas_pixbuf_draw;
+       item_class->point = gnome_canvas_pixbuf_point;
+       item_class->bounds = gnome_canvas_pixbuf_bounds;
+
+       g_type_class_add_private (class, sizeof (GnomeCanvasPixbufPrivate));
+}
+
+/* Object initialization function for the pixbuf canvas item */
+static void
+gnome_canvas_pixbuf_init (GnomeCanvasPixbuf *gcp)
+{
+       gcp->priv = GNOME_CANVAS_PIXBUF_GET_PRIVATE (gcp);
+}
+
+/* Dispose handler for the pixbuf canvas item */
+static void
+gnome_canvas_pixbuf_dispose (GnomeCanvasItem *object)
+{
+       GnomeCanvasPixbuf *gcp;
+       GnomeCanvasPixbufPrivate *priv;
+
+       g_return_if_fail (object != NULL);
+       g_return_if_fail (GNOME_IS_CANVAS_PIXBUF (object));
+
+       gcp = GNOME_CANVAS_PIXBUF (object);
+       priv = gcp->priv;
+
+       g_clear_object (&priv->pixbuf);
+
+       if (GNOME_CANVAS_ITEM_CLASS (gnome_canvas_pixbuf_parent_class)->dispose)
+               GNOME_CANVAS_ITEM_CLASS (gnome_canvas_pixbuf_parent_class)->dispose (object);
+}
+
+/* Set_property handler for the pixbuf canvas item */
+static void
+gnome_canvas_pixbuf_set_property (GObject *object,
+                                  guint param_id,
+                                  const GValue *value,
+                                  GParamSpec *pspec)
+{
+       GnomeCanvasItem *item;
+       GnomeCanvasPixbuf *gcp;
+       GnomeCanvasPixbufPrivate *priv;
+       GdkPixbuf *pixbuf;
+
+       g_return_if_fail (object != NULL);
+       g_return_if_fail (GNOME_IS_CANVAS_PIXBUF (object));
+
+       item = GNOME_CANVAS_ITEM (object);
+       gcp = GNOME_CANVAS_PIXBUF (object);
+       priv = gcp->priv;
+
+       switch (param_id) {
+       case PROP_PIXBUF:
+               pixbuf = g_value_get_object (value);
+               if (pixbuf != priv->pixbuf) {
+                       if (priv->pixbuf)
+                               g_object_unref (priv->pixbuf);
+
+                       priv->pixbuf = g_object_ref (pixbuf);
+               }
+
+               gnome_canvas_item_request_update (item);
+               break;
+
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+               break;
+       }
+}
+
+/* Get_property handler for the pixbuf canvasi item */
+static void
+gnome_canvas_pixbuf_get_property (GObject *object,
+                                  guint param_id,
+                                  GValue *value,
+                                  GParamSpec *pspec)
+{
+       GnomeCanvasPixbuf *gcp;
+       GnomeCanvasPixbufPrivate *priv;
+
+       g_return_if_fail (object != NULL);
+       g_return_if_fail (GNOME_IS_CANVAS_PIXBUF (object));
+
+       gcp = GNOME_CANVAS_PIXBUF (object);
+       priv = gcp->priv;
+
+       switch (param_id) {
+       case PROP_PIXBUF:
+               g_value_set_object (value, priv->pixbuf);
+               break;
+
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+               break;
+       }
+}
+
+/* Bounds and utilities */
+
+/* Recomputes the bounding box of a pixbuf canvas item.  The horizontal and
+ * vertical dimensions may be specified in units or pixels, separately, so we
+ * have to compute the components individually for each dimension.
+ */
+static void
+recompute_bounding_box (GnomeCanvasPixbuf *gcp)
+{
+       GnomeCanvasItem *item;
+       GnomeCanvasPixbufPrivate *priv;
+       cairo_matrix_t i2c;
+       gdouble x1, x2, y1, y2;
+
+       item = GNOME_CANVAS_ITEM (gcp);
+       priv = gcp->priv;
+
+       if (!priv->pixbuf) {
+               item->x1 = item->y1 = item->x2 = item->y2 = 0.0;
+               return;
+       }
+
+       x1 = 0.0;
+       x2 = gdk_pixbuf_get_width (priv->pixbuf);
+       y1 = 0.0;
+       y2 = gdk_pixbuf_get_height (priv->pixbuf);
+
+       gnome_canvas_item_i2c_matrix (item, &i2c);
+       gnome_canvas_matrix_transform_rect (&i2c, &x1, &y1, &x2, &y2);
+
+       item->x1 = floor (x1);
+       item->y1 = floor (y1);
+       item->x2 = ceil (x2);
+       item->y2 = ceil (y2);
+}
+
+/* Update sequence */
+
+/* Update handler for the pixbuf canvas item */
+static void
+gnome_canvas_pixbuf_update (GnomeCanvasItem *item,
+                            const cairo_matrix_t *i2c,
+                            gint flags)
+{
+       GnomeCanvasPixbuf *gcp;
+
+       gcp = GNOME_CANVAS_PIXBUF (item);
+
+       if (GNOME_CANVAS_ITEM_CLASS (gnome_canvas_pixbuf_parent_class)->update)
+               GNOME_CANVAS_ITEM_CLASS (gnome_canvas_pixbuf_parent_class)->
+                       update (item, i2c, flags);
+
+       /* ordinary update logic */
+       gnome_canvas_request_redraw (
+               item->canvas, item->x1, item->y1, item->x2, item->y2);
+       recompute_bounding_box (gcp);
+       gnome_canvas_request_redraw (
+               item->canvas, item->x1, item->y1, item->x2, item->y2);
+}
+
+/* Draw handler for the pixbuf canvas item */
+static void
+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;
+
+       gcp = GNOME_CANVAS_PIXBUF (item);
+       priv = gcp->priv;
+
+       if (!priv->pixbuf)
+               return;
+
+       gnome_canvas_item_i2c_matrix (item, &matrix);
+
+       matrix.x0 -= x;
+       matrix.y0 -= y;
+
+       cairo_save (cr);
+       cairo_transform (cr, &matrix);
+
+       gdk_cairo_set_source_pixbuf (cr, priv->pixbuf, 0, 0);
+       cairo_paint (cr);
+       cairo_restore (cr);
+}
+
+/* Point handler for the pixbuf canvas item */
+static GnomeCanvasItem *
+gnome_canvas_pixbuf_point (GnomeCanvasItem *item,
+                           gdouble x,
+                           gdouble y,
+                           gint cx,
+                           gint cy)
+{
+       GnomeCanvasPixbuf *gcp;
+       GnomeCanvasPixbufPrivate *priv;
+       GdkPixbuf *pixbuf;
+       gint px, py;
+       guchar *src;
+
+       gcp = GNOME_CANVAS_PIXBUF (item);
+       priv = gcp->priv;
+       pixbuf = priv->pixbuf;
+
+       if (!priv->pixbuf)
+               return NULL;
+
+       px = x;
+       py = y;
+
+       if (px < 0 || px >= gdk_pixbuf_get_width (pixbuf) ||
+           py < 0 || py >= gdk_pixbuf_get_height (pixbuf))
+               return NULL;
+
+       if (!gdk_pixbuf_get_has_alpha (pixbuf))
+               return item;
+
+       src = gdk_pixbuf_get_pixels (pixbuf) +
+           py * gdk_pixbuf_get_rowstride (pixbuf) +
+           px * gdk_pixbuf_get_n_channels (pixbuf);
+
+       if (src[3] < 128)
+               return NULL;
+       else
+               return item;
+}
+
+/* Bounds handler for the pixbuf canvas item */
+static void
+gnome_canvas_pixbuf_bounds (GnomeCanvasItem *item,
+                            gdouble *x1,
+                            gdouble *y1,
+                            gdouble *x2,
+                            gdouble *y2)
+{
+       GnomeCanvasPixbuf *gcp;
+       GnomeCanvasPixbufPrivate *priv;
+
+       gcp = GNOME_CANVAS_PIXBUF (item);
+       priv = gcp->priv;
+
+       if (!priv->pixbuf) {
+               *x1 = *y1 = *x2 = *y2 = 0.0;
+               return;
+       }
+
+       *x1 = 0;
+       *y1 = 0;
+       *x2 = gdk_pixbuf_get_width (priv->pixbuf);
+       *y2 = gdk_pixbuf_get_height (priv->pixbuf);
+}
diff --git a/src/libgnomecanvas/gnome-canvas-pixbuf.h b/src/libgnomecanvas/gnome-canvas-pixbuf.h
new file mode 100644
index 00000000..0ebb4f6f
--- /dev/null
+++ b/src/libgnomecanvas/gnome-canvas-pixbuf.h
@@ -0,0 +1,53 @@
+/* GNOME libraries - GdkPixbuf item for the GNOME canvas
+ *
+ * Copyright (C) 1999 The Free Software Foundation
+ *
+ * Author: Federico Mena-Quintero <federico gimp org>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GNOME_CANVAS_PIXBUF_H
+#define GNOME_CANVAS_PIXBUF_H
+
+#include <libgnomecanvas/gnome-canvas.h>
+
+G_BEGIN_DECLS
+
+#define GNOME_TYPE_CANVAS_PIXBUF            (gnome_canvas_pixbuf_get_type ())
+#define GNOME_CANVAS_PIXBUF(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNOME_TYPE_CANVAS_PIXBUF, 
GnomeCanvasPixbuf))
+#define GNOME_CANVAS_PIXBUF_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GNOME_TYPE_CANVAS_PIXBUF, 
GnomeCanvasPixbufClass))
+#define GNOME_IS_CANVAS_PIXBUF(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNOME_TYPE_CANVAS_PIXBUF))
+#define GNOME_IS_CANVAS_PIXBUF_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GNOME_TYPE_CANVAS_PIXBUF))
+#define GNOME_CANVAS_PIXBUF_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GNOME_TYPE_CANVAS_PIXBUF, 
GnomeCanvasPixbufClass))
+
+typedef struct _GnomeCanvasPixbuf GnomeCanvasPixbuf;
+typedef struct _GnomeCanvasPixbufClass GnomeCanvasPixbufClass;
+typedef struct _GnomeCanvasPixbufPrivate GnomeCanvasPixbufPrivate;
+
+struct _GnomeCanvasPixbuf {
+       GnomeCanvasItem item;
+
+       /* Private data */
+       GnomeCanvasPixbufPrivate *priv;
+};
+
+struct _GnomeCanvasPixbufClass {
+       GnomeCanvasItemClass parent_class;
+};
+
+GType gnome_canvas_pixbuf_get_type (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif
diff --git a/src/libgnomecanvas/gnome-canvas-rect.c b/src/libgnomecanvas/gnome-canvas-rect.c
new file mode 100644
index 00000000..a2855fbd
--- /dev/null
+++ b/src/libgnomecanvas/gnome-canvas-rect.c
@@ -0,0 +1,718 @@
+/* Generic bezier rect item for GnomeCanvasWidget.  Most code taken
+ * from gnome-canvas-bpath but made into a rect item.
+ *
+ * GnomeCanvas is basically a port of the Tk toolkit's most excellent
+ * canvas widget.  Tk is copyrighted by the Regents of the University
+ * of California, Sun Microsystems, and other parties.
+ *
+ * Copyright (C) 1998,1999 The Free Software Foundation
+ *
+ * Authors: Federico Mena <federico nuclecu unam mx>
+ *          Raph Levien <raph acm org>
+ *          Lauris Kaplinski <lauris ximian com>
+ *          Miguel de Icaza <miguel kernel org>
+ *          Cody Russell <bratsche gnome org>
+ *          Rusty Conover <rconover bangtail net>
+ */
+
+/* These includes are set up for standalone compile. If/when this codebase
+ * is integrated into libgnomeui, the includes will need to change. */
+
+#include "evolution-config.h"
+
+#include <math.h>
+#include <string.h>
+
+#include <gtk/gtk.h>
+#include <cairo-gobject.h>
+#include "gnome-canvas.h"
+#include "gnome-canvas-util.h"
+
+#include "gnome-canvas-rect.h"
+
+#define GNOME_CANVAS_RECT_GET_PRIVATE(obj) \
+       (G_TYPE_INSTANCE_GET_PRIVATE \
+       ((obj), GNOME_TYPE_CANVAS_RECT, GnomeCanvasRectPrivate))
+
+struct _GnomeCanvasRectPrivate {
+       cairo_path_t *path;             /* Our bezier path representation */
+
+       gdouble x1, y1, x2, y2;
+
+       gdouble scale;                  /* CTM scaling (for pen) */
+
+       guint fill_set : 1;             /* Is fill color set? */
+       guint outline_set : 1;          /* Is outline color set? */
+
+       gdouble line_width;             /* Width of outline, in user coords */
+
+       guint32 fill_rgba;              /* Fill color, RGBA */
+       guint32 outline_rgba;           /* Outline color, RGBA */
+
+       cairo_line_cap_t cap;           /* Cap style for line */
+       cairo_line_join_t join;         /* Join style for line */
+       cairo_fill_rule_t wind;         /* Winding rule */
+       gdouble miterlimit;             /* Miter limit */
+
+        guint n_dash;                   /* Number of elements in dashing pattern */
+       gdouble *dash;          /* Dashing pattern */
+        gdouble dash_offset;            /* Dashing offset */
+};
+
+enum {
+       PROP_0,
+       PROP_X1,
+       PROP_Y1,
+       PROP_X2,
+       PROP_Y2,
+       PROP_FILL_COLOR,
+       PROP_FILL_COLOR_GDK,
+       PROP_FILL_COLOR_RGBA,
+       PROP_OUTLINE_COLOR,
+       PROP_OUTLINE_COLOR_GDK,
+       PROP_OUTLINE_COLOR_RGBA,
+       PROP_LINE_WIDTH,
+       PROP_CAP_STYLE,
+       PROP_JOIN_STYLE,
+       PROP_WIND,
+       PROP_MITERLIMIT,
+       PROP_DASH
+};
+
+static void   gnome_canvas_rect_bounds      (GnomeCanvasItem *item,
+                                             gdouble *x1, gdouble *y1, gdouble *x2, gdouble *y2);
+
+G_DEFINE_TYPE (GnomeCanvasRect, gnome_canvas_rect, GNOME_TYPE_CANVAS_ITEM)
+
+static guint32
+get_rgba_from_color (GdkColor *color)
+{
+       guint32 rr, gg, bb, aa;
+
+       rr = 0xFF * color->red / 65535.0;
+       gg = 0xFF * color->green / 65535.0;
+       bb = 0xFF * color->blue / 65535.0;
+       aa = 0xFF;
+
+       return (rr & 0xFFu) << 24 |
+               (gg & 0xFFu) << 16 |
+               (bb & 0xFFu) << 8 |
+               (aa & 0xFFu);
+}
+
+static gboolean
+gnome_canvas_rect_setup_for_fill (GnomeCanvasRect *rect,
+                                  cairo_t *cr)
+{
+       if (!rect->priv->fill_set)
+               return FALSE;
+
+       cairo_set_source_rgba (
+               cr,
+               ((rect->priv->fill_rgba >> 24) & 0xff) / 255.0,
+               ((rect->priv->fill_rgba >> 16) & 0xff) / 255.0,
+               ((rect->priv->fill_rgba >> 8) & 0xff) / 255.0,
+               ( rect->priv->fill_rgba & 0xff) / 255.0);
+       cairo_set_fill_rule (cr, rect->priv->wind);
+
+       return TRUE;
+}
+
+static gboolean
+gnome_canvas_rect_setup_for_stroke (GnomeCanvasRect *rect,
+                                    cairo_t *cr)
+{
+       if (!rect->priv->outline_set)
+               return FALSE;
+
+       cairo_set_source_rgba (
+               cr,
+               ((rect->priv->outline_rgba >> 24) & 0xff) / 255.0,
+               ((rect->priv->outline_rgba >> 16) & 0xff) / 255.0,
+               ((rect->priv->outline_rgba >> 8) & 0xff) / 255.0,
+               ( rect->priv->outline_rgba & 0xff) / 255.0);
+       cairo_set_line_width (cr, rect->priv->line_width);
+       cairo_set_line_cap (cr, rect->priv->cap);
+       cairo_set_line_join (cr, rect->priv->join);
+       cairo_set_miter_limit (cr, rect->priv->miterlimit);
+       cairo_set_dash (
+               cr, rect->priv->dash, rect->priv->n_dash,
+               rect->priv->dash_offset);
+
+       return TRUE;
+}
+
+static void
+gnome_canvas_rect_set_property (GObject *object,
+                                guint property_id,
+                                const GValue *value,
+                                GParamSpec *pspec)
+{
+       GnomeCanvasItem *item;
+       GnomeCanvasRect *rect;
+       GnomeCanvasRectPrivate *priv;
+       GdkColor color;
+       GdkColor *colorptr;
+       const gchar *color_string;
+
+       item = GNOME_CANVAS_ITEM (object);
+       rect = GNOME_CANVAS_RECT (object);
+       priv = rect->priv;
+
+       switch (property_id) {
+       case PROP_X1:
+               priv->x1 = g_value_get_double (value);
+               gnome_canvas_item_request_update (item);
+               break;
+
+       case PROP_Y1:
+               priv->y1 = g_value_get_double (value);
+               gnome_canvas_item_request_update (item);
+               break;
+
+       case PROP_X2:
+               priv->x2 = g_value_get_double (value);
+               gnome_canvas_item_request_update (item);
+               break;
+
+       case PROP_Y2:
+               priv->y2 = g_value_get_double (value);
+               gnome_canvas_item_request_update (item);
+               break;
+
+       case PROP_FILL_COLOR:
+               color_string = g_value_get_string (value);
+               if (color_string != NULL) {
+                       if (!gdk_color_parse (color_string, &color)) {
+                               g_warning (
+                                       "Failed to parse color '%s'",
+                                       color_string);
+                               break;
+                       }
+                       priv->fill_set = TRUE;
+                       priv->fill_rgba = get_rgba_from_color (&color);
+               } else if (priv->fill_set)
+                       priv->fill_set = FALSE;
+               else
+                       break;
+
+               gnome_canvas_item_request_update (item);
+               break;
+
+       case PROP_FILL_COLOR_GDK:
+               colorptr = g_value_get_boxed (value);
+               if (colorptr != NULL) {
+                       priv->fill_set = TRUE;
+                       priv->fill_rgba = get_rgba_from_color (colorptr);
+               } else if (priv->fill_set)
+                       priv->fill_set = FALSE;
+               else
+                       break;
+
+               gnome_canvas_item_request_update (item);
+               break;
+
+       case PROP_FILL_COLOR_RGBA:
+               priv->fill_set = TRUE;
+               priv->fill_rgba = g_value_get_uint (value);
+
+               gnome_canvas_item_request_update (item);
+               break;
+
+       case PROP_OUTLINE_COLOR:
+               color_string = g_value_get_string (value);
+               if (color_string != NULL) {
+                       if (!gdk_color_parse (color_string, &color)) {
+                               g_warning (
+                                       "Failed to parse color '%s'",
+                                       color_string);
+                               break;
+                       }
+                       priv->outline_set = TRUE;
+                       priv->outline_rgba = get_rgba_from_color (&color);
+               } else if (priv->outline_set)
+                       priv->outline_set = FALSE;
+               else
+                       break;
+
+               gnome_canvas_item_request_update (item);
+               break;
+
+       case PROP_OUTLINE_COLOR_GDK:
+               colorptr = g_value_get_boxed (value);
+               if (colorptr != NULL) {
+                       priv->outline_set = TRUE;
+                       priv->outline_rgba = get_rgba_from_color (colorptr);
+               } else if (priv->outline_set)
+                       priv->outline_set = FALSE;
+               else
+                       break;
+
+               gnome_canvas_item_request_update (item);
+               break;
+
+       case PROP_OUTLINE_COLOR_RGBA:
+               priv->outline_set = TRUE;
+               priv->outline_rgba = g_value_get_uint (value);
+
+               gnome_canvas_item_request_update (item);
+               break;
+
+       case PROP_LINE_WIDTH:
+               priv->line_width = g_value_get_double (value);
+
+               gnome_canvas_item_request_update (item);
+               break;
+
+       case PROP_WIND:
+               priv->wind = g_value_get_enum (value);
+               gnome_canvas_item_request_update (item);
+               break;
+
+       case PROP_CAP_STYLE:
+               priv->cap = g_value_get_enum (value);
+               gnome_canvas_item_request_update (item);
+               break;
+
+       case PROP_JOIN_STYLE:
+               priv->join = g_value_get_enum (value);
+               gnome_canvas_item_request_update (item);
+               break;
+
+       case PROP_MITERLIMIT:
+               priv->miterlimit = g_value_get_double (value);
+               gnome_canvas_item_request_update (item);
+               break;
+
+       case PROP_DASH:
+               /* XXX */
+               g_warn_if_reached ();
+               break;
+
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+               break;
+       }
+}
+
+static void
+gnome_canvas_rect_get_property (GObject *object,
+                                guint property_id,
+                                GValue *value,
+                                GParamSpec *pspec)
+{
+       GnomeCanvasRect *rect = GNOME_CANVAS_RECT (object);
+       GnomeCanvasRectPrivate *priv = rect->priv;
+
+       switch (property_id) {
+
+       case PROP_X1:
+               g_value_set_double (value, priv->x1);
+               break;
+
+       case PROP_Y1:
+               g_value_set_double (value, priv->y1);
+               break;
+
+       case PROP_X2:
+               g_value_set_double (value, priv->x2);
+               break;
+
+       case PROP_Y2:
+               g_value_set_double (value, priv->y2);
+               break;
+
+       case PROP_FILL_COLOR_RGBA:
+               g_value_set_uint (value, priv->fill_rgba);
+               break;
+
+       case PROP_OUTLINE_COLOR_RGBA:
+               g_value_set_uint (value, priv->outline_rgba);
+               break;
+
+       case PROP_WIND:
+               g_value_set_uint (value, priv->wind);
+               break;
+
+       case PROP_CAP_STYLE:
+               g_value_set_enum (value, priv->cap);
+               break;
+
+       case PROP_JOIN_STYLE:
+               g_value_set_enum (value, priv->join);
+               break;
+
+       case PROP_LINE_WIDTH:
+               g_value_set_double (value, priv->line_width);
+               break;
+
+       case PROP_MITERLIMIT:
+               g_value_set_double (value, priv->miterlimit);
+               break;
+
+       case PROP_DASH:
+               /* XXX */
+               g_warn_if_reached ();
+               break;
+
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+               break;
+       }
+}
+
+static void
+gnome_canvas_rect_dispose (GnomeCanvasItem *object)
+{
+       GnomeCanvasRect *rect;
+
+       g_return_if_fail (GNOME_IS_CANVAS_RECT (object));
+
+       rect = GNOME_CANVAS_RECT (object);
+       g_clear_pointer (&rect->priv->path, cairo_path_destroy);
+
+       g_free (rect->priv->dash);
+       rect->priv->dash = NULL;
+
+       if (GNOME_CANVAS_ITEM_CLASS (gnome_canvas_rect_parent_class)->dispose)
+               GNOME_CANVAS_ITEM_CLASS (gnome_canvas_rect_parent_class)->dispose (object);
+}
+
+static void
+gnome_canvas_rect_update (GnomeCanvasItem *item,
+                          const cairo_matrix_t *i2c,
+                          gint flags)
+{
+       gdouble x1, x2, y1, y2;
+
+       GNOME_CANVAS_ITEM_CLASS (gnome_canvas_rect_parent_class)->
+               update (item, i2c, flags);
+
+       gnome_canvas_rect_bounds (item, &x1, &y1, &x2, &y2);
+       gnome_canvas_matrix_transform_rect (i2c, &x1, &y1, &x2, &y2);
+
+       gnome_canvas_update_bbox (
+               item, floor (x1), floor (y1), ceil (x2), ceil (y2));
+}
+
+static void
+gnome_canvas_rect_draw (GnomeCanvasItem *item,
+                        cairo_t *cr,
+                        gint x,
+                        gint y,
+                        gint width,
+                        gint height)
+{
+       GnomeCanvasRect *rect;
+       cairo_matrix_t matrix;
+
+       rect = GNOME_CANVAS_RECT (item);
+
+       cairo_save (cr);
+
+       gnome_canvas_item_i2c_matrix (item, &matrix);
+       cairo_transform (cr, &matrix);
+
+       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_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_restore (cr);
+}
+
+static GnomeCanvasItem *
+gnome_canvas_rect_point (GnomeCanvasItem *item,
+                         gdouble x,
+                         gdouble y,
+                         gint cx,
+                         gint cy)
+{
+       GnomeCanvasRect *rect;
+       cairo_t *cr;
+
+       rect = GNOME_CANVAS_RECT (item);
+
+       cr = gnome_canvas_cairo_create_scratch ();
+
+       cairo_rectangle (
+               cr,
+               rect->priv->x1,
+               rect->priv->y1,
+               rect->priv->x2 - rect->priv->x1,
+               rect->priv->y2 - rect->priv->y1);
+
+       if (gnome_canvas_rect_setup_for_fill (rect, cr) &&
+           cairo_in_fill (cr, x, y)) {
+               cairo_destroy (cr);
+               return item;
+       }
+
+       if (gnome_canvas_rect_setup_for_stroke (rect, cr) &&
+           cairo_in_stroke (cr, x, y)) {
+               cairo_destroy (cr);
+               return item;
+       }
+
+       cairo_destroy (cr);
+
+       return NULL;
+}
+
+static void
+gnome_canvas_rect_bounds (GnomeCanvasItem *item,
+                          gdouble *x1,
+                          gdouble *y1,
+                          gdouble *x2,
+                          gdouble *y2)
+{
+       GnomeCanvasRect *rect;
+
+       rect = GNOME_CANVAS_RECT (item);
+
+       *x1 = rect->priv->x1;
+       *y1 = rect->priv->y1;
+       *x2 = rect->priv->x2;
+       *y2 = rect->priv->y2;
+}
+
+static void
+gnome_canvas_rect_class_init (GnomeCanvasRectClass *class)
+{
+       GObjectClass *object_class;
+       GnomeCanvasItemClass *item_class;
+
+       g_type_class_add_private (class, sizeof (GnomeCanvasRectPrivate));
+
+       object_class = G_OBJECT_CLASS (class);
+       object_class->set_property = gnome_canvas_rect_set_property;
+       object_class->get_property = gnome_canvas_rect_get_property;
+
+       item_class = GNOME_CANVAS_ITEM_CLASS (class);
+       item_class->dispose = gnome_canvas_rect_dispose;
+       item_class->update = gnome_canvas_rect_update;
+       item_class->draw = gnome_canvas_rect_draw;
+       item_class->point = gnome_canvas_rect_point;
+       item_class->bounds = gnome_canvas_rect_bounds;
+
+       g_object_class_install_property (
+               object_class,
+               PROP_X1,
+               g_param_spec_double (
+                       "x1",
+                       NULL,
+                       NULL,
+                       -G_MAXDOUBLE,
+                       G_MAXDOUBLE,
+                       0,
+                       G_PARAM_READWRITE));
+
+       g_object_class_install_property (
+               object_class,
+               PROP_Y1,
+               g_param_spec_double (
+                       "y1",
+                       NULL,
+                       NULL,
+                       -G_MAXDOUBLE,
+                       G_MAXDOUBLE,
+                       0,
+                       G_PARAM_READWRITE));
+
+       g_object_class_install_property (
+               object_class,
+               PROP_X2,
+               g_param_spec_double (
+                       "x2",
+                       NULL,
+                       NULL,
+                       -G_MAXDOUBLE,
+                       G_MAXDOUBLE,
+                       0,
+                       G_PARAM_READWRITE));
+
+       g_object_class_install_property (
+               object_class,
+               PROP_Y2,
+               g_param_spec_double (
+                       "y2",
+                       NULL,
+                       NULL,
+                       -G_MAXDOUBLE,
+                       G_MAXDOUBLE,
+                       0,
+                       G_PARAM_READWRITE));
+
+       g_object_class_install_property (
+               object_class,
+               PROP_FILL_COLOR,
+               g_param_spec_string (
+                       "fill_color",
+                       NULL,
+                       NULL,
+                       NULL,
+                       G_PARAM_WRITABLE));
+
+       g_object_class_install_property (
+               object_class,
+               PROP_FILL_COLOR_GDK,
+               g_param_spec_boxed (
+                       "fill_color_gdk",
+                       NULL,
+                       NULL,
+                       GDK_TYPE_COLOR,
+                       G_PARAM_WRITABLE));
+
+       g_object_class_install_property (
+               object_class,
+               PROP_FILL_COLOR_RGBA,
+               g_param_spec_uint (
+                       "fill_color_rgba",
+                       NULL,
+                       NULL,
+                       0,
+                       G_MAXUINT,
+                       0,
+                       G_PARAM_READWRITE));
+
+       g_object_class_install_property (
+               object_class,
+               PROP_OUTLINE_COLOR,
+               g_param_spec_string (
+                       "outline_color",
+                       NULL,
+                       NULL,
+                       NULL,
+                       G_PARAM_WRITABLE));
+
+       g_object_class_install_property (
+               object_class,
+               PROP_OUTLINE_COLOR_GDK,
+               g_param_spec_boxed (
+                       "outline_color_gdk",
+                       NULL,
+                       NULL,
+                       GDK_TYPE_COLOR,
+                       G_PARAM_WRITABLE));
+
+       g_object_class_install_property (
+               object_class,
+               PROP_OUTLINE_COLOR_RGBA,
+               g_param_spec_uint (
+                       "outline_rgba",
+                       NULL,
+                       NULL,
+                       0,
+                       G_MAXUINT,
+                       0,
+                       G_PARAM_READWRITE));
+
+       g_object_class_install_property (
+               object_class,
+               PROP_LINE_WIDTH,
+               g_param_spec_double (
+                       "line_width",
+                       NULL,
+                       NULL,
+                       0.0,
+                       G_MAXDOUBLE,
+                       1.0,
+                       G_PARAM_READWRITE));
+
+       g_object_class_install_property (
+               object_class,
+               PROP_CAP_STYLE,
+               g_param_spec_enum (
+                       "cap_style",
+                       NULL,
+                       NULL,
+                       CAIRO_GOBJECT_TYPE_LINE_CAP,
+                       CAIRO_LINE_CAP_BUTT,
+                       G_PARAM_READWRITE));
+
+       g_object_class_install_property (
+               object_class,
+               PROP_JOIN_STYLE,
+               g_param_spec_enum (
+                       "join_style",
+                       NULL,
+                       NULL,
+                       CAIRO_GOBJECT_TYPE_LINE_JOIN,
+                       CAIRO_LINE_JOIN_MITER,
+                       G_PARAM_READWRITE));
+
+       g_object_class_install_property (
+               object_class,
+               PROP_WIND,
+               g_param_spec_enum (
+                       "wind",
+                       NULL,
+                       NULL,
+                       CAIRO_GOBJECT_TYPE_FILL_RULE,
+                       CAIRO_FILL_RULE_EVEN_ODD,
+                       G_PARAM_READWRITE));
+
+       g_object_class_install_property (
+               object_class,
+               PROP_MITERLIMIT,
+               g_param_spec_double (
+                       "miterlimit",
+                       NULL,
+                       NULL,
+                       0.0,
+                       G_MAXDOUBLE,
+                       10.43,
+                       G_PARAM_READWRITE));
+
+#if 0
+       /* XXX: Find a good way to pass dash properties in a property */
+       g_object_class_install_property (
+               object_class,
+               PROP_DASH,
+               g_param_spec_pointer (
+                       "dash",
+                       NULL,
+                       NULL,
+                       G_PARAM_READWRITE));
+#endif
+}
+
+static void
+gnome_canvas_rect_init (GnomeCanvasRect *rect)
+{
+       rect->priv = GNOME_CANVAS_RECT_GET_PRIVATE (rect);
+
+       rect->priv->scale = 1.0;
+
+       rect->priv->fill_set = FALSE;
+       rect->priv->outline_set = FALSE;
+
+       rect->priv->line_width = 1.0;
+
+       rect->priv->fill_rgba = 0x0000003f;
+       rect->priv->outline_rgba = 0x0000007f;
+
+       rect->priv->cap = CAIRO_LINE_CAP_BUTT;
+       rect->priv->join = CAIRO_LINE_JOIN_MITER;
+       rect->priv->wind = CAIRO_FILL_RULE_EVEN_ODD;
+       rect->priv->miterlimit = 10.43;    /* X11 default */
+
+       rect->priv->n_dash = 0;
+       rect->priv->dash = NULL;
+}
+
diff --git a/src/libgnomecanvas/gnome-canvas-rect.h b/src/libgnomecanvas/gnome-canvas-rect.h
new file mode 100644
index 00000000..683b7523
--- /dev/null
+++ b/src/libgnomecanvas/gnome-canvas-rect.h
@@ -0,0 +1,68 @@
+/* Generic bezier shape item for GnomeCanvas
+ *
+ * GnomeCanvas is basically a port of the Tk toolkit's most excellent canvas widget.  Tk is
+ * copyrighted by the Regents of the University of California, Sun Microsystems, and other parties.
+ *
+ * Copyright (C) 1998,1999 The Free Software Foundation
+ *
+ * Authors: Federico Mena <federico nuclecu unam mx>
+ *          Raph Levien <raph acm org>
+ *          Lauris Kaplinski <lauris ximian com>
+ *          Rusty Conover <rconover bangtail net>
+ */
+
+#ifndef GNOME_CANVAS_RECT_H
+#define GNOME_CANVAS_RECT_H
+
+#include <libgnomecanvas/gnome-canvas.h>
+
+G_BEGIN_DECLS
+
+/* Rect item for the canvas.
+ *
+ * The following object arguments are available:
+ *
+ * name                        type                    read/write      description
+ * ------------------------------------------------------------------------------------------
+ * fill_color          string                  W               X color specification for fill color,
+ *                                                             or NULL pointer for no color (transparent).
+ * fill_color_gdk      GdkColor*               RW              Allocated GdkColor for fill.
+ * outline_color       string                  W               X color specification for outline color,
+ *                                                             or NULL pointer for no color (transparent).
+ * outline_color_gdk   GdkColor*               RW              Allocated GdkColor for outline.
+ * width_pixels                uint                    RW              Width of the outline in pixels.  The 
outline will
+ *                                                             not be scaled when the canvas zoom factor is 
changed.
+ * width_units         gdouble                 RW              Width of the outline in canvas units.  The 
outline
+ *                                                             will be scaled when the canvas zoom factor is 
changed.
+ * cap_style           cairo_line_cap_t        RW              Cap ("endpoint") style for the bpath.
+ * join_style          cairo_line_join_t       RW              Join ("vertex") style for the bpath.
+ * wind                 cairo_fill_rule_t       RW              Winding rule for the bpath.
+ * dash                        XXX: disabled           RW              Dashing pattern
+ * miterlimit          gdouble                 RW              Minimum angle between segments, where miter 
join
+ *                                                             rule is applied.
+ */
+
+#define GNOME_TYPE_CANVAS_RECT            (gnome_canvas_rect_get_type ())
+#define GNOME_CANVAS_RECT(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNOME_TYPE_CANVAS_RECT, 
GnomeCanvasRect))
+#define GNOME_CANVAS_RECT_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GNOME_TYPE_CANVAS_RECT, 
GnomeCanvasRectClass))
+#define GNOME_IS_CANVAS_RECT(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNOME_TYPE_CANVAS_RECT))
+#define GNOME_IS_CANVAS_RECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GNOME_TYPE_CANVAS_RECT))
+
+typedef struct _GnomeCanvasRect GnomeCanvasRect;
+typedef struct _GnomeCanvasRectClass GnomeCanvasRectClass;
+typedef struct _GnomeCanvasRectPrivate GnomeCanvasRectPrivate;
+
+struct _GnomeCanvasRect {
+       GnomeCanvasItem item;
+       GnomeCanvasRectPrivate *priv;
+};
+
+struct _GnomeCanvasRectClass {
+       GnomeCanvasItemClass parent_class;
+};
+
+GType gnome_canvas_rect_get_type (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif /* GNOME_CANVAS_RECT_H */
diff --git a/src/libgnomecanvas/gnome-canvas-text.c b/src/libgnomecanvas/gnome-canvas-text.c
new file mode 100644
index 00000000..df68def3
--- /dev/null
+++ b/src/libgnomecanvas/gnome-canvas-text.c
@@ -0,0 +1,1412 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * $Id$
+ * Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation
+ * All rights reserved.
+ *
+ * This file is part of the Gnome Library.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * published by the Free Software Foundation; either the
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * License along with the Gnome Library; see the file COPYING.LIB.  If not,
+ */
+/*
+  @NOTATION@
+ */
+/* Text item type for GnomeCanvas widget
+ *
+ * GnomeCanvas is basically a port of the Tk toolkit's most excellent canvas
+ * widget.  Tk is copyrighted by the Regents of the University of California,
+ * Sun Microsystems, and other parties.
+ *
+ *
+ * Author: Federico Mena <federico nuclecu unam mx>
+ * Port to Pango co-done by Gerg� �rdi <cactus cactus rulez org>
+ */
+
+#include "evolution-config.h"
+
+#include <math.h>
+#include <string.h>
+#include "gnome-canvas-text.h"
+
+#include "gnome-canvas-util.h"
+#include "gnome-canvas-i18n.h"
+
+/* Object argument IDs */
+enum {
+       PROP_0,
+
+       /* Text contents */
+       PROP_TEXT,
+       PROP_MARKUP,
+
+       /* Position */
+       PROP_X,
+       PROP_Y,
+
+       /* Font */
+       PROP_FONT,
+       PROP_FONT_DESC,
+       PROP_FAMILY, PROP_FAMILY_SET,
+
+       /* Style */
+       PROP_ATTRIBUTES,
+       PROP_STYLE,         PROP_STYLE_SET,
+       PROP_VARIANT,       PROP_VARIANT_SET,
+       PROP_WEIGHT,        PROP_WEIGHT_SET,
+       PROP_STRETCH,       PROP_STRETCH_SET,
+       PROP_SIZE,          PROP_SIZE_SET,
+       PROP_SIZE_POINTS,
+       PROP_STRIKETHROUGH, PROP_STRIKETHROUGH_SET,
+       PROP_UNDERLINE,     PROP_UNDERLINE_SET,
+       PROP_RISE,          PROP_RISE_SET,
+       PROP_SCALE,         PROP_SCALE_SET,
+
+       /* Clipping */
+       PROP_JUSTIFICATION,
+       PROP_CLIP_WIDTH,
+       PROP_CLIP_HEIGHT,
+       PROP_CLIP,
+       PROP_X_OFFSET,
+       PROP_Y_OFFSET,
+
+       /* Coloring */
+       PROP_FILL_COLOR,
+       PROP_FILL_COLOR_GDK,
+       PROP_FILL_COLOR_RGBA,
+
+       /* Rendered size accessors */
+       PROP_TEXT_WIDTH,
+       PROP_TEXT_HEIGHT
+};
+
+static void gnome_canvas_text_dispose (GnomeCanvasItem *object);
+static void gnome_canvas_text_set_property (GObject            *object,
+                                           guint               param_id,
+                                           const GValue       *value,
+                                           GParamSpec         *pspec);
+static void gnome_canvas_text_get_property (GObject            *object,
+                                           guint               param_id,
+                                           GValue             *value,
+                                           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, cairo_t *cr,
+                                   gint x, gint y, gint width, gint height);
+static GnomeCanvasItem *gnome_canvas_text_point (GnomeCanvasItem *item,
+                                                 gdouble x,
+                                                 gdouble y,
+                                                 gint cx,
+                                                 gint cy);
+static void gnome_canvas_text_bounds (GnomeCanvasItem *item,
+                                     gdouble *x1, gdouble *y1, gdouble *x2, gdouble *y2);
+
+static void gnome_canvas_text_set_markup (GnomeCanvasText *textitem,
+                                         const gchar     *markup);
+
+static void gnome_canvas_text_set_font_desc    (GnomeCanvasText *textitem,
+                                               PangoFontDescription *font_desc);
+
+static void gnome_canvas_text_apply_font_desc  (GnomeCanvasText *textitem);
+static void gnome_canvas_text_apply_attributes (GnomeCanvasText *textitem);
+
+static void add_attr (PangoAttrList  *attr_list,
+                     PangoAttribute *attr);
+
+G_DEFINE_TYPE (
+       GnomeCanvasText,
+       gnome_canvas_text,
+       GNOME_TYPE_CANVAS_ITEM)
+
+/* Class initialization function for the text item */
+static void
+gnome_canvas_text_class_init (GnomeCanvasTextClass *class)
+{
+       GObjectClass *gobject_class;
+       GnomeCanvasItemClass *item_class;
+
+       gobject_class = (GObjectClass *) class;
+       item_class = (GnomeCanvasItemClass *) class;
+
+       gobject_class->set_property = gnome_canvas_text_set_property;
+       gobject_class->get_property = gnome_canvas_text_get_property;
+
+       /* Text */
+       g_object_class_install_property (
+               gobject_class,
+               PROP_TEXT,
+               g_param_spec_string (
+                       "text",
+                       "Text",
+                       "Text to render",
+                       NULL,
+                       G_PARAM_READABLE |
+                       G_PARAM_WRITABLE));
+
+       g_object_class_install_property (
+               gobject_class,
+               PROP_MARKUP,
+               g_param_spec_string (
+                       "markup",
+                       "Markup",
+                       "Marked up text to render",
+                       NULL,
+                       G_PARAM_WRITABLE));
+
+       /* Position */
+       g_object_class_install_property (
+               gobject_class,
+               PROP_X,
+               g_param_spec_double (
+                       "x",
+                       NULL,
+                       NULL,
+                       -G_MAXDOUBLE,
+                       G_MAXDOUBLE,
+                       0.0,
+                       G_PARAM_READABLE |
+                       G_PARAM_WRITABLE));
+
+       g_object_class_install_property (
+               gobject_class,
+               PROP_Y,
+               g_param_spec_double (
+                       "y",
+                       NULL,
+                       NULL,
+                       -G_MAXDOUBLE,
+                       G_MAXDOUBLE,
+                       0.0,
+                       G_PARAM_READABLE |
+                       G_PARAM_WRITABLE));
+
+       /* Font */
+       g_object_class_install_property (
+               gobject_class,
+               PROP_FONT,
+               g_param_spec_string (
+                       "font",
+                       "Font",
+                       "Font description as a string",
+                       NULL,
+                       G_PARAM_READABLE |
+                       G_PARAM_WRITABLE));
+
+       g_object_class_install_property (
+               gobject_class,
+               PROP_FONT_DESC,
+               g_param_spec_boxed (
+                       "font_desc",
+                       "Font description",
+                       "Font description as a PangoFontDescription struct",
+                       PANGO_TYPE_FONT_DESCRIPTION,
+                       G_PARAM_READABLE |
+                       G_PARAM_WRITABLE));
+
+       g_object_class_install_property (
+               gobject_class,
+               PROP_FAMILY,
+               g_param_spec_string (
+                       "family",
+                       "Font family",
+                       "Name of the font family, e.g. "
+                       "Sans, Helvetica, Times, Monospace",
+                       NULL,
+                       G_PARAM_READABLE |
+                       G_PARAM_WRITABLE));
+
+       /* Style */
+       g_object_class_install_property (
+               gobject_class,
+               PROP_ATTRIBUTES,
+               g_param_spec_boxed (
+                       "attributes",
+                       NULL,
+                       NULL,
+                       PANGO_TYPE_ATTR_LIST,
+                       G_PARAM_READABLE |
+                       G_PARAM_WRITABLE));
+
+       g_object_class_install_property (
+               gobject_class,
+               PROP_STYLE,
+               g_param_spec_enum (
+                       "style",
+                       "Font style",
+                       "Font style",
+                       PANGO_TYPE_STYLE,
+                       PANGO_STYLE_NORMAL,
+                       G_PARAM_READABLE |
+                       G_PARAM_WRITABLE));
+
+       g_object_class_install_property (
+               gobject_class,
+               PROP_VARIANT,
+               g_param_spec_enum (
+                       "variant",
+                       "Font variant",
+                       "Font variant",
+                       PANGO_TYPE_VARIANT,
+                       PANGO_VARIANT_NORMAL,
+                       G_PARAM_READABLE |
+                       G_PARAM_WRITABLE));
+
+       g_object_class_install_property (
+               gobject_class,
+               PROP_WEIGHT,
+               g_param_spec_int (
+                       "weight",
+                       "Font weight",
+                       "Font weight",
+                       0,
+                       G_MAXINT,
+                       PANGO_WEIGHT_NORMAL,
+                       G_PARAM_READABLE |
+                       G_PARAM_WRITABLE));
+
+       g_object_class_install_property (
+               gobject_class,
+               PROP_STRETCH,
+               g_param_spec_enum (
+                       "stretch",
+                       "Font stretch",
+                       "Font stretch",
+                       PANGO_TYPE_STRETCH,
+                       PANGO_STRETCH_NORMAL,
+                       G_PARAM_READABLE |
+                       G_PARAM_WRITABLE));
+
+       g_object_class_install_property (
+               gobject_class,
+               PROP_SIZE,
+               g_param_spec_int (
+                       "size",
+                       "Font size",
+                       "Font size (as a multiple of PANGO_SCALE, "
+                       "eg. 12*PANGO_SCALE for a 12pt font size)",
+                       0,
+                       G_MAXINT,
+                       0,
+                       G_PARAM_READABLE |
+                       G_PARAM_WRITABLE));
+
+       g_object_class_install_property (
+               gobject_class,
+               PROP_SIZE_POINTS,
+               g_param_spec_double (
+                       "size_points",
+                       "Font points",
+                       "Font size in points (eg. 12 for a 12pt font size)",
+                       0.0,
+                       G_MAXDOUBLE,
+                       0.0,
+                       G_PARAM_READABLE |
+                       G_PARAM_WRITABLE));
+
+       g_object_class_install_property (
+               gobject_class,
+               PROP_RISE,
+               g_param_spec_int (
+                       "rise",
+                       "Rise",
+                       "Offset of text above the baseline "
+                       "(below the baseline if rise is negative)",
+                       -G_MAXINT,
+                       G_MAXINT,
+                       0,
+                       G_PARAM_READABLE |
+                       G_PARAM_WRITABLE));
+
+       g_object_class_install_property (
+               gobject_class,
+               PROP_STRIKETHROUGH,
+               g_param_spec_boolean (
+                       "strikethrough",
+                       "Strikethrough",
+                       "Whether to strike through the text",
+                       FALSE,
+                       G_PARAM_READABLE |
+                       G_PARAM_WRITABLE));
+
+       g_object_class_install_property (
+               gobject_class,
+               PROP_UNDERLINE,
+               g_param_spec_enum (
+                       "underline",
+                       "Underline",
+                       "Style of underline for this text",
+                       PANGO_TYPE_UNDERLINE,
+                       PANGO_UNDERLINE_NONE,
+                       G_PARAM_READABLE |
+                       G_PARAM_WRITABLE));
+
+       g_object_class_install_property (
+               gobject_class,
+               PROP_SCALE,
+               g_param_spec_double (
+                       "scale",
+                       "Scale",
+                       "Size of font, relative to default size",
+                       0.0,
+                       G_MAXDOUBLE,
+                       1.0,
+                       G_PARAM_READABLE |
+                       G_PARAM_WRITABLE));
+
+       g_object_class_install_property (
+               gobject_class,
+               PROP_JUSTIFICATION,
+               g_param_spec_enum (
+                       "justification",
+                       NULL,
+                       NULL,
+                       GTK_TYPE_JUSTIFICATION,
+                       GTK_JUSTIFY_LEFT,
+                       G_PARAM_READABLE |
+                       G_PARAM_WRITABLE));
+
+       g_object_class_install_property (
+               gobject_class,
+               PROP_CLIP_WIDTH,
+               g_param_spec_double (
+                       "clip_width",
+                       NULL,
+                       NULL,
+                       -G_MAXDOUBLE,
+                       G_MAXDOUBLE,
+                       0.0,
+                       G_PARAM_READABLE |
+                       G_PARAM_WRITABLE));
+
+       g_object_class_install_property (
+               gobject_class,
+               PROP_CLIP_HEIGHT,
+               g_param_spec_double (
+                       "clip_height",
+                       NULL,
+                       NULL,
+                       -G_MAXDOUBLE,
+                       G_MAXDOUBLE,
+                       0.0,
+                       G_PARAM_READABLE |
+                       G_PARAM_WRITABLE));
+
+       g_object_class_install_property (
+               gobject_class,
+               PROP_CLIP,
+               g_param_spec_boolean (
+                       "clip",
+                       NULL,
+                       NULL,
+                       FALSE,
+                       G_PARAM_READABLE |
+                       G_PARAM_WRITABLE));
+
+       g_object_class_install_property (
+               gobject_class,
+               PROP_X_OFFSET,
+               g_param_spec_double (
+                       "x_offset",
+                       NULL,
+                       NULL,
+                       -G_MAXDOUBLE,
+                       G_MAXDOUBLE,
+                       0.0,
+                       G_PARAM_READABLE |
+                       G_PARAM_WRITABLE));
+
+       g_object_class_install_property (
+               gobject_class,
+               PROP_Y_OFFSET,
+               g_param_spec_double (
+                       "y_offset",
+                       NULL,
+                       NULL,
+                       -G_MAXDOUBLE,
+                       G_MAXDOUBLE,
+                       0.0,
+                       G_PARAM_READABLE |
+                       G_PARAM_WRITABLE));
+
+       g_object_class_install_property (
+               gobject_class,
+               PROP_FILL_COLOR,
+               g_param_spec_string (
+                       "fill_color",
+                       "Color",
+                       "Text color, as string",
+                       NULL,
+                       G_PARAM_WRITABLE));
+
+       g_object_class_install_property (
+               gobject_class,
+               PROP_FILL_COLOR_GDK,
+               g_param_spec_boxed (
+                       "fill_color_gdk",
+                       "Color",
+                       "Text color, as a GdkColor",
+                       GDK_TYPE_COLOR,
+                       G_PARAM_WRITABLE));
+
+       g_object_class_install_property (
+               gobject_class,
+               PROP_FILL_COLOR_RGBA,
+               g_param_spec_uint (
+                       "fill_color_rgba",
+                       "Color",
+                       "Text color, as an R/G/B/A combined integer",
+                       0, G_MAXUINT, 0,
+                       G_PARAM_READABLE |
+                       G_PARAM_WRITABLE));
+
+       g_object_class_install_property (
+               gobject_class,
+               PROP_TEXT_WIDTH,
+               g_param_spec_double (
+                       "text_width",
+                       "Text width",
+                       "Width of the rendered text",
+                       0.0, G_MAXDOUBLE, 0.0,
+                       G_PARAM_READABLE));
+
+       g_object_class_install_property (
+               gobject_class,
+               PROP_TEXT_HEIGHT,
+               g_param_spec_double (
+                       "text_height",
+                       "Text height",
+                       "Height of the rendered text",
+                       0.0, G_MAXDOUBLE, 0.0,
+                       G_PARAM_READABLE));
+
+       /* Style props are set (explicitly applied) or not */
+#define ADD_SET_PROP(propname, propval, nick, blurb) \
+       g_object_class_install_property ( \
+               gobject_class, propval, \
+               g_param_spec_boolean ( \
+                       propname, nick, blurb, FALSE, \
+                       G_PARAM_READABLE | G_PARAM_WRITABLE))
+
+       ADD_SET_PROP (
+               "family_set",
+               PROP_FAMILY_SET,
+               "Font family set",
+               "Whether this tag affects the font family");
+
+       ADD_SET_PROP (
+               "style_set",
+               PROP_STYLE_SET,
+               "Font style set",
+               "Whether this tag affects the font style");
+
+       ADD_SET_PROP (
+               "variant_set",
+               PROP_VARIANT_SET,
+               "Font variant set",
+               "Whether this tag affects the font variant");
+
+       ADD_SET_PROP (
+               "weight_set",
+               PROP_WEIGHT_SET,
+               "Font weight set",
+               "Whether this tag affects the font weight");
+
+       ADD_SET_PROP (
+               "stretch_set",
+               PROP_STRETCH_SET,
+               "Font stretch set",
+               "Whether this tag affects the font stretch");
+
+       ADD_SET_PROP (
+               "size_set",
+               PROP_SIZE_SET,
+               "Font size set",
+               "Whether this tag affects the font size");
+
+       ADD_SET_PROP (
+               "rise_set",
+               PROP_RISE_SET,
+               "Rise set",
+               "Whether this tag affects the rise");
+
+       ADD_SET_PROP (
+               "strikethrough_set",
+               PROP_STRIKETHROUGH_SET,
+               "Strikethrough set",
+               "Whether this tag affects strikethrough");
+
+       ADD_SET_PROP (
+               "underline_set",
+               PROP_UNDERLINE_SET,
+               "Underline set",
+               "Whether this tag affects underlining");
+
+       ADD_SET_PROP (
+               "scale_set",
+               PROP_SCALE_SET,
+               "Scale set",
+               "Whether this tag affects font scaling");
+#undef ADD_SET_PROP
+
+       item_class->dispose = gnome_canvas_text_dispose;
+       item_class->update = gnome_canvas_text_update;
+       item_class->draw = gnome_canvas_text_draw;
+       item_class->point = gnome_canvas_text_point;
+       item_class->bounds = gnome_canvas_text_bounds;
+}
+
+/* Object initialization function for the text item */
+static void
+gnome_canvas_text_init (GnomeCanvasText *text)
+{
+       text->x = 0.0;
+       text->y = 0.0;
+       text->justification = GTK_JUSTIFY_LEFT;
+       text->clip_width = 0.0;
+       text->clip_height = 0.0;
+       text->xofs = 0.0;
+       text->yofs = 0.0;
+       text->layout = NULL;
+
+       text->font_desc = NULL;
+
+       text->underline = PANGO_UNDERLINE_NONE;
+       text->strikethrough = FALSE;
+       text->rise = 0;
+
+       text->underline_set = FALSE;
+       text->strike_set = FALSE;
+       text->rise_set = FALSE;
+}
+
+/* Dispose handler for the text item */
+static void
+gnome_canvas_text_dispose (GnomeCanvasItem *object)
+{
+       GnomeCanvasText *text;
+
+       g_return_if_fail (GNOME_IS_CANVAS_TEXT (object));
+
+       text = GNOME_CANVAS_TEXT (object);
+
+       g_free (text->text);
+       text->text = NULL;
+
+       g_clear_object (&text->layout);
+       g_clear_pointer (&text->font_desc, pango_font_description_free);
+       g_clear_pointer (&text->attr_list, pango_attr_list_unref);
+
+       GNOME_CANVAS_ITEM_CLASS (gnome_canvas_text_parent_class)->
+               dispose (object);
+}
+
+static void
+get_bounds (GnomeCanvasText *text,
+            gdouble *px1,
+            gdouble *py1,
+            gdouble *px2,
+            gdouble *py2)
+{
+       GnomeCanvasItem *item;
+       gdouble wx, wy;
+
+       item = GNOME_CANVAS_ITEM (text);
+
+       /* Get canvas pixel coordinates for text position */
+
+       wx = text->x;
+       wy = text->y;
+       gnome_canvas_item_i2w (item, &wx, &wy);
+       gnome_canvas_w2c (
+               item->canvas, wx + text->xofs, wy + text->yofs,
+               &text->cx, &text->cy);
+
+       /* Get canvas pixel coordinates for clip rectangle position */
+
+       gnome_canvas_w2c (item->canvas, wx, wy, &text->clip_cx, &text->clip_cy);
+       text->clip_cwidth = text->clip_width;
+       text->clip_cheight = text->clip_height;
+
+       /* Bounds */
+
+       if (text->clip) {
+               *px1 = text->clip_cx;
+               *py1 = text->clip_cy;
+               *px2 = text->clip_cx + text->clip_cwidth;
+               *py2 = text->clip_cy + text->clip_cheight;
+       } else {
+               *px1 = text->cx;
+               *py1 = text->cy;
+               *px2 = text->cx + text->max_width;
+               *py2 = text->cy + text->height;
+       }
+}
+
+static PangoFontMask
+get_property_font_set_mask (guint property_id)
+{
+       switch (property_id) {
+               case PROP_FAMILY_SET:
+                       return PANGO_FONT_MASK_FAMILY;
+               case PROP_STYLE_SET:
+                       return PANGO_FONT_MASK_STYLE;
+               case PROP_VARIANT_SET:
+                       return PANGO_FONT_MASK_VARIANT;
+               case PROP_WEIGHT_SET:
+                       return PANGO_FONT_MASK_WEIGHT;
+               case PROP_STRETCH_SET:
+                       return PANGO_FONT_MASK_STRETCH;
+               case PROP_SIZE_SET:
+                       return PANGO_FONT_MASK_SIZE;
+       }
+
+       return 0;
+}
+
+static void
+ensure_font (GnomeCanvasText *text)
+{
+       if (!text->font_desc)
+               text->font_desc = pango_font_description_new ();
+}
+
+/* Set_arg handler for the text item */
+static void
+gnome_canvas_text_set_property (GObject *object,
+                                guint param_id,
+                                const GValue *value,
+                                GParamSpec *pspec)
+{
+       GnomeCanvasItem *item;
+       GnomeCanvasText *text;
+       GdkColor *pcolor;
+       PangoAlignment align;
+
+       g_return_if_fail (object != NULL);
+       g_return_if_fail (GNOME_IS_CANVAS_TEXT (object));
+
+       item = GNOME_CANVAS_ITEM (object);
+       text = GNOME_CANVAS_TEXT (object);
+
+       if (!text->layout)
+               text->layout = pango_layout_new (
+                       gtk_widget_get_pango_context (
+                       GTK_WIDGET (item->canvas)));
+
+       switch (param_id) {
+       case PROP_TEXT:
+               g_free (text->text);
+
+               text->text = g_value_dup_string (value);
+               pango_layout_set_text (text->layout, text->text, -1);
+
+               break;
+
+       case PROP_MARKUP:
+               gnome_canvas_text_set_markup (
+                       text, g_value_get_string (value));
+               break;
+
+       case PROP_X:
+               text->x = g_value_get_double (value);
+               break;
+
+       case PROP_Y:
+               text->y = g_value_get_double (value);
+               break;
+
+       case PROP_FONT: {
+               const gchar *font_name;
+               PangoFontDescription *font_desc;
+
+               font_name = g_value_get_string (value);
+               if (font_name)
+                       font_desc = pango_font_description_from_string (font_name);
+               else
+                       font_desc = NULL;
+
+               gnome_canvas_text_set_font_desc (text, font_desc);
+               if (font_desc)
+                       pango_font_description_free (font_desc);
+
+               break;
+       }
+
+       case PROP_FONT_DESC:
+               gnome_canvas_text_set_font_desc (text, g_value_peek_pointer (value));
+               break;
+
+       case PROP_FAMILY:
+       case PROP_STYLE:
+       case PROP_VARIANT:
+       case PROP_WEIGHT:
+       case PROP_STRETCH:
+       case PROP_SIZE:
+       case PROP_SIZE_POINTS:
+               ensure_font (text);
+
+               switch (param_id) {
+               case PROP_FAMILY:
+                       pango_font_description_set_family (
+                               text->font_desc,
+                               g_value_get_string (value));
+                       break;
+               case PROP_STYLE:
+                       pango_font_description_set_style (
+                               text->font_desc,
+                               g_value_get_enum (value));
+                       break;
+               case PROP_VARIANT:
+                       pango_font_description_set_variant (
+                               text->font_desc,
+                               g_value_get_enum (value));
+                       break;
+               case PROP_WEIGHT:
+                       pango_font_description_set_weight (
+                               text->font_desc,
+                               g_value_get_int (value));
+                       break;
+               case PROP_STRETCH:
+                       pango_font_description_set_stretch (
+                               text->font_desc,
+                               g_value_get_enum (value));
+                       break;
+               case PROP_SIZE:
+                       /* FIXME: This is bogus! It should be pixels, not points/PANGO_SCALE! */
+                       pango_font_description_set_size (
+                               text->font_desc,
+                               g_value_get_int (value));
+                       break;
+               case PROP_SIZE_POINTS:
+                       pango_font_description_set_size (
+                               text->font_desc,
+                               g_value_get_double (value) * PANGO_SCALE);
+                       break;
+               }
+
+               gnome_canvas_text_apply_font_desc (text);
+               break;
+
+       case PROP_FAMILY_SET:
+       case PROP_STYLE_SET:
+       case PROP_VARIANT_SET:
+       case PROP_WEIGHT_SET:
+       case PROP_STRETCH_SET:
+       case PROP_SIZE_SET:
+               if (!g_value_get_boolean (value) && text->font_desc)
+                       pango_font_description_unset_fields (
+                               text->font_desc,
+                               get_property_font_set_mask (param_id));
+               break;
+
+       case PROP_SCALE:
+               text->scale = g_value_get_double (value);
+               text->scale_set = TRUE;
+
+               gnome_canvas_text_apply_font_desc (text);
+               break;
+
+       case PROP_SCALE_SET:
+               text->scale_set = g_value_get_boolean (value);
+
+               gnome_canvas_text_apply_font_desc (text);
+               break;
+
+       case PROP_UNDERLINE:
+               text->underline = g_value_get_enum (value);
+               text->underline_set = TRUE;
+
+               gnome_canvas_text_apply_attributes (text);
+               break;
+
+       case PROP_UNDERLINE_SET:
+               text->underline_set = g_value_get_boolean (value);
+
+               gnome_canvas_text_apply_attributes (text);
+               break;
+
+       case PROP_STRIKETHROUGH:
+               text->strikethrough = g_value_get_boolean (value);
+               text->strike_set = TRUE;
+
+               gnome_canvas_text_apply_attributes (text);
+               break;
+
+       case PROP_STRIKETHROUGH_SET:
+               text->strike_set = g_value_get_boolean (value);
+
+               gnome_canvas_text_apply_attributes (text);
+               break;
+
+       case PROP_RISE:
+               text->rise = g_value_get_int (value);
+               text->rise_set = TRUE;
+
+               gnome_canvas_text_apply_attributes (text);
+               break;
+
+       case PROP_RISE_SET:
+               text->rise_set = TRUE;
+
+               gnome_canvas_text_apply_attributes (text);
+               break;
+
+       case PROP_ATTRIBUTES:
+               if (text->attr_list)
+                       pango_attr_list_unref (text->attr_list);
+
+               text->attr_list = g_value_peek_pointer (value);
+               pango_attr_list_ref (text->attr_list);
+
+               gnome_canvas_text_apply_attributes (text);
+               break;
+
+       case PROP_JUSTIFICATION:
+               text->justification = g_value_get_enum (value);
+
+               switch (text->justification) {
+               case GTK_JUSTIFY_LEFT:
+                       align = PANGO_ALIGN_LEFT;
+                       break;
+               case GTK_JUSTIFY_CENTER:
+                       align = PANGO_ALIGN_CENTER;
+                       break;
+               case GTK_JUSTIFY_RIGHT:
+                       align = PANGO_ALIGN_RIGHT;
+                       break;
+               default:
+                       /* GTK_JUSTIFY_FILL isn't supported yet. */
+                       align = PANGO_ALIGN_LEFT;
+                       break;
+               }
+               pango_layout_set_alignment (text->layout, align);
+               break;
+
+       case PROP_CLIP_WIDTH:
+               text->clip_width = fabs (g_value_get_double (value));
+               break;
+
+       case PROP_CLIP_HEIGHT:
+               text->clip_height = fabs (g_value_get_double (value));
+               break;
+
+       case PROP_CLIP:
+               text->clip = g_value_get_boolean (value);
+               break;
+
+       case PROP_X_OFFSET:
+               text->xofs = g_value_get_double (value);
+               break;
+
+       case PROP_Y_OFFSET:
+               text->yofs = g_value_get_double (value);
+               break;
+
+       case PROP_FILL_COLOR: {
+               const gchar *color_name;
+
+               color_name = g_value_get_string (value);
+               if (color_name) {
+                       GdkColor color;
+                       if (gdk_color_parse (color_name, &color)) {
+                               text->rgba = GNOME_CANVAS_COLOR (color.red, color.green, color.blue);
+                       } else {
+                               g_warning (
+                                       "%s: Failed to parse color form string '%s'",
+                                       G_STRFUNC, color_name);
+                       }
+               }
+               break;
+       }
+
+       case PROP_FILL_COLOR_GDK:
+               pcolor = g_value_get_boxed (value);
+               if (pcolor) {
+                       text->rgba = GNOME_CANVAS_COLOR (pcolor->red, pcolor->green, pcolor->blue);
+               } else {
+                       text->rgba = 0;
+               }
+               break;
+
+       case PROP_FILL_COLOR_RGBA:
+               text->rgba = g_value_get_uint (value);
+               break;
+
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+               break;
+       }
+
+       /* Calculate text dimensions */
+
+       if (text->layout)
+               pango_layout_get_pixel_size (
+                       text->layout,
+                       &text->max_width,
+                       &text->height);
+       else {
+               text->max_width = 0;
+               text->height = 0;
+       }
+
+       gnome_canvas_item_request_update (item);
+}
+
+/* Get_arg handler for the text item */
+static void
+gnome_canvas_text_get_property (GObject *object,
+                                guint param_id,
+                                GValue *value,
+                                GParamSpec *pspec)
+{
+       GnomeCanvasText *text;
+
+       g_return_if_fail (object != NULL);
+       g_return_if_fail (GNOME_IS_CANVAS_TEXT (object));
+
+       text = GNOME_CANVAS_TEXT (object);
+
+       switch (param_id) {
+       case PROP_TEXT:
+               g_value_set_string (value, text->text);
+               break;
+
+       case PROP_X:
+               g_value_set_double (value, text->x);
+               break;
+
+       case PROP_Y:
+               g_value_set_double (value, text->y);
+               break;
+
+       case PROP_FONT:
+       case PROP_FONT_DESC:
+       case PROP_FAMILY:
+       case PROP_STYLE:
+       case PROP_VARIANT:
+       case PROP_WEIGHT:
+       case PROP_STRETCH:
+       case PROP_SIZE:
+       case PROP_SIZE_POINTS:
+               ensure_font (text);
+
+               switch (param_id) {
+               case PROP_FONT:
+               {
+                       /* FIXME GValue imposes a totally gratuitous string
+                        *       copy here, we could just hand off string
+                        *       ownership. */
+                       gchar *str;
+
+                       str = pango_font_description_to_string (text->font_desc);
+                       g_value_set_string (value, str);
+                       g_free (str);
+
+                       break;
+               }
+
+               case PROP_FONT_DESC:
+                       g_value_set_boxed (value, text->font_desc);
+                       break;
+
+               case PROP_FAMILY:
+                       g_value_set_string (
+                               value,
+                               pango_font_description_get_family (
+                               text->font_desc));
+                       break;
+
+               case PROP_STYLE:
+                       g_value_set_enum (
+                               value,
+                               pango_font_description_get_style (
+                               text->font_desc));
+                       break;
+
+               case PROP_VARIANT:
+                       g_value_set_enum (
+                               value,
+                               pango_font_description_get_variant (
+                               text->font_desc));
+                       break;
+
+               case PROP_WEIGHT:
+                       g_value_set_int (
+                               value,
+                               pango_font_description_get_weight (
+                               text->font_desc));
+                       break;
+
+               case PROP_STRETCH:
+                       g_value_set_enum (
+                               value,
+                               pango_font_description_get_stretch (
+                               text->font_desc));
+                       break;
+
+               case PROP_SIZE:
+                       g_value_set_int (
+                               value,
+                               pango_font_description_get_size (
+                               text->font_desc));
+                       break;
+
+               case PROP_SIZE_POINTS:
+                       g_value_set_double (
+                               value, ((gdouble)
+                               pango_font_description_get_size (
+                               text->font_desc)) / (gdouble) PANGO_SCALE);
+                       break;
+               }
+               break;
+
+       case PROP_FAMILY_SET:
+       case PROP_STYLE_SET:
+       case PROP_VARIANT_SET:
+       case PROP_WEIGHT_SET:
+       case PROP_STRETCH_SET:
+       case PROP_SIZE_SET:
+       {
+               PangoFontMask set_mask = text->font_desc ?
+                       pango_font_description_get_set_fields (text->font_desc) : 0;
+               PangoFontMask test_mask = get_property_font_set_mask (param_id);
+               g_value_set_boolean (value, (set_mask & test_mask) != 0);
+
+               break;
+       }
+
+       case PROP_SCALE:
+               g_value_set_double (value, text->scale);
+               break;
+       case PROP_SCALE_SET:
+               g_value_set_boolean (value, text->scale_set);
+               break;
+
+       case PROP_UNDERLINE:
+               g_value_set_enum (value, text->underline);
+               break;
+       case PROP_UNDERLINE_SET:
+               g_value_set_boolean (value, text->underline_set);
+               break;
+
+       case PROP_STRIKETHROUGH:
+               g_value_set_boolean (value, text->strikethrough);
+               break;
+       case PROP_STRIKETHROUGH_SET:
+               g_value_set_boolean (value, text->strike_set);
+               break;
+
+       case PROP_RISE:
+               g_value_set_int (value, text->rise);
+               break;
+       case PROP_RISE_SET:
+               g_value_set_boolean (value, text->rise_set);
+               break;
+
+       case PROP_ATTRIBUTES:
+               g_value_set_boxed (value, text->attr_list);
+               break;
+
+       case PROP_JUSTIFICATION:
+               g_value_set_enum (value, text->justification);
+               break;
+
+       case PROP_CLIP_WIDTH:
+               g_value_set_double (value, text->clip_width);
+               break;
+
+       case PROP_CLIP_HEIGHT:
+               g_value_set_double (value, text->clip_height);
+               break;
+
+       case PROP_CLIP:
+               g_value_set_boolean (value, text->clip);
+               break;
+
+       case PROP_X_OFFSET:
+               g_value_set_double (value, text->xofs);
+               break;
+
+       case PROP_Y_OFFSET:
+               g_value_set_double (value, text->yofs);
+               break;
+
+       case PROP_FILL_COLOR_RGBA:
+               g_value_set_uint (value, text->rgba);
+               break;
+
+       case PROP_TEXT_WIDTH:
+               g_value_set_double (value, text->max_width);
+               break;
+
+       case PROP_TEXT_HEIGHT:
+               g_value_set_double (value, text->height);
+               break;
+
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+               break;
+       }
+}
+
+/* */
+static void
+gnome_canvas_text_apply_font_desc (GnomeCanvasText *text)
+{
+       PangoFontDescription *font_desc;
+       PangoContext *pango_context;
+       GtkWidget *widget;
+
+       widget = GTK_WIDGET (GNOME_CANVAS_ITEM (text)->canvas);
+       pango_context = gtk_widget_create_pango_context (widget);
+       font_desc = pango_font_description_copy (pango_context_get_font_description (pango_context));
+       g_object_unref (pango_context);
+
+       if (text->font_desc)
+               pango_font_description_merge (font_desc, text->font_desc, TRUE);
+
+       pango_layout_set_font_description (text->layout, font_desc);
+       pango_font_description_free (font_desc);
+}
+
+static void
+add_attr (PangoAttrList *attr_list,
+          PangoAttribute *attr)
+{
+       attr->start_index = 0;
+       attr->end_index = G_MAXINT;
+
+       pango_attr_list_insert (attr_list, attr);
+}
+
+/* */
+static void
+gnome_canvas_text_apply_attributes (GnomeCanvasText *text)
+{
+       PangoAttrList *attr_list;
+
+       if (text->attr_list)
+               attr_list = pango_attr_list_copy (text->attr_list);
+       else
+               attr_list = pango_attr_list_new ();
+
+       if (text->underline_set)
+               add_attr (attr_list, pango_attr_underline_new (text->underline));
+       if (text->strike_set)
+               add_attr (attr_list, pango_attr_strikethrough_new (text->strikethrough));
+       if (text->rise_set)
+               add_attr (attr_list, pango_attr_rise_new (text->rise));
+
+       pango_layout_set_attributes (text->layout, attr_list);
+       pango_attr_list_unref (attr_list);
+}
+
+static void
+gnome_canvas_text_set_font_desc (GnomeCanvasText *text,
+                                 PangoFontDescription *font_desc)
+{
+       if (text->font_desc)
+               pango_font_description_free (text->font_desc);
+
+       if (font_desc)
+               text->font_desc = pango_font_description_copy (font_desc);
+       else
+               text->font_desc = NULL;
+
+       gnome_canvas_text_apply_font_desc (text);
+}
+
+/* Setting the text from a Pango markup string */
+static void
+gnome_canvas_text_set_markup (GnomeCanvasText *textitem,
+                              const gchar *markup)
+{
+       PangoAttrList *attr_list = NULL;
+       gchar         *text = NULL;
+       GError        *error = NULL;
+
+       if (markup && !pango_parse_markup (markup, -1,
+                                          0,
+                                          &attr_list, &text, NULL,
+                                          &error))
+       {
+               g_warning (
+                       "Failed to set cell text from markup due to "
+                       "error parsing markup: %s", error->message);
+               g_error_free (error);
+               return;
+       }
+
+       g_free (textitem->text);
+       if (textitem->attr_list)
+               pango_attr_list_unref (textitem->attr_list);
+
+       textitem->text = text;
+       textitem->attr_list = attr_list;
+
+       pango_layout_set_text (textitem->layout, text, -1);
+
+       gnome_canvas_text_apply_attributes (textitem);
+}
+
+/* Update handler for the text item */
+static void
+gnome_canvas_text_update (GnomeCanvasItem *item,
+                          const cairo_matrix_t *matrix,
+                          gint flags)
+{
+       GnomeCanvasText *text;
+       gdouble x1, y1, x2, y2;
+
+       text = GNOME_CANVAS_TEXT (item);
+
+       GNOME_CANVAS_ITEM_CLASS (gnome_canvas_text_parent_class)->
+               update (item, matrix, flags);
+
+       get_bounds (text, &x1, &y1, &x2, &y2);
+
+       gnome_canvas_update_bbox (
+               item,
+               floor (x1), floor (y1),
+               ceil (x2), ceil (y2));
+}
+
+/* Draw handler for the text item */
+static void
+gnome_canvas_text_draw (GnomeCanvasItem *item,
+                        cairo_t *cr,
+                        gint x,
+                        gint y,
+                        gint width,
+                        gint height)
+{
+       GnomeCanvasText *text = GNOME_CANVAS_TEXT (item);
+
+       if (!text->text)
+               return;
+
+       cairo_save (cr);
+
+       if (text->clip) {
+               cairo_rectangle (
+                       cr,
+                       text->clip_cx - x,
+                       text->clip_cy - y,
+                       text->clip_cwidth,
+                       text->clip_cheight);
+               cairo_clip (cr);
+       }
+
+       cairo_set_source_rgba (
+               cr,
+               ((text->rgba >> 24) & 0xff) / 255.0,
+               ((text->rgba >> 16) & 0xff) / 255.0,
+               ((text->rgba >> 8) & 0xff) / 255.0,
+               ( text->rgba & 0xff) / 255.0);
+
+       cairo_move_to (cr, text->cx - x, text->cy - y);
+       pango_cairo_show_layout (cr, text->layout);
+
+       cairo_restore (cr);
+}
+
+/* Point handler for the text item */
+static GnomeCanvasItem *
+gnome_canvas_text_point (GnomeCanvasItem *item,
+                         gdouble x,
+                         gdouble y,
+                         gint cx,
+                         gint cy)
+{
+       GnomeCanvasText *text;
+       PangoLayoutIter *iter;
+       gint x1, y1, x2, y2;
+
+       text = GNOME_CANVAS_TEXT (item);
+
+       /* The idea is to build bounding rectangles for each of the lines of
+        * text (clipped by the clipping rectangle, if it is activated) and see
+        * whether the point is inside any of these.  If it is, we are done.
+        * Otherwise, calculate the distance to the nearest rectangle.
+        */
+
+       iter = pango_layout_get_iter (text->layout);
+       do {
+               PangoRectangle log_rect;
+
+               pango_layout_iter_get_line_extents (iter, NULL, &log_rect);
+
+               x1 = text->cx + PANGO_PIXELS (log_rect.x);
+               y1 = text->cy + PANGO_PIXELS (log_rect.y);
+               x2 = x1 + PANGO_PIXELS (log_rect.width);
+               y2 = y1 + PANGO_PIXELS (log_rect.height);
+
+               if (text->clip) {
+                       if (x1 < text->clip_cx)
+                               x1 = text->clip_cx;
+
+                       if (y1 < text->clip_cy)
+                               y1 = text->clip_cy;
+
+                       if (x2 > (text->clip_cx + text->clip_width))
+                               x2 = text->clip_cx + text->clip_width;
+
+                       if (y2 > (text->clip_cy + text->clip_height))
+                               y2 = text->clip_cy + text->clip_height;
+
+                       if ((x1 >= x2) || (y1 >= y2))
+                               continue;
+               }
+
+               /* Calculate distance from point to rectangle */
+
+               if (cx >= x1 && cx < x2 && cy >= y1 && cy < y2) {
+                       pango_layout_iter_free (iter);
+                       return item;
+               }
+
+       } while (pango_layout_iter_next_line (iter));
+
+       pango_layout_iter_free (iter);
+
+       return NULL;
+}
+
+/* Bounds handler for the text item */
+static void
+gnome_canvas_text_bounds (GnomeCanvasItem *item,
+                          gdouble *x1,
+                          gdouble *y1,
+                          gdouble *x2,
+                          gdouble *y2)
+{
+       GnomeCanvasText *text;
+       gdouble width, height;
+
+       text = GNOME_CANVAS_TEXT (item);
+
+       *x1 = text->x;
+       *y1 = text->y;
+
+       if (text->clip) {
+               width = text->clip_width;
+               height = text->clip_height;
+       } else {
+               width = text->max_width;
+               height = text->height;
+       }
+
+       *x2 = *x1 + width;
+       *y2 = *y1 + height;
+}
diff --git a/src/libgnomecanvas/gnome-canvas-text.h b/src/libgnomecanvas/gnome-canvas-text.h
new file mode 100644
index 00000000..dc868641
--- /dev/null
+++ b/src/libgnomecanvas/gnome-canvas-text.h
@@ -0,0 +1,150 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation
+ * All rights reserved.
+ *
+ * This file is part of the Gnome Library.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * published by the Free Software Foundation; either the
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * License along with the Gnome Library; see the file COPYING.LIB.  If not,
+ */
+/*
+  @NOTATION@
+ */
+/* Text item type for GnomeCanvas widget
+ *
+ * GnomeCanvas is basically a port of the Tk toolkit's most excellent canvas widget.  Tk is
+ * copyrighted by the Regents of the University of California, Sun Microsystems, and other parties.
+ *
+ *
+ * Author: Federico Mena <federico nuclecu unam mx>
+ * Port to Pango co-done by Gergõ Érdi <cactus cactus rulez org>
+ */
+
+#ifndef GNOME_CANVAS_TEXT_H
+#define GNOME_CANVAS_TEXT_H
+
+#include <libgnomecanvas/gnome-canvas.h>
+
+G_BEGIN_DECLS
+
+/* Text item for the canvas.  Text items are positioned by an anchor point and an anchor direction.
+ *
+ * A clipping rectangle may be specified for the text.  The rectangle is anchored at the text's anchor
+ * point, and is specified by clipping width and height parameters.  If the clipping rectangle is
+ * enabled, it will clip the text.
+ *
+ * In addition, x and y offset values may be specified.  These specify an offset from the anchor
+ * position.  If used in conjunction with the clipping rectangle, these could be used to implement
+ * simple scrolling of the text within the clipping rectangle.
+ *
+ * Properties marked with [*] also have _set properties associated
+ * with them, that determine if the specified value should be used
+ * instead of the default (style-defined) values
+ *
+ * The following object arguments are available:
+ *
+ * name                        type                    read/write      description
+ * ------------------------------------------------------------------------------------------
+ * text                        string                  RW              The string of the text label
+ * markup              string                   W              A Pango markup string for the text label
+ *
+ * x                   gdouble                 RW              X coordinate of anchor point
+ * y                   gdouble                 RW              Y coordinate of anchor point
+ *
+ * font                        string                   W              A string describing the font
+ * font_desc           PangoFontDescription*   RW              Pointer to a PangoFontDescriptor
+ * attributes           PangoAttrList*          RW             Pointer to a Pango attribute list
+ * style               PangoStyle              RW              Pango style of font to use      [*]
+ * variant             PangoVariant            RW              Pango variant of font to use    [*]
+ * weight              gint                    RW              Pango weight of font to use     [*]
+ * stretch             PangoStretch            RW              Pango stretch of font to use    [*]
+ * size                        gint                    RW              Size (in pixels) of font        [*]
+ * size_points         gdouble                 RW              Size (in points) of font
+ * scale                gdouble                  RW              Ratio to scale font           [*]
+ *
+ * justification       GtkJustification        RW              Justification for multiline text
+ * clip_width          gdouble                 RW              Width of clip rectangle
+ * clip_height         gdouble                 RW              Height of clip rectangle
+ * clip                        boolean                 RW              Use clipping rectangle?
+ * x_offset            gdouble                 RW              Horizontal offset distance from anchor 
position
+ * y_offset            gdouble                 RW              Vertical offset distance from anchor position
+ *
+ * text_width          gdouble                 R               Used to query the width of the rendered text
+ * text_height         gdouble                 R               Used to query the rendered height of the text
+ *
+ * fill_color          string                   W              X color specification for text
+ * fill_color_gdk      GdkColor*               RW              Pointer to an allocated GdkColor
+ * fill_color_rgba     guint                   RW              RGBA value used for AA color.
+ */
+
+#define GNOME_TYPE_CANVAS_TEXT            (gnome_canvas_text_get_type ())
+#define GNOME_CANVAS_TEXT(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNOME_TYPE_CANVAS_TEXT, 
GnomeCanvasText))
+#define GNOME_CANVAS_TEXT_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GNOME_TYPE_CANVAS_TEXT, 
GnomeCanvasTextClass))
+#define GNOME_IS_CANVAS_TEXT(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNOME_TYPE_CANVAS_TEXT))
+#define GNOME_IS_CANVAS_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GNOME_TYPE_CANVAS_TEXT))
+#define GNOME_CANVAS_TEXT_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GNOME_TYPE_CANVAS_TEXT, 
GnomeCanvasTextClass))
+
+typedef struct _GnomeCanvasText GnomeCanvasText;
+typedef struct _GnomeCanvasTextClass GnomeCanvasTextClass;
+
+struct _GnomeCanvasText {
+       GnomeCanvasItem item;
+
+       PangoFontDescription *font_desc; /* Font description for text */
+       PangoAttrList *attr_list;        /* Attribute list of the text (caching) */
+       PangoUnderline underline;
+       gboolean       strikethrough;
+       gint            rise;
+       gdouble         scale;
+
+       gchar *text;                    /* Text to display */
+        PangoLayout *layout;            /* The PangoLayout containing the text */
+
+       gdouble x, y;                   /* Position at anchor */
+
+       gdouble clip_width;             /* Width of optional clip rectangle */
+       gdouble clip_height;            /* Height of optional clip rectangle */
+
+       gdouble xofs, yofs;             /* Text offset distance from anchor position */
+
+       gdouble affine[6];               /* The item -> canvas affine */ /*AA */
+
+       GtkJustification justification; /* Justification for text */
+
+       gint cx, cy;                    /* Top-left canvas coordinates for text */
+       gint clip_cx, clip_cy;          /* Top-left canvas coordinates for clip rectangle */
+       gint clip_cwidth, clip_cheight; /* Size of clip rectangle in pixels */
+       gint max_width;                 /* Maximum width of text lines */
+       gint height;                    /* Rendered text height in pixels */
+
+        guint32 rgba;                  /* RGBA color for text */ /*AA */
+
+       guint clip : 1;                 /* Use clip rectangle? */
+
+       guint underline_set : 1;        /* Apply specified underline style? */
+       guint strike_set    : 1;        /* Apply specified strikethrough style? */
+       guint rise_set      : 1;        /* Apply specified ascension/descension? */
+
+       guint scale_set     : 1;        /* Apply specified font scaling ratio? */
+};
+
+struct _GnomeCanvasTextClass {
+       GnomeCanvasItemClass parent_class;
+};
+
+/* Standard Gtk function */
+GType gnome_canvas_text_get_type (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif
diff --git a/src/libgnomecanvas/gnome-canvas-util.c b/src/libgnomecanvas/gnome-canvas-util.c
new file mode 100644
index 00000000..60e70ff1
--- /dev/null
+++ b/src/libgnomecanvas/gnome-canvas-util.c
@@ -0,0 +1,167 @@
+/*
+ * Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation
+ * All rights reserved.
+ *
+ * This file is part of the Gnome Library.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * published by the Free Software Foundation; either the
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * License along with the Gnome Library; see the file COPYING.LIB.  If not,
+ */
+/*
+  @NOTATION@
+ */
+/* Miscellaneous utility functions for the GnomeCanvas widget
+ *
+ * GnomeCanvas is basically a port of the Tk toolkit's most excellent canvas
+ * widget.  Tk is copyrighted by the Regents of the University of California,
+ * Sun Microsystems, and other parties.
+ *
+ *
+ * Author: Federico Mena <federico nuclecu unam mx>
+ */
+
+#include "evolution-config.h"
+
+/* needed for M_PI_2 under 'gcc -ansi -predantic' on GNU/Linux */
+#ifndef _DEFAULT_SOURCE
+#  define _DEFAULT_SOURCE 1
+#endif
+#include <sys/types.h>
+
+#include <math.h>
+#include "gnome-canvas.h"
+#include "gnome-canvas-util.h"
+
+/* Here are some helper functions for aa rendering: */
+
+/**
+ * gnome_canvas_item_reset_bounds:
+ * @item: A canvas item
+ *
+ * Resets the bounding box of a canvas item to an empty rectangle.
+ **/
+void
+gnome_canvas_item_reset_bounds (GnomeCanvasItem *item)
+{
+       item->x1 = 0.0;
+       item->y1 = 0.0;
+       item->x2 = 0.0;
+       item->y2 = 0.0;
+}
+
+/**
+ * gnome_canvas_update_bbox:
+ * @item: the canvas item needing update
+ * @x1: Left coordinate of the new bounding box
+ * @y1: Top coordinate of the new bounding box
+ * @x2: Right coordinate of the new bounding box
+ * @y2: Bottom coordinate of the new bounding box
+ *
+ * Sets the bbox to the new value, requesting full repaint.
+ **/
+void
+gnome_canvas_update_bbox (GnomeCanvasItem *item,
+                          gint x1,
+                          gint y1,
+                          gint x2,
+                          gint y2)
+{
+       gnome_canvas_request_redraw (
+               item->canvas, item->x1, item->y1, item->x2, item->y2);
+
+       item->x1 = x1;
+       item->y1 = y1;
+       item->x2 = x2;
+       item->y2 = y2;
+
+       gnome_canvas_request_redraw (
+               item->canvas, item->x1, item->y1, item->x2, item->y2);
+}
+
+/**
+ * gnome_canvas_cairo_create_scratch:
+ *
+ * Create a scratch #cairo_t. This is useful for measuring purposes or
+ * calling functions like cairo_in_fill().
+ *
+ * Returns: A new cairo_t. Destroy with cairo_destroy() after use.
+ **/
+cairo_t *
+gnome_canvas_cairo_create_scratch (void)
+{
+       cairo_surface_t *surface;
+       cairo_t *cr;
+
+       surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 0, 0);
+       cr = cairo_create (surface);
+       cairo_surface_destroy (surface);
+
+       return cr;
+}
+
+/**
+ * gnome_canvas_matrix_transform_rect:
+ * @matrix: a cairo matrix
+ * @x1: x coordinate of top left position of rectangle (in-out)
+ * @y1: y coordinate of top left position of rectangle (in-out)
+ * @x2: x coordinate of bottom right position of rectangle (in-out)
+ * @y2: y coordinate of bottom right position of rectangle (in-out)
+ *
+ * Computes the smallest rectangle containing the whole area of the given
+ * rectangle after applying the transformation given in @matrix.
+ **/
+void
+gnome_canvas_matrix_transform_rect (const cairo_matrix_t *matrix,
+                                    gdouble *x1,
+                                    gdouble *y1,
+                                    gdouble *x2,
+                                    gdouble *y2)
+{
+       gdouble maxx, maxy, minx, miny;
+       gdouble tmpx, tmpy;
+
+       tmpx = *x1;
+       tmpy = *y1;
+       cairo_matrix_transform_point (matrix, &tmpx, &tmpy);
+       minx = maxx = tmpx;
+       miny = maxy = tmpy;
+
+       tmpx = *x2;
+       tmpy = *y1;
+       cairo_matrix_transform_point (matrix, &tmpx, &tmpy);
+       minx = MIN (minx, tmpx);
+       maxx = MAX (maxx, tmpx);
+       miny = MIN (miny, tmpy);
+       maxy = MAX (maxy, tmpy);
+
+       tmpx = *x2;
+       tmpy = *y2;
+       cairo_matrix_transform_point (matrix, &tmpx, &tmpy);
+       minx = MIN (minx, tmpx);
+       maxx = MAX (maxx, tmpx);
+       miny = MIN (miny, tmpy);
+       maxy = MAX (maxy, tmpy);
+
+       tmpx = *x1;
+       tmpy = *y2;
+       cairo_matrix_transform_point (matrix, &tmpx, &tmpy);
+       minx = MIN (minx, tmpx);
+       maxx = MAX (maxx, tmpx);
+       miny = MIN (miny, tmpy);
+       maxy = MAX (maxy, tmpy);
+
+        *x1 = minx;
+        *x2 = maxx;
+        *y1 = miny;
+        *y2 = maxy;
+}
+
diff --git a/src/libgnomecanvas/gnome-canvas-util.h b/src/libgnomecanvas/gnome-canvas-util.h
new file mode 100644
index 00000000..c4d2325c
--- /dev/null
+++ b/src/libgnomecanvas/gnome-canvas-util.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation
+ * All rights reserved.
+ *
+ * This file is part of the Gnome Library.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * published by the Free Software Foundation; either the
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * License along with the Gnome Library; see the file COPYING.LIB.  If not,
+ */
+/*
+  @NOTATION@
+ */
+/* Miscellaneous utility functions for the GnomeCanvas widget
+ *
+ * GnomeCanvas is basically a port of the Tk toolkit's most excellent canvas widget.  Tk is
+ * copyrighted by the Regents of the University of California, Sun Microsystems, and other parties.
+ *
+ * Author: Federico Mena <federico nuclecu unam mx>
+ */
+
+#ifndef GNOME_CANVAS_UTIL_H
+#define GNOME_CANVAS_UTIL_H
+
+#include <libgnomecanvas/gnome-canvas.h>
+
+G_BEGIN_DECLS
+
+/* Sets the svp to the new value, requesting repaint on what's changed. This
+ * function takes responsibility for freeing new_svp. This routine also adds the
+ * svp's bbox to the item's.
+ */
+void gnome_canvas_item_reset_bounds (GnomeCanvasItem *item);
+
+/* Sets the bbox to the new value, requesting full repaint. */
+void gnome_canvas_update_bbox (GnomeCanvasItem *item, gint x1, gint y1, gint x2, gint y2);
+
+/* Create a scratch cairo_t for measuring purposes */
+cairo_t *gnome_canvas_cairo_create_scratch (void);
+
+void gnome_canvas_matrix_transform_rect (const cairo_matrix_t *matrix, double *x1, double *y1, double *x2, 
double *y2);
+
+G_END_DECLS
+
+#endif
diff --git a/src/libgnomecanvas/gnome-canvas-widget.c b/src/libgnomecanvas/gnome-canvas-widget.c
new file mode 100644
index 00000000..7593970e
--- /dev/null
+++ b/src/libgnomecanvas/gnome-canvas-widget.c
@@ -0,0 +1,467 @@
+/*
+ * Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation
+ * All rights reserved.
+ *
+ * This file is part of the Gnome Library.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * published by the Free Software Foundation; either the
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * License along with the Gnome Library; see the file COPYING.LIB.  If not,
+ */
+/*
+  @NOTATION@
+ */
+/* Widget item type for GnomeCanvas widget
+ *
+ * GnomeCanvas is basically a port of the Tk toolkit's most excellent canvas
+ * widget.  Tk is copyrighted by the Regents of the University of California,
+ * Sun Microsystems, and other parties.
+ *
+ *
+ * Author: Federico Mena <federico nuclecu unam mx>
+ */
+
+#include "evolution-config.h"
+
+#include <math.h>
+#include "gnome-canvas-widget.h"
+
+enum {
+       PROP_0,
+       PROP_WIDGET,
+       PROP_X,
+       PROP_Y,
+       PROP_WIDTH,
+       PROP_HEIGHT,
+       PROP_SIZE_PIXELS
+};
+
+static void gnome_canvas_widget_dispose    (GnomeCanvasItem      *object);
+static void gnome_canvas_widget_get_property (GObject            *object,
+                                             guint               param_id,
+                                             GValue             *value,
+                                             GParamSpec         *pspec);
+static void gnome_canvas_widget_set_property (GObject            *object,
+                                             guint               param_id,
+                                             const GValue       *value,
+                                             GParamSpec         *pspec);
+
+static void    gnome_canvas_widget_update      (GnomeCanvasItem *item,
+                                                const cairo_matrix_t *matrix,
+                                                gint flags);
+static GnomeCanvasItem *gnome_canvas_widget_point (GnomeCanvasItem *item,
+                                                gdouble x,
+                                                gdouble y,
+                                                gint cx,
+                                                gint cy);
+static void    gnome_canvas_widget_bounds      (GnomeCanvasItem *item,
+                                                gdouble *x1,
+                                                gdouble *y1,
+                                                gdouble *x2,
+                                                gdouble *y2);
+
+static void    gnome_canvas_widget_draw        (GnomeCanvasItem *item,
+                                                cairo_t *cr,
+                                                gint x,
+                                                gint y,
+                                                gint width,
+                                                gint height);
+
+G_DEFINE_TYPE (
+       GnomeCanvasWidget,
+       gnome_canvas_widget,
+       GNOME_TYPE_CANVAS_ITEM)
+
+static void
+gnome_canvas_widget_class_init (GnomeCanvasWidgetClass *class)
+{
+       GObjectClass *gobject_class;
+       GnomeCanvasItemClass *item_class;
+
+       gobject_class = (GObjectClass *) class;
+       item_class = (GnomeCanvasItemClass *) class;
+
+       gobject_class->set_property = gnome_canvas_widget_set_property;
+       gobject_class->get_property = gnome_canvas_widget_get_property;
+
+       g_object_class_install_property
+               (gobject_class,
+                PROP_WIDGET,
+                g_param_spec_object ("widget", NULL, NULL,
+                                     GTK_TYPE_WIDGET,
+                                     (G_PARAM_READABLE | G_PARAM_WRITABLE)));
+       g_object_class_install_property
+               (gobject_class,
+                PROP_X,
+                g_param_spec_double ("x", NULL, NULL,
+                                     -G_MAXDOUBLE, G_MAXDOUBLE, 0.0,
+                                     (G_PARAM_READABLE | G_PARAM_WRITABLE)));
+       g_object_class_install_property
+               (gobject_class,
+                PROP_Y,
+                g_param_spec_double ("y", NULL, NULL,
+                                     -G_MAXDOUBLE, G_MAXDOUBLE, 0.0,
+                                     (G_PARAM_READABLE | G_PARAM_WRITABLE)));
+       g_object_class_install_property
+               (gobject_class,
+                PROP_WIDTH,
+                g_param_spec_double ("width", NULL, NULL,
+                                     -G_MAXDOUBLE, G_MAXDOUBLE, 0.0,
+                                     (G_PARAM_READABLE | G_PARAM_WRITABLE)));
+       g_object_class_install_property
+               (gobject_class,
+                PROP_HEIGHT,
+                g_param_spec_double ("height", NULL, NULL,
+                                     -G_MAXDOUBLE, G_MAXDOUBLE, 0.0,
+                                     (G_PARAM_READABLE | G_PARAM_WRITABLE)));
+       g_object_class_install_property
+               (gobject_class,
+                PROP_SIZE_PIXELS,
+                g_param_spec_boolean ("size_pixels", NULL, NULL,
+                                      FALSE,
+                                      (G_PARAM_READABLE | G_PARAM_WRITABLE)));
+
+       item_class->dispose = gnome_canvas_widget_dispose;
+       item_class->update = gnome_canvas_widget_update;
+       item_class->point = gnome_canvas_widget_point;
+       item_class->bounds = gnome_canvas_widget_bounds;
+       item_class->draw = gnome_canvas_widget_draw;
+}
+
+static void
+do_destroy (gpointer data,
+            GObject *gone_object)
+{
+       GnomeCanvasWidget *witem;
+
+       witem = data;
+
+       if (!witem->in_destroy) {
+               witem->in_destroy = TRUE;
+               g_object_run_dispose (G_OBJECT (witem));
+       }
+}
+
+static void
+gnome_canvas_widget_init (GnomeCanvasWidget *witem)
+{
+       witem->x = 0.0;
+       witem->y = 0.0;
+       witem->width = 0.0;
+       witem->height = 0.0;
+       witem->size_pixels = FALSE;
+}
+
+static void
+gnome_canvas_widget_dispose (GnomeCanvasItem *object)
+{
+       GnomeCanvasWidget *witem;
+
+       g_return_if_fail (object != NULL);
+       g_return_if_fail (GNOME_IS_CANVAS_WIDGET (object));
+
+       witem = GNOME_CANVAS_WIDGET (object);
+
+       if (witem->widget && !witem->in_destroy) {
+               g_object_weak_unref (G_OBJECT (witem->widget), do_destroy, witem);
+               gtk_widget_destroy (witem->widget);
+               witem->widget = NULL;
+       }
+
+       GNOME_CANVAS_ITEM_CLASS (gnome_canvas_widget_parent_class)->
+               dispose (object);
+}
+
+static gboolean
+reposition_widget_cb (gpointer user_data)
+{
+       GnomeCanvasWidget *witem = user_data;
+
+       g_return_val_if_fail (GNOME_IS_CANVAS_WIDGET (witem), FALSE);
+
+       if (witem->widget)
+               gtk_widget_queue_resize (witem->widget);
+
+       return FALSE;
+}
+
+static void
+recalc_bounds (GnomeCanvasWidget *witem)
+{
+       GnomeCanvasItem *item;
+       gdouble wx, wy;
+
+       item = GNOME_CANVAS_ITEM (witem);
+
+       /* Get world coordinates */
+
+       wx = witem->x;
+       wy = witem->y;
+       gnome_canvas_item_i2w (item, &wx, &wy);
+
+       /* Get canvas pixel coordinates */
+
+       gnome_canvas_w2c (item->canvas, wx, wy, &witem->cx, &witem->cy);
+
+       /* Bounds */
+
+       item->x1 = witem->cx;
+       item->y1 = witem->cy;
+       item->x2 = witem->cx + witem->cwidth;
+       item->y2 = witem->cy + witem->cheight;
+
+       if (witem->widget) {
+               gint current_x = 0, current_y = 0;
+
+               gtk_container_child_get (GTK_CONTAINER (item->canvas), witem->widget,
+                       "x", &current_x,
+                       "y", &current_y,
+                       NULL);
+
+               if (current_x != ((gint) (witem->cx + item->canvas->zoom_xofs)) ||
+                   current_y != ((gint) (witem->cy + item->canvas->zoom_yofs))) {
+                       gtk_layout_move (
+                               GTK_LAYOUT (item->canvas), witem->widget,
+                               witem->cx + item->canvas->zoom_xofs,
+                               witem->cy + item->canvas->zoom_yofs);
+
+                       /* This is needed, because the gtk_layout_move() calls gtk_widget_queue_resize(),
+                          which can be silently ignored when called inside "size-allocate" handler, causing
+                          misposition of the child widget. */
+                       g_idle_add_full (G_PRIORITY_HIGH_IDLE,
+                               reposition_widget_cb, g_object_ref (witem), g_object_unref);
+               }
+       }
+}
+
+static void
+gnome_canvas_widget_set_property (GObject *object,
+                                  guint param_id,
+                                  const GValue *value,
+                                  GParamSpec *pspec)
+{
+       GnomeCanvasItem *item;
+       GnomeCanvasWidget *witem;
+       GObject *obj;
+       gint update;
+       gint calc_bounds;
+
+       g_return_if_fail (object != NULL);
+       g_return_if_fail (GNOME_IS_CANVAS_WIDGET (object));
+
+       item = GNOME_CANVAS_ITEM (object);
+       witem = GNOME_CANVAS_WIDGET (object);
+
+       update = FALSE;
+       calc_bounds = FALSE;
+
+       switch (param_id) {
+       case PROP_WIDGET:
+               if (witem->widget) {
+                       g_object_weak_unref (G_OBJECT (witem->widget), do_destroy, witem);
+                       gtk_container_remove (GTK_CONTAINER (item->canvas), witem->widget);
+               }
+
+               obj = g_value_get_object (value);
+               if (obj) {
+                       witem->widget = GTK_WIDGET (obj);
+                       g_object_weak_ref (obj, do_destroy, witem);
+                       gtk_layout_put (
+                               GTK_LAYOUT (item->canvas), witem->widget,
+                               witem->cx + item->canvas->zoom_xofs,
+                               witem->cy + item->canvas->zoom_yofs);
+               }
+
+               update = TRUE;
+               break;
+
+       case PROP_X:
+               if (witem->x != g_value_get_double (value))
+               {
+                       witem->x = g_value_get_double (value);
+                       calc_bounds = TRUE;
+               }
+               break;
+
+       case PROP_Y:
+               if (witem->y != g_value_get_double (value))
+               {
+                       witem->y = g_value_get_double (value);
+                       calc_bounds = TRUE;
+               }
+               break;
+
+       case PROP_WIDTH:
+               if (witem->width != fabs (g_value_get_double (value)))
+               {
+                       witem->width = fabs (g_value_get_double (value));
+                       update = TRUE;
+               }
+               break;
+
+       case PROP_HEIGHT:
+               if (witem->height != fabs (g_value_get_double (value)))
+               {
+                       witem->height = fabs (g_value_get_double (value));
+                       update = TRUE;
+               }
+               break;
+
+       case PROP_SIZE_PIXELS:
+               if (witem->size_pixels != g_value_get_boolean (value))
+               {
+                       witem->size_pixels = g_value_get_boolean (value);
+                       update = TRUE;
+               }
+               break;
+
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+               break;
+       }
+
+       if (update)
+               (* GNOME_CANVAS_ITEM_GET_CLASS (item)->update) (item, NULL, 0);
+
+       if (calc_bounds)
+               recalc_bounds (witem);
+}
+
+static void
+gnome_canvas_widget_get_property (GObject *object,
+                                  guint param_id,
+                                  GValue *value,
+                                  GParamSpec *pspec)
+{
+       GnomeCanvasWidget *witem;
+
+       g_return_if_fail (object != NULL);
+       g_return_if_fail (GNOME_IS_CANVAS_WIDGET (object));
+
+       witem = GNOME_CANVAS_WIDGET (object);
+
+       switch (param_id) {
+       case PROP_WIDGET:
+               g_value_set_object (value, (GObject *) witem->widget);
+               break;
+
+       case PROP_X:
+               g_value_set_double (value, witem->x);
+               break;
+
+       case PROP_Y:
+               g_value_set_double (value, witem->y);
+               break;
+
+       case PROP_WIDTH:
+               g_value_set_double (value, witem->width);
+               break;
+
+       case PROP_HEIGHT:
+               g_value_set_double (value, witem->height);
+               break;
+
+       case PROP_SIZE_PIXELS:
+               g_value_set_boolean (value, witem->size_pixels);
+               break;
+
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+               break;
+       }
+}
+
+static void
+gnome_canvas_widget_update (GnomeCanvasItem *item,
+                            const cairo_matrix_t *matrix,
+                            gint flags)
+{
+       GnomeCanvasWidget *witem;
+
+       witem = GNOME_CANVAS_WIDGET (item);
+
+       GNOME_CANVAS_ITEM_CLASS (gnome_canvas_widget_parent_class)->
+               update (item, matrix, flags);
+
+       if (witem->widget) {
+               witem->cwidth = (gint) (witem->width + 0.5);
+               witem->cheight = (gint) (witem->height + 0.5);
+
+               gtk_widget_set_size_request (witem->widget, witem->cwidth, witem->cheight);
+       } else {
+               witem->cwidth = 0.0;
+               witem->cheight = 0.0;
+       }
+
+       recalc_bounds (witem);
+}
+
+static void
+gnome_canvas_widget_draw (GnomeCanvasItem *item,
+                          cairo_t *cr,
+                          gint x,
+                          gint y,
+                          gint width,
+                          gint height)
+{
+#if 0
+       GnomeCanvasWidget *witem;
+
+       witem = GNOME_CANVAS_WIDGET (item);
+
+       if (witem->widget)
+               gtk_widget_queue_draw (witem->widget);
+#endif
+}
+
+static GnomeCanvasItem *
+gnome_canvas_widget_point (GnomeCanvasItem *item,
+                           gdouble x,
+                           gdouble y,
+                           gint cx,
+                           gint cy)
+{
+       GnomeCanvasWidget *witem;
+       gdouble x1, y1, x2, y2;
+
+       witem = GNOME_CANVAS_WIDGET (item);
+
+       gnome_canvas_c2w (item->canvas, witem->cx, witem->cy, &x1, &y1);
+
+       x2 = x1 + (witem->cwidth - 1);
+       y2 = y1 + (witem->cheight - 1);
+
+       /* Is point inside widget bounds? */
+
+       if ((x >= x1) && (y >= y1) && (x <= x2) && (y <= y2))
+               return item;
+
+       /* Point is outside widget bounds */
+       return NULL;
+}
+
+static void
+gnome_canvas_widget_bounds (GnomeCanvasItem *item,
+                            gdouble *x1,
+                            gdouble *y1,
+                            gdouble *x2,
+                            gdouble *y2)
+{
+       GnomeCanvasWidget *witem;
+
+       witem = GNOME_CANVAS_WIDGET (item);
+
+       *x1 = witem->x;
+       *y1 = witem->y;
+
+       *x2 = *x1 + witem->width;
+       *y2 = *y1 + witem->height;
+}
diff --git a/src/libgnomecanvas/gnome-canvas-widget.h b/src/libgnomecanvas/gnome-canvas-widget.h
new file mode 100644
index 00000000..89418360
--- /dev/null
+++ b/src/libgnomecanvas/gnome-canvas-widget.h
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation
+ * All rights reserved.
+ *
+ * This file is part of the Gnome Library.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * published by the Free Software Foundation; either the
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * License along with the Gnome Library; see the file COPYING.LIB.  If not,
+ */
+/*
+  @NOTATION@
+ */
+/* Widget item type for GnomeCanvas widget
+ *
+ * GnomeCanvas is basically a port of the Tk toolkit's most excellent canvas widget.  Tk is
+ * copyrighted by the Regents of the University of California, Sun Microsystems, and other parties.
+ *
+ *
+ * Author: Federico Mena <federico nuclecu unam mx>
+ */
+
+#ifndef GNOME_CANVAS_WIDGET_H
+#define GNOME_CANVAS_WIDGET_H
+
+#include <libgnomecanvas/gnome-canvas.h>
+
+G_BEGIN_DECLS
+
+/* Widget item for canvas.  The widget is positioned with respect to an anchor point.
+ * The following object arguments are available:
+ *
+ * name                        type                    read/write      description
+ * ------------------------------------------------------------------------------------------
+ * widget              GtkWidget*              RW              Pointer to the widget
+ * x                   gdouble                 RW              X coordinate of anchor point
+ * y                   gdouble                 RW              Y coordinate of anchor point
+ * width               gdouble                 RW              Width of widget (see below)
+ * height              gdouble                 RW              Height of widget (see below)
+ * size_pixels         boolean                 RW              Specifies whether the widget size
+ *                                                             is specified in pixels or canvas units.
+ *                                                             If it is in pixels, then the widget will not
+ *                                                             be scaled when the canvas zoom factor changes.
+ *                                                             Otherwise, it will be scaled.
+ */
+
+#define GNOME_TYPE_CANVAS_WIDGET            (gnome_canvas_widget_get_type ())
+#define GNOME_CANVAS_WIDGET(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNOME_TYPE_CANVAS_WIDGET, 
GnomeCanvasWidget))
+#define GNOME_CANVAS_WIDGET_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GNOME_TYPE_CANVAS_WIDGET, 
GnomeCanvasWidgetClass))
+#define GNOME_IS_CANVAS_WIDGET(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNOME_TYPE_CANVAS_WIDGET))
+#define GNOME_IS_CANVAS_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GNOME_TYPE_CANVAS_WIDGET))
+#define GNOME_CANVAS_WIDGET_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GNOME_TYPE_CANVAS_WIDGET, 
GnomeCanvasWidgetClass))
+
+typedef struct _GnomeCanvasWidget GnomeCanvasWidget;
+typedef struct _GnomeCanvasWidgetClass GnomeCanvasWidgetClass;
+
+struct _GnomeCanvasWidget {
+       GnomeCanvasItem item;
+
+       GtkWidget *widget;              /* The child widget */
+
+       gdouble x, y;                   /* Position at anchor */
+       gdouble width, height;          /* Dimensions of widget */
+
+       gint cx, cy;                    /* Top-left canvas coordinates for widget */
+       gint cwidth, cheight;           /* Size of widget in pixels */
+
+       guint size_pixels : 1;          /* Is size specified in (unchanging) pixels or units (get scaled)? */
+       guint in_destroy : 1;           /* Is child widget being destroyed? */
+};
+
+struct _GnomeCanvasWidgetClass {
+       GnomeCanvasItemClass parent_class;
+};
+
+/* Standard Gtk function */
+GType gnome_canvas_widget_get_type (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif
diff --git a/src/libgnomecanvas/gnome-canvas.c b/src/libgnomecanvas/gnome-canvas.c
new file mode 100644
index 00000000..53f2a15d
--- /dev/null
+++ b/src/libgnomecanvas/gnome-canvas.c
@@ -0,0 +1,3501 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: 8; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation
+ * All rights reserved.
+ *
+ * This file is part of the Gnome Library.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * published by the Free Software Foundation; either the
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * License along with the Gnome Library; see the file COPYING.LIB.  If not,
+ */
+/*
+  @NOTATION@
+ */
+/*
+ * GnomeCanvas widget - Tk-like canvas widget for Gnome
+ *
+ * GnomeCanvas is basically a port of the Tk toolkit's most excellent canvas
+ * widget.  Tk is copyrighted by the Regents of the University of California,
+ * Sun Microsystems, and other parties.
+ *
+ *
+ * Authors: Federico Mena <federico nuclecu unam mx>
+ *          Raph Levien <raph gimp org>
+ */
+
+/*
+ * TO-DO list for the canvas:
+ *
+ * - Allow to specify whether GnomeCanvasImage sizes are in units or pixels
+ *   (scale or don't scale).
+ *
+ * - Implement a flag for gnome_canvas_item_reparent() that tells the function
+ *   to keep the item visually in the same place, that is, to keep it in the
+ *   same place with respect to the canvas origin.
+ *
+ * - GC put functions for items.
+ *
+ * - Widget item (finish it).
+ *
+ * - GList *
+ *   gnome_canvas_gimme_all_items_contained_in_this_area (GnomeCanvas *canvas,
+ *                                                        Rectangle area);
+ *
+ * - Retrofit all the primitive items with microtile support.
+ *
+ * - Curve support for line item.
+ *
+ * - Arc item (Havoc has it; to be integrated in GnomeCanvasEllipse).
+ *
+ * - Sane font handling API.
+ *
+ * - Get_arg methods for items:
+ *   - How to fetch the outline width and know whether it is in pixels or units?
+ */
+
+/*
+ * Raph's TODO list for the antialiased canvas integration:
+ *
+ * - ::point() method for text item not accurate when affine transformed.
+ *
+ * - Clip rectangle not implemented in aa renderer for text item.
+ *
+ * - Clip paths only partially implemented.
+ *
+ * - Add more image loading techniques to work around imlib deficiencies.
+ */
+
+#include "evolution-config.h"
+
+#include <math.h>
+#include <string.h>
+#include <stdio.h>
+#include <gdk/gdkprivate.h>
+#include <gtk/gtk.h>
+#include <cairo-gobject.h>
+#include "gailcanvas.h"
+#include "gnome-canvas.h"
+#include "gnome-canvas-i18n.h"
+#include "gnome-canvas-util.h"
+
+/* We must run our idle update handler *before* GDK wants to redraw. */
+#define CANVAS_IDLE_PRIORITY (GDK_PRIORITY_REDRAW - 5)
+
+static void gnome_canvas_request_update (GnomeCanvas      *canvas);
+static void group_add                   (GnomeCanvasGroup *group,
+                                        GnomeCanvasItem  *item);
+static void group_remove                (GnomeCanvasGroup *group,
+                                        GnomeCanvasItem  *item);
+static void add_idle                    (GnomeCanvas      *canvas);
+
+/*** GnomeCanvasItem ***/
+
+/* Some convenience stuff */
+#define GCI_UPDATE_MASK \
+       (GNOME_CANVAS_UPDATE_REQUESTED | \
+        GNOME_CANVAS_UPDATE_AFFINE | \
+        GNOME_CANVAS_UPDATE_CLIP | \
+        GNOME_CANVAS_UPDATE_VISIBILITY)
+#define GCI_EPSILON 1e-18
+#define GCI_PRINT_MATRIX(s,a) \
+       g_print ("%s %g %g %g %g %g %g\n", \
+       s, (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5])
+
+enum {
+       ITEM_PROP_0,
+       ITEM_PROP_PARENT
+};
+
+enum {
+       ITEM_EVENT,
+       ITEM_LAST_SIGNAL
+};
+
+static gint  emit_event                       (GnomeCanvas *canvas, GdkEvent *event);
+
+static guint item_signals[ITEM_LAST_SIGNAL];
+
+G_DEFINE_TYPE (
+       GnomeCanvasItem,
+       gnome_canvas_item,
+       G_TYPE_INITIALLY_UNOWNED)
+
+/* Object initialization function for GnomeCanvasItem */
+static void
+gnome_canvas_item_init (GnomeCanvasItem *item)
+{
+       item->flags |= GNOME_CANVAS_ITEM_VISIBLE;
+
+       cairo_matrix_init_identity (&item->matrix);
+}
+
+/**
+ * gnome_canvas_item_new:
+ * @parent: The parent group for the new item.
+ * @type: The object type of the item.
+ * @first_arg_name: A list of object argument name/value pairs, NULL-terminated,
+ * used to configure the item.  For example, "fill_color", "black",
+ * "width_units", 5.0, NULL.
+ * @Varargs:
+ *
+ * Creates a new canvas item with @parent as its parent group.  The item is
+ * created at the top of its parent's stack, and starts up as visible.  The item
+ * is of the specified @type, for example, it can be
+ * gnome_canvas_rect_get_type().  The list of object arguments/value pairs is
+ * used to configure the item. If you need to pass construct time parameters, you
+ * should use g_object_new() to pass the parameters and
+ * gnome_canvas_item_construct() to set up the canvas item.
+ *
+ * Return value: The newly-created item.
+ **/
+GnomeCanvasItem *
+gnome_canvas_item_new (GnomeCanvasGroup *parent,
+                       GType type,
+                       const gchar *first_arg_name, ...)
+{
+       GnomeCanvasItem *item;
+       va_list args;
+
+       g_return_val_if_fail (GNOME_IS_CANVAS_GROUP (parent), NULL);
+       g_return_val_if_fail (g_type_is_a (type, gnome_canvas_item_get_type ()), NULL);
+
+       item = GNOME_CANVAS_ITEM (g_object_new (type, NULL));
+
+       va_start (args, first_arg_name);
+       gnome_canvas_item_construct (item, parent, first_arg_name, args);
+       va_end (args);
+
+       return item;
+}
+
+/* Performs post-creation operations on a canvas item (adding it to its parent
+ * group, etc.)
+ */
+static void
+item_post_create_setup (GnomeCanvasItem *item)
+{
+       group_add (GNOME_CANVAS_GROUP (item->parent), item);
+
+       gnome_canvas_request_redraw (
+               item->canvas, item->x1, item->y1, item->x2 + 1, item->y2 + 1);
+       item->canvas->need_repick = TRUE;
+}
+
+/* Set_property handler for canvas items */
+static void
+gnome_canvas_item_set_property (GObject *gobject,
+                                guint property_id,
+                                const GValue *value,
+                                GParamSpec *pspec)
+{
+       GnomeCanvasItem *item;
+
+       g_return_if_fail (GNOME_IS_CANVAS_ITEM (gobject));
+
+       item = GNOME_CANVAS_ITEM (gobject);
+
+       switch (property_id) {
+       case ITEM_PROP_PARENT:
+               if (item->parent != NULL) {
+                   g_warning ("Cannot set `parent' argument after item has "
+                              "already been constructed.");
+               } else if (g_value_get_object (value)) {
+                       item->parent = GNOME_CANVAS_ITEM (g_value_get_object (value));
+                       item->canvas = item->parent->canvas;
+                       item_post_create_setup (item);
+               }
+               break;
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, property_id, pspec);
+               break;
+       }
+}
+
+/* Get_property handler for canvas items */
+static void
+gnome_canvas_item_get_property (GObject *gobject,
+                                guint property_id,
+                                GValue *value,
+                                GParamSpec *pspec)
+{
+       GnomeCanvasItem *item;
+
+       g_return_if_fail (GNOME_IS_CANVAS_ITEM (gobject));
+
+       item = GNOME_CANVAS_ITEM (gobject);
+
+       switch (property_id) {
+       case ITEM_PROP_PARENT:
+               g_value_set_object (value, item->parent);
+               break;
+
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, property_id, pspec);
+               break;
+       }
+}
+
+/**
+ * gnome_canvas_item_construct:
+ * @item: An unconstructed canvas item.
+ * @parent: The parent group for the item.
+ * @first_arg_name: The name of the first argument for configuring the item.
+ * @args: The list of arguments used to configure the item.
+ *
+ * Constructs a canvas item; meant for use only by item implementations.
+ **/
+void
+gnome_canvas_item_construct (GnomeCanvasItem *item,
+                             GnomeCanvasGroup *parent,
+                             const gchar *first_arg_name,
+                             va_list args)
+{
+       g_return_if_fail (GNOME_IS_CANVAS_GROUP (parent));
+       g_return_if_fail (GNOME_IS_CANVAS_ITEM (item));
+
+       item->parent = GNOME_CANVAS_ITEM (parent);
+       item->canvas = item->parent->canvas;
+
+       g_object_set_valist (G_OBJECT (item), first_arg_name, args);
+
+       item_post_create_setup (item);
+}
+
+/* If the item is visible, requests a redraw of it. */
+static void
+redraw_if_visible (GnomeCanvasItem *item)
+{
+       if (item->flags & GNOME_CANVAS_ITEM_VISIBLE)
+               gnome_canvas_request_redraw (
+                       item->canvas, item->x1, item->y1,
+                       MIN (item->x2 + 1, G_MAXINT), MIN (item->y2 + 1, G_MAXINT));
+}
+
+/* Standard object dispose function for canvas items */
+static void
+gnome_canvas_item_dispose (GObject *object)
+{
+       GnomeCanvasItemClass *klass;
+       GnomeCanvasItem *item;
+
+       g_return_if_fail (GNOME_IS_CANVAS_ITEM (object));
+
+       item = GNOME_CANVAS_ITEM (object);
+       klass = GNOME_CANVAS_ITEM_GET_CLASS (item);
+
+       if (item->canvas)
+               redraw_if_visible (item);
+
+       /* Make the canvas forget about us */
+
+       if (item->canvas && item == item->canvas->current_item) {
+               item->canvas->current_item = NULL;
+               item->canvas->need_repick = TRUE;
+       }
+
+       if (item->canvas && item == item->canvas->new_current_item) {
+               item->canvas->new_current_item = NULL;
+               item->canvas->need_repick = TRUE;
+       }
+
+       if (item->canvas && item == item->canvas->grabbed_item) {
+               item->canvas->grabbed_item = NULL;
+
+               gdk_device_ungrab (
+                       item->canvas->grabbed_device, GDK_CURRENT_TIME);
+               g_object_unref (item->canvas->grabbed_device);
+               item->canvas->grabbed_device = NULL;
+       }
+
+       if (item->canvas && item == item->canvas->focused_item)
+               item->canvas->focused_item = NULL;
+
+       /* Normal dispose stuff */
+
+       if (item->flags & GNOME_CANVAS_ITEM_MAPPED) {
+               if (klass)
+                       klass->unmap (item);
+       }
+
+       if (item->flags & GNOME_CANVAS_ITEM_REALIZED) {
+               if (klass)
+                       klass->unrealize (item);
+       }
+
+       if (item->parent)
+               group_remove (GNOME_CANVAS_GROUP (item->parent), item);
+
+       if (klass && klass->dispose)
+               klass->dispose (item);
+
+       G_OBJECT_CLASS (gnome_canvas_item_parent_class)->dispose (object);
+       /* items should remove any reference to item->canvas after the
+        * first ::dispose */
+       item->canvas = NULL;
+}
+
+/* Update handler for canvas items */
+static void
+gnome_canvas_item_update (GnomeCanvasItem *item,
+                          const cairo_matrix_t *matrix,
+                          gint flags)
+{
+       item->flags &= ~GNOME_CANVAS_ITEM_NEED_UPDATE;
+       item->flags &= ~GNOME_CANVAS_ITEM_NEED_AFFINE;
+       item->flags &= ~GNOME_CANVAS_ITEM_NEED_CLIP;
+       item->flags &= ~GNOME_CANVAS_ITEM_NEED_VIS;
+}
+
+/* Realize handler for canvas items */
+static void
+gnome_canvas_item_realize (GnomeCanvasItem *item)
+{
+       item->flags |= GNOME_CANVAS_ITEM_REALIZED;
+
+       gnome_canvas_item_request_update (item);
+}
+
+/* Unrealize handler for canvas items */
+static void
+gnome_canvas_item_unrealize (GnomeCanvasItem *item)
+{
+       item->flags &= ~GNOME_CANVAS_ITEM_REALIZED;
+}
+
+/* Map handler for canvas items */
+static void
+gnome_canvas_item_map (GnomeCanvasItem *item)
+{
+       item->flags |= GNOME_CANVAS_ITEM_MAPPED;
+}
+
+/* Unmap handler for canvas items */
+static void
+gnome_canvas_item_unmap (GnomeCanvasItem *item)
+{
+       item->flags &= ~GNOME_CANVAS_ITEM_MAPPED;
+}
+
+/* Dispose handler for canvas items */
+static void
+gnome_canvas_item_dispose_item (GnomeCanvasItem *item)
+{
+       /* Placeholder so subclasses can safely chain up. */
+}
+
+static void
+gnome_canvas_item_draw (GnomeCanvasItem *item,
+                        cairo_t *cr,
+                        gint x,
+                        gint y,
+                        gint width,
+                        gint height)
+{
+       /* Placeholder so subclasses can safely chain up. */
+}
+
+static GnomeCanvasItem *
+gnome_canvas_item_point (GnomeCanvasItem *item,
+                         gdouble x,
+                         gdouble y,
+                         gint cx,
+                         gint cy)
+{
+       /* Placeholder so subclasses can safely chain up. */
+
+       return NULL;
+}
+
+static void
+gnome_canvas_item_bounds (GnomeCanvasItem *item,
+                          gdouble *x1,
+                          gdouble *y1,
+                          gdouble *x2,
+                          gdouble *y2)
+{
+       /* Placeholder so subclasses can safely chain up. */
+}
+
+static gboolean
+gnome_canvas_item_event (GnomeCanvasItem *item,
+                         GdkEvent *event)
+{
+       /* Placeholder so subclasses can safely chain up. */
+
+       return FALSE;  /* event was not handled */
+}
+
+/*
+ * This routine invokes the update method of the item
+ * Please notice, that we take parent to canvas pixel matrix as argument
+ * unlike virtual method ::update, whose argument is item 2 canvas pixel
+ * matrix
+ *
+ * I will try to force somewhat meaningful naming for affines (Lauris)
+ * General naming rule is FROM2TO, where FROM and TO are abbreviations
+ * So p2cpx is Parent2CanvasPixel and i2cpx is Item2CanvasPixel
+ * I hope that this helps to keep track of what really happens
+ *
+ */
+
+static void
+gnome_canvas_item_invoke_update (GnomeCanvasItem *item,
+                                 const cairo_matrix_t *p2c,
+                                 gint flags)
+{
+       gint child_flags;
+       cairo_matrix_t i2c;
+
+       child_flags = flags;
+       if (!(item->flags & GNOME_CANVAS_ITEM_VISIBLE))
+               child_flags &= ~GNOME_CANVAS_UPDATE_IS_VISIBLE;
+
+       /* Calculate actual item transformation matrix */
+
+       cairo_matrix_multiply (&i2c, &item->matrix, p2c);
+
+       /* apply object flags to child flags */
+
+       child_flags &= ~GNOME_CANVAS_UPDATE_REQUESTED;
+
+       if (item->flags & GNOME_CANVAS_ITEM_NEED_UPDATE)
+               child_flags |= GNOME_CANVAS_UPDATE_REQUESTED;
+
+       if (item->flags & GNOME_CANVAS_ITEM_NEED_AFFINE)
+               child_flags |= GNOME_CANVAS_UPDATE_AFFINE;
+
+       if (item->flags & GNOME_CANVAS_ITEM_NEED_CLIP)
+               child_flags |= GNOME_CANVAS_UPDATE_CLIP;
+
+       if (item->flags & GNOME_CANVAS_ITEM_NEED_VIS)
+               child_flags |= GNOME_CANVAS_UPDATE_VISIBILITY;
+
+       if (child_flags & GCI_UPDATE_MASK) {
+               GnomeCanvasItemClass *klass = GNOME_CANVAS_ITEM_GET_CLASS (item);
+
+               if (klass && klass->update)
+                       klass->update (item, &i2c, child_flags);
+       }
+}
+
+/*
+ * This routine invokes the point method of the item.
+ * The arguments x, y should be in the parent item local coordinates.
+ *
+ * This is potentially evil, as we are relying on matrix inversion (Lauris)
+ */
+
+static GnomeCanvasItem *
+gnome_canvas_item_invoke_point (GnomeCanvasItem *item,
+                                gdouble x,
+                                gdouble y,
+                                gint cx,
+                                gint cy)
+{
+       GnomeCanvasItemClass *klass = GNOME_CANVAS_ITEM_GET_CLASS (item);
+       cairo_matrix_t inverse;
+
+       /* Calculate x & y in item local coordinates */
+       inverse = item->matrix;
+       if (cairo_matrix_invert (&inverse) != CAIRO_STATUS_SUCCESS)
+               return NULL;
+
+       cairo_matrix_transform_point (&inverse, &x, &y);
+
+       if (klass && klass->point)
+               return klass->point (item, x, y, cx, cy);
+
+       return NULL;
+}
+
+/**
+ * gnome_canvas_item_set:
+ * @item: A canvas item.
+ * @first_arg_name: The list of object argument name/value pairs used to
+ *                  configure the item.
+ * @Varargs:
+ *
+ * Configures a canvas item.  The arguments in the item are set to the
+ * specified values, and the item is repainted as appropriate.
+ **/
+void
+gnome_canvas_item_set (GnomeCanvasItem *item,
+                       const gchar *first_arg_name,
+                       ...)
+{
+       va_list args;
+
+       va_start (args, first_arg_name);
+       gnome_canvas_item_set_valist (item, first_arg_name, args);
+       va_end (args);
+}
+
+/**
+ * gnome_canvas_item_set_valist:
+ * @item: A canvas item.
+ * @first_arg_name: The name of the first argument used to configure the item.
+ * @args: The list of object argument name/value pairs used to configure the item.
+ *
+ * Configures a canvas item.  The arguments in the item are set to the specified
+ * values, and the item is repainted as appropriate.
+ **/
+void
+gnome_canvas_item_set_valist (GnomeCanvasItem *item,
+                              const gchar *first_arg_name,
+                              va_list args)
+{
+       g_return_if_fail (GNOME_IS_CANVAS_ITEM (item));
+
+       g_object_set_valist (G_OBJECT (item), first_arg_name, args);
+
+       item->canvas->need_repick = TRUE;
+}
+
+/**
+ * gnome_canvas_item_transform:
+ * @item: A canvas item.
+ * @matrix: An affine transformation matrix.
+ *
+ * Combines the specified affine transformation matrix with the item's current
+ * transformation.
+ **/
+void
+gnome_canvas_item_transform (GnomeCanvasItem *item,
+                             const cairo_matrix_t *matrix)
+{
+       cairo_matrix_t i2p;
+
+       g_return_if_fail (GNOME_IS_CANVAS_ITEM (item));
+       g_return_if_fail (matrix != NULL);
+
+       /* Calculate actual item transformation matrix */
+       cairo_matrix_multiply (&i2p, matrix, &item->matrix);
+
+       gnome_canvas_item_set_matrix (item, &i2p);
+}
+
+/**
+ * gnome_canvas_item_set_matrix:
+ * @item: A canvas item.
+ * @matrix: An affine transformation matrix or %NULL for the identity matrix.
+ *
+ * Makes the item's affine transformation matrix be equal to the specified
+ * matrix. NULL is treated as identity.
+ **/
+void
+gnome_canvas_item_set_matrix (GnomeCanvasItem *item,
+                              const cairo_matrix_t *matrix)
+{
+       g_return_if_fail (GNOME_IS_CANVAS_ITEM (item));
+
+       if (matrix) {
+               item->matrix = *matrix;
+       } else {
+               cairo_matrix_init_identity (&item->matrix);
+       }
+
+       if (!(item->flags & GNOME_CANVAS_ITEM_NEED_AFFINE)) {
+               /* Request update */
+               item->flags |= GNOME_CANVAS_ITEM_NEED_AFFINE;
+               gnome_canvas_item_request_update (item);
+       }
+
+       item->canvas->need_repick = TRUE;
+}
+
+/**
+ * gnome_canvas_item_move:
+ * @item: A canvas item.
+ * @dx: Horizontal offset.
+ * @dy: Vertical offset.
+ *
+ * Moves a canvas item by creating an affine transformation matrix for
+ * translation by using the specified values. This happens in item
+ * local coordinate system, so if you have nontrivial transform, it
+ * most probably does not do, what you want.
+ **/
+void
+gnome_canvas_item_move (GnomeCanvasItem *item,
+                        gdouble dx,
+                        gdouble dy)
+{
+       cairo_matrix_t translate;
+
+       g_return_if_fail (GNOME_IS_CANVAS_ITEM (item));
+
+       cairo_matrix_init_translate (&translate, dx, dy);
+
+       gnome_canvas_item_transform (item, &translate);
+}
+
+/* Convenience function to reorder items in a group's child list.  This puts the
+ * specified link after the "before" link. Returns TRUE if the list was changed.
+ */
+static gboolean
+put_item_after (GList *link,
+                GList *before)
+{
+       GnomeCanvasGroup *parent;
+       GList *old_before, *old_after;
+       GList *after;
+
+       parent = GNOME_CANVAS_GROUP (GNOME_CANVAS_ITEM (link->data)->parent);
+
+       if (before)
+               after = before->next;
+       else
+               after = parent->item_list;
+
+       if (before == link || after == link)
+               return FALSE;
+
+       /* Unlink */
+
+       old_before = link->prev;
+       old_after = link->next;
+
+       if (old_before)
+               old_before->next = old_after;
+       else
+               parent->item_list = old_after;
+
+       if (old_after)
+               old_after->prev = old_before;
+       else
+               parent->item_list_end = old_before;
+
+       /* Relink */
+
+       link->prev = before;
+       if (before)
+               before->next = link;
+       else
+               parent->item_list = link;
+
+       link->next = after;
+       if (after)
+               after->prev = link;
+       else
+               parent->item_list_end = link;
+
+       return TRUE;
+}
+
+/**
+ * gnome_canvas_item_raise:
+ * @item: A canvas item.
+ * @positions: Number of steps to raise the item.
+ *
+ * Raises the item in its parent's stack by the specified number of positions.
+ * If the number of positions is greater than the distance to the top of the
+ * stack, then the item is put at the top.
+ **/
+void
+gnome_canvas_item_raise (GnomeCanvasItem *item,
+                         gint positions)
+{
+       GList *link, *before;
+       GnomeCanvasGroup *parent;
+
+       g_return_if_fail (GNOME_IS_CANVAS_ITEM (item));
+       g_return_if_fail (positions >= 0);
+
+       if (!item->parent || positions == 0)
+               return;
+
+       parent = GNOME_CANVAS_GROUP (item->parent);
+       link = g_list_find (parent->item_list, item);
+       g_return_if_fail (link != NULL);
+
+       for (before = link; positions && before; positions--)
+               before = before->next;
+
+       if (!before)
+               before = parent->item_list_end;
+
+       if (put_item_after (link, before)) {
+               redraw_if_visible (item);
+               item->canvas->need_repick = TRUE;
+       }
+}
+
+/**
+ * gnome_canvas_item_lower:
+ * @item: A canvas item.
+ * @positions: Number of steps to lower the item.
+ *
+ * Lowers the item in its parent's stack by the specified number of positions.
+ * If the number of positions is greater than the distance to the bottom of the
+ * stack, then the item is put at the bottom.
+ **/
+void
+gnome_canvas_item_lower (GnomeCanvasItem *item,
+                         gint positions)
+{
+       GList *link, *before;
+       GnomeCanvasGroup *parent;
+
+       g_return_if_fail (GNOME_IS_CANVAS_ITEM (item));
+       g_return_if_fail (positions >= 1);
+
+       if (!item->parent || positions == 0)
+               return;
+
+       parent = GNOME_CANVAS_GROUP (item->parent);
+       link = g_list_find (parent->item_list, item);
+       g_return_if_fail (link != NULL);
+
+       if (link->prev)
+               for (before = link->prev; positions && before; positions--)
+                       before = before->prev;
+       else
+               before = NULL;
+
+       if (put_item_after (link, before)) {
+               redraw_if_visible (item);
+               item->canvas->need_repick = TRUE;
+       }
+}
+
+/**
+ * gnome_canvas_item_raise_to_top:
+ * @item: A canvas item.
+ *
+ * Raises an item to the top of its parent's stack.
+ **/
+void
+gnome_canvas_item_raise_to_top (GnomeCanvasItem *item)
+{
+       GList *link;
+       GnomeCanvasGroup *parent;
+
+       g_return_if_fail (GNOME_IS_CANVAS_ITEM (item));
+
+       if (!item->parent)
+               return;
+
+       parent = GNOME_CANVAS_GROUP (item->parent);
+       link = g_list_find (parent->item_list, item);
+       g_return_if_fail (link != NULL);
+
+       if (put_item_after (link, parent->item_list_end)) {
+               redraw_if_visible (item);
+               item->canvas->need_repick = TRUE;
+       }
+}
+
+/**
+ * gnome_canvas_item_lower_to_bottom:
+ * @item: A canvas item.
+ *
+ * Lowers an item to the bottom of its parent's stack.
+ **/
+void
+gnome_canvas_item_lower_to_bottom (GnomeCanvasItem *item)
+{
+       GList *link;
+       GnomeCanvasGroup *parent;
+
+       g_return_if_fail (GNOME_IS_CANVAS_ITEM (item));
+
+       if (!item->parent)
+               return;
+
+       parent = GNOME_CANVAS_GROUP (item->parent);
+       link = g_list_find (parent->item_list, item);
+       g_return_if_fail (link != NULL);
+
+       if (put_item_after (link, NULL)) {
+               redraw_if_visible (item);
+               item->canvas->need_repick = TRUE;
+       }
+}
+
+/**
+ * gnome_canvas_item_show:
+ * @item: A canvas item.
+ *
+ * Shows a canvas item.  If the item was already shown, then no action is taken.
+ **/
+void
+gnome_canvas_item_show (GnomeCanvasItem *item)
+{
+       g_return_if_fail (GNOME_IS_CANVAS_ITEM (item));
+
+       if (!(item->flags & GNOME_CANVAS_ITEM_VISIBLE)) {
+               item->flags |= GNOME_CANVAS_ITEM_VISIBLE;
+               gnome_canvas_request_redraw (
+                       item->canvas, item->x1, item->y1,
+                       item->x2 + 1, item->y2 + 1);
+               item->canvas->need_repick = TRUE;
+       }
+}
+
+/**
+ * gnome_canvas_item_hide:
+ * @item: A canvas item.
+ *
+ * Hides a canvas item.  If the item was already hidden, then no action is
+ * taken.
+ **/
+void
+gnome_canvas_item_hide (GnomeCanvasItem *item)
+{
+       g_return_if_fail (GNOME_IS_CANVAS_ITEM (item));
+
+       if (item->flags & GNOME_CANVAS_ITEM_VISIBLE) {
+               item->flags &= ~GNOME_CANVAS_ITEM_VISIBLE;
+               gnome_canvas_request_redraw (
+                       item->canvas, item->x1, item->y1,
+                       item->x2 + 1, item->y2 + 1);
+               item->canvas->need_repick = TRUE;
+       }
+}
+
+/**
+ * gnome_canvas_item_grab:
+ * @item: A canvas item.
+ * @event_mask: Mask of events that will be sent to this item.
+ * @cursor: If non-NULL, the cursor that will be used while the grab is active.
+ * @device: The pointer device to grab.
+ * @etime: The timestamp required for grabbing @device, or GDK_CURRENT_TIME.
+ *
+ * Specifies that all events that match the specified event mask should be sent
+ * to the specified item, and also grabs @device by calling gdk_device_grab().
+ * The event mask is also used when grabbing the @device.  If @cursor is not
+ * NULL, then that cursor is used while the grab is active.  The @etime
+ * parameter is the timestamp required for grabbing the @device.
+ *
+ * Return value: If an item was already grabbed, it returns
+ * %GDK_GRAB_ALREADY_GRABBED.  If the specified item was hidden by calling
+ * gnome_canvas_item_hide(), then it returns %GDK_GRAB_NOT_VIEWABLE.  Else,
+ * it returns the result of calling gdk_device_grab().
+ **/
+gint
+gnome_canvas_item_grab (GnomeCanvasItem *item,
+                        guint event_mask,
+                        GdkCursor *cursor,
+                        GdkDevice *device,
+                        guint32 etime)
+{
+       GtkLayout *layout;
+       GdkWindow *bin_window;
+       gint retval;
+
+       g_return_val_if_fail (
+               GNOME_IS_CANVAS_ITEM (item), GDK_GRAB_NOT_VIEWABLE);
+       g_return_val_if_fail (
+               gtk_widget_get_mapped (GTK_WIDGET (item->canvas)),
+               GDK_GRAB_NOT_VIEWABLE);
+       g_return_val_if_fail (
+               GDK_IS_DEVICE (device), GDK_GRAB_NOT_VIEWABLE);
+
+       if (item->canvas->grabbed_item)
+               return GDK_GRAB_ALREADY_GRABBED;
+
+       if (!(item->flags & GNOME_CANVAS_ITEM_VISIBLE))
+               return GDK_GRAB_NOT_VIEWABLE;
+
+       layout = GTK_LAYOUT (item->canvas);
+       bin_window = gtk_layout_get_bin_window (layout);
+
+       retval = gdk_device_grab (
+               device, bin_window, GDK_OWNERSHIP_NONE,
+               FALSE, event_mask, cursor, etime);
+
+       if (retval != GDK_GRAB_SUCCESS)
+               return retval;
+
+       item->canvas->grabbed_item = item;
+       item->canvas->grabbed_device = g_object_ref (device);
+       item->canvas->grabbed_event_mask = event_mask;
+       item->canvas->current_item = item; /* So that events go to the grabbed item */
+
+       return retval;
+}
+
+/**
+ * gnome_canvas_item_ungrab:
+ * @item: A canvas item that holds a grab.
+ * @etime: The timestamp for ungrabbing the mouse.
+ *
+ * Ungrabs the item, which must have been grabbed in the canvas, and ungrabs the
+ * mouse.
+ **/
+void
+gnome_canvas_item_ungrab (GnomeCanvasItem *item,
+                          guint32 etime)
+{
+       g_return_if_fail (GNOME_IS_CANVAS_ITEM (item));
+
+       if (item->canvas->grabbed_item != item)
+               return;
+
+       item->canvas->grabbed_item = NULL;
+
+       g_return_if_fail (item->canvas->grabbed_device != NULL);
+       gdk_device_ungrab (item->canvas->grabbed_device, etime);
+
+       g_object_unref (item->canvas->grabbed_device);
+       item->canvas->grabbed_device = NULL;
+}
+
+void
+gnome_canvas_item_i2w_matrix (GnomeCanvasItem *item,
+                              cairo_matrix_t *matrix)
+{
+       g_return_if_fail (GNOME_IS_CANVAS_ITEM (item));
+       g_return_if_fail (matrix != NULL);
+
+       cairo_matrix_init_identity (matrix);
+
+       while (item) {
+               cairo_matrix_multiply (matrix, matrix, &item->matrix);
+
+               item = item->parent;
+       }
+}
+
+void
+gnome_canvas_item_w2i_matrix (GnomeCanvasItem *item,
+                              cairo_matrix_t *matrix)
+{
+       cairo_status_t status;
+
+       g_return_if_fail (GNOME_IS_CANVAS_ITEM (item));
+       g_return_if_fail (matrix != NULL);
+
+       gnome_canvas_item_i2w_matrix (item, matrix);
+       status = cairo_matrix_invert (matrix);
+       g_return_if_fail (status == CAIRO_STATUS_SUCCESS);
+}
+
+/**
+ * gnome_canvas_item_w2i:
+ * @item: A canvas item.
+ * @x: X coordinate to convert (input/output value).
+ * @y: Y coordinate to convert (input/output value).
+ *
+ * Converts a coordinate pair from world coordinates to item-relative
+ * coordinates.
+ **/
+void
+gnome_canvas_item_w2i (GnomeCanvasItem *item,
+                       gdouble *x,
+                       gdouble *y)
+{
+       cairo_matrix_t matrix;
+
+       g_return_if_fail (GNOME_IS_CANVAS_ITEM (item));
+       g_return_if_fail (x != NULL);
+       g_return_if_fail (y != NULL);
+
+       gnome_canvas_item_w2i_matrix (item, &matrix);
+       cairo_matrix_transform_point (&matrix, x, y);
+}
+
+/**
+ * gnome_canvas_item_i2w:
+ * @item: A canvas item.
+ * @x: X coordinate to convert (input/output value).
+ * @y: Y coordinate to convert (input/output value).
+ *
+ * Converts a coordinate pair from item-relative coordinates to world
+ * coordinates.
+ **/
+void
+gnome_canvas_item_i2w (GnomeCanvasItem *item,
+                       gdouble *x,
+                       gdouble *y)
+{
+       cairo_matrix_t matrix;
+
+       g_return_if_fail (GNOME_IS_CANVAS_ITEM (item));
+       g_return_if_fail (x != NULL);
+       g_return_if_fail (y != NULL);
+
+       gnome_canvas_item_i2w_matrix (item, &matrix);
+       cairo_matrix_transform_point (&matrix, x, y);
+}
+
+/**
+ * gnome_canvas_item_i2c_matrix:
+ * @item: A canvas item.
+ * @matrix: Matrix to take the resulting transformation matrix (return value).
+ *
+ * Gets the affine transform that converts from item-relative coordinates to
+ * canvas pixel coordinates.
+ **/
+void
+gnome_canvas_item_i2c_matrix (GnomeCanvasItem *item,
+                              cairo_matrix_t *matrix)
+{
+       cairo_matrix_t i2w, w2c;
+
+       gnome_canvas_item_i2w_matrix (item, &i2w);
+       gnome_canvas_w2c_matrix (item->canvas, &w2c);
+       cairo_matrix_multiply (matrix, &i2w, &w2c);
+}
+
+/* Returns whether the item is an inferior of or is equal to the parent. */
+static gint
+is_descendant (GnomeCanvasItem *item,
+               GnomeCanvasItem *parent)
+{
+       for (; item; item = item->parent)
+               if (item == parent)
+                       return TRUE;
+
+       return FALSE;
+}
+
+/**
+ * gnome_canvas_item_reparent:
+ * @item: A canvas item.
+ * @new_group: A canvas group.
+ *
+ * Changes the parent of the specified item to be the new group.  The item keeps
+ * its group-relative coordinates as for its old parent, so the item may change
+ * its absolute position within the canvas.
+ **/
+void
+gnome_canvas_item_reparent (GnomeCanvasItem *item,
+                            GnomeCanvasGroup *new_group)
+{
+       g_return_if_fail (GNOME_IS_CANVAS_ITEM (item));
+       g_return_if_fail (GNOME_IS_CANVAS_GROUP (new_group));
+
+       /* Both items need to be in the same canvas */
+       g_return_if_fail (item->canvas == GNOME_CANVAS_ITEM (new_group)->canvas);
+
+       /* The group cannot be an inferior of the item or be the item itself --
+        * this also takes care of the case where the item is the root item of
+        * the canvas.  */
+       g_return_if_fail (!is_descendant (GNOME_CANVAS_ITEM (new_group), item));
+
+       /* Everything is ok, now actually reparent the item */
+
+       g_object_ref (item); /* protect it from the unref in group_remove */
+
+       redraw_if_visible (item);
+
+       group_remove (GNOME_CANVAS_GROUP (item->parent), item);
+       item->parent = GNOME_CANVAS_ITEM (new_group);
+       group_add (new_group, item);
+
+       /* Redraw and repick */
+
+       redraw_if_visible (item);
+       item->canvas->need_repick = TRUE;
+
+       g_object_unref (item);
+}
+
+/**
+ * gnome_canvas_item_grab_focus:
+ * @item: A canvas item.
+ *
+ * Makes the specified item take the keyboard focus, so all keyboard events will
+ * be sent to it.  If the canvas widget itself did not have the focus, it grabs
+ * it as well.
+ **/
+void
+gnome_canvas_item_grab_focus (GnomeCanvasItem *item)
+{
+       GnomeCanvasItem *focused_item;
+       GdkEvent ev;
+
+       g_return_if_fail (GNOME_IS_CANVAS_ITEM (item));
+       g_return_if_fail (gtk_widget_get_can_focus (GTK_WIDGET (item->canvas)));
+
+       focused_item = item->canvas->focused_item;
+
+       if (focused_item) {
+               GtkLayout *layout;
+               GdkWindow *bin_window;
+
+               layout = GTK_LAYOUT (item->canvas);
+               bin_window = gtk_layout_get_bin_window (layout);
+
+               ev.focus_change.type = GDK_FOCUS_CHANGE;
+               ev.focus_change.window = bin_window;
+               ev.focus_change.send_event = FALSE;
+               ev.focus_change.in = FALSE;
+
+               emit_event (item->canvas, &ev);
+       }
+
+       item->canvas->focused_item = item;
+       gtk_widget_grab_focus (GTK_WIDGET (item->canvas));
+
+       if (focused_item) {
+               GtkLayout *layout;
+               GdkWindow *bin_window;
+
+               layout = GTK_LAYOUT (item->canvas);
+               bin_window = gtk_layout_get_bin_window (layout);
+
+               ev.focus_change.type = GDK_FOCUS_CHANGE;
+               ev.focus_change.window = bin_window;
+               ev.focus_change.send_event = FALSE;
+               ev.focus_change.in = TRUE;
+
+               emit_event (item->canvas, &ev);
+       }
+}
+
+/**
+ * gnome_canvas_item_get_bounds:
+ * @item: A canvas item.
+ * @x1: Leftmost edge of the bounding box (return value).
+ * @y1: Upper edge of the bounding box (return value).
+ * @x2: Rightmost edge of the bounding box (return value).
+ * @y2: Lower edge of the bounding box (return value).
+ *
+ * Queries the bounding box of a canvas item.  The bounds are returned in the
+ * coordinate system of the item's parent.
+ **/
+void
+gnome_canvas_item_get_bounds (GnomeCanvasItem *item,
+                              gdouble *x1,
+                              gdouble *y1,
+                              gdouble *x2,
+                              gdouble *y2)
+{
+       GnomeCanvasItemClass *klass;
+       gdouble tx1, ty1, tx2, ty2;
+
+       g_return_if_fail (GNOME_IS_CANVAS_ITEM (item));
+
+       klass = GNOME_CANVAS_ITEM_GET_CLASS (item);
+       g_return_if_fail (klass != NULL);
+
+       tx1 = ty1 = tx2 = ty2 = 0.0;
+
+       /* Get the item's bounds in its coordinate system */
+
+       if (klass->bounds)
+               klass->bounds (item, &tx1, &ty1, &tx2, &ty2);
+
+       /* Make the bounds relative to the item's parent coordinate system */
+       gnome_canvas_matrix_transform_rect (&item->matrix, &tx1, &ty1, &tx2, &ty2);
+
+       /* Return the values */
+
+       if (x1)
+               *x1 = tx1;
+
+       if (y1)
+               *y1 = ty1;
+
+       if (x2)
+               *x2 = tx2;
+
+       if (y2)
+               *y2 = ty2;
+}
+
+/**
+ * gnome_canvas_item_request_update
+ * @item: A canvas item.
+ *
+ * To be used only by item implementations.  Requests that the canvas queue an
+ * update for the specified item.
+ **/
+void
+gnome_canvas_item_request_update (GnomeCanvasItem *item)
+{
+       if (item->flags & GNOME_CANVAS_ITEM_NEED_UPDATE)
+               return;
+
+       item->flags |= GNOME_CANVAS_ITEM_NEED_UPDATE;
+
+       if (item->parent != NULL) {
+               /* Recurse up the tree */
+               gnome_canvas_item_request_update (item->parent);
+       } else {
+               /* Have reached the top of the tree, make
+                * sure the update call gets scheduled. */
+               gnome_canvas_request_update (item->canvas);
+       }
+}
+
+/*** GnomeCanvasGroup ***/
+
+enum {
+       GROUP_PROP_0,
+       GROUP_PROP_X,
+       GROUP_PROP_Y
+};
+
+static void gnome_canvas_group_set_property (GObject               *object,
+                                           guint                  property_id,
+                                           const GValue          *value,
+                                           GParamSpec            *pspec);
+static void gnome_canvas_group_get_property (GObject               *object,
+                                           guint                  property_id,
+                                           GValue                *value,
+                                           GParamSpec            *pspec);
+
+static void gnome_canvas_group_dispose     (GnomeCanvasItem *object);
+
+static void   gnome_canvas_group_update      (GnomeCanvasItem *item,
+                                              const cairo_matrix_t *matrix,
+                                             gint flags);
+static void   gnome_canvas_group_realize     (GnomeCanvasItem *item);
+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,
+                                             cairo_t *cr,
+                                             gint x, gint y,
+                                             gint width, gint height);
+static GnomeCanvasItem *gnome_canvas_group_point (GnomeCanvasItem *item,
+                                             gdouble x, gdouble y,
+                                             gint cx, gint cy);
+static void   gnome_canvas_group_bounds      (GnomeCanvasItem *item,
+                                             gdouble *x1, gdouble *y1,
+                                             gdouble *x2, gdouble *y2);
+
+G_DEFINE_TYPE (
+       GnomeCanvasGroup,
+       gnome_canvas_group,
+       GNOME_TYPE_CANVAS_ITEM)
+
+/* Class initialization function for GnomeCanvasGroupClass */
+static void
+gnome_canvas_group_class_init (GnomeCanvasGroupClass *class)
+{
+       GObjectClass *object_class;
+       GnomeCanvasItemClass *item_class;
+
+       object_class = (GObjectClass *) class;
+       item_class = (GnomeCanvasItemClass *) class;
+
+       object_class->set_property = gnome_canvas_group_set_property;
+       object_class->get_property = gnome_canvas_group_get_property;
+
+       g_object_class_install_property (
+               object_class,
+               GROUP_PROP_X,
+               g_param_spec_double (
+                       "x",
+                       "X",
+                       "X",
+                       -G_MAXDOUBLE,
+                       G_MAXDOUBLE,
+                       0.0,
+                       G_PARAM_READABLE |
+                       G_PARAM_WRITABLE));
+
+       g_object_class_install_property (
+               object_class,
+               GROUP_PROP_Y,
+               g_param_spec_double (
+                       "y",
+                       "Y",
+                       "Y",
+                       -G_MAXDOUBLE,
+                       G_MAXDOUBLE,
+                       0.0,
+                       G_PARAM_READABLE |
+                       G_PARAM_WRITABLE));
+
+       item_class->dispose = gnome_canvas_group_dispose;
+       item_class->update = gnome_canvas_group_update;
+       item_class->realize = gnome_canvas_group_realize;
+       item_class->unrealize = gnome_canvas_group_unrealize;
+       item_class->map = gnome_canvas_group_map;
+       item_class->unmap = gnome_canvas_group_unmap;
+       item_class->draw = gnome_canvas_group_draw;
+       item_class->point = gnome_canvas_group_point;
+       item_class->bounds = gnome_canvas_group_bounds;
+}
+
+/* Object initialization function for GnomeCanvasGroup */
+static void
+gnome_canvas_group_init (GnomeCanvasGroup *group)
+{
+}
+
+/* Set_property handler for canvas groups */
+static void
+gnome_canvas_group_set_property (GObject *gobject,
+                                 guint property_id,
+                                 const GValue *value,
+                                 GParamSpec *pspec)
+{
+       GnomeCanvasItem *item;
+
+       g_return_if_fail (GNOME_IS_CANVAS_GROUP (gobject));
+
+       item = GNOME_CANVAS_ITEM (gobject);
+
+       switch (property_id) {
+       case GROUP_PROP_X:
+               item->matrix.x0 = g_value_get_double (value);
+               break;
+
+       case GROUP_PROP_Y:
+               item->matrix.y0 = g_value_get_double (value);
+               break;
+
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, property_id, pspec);
+               break;
+       }
+}
+
+/* Get_property handler for canvas groups */
+static void
+gnome_canvas_group_get_property (GObject *gobject,
+                                 guint property_id,
+                                 GValue *value,
+                                 GParamSpec *pspec)
+{
+       GnomeCanvasItem *item;
+
+       g_return_if_fail (GNOME_IS_CANVAS_GROUP (gobject));
+
+       item = GNOME_CANVAS_ITEM (gobject);
+
+       switch (property_id) {
+       case GROUP_PROP_X:
+               g_value_set_double (value, item->matrix.x0);
+               break;
+
+       case GROUP_PROP_Y:
+               g_value_set_double (value, item->matrix.y0);
+               break;
+
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, property_id, pspec);
+               break;
+       }
+}
+
+/* Dispose handler for canvas groups */
+static void
+gnome_canvas_group_dispose (GnomeCanvasItem *object)
+{
+       GnomeCanvasGroup *group;
+
+       g_return_if_fail (GNOME_IS_CANVAS_GROUP (object));
+
+       group = GNOME_CANVAS_GROUP (object);
+
+       while (group->item_list) {
+               /* child is unref'ed by the child's group_remove (). */
+               g_object_run_dispose (G_OBJECT (group->item_list->data));
+       }
+
+       GNOME_CANVAS_ITEM_CLASS (gnome_canvas_group_parent_class)->
+               dispose (object);
+}
+
+/* Update handler for canvas groups */
+static void
+gnome_canvas_group_update (GnomeCanvasItem *item,
+                           const cairo_matrix_t *i2c,
+                           gint flags)
+{
+       GnomeCanvasGroup *group;
+       GList *list;
+       GnomeCanvasItem *i;
+       gdouble x1, y1, x2, y2;
+
+       group = GNOME_CANVAS_GROUP (item);
+
+       GNOME_CANVAS_ITEM_CLASS (gnome_canvas_group_parent_class)->
+               update (item, i2c, flags);
+
+       x1 = G_MAXDOUBLE;
+       y1 = G_MAXDOUBLE;
+       x2 = -G_MAXDOUBLE;
+       y2 = -G_MAXDOUBLE;
+
+       for (list = group->item_list; list; list = list->next) {
+               i = list->data;
+
+               gnome_canvas_item_invoke_update (i, i2c, flags);
+
+               x1 = MIN (x1, i->x1);
+               x2 = MAX (x2, i->x2);
+               y1 = MIN (y1, i->y1);
+               y2 = MAX (y2, i->y2);
+       }
+       if (x1 >= x2 || y1 >= y2) {
+               item->x1 = item->x2 = item->y1 = item->y2 = 0;
+       } else {
+               item->x1 = x1;
+               item->y1 = y1;
+               item->x2 = x2;
+               item->y2 = y2;
+       }
+}
+
+/* Realize handler for canvas groups */
+static void
+gnome_canvas_group_realize (GnomeCanvasItem *item)
+{
+       GnomeCanvasGroup *group;
+       GList *list;
+       GnomeCanvasItem *i;
+
+       group = GNOME_CANVAS_GROUP (item);
+
+       for (list = group->item_list; list; list = list->next) {
+               i = list->data;
+
+               if (!(i->flags & GNOME_CANVAS_ITEM_REALIZED)) {
+                       GnomeCanvasItemClass *klass = GNOME_CANVAS_ITEM_GET_CLASS (i);
+
+                       if (klass)
+                               klass->realize (i);
+               }
+       }
+
+       GNOME_CANVAS_ITEM_CLASS (gnome_canvas_group_parent_class)->realize (item);
+}
+
+/* Unrealize handler for canvas groups */
+static void
+gnome_canvas_group_unrealize (GnomeCanvasItem *item)
+{
+       GnomeCanvasGroup *group;
+       GList *list;
+       GnomeCanvasItem *i;
+
+       group = GNOME_CANVAS_GROUP (item);
+
+       for (list = group->item_list; list; list = list->next) {
+               i = list->data;
+
+               if (i->flags & GNOME_CANVAS_ITEM_REALIZED) {
+                       GnomeCanvasItemClass *klass = GNOME_CANVAS_ITEM_GET_CLASS (i);
+
+                       if (klass)
+                               klass->unrealize (i);
+               }
+       }
+
+       GNOME_CANVAS_ITEM_CLASS (gnome_canvas_group_parent_class)->
+               unrealize (item);
+}
+
+/* Map handler for canvas groups */
+static void
+gnome_canvas_group_map (GnomeCanvasItem *item)
+{
+       GnomeCanvasGroup *group;
+       GList *list;
+       GnomeCanvasItem *i;
+
+       group = GNOME_CANVAS_GROUP (item);
+
+       for (list = group->item_list; list; list = list->next) {
+               i = list->data;
+
+               if (!(i->flags & GNOME_CANVAS_ITEM_MAPPED)) {
+                       GnomeCanvasItemClass *klass = GNOME_CANVAS_ITEM_GET_CLASS (i);
+
+                       if (klass)
+                               klass->map (i);
+               }
+       }
+
+       GNOME_CANVAS_ITEM_CLASS (gnome_canvas_group_parent_class)->map (item);
+}
+
+/* Unmap handler for canvas groups */
+static void
+gnome_canvas_group_unmap (GnomeCanvasItem *item)
+{
+       GnomeCanvasGroup *group;
+       GList *list;
+       GnomeCanvasItem *i;
+
+       group = GNOME_CANVAS_GROUP (item);
+
+       for (list = group->item_list; list; list = list->next) {
+               i = list->data;
+
+               if (i->flags & GNOME_CANVAS_ITEM_MAPPED) {
+                       GnomeCanvasItemClass *klass = GNOME_CANVAS_ITEM_GET_CLASS (i);
+
+                       if (klass)
+                               klass->unmap (i);
+               }
+       }
+
+       GNOME_CANVAS_ITEM_CLASS (gnome_canvas_group_parent_class)->unmap (item);
+}
+
+/* Draw handler for canvas groups */
+static void
+gnome_canvas_group_draw (GnomeCanvasItem *item,
+                         cairo_t *cr,
+                         gint x,
+                         gint y,
+                         gint width,
+                         gint height)
+{
+       GnomeCanvasGroup *group;
+       GList *list;
+       GnomeCanvasItem *child = NULL;
+
+       group = GNOME_CANVAS_GROUP (item);
+
+       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))) {
+                       GnomeCanvasItemClass *klass = GNOME_CANVAS_ITEM_GET_CLASS (child);
+
+                       if (klass && klass->draw) {
+                               cairo_save (cr);
+
+                               klass->draw (child, cr, x, y, width, height);
+
+                               cairo_restore (cr);
+                       }
+               }
+       }
+}
+
+/* Point handler for canvas groups */
+static GnomeCanvasItem *
+gnome_canvas_group_point (GnomeCanvasItem *item,
+                          gdouble x,
+                          gdouble y,
+                          gint cx,
+                          gint cy)
+{
+       GnomeCanvasGroup *group;
+       GList *list;
+       GnomeCanvasItem *child, *point_item;
+
+       group = GNOME_CANVAS_GROUP (item);
+
+       for (list = g_list_last (group->item_list); list; list = list->prev) {
+               child = list->data;
+
+               if ((child->x1 > cx) || (child->y1 > cy))
+                       continue;
+
+               if ((child->x2 < cx) || (child->y2 < cy))
+                       continue;
+
+               if (!(child->flags & GNOME_CANVAS_ITEM_VISIBLE))
+                       continue;
+
+               point_item = gnome_canvas_item_invoke_point (child, x, y, cx, cy);
+               if (point_item)
+                       return point_item;
+       }
+
+       return NULL;
+}
+
+/* Bounds handler for canvas groups */
+static void
+gnome_canvas_group_bounds (GnomeCanvasItem *item,
+                           gdouble *x1,
+                           gdouble *y1,
+                           gdouble *x2,
+                           gdouble *y2)
+{
+       GnomeCanvasGroup *group;
+       GnomeCanvasItem *child;
+       GList *list;
+       gdouble tx1, ty1, tx2, ty2;
+       gdouble minx, miny, maxx, maxy;
+       gint set;
+
+       group = GNOME_CANVAS_GROUP (item);
+
+       /* Get the bounds of the first visible item */
+
+       child = NULL; /* Unnecessary but eliminates a warning. */
+
+       set = FALSE;
+
+       for (list = group->item_list; list; list = list->next) {
+               child = list->data;
+
+               if (child->flags & GNOME_CANVAS_ITEM_VISIBLE) {
+                       set = TRUE;
+                       gnome_canvas_item_get_bounds (child, &minx, &miny, &maxx, &maxy);
+                       break;
+               }
+       }
+
+       /* If there were no visible items, return an empty bounding box */
+
+       if (!set) {
+               *x1 = *y1 = *x2 = *y2 = 0.0;
+               return;
+       }
+
+       /* Now we can grow the bounds using the rest of the items */
+
+       list = list->next;
+
+       for (; list; list = list->next) {
+               child = list->data;
+
+               if (!(child->flags & GNOME_CANVAS_ITEM_VISIBLE))
+                       continue;
+
+               gnome_canvas_item_get_bounds (child, &tx1, &ty1, &tx2, &ty2);
+
+               if (tx1 < minx)
+                       minx = tx1;
+
+               if (ty1 < miny)
+                       miny = ty1;
+
+               if (tx2 > maxx)
+                       maxx = tx2;
+
+               if (ty2 > maxy)
+                       maxy = ty2;
+       }
+
+       *x1 = minx;
+       *y1 = miny;
+       *x2 = maxx;
+       *y2 = maxy;
+}
+
+/* Adds an item to a group */
+static void
+group_add (GnomeCanvasGroup *group,
+           GnomeCanvasItem *item)
+{
+       g_object_ref_sink (item);
+
+       if (!group->item_list) {
+               group->item_list = g_list_append (group->item_list, item);
+               group->item_list_end = group->item_list;
+       } else
+               group->item_list_end = g_list_append (group->item_list_end, item)->next;
+
+       if (group->item.flags & GNOME_CANVAS_ITEM_REALIZED) {
+               GnomeCanvasItemClass *klass = GNOME_CANVAS_ITEM_GET_CLASS (item);
+
+               if (klass)
+                       klass->realize (item);
+       }
+
+       if (group->item.flags & GNOME_CANVAS_ITEM_MAPPED) {
+               GnomeCanvasItemClass *klass = GNOME_CANVAS_ITEM_GET_CLASS (item);
+
+               if (klass)
+                       klass->map (item);
+       }
+
+       g_object_notify (G_OBJECT (item), "parent");
+}
+
+/* Removes an item from a group */
+static void
+group_remove (GnomeCanvasGroup *group,
+              GnomeCanvasItem *item)
+{
+       GList *children;
+
+       g_return_if_fail (GNOME_IS_CANVAS_GROUP (group));
+       g_return_if_fail (GNOME_IS_CANVAS_ITEM (item));
+
+       for (children = group->item_list; children; children = children->next)
+               if (children->data == item) {
+                       if (item->flags & GNOME_CANVAS_ITEM_MAPPED) {
+                               GnomeCanvasItemClass *klass = GNOME_CANVAS_ITEM_GET_CLASS (item);
+
+                               if (klass)
+                                       klass->unmap (item);
+                       }
+
+                       if (item->flags & GNOME_CANVAS_ITEM_REALIZED) {
+                               GnomeCanvasItemClass *klass = GNOME_CANVAS_ITEM_GET_CLASS (item);
+
+                               if (klass)
+                                       klass->unrealize (item);
+                       }
+
+                       /* Unparent the child */
+
+                       item->parent = NULL;
+                       g_object_unref (item);
+
+                       /* Remove it from the list */
+
+                       if (children == group->item_list_end)
+                               group->item_list_end = children->prev;
+
+                       group->item_list = g_list_remove_link (group->item_list, children);
+                       g_list_free (children);
+                       break;
+               }
+}
+
+/*** GnomeCanvas ***/
+
+enum {
+       DRAW_BACKGROUND,
+       LAST_SIGNAL
+};
+
+static void gnome_canvas_dispose             (GObject          *object);
+static void gnome_canvas_map                 (GtkWidget        *widget);
+static void gnome_canvas_unmap               (GtkWidget        *widget);
+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 void gnome_canvas_drag_end            (GtkWidget        *widget,
+                                             GdkDragContext   *context);
+static gint gnome_canvas_button              (GtkWidget        *widget,
+                                             GdkEventButton   *event);
+static gint gnome_canvas_motion              (GtkWidget        *widget,
+                                             GdkEventMotion   *event);
+static gboolean gnome_canvas_key             (GtkWidget        *widget,
+                                             GdkEventKey      *event);
+static gint gnome_canvas_crossing            (GtkWidget        *widget,
+                                             GdkEventCrossing *event);
+static gint gnome_canvas_focus_in            (GtkWidget        *widget,
+                                             GdkEventFocus    *event);
+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,
+                                             cairo_t          *cr,
+                                             gint              x,
+                                             gint              y,
+                                             gint              width,
+                                             gint              height);
+
+static guint canvas_signals[LAST_SIGNAL];
+
+enum {
+        PROP_0,
+       PROP_FOCUSED_ITEM,
+};
+
+G_DEFINE_TYPE (
+       GnomeCanvas,
+       gnome_canvas,
+       GTK_TYPE_LAYOUT)
+
+static void
+gnome_canvas_paint_rect (GnomeCanvas *canvas,
+                         cairo_t *cr,
+                         gint x0,
+                         gint y0,
+                         gint x1,
+                         gint y1)
+{
+       GtkWidget *widget;
+       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);
+
+       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) {
+               GnomeCanvasItemClass *klass = GNOME_CANVAS_ITEM_GET_CLASS (canvas->root);
+
+               if (klass && klass->draw) {
+                       cairo_save (cr);
+
+                       klass->draw (
+                               canvas->root, cr,
+                               draw_x1, draw_y1,
+                               draw_width, draw_height);
+
+                       cairo_restore (cr);
+               }
+       }
+}
+
+static void
+gnome_canvas_get_property (GObject *object,
+                           guint property_id,
+                           GValue *value,
+                           GParamSpec *pspec)
+{
+       switch (property_id) {
+       case PROP_FOCUSED_ITEM:
+               g_value_set_object (value, GNOME_CANVAS (object)->focused_item);
+               break;
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+               break;
+       }
+}
+
+static void
+gnome_canvas_set_property (GObject *object,
+                           guint property_id,
+                           const GValue *value,
+                           GParamSpec *pspec)
+{
+       switch (property_id) {
+       case PROP_FOCUSED_ITEM:
+               GNOME_CANVAS (object)->focused_item = g_value_get_object (value);
+               break;
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+               break;
+       }
+}
+
+/* Class initialization function for GnomeCanvasClass */
+static void
+gnome_canvas_class_init (GnomeCanvasClass *class)
+{
+       GObjectClass   *object_class;
+       GtkWidgetClass *widget_class;
+
+       object_class = (GObjectClass *) class;
+       widget_class = (GtkWidgetClass *) class;
+
+       object_class->set_property = gnome_canvas_set_property;
+       object_class->get_property = gnome_canvas_get_property;
+       object_class->dispose = gnome_canvas_dispose;
+
+       widget_class->map = gnome_canvas_map;
+       widget_class->unmap = gnome_canvas_unmap;
+       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->drag_end = gnome_canvas_drag_end;
+       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->key_press_event = gnome_canvas_key;
+       widget_class->key_release_event = gnome_canvas_key;
+       widget_class->enter_notify_event = gnome_canvas_crossing;
+       widget_class->leave_notify_event = gnome_canvas_crossing;
+       widget_class->focus_in_event = gnome_canvas_focus_in;
+       widget_class->focus_out_event = gnome_canvas_focus_out;
+
+       class->draw_background = gnome_canvas_draw_background;
+       class->request_update = gnome_canvas_request_update_real;
+
+       g_object_class_install_property (
+               object_class,
+               PROP_FOCUSED_ITEM,
+               g_param_spec_object (
+                       "focused_item",
+                       NULL,
+                       NULL,
+                       GNOME_TYPE_CANVAS_ITEM,
+                       G_PARAM_READABLE |
+                       G_PARAM_WRITABLE));
+
+       canvas_signals[DRAW_BACKGROUND] = g_signal_new (
+               "draw_background",
+               G_TYPE_FROM_CLASS (object_class),
+               G_SIGNAL_RUN_LAST,
+               G_STRUCT_OFFSET (GnomeCanvasClass, draw_background),
+               NULL, NULL, NULL,
+               G_TYPE_NONE, 5,
+               CAIRO_GOBJECT_TYPE_CONTEXT,
+               G_TYPE_INT,
+               G_TYPE_INT,
+               G_TYPE_INT,
+               G_TYPE_INT);
+
+       gtk_widget_class_set_accessible_type (widget_class, GAIL_TYPE_CANVAS);
+       gail_canvas_a11y_init ();
+}
+
+/* Callback used when the root item of a canvas is destroyed.  The user should
+ * never ever do this, so we panic if this happens.
+ */
+G_GNUC_NORETURN static void
+panic_root_finalized (gpointer data,
+                      GObject *gone_object)
+{
+       g_error ("Eeeek, root item %p of canvas %p was destroyed!", gone_object, data);
+}
+
+/* Object initialization function for GnomeCanvas */
+static void
+gnome_canvas_init (GnomeCanvas *canvas)
+{
+       GtkLayout *layout;
+       guint layout_width, layout_height;
+
+       layout = GTK_LAYOUT (canvas);
+       gtk_layout_get_size (layout, &layout_width, &layout_height);
+
+       gtk_widget_set_can_focus (GTK_WIDGET (canvas), TRUE);
+
+       canvas->need_update = FALSE;
+       canvas->idle_id = 0;
+
+       canvas->scroll_x1 = 0.0;
+       canvas->scroll_y1 = 0.0;
+       canvas->scroll_x2 = layout_width;
+       canvas->scroll_y2 = layout_height;
+
+       canvas->pick_event.type = GDK_LEAVE_NOTIFY;
+       canvas->pick_event.crossing.x = 0;
+       canvas->pick_event.crossing.y = 0;
+
+       gtk_scrollable_set_hadjustment (GTK_SCROLLABLE (canvas), NULL);
+       gtk_scrollable_set_vadjustment (GTK_SCROLLABLE (canvas), NULL);
+
+       /* Create the root item as a special case */
+
+       canvas->root = GNOME_CANVAS_ITEM (
+               g_object_new (gnome_canvas_group_get_type (), NULL));
+       canvas->root->canvas = canvas;
+
+       g_object_ref_sink (canvas->root);
+
+       g_object_weak_ref (G_OBJECT (canvas->root), panic_root_finalized, canvas);
+
+       canvas->need_repick = TRUE;
+}
+
+/* Convenience function to remove the idle handler of a canvas */
+static void
+remove_idle (GnomeCanvas *canvas)
+{
+       if (canvas->idle_id == 0)
+               return;
+
+       g_source_remove (canvas->idle_id);
+       canvas->idle_id = 0;
+}
+
+/* Removes the transient state of the canvas (idle handler, grabs). */
+static void
+shutdown_transients (GnomeCanvas *canvas)
+{
+       if (canvas->grabbed_device != NULL) {
+               gdk_device_ungrab (canvas->grabbed_device, GDK_CURRENT_TIME);
+               g_object_unref (canvas->grabbed_device);
+               canvas->grabbed_device = NULL;
+       }
+
+       canvas->grabbed_item = NULL;
+
+       remove_idle (canvas);
+}
+
+/* Dispose handler for GnomeCanvas */
+static void
+gnome_canvas_dispose (GObject *object)
+{
+       GnomeCanvas *canvas;
+
+       g_return_if_fail (GNOME_IS_CANVAS (object));
+
+       /* remember, dispose can be run multiple times! */
+
+       canvas = GNOME_CANVAS (object);
+
+       if (canvas->root) {
+               g_object_weak_unref (G_OBJECT (canvas->root), panic_root_finalized, canvas);
+               g_object_unref (canvas->root);
+               canvas->root = NULL;
+       }
+
+       shutdown_transients (canvas);
+
+       /* Chain up to parent's dispose() method. */
+       G_OBJECT_CLASS (gnome_canvas_parent_class)->dispose (object);
+}
+
+/**
+ * gnome_canvas_new:
+ *
+ * Creates a new empty canvas in non-antialiased mode.
+ *
+ * Return value: A newly-created canvas.
+ **/
+GtkWidget *
+gnome_canvas_new (void)
+{
+       return GTK_WIDGET (g_object_new (gnome_canvas_get_type (), NULL));
+}
+
+/* Map handler for the canvas */
+static void
+gnome_canvas_map (GtkWidget *widget)
+{
+       GnomeCanvas *canvas;
+       GnomeCanvasItemClass *klass;
+
+       g_return_if_fail (GNOME_IS_CANVAS (widget));
+
+       /* Normal widget mapping stuff */
+
+       GTK_WIDGET_CLASS (gnome_canvas_parent_class)->map (widget);
+
+       canvas = GNOME_CANVAS (widget);
+
+       if (canvas->need_update)
+               add_idle (canvas);
+
+       /* Map items */
+
+       klass = GNOME_CANVAS_ITEM_GET_CLASS (canvas->root);
+       g_return_if_fail (klass != NULL);
+
+       if (klass->map)
+               klass->map (canvas->root);
+}
+
+/* Unmap handler for the canvas */
+static void
+gnome_canvas_unmap (GtkWidget *widget)
+{
+       GnomeCanvas *canvas;
+       GnomeCanvasItemClass *klass;
+
+       g_return_if_fail (GNOME_IS_CANVAS (widget));
+
+       canvas = GNOME_CANVAS (widget);
+
+       shutdown_transients (canvas);
+
+       /* Unmap items */
+
+       klass = GNOME_CANVAS_ITEM_GET_CLASS (canvas->root);
+       g_return_if_fail (klass != NULL);
+
+       if (klass->unmap)
+               klass->unmap (canvas->root);
+
+       /* Normal widget unmapping stuff */
+
+       GTK_WIDGET_CLASS (gnome_canvas_parent_class)->unmap (widget);
+}
+
+/* Realize handler for the canvas */
+static void
+gnome_canvas_realize (GtkWidget *widget)
+{
+       GnomeCanvas *canvas;
+       GnomeCanvasItemClass *klass;
+       GtkLayout *layout;
+       GdkWindow *bin_window;
+
+       g_return_if_fail (GNOME_IS_CANVAS (widget));
+
+       /* Normal widget realization stuff */
+
+       GTK_WIDGET_CLASS (gnome_canvas_parent_class)->realize (widget);
+
+       canvas = GNOME_CANVAS (widget);
+
+       layout = GTK_LAYOUT (canvas);
+       bin_window = gtk_layout_get_bin_window (layout);
+
+       gdk_window_set_events (
+               bin_window,
+               (gdk_window_get_events (bin_window)
+               | GDK_EXPOSURE_MASK
+               | GDK_SCROLL_MASK
+               | GDK_BUTTON_PRESS_MASK
+               | GDK_BUTTON_RELEASE_MASK
+               | GDK_POINTER_MOTION_MASK
+               | GDK_KEY_PRESS_MASK
+               | GDK_KEY_RELEASE_MASK
+               | GDK_ENTER_NOTIFY_MASK
+               | GDK_LEAVE_NOTIFY_MASK
+               | GDK_FOCUS_CHANGE_MASK));
+
+       klass = GNOME_CANVAS_ITEM_GET_CLASS (canvas->root);
+       g_return_if_fail (klass != NULL);
+
+       /* Create our own temporary pixmap gc and realize all the items */
+
+       klass->realize (canvas->root);
+}
+
+/* Unrealize handler for the canvas */
+static void
+gnome_canvas_unrealize (GtkWidget *widget)
+{
+       GnomeCanvas *canvas;
+       GnomeCanvasItemClass *klass;
+
+       g_return_if_fail (GNOME_IS_CANVAS (widget));
+
+       canvas = GNOME_CANVAS (widget);
+
+       shutdown_transients (canvas);
+
+       /* Unrealize items and parent widget */
+
+       klass = GNOME_CANVAS_ITEM_GET_CLASS (canvas->root);
+       g_return_if_fail (klass != NULL);
+
+       klass->unrealize (canvas->root);
+
+       GTK_WIDGET_CLASS (gnome_canvas_parent_class)->unrealize (widget);
+}
+
+/* Handles scrolling of the canvas.  Adjusts the scrolling and zooming offset to
+ * keep as much as possible of the canvas scrolling region in view.
+ */
+static void
+scroll_to (GnomeCanvas *canvas,
+           gint cx,
+           gint cy)
+{
+       GtkWidget *widget;
+       GtkAllocation allocation;
+       GtkScrollable *scrollable;
+       GtkAdjustment *hadjustment;
+       GtkAdjustment *vadjustment;
+       guint layout_width, layout_height;
+       gint scroll_width, scroll_height;
+       gint right_limit, bottom_limit;
+       gint old_zoom_xofs, old_zoom_yofs;
+       gint canvas_width, canvas_height;
+
+       widget = GTK_WIDGET (canvas);
+       gtk_widget_get_allocation (widget, &allocation);
+
+       scrollable = GTK_SCROLLABLE (canvas);
+       hadjustment = gtk_scrollable_get_hadjustment (scrollable);
+       vadjustment = gtk_scrollable_get_vadjustment (scrollable);
+
+       gtk_layout_get_size (GTK_LAYOUT (canvas), &layout_width, &layout_height);
+
+       canvas_width = allocation.width;
+       canvas_height = allocation.height;
+
+       scroll_width =
+               floor ((canvas->scroll_x2 - canvas->scroll_x1) + 0.5);
+       scroll_height =
+               floor ((canvas->scroll_y2 - canvas->scroll_y1) + 0.5);
+
+       right_limit = scroll_width - canvas_width;
+       bottom_limit = scroll_height - canvas_height;
+
+       old_zoom_xofs = canvas->zoom_xofs;
+       old_zoom_yofs = canvas->zoom_yofs;
+
+       if (right_limit < 0) {
+               cx = 0;
+               canvas->zoom_xofs = (canvas_width - scroll_width) / 2;
+               scroll_width = canvas_width;
+       } else if (cx < 0) {
+               cx = 0;
+               canvas->zoom_xofs = 0;
+       } else if (cx > right_limit) {
+               cx = right_limit;
+               canvas->zoom_xofs = 0;
+       } else
+               canvas->zoom_xofs = 0;
+
+       if (bottom_limit < 0) {
+               cy = 0;
+               canvas->zoom_yofs = (canvas_height - scroll_height) / 2;
+               scroll_height = canvas_height;
+       } else if (cy < 0) {
+               cy = 0;
+               canvas->zoom_yofs = 0;
+       } else if (cy > bottom_limit) {
+               cy = bottom_limit;
+               canvas->zoom_yofs = 0;
+       } else
+               canvas->zoom_yofs = 0;
+
+       if ((canvas->zoom_xofs != old_zoom_xofs) ||
+           (canvas->zoom_yofs != old_zoom_yofs)) {
+               /* This can only occur, if either canvas size or widget
+                * size changes.  So I think we can request full redraw
+                * here.  The reason is, that coverage UTA will be
+                * invalidated by offset change. */
+               /* FIXME Strictly this is not correct - we have to remove
+                *       our own idle (Lauris) */
+               /* More stuff - we have to mark root as needing fresh affine
+                * (Lauris) */
+               if (!(canvas->root->flags & GNOME_CANVAS_ITEM_NEED_AFFINE)) {
+                       canvas->root->flags |= GNOME_CANVAS_ITEM_NEED_AFFINE;
+                       gnome_canvas_request_update (canvas);
+               }
+               gtk_widget_queue_draw (GTK_WIDGET (canvas));
+       }
+
+       if (hadjustment)
+               gtk_adjustment_set_value (hadjustment, cx);
+
+       if (vadjustment)
+               gtk_adjustment_set_value (vadjustment, cy);
+
+       if ((scroll_width != (gint) layout_width)
+           || (scroll_height != (gint) layout_height))
+               gtk_layout_set_size (GTK_LAYOUT (canvas), scroll_width, scroll_height);
+}
+
+/* Size allocation handler for the canvas */
+static void
+gnome_canvas_size_allocate (GtkWidget *widget,
+                            GtkAllocation *allocation)
+{
+       GtkScrollable *scrollable;
+       GtkAdjustment *hadjustment;
+       GtkAdjustment *vadjustment;
+
+       g_return_if_fail (GNOME_IS_CANVAS (widget));
+       g_return_if_fail (allocation != NULL);
+
+       GTK_WIDGET_CLASS (gnome_canvas_parent_class)->
+               size_allocate (widget, allocation);
+
+       scrollable = GTK_SCROLLABLE (widget);
+       hadjustment = gtk_scrollable_get_hadjustment (scrollable);
+       vadjustment = gtk_scrollable_get_vadjustment (scrollable);
+
+       /* Recenter the view, if appropriate */
+
+       g_object_freeze_notify (G_OBJECT (hadjustment));
+       g_object_freeze_notify (G_OBJECT (vadjustment));
+
+       gtk_adjustment_set_page_size (hadjustment, allocation->width);
+       gtk_adjustment_set_page_increment (hadjustment, allocation->width / 2);
+
+       gtk_adjustment_set_page_size (vadjustment, allocation->height);
+       gtk_adjustment_set_page_increment (vadjustment, allocation->height / 2);
+
+       scroll_to (
+               GNOME_CANVAS (widget),
+               gtk_adjustment_get_value (hadjustment),
+               gtk_adjustment_get_value (vadjustment));
+
+       g_object_thaw_notify (G_OBJECT (hadjustment));
+       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;
+       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);
+
+       gdk_cairo_get_clip_rectangle (cr, &rect);
+
+       if (canvas->need_update) {
+               cairo_matrix_t w2c;
+
+               /* We start updating root with w2c matrix */
+               gnome_canvas_w2c_matrix (canvas, &w2c);
+
+               gnome_canvas_item_invoke_update (canvas->root, &w2c, 0);
+
+               canvas->need_update = FALSE;
+       }
+
+       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 (gnome_canvas_parent_class)->draw (widget, cr);
+
+       return FALSE;
+}
+
+static void
+gnome_canvas_drag_end (GtkWidget *widget,
+                      GdkDragContext *context)
+{
+       GnomeCanvas *canvas = GNOME_CANVAS (widget);
+
+       if (canvas->grabbed_item) {
+               gnome_canvas_item_ungrab (canvas->grabbed_item, GDK_CURRENT_TIME);
+       }
+
+       if (GTK_WIDGET_CLASS (gnome_canvas_parent_class)->drag_end)
+               GTK_WIDGET_CLASS (gnome_canvas_parent_class)->drag_end (widget, context);
+}
+
+/* Emits an event for an item in the canvas, be it the current item, grabbed
+ * item, or focused item, as appropriate.
+ */
+
+static gint
+emit_event (GnomeCanvas *canvas,
+            GdkEvent *event)
+{
+       GdkEvent *ev;
+       gint finished;
+       GnomeCanvasItem *item;
+       GnomeCanvasItem *parent;
+       guint mask;
+
+       /* Perform checks for grabbed items */
+
+       if (canvas->grabbed_item &&
+           !is_descendant (canvas->current_item, canvas->grabbed_item)) {
+               /* I think this warning is annoying and I don't know what it's for
+                * so I'll disable it for now.
+                */
+/*                g_warning ("emit_event() returning FALSE!\n");*/
+               return FALSE;
+       }
+
+       if (canvas->grabbed_item) {
+               switch (event->type) {
+               case GDK_ENTER_NOTIFY:
+                       mask = GDK_ENTER_NOTIFY_MASK;
+                       break;
+
+               case GDK_LEAVE_NOTIFY:
+                       mask = GDK_LEAVE_NOTIFY_MASK;
+                       break;
+
+               case GDK_MOTION_NOTIFY:
+                       mask = GDK_POINTER_MOTION_MASK;
+                       break;
+
+               case GDK_BUTTON_PRESS:
+               case GDK_2BUTTON_PRESS:
+               case GDK_3BUTTON_PRESS:
+                       mask = GDK_BUTTON_PRESS_MASK;
+                       break;
+
+               case GDK_BUTTON_RELEASE:
+                       mask = GDK_BUTTON_RELEASE_MASK;
+                       break;
+
+               case GDK_KEY_PRESS:
+                       mask = GDK_KEY_PRESS_MASK;
+                       break;
+
+               case GDK_KEY_RELEASE:
+                       mask = GDK_KEY_RELEASE_MASK;
+                       break;
+
+               case GDK_SCROLL:
+                       mask = GDK_SCROLL_MASK;
+                       break;
+
+               default:
+                       mask = 0;
+                       break;
+               }
+
+               if (!(mask & canvas->grabbed_event_mask))
+                       return FALSE;
+       }
+
+       /* Convert to world coordinates -- we have two cases because of diferent
+        * offsets of the fields in the event structures.
+        */
+
+       ev = gdk_event_copy (event);
+
+       switch (ev->type)
+       {
+       case GDK_ENTER_NOTIFY:
+       case GDK_LEAVE_NOTIFY:
+               gnome_canvas_window_to_world (
+                       canvas,
+                       ev->crossing.x, ev->crossing.y,
+                       &ev->crossing.x, &ev->crossing.y);
+               break;
+
+       case GDK_MOTION_NOTIFY:
+       case GDK_BUTTON_PRESS:
+       case GDK_2BUTTON_PRESS:
+       case GDK_3BUTTON_PRESS:
+       case GDK_BUTTON_RELEASE:
+               gnome_canvas_window_to_world (
+                       canvas,
+                       ev->motion.x, ev->motion.y,
+                       &ev->motion.x, &ev->motion.y);
+               break;
+
+       default:
+               break;
+       }
+
+       /* Choose where we send the event */
+
+       item = canvas->current_item;
+
+       if (canvas->focused_item
+           && ((event->type == GDK_KEY_PRESS) ||
+               (event->type == GDK_KEY_RELEASE) ||
+               (event->type == GDK_FOCUS_CHANGE)))
+               item = canvas->focused_item;
+
+       /* The event is propagated up the hierarchy (for if someone connected to
+        * a group instead of a leaf event), and emission is stopped if a
+        * handler returns TRUE, just like for GtkWidget events.
+        */
+
+       finished = FALSE;
+
+       while (item && !finished) {
+               g_object_ref (item);
+
+               g_signal_emit (
+                       item, item_signals[ITEM_EVENT], 0,
+                       ev, &finished);
+
+               parent = item->parent;
+               g_object_unref (item);
+
+               item = parent;
+       }
+
+       gdk_event_free (ev);
+
+       return finished;
+}
+
+/* Re-picks the current item in the canvas, based on the event's coordinates.
+ * Also emits enter/leave events for items as appropriate.
+ */
+static gint
+pick_current_item (GnomeCanvas *canvas,
+                   GdkEvent *event)
+{
+       gint button_down;
+       gdouble x, y;
+       gint cx, cy;
+       gint retval;
+
+       retval = FALSE;
+
+       /* If a button is down, we'll perform enter and leave events on the
+        * current item, but not enter on any other item.  This is more or less
+        * like X pointer grabbing for canvas items.
+        */
+       button_down = canvas->state & (GDK_BUTTON1_MASK
+                                      | GDK_BUTTON2_MASK
+                                      | GDK_BUTTON3_MASK
+                                      | GDK_BUTTON4_MASK
+                                      | GDK_BUTTON5_MASK);
+       if (!button_down)
+               canvas->left_grabbed_item = FALSE;
+
+       /* Save the event in the canvas.  This is used to synthesize enter and
+        * leave events in case the current item changes.  It is also used to
+        * re-pick the current item if the current one gets deleted.  Also,
+        * synthesize an enter event.
+        */
+       if (event != &canvas->pick_event) {
+               if ((event->type == GDK_MOTION_NOTIFY) ||
+                   (event->type == GDK_BUTTON_RELEASE)) {
+                       /* these fields have the same offsets in both types of events */
+
+                       canvas->pick_event.crossing.type = GDK_ENTER_NOTIFY;
+                       canvas->pick_event.crossing.window = event->motion.window;
+                       canvas->pick_event.crossing.send_event = event->motion.send_event;
+                       canvas->pick_event.crossing.subwindow = NULL;
+                       canvas->pick_event.crossing.x = event->motion.x;
+                       canvas->pick_event.crossing.y = event->motion.y;
+                       canvas->pick_event.crossing.mode = GDK_CROSSING_NORMAL;
+                       canvas->pick_event.crossing.detail = GDK_NOTIFY_NONLINEAR;
+                       canvas->pick_event.crossing.focus = FALSE;
+                       canvas->pick_event.crossing.state = event->motion.state;
+
+                       /* these fields don't have the same offsets in both types of events */
+
+                       if (event->type == GDK_MOTION_NOTIFY) {
+                               canvas->pick_event.crossing.x_root = event->motion.x_root;
+                               canvas->pick_event.crossing.y_root = event->motion.y_root;
+                       } else {
+                               canvas->pick_event.crossing.x_root = event->button.x_root;
+                               canvas->pick_event.crossing.y_root = event->button.y_root;
+                       }
+               } else
+                       canvas->pick_event = *event;
+       }
+
+       /* Don't do anything else if this is a recursive call */
+
+       if (canvas->in_repick)
+               return retval;
+
+       /* LeaveNotify means that there is no current item, so we don't look for one */
+
+       if (canvas->pick_event.type != GDK_LEAVE_NOTIFY) {
+               /* these fields don't have the same offsets in both types of events */
+
+               if (canvas->pick_event.type == GDK_ENTER_NOTIFY) {
+                       x = canvas->pick_event.crossing.x - canvas->zoom_xofs;
+                       y = canvas->pick_event.crossing.y - canvas->zoom_yofs;
+               } else {
+                       x = canvas->pick_event.motion.x - canvas->zoom_xofs;
+                       y = canvas->pick_event.motion.y - canvas->zoom_yofs;
+               }
+
+               /* canvas pixel coords */
+
+               cx = (gint) (x + 0.5);
+               cy = (gint) (y + 0.5);
+
+               /* world coords */
+
+               x = canvas->scroll_x1 + x;
+               y = canvas->scroll_y1 + y;
+
+               /* find the closest item */
+
+               if (canvas->root->flags & GNOME_CANVAS_ITEM_VISIBLE)
+                       canvas->new_current_item =
+                               gnome_canvas_item_invoke_point (
+                               canvas->root, x, y, cx, cy);
+               else
+                       canvas->new_current_item = NULL;
+       } else
+               canvas->new_current_item = NULL;
+
+       if ((canvas->new_current_item == canvas->current_item)
+           && !canvas->left_grabbed_item)
+               return retval; /* current item did not change */
+
+       /* Synthesize events for old and new current items */
+
+       if ((canvas->new_current_item != canvas->current_item)
+           && (canvas->current_item != NULL)
+           && !canvas->left_grabbed_item) {
+               GdkEvent new_event;
+
+               new_event = canvas->pick_event;
+               new_event.type = GDK_LEAVE_NOTIFY;
+
+               new_event.crossing.detail = GDK_NOTIFY_ANCESTOR;
+               new_event.crossing.subwindow = NULL;
+               canvas->in_repick = TRUE;
+               retval = emit_event (canvas, &new_event);
+               canvas->in_repick = FALSE;
+       }
+
+       /* new_current_item may have been set to NULL during the
+        * call to emit_event() above */
+
+       if ((canvas->new_current_item != canvas->current_item) && button_down) {
+               canvas->left_grabbed_item = TRUE;
+               return retval;
+       }
+
+       /* Handle the rest of cases */
+
+       canvas->left_grabbed_item = FALSE;
+       canvas->current_item = canvas->new_current_item;
+
+       if (canvas->current_item != NULL) {
+               GdkEvent new_event;
+
+               new_event = canvas->pick_event;
+               new_event.type = GDK_ENTER_NOTIFY;
+               new_event.crossing.detail = GDK_NOTIFY_ANCESTOR;
+               new_event.crossing.subwindow = NULL;
+               retval = emit_event (canvas, &new_event);
+       }
+
+       return retval;
+}
+
+/* Button event handler for the canvas */
+static gint
+gnome_canvas_button (GtkWidget *widget,
+                     GdkEventButton *event)
+{
+       GnomeCanvas *canvas;
+       GtkLayout *layout;
+       GdkWindow *bin_window;
+       gint mask;
+       gint retval;
+
+       g_return_val_if_fail (GNOME_IS_CANVAS (widget), FALSE);
+       g_return_val_if_fail (event != NULL, FALSE);
+
+       retval = FALSE;
+
+       canvas = GNOME_CANVAS (widget);
+
+       layout = GTK_LAYOUT (canvas);
+       bin_window = gtk_layout_get_bin_window (layout);
+
+       /*
+        * dispatch normally regardless of the event's window if an item has
+        * has a pointer grab in effect
+        */
+       if (!canvas->grabbed_item && event->window != bin_window)
+               return retval;
+
+       switch (event->button) {
+               case 1:
+                       mask = GDK_BUTTON1_MASK;
+                       break;
+               case 2:
+                       mask = GDK_BUTTON2_MASK;
+                       break;
+               case 3:
+                       mask = GDK_BUTTON3_MASK;
+                       break;
+               case 4:
+                       mask = GDK_BUTTON4_MASK;
+                       break;
+               case 5:
+                       mask = GDK_BUTTON5_MASK;
+                       break;
+               default:
+                       mask = 0;
+       }
+
+       switch (event->type) {
+               case GDK_BUTTON_PRESS:
+               case GDK_2BUTTON_PRESS:
+               case GDK_3BUTTON_PRESS:
+                       /* Pick the current item as if the button were
+                        * not pressed, and then process the event. */
+                       canvas->state = event->state;
+                       pick_current_item (canvas, (GdkEvent *) event);
+                       canvas->state ^= mask;
+                       retval = emit_event (canvas, (GdkEvent *) event);
+                       break;
+
+               case GDK_BUTTON_RELEASE:
+                       /* Process the event as if the button were pressed,
+                        * then repick after the button has been released. */
+                       canvas->state = event->state;
+                       retval = emit_event (canvas, (GdkEvent *) event);
+                       event->state ^= mask;
+                       canvas->state = event->state;
+                       pick_current_item (canvas, (GdkEvent *) event);
+                       event->state ^= mask;
+                       break;
+
+               default:
+                       g_warn_if_reached ();
+       }
+
+       return retval;
+}
+
+/* Motion event handler for the canvas */
+static gint
+gnome_canvas_motion (GtkWidget *widget,
+                     GdkEventMotion *event)
+{
+       GnomeCanvas *canvas;
+       GtkLayout *layout;
+       GdkWindow *bin_window;
+
+       g_return_val_if_fail (GNOME_IS_CANVAS (widget), FALSE);
+       g_return_val_if_fail (event != NULL, FALSE);
+
+       canvas = GNOME_CANVAS (widget);
+
+       layout = GTK_LAYOUT (widget);
+       bin_window = gtk_layout_get_bin_window (layout);
+
+       if (event->window != bin_window)
+               return FALSE;
+
+       canvas->state = event->state;
+       pick_current_item (canvas, (GdkEvent *) event);
+       return emit_event (canvas, (GdkEvent *) event);
+}
+
+/* Key event handler for the canvas */
+static gboolean
+gnome_canvas_key (GtkWidget *widget,
+                  GdkEventKey *event)
+{
+       GnomeCanvas *canvas;
+
+       g_return_val_if_fail (GNOME_IS_CANVAS (widget), FALSE);
+       g_return_val_if_fail (event != NULL, FALSE);
+
+       canvas = GNOME_CANVAS (widget);
+
+       if (!emit_event (canvas, (GdkEvent *) event)) {
+               GtkWidgetClass *widget_class;
+
+               widget_class = GTK_WIDGET_CLASS (gnome_canvas_parent_class);
+
+               if (event->type == GDK_KEY_PRESS) {
+                       if (widget_class->key_press_event)
+                               return (* widget_class->key_press_event) (widget, event);
+               } else if (event->type == GDK_KEY_RELEASE) {
+                       if (widget_class->key_release_event)
+                               return (* widget_class->key_release_event) (widget, event);
+               } else
+                       g_warn_if_reached ();
+
+               return FALSE;
+       } else
+               return TRUE;
+}
+
+/* Crossing event handler for the canvas */
+static gint
+gnome_canvas_crossing (GtkWidget *widget,
+                       GdkEventCrossing *event)
+{
+       GnomeCanvas *canvas;
+       GtkLayout *layout;
+       GdkWindow *bin_window;
+
+       g_return_val_if_fail (GNOME_IS_CANVAS (widget), FALSE);
+       g_return_val_if_fail (event != NULL, FALSE);
+
+       canvas = GNOME_CANVAS (widget);
+
+       layout = GTK_LAYOUT (canvas);
+       bin_window = gtk_layout_get_bin_window (layout);
+
+       if (event->window != bin_window)
+               return FALSE;
+
+       /* XXX Detect and disregard synthesized crossing events generated
+        *     by synth_crossing() in gtkwidget.c.  The pointer coordinates
+        *     are invalid and pick_current_item() relies on them. */
+       if (event->x == 0 && event->y == 0 &&
+           event->x_root == 0 && event->y_root == 0)
+               return FALSE;
+
+       canvas->state = event->state;
+       return pick_current_item (canvas, (GdkEvent *) event);
+}
+
+/* Focus in handler for the canvas */
+static gint
+gnome_canvas_focus_in (GtkWidget *widget,
+                       GdkEventFocus *event)
+{
+       GnomeCanvas *canvas;
+
+       /* XXX Can't access flags directly anymore, but is it really needed?
+        *     If so, could we call gtk_widget_send_focus_change() instead? */
+#if 0
+       GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS);
+#endif
+
+       canvas = GNOME_CANVAS (widget);
+
+       if (canvas->focused_item)
+               return emit_event (canvas, (GdkEvent *) event);
+       else
+               return FALSE;
+}
+
+/* Focus out handler for the canvas */
+static gint
+gnome_canvas_focus_out (GtkWidget *widget,
+                        GdkEventFocus *event)
+{
+       GnomeCanvas *canvas;
+
+       /* XXX Can't access flags directly anymore, but is it really needed?
+        *     If so, could we call gtk_widget_send_focus_change() instead? */
+#if 0
+       GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_FOCUS);
+#endif
+
+       canvas = GNOME_CANVAS (widget);
+
+       if (canvas->focused_item)
+               return emit_event (canvas, (GdkEvent *) event);
+       else
+               return FALSE;
+}
+
+static void
+gnome_canvas_draw_background (GnomeCanvas *canvas,
+                              cairo_t *cr,
+                              gint x,
+                              gint y,
+                              gint width,
+                              gint height)
+{
+       GtkStyleContext *style_context;
+       GdkRGBA rgba;
+
+       style_context = gtk_widget_get_style_context (GTK_WIDGET (canvas));
+       if (!gtk_style_context_lookup_color (style_context, "theme_bg_color", &rgba))
+               gdk_rgba_parse (&rgba, "#aaaaaa");
+
+       cairo_save (cr);
+       gdk_cairo_set_source_rgba (cr, &rgba);
+       cairo_paint (cr);
+       cairo_restore (cr);
+}
+
+static void
+do_update (GnomeCanvas *canvas)
+{
+       /* Cause the update if necessary */
+
+update_again:
+       if (canvas->need_update) {
+               cairo_matrix_t w2c;
+
+               /* We start updating root with w2c matrix */
+               gnome_canvas_w2c_matrix (canvas, &w2c);
+
+               gnome_canvas_item_invoke_update (canvas->root, &w2c, 0);
+
+               canvas->need_update = FALSE;
+       }
+
+       /* Pick new current item */
+
+       while (canvas->need_repick) {
+               canvas->need_repick = FALSE;
+               pick_current_item (canvas, &canvas->pick_event);
+       }
+
+       /* it is possible that during picking we emitted an event in which
+        * the user then called some function which then requested update
+        * of something.  Without this we'd be left in a state where
+        * need_update would have been left TRUE and the canvas would have
+        * been left unpainted. */
+       if (canvas->need_update) {
+               goto update_again;
+       }
+}
+
+/* Idle handler for the canvas.  It deals with pending updates and redraws. */
+static gboolean
+idle_handler (gpointer data)
+{
+       GnomeCanvas *canvas;
+
+       canvas = GNOME_CANVAS (data);
+
+       do_update (canvas);
+
+       /* Reset idle id */
+       canvas->idle_id = 0;
+
+       return FALSE;
+}
+
+/* Convenience function to add an idle handler to a canvas */
+static void
+add_idle (GnomeCanvas *canvas)
+{
+       g_return_if_fail (canvas->need_update);
+
+       if (!canvas->idle_id)
+               canvas->idle_id = g_idle_add_full (
+                       CANVAS_IDLE_PRIORITY,
+                       idle_handler,
+                       canvas,
+                       NULL);
+
+/*     canvas->idle_id = gtk_idle_add (idle_handler, canvas); */
+}
+
+/**
+ * gnome_canvas_root:
+ * @canvas: A canvas.
+ *
+ * Queries the root group of a canvas.
+ *
+ * Return value: The root group of the specified canvas.
+ **/
+GnomeCanvasGroup *
+gnome_canvas_root (GnomeCanvas *canvas)
+{
+       g_return_val_if_fail (GNOME_IS_CANVAS (canvas), NULL);
+
+       return GNOME_CANVAS_GROUP (canvas->root);
+}
+
+/**
+ * gnome_canvas_set_scroll_region:
+ * @canvas: A canvas.
+ * @x1: Leftmost limit of the scrolling region.
+ * @y1: Upper limit of the scrolling region.
+ * @x2: Rightmost limit of the scrolling region.
+ * @y2: Lower limit of the scrolling region.
+ *
+ * Sets the scrolling region of a canvas to the specified rectangle.  The canvas
+ * will then be able to scroll only within this region.  The view of the canvas
+ * is adjusted as appropriate to display as much of the new region as possible.
+ **/
+void
+gnome_canvas_set_scroll_region (GnomeCanvas *canvas,
+                                gdouble x1,
+                                gdouble y1,
+                                gdouble x2,
+                                gdouble y2)
+{
+       GtkScrollable *scrollable;
+       GtkAdjustment *hadjustment;
+       GtkAdjustment *vadjustment;
+       gdouble hadjustment_value;
+       gdouble vadjustment_value;
+       gdouble wxofs, wyofs;
+       gint xofs, yofs;
+
+       g_return_if_fail (GNOME_IS_CANVAS (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);
+
+       /*
+        * Set the new scrolling region.  If possible, do not move the
+        * visible contents of the canvas.
+        */
+
+       gnome_canvas_c2w (
+               canvas,
+               hadjustment_value + canvas->zoom_xofs,
+               vadjustment_value + canvas->zoom_yofs,
+               &wxofs, &wyofs);
+
+       canvas->scroll_x1 = x1;
+       canvas->scroll_y1 = y1;
+       canvas->scroll_x2 = x2;
+       canvas->scroll_y2 = y2;
+
+       gnome_canvas_w2c (canvas, wxofs, wyofs, &xofs, &yofs);
+
+       scroll_to (canvas, xofs, yofs);
+
+       canvas->need_repick = TRUE;
+#if 0
+       /* todo: should be requesting update */
+       (* GNOME_CANVAS_ITEM_CLASS (canvas->root->object.class)->update) (
+               canvas->root, NULL, NULL, 0);
+#endif
+}
+
+/**
+ * gnome_canvas_get_scroll_region:
+ * @canvas: A canvas.
+ * @x1: Leftmost limit of the scrolling region (return value).
+ * @y1: Upper limit of the scrolling region (return value).
+ * @x2: Rightmost limit of the scrolling region (return value).
+ * @y2: Lower limit of the scrolling region (return value).
+ *
+ * Queries the scrolling region of a canvas.
+ **/
+void
+gnome_canvas_get_scroll_region (GnomeCanvas *canvas,
+                                gdouble *x1,
+                                gdouble *y1,
+                                gdouble *x2,
+                                gdouble *y2)
+{
+       g_return_if_fail (GNOME_IS_CANVAS (canvas));
+
+       if (x1)
+               *x1 = canvas->scroll_x1;
+
+       if (y1)
+               *y1 = canvas->scroll_y1;
+
+       if (x2)
+               *x2 = canvas->scroll_x2;
+
+       if (y2)
+               *y2 = canvas->scroll_y2;
+}
+
+/**
+ * gnome_canvas_scroll_to:
+ * @canvas: A canvas.
+ * @cx: Horizontal scrolling offset in canvas pixel units.
+ * @cy: Vertical scrolling offset in canvas pixel units.
+ *
+ * Makes a canvas scroll to the specified offsets, given in canvas pixel units.
+ * The canvas will adjust the view so that it is not outside the scrolling
+ * region.  This function is typically not used, as it is better to hook
+ * scrollbars to the canvas layout's scrolling adjusments.
+ **/
+void
+gnome_canvas_scroll_to (GnomeCanvas *canvas,
+                        gint cx,
+                        gint cy)
+{
+       g_return_if_fail (GNOME_IS_CANVAS (canvas));
+
+       scroll_to (canvas, cx, cy);
+}
+
+/**
+ * gnome_canvas_get_scroll_offsets:
+ * @canvas: A canvas.
+ * @cx: Horizontal scrolling offset (return value).
+ * @cy: Vertical scrolling offset (return value).
+ *
+ * Queries the scrolling offsets of a canvas.  The values are returned in canvas
+ * pixel units.
+ **/
+void
+gnome_canvas_get_scroll_offsets (GnomeCanvas *canvas,
+                                 gint *cx,
+                                 gint *cy)
+{
+       GtkAdjustment *adjustment;
+       GtkScrollable *scrollable;
+
+       g_return_if_fail (GNOME_IS_CANVAS (canvas));
+
+       scrollable = GTK_SCROLLABLE (canvas);
+
+       if (cx) {
+               adjustment = gtk_scrollable_get_hadjustment (scrollable);
+               *cx = (gint) gtk_adjustment_get_value (adjustment);
+       }
+
+       if (cy) {
+               adjustment = gtk_scrollable_get_vadjustment (scrollable);
+               *cy = (gint) gtk_adjustment_get_value (adjustment);
+       }
+}
+
+/**
+ * gnome_canvas_get_item_at:
+ * @canvas: A canvas.
+ * @x: X position in world coordinates.
+ * @y: Y position in world coordinates.
+ *
+ * Looks for the item that is under the specified position, which must be
+ * specified in world coordinates.
+ *
+ * Return value: The sought item, or NULL if no item is at the specified
+ * coordinates.
+ **/
+GnomeCanvasItem *
+gnome_canvas_get_item_at (GnomeCanvas *canvas,
+                          gdouble x,
+                          gdouble y)
+{
+       gint cx, cy;
+
+       g_return_val_if_fail (GNOME_IS_CANVAS (canvas), NULL);
+
+       gnome_canvas_w2c (canvas, x, y, &cx, &cy);
+
+       return gnome_canvas_item_invoke_point (canvas->root, x, y, cx, cy);
+}
+
+/* Queues an update of the canvas */
+static void
+gnome_canvas_request_update (GnomeCanvas *canvas)
+{
+       GNOME_CANVAS_GET_CLASS (canvas)->request_update (canvas);
+}
+
+static void
+gnome_canvas_request_update_real (GnomeCanvas *canvas)
+{
+       if (canvas->need_update)
+               return;
+
+       canvas->need_update = TRUE;
+       if (gtk_widget_get_mapped ((GtkWidget *) canvas))
+               add_idle (canvas);
+}
+
+static inline void
+get_visible_rect (GnomeCanvas *canvas,
+                  GdkRectangle *visible)
+{
+       GtkAllocation allocation;
+       GtkScrollable *scrollable;
+       GtkAdjustment *hadjustment;
+       GtkAdjustment *vadjustment;
+       gdouble hadjustment_value;
+       gdouble vadjustment_value;
+
+       gtk_widget_get_allocation (GTK_WIDGET (canvas), &allocation);
+
+       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);
+
+       visible->x = hadjustment_value - canvas->zoom_xofs;
+       visible->y = vadjustment_value - canvas->zoom_yofs;
+       visible->width = allocation.width;
+       visible->height = allocation.height;
+}
+
+/**
+ * gnome_canvas_request_redraw:
+ * @canvas: A canvas.
+ * @x1: Leftmost coordinate of the rectangle to be redrawn.
+ * @y1: Upper coordinate of the rectangle to be redrawn.
+ * @x2: Rightmost coordinate of the rectangle to be redrawn, plus 1.
+ * @y2: Lower coordinate of the rectangle to be redrawn, plus 1.
+ *
+ * Convenience function that informs a canvas that the specified rectangle needs
+ * to be repainted.  The rectangle includes @x1 and @y1, but not @x2 and @y2.  To
+ * be used only by item implementations.
+ **/
+void
+gnome_canvas_request_redraw (GnomeCanvas *canvas,
+                             gint x1,
+                             gint y1,
+                             gint x2,
+                             gint y2)
+{
+       GdkRectangle area, clip;
+
+       g_return_if_fail (GNOME_IS_CANVAS (canvas));
+
+       if (!gtk_widget_is_drawable (GTK_WIDGET (canvas)) || (x1 >= x2) || (y1 >= y2))
+               return;
+
+       area.x = x1;
+       area.y = y1;
+       area.width = x2 - x1 + 1;
+       area.height = y2 - y1 + 1;
+
+       get_visible_rect (canvas, &clip);
+       if (!gdk_rectangle_intersect (&area, &clip, &area))
+               return;
+
+       gdk_window_invalidate_rect (
+               gtk_layout_get_bin_window (GTK_LAYOUT (canvas)),
+               &area, FALSE);
+}
+
+/**
+ * gnome_canvas_w2c_matrix:
+ * @canvas: A canvas.
+ * @matrix: (out): matrix to initialize
+ *
+ * Gets the transformtion matrix that converts from world coordinates to canvas
+ * pixel coordinates.
+ **/
+void
+gnome_canvas_w2c_matrix (GnomeCanvas *canvas,
+                         cairo_matrix_t *matrix)
+{
+       g_return_if_fail (GNOME_IS_CANVAS (canvas));
+       g_return_if_fail (matrix != NULL);
+
+       cairo_matrix_init_translate (
+               matrix, -canvas->scroll_x1, -canvas->scroll_y1);
+}
+
+/**
+ * gnome_canvas_c2w_matrix:
+ * @canvas: A canvas.
+ * @matrix: (out): matrix to initialize
+ *
+ * Gets the transformtion matrix that converts from canvas pixel coordinates to
+ * world coordinates.
+ **/
+void
+gnome_canvas_c2w_matrix (GnomeCanvas *canvas,
+                         cairo_matrix_t *matrix)
+{
+       g_return_if_fail (GNOME_IS_CANVAS (canvas));
+       g_return_if_fail (matrix != NULL);
+
+       cairo_matrix_init_translate (
+               matrix, canvas->scroll_x1, canvas->scroll_y1);
+}
+
+/**
+ * gnome_canvas_w2c:
+ * @canvas: A canvas.
+ * @wx: World X coordinate.
+ * @wy: World Y coordinate.
+ * @cx: X pixel coordinate (return value).
+ * @cy: Y pixel coordinate (return value).
+ *
+ * Converts world coordinates into canvas pixel coordinates.
+ **/
+void
+gnome_canvas_w2c (GnomeCanvas *canvas,
+                  gdouble wx,
+                  gdouble wy,
+                  gint *cx,
+                  gint *cy)
+{
+       cairo_matrix_t w2c;
+
+       g_return_if_fail (GNOME_IS_CANVAS (canvas));
+
+       gnome_canvas_w2c_matrix (canvas, &w2c);
+       cairo_matrix_transform_point (&w2c, &wx, &wy);
+
+       if (cx)
+               *cx = floor (wx + 0.5);
+       if (cy)
+               *cy = floor (wy + 0.5);
+}
+
+/**
+ * gnome_canvas_w2c_d:
+ * @canvas: A canvas.
+ * @wx: World X coordinate.
+ * @wy: World Y coordinate.
+ * @cx: X pixel coordinate (return value).
+ * @cy: Y pixel coordinate (return value).
+ *
+ * Converts world coordinates into canvas pixel coordinates.  This
+ * version returns coordinates in floating point coordinates, for
+ * greater precision.
+ **/
+void
+gnome_canvas_w2c_d (GnomeCanvas *canvas,
+                    gdouble wx,
+                    gdouble wy,
+                    gdouble *cx,
+                    gdouble *cy)
+{
+       cairo_matrix_t w2c;
+
+       g_return_if_fail (GNOME_IS_CANVAS (canvas));
+
+       gnome_canvas_w2c_matrix (canvas, &w2c);
+       cairo_matrix_transform_point (&w2c, &wx, &wy);
+
+       if (cx)
+               *cx = wx;
+       if (cy)
+               *cy = wy;
+}
+
+/**
+ * gnome_canvas_c2w:
+ * @canvas: A canvas.
+ * @cx: Canvas pixel X coordinate.
+ * @cy: Canvas pixel Y coordinate.
+ * @wx: X world coordinate (return value).
+ * @wy: Y world coordinate (return value).
+ *
+ * Converts canvas pixel coordinates to world coordinates.
+ **/
+void
+gnome_canvas_c2w (GnomeCanvas *canvas,
+                  gint cx,
+                  gint cy,
+                  gdouble *wx,
+                  gdouble *wy)
+{
+       cairo_matrix_t c2w;
+       gdouble x, y;
+
+       g_return_if_fail (GNOME_IS_CANVAS (canvas));
+
+       x = cx;
+       y = cy;
+       gnome_canvas_c2w_matrix (canvas, &c2w);
+       cairo_matrix_transform_point (&c2w, &x, &y);
+
+       if (wx)
+               *wx = x;
+       if (wy)
+               *wy = y;
+}
+
+/**
+ * gnome_canvas_window_to_world:
+ * @canvas: A canvas.
+ * @winx: Window-relative X coordinate.
+ * @winy: Window-relative Y coordinate.
+ * @worldx: X world coordinate (return value).
+ * @worldy: Y world coordinate (return value).
+ *
+ * Converts window-relative coordinates into world coordinates.  You can use
+ * this when you need to convert mouse coordinates into world coordinates, for
+ * example.
+ **/
+void
+gnome_canvas_window_to_world (GnomeCanvas *canvas,
+                              gdouble winx,
+                              gdouble winy,
+                              gdouble *worldx,
+                              gdouble *worldy)
+{
+       g_return_if_fail (GNOME_IS_CANVAS (canvas));
+
+       if (worldx)
+               *worldx = canvas->scroll_x1 + (winx - canvas->zoom_xofs);
+
+       if (worldy)
+               *worldy = canvas->scroll_y1 + (winy - canvas->zoom_yofs);
+}
+
+/**
+ * gnome_canvas_world_to_window:
+ * @canvas: A canvas.
+ * @worldx: World X coordinate.
+ * @worldy: World Y coordinate.
+ * @winx: X window-relative coordinate.
+ * @winy: Y window-relative coordinate.
+ *
+ * Converts world coordinates into window-relative coordinates.
+ **/
+void
+gnome_canvas_world_to_window (GnomeCanvas *canvas,
+                              gdouble worldx,
+                              gdouble worldy,
+                              gdouble *winx,
+                              gdouble *winy)
+{
+       g_return_if_fail (GNOME_IS_CANVAS (canvas));
+
+       if (winx)
+               *winx = (worldx - canvas->scroll_x1) + canvas->zoom_xofs;
+
+       if (winy)
+               *winy = (worldy - canvas->scroll_y1) + canvas->zoom_yofs;
+}
+
+static gboolean
+boolean_handled_accumulator (GSignalInvocationHint *ihint,
+                             GValue *return_accu,
+                             const GValue *handler_return,
+                             gpointer dummy)
+{
+       gboolean continue_emission;
+       gboolean signal_handled;
+
+       signal_handled = g_value_get_boolean (handler_return);
+       g_value_set_boolean (return_accu, signal_handled);
+       continue_emission = !signal_handled;
+
+       return continue_emission;
+}
+
+/* Class initialization function for GnomeCanvasItemClass */
+static void
+gnome_canvas_item_class_init (GnomeCanvasItemClass *class)
+{
+       GObjectClass *gobject_class;
+
+       gobject_class = (GObjectClass *) class;
+
+       gobject_class->set_property = gnome_canvas_item_set_property;
+       gobject_class->get_property = gnome_canvas_item_get_property;
+
+       g_object_class_install_property (
+               gobject_class,
+               ITEM_PROP_PARENT,
+               g_param_spec_object (
+                       "parent",
+                       NULL,
+                       NULL,
+                       GNOME_TYPE_CANVAS_ITEM,
+                       G_PARAM_READABLE |
+                       G_PARAM_WRITABLE));
+
+       item_signals[ITEM_EVENT] = g_signal_new (
+               "event",
+               G_TYPE_FROM_CLASS (class),
+               G_SIGNAL_RUN_LAST,
+               G_STRUCT_OFFSET (GnomeCanvasItemClass, event),
+               boolean_handled_accumulator, NULL, NULL,
+               G_TYPE_BOOLEAN, 1,
+               GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
+
+       gobject_class->dispose = gnome_canvas_item_dispose;
+
+       class->update = gnome_canvas_item_update;
+       class->realize = gnome_canvas_item_realize;
+       class->unrealize = gnome_canvas_item_unrealize;
+       class->map = gnome_canvas_item_map;
+       class->unmap = gnome_canvas_item_unmap;
+       class->dispose = gnome_canvas_item_dispose_item;
+       class->draw = gnome_canvas_item_draw;
+       class->point = gnome_canvas_item_point;
+       class->bounds = gnome_canvas_item_bounds;
+       class->event = gnome_canvas_item_event;
+}
diff --git a/src/libgnomecanvas/gnome-canvas.h b/src/libgnomecanvas/gnome-canvas.h
new file mode 100644
index 00000000..ebd58045
--- /dev/null
+++ b/src/libgnomecanvas/gnome-canvas.h
@@ -0,0 +1,489 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: 8; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation
+ * All rights reserved.
+ *
+ * This file is part of the Gnome Library.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * published by the Free Software Foundation; either the
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * License along with the Gnome Library; see the file COPYING.LIB.  If not,
+ */
+/*
+  @NOTATION@
+ */
+/* GnomeCanvas widget - Tk-like canvas widget for Gnome
+ *
+ * GnomeCanvas is basically a port of the Tk toolkit's most excellent canvas
+ * widget.  Tk is copyrighted by the Regents of the University of California,
+ * Sun Microsystems, and other parties.
+ *
+ *
+ * Authors: Federico Mena <federico nuclecu unam mx>
+ *          Raph Levien <raph gimp org>
+ */
+
+#ifndef GNOME_CANVAS_H
+#define GNOME_CANVAS_H
+
+#include <gtk/gtk.h>
+#include <stdarg.h>
+
+G_BEGIN_DECLS
+
+/* "Small" value used by canvas stuff */
+#define GNOME_CANVAS_EPSILON 1e-10
+
+/* Macros for building colors that fit in a 32-bit integer.  The values are in
+ * [0, 255].
+ */
+
+#define GNOME_CANVAS_COLOR(r, g, b) ((((guint) (r) & 0xffu) << 24) \
+                                    | (((guint) (g) & 0xffu) << 16) \
+                                    | (((guint) (b) & 0xffu) << 8) \
+                                    | 0xffu)
+
+#define GNOME_CANVAS_COLOR_A(r, g, b, a) ((((guint) (r) & 0xffu) << 24) \
+                                         | (((guint) (g) & 0xffu) << 16) \
+                                         | (((guint) (b) & 0xffu) << 8) \
+                                         | ((guint) (a) & 0xffu))
+
+typedef struct _GnomeCanvas           GnomeCanvas;
+typedef struct _GnomeCanvasClass      GnomeCanvasClass;
+typedef struct _GnomeCanvasItem       GnomeCanvasItem;
+typedef struct _GnomeCanvasItemClass  GnomeCanvasItemClass;
+typedef struct _GnomeCanvasGroup      GnomeCanvasGroup;
+typedef struct _GnomeCanvasGroupClass GnomeCanvasGroupClass;
+
+/* GnomeCanvasItem - base item class for canvas items
+ *
+ * All canvas items are derived from GnomeCanvasItem.  The only information a
+ * GnomeCanvasItem contains is its parent canvas, its parent canvas item group,
+ * its bounding box in world coordinates, and its current affine transformation.
+ *
+ * Items inside a canvas are organized in a tree of GnomeCanvasItemGroup nodes
+ * and GnomeCanvasItem leaves.  Each canvas has a single root group, which can
+ * be obtained with the gnome_canvas_get_root() function.
+ *
+ * The abstract GnomeCanvasItem class does not have any configurable or
+ * queryable attributes.
+ */
+
+/* Object flags for items */
+typedef enum {
+       GNOME_CANVAS_ITEM_REALIZED = 1 << 0,
+       GNOME_CANVAS_ITEM_MAPPED = 1 << 1,
+       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 */
+enum {
+       GNOME_CANVAS_UPDATE_REQUESTED = 1 << 0,
+       GNOME_CANVAS_UPDATE_AFFINE = 1 << 1,
+       GNOME_CANVAS_UPDATE_CLIP = 1 << 2,
+       GNOME_CANVAS_UPDATE_VISIBILITY = 1 << 3,
+       GNOME_CANVAS_UPDATE_IS_VISIBLE = 1 << 4         /* Deprecated.  FIXME: remove this */
+};
+
+#define GNOME_TYPE_CANVAS_ITEM            (gnome_canvas_item_get_type ())
+#define GNOME_CANVAS_ITEM(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNOME_TYPE_CANVAS_ITEM, 
GnomeCanvasItem))
+#define GNOME_CANVAS_ITEM_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GNOME_TYPE_CANVAS_ITEM, 
GnomeCanvasItemClass))
+#define GNOME_IS_CANVAS_ITEM(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNOME_TYPE_CANVAS_ITEM))
+#define GNOME_IS_CANVAS_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GNOME_TYPE_CANVAS_ITEM))
+#define GNOME_CANVAS_ITEM_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GNOME_TYPE_CANVAS_ITEM, 
GnomeCanvasItemClass))
+
+struct _GnomeCanvasItem {
+       GObject object;
+
+       /* Parent canvas for this item */
+       GnomeCanvas *canvas;
+
+       /* Parent canvas group for this item (a GnomeCanvasGroup) */
+       GnomeCanvasItem *parent;
+
+       /* The transformation for this item */
+       cairo_matrix_t matrix;
+
+       /* Bounding box for this item (in canvas coordinates) */
+       gdouble x1, y1, x2, y2;
+
+       /* XXX GObject flags are sealed now, so we have to provide
+        *     our own.  This breaks ABI compatibility with upstream. */
+       GnomeCanvasItemFlags flags;
+};
+
+struct _GnomeCanvasItemClass {
+       GObjectClass parent_class;
+
+       /* Tell the item to update itself.  The flags are from the update flags
+        * defined above.  The item should update its internal state from its
+        * queued state, and recompute and request its repaint area.  The
+        * affine, if used, is a pointer to a 6-element array of doubles.  The
+        * update method also recomputes the bounding box of the item.
+        */
+       void (* update) (GnomeCanvasItem *item, const cairo_matrix_t *i2c, gint flags);
+
+       /* Realize an item -- create GCs, etc. */
+       void (* realize) (GnomeCanvasItem *item);
+
+       /* Unrealize an item */
+       void (* unrealize) (GnomeCanvasItem *item);
+
+       /* Map an item - normally only need by items with their own GdkWindows */
+       void (* map) (GnomeCanvasItem *item);
+
+       /* Unmap an item */
+       void (* unmap) (GnomeCanvasItem *item);
+
+       /* Dispose item; called inside GObject's dispose of the base class */
+       void (* dispose) (GnomeCanvasItem *item);
+
+       /* Draw an item of this type.  (x, y) are the upper-left canvas pixel
+        * coordinates of the drawable, a temporary pixmap, where things get
+        * drawn.  (width, height) are the dimensions of the 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
+         * item itself in the case of the object being an actual leaf item, or
+         * a child in case of the object being a canvas group.  (cx, cy) are
+         * the canvas pixel coordinates that correspond to the item-relative
+         * coordinates (x, y).
+        */
+       GnomeCanvasItem * (* point) (GnomeCanvasItem *item, gdouble x, gdouble y, gint cx, gint cy);
+
+       /* Fetch the item's bounding box (need not be exactly tight).  This
+        * should be in item-relative coordinates.
+        */
+       void (* bounds) (GnomeCanvasItem *item, gdouble *x1, gdouble *y1, gdouble *x2, gdouble *y2);
+
+       /* Signal: an event occurred for an item of this type.  The (x, y)
+        * coordinates are in the canvas world coordinate system.
+        */
+       gboolean (* event)                (GnomeCanvasItem *item, GdkEvent *event);
+
+       /* Reserved for future expansion */
+       gpointer spare_vmethods[4];
+};
+
+GType gnome_canvas_item_get_type (void) G_GNUC_CONST;
+
+/* Create a canvas item using the standard Gtk argument mechanism.  The item is
+ * automatically inserted at the top of the specified canvas group.  The last
+ * argument must be a NULL pointer.
+ */
+GnomeCanvasItem *gnome_canvas_item_new (GnomeCanvasGroup *parent, GType type,
+                                       const gchar *first_arg_name, ...);
+
+/* Constructors for use in derived classes and language wrappers */
+void gnome_canvas_item_construct (GnomeCanvasItem *item, GnomeCanvasGroup *parent,
+                                 const gchar *first_arg_name, va_list args);
+
+/* Configure an item using the standard Gtk argument mechanism.  The last
+ * argument must be a NULL pointer.
+ */
+void gnome_canvas_item_set (GnomeCanvasItem *item, const gchar *first_arg_name, ...) G_GNUC_NULL_TERMINATED;
+
+/* Used only for language wrappers and the like */
+void gnome_canvas_item_set_valist (GnomeCanvasItem *item,
+                                  const gchar *first_arg_name, va_list args);
+
+/* Move an item by the specified amount */
+void gnome_canvas_item_move (GnomeCanvasItem *item, gdouble dx, gdouble dy);
+
+/* Apply a relative affine transformation to the item. */
+void gnome_canvas_item_transform (GnomeCanvasItem *item, const cairo_matrix_t *matrix);
+
+/* Apply an absolute affine transformation to the item. */
+void gnome_canvas_item_set_matrix (GnomeCanvasItem *item, const cairo_matrix_t *matrix);
+
+/* Raise an item in the z-order of its parent group by the specified number of
+ * positions.
+ */
+void gnome_canvas_item_raise (GnomeCanvasItem *item, gint positions);
+
+/* Lower an item in the z-order of its parent group by the specified number of
+ * positions.
+ */
+void gnome_canvas_item_lower (GnomeCanvasItem *item, gint positions);
+
+/* Raise an item to the top of its parent group's z-order. */
+void gnome_canvas_item_raise_to_top (GnomeCanvasItem *item);
+
+/* Lower an item to the bottom of its parent group's z-order */
+void gnome_canvas_item_lower_to_bottom (GnomeCanvasItem *item);
+
+/* Show an item (make it visible).  If the item is already shown, it has no
+ * effect.
+ */
+void gnome_canvas_item_show (GnomeCanvasItem *item);
+
+/* Hide an item (make it invisible).  If the item is already invisible, it has
+ * no effect.
+ */
+void gnome_canvas_item_hide (GnomeCanvasItem *item);
+
+/* Grab the mouse for the specified item.  Only the events in event_mask will be
+ * reported.  If cursor is non-NULL, it will be used during the duration of the
+ * grab.  Time is a proper X event time parameter.  Returns the same values as
+ * XGrabPointer().
+ */
+gint gnome_canvas_item_grab (GnomeCanvasItem *item, guint event_mask,
+                           GdkCursor *cursor, GdkDevice *device,
+                           guint32 etime);
+
+/* Ungrabs the mouse -- the specified item must be the same that was passed to
+ * gnome_canvas_item_grab().  Time is a proper X event time parameter.
+ */
+void gnome_canvas_item_ungrab (GnomeCanvasItem *item, guint32 etime);
+
+/* These functions convert from a coordinate system to another.  "w" is world
+ * coordinates and "i" is item coordinates.
+ */
+void gnome_canvas_item_w2i (GnomeCanvasItem *item, gdouble *x, gdouble *y);
+void gnome_canvas_item_i2w (GnomeCanvasItem *item, gdouble *x, gdouble *y);
+
+/* Gets the affine transform that converts from item-relative coordinates to
+ * world coordinates.
+ */
+void gnome_canvas_item_i2w_matrix (GnomeCanvasItem *item, cairo_matrix_t *matrix);
+void gnome_canvas_item_w2i_matrix (GnomeCanvasItem *item, cairo_matrix_t *matrix);
+
+/* Gets the affine transform that converts from item-relative coordinates to
+ * canvas pixel coordinates.
+ */
+void gnome_canvas_item_i2c_matrix (GnomeCanvasItem *item, cairo_matrix_t *matrix);
+
+/* Remove the item from its parent group and make the new group its parent.  The
+ * item will be put on top of all the items in the new group.  The item's
+ * coordinates relative to its new parent to *not* change -- this means that the
+ * item could potentially move on the screen.
+ *
+ * The item and the group must be in the same canvas.  An item cannot be
+ * reparented to a group that is the item itself or that is an inferior of the
+ * item.
+ */
+void gnome_canvas_item_reparent (GnomeCanvasItem *item, GnomeCanvasGroup *new_group);
+
+/* Used to send all of the keystroke events to a specific item as well as
+ * GDK_FOCUS_CHANGE events.
+ */
+void gnome_canvas_item_grab_focus (GnomeCanvasItem *item);
+
+/* Fetch the bounding box of the item.  The bounding box may not be exactly
+ * tight, but the canvas items will do the best they can.  The returned bounding
+ * box is in the coordinate system of the item's parent.
+ */
+void gnome_canvas_item_get_bounds (GnomeCanvasItem *item,
+                                  gdouble *x1, gdouble *y1, gdouble *x2, gdouble *y2);
+
+/* Request that the update method eventually get called.  This should be used
+ * only by item implementations.
+ */
+void gnome_canvas_item_request_update (GnomeCanvasItem *item);
+
+/* GnomeCanvasGroup - a group of canvas items
+ *
+ * A group is a node in the hierarchical tree of groups/items inside a canvas.
+ * Groups serve to give a logical structure to the items.
+ *
+ * Consider a circuit editor application that uses the canvas for its schematic
+ * display.  Hierarchically, there would be canvas groups that contain all the
+ * components needed for an "adder", for example -- this includes some logic
+ * gates as well as wires.  You can move stuff around in a convenient way by
+ * doing a gnome_canvas_item_move() of the hierarchical groups -- to move an
+ * adder, simply move the group that represents the adder.
+ *
+ * The following arguments are available:
+ *
+ * name                type            read/write      description
+ * --------------------------------------------------------------------------------
+ * x           gdouble         RW              X coordinate of group's origin
+ * y           gdouble         RW              Y coordinate of group's origin
+ */
+
+#define GNOME_TYPE_CANVAS_GROUP            (gnome_canvas_group_get_type ())
+#define GNOME_CANVAS_GROUP(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNOME_TYPE_CANVAS_GROUP, 
GnomeCanvasGroup))
+#define GNOME_CANVAS_GROUP_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GNOME_TYPE_CANVAS_GROUP, 
GnomeCanvasGroupClass))
+#define GNOME_IS_CANVAS_GROUP(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNOME_TYPE_CANVAS_GROUP))
+#define GNOME_IS_CANVAS_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GNOME_TYPE_CANVAS_GROUP))
+#define GNOME_CANVAS_GROUP_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GNOME_TYPE_CANVAS_GROUP, 
GnomeCanvasGroupClass))
+
+struct _GnomeCanvasGroup {
+       GnomeCanvasItem item;
+
+       /* Children of the group */
+       GList *item_list;
+       GList *item_list_end;
+};
+
+struct _GnomeCanvasGroupClass {
+       GnomeCanvasItemClass parent_class;
+};
+
+GType gnome_canvas_group_get_type (void) G_GNUC_CONST;
+
+/*** GnomeCanvas ***/
+
+#define GNOME_TYPE_CANVAS            (gnome_canvas_get_type ())
+#define GNOME_CANVAS(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNOME_TYPE_CANVAS, GnomeCanvas))
+#define GNOME_CANVAS_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GNOME_TYPE_CANVAS, GnomeCanvasClass))
+#define GNOME_IS_CANVAS(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNOME_TYPE_CANVAS))
+#define GNOME_IS_CANVAS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GNOME_TYPE_CANVAS))
+#define GNOME_CANVAS_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GNOME_TYPE_CANVAS, GnomeCanvasClass))
+
+struct _GnomeCanvas {
+       GtkLayout layout;
+
+       /* Root canvas group */
+       GnomeCanvasItem *root;
+
+       /* The item containing the mouse pointer, or NULL if none */
+       GnomeCanvasItem *current_item;
+
+       /* Item that is about to become current (used to track deletions and such) */
+       GnomeCanvasItem *new_current_item;
+
+       /* Item that holds a pointer grab, or NULL if none */
+       GnomeCanvasItem *grabbed_item;
+
+       /* The grabbed device for grabbed_item. */
+       GdkDevice *grabbed_device;
+
+       /* If non-NULL, the currently focused item */
+       GnomeCanvasItem *focused_item;
+
+       /* Event on which selection of current item is based */
+       GdkEvent pick_event;
+
+       /* Scrolling region */
+       gdouble scroll_x1, scroll_y1;
+       gdouble scroll_x2, scroll_y2;
+
+       /* Idle handler ID */
+       guint idle_id;
+
+       /* Offsets of the temprary drawing pixmap */
+       gint draw_xofs, draw_yofs;
+
+       /* Internal pixel offsets when zoomed out */
+       gint zoom_xofs, zoom_yofs;
+
+       /* Last known modifier state, for deferred repick when a button is down */
+       gint state;
+
+       /* Event mask specified when grabbing an item */
+       guint grabbed_event_mask;
+
+       /* Whether items need update at next idle loop iteration */
+       guint need_update : 1;
+
+       /* Whether current item will be repicked at next idle loop iteration */
+       guint need_repick : 1;
+
+       /* For use by internal pick_current_item() function */
+       guint left_grabbed_item : 1;
+
+       /* For use by internal pick_current_item() function */
+       guint in_repick : 1;
+};
+
+struct _GnomeCanvasClass {
+       GtkLayoutClass parent_class;
+
+       /* Draw the background for the area given. This method is only used
+        * for non-antialiased canvases.
+        */
+       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 */
+       void (* request_update) (GnomeCanvas *canvas);
+
+       /* Reserved for future expansion */
+       gpointer spare_vmethods[4];
+};
+
+GType gnome_canvas_get_type (void) G_GNUC_CONST;
+
+/* Creates a new canvas.  You should check that the canvas is created with the
+ * proper visual and colormap.  Any visual will do unless you intend to insert
+ * gdk_imlib images into it, in which case you should use the gdk_imlib visual.
+ *
+ * You should call gnome_canvas_set_scroll_region() soon after calling this
+ * function to set the desired scrolling limits for the canvas.
+ */
+GtkWidget *gnome_canvas_new (void);
+
+/* Returns the root canvas item group of the canvas */
+GnomeCanvasGroup *gnome_canvas_root (GnomeCanvas *canvas);
+
+/* Sets the limits of the scrolling region, in world coordinates */
+void gnome_canvas_set_scroll_region (GnomeCanvas *canvas,
+                                    gdouble x1, gdouble y1, gdouble x2, gdouble y2);
+
+/* Gets the limits of the scrolling region, in world coordinates */
+void gnome_canvas_get_scroll_region (GnomeCanvas *canvas,
+                                    gdouble *x1, gdouble *y1, gdouble *x2, gdouble *y2);
+
+/* Scrolls the canvas to the specified offsets, given in canvas pixel coordinates */
+void gnome_canvas_scroll_to (GnomeCanvas *canvas, gint cx, gint cy);
+
+/* Returns the scroll offsets of the canvas in canvas pixel coordinates.  You
+ * can specify NULL for any of the values, in which case that value will not be
+ * queried.
+ */
+void gnome_canvas_get_scroll_offsets (GnomeCanvas *canvas, gint *cx, gint *cy);
+
+/* Returns the item that is at the specified position in world coordinates, or
+ * NULL if no item is there.
+ */
+GnomeCanvasItem *gnome_canvas_get_item_at (GnomeCanvas *canvas, gdouble x, gdouble y);
+
+/* For use only by item type implementations.  Request that the canvas
+ * eventually redraw the specified region, specified in canvas pixel
+ * coordinates.  The region contains (x1, y1) but not (x2, y2).
+ */
+void gnome_canvas_request_redraw (GnomeCanvas *canvas, gint x1, gint y1, gint x2, gint y2);
+
+/* Gets the affine transform that converts world coordinates into canvas pixel
+ * coordinates.
+ */
+void gnome_canvas_w2c_matrix (GnomeCanvas *canvas, cairo_matrix_t *matrix);
+void gnome_canvas_c2w_matrix (GnomeCanvas *canvas, cairo_matrix_t *matrix);
+
+/* These functions convert from a coordinate system to another.  "w" is world
+ * coordinates, "c" is canvas pixel coordinates (pixel coordinates that are
+ * (0,0) for the upper-left scrolling limit and something else for the
+ * lower-left scrolling limit).
+ */
+void gnome_canvas_w2c (GnomeCanvas *canvas, gdouble wx, gdouble wy, gint *cx, gint *cy);
+void gnome_canvas_w2c_d (GnomeCanvas *canvas, gdouble wx, gdouble wy, gdouble *cx, gdouble *cy);
+void gnome_canvas_c2w (GnomeCanvas *canvas, gint cx, gint cy, gdouble *wx, gdouble *wy);
+
+/* This function takes in coordinates relative to the GTK_LAYOUT
+ * (canvas)->bin_window and converts them to world coordinates.
+ */
+void gnome_canvas_window_to_world (GnomeCanvas *canvas,
+                                  gdouble winx, gdouble winy, gdouble *worldx, gdouble *worldy);
+
+/* This is the inverse of gnome_canvas_window_to_world() */
+void gnome_canvas_world_to_window (GnomeCanvas *canvas,
+                                  gdouble worldx, gdouble worldy, gdouble *winx, gdouble *winy);
+
+G_END_DECLS
+
+#endif
diff --git a/src/libgnomecanvas/libgnomecanvas.h b/src/libgnomecanvas/libgnomecanvas.h
new file mode 100644
index 00000000..028afbed
--- /dev/null
+++ b/src/libgnomecanvas/libgnomecanvas.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation
+ * All rights reserved.
+ *
+ * This file is part of the Gnome Library.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * published by the Free Software Foundation; either the
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * License along with the Gnome Library; see the file COPYING.LIB.  If not,
+ */
+/*
+  @NOTATION@
+ */
+
+#ifndef LIBGNOMECANVAS_H
+#define LIBGNOMECANVAS_H
+
+#include <libgnomecanvas/gnome-canvas.h>
+#include <libgnomecanvas/gnome-canvas-text.h>
+#include <libgnomecanvas/gnome-canvas-pixbuf.h>
+#include <libgnomecanvas/gnome-canvas-widget.h>
+#include <libgnomecanvas/gnome-canvas-rect.h>
+#include <libgnomecanvas/gnome-canvas-util.h>
+
+#endif /* LIBGNOMECANVAS_H */


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