Commit 06f929f7 authored by Michael Meeks's avatar Michael Meeks

Re-worked sheet-object code.

parent 4dd76292
1999-09-09 Michael Meeks <michael@nuclecu.unam.mx>
* src/workbook.c (workbook_delete_event): Fix object_unref for
Bonobo case. (workbook_widget_delete_event): remove strange unref, this
needs looking at.
* src/sheet-object.c (sheet_view_object_unrealize, sheet_object_destroy),
(sheet_object_destroy_control_points): Changed _unref to _destroy nailing
scads of warnings.
* src/sheet-object-container.c (sheet_object_container_destroy_views):
ditto.
* src/sheet-object-container.c (sheet_object_container_land): Get
auto sizing working.
* src/sheet-object*.[ch]: Large overhaul, extensively re-wrote signal
handling, and state passing. Generic object 'bounds' is now stored in
sheet-object, and accessed via access procedures. Homegenized naming,
Drasticaly simplified re-sizing modes.
* src/sheet-view.c: Include selection.h to kill warnings.
* src/sheet-object.c (sheet_object_get_bounds): Created.
(sheet_view_object_unrealize): Fix the same list manipulation bug
( it gets everywhere ).
1999-09-09 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/functions/fn-*: Started adding examples to all functions.
......
1999-09-09 Michael Meeks <michael@nuclecu.unam.mx>
* src/workbook.c (workbook_delete_event): Fix object_unref for
Bonobo case. (workbook_widget_delete_event): remove strange unref, this
needs looking at.
* src/sheet-object.c (sheet_view_object_unrealize, sheet_object_destroy),
(sheet_object_destroy_control_points): Changed _unref to _destroy nailing
scads of warnings.
* src/sheet-object-container.c (sheet_object_container_destroy_views):
ditto.
* src/sheet-object-container.c (sheet_object_container_land): Get
auto sizing working.
* src/sheet-object*.[ch]: Large overhaul, extensively re-wrote signal
handling, and state passing. Generic object 'bounds' is now stored in
sheet-object, and accessed via access procedures. Homegenized naming,
Drasticaly simplified re-sizing modes.
* src/sheet-view.c: Include selection.h to kill warnings.
* src/sheet-object.c (sheet_object_get_bounds): Created.
(sheet_view_object_unrealize): Fix the same list manipulation bug
( it gets everywhere ).
1999-09-09 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/functions/fn-*: Started adding examples to all functions.
......
......@@ -13,6 +13,7 @@
#include <string.h>
#include "gnumeric.h"
#include "gnumeric-sheet.h"
#include "selection.h"
#include "sheet-object.h"
#include "item-cursor.h"
#include "utils.h"
......
......@@ -43,17 +43,17 @@ static GnomeCanvasItem *
make_container_item (SheetObject *so, SheetView *sheet_view, GtkWidget *w)
{
GnomeCanvasItem *item;
double *c;
double x1, y1, x2, y2;
c = so->bbox_points->coords;
sheet_object_get_bounds (so, &x1, &y1, &x2, &y2);
item = gnome_canvas_item_new (
sheet_view->object_group,
gnome_canvas_widget_get_type (),
"widget", w,
"x", MIN (c [0], c [2]),
"y", MIN (c [1], c [3]),
"width", fabs (c [0] - c [2]),
"height", fabs (c [1] - c [3]),
"x", x1,
"y", y1,
"width", x2 - x1,
"height", y2 - y1,
"size_pixels", FALSE,
NULL);
......@@ -69,7 +69,7 @@ sheet_object_container_destroy_views (SheetObject *so)
for (l = so->realized_list; l; l = l->next){
GnomeCanvasItem *item = l->data;
gtk_object_unref (GTK_OBJECT (item));
gtk_object_destroy (GTK_OBJECT (item));
}
g_list_free (so->realized_list);
so->realized_list = NULL;
......@@ -267,18 +267,7 @@ sheet_object_container_land (SheetObject *so, const gchar *fname,
}
/*
* 4. Ask the component how big it wants to be, if it is allowed.
*/
if (own_size) {
int dx = -1, dy = -1;
gtk_signal_emit_by_name (GTK_OBJECT (soc->client_site),
"size_query", &dx, &dy);
if (dx > 0 && dy > 0)
g_warning ("unimplemented auto size to %d, %d", dx, dy);
}
/*
* 5. Instatiate the views of the object across the sheet views
* 4. Instatiate the views of the object across the sheet views
*/
for (l = so->sheet->sheet_views; l; l = l->next){
GnomeCanvasItem *item;
......@@ -297,6 +286,26 @@ sheet_object_container_land (SheetObject *so, const gchar *fname,
GTK_SIGNAL_FUNC (user_activation_request_cb), so);
gtk_signal_connect (GTK_OBJECT (view_frame), "view_activated",
GTK_SIGNAL_FUNC (view_activated_cb), so);
/*
* 5. Ask the component how big it wants to be, if it is allowed.
*/
if (own_size) {
int dx = -1, dy = -1;
gnome_view_frame_size_request (view_frame, &dx, &dy);
if (dx < 8 || dy < 8)
g_warning ("Refused to auto-size %s to %d %d",
soc->repoid?soc->repoid:"No ID!", dx, dy);
else {
double tlx, tly, brx, bry;
printf ("Auto sizing\n");
sheet_object_get_bounds (so, &tlx, &tly, &brx, &bry);
sheet_object_set_bounds (so, tlx, tly, tlx + dx, tly + dy);
}
}
view_widget = gnome_view_frame_get_wrapper (view_frame);
item = make_container_item (so, sheet_view, view_widget);
......@@ -330,20 +339,23 @@ sheet_object_container_realize (SheetObject *so, SheetView *sheet_view)
return i;
}
/*
* This implemenation moves the widget rather than
* destroying/updating/creating the views
*/
static void
sheet_object_container_set_coords (SheetObject *so,
gdouble x1, gdouble y1,
gdouble x2, gdouble y2)
sheet_object_container_update_bounds (SheetObject *so)
{
GList *l;
double *c;
double x1, y1, x2, y2;
double const zoom = so->sheet->last_zoom_factor_used;
c = so->bbox_points->coords;
sheet_object_get_bounds (so, &x1, &y1, &x2, &y2);
c [0] = x1;
c [1] = y1;
c [2] = x2;
c [3] = y2;
x1 *= zoom;
y1 *= zoom;
x2 *= zoom;
y2 *= zoom;
for (l = so->realized_list; l; l = l->next){
GnomeCanvasItem *item = l->data;
......@@ -352,55 +364,12 @@ sheet_object_container_set_coords (SheetObject *so,
item,
"x", x1,
"y", y1,
"width", fabs (x2-x1),
"height", fabs (y2-y1),
"width", x2 - x1,
"height", y2 - y1,
NULL);
}
}
static void
sheet_object_container_update (SheetObject *so, gdouble to_x, gdouble to_y)
{
double x1, x2, y1, y2;
double *c;
c = so->bbox_points->coords;
x1 = MIN (c [0], to_x);
x2 = MAX (c [0], to_x);
y1 = MIN (c [1], to_y);
y2 = MAX (c [1], to_y);
sheet_object_container_set_coords (so, x1, y1, x2, y2);
}
/*
* This implemenation moves the widget rather than
* destroying/updating/creating the views
*/
static void
sheet_object_container_update_coords (SheetObject *so,
gdouble x1d, gdouble y1d,
gdouble x2d, gdouble y2d)
{
double *c = so->bbox_points->coords;
gdouble x1, y1, x2, y2;
/* Update coordinates */
c [0] += x1d;
c [1] += y1d;
c [2] += x2d;
c [3] += y2d;
/* Normalize it */
x1 = MIN (c [0], c [2]);
y1 = MIN (c [1], c [3]);
x2 = MAX (c [0], c [2]);
y2 = MAX (c [1], c [3]);
sheet_object_container_set_coords (so, x1, y1, x2, y2);
}
static void
sheet_object_container_creation_finished (SheetObject *so)
{
......@@ -427,8 +396,7 @@ sheet_object_container_class_init (GtkObjectClass *object_class)
/* SheetObject class method overrides */
sheet_object_class->realize = sheet_object_container_realize;
sheet_object_class->update = sheet_object_container_update;
sheet_object_class->update_coords = sheet_object_container_update_coords;
sheet_object_class->update_bounds = sheet_object_container_update_bounds;
sheet_object_class->creation_finished = sheet_object_container_creation_finished;
}
......@@ -466,8 +434,6 @@ sheet_object_container_new (Sheet *sheet,
g_return_val_if_fail (sheet != NULL, NULL);
g_return_val_if_fail (IS_SHEET (sheet), NULL);
g_return_val_if_fail (x1 <= x2, NULL);
g_return_val_if_fail (y1 <= y2, NULL);
#if 0
GnomeObjectClient *object_server;
......@@ -547,11 +513,8 @@ sheet_object_container_new (Sheet *sheet,
c = gtk_type_new (sheet_object_container_get_type ());
so = SHEET_OBJECT (c);
sheet_object_construct (so, sheet);
so->bbox_points->coords [0] = x1;
so->bbox_points->coords [1] = y1;
so->bbox_points->coords [2] = x2;
so->bbox_points->coords [3] = y2;
sheet_object_construct (so, sheet);
sheet_object_set_bounds (so, x1, y1, x2, y2);
c->repoid = g_strdup (objref);
......
......@@ -34,7 +34,7 @@ sheet_object_graphic_realize (SheetObject *so, SheetView *sheet_view)
g_return_val_if_fail (so != NULL, NULL);
g_return_val_if_fail (sheet_view != NULL, NULL);
switch (sog->type){
switch (sog->type) {
case SHEET_OBJECT_LINE:
item = gnome_canvas_item_new (
sheet_view->object_group,
......@@ -66,22 +66,6 @@ sheet_object_graphic_realize (SheetObject *so, SheetView *sheet_view)
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->bbox_points->coords [2] = (gdouble) to_x;
sheet_object->bbox_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->bbox_points, NULL);
}
}
static void
sheet_object_graphic_class_init (GtkObjectClass *object_class)
{
......@@ -94,7 +78,6 @@ sheet_object_graphic_class_init (GtkObjectClass *object_class)
/* SheetObject class method overrides */
sheet_object_class->realize = sheet_object_graphic_realize;
sheet_object_class->update = sheet_object_graphic_update;
}
GtkType
......@@ -141,12 +124,9 @@ sheet_object_create_line (Sheet *sheet, int is_arrow,
so = SHEET_OBJECT (sog);
sheet_object_construct (so, sheet);
sheet_object_set_bounds (so, x1, y1, x2, y2);
sog->type = is_arrow ? SHEET_OBJECT_ARROW : SHEET_OBJECT_LINE;
so->bbox_points->coords [0] = (gdouble) x1;
so->bbox_points->coords [1] = (gdouble) y1;
so->bbox_points->coords [2] = (gdouble) x2;
so->bbox_points->coords [3] = (gdouble) y2;
sog->type = is_arrow ? SHEET_OBJECT_ARROW : SHEET_OBJECT_LINE;
sog->color = string_get (color);
sog->width = w;
......@@ -170,7 +150,7 @@ sheet_object_filled_realize (SheetObject *so, SheetView *sheet_view)
SheetObjectGraphic *sog = SHEET_OBJECT_GRAPHIC (so);
SheetObjectFilled *sof = SHEET_OBJECT_FILLED (so);
GnomeCanvasItem *item = NULL;
double *c, x1, y1, x2, y2;
double x1, y1, x2, y2;
GtkType type;
g_return_val_if_fail (so != NULL, NULL);
......@@ -190,15 +170,15 @@ sheet_object_filled_realize (SheetObject *so, SheetView *sheet_view)
g_assert_not_reached ();
}
c = so->bbox_points->coords;
sheet_object_get_bounds (so, &x1, &y1, &x2, &y2);
item = gnome_canvas_item_new (
sheet_view->object_group,
type,
"x1", x1 = MIN (c [0], c [2]),
"y1", y1 = MIN (c [1], c [3]),
"x2", x2 = MAX (c [0], c [2]),
"y2", y2 = MAX (c [1], c [3]),
"x1", x1,
"y1", y1,
"x2", x2,
"y2", y2,
"fill_color", sof->fill_color ? sof->fill_color->str : NULL,
"outline_color", sog->color->str,
"width_pixels", sog->width,
......@@ -208,23 +188,26 @@ sheet_object_filled_realize (SheetObject *so, SheetView *sheet_view)
}
static void
sheet_object_filled_update (SheetObject *sheet_object, gdouble to_x, gdouble to_y)
sheet_object_filled_update (SheetObject *so)
{
double *coords = sheet_object->bbox_points->coords;
GList *l;
double x1, y1, x2, y2;
double zoom = so->sheet->last_zoom_factor_used;
sheet_object_get_bounds (so, &x1, &y1, &x2, &y2);
x1 *= zoom;
y1 *= zoom;
x2 *= zoom;
y2 *= zoom;
coords [2] = to_x;
coords [3] = to_y;
for (l = sheet_object->realized_list; l; l = l->next){
for (l = so->realized_list; l; l = l->next){
GnomeCanvasItem *item = l->data;
gnome_canvas_item_set (
item,
"x1", MIN (coords [0], to_x),
"y1", MIN (coords [1], to_y),
"x2", MAX (coords [0], to_x),
"y2", MAX (coords [1], to_y),
"x1", x1, "y1", y1,
"x2", x2, "y2", y2,
NULL);
}
}
......@@ -237,7 +220,7 @@ sheet_object_filled_class_init (GtkObjectClass *object_class)
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_class->update_bounds = sheet_object_filled_update;
}
/*
......@@ -260,15 +243,13 @@ sheet_object_create_filled (Sheet *sheet, int type,
g_return_val_if_fail (IS_SHEET (sheet), NULL);
so = gtk_type_new (sheet_object_filled_get_type ());
sheet_object_construct (so, sheet);
sheet_object_construct (so, sheet);
sheet_object_set_bounds (so, x1, y1, x2, y2);
sof = SHEET_OBJECT_FILLED (so);
sog = SHEET_OBJECT_GRAPHIC (so);
sog->type = type;
so->bbox_points->coords [0] = x1;
so->bbox_points->coords [1] = y1;
so->bbox_points->coords [2] = x2;
so->bbox_points->coords [3] = y2;
sog->width = w;
sof->pattern = 0;
......@@ -277,6 +258,7 @@ sheet_object_create_filled (Sheet *sheet, int type,
if (fill_color)
sof->fill_color = string_get (fill_color);
return so;
}
......
......@@ -23,96 +23,54 @@ sheet_object_widget_realize (SheetObject *so, SheetView *sheet_view)
SheetObjectWidget *sow;
GnomeCanvasItem *item;
GtkWidget *view_widget;
double *c;
c = so->bbox_points->coords;
double x1, x2, y1, y2;
sheet_object_get_bounds (so, &x1, &y1, &x2, &y2);
sow = SHEET_OBJECT_WIDGET (so);
view_widget = sow->realize (sow, sow->realize_closure);
item = gnome_canvas_item_new (
sheet_view->object_group,
gnome_canvas_widget_get_type (),
"widget", view_widget,
"x", MIN (c [0], c [2]),
"y", MIN (c [1], c [3]),
"width", fabs (c [0] - c [2]),
"height", fabs (c [1] - c [3]),
"x", x1,
"y", y1,
"width", x2 - x1,
"height", y2 - y1,
"size_pixels", FALSE,
NULL);
return item;
}
/*
* This implemenation moves the widget rather than
* destroying/updating/creating the views
*/
static void
sheet_object_widget_set_coords (SheetObject *so,
gdouble x1, gdouble y1,
gdouble x2, gdouble y2)
sheet_object_widget_update_bounds (SheetObject *so)
{
GList *l;
double *c;
GList *l;
double x1, y1, x2, y2;
double zoom = so->sheet->last_zoom_factor_used;
c = so->bbox_points->coords;
c [0] = MIN (x1, x2);
c [1] = MIN (y1, y2);
c [2] = MAX (x1, x2);
c [3] = MAX (y1, y2);
sheet_object_get_bounds (so, &x1, &y1, &x2, &y2);
x1 *= zoom;
y1 *= zoom;
x2 *= zoom;
y2 *= zoom;
for (l = so->realized_list; l; l = l->next){
GnomeCanvasItem *item = l->data;
gnome_canvas_item_set (
item,
"x", c [0],
"y", c [1],
"width", fabs (x2-x1),
"height", fabs (y2-y1),
"x", x1,
"y", y1,
"width", x2 - x1,
"height", y2 - y1,
NULL);
}
}
static void
sheet_object_widget_update (SheetObject *so, gdouble to_x, gdouble to_y)
{
double x1, x2, y1, y2;
double *c;
c = so->bbox_points->coords;
x1 = MIN (c [0], to_x);
x2 = MAX (c [0], to_x);
y1 = MIN (c [1], to_y);
y2 = MAX (c [1], to_y);
sheet_object_widget_set_coords (so, x1, y1, x2, y2);
}
/*
* This implemenation moves the widget rather than
* destroying/updating/creating the views
*/
static void
sheet_object_widget_update_coords (SheetObject *so,
gdouble x1d, gdouble y1d,
gdouble x2d, gdouble y2d)
{
double *c = so->bbox_points->coords;
gdouble x1, y1, x2, y2;
double const zoom = so->sheet->last_zoom_factor_used;
/* Update coordinates */
c [0] += x1d*zoom;
c [1] += y1d*zoom;
c [2] += x2d*zoom;
c [3] += y2d*zoom;
/* Normalize it */
x1 = MIN (c [0], c [2]);
y1 = MIN (c [1], c [3]);
x2 = MAX (c [0], c [2]);
y2 = MAX (c [1], c [3]);
sheet_object_widget_set_coords (so, x1, y1, x2, y2);
}
static void
sheet_object_widget_class_init (GtkObjectClass *object_class)
{
......@@ -122,8 +80,7 @@ sheet_object_widget_class_init (GtkObjectClass *object_class)
/* SheetObject class method overrides */
sheet_object_class->realize = sheet_object_widget_realize;
sheet_object_class->update = sheet_object_widget_update;
sheet_object_class->update_coords = sheet_object_widget_update_coords;
sheet_object_class->update_bounds = sheet_object_widget_update_bounds;
}
GtkType
......@@ -162,18 +119,12 @@ sheet_object_widget_construct (SheetObjectWidget *sow,
g_return_if_fail (IS_SHEET_WIDGET_OBJECT (sow));
g_return_if_fail (sheet != NULL);
g_return_if_fail (IS_SHEET (sheet));
g_return_if_fail (x1 <= x2);
g_return_if_fail (y1 <= y2);
g_return_if_fail (realize != NULL);
so = SHEET_OBJECT (sow);
sheet_object_construct (so, sheet);
so->bbox_points->coords [0] = x1;
so->bbox_points->coords [1] = y1;
so->bbox_points->coords [2] = x2;
so->bbox_points->coords [3] = y2;
sheet_object_construct (so, sheet);
sheet_object_set_bounds (so, x1, y1, x2, y2);
sow->realize = realize;
sow->realize_closure = realize_closure;
......@@ -190,8 +141,6 @@ sheet_object_widget_new (Sheet *sheet,
g_return_val_if_fail (sheet != NULL, NULL);
g_return_val_if_fail (IS_SHEET (sheet), NULL);
g_return_val_if_fail (x1 <= x2, NULL);
g_return_val_if_fail (y1 <= y2, NULL);
g_return_val_if_fail (realize != NULL, NULL);
sow = gtk_type_new (sheet_object_widget_get_type ());
......
......@@ -76,38 +76,35 @@ sheet_object_destroy (GtkObject *object)
if (so == sheet->current_object)
sheet->current_object = NULL;
for (l = so->realized_list; l; l = l->next){
for (l = so->realized_list; l; l = l->next) {
GnomeCanvasItem *item = l->data;
gtk_object_unref (GTK_OBJECT (item));
gtk_object_destroy (GTK_OBJECT (item));
}
g_list_free (so->realized_list);
sheet->objects = g_list_remove (sheet->objects, so);
so->realized_list = NULL;
sheet->objects = g_list_remove (sheet->objects, so);
sheet->modified = TRUE;
gnome_canvas_points_free (so->bbox_points);
(*sheet_object_parent_class->destroy)(object);
}
/*
* Default method implementation for update_coords,
* This is used by cheap objects: we unrealize the objects,
* update the coordinates and realize the object
*/
/**
* sheet_object_update_bounds:
* @so: The sheet object
*
* This is a default implementation for lightweight objects.
* The process or re-realizing the object will use the new
* set of co-ordinates.
*
**/
static void
sheet_object_update_coords (SheetObject *so,
gdouble x1d, gdouble y1d,
gdouble x2d, gdouble y2d)
sheet_object_update_bounds (SheetObject *so)
{
double *coords = so->bbox_points->coords;
double const zoom = so->sheet->last_zoom_factor_used;
sheet_object_unrealize (so);
coords [0] += x1d*zoom;
coords [1] += y1d*zoom;
coords [2] += x2d*zoom;
coords [3] += y2d*zoom;
sheet_object_realize (so);
sheet_object_realize (so);
}
static void
......@@ -118,7 +115,7 @@ sheet_object_class_init (GtkObjectClass *object_class)
sheet_object_parent_class = gtk_type_class (gtk_object_get_type ());
object_class->destroy = sheet_object_destroy;
sheet_object_class->update_coords = sheet_object_update_coords;
sheet_object_class->update_bounds = sheet_object_update_bounds;
}
GtkType
......@@ -200,6 +197,63 @@ sheet_object_drop_file (SheetView *sheet_view, gint x, gint y, const char *fname
#endif
}
/**
* sheet_object_get_bounds:
* @so: The sheet object we are interested in
* @tlx: set to the top left x position
* @tly: set to the top left y position
* @brx: set to the bottom right x position
* @bry: set to the bottom right y position
*
* This function returns the bounds of the sheet object
* in the pointers it is passed.
*
**/
void
sheet_object_get_bounds (SheetObject *so, double *tlx, double *tly,
double *brx, double *bry)
{
g_return_if_fail (so != NULL);
g_return_if_fail (tlx != NULL);
g_return_if_fail (tly != NULL);
g_return_if_fail (brx != NULL);
g_return_if_fail (bry != NULL);
*tlx = MIN (so->bbox_points->coords[0],
so->bbox_points->coords[2]);
*brx = MAX (so->bbox_points->coords[0],
so->bbox_points->coords[2]);
*tly = MIN (so->bbox_points->coords[1],
so->bbox_points->coords[3]);
*bry = MAX (so->bbox_points->coords[1],
so->bbox_points->coords[3]);
}
/**
* sheet_object_get_bounds:
* @so: The sheet object we are interested in
* @tlx: top left x position
* @tly: top left y position
* @brx: bottom right x position
* @bry: bottom right y position
*
* This sets the co-ordinates of the bounding box and
* does any neccessary housekeeping.
*
**/
void
sheet_object_set_bounds (SheetObject *so, double tlx, double tly,
double brx, double bry)
{
g_return_if_fail (so != NULL);
g_return_if_fail (so->bbox_points != NULL);
so->bbox_points->coords[0] = MIN (tlx, brx);
so->bbox_points->coords[1] = MIN (tly, bry);
so->bbox_points->coords[2] = MAX (tlx, brx);
so->bbox_points->coords[3] = MAX (tly, bry);
}
/*
* sheet_view_object_realize
*
......@@ -215,11 +269,9 @@ sheet_view_object_realize (SheetView *sheet_view, SheetObject *object)
g_return_val_if_fail (object != NULL, NULL);
g_return_val_if_fail (IS_SHEET_OBJECT (object), NULL);
item = NULL;
item = SO_CLASS (object)->realize (object, sheet_view);
if (item == NULL){
if (item == NULL) {
g_warning ("We created an unsupported type\n");
return NULL;
}
......@@ -246,15 +298,20 @@ sheet_view_object_unrealize (SheetView *sheet_view, SheetObject *object)
g_return_if_fail (object != NULL);
g_return_if_fail (IS_SHEET_OBJECT (object));
for (l = object->realized_list; l; l = l->next){