Commit 809d8e5e authored by Miguel de Icaza's avatar Miguel de Icaza Committed by Arturo Espinosa

SheetObjects are now GtkObjects, this is an abstract class.


SheetObjects are now GtkObjects, this is an abstract class.
SheetObjectGraphics includes the graphic objects we had before.
SheetObjectObject will be the Bonobo objects.

PLUG AND PLAY TIME!

Miguel.

1999-04-13  Miguel de Icaza  <miguel@nuclecu.unam.mx>

	* src/sheet-object.c: Converted SheetObject to a Gtk+ object.
	Splitted the functionality of the SheetObject into classes:
	SheetObject abstract class;  SheetObjectGraphic for simple drawings;
	SheetObjectFilled for objects that have a fill attribute.

	* src/sheet-object-graphic.c: Implement the SheetObjectGraphic and
	SheetObjectFilled objects.
parent 7c08fe2a
1999-04-13 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet-object.c: Converted SheetObject to a Gtk+ object.
Splitted the functionality of the SheetObject into classes:
SheetObject abstract class; SheetObjectGraphic for simple drawings;
SheetObjectFilled for objects that have a fill attribute.
* src/sheet-object-graphic.c: Implement the SheetObjectGraphic and
SheetObjectFilled objects.
1999-04-13 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/xml-io.c (xml_probe): Do not crash if the file is a broken
......
1999-04-13 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet-object.c: Converted SheetObject to a Gtk+ object.
Splitted the functionality of the SheetObject into classes:
SheetObject abstract class; SheetObjectGraphic for simple drawings;
SheetObjectFilled for objects that have a fill attribute.
* src/sheet-object-graphic.c: Implement the SheetObjectGraphic and
SheetObjectFilled objects.
1999-04-13 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/xml-io.c (xml_probe): Do not crash if the file is a broken
......
1999-04-13 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet-object.c: Converted SheetObject to a Gtk+ object.
Splitted the functionality of the SheetObject into classes:
SheetObject abstract class; SheetObjectGraphic for simple drawings;
SheetObjectFilled for objects that have a fill attribute.
* src/sheet-object-graphic.c: Implement the SheetObjectGraphic and
SheetObjectFilled objects.
1999-04-13 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/xml-io.c (xml_probe): Do not crash if the file is a broken
......
1999-04-13 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet-object.c: Converted SheetObject to a Gtk+ object.
Splitted the functionality of the SheetObject into classes:
SheetObject abstract class; SheetObjectGraphic for simple drawings;
SheetObjectFilled for objects that have a fill attribute.
* src/sheet-object-graphic.c: Implement the SheetObjectGraphic and
SheetObjectFilled objects.
1999-04-13 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/xml-io.c (xml_probe): Do not crash if the file is a broken
......
......@@ -117,7 +117,13 @@ AM_CONDITIONAL(WITH_PYTHON, $python_val)
dnl ******************************
dnl Check for Bonobo
dnl ******************************
AM_PATH_BONOBO(0.1.0, [AC_DEFINE(ENABLE_BONOBO)])
AM_PATH_BONOBO(0.1.0, [
AC_DEFINE(ENABLE_BONOBO)
have_bonobo=true
],[
have_bonobo=false
])
AM_CONDITIONAL(BONOBO, $have_bonobo)
AC_OUTPUT([
gnumeric.spec
......
......@@ -2,7 +2,11 @@
# -Wshadow -Wpointer-arith \
# -Wmissing-prototypes -Wmissing-declarations
bin_PROGRAMS = gnumeric gnumeric-corba
if BONOBO
bin_PROGRAMS = gnumeric-bonobo
else
bin_PROGRAMS = gnumeric-corba gnumeric
endif
#noinst_PROGRAMS = number-match
......@@ -97,6 +101,8 @@ GNUMERIC_BASE_SOURCES = \
sheet-autofill.h \
sheet-object.c \
sheet-object.h \
sheet-object-graphic.c \
sheet-object-graphic.h \
sheet-view.c \
sheet-view.h \
solver-lp.c \
......@@ -140,7 +146,6 @@ gnumeric_corba_SOURCES = \
$(GNUMERIC_BASE_SOURCES)
gnumeric_LDFLAGS = -export-dynamic
gnumeric_corba_LDFLAGS = $(gnumeric_LDFLAGS)
gnumeric_LDADD = \
../plugins/excel/libexcel.a \
......@@ -150,7 +155,16 @@ gnumeric_LDADD = \
$(GUILE_LIBS) \
$(INTLLIBS)
gnumeric_corba_LDADD = $(gnumeric_LDADD) $(GNOMEGNORBA_LIBS) $(BONOBO_LIBS)
gnumeric_corba_LDADD = \
$(gnumeric_LDADD) \
$(GNOMEGNORBA_LIBS)
gnumeric_bonobo_LDADD = \
../plugins/excel/libexcel.a \
$(BONOBO_LIBS) \
$(GNOME_XML_LIB) \
$(GUILE_LIBS) \
$(INTLLIBS)
wc:
......
......@@ -801,7 +801,7 @@ gnumeric_sheet_key_mode_object (GnumericSheet *gsheet, GdkEventKey *event)
case GDK_BackSpace:
case GDK_Delete:
sheet_object_destroy (sheet->current_object);
gtk_object_destroy (GTK_OBJECT (sheet->current_object));
sheet_set_mode_type (sheet, SHEET_MODE_SHEET);
break;
......
......@@ -801,7 +801,7 @@ gnumeric_sheet_key_mode_object (GnumericSheet *gsheet, GdkEventKey *event)
case GDK_BackSpace:
case GDK_Delete:
sheet_object_destroy (sheet->current_object);
gtk_object_destroy (GTK_OBJECT (sheet->current_object));
sheet_set_mode_type (sheet, SHEET_MODE_SHEET);
break;
......
/*
* sheet-object-graphic.c: Implements the drawing object manipulation for Gnumeric
*
* Author:
* Miguel de Icaza (miguel@kernel.org)
*/
#include <config.h>
#include <gnome.h>
#include <gdk/gdkkeysyms.h>
#include "gnumeric.h"
#include "gnumeric-util.h"
#include "gnumeric-sheet.h"
#include "dialogs.h"
#include "sheet-object-graphic.h"
#include "cursors.h"
static SheetObject *sheet_object_graphic_parent_class;
static SheetObjectGraphic *sheet_object_filled_parent_class;
static void
sheet_object_graphic_destroy (GtkObject *object)
{
SheetObjectGraphic *sog = SHEET_OBJECT_GRAPHIC (object);
string_unref (sog->color);
GTK_OBJECT_CLASS (sheet_object_graphic_parent_class)->destroy(object);
}
static GnomeCanvasItem *
sheet_object_graphic_realize (SheetObject *so, SheetView *sheet_view)
{
SheetObjectGraphic *sog = SHEET_OBJECT_GRAPHIC (so);
GnomeCanvasItem *item = NULL;
g_return_val_if_fail (so != NULL, NULL);
g_return_val_if_fail (sheet_view != NULL, NULL);
switch (sog->type){
case SHEET_OBJECT_LINE:
item = gnome_canvas_item_new (
sheet_view->object_group,
gnome_canvas_line_get_type (),
"points", so->points,
"fill_color", sog->color->str,
"width_pixels", sog->width,
NULL);
break;
case SHEET_OBJECT_ARROW:
item = gnome_canvas_item_new (
sheet_view->object_group,
gnome_canvas_line_get_type (),
"points", so->points,
"fill_color", sog->color->str,
"width_pixels", sog->width,
"arrow_shape_a", 8.0,
"arrow_shape_b", 10.0,
"arrow_shape_c", 3.0,
"last_arrowhead", TRUE,
NULL);
break;
default:
g_assert_not_reached ();
}
return item;
}
static void
sheet_object_graphic_update (SheetObject *sheet_object, gdouble to_x, gdouble to_y)
{
SheetObjectGraphic *sog = SHEET_OBJECT_GRAPHIC (sheet_object);
GList *l;
sheet_object->points->coords [2] = (gdouble) to_x;
sheet_object->points->coords [3] = (gdouble) to_y;
for (l = sheet_object->realized_list; l; l = l->next){
GnomeCanvasItem *item = l->data;
gnome_canvas_item_set (item, "points", sheet_object->points, NULL);
}
}
static void
sheet_object_graphic_class_init (GtkObjectClass *object_class)
{
SheetObjectClass *sheet_object_class = SHEET_OBJECT_CLASS (object_class);
sheet_object_graphic_parent_class = gtk_type_class (sheet_object_get_type ());
object_class->destroy = sheet_object_graphic_destroy;
sheet_object_class->realize = sheet_object_graphic_realize;
sheet_object_class->update = sheet_object_graphic_update;
}
GtkType
sheet_object_graphic_get_type (void)
{
static GtkType type = 0;
if (!type){
GtkTypeInfo info = {
"SheetObjectGraphic",
sizeof (SheetObjectGraphic),
sizeof (SheetObjectGraphicClass),
(GtkClassInitFunc) sheet_object_graphic_class_init,
(GtkObjectInitFunc) NULL,
NULL, /* reserved 1 */
NULL, /* reserved 2 */
(GtkClassInitFunc) NULL
};
type = gtk_type_unique (sheet_object_get_type (), &info);
}
return type;
}
/*
* sheet_object_create_line
*
* Creates a line object
*/
SheetObject *
sheet_object_create_line (Sheet *sheet, int is_arrow,
double x1, double y1,
double x2, double y2,
char *color, int w)
{
SheetObjectGraphic *sog;
SheetObject *so;
g_return_val_if_fail (sheet != NULL, NULL);
g_return_val_if_fail (IS_SHEET (sheet), NULL);
sog = gtk_type_new (sheet_object_graphic_get_type ());
so = SHEET_OBJECT (sog);
sheet_object_construct (so, sheet);
sog->type = is_arrow ? SHEET_OBJECT_ARROW : SHEET_OBJECT_LINE;
so->points = gnome_canvas_points_new (2);
so->points->coords [0] = (gdouble) x1;
so->points->coords [1] = (gdouble) y1;
so->points->coords [2] = (gdouble) x2;
so->points->coords [3] = (gdouble) y2;
sog->color = string_get (color);
sog->width = w;
sheet->objects = g_list_prepend (sheet->objects, sog);
return SHEET_OBJECT (sog);
}
static void
sheet_object_filled_destroy (GtkObject *object)
{
SheetObjectFilled *sof = SHEET_OBJECT_FILLED (object);
if (sof->fill_color)
string_unref (sof->fill_color);
GTK_OBJECT_CLASS (sheet_object_filled_parent_class)->destroy (object);
}
static GnomeCanvasItem *
sheet_object_filled_realize (SheetObject *so, SheetView *sheet_view)
{
SheetObjectGraphic *sog = SHEET_OBJECT_GRAPHIC (so);
SheetObjectFilled *sof = SHEET_OBJECT_FILLED (so);
GnomeCanvasItem *item = NULL;
g_return_val_if_fail (so != NULL, NULL);
g_return_val_if_fail (sheet_view != NULL, NULL);
switch (sog->type){
case SHEET_OBJECT_RECTANGLE: {
double *c = so->points->coords;
item = gnome_canvas_item_new (
sheet_view->object_group,
gnome_canvas_rect_get_type (),
"x1", MIN (c [0], c [2]),
"y1", MIN (c [1], c [3]),
"x2", MAX (c [0], c [2]),
"y2", MAX (c [1], c [3]),
"fill_color", sof->fill_color ?
sof->fill_color->str : NULL,
"outline_color", sog->color->str,
"width_pixels", sog->width,
NULL);
break;
}
case SHEET_OBJECT_ELLIPSE: {
double *c = so->points->coords;
item = gnome_canvas_item_new (
sheet_view->object_group,
gnome_canvas_ellipse_get_type (),
"x1", MIN (c [0], c [2]),
"y1", MIN (c [1], c [3]),
"x2", MAX (c [0], c [2]),
"y2", MAX (c [1], c [3]),
"fill_color", sof->fill_color ? sof->fill_color->str : NULL,
"outline_color", sog->color->str,
"width_pixels", sog->width,
NULL);
break;
}
default:
g_assert_not_reached ();
}
return item;
}
static void
sheet_object_filled_update (SheetObject *sheet_object, gdouble to_x, gdouble to_y)
{
double x1, x2, y1, y2;
GList *l;
x1 = MIN (sheet_object->points->coords [0], to_x);
x2 = MAX (sheet_object->points->coords [0], to_x);
y1 = MIN (sheet_object->points->coords [1], to_y);
y2 = MAX (sheet_object->points->coords [1], to_y);
for (l = sheet_object->realized_list; l; l = l->next){
GnomeCanvasItem *item = l->data;
gnome_canvas_item_set (
item,
"x1", x1,
"y1", y1,
"x2", x2,
"y2", y2,
NULL);
}
}
static void
sheet_object_filled_class_init (GtkObjectClass *object_class)
{
SheetObjectClass *sheet_object_class = SHEET_OBJECT_CLASS (object_class);
sheet_object_filled_parent_class = gtk_type_class (sheet_object_graphic_get_type ());
object_class->destroy = sheet_object_filled_destroy;
sheet_object_class->realize = sheet_object_filled_realize;
sheet_object_class->update = sheet_object_filled_update;
}
/*
* sheet_object_create_filled:
*
* Creates and initializes a filled object of type TYPE.
*/
SheetObject *
sheet_object_create_filled (Sheet *sheet, int type,
double x1, double y1,
double x2, double y2,
char *fill_color, char *outline_color, int w)
{
SheetObjectFilled *sof;
SheetObjectGraphic *sog;
SheetObject *so;
g_return_val_if_fail (sheet != NULL, NULL);
g_return_val_if_fail (IS_SHEET (sheet), NULL);
so = gtk_type_new (sheet_object_filled_get_type ());
sheet_object_construct (so, sheet);
sof = SHEET_OBJECT_FILLED (so);
sog = SHEET_OBJECT_GRAPHIC (so);
sog->type = type;
so->points = gnome_canvas_points_new (2);
so->points->coords [0] = x1;
so->points->coords [1] = y1;
so->points->coords [2] = x2;
so->points->coords [3] = y2;
sog->width = w;
sof->pattern = 0;
if (outline_color)
sog->color = string_get (outline_color);
if (fill_color)
sof->fill_color = string_get (fill_color);
sheet->objects = g_list_prepend (sheet->objects, sof);
return so;
}
GtkType
sheet_object_filled_get_type (void)
{
static GtkType type = 0;
if (!type){
GtkTypeInfo info = {
"SheetObjectFilled",
sizeof (SheetObjectFilled),
sizeof (SheetObjectFilledClass),
(GtkClassInitFunc) sheet_object_filled_class_init,
(GtkObjectInitFunc) NULL,
NULL, /* reserved 1 */
NULL, /* reserved 2 */
(GtkClassInitFunc) NULL
};
type = gtk_type_unique (sheet_object_graphic_get_type (), &info);
}
return type;
}
#ifndef GNUMERIC_SHEET_OBJECT_GRAPHIC_H
#define GNUMERIC_SHEET_OBJECT_GRAPHIC_H
#include "sheet-object.h"
/*
* SheetObjectGraphic:
*
* Sample graphic objects
*/
#define SHEET_OBJECT_GRAPHIC_TYPE (sheet_object_graphic_get_type ())
#define SHEET_OBJECT_GRAPHIC(obj) (GTK_CHECK_CAST((obj), SHEET_OBJECT_GRAPHIC_TYPE, SheetObjectGraphic))
#define SHEET_OBJECT_GRAPHIC_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), SHEET_OBJECT_GRAPHIC_TYPE))
#define IS_SHEET_GRAPHIC_OBJECT(o) (GTK_CHECK_TYPE((o), SHEET_OBJECT_GRAPHIC_TYPE))
typedef struct {
SheetObject parent_object;
SheetObjectType type;
String *color;
int width;
} SheetObjectGraphic;
typedef struct {
SheetObjectClass parent_class;
} SheetObjectGraphicClass;
GtkType sheet_object_graphic_get_type (void);
/*
* SheetObjectFilled
*
* Derivative of SheetObjectGraphic, with filled parameter
*/
#define SHEET_OBJECT_FILLED_TYPE (sheet_object_filled_get_type ())
#define SHEET_OBJECT_FILLED(obj) (GTK_CHECK_CAST((obj), SHEET_OBJECT_FILLED_TYPE, SheetObjectFilled))
#define SHEET_OBJECT_FILLED_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), SHEET_OBJECT_FILLED_TYPE, SheetObjectFilledClass))
#define IS_SHEET_FILLED_OBJECT(o) (GTK_CHECK_TYPE((o), SHEET_OBJECT_FILLED_TYPE))
typedef struct {
SheetObjectGraphic parent_object;
String *fill_color;
int pattern;
} SheetObjectFilled;
typedef struct {
SheetObjectGraphicClass parent_class;
} SheetObjectFilledClass;
GtkType sheet_object_filled_get_type (void);
SheetObject *sheet_object_create_line (Sheet *sheet, int is_arrow,
double x1, double y1,
double x2, double y2,
char *color, int w);
#endif
/*
* sheet-object.c: Implements the drawing object manipulation for Gnumeric
* sheet-object.c: Implements the sheet object manipulation for Gnumeric
*
* Author:
* Miguel de Icaza (miguel@kernel.org)
......@@ -14,8 +14,14 @@
#include "sheet-object.h"
#include "cursors.h"
/* Pulls the GnumericSheet from a SheetView */
#define GNUMERIC_SHEET_VIEW(p) GNUMERIC_SHEET (SHEET_VIEW(p)->sheet_view);
/* Returns the class for a SheetObject */
#define SO_CLASS(so) SHEET_OBJECT_CLASS (GTK_OBJECT(so)->klass)
static GtkObjectClass *sheet_object_parent_class;
static void sheet_finish_object_creation (Sheet *sheet, SheetObject *object);
static void sheet_object_start_editing (SheetObject *object);
static void sheet_object_stop_editing (SheetObject *object);
......@@ -53,110 +59,72 @@ sheet_release_coords (Sheet *sheet)
sheet->coords = NULL;
}
/*
* sheet_object_new:
*
* Creates a new simple object
*/
static inline SheetObject *
sheet_object_new (Sheet *sheet)
static void
sheet_object_destroy (GtkObject *object)
{
SheetObject *so;
SheetObject *so = SHEET_OBJECT (object);
Sheet *sheet;
GList *l;
sheet = so->sheet;
sheet_object_stop_editing (so);
if (so == sheet->current_object)
sheet->current_object = NULL;
so = g_new0 (SheetObject, 1);
so->signature = SHEET_OBJECT_SIGNATURE;
so->sheet = sheet;
for (l = so->realized_list; l; l = l->next){
GnomeCanvasItem *item = l->data;
gtk_object_destroy (GTK_OBJECT (item));
}
g_list_free (so->realized_list);
sheet->objects = g_list_remove (sheet->objects, so);
sheet->modified = TRUE;
gnome_canvas_points_free (so->points);
return so;
(*sheet_object_parent_class->destroy)(object);
}
/*
* sheet_object_new:
*
* Creates a new filled object.
*/
static inline SheetObject *
sheet_filled_object_new (Sheet *sheet)
static void
sheet_object_class_init (GtkObjectClass *object_class)
{
SheetFilledObject *sfo;
sfo = g_new0 (SheetFilledObject, 1);
sfo->sheet_object.signature = SHEET_OBJECT_SIGNATURE;
sfo->sheet_object.sheet = sheet;
sheet_object_parent_class = gtk_type_class (gtk_object_get_type ());
return (SheetObject *) sfo;
object_class->destroy = sheet_object_destroy;
}
/*
* sheet_object_create_filled:
*
* Creates and initializes a filled object of type TYPE.
*/
SheetObject *
sheet_object_create_filled (Sheet *sheet, int type,
double x1, double y1,
double x2, double y2,
char *fill_color, char *outline_color, int w)
GtkType
sheet_object_get_type (void)
{
SheetFilledObject *sfo;
SheetObject *so;
g_return_val_if_fail (sheet != NULL, NULL);
g_return_val_if_fail (IS_SHEET (sheet), NULL);
static GtkType type = 0;
if (!type){
GtkTypeInfo info = {
"SheetObject",
sizeof (SheetObject),
sizeof (SheetObjectClass),
(GtkClassInitFunc) sheet_object_class_init,
(GtkObjectInitFunc) NULL,
NULL, /* reserved 1 */
NULL, /* reserved 2 */
(GtkClassInitFunc) NULL
};
type = gtk_type_unique (gtk_object_get_type (), &info);
}
so = sheet_filled_object_new (sheet);
sfo = (SheetFilledObject *) so;
so->type = type;
so->points = gnome_canvas_points_new (2);
so->points->coords [0] = x1;
so->points->coords [1] = y1;
so->points->coords [2] = x2;
so->points->coords [3] = y2;
so->width = w;
sfo->pattern = 0;
if (outline_color)
so->color = string_get (outline_color);
if (fill_color)
sfo->fill_color = string_get (fill_color);
sheet->objects = g_list_prepend (sheet->objects, sfo);
return (SheetObject *) sfo;
return type;
}
/*
* sheet_object_create_line
*
* Creates a line object
*/
SheetObject *
sheet_object_create_line (Sheet *sheet, int is_arrow,
double x1, double y1,
double x2, double y2,
char *color, int w)
void
sheet_object_construct (SheetObject *sheet_object, Sheet *sheet)
{
SheetObject *so;
g_return_val_if_fail (sheet != NULL, NULL);
g_return_val_if_fail (IS_SHEET (sheet), NULL);
so = sheet_object_new (sheet);
so->type = is_arrow ? SHEET_OBJECT_ARROW : SHEET_OBJECT_LINE;
so->points = gnome_canvas_points_new (2);
so->points->coords [0] = (gdouble) x1;
so->points->coords [1] = (gdouble) y1;
so->points->coords [2] = (gdouble) x2;
so->points->coords [3] = (gdouble) y2;
so->color = string_get (color);
so->width = w;
sheet->objects = g_list_prepend (sheet->objects, so);
g_return_if_fail (sheet_object != NULL);
g_return_if_fail (IS_SHEET_OBJECT (sheet_object));
g_return_if_fail (sheet != NULL);
g_return_if_fail (IS_SHEET (sheet));
return so;
sheet_object->sheet = sheet;
}
/*
......@@ -167,7 +135,6 @@ sheet_object_create_line (Sheet *sheet, int is_arrow,
static GnomeCanvasItem *
sheet_view_object_realize (SheetView *sheet_view, SheetObject *object)
{
SheetFilledObject *filled_object = (SheetFilledObject *) object;
GnomeCanvasItem *item;
g_return_val_if_fail (sheet_view != NULL, NULL);
......@@ -176,75 +143,17 @@ sheet_view_object_realize (SheetView *sheet_view, SheetObject *object)
g_return_val_if_fail (IS_SHEET_OBJECT (object), NULL);
item = NULL;
switch (object->type){
case SHEET_OBJECT_LINE:
item = gnome_canvas_item_new (
sheet_view->object_group,
gnome_canvas_line_get_type (),
"points", object->points,
"fill_color", object->color->str,
"width_pixels", object->width,
NULL);
break;
case SHEET_OBJECT_ARROW:
item = gnome_canvas_item_new (
sheet_view->object_group,
gnome_canvas_line_get_type (),
"points", object->points,
"fill_color", object->color->str,
"width_pixels", object->width,
"arrow_shape_a", 8.0,
"arrow_shape_b", 10.0,
"arrow_shape_c", 3.0,
"last_arrowhead", TRUE,
NULL);
break;
case SHEET_OBJECT_RECTANGLE: {
double *c = object->points->coords;
item = gnome_canvas_item_new (