Implementing gnome canvas items



HI,

I'm trying to implement a "background item" for the canvas which is invisible,
but catches all events on the background. I need it so I can change the
behaviour of the normal canvas event handling (which is to catch all events,
whether or not they are caught by an item). Unfortunatly, my new item doesn't
catch any event. I can't figure out why. I just took the image item and stripped
out all the rendering code... while making my new item "infinite". I'm sending
the code in attachment. Does anyone have an idea of what I did wrong?

Thanks, 


-- 
Jean-Marc Valin
Universite de Sherbrooke - Genie Electrique
valj01@gel.usherb.ca
/* Image 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.
 *
 * Copyright (C) 1998 The Free Software Foundation
 *
 * Author: Federico Mena <federico@nuclecu.unam.mx>
 */

#include "canvas-background.h"




static void gnome_canvas_background_class_init (GnomeCanvasBackgroundClass *class);
static void gnome_canvas_background_init       (GnomeCanvasBackground      *background);
static void gnome_canvas_background_destroy    (GtkObject             *object);
static void gnome_canvas_background_set_arg    (GtkObject             *object,
					   GtkArg                *arg,
					   guint                  arg_id);
static void gnome_canvas_background_get_arg    (GtkObject             *object,
					   GtkArg                *arg,
					   guint                  arg_id);

static void   gnome_canvas_background_update      (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags);
static void   gnome_canvas_background_realize     (GnomeCanvasItem *item);
static void   gnome_canvas_background_unrealize   (GnomeCanvasItem *item);
static void   gnome_canvas_background_draw        (GnomeCanvasItem *item, GdkDrawable *drawable,
					      int x, int y, int width, int height);
static double gnome_canvas_background_point       (GnomeCanvasItem *item, double x, double y,
					      int cx, int cy, GnomeCanvasItem **actual_item);
static void   gnome_canvas_background_translate   (GnomeCanvasItem *item, double dx, double dy);
static void   gnome_canvas_background_bounds      (GnomeCanvasItem *item, double *x1, double *y1, double *x2, double *y2);
static void   gnome_canvas_background_render      (GnomeCanvasItem *item, GnomeCanvasBuf *buf);

//static ArtPixBuf * pixbuf_from_imlib_background (GdkImlibBackground *im);

static GnomeCanvasItemClass *parent_class;


GtkType
gnome_canvas_background_get_type (void)
{
	static GtkType background_type = 0;

	if (!background_type) {
		GtkTypeInfo background_info = {
			"GnomeCanvasBackground",
			sizeof (GnomeCanvasBackground),
			sizeof (GnomeCanvasBackgroundClass),
			(GtkClassInitFunc) gnome_canvas_background_class_init,
			(GtkObjectInitFunc) gnome_canvas_background_init,
			NULL, /* reserved_1 */
			NULL, /* reserved_2 */
			(GtkClassInitFunc) NULL
		};

		background_type = gtk_type_unique (gnome_canvas_item_get_type (), &background_info);
	}

	return background_type;
}

static void
gnome_canvas_background_class_init (GnomeCanvasBackgroundClass *class)
{
	GtkObjectClass *object_class;
	GnomeCanvasItemClass *item_class;

	object_class = (GtkObjectClass *) class;
	item_class = (GnomeCanvasItemClass *) class;

	parent_class = gtk_type_class (gnome_canvas_item_get_type ());


	object_class->destroy = gnome_canvas_background_destroy;
	object_class->set_arg = gnome_canvas_background_set_arg;
	object_class->get_arg = gnome_canvas_background_get_arg;

	item_class->update = gnome_canvas_background_update;
	item_class->realize = gnome_canvas_background_realize;
	item_class->unrealize = gnome_canvas_background_unrealize;
	item_class->draw = gnome_canvas_background_draw;
	item_class->point = gnome_canvas_background_point;
	item_class->translate = gnome_canvas_background_translate;
	item_class->bounds = gnome_canvas_background_bounds;
	item_class->render = gnome_canvas_background_render;


}

static void
gnome_canvas_background_init (GnomeCanvasBackground *background)
{
   GnomeCanvasItem *item;

   item = GNOME_CANVAS_ITEM(background);
   item->x1 = -10000;
   item->y1 = -10000;
   item->x2 =  10000;
   item->y2 =  10000;
}

static void gnome_canvas_background_destroy (GtkObject *object)
{
   //GnomeCanvasBackground *background;

        g_return_if_fail (object != NULL);
        g_return_if_fail (GNOME_IS_CANVAS_BACKGROUND (object));

        //background = GNOME_CANVAS_IMAGE (object);


        if (GTK_OBJECT_CLASS (parent_class)->destroy)
                (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
}


static void
gnome_canvas_background_set_arg (GtkObject *object, GtkArg *arg, guint arg_id)
{

}

static void
gnome_canvas_background_get_arg (GtkObject *object, GtkArg *arg, guint arg_id)
{

}

static void
gnome_canvas_background_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags)
{
if (parent_class->update)
                (* parent_class->update) (item, affine, clip_path, flags);

}

static void
gnome_canvas_background_realize (GnomeCanvasItem *item)
{
	GnomeCanvasBackground *background;

	background = GNOME_CANVAS_BACKGROUND (item);

	if (parent_class->realize)
		(* parent_class->realize) (item);

//	if (!item->canvas->aa)
//		background->gc = gdk_gc_new (item->canvas->layout.bin_window);
}

static void
gnome_canvas_background_unrealize (GnomeCanvasItem *item)
{
	GnomeCanvasBackground *background;

	background = GNOME_CANVAS_BACKGROUND (item);

	if (parent_class->unrealize)
		(* parent_class->unrealize) (item);
}



static void
gnome_canvas_background_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
			 int x, int y, int width, int height)
{

}


static void
gnome_canvas_background_translate (GnomeCanvasItem *item, double dx, double dy)
{
}

static void
gnome_canvas_background_bounds (GnomeCanvasItem *item, double *x1, double *y1, double *x2, double *y2)
{
   *x1 = -10000000;
   *y1 = -10000000;
   *x2 =  10000000;
   *y2 =  10000000;
}

static double
gnome_canvas_background_point (GnomeCanvasItem *item, double x, double y,
                          int cx, int cy, GnomeCanvasItem **actual_item)
{
   return 0.0;
}


static void   gnome_canvas_background_render      (GnomeCanvasItem *item, GnomeCanvasBuf *buf)
{
}
/* Image 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.
 *
 * Copyright (C) 1998 The Free Software Foundation
 *
 * Author: Federico Mena <federico@nuclecu.unam.mx>
 */

#ifndef GNOME_CANVAS_BACKGROUND_H
#define GNOME_CANVAS_BACKGROUND_H

#include <gnome.h>


BEGIN_GNOME_DECLS




#define GNOME_TYPE_CANVAS_BACKGROUND            (gnome_canvas_background_get_type ())
#define GNOME_CANVAS_BACKGROUND(obj)            (GTK_CHECK_CAST ((obj), GNOME_TYPE_CANVAS_BACKGROUND, GnomeCanvasBackground))
#define GNOME_CANVAS_BACKGROUND_CLASS(klass)    (GTK_CHECK_CLASS_CAST ((klass), GNOME_TYPE_CANVAS_BACKGROUND, GnomeCanvasBackgroundClass))
#define GNOME_IS_CANVAS_BACKGROUND(obj)         (GTK_CHECK_TYPE ((obj), GNOME_TYPE_CANVAS_BACKGROUND))
#define GNOME_IS_CANVAS_BACKGROUND_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GNOME_TYPE_CANVAS_BACKGROUND))


typedef struct _GnomeCanvasBackground GnomeCanvasBackground;
typedef struct _GnomeCanvasBackgroundClass GnomeCanvasBackgroundClass;

struct _GnomeCanvasBackground {
	GnomeCanvasItem item;
};

struct _GnomeCanvasBackgroundClass {
	GnomeCanvasItemClass parent_class;
};


/* Standard Gtk function */
GtkType gnome_canvas_background_get_type (void);


END_GNOME_DECLS

#endif


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