Deleting a GnomeCanvasItem

I can't seem to find any references in the online documetation on how
to do this.  I am loading a GdkPixbuf into a canvas as shown in the
callback below.  This gets invoked just after a file selection widget
is closed and the new file is added to an internal list of files.  I
create a new GdkPixbuf and then add a new item.  The canvas will only
ever have one item; how do I find the old one and delete it?  I'm a
little fuzzy on what gnome_canvas_item_new is doing; am I naming the
item "pixbuf" and if so, does creating a new item with the same name
implicitly destroy the old one?

show_image (gint index)
   GdkPixbuf *pixbuf;

   if (index >= files.max_files)
      /* Complain and return. */
      g_message ("show_image(%d) out of range (max_files=%d)\n",
		 index, files.max_files);
   pixbuf = gdk_pixbuf_new_from_file (files.file[index].name);

   if (!pixbuf) {
      g_message ("Could not load the image (%s)!", files.file[index].name);
   } else {
      GnomeCanvasItem *item;
      GtkWidget *canvas;

      /* Find the canvas so we can add an item to it.  */
      canvas = lookup_widget (GTK_WIDGET (aip_window), "canvas");
      /* Add the pixbuf to the scrolled window. */
      item = gnome_canvas_item_new (gnome_canvas_root (GNOME_CANVAS(canvas)),
				    "pixbuf", pixbuf,

      /* Make the scroll region only as big as the image itself. */
      gnome_canvas_set_scroll_region(GNOME_CANVAS(canvas), 0, 0,

      /* Free the GdkPixbuf. */
      gdk_pixbuf_unref (pixbuf);

		       PGP Key ID: 66 BC 3B CD
Roland B. Roberts, PhD                             RL Enterprises
roland rlenter com                     76-15 113th Street, Apt 3B
rbroberts acm org                          Forest Hills, NY 11375

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