gnumeric-simple-canvas.c 1.79 KB
Newer Older
Jody Goldberg's avatar
Jody Goldberg committed
1
/* vim: set sw=8: */
2 3
#include <gnumeric-config.h>
#include "gnumeric.h"
Jody Goldberg's avatar
Jody Goldberg committed
4
#include "gnumeric-simple-canvas.h"
5

Jody Goldberg's avatar
Jody Goldberg committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
#include "sheet-control-gui-priv.h"
#include <gal/util/e-util.h>

static GtkWidgetClass const *parent;
static gint
gnm_simple_canvas_key_press (GtkWidget *widget, GdkEventKey *event)
{
	GnmSimpleCanvas *gcanvas = GNM_SIMPLE_CANVAS (widget);

	if (gcanvas->scg->grab_stack > 0)
		return TRUE;
	return parent->key_press_event (widget, event);
}

static gint
gnm_simple_canvas_key_release (GtkWidget *widget, GdkEventKey *event)
{
	GnmSimpleCanvas *gcanvas = GNM_SIMPLE_CANVAS (widget);

	if (gcanvas->scg->grab_stack > 0)
		return TRUE;
	return parent->key_release_event (widget, event);
}

static void
gnm_simple_canvas_class_init (GtkWidgetClass *klass)
{
	parent = gtk_type_class (gnome_canvas_get_type ());

Jody Goldberg's avatar
Jody Goldberg committed
35 36
	klass->key_press_event	 = gnm_simple_canvas_key_press;
	klass->key_release_event = gnm_simple_canvas_key_release;
Jody Goldberg's avatar
Jody Goldberg committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
}

E_MAKE_TYPE (gnm_simple_canvas, "GnmSimpleCanvas", GnmSimpleCanvas,
	     gnm_simple_canvas_class_init, NULL,
	     GNOME_TYPE_CANVAS);

GnomeCanvas *
gnm_simple_canvas_new (SheetControlGUI *scg)
{
	GnmSimpleCanvas *gcanvas = gtk_type_new (gnm_simple_canvas_get_type ());
	gcanvas->scg = scg;
	return GNOME_CANVAS (gcanvas);
}

void
gnm_simple_canvas_ungrab (GnomeCanvasItem *item, guint32 etime)
{
	GnmSimpleCanvas *gcanvas = GNM_SIMPLE_CANVAS(item->canvas);

	g_return_if_fail (gcanvas != NULL);

	gcanvas->scg->grab_stack--;
	gnome_canvas_item_ungrab (item, etime);
}

int
gnm_simple_canvas_grab (GnomeCanvasItem *item, unsigned int event_mask,
			GdkCursor *cursor, guint32 etime)
{
	GnmSimpleCanvas *gcanvas = GNM_SIMPLE_CANVAS(item->canvas);

	g_return_val_if_fail (gcanvas != NULL, TRUE);

	gcanvas->scg->grab_stack++;
	return gnome_canvas_item_grab (item, event_mask, cursor, etime);
}