gnumeric-canvas.c 2.56 KB
Newer Older
1
#include <config.h>
2 3 4 5

#include <gnome.h>
#include "gnumeric.h"
#include "gnumeric-sheet.h"
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

/* Signals emited by the Gnumeric Sheet widget */
enum {
	GNUMERIC_SHEET_LAST_SIGNAL
};

static guint sheet_signals [GNUMERIC_SHEET_LAST_SIGNAL] = { 0 };

static GnomeCanvasClass *sheet_parent_class;

static void
gnumeric_sheet_destroy (GtkObject *object)
{
	GnumericSheet *gsheet;

	/* Add shutdown code here */
Arturo Espinosa's avatar
Arturo Espinosa committed
22 23
	gsheet = GNUMERIC_SHEET (object);
	
24 25 26 27
	if (GTK_OBJECT_CLASS (sheet_parent_class)->destroy)
		(*GTK_OBJECT_CLASS (sheet_parent_class)->destroy)(object);
}

Arturo Espinosa's avatar
Arturo Espinosa committed
28 29
static GnumericSheet *
gnumeric_sheet_create (Sheet *sheet)
Arturo Espinosa's avatar
Arturo Espinosa committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
{
	GnumericSheet *gsheet;
	GnomeCanvas   *canvas;
	
	gsheet = gtk_type_new (gnumeric_sheet_get_type ());
	canvas = GNOME_CANVAS (gsheet);

	canvas->visual = gtk_widget_get_default_visual ();
	canvas->colormap = gtk_widget_get_default_colormap ();
	canvas->cc   = gdk_color_context_new (canvas->visual, canvas->colormap);
	canvas->root = gnome_canvas_group_new (canvas);
	
	gsheet->sheet   = sheet;
	gsheet->top_col = 0;
	gsheet->top_row = 0;

Arturo Espinosa's avatar
Arturo Espinosa committed
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
	return gsheet;
}

GtkWidget *
gnumeric_sheet_new (Sheet *sheet)
{
	GnumericSheet *gsheet;
	
	gsheet = gnumeric_sheet_create (sheet);
	gnome_canvas_set_size (GNOME_CANVAS (gsheet), 300, 100);
	
	gsheet->item_grid = ITEM_GRID (gnome_canvas_item_new (
		GNOME_CANVAS (gsheet),
		GNOME_CANVAS_GROUP (GNOME_CANVAS(gsheet)->root),
		item_grid_get_type (),
		NULL));
Arturo Espinosa's avatar
Arturo Espinosa committed
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
	return GTK_WIDGET (gsheet);
}

static void
gnumeric_sheet_class_init (GnumericSheetClass *class)
{
	GtkObjectClass *object_class;
	GtkWidgetClass *widget_class;
	GnomeCanvasClass *canvas_class;

	object_class = (GtkObjectClass *) class;
	widget_class = (GtkWidgetClass *) class;
	canvas_class = (GnomeCanvasClass *) class;
	
	sheet_parent_class = gtk_type_class (gnome_canvas_get_type());

	/* Method override */
	object_class->destroy = gnumeric_sheet_destroy;
}

Arturo Espinosa's avatar
Arturo Espinosa committed
82 83 84 85 86 87 88 89 90
static void
gnumeric_sheet_init (GnumericSheet *gsheet)
{
	GnomeCanvas *canvas = GNOME_CANVAS (gsheet);

	printf ("idel_id=%d\n", canvas->idle_id);
	printf ("pixs=%g\n", canvas->pixels_per_unit);
}

91 92 93 94 95 96 97 98 99 100 101
GtkType
gnumeric_sheet_get_type (void)
{
	static GtkType gnumeric_sheet_type = 0;

	if (!gnumeric_sheet_type){
		GtkTypeInfo gnumeric_sheet_info = {
			"GnumericSheet",
			sizeof (GnumericSheet),
			sizeof (GnumericSheetClass),
			(GtkClassInitFunc) gnumeric_sheet_class_init,
Arturo Espinosa's avatar
Arturo Espinosa committed
102
			(GtkObjectInitFunc) gnumeric_sheet_init,
103 104 105 106 107
			NULL, /* reserved 1 */
			NULL, /* reserved 2 */
			(GtkClassInitFunc) NULL
		};

Arturo Espinosa's avatar
Arturo Espinosa committed
108
		gnumeric_sheet_type = gtk_type_unique (gnome_canvas_get_type (), &gnumeric_sheet_info);
109 110 111 112 113
	}

	return gnumeric_sheet_type;
}