Commit 154bb705 authored by Arturo Espinosa's avatar Arturo Espinosa

Emebedding Bonobo objects works. It currently is hardcoded to embed the



Emebedding Bonobo objects works.  It currently is hardcoded to
embed the Sample Server

Miguel.
parent b3ae7260
1999-04-17 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet-object-container.c (make_container_item): New
routine.
(sheet_object_container_land): Used to convert from the temporary
widgets to the view provided by Bonobo.
1999-04-16 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/expr.c (value_array_resize): Fix typo bug I introduced.
......
1999-04-17 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet-object-container.c (make_container_item): New
routine.
(sheet_object_container_land): Used to convert from the temporary
widgets to the view provided by Bonobo.
1999-04-16 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/expr.c (value_array_resize): Fix typo bug I introduced.
......
1999-04-17 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet-object-container.c (make_container_item): New
routine.
(sheet_object_container_land): Used to convert from the temporary
widgets to the view provided by Bonobo.
1999-04-16 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/expr.c (value_array_resize): Fix typo bug I introduced.
......
1999-04-17 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet-object-container.c (make_container_item): New
routine.
(sheet_object_container_land): Used to convert from the temporary
widgets to the view provided by Bonobo.
1999-04-16 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/expr.c (value_array_resize): Fix typo bug I introduced.
......
......@@ -7,12 +7,15 @@
*/
#include <config.h>
#include <gnome.h>
#include <libgnorba/gnorba.h>
#include <gdk/gdkkeysyms.h>
#include <math.h>
#include "gnumeric.h"
#include "gnumeric-util.h"
#include "gnumeric-sheet.h"
#include "sheet-object-container.h"
#include <bonobo/gnome-container.h>
#include <bonobo/gnome-component.h>
static SheetObject *sheet_object_container_parent_class;
......@@ -31,14 +34,13 @@ sheet_object_container_destroy (GtkObject *object)
}
static GnomeCanvasItem *
sheet_object_container_realize (SheetObject *so, SheetView *sheet_view)
make_container_item (SheetObject *so, SheetView *sheet_view, GtkWidget *w)
{
GtkWidget *w = gtk_button_new_with_label ("OBJECT");
GnomeCanvasItem *i;
GnomeCanvasItem *item;
double *c;
c = so->bbox_points->coords;
i = gnome_canvas_item_new (
item = gnome_canvas_item_new (
sheet_view->object_group,
gnome_canvas_widget_get_type (),
"widget", w,
......@@ -50,46 +52,164 @@ sheet_object_container_realize (SheetObject *so, SheetView *sheet_view)
NULL);
gtk_widget_show (w);
return item;
}
static void
sheet_object_container_destroy_views (SheetObject *so)
{
GList *l;
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);
so->realized_list = NULL;
}
void
sheet_object_container_land (SheetObject *so)
{
SheetObjectContainer *soc;
GnomeObject *component;
GList *l;
g_return_if_fail (so != NULL);
g_return_if_fail (IS_SHEET_OBJECT (so));
soc = SHEET_OBJECT_CONTAINER (so);
g_return_if_fail (soc->client_site == NULL);
/*
* 1. Kill the temporary objects we used for
* the interactive creation.
*/
sheet_object_container_destroy_views (so);
/*
* 2. Create our Client Site.
*/
soc->client_site = gnome_client_site_new (so->sheet->workbook->gnome_container);
/*
* 3. Bind it to our object
*/
if (!gnome_client_site_bind_component (soc->client_site, soc->object_server))
return;
/*
* 4. Instatiate the views of the object across the sheet views
*/
for (l = so->sheet->sheet_views; l; l = l->next){
GnomeCanvasItem *item;
SheetView *sheet_view = l->data;
GtkWidget *view;
view = gnome_component_new_view (soc->object_server);
item = make_container_item (so, sheet_view, view);
so->realized_list = g_list_prepend (so->realized_list, item);
}
}
static GnomeCanvasItem *
sheet_object_container_realize (SheetObject *so, SheetView *sheet_view)
{
SheetObjectContainer *soc;
GnomeCanvasItem *i;
GtkWidget *w;
soc = SHEET_OBJECT_CONTAINER (so);
if (soc->client_site == NULL)
w = gtk_button_new_with_label (_("Object server"));
else
w = gnome_component_new_view (soc->object_server);
i = make_container_item (so, sheet_view, w);
return i;
}
static void
sheet_object_container_update (SheetObject *so, gdouble to_x, gdouble to_y)
sheet_object_container_set_coords (SheetObject *so,
gdouble x1, gdouble y1,
gdouble x2, gdouble y2)
{
double x1, x2, y1, y2;
GList *l;
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);
c [0] = x1;
c [1] = y1;
c [2] = x2;
c [3] = y2;
for (l = so->realized_list; l; l = l->next){
GnomeCanvasItem *item = l->data;
gnome_canvas_item_set (
item,
"x", x1,
"y", y1,
"width", fabs (x2-x1),
"height", fabs (y2-y1),
"x", x1,
"y", y1,
"width", fabs (x2-x1),
"height", fabs (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)
{
SheetObjectContainer *soc = SHEET_OBJECT_CONTAINER (so);
if (soc->client_site == NULL)
sheet_object_container_land (so);
}
static void
......@@ -105,6 +225,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->creation_finished = sheet_object_container_creation_finished;
}
......@@ -132,18 +253,24 @@ sheet_object_container_get_type (void)
}
SheetObject *
sheet_object_graphic_new (Sheet *sheet,
double x1, double y1,
double x2, double y2)
sheet_object_container_new (Sheet *sheet,
double x1, double y1,
double x2, double y2,
char *repoid)
{
SheetObjectContainer *c;
SheetObject *so;
GnomeObject *object_server;
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);
object_server = gnome_object_activate_with_repo_id (NULL, repoid, 0, NULL);
if (!object_server)
return NULL;
c = gtk_type_new (sheet_object_container_get_type ());
so = SHEET_OBJECT (c);
......@@ -152,8 +279,17 @@ sheet_object_graphic_new (Sheet *sheet,
so->bbox_points->coords [1] = y1;
so->bbox_points->coords [2] = x2;
so->bbox_points->coords [3] = y2;
c->repoid = g_strdup ("IDL:Gnumeric/Graphics:1.0");
c->repoid = g_strdup (repoid);
c->object_server = object_server;
return SHEET_OBJECT (c);
}
SheetObject *
sheet_object_graphic_new (Sheet *sheet,
double x1, double y1,
double x2, double y2)
{
return sheet_object_container_new (sheet, x1, y1, x2, y2, "IDL:Sample/server:1.0");
}
......@@ -24,6 +24,10 @@ typedef struct {
*/
GnomeClientSite *client_site;
/*
* Points to the object server that implements this view
*/
GnomeObject *object_server;
char *repoid;
} SheetObjectContainer;
......@@ -31,8 +35,21 @@ typedef struct {
SheetObjectClass parent_class;
} SheetObjectContainerClass;
/*
* Generic Bonobo containers.
*/
GtkType sheet_object_container_get_type (void);
SheetObject *sheet_object_container_new (Sheet *sheet,
double x1, double y1,
double x2, double y2,
char *repoid);
void sheet_object_container_land (SheetObject *so);
/*
* Graphics
*/
SheetObject *sheet_object_graphic_new (Sheet *sheet,
double x1, double y1,
double x2, double y2);
#endif /* GNUMERIC_SHEET_OBJECT_CONTAINER_H */
......@@ -170,7 +170,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;
double *c, x1, y1, x2, y2;
GtkType type;
g_return_val_if_fail (so != NULL, NULL);
......@@ -195,10 +195,10 @@ sheet_object_filled_realize (SheetObject *so, SheetView *sheet_view)
item = gnome_canvas_item_new (
sheet_view->object_group,
type,
"x1", c [0] = MIN (c [0], c [2]),
"y1", c [1] = MIN (c [1], c [3]),
"x2", c [2] = MAX (c [0], c [2]),
"y2", c [3] = MAX (c [1], c [3]),
"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]),
"fill_color", sof->fill_color ? sof->fill_color->str : NULL,
"outline_color", sog->color->str,
"width_pixels", sog->width,
......@@ -211,22 +211,21 @@ static void
sheet_object_filled_update (SheetObject *sheet_object, gdouble to_x, gdouble to_y)
{
double x1, x2, y1, y2;
double *coords = sheet_object->bbox_points->coords;
GList *l;
x1 = MIN (sheet_object->bbox_points->coords [0], to_x);
x2 = MAX (sheet_object->bbox_points->coords [0], to_x);
y1 = MIN (sheet_object->bbox_points->coords [1], to_y);
y2 = MAX (sheet_object->bbox_points->coords [1], to_y);
coords [2] = to_x;
coords [3] = 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,
"x1", MIN (coords [0], to_x),
"y1", MIN (coords [1], to_y),
"x2", MAX (coords [0], to_x),
"y2", MAX (coords [1], to_y),
NULL);
}
}
......
......@@ -88,12 +88,35 @@ sheet_object_destroy (GtkObject *object)
(*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
*/
static void
sheet_object_update_coords (SheetObject *so,
gdouble x1d, gdouble y1d,
gdouble x2d, gdouble y2d)
{
double *coords = so->bbox_points->coords;
sheet_object_unrealize (so);
coords [0] += x1d;
coords [1] += y1d;
coords [2] += x2d;
coords [3] += y2d;
sheet_object_realize (so);
}
static void
sheet_object_class_init (GtkObjectClass *object_class)
{
SheetObjectClass *sheet_object_class = SHEET_OBJECT_CLASS (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;
}
GtkType
......@@ -199,16 +222,14 @@ sheet_view_object_unrealize (SheetView *sheet_view, SheetObject *object)
* on every existing SheetView)
*/
void
sheet_object_realize (Sheet *sheet, SheetObject *object)
sheet_object_realize (SheetObject *object)
{
GList *l;
g_return_if_fail (sheet != NULL);
g_return_if_fail (IS_SHEET (sheet));
g_return_if_fail (object != NULL);
g_return_if_fail (IS_SHEET_OBJECT (object));
for (l = sheet->sheet_views; l; l = l->next){
for (l = object->sheet->sheet_views; l; l = l->next){
SheetView *sheet_view = l->data;
GnomeCanvasItem *item;
......@@ -224,16 +245,14 @@ sheet_object_realize (Sheet *sheet, SheetObject *object)
* every SheetViews.
*/
void
sheet_object_unrealize (Sheet *sheet, SheetObject *object)
sheet_object_unrealize (SheetObject *object)
{
GList *l;
g_return_if_fail (sheet != NULL);
g_return_if_fail (IS_SHEET (sheet));
g_return_if_fail (object != NULL);
g_return_if_fail (IS_SHEET_OBJECT (object));
for (l = sheet->sheet_views; l; l = l->next){
for (l = object->sheet->sheet_views; l; l = l->next){
SheetView *sheet_view = l->data;
sheet_view_object_unrealize (sheet_view, object);
......@@ -306,7 +325,7 @@ create_object (Sheet *sheet, gdouble to_x, gdouble to_y)
g_assert_not_reached ();
}
sheet_object_realize (sheet, o);
sheet_object_realize (o);
return o;
}
......@@ -382,6 +401,16 @@ sheet_button_press (GnumericSheet *gsheet, GdkEventButton *event, Sheet *sheet)
sheet->coords = g_list_append (sheet->coords, oc);
sheet->current_object = create_object (sheet, oc->x, oc->y);
/*
* If something fails during object creation,
* set the mode to the normal sheet mode
*/
if (!sheet->current_object){
sheet_set_mode_type (sheet, SHEET_MODE_SHEET);
return 1;
}
gtk_signal_connect (GTK_OBJECT (gsheet), "button_release_event",
GTK_SIGNAL_FUNC (sheet_button_release), sheet);
......@@ -657,15 +686,6 @@ control_point_handle_event (GnomeCanvasItem *item, GdkEvent *event, SheetObject
GnomeCanvasItem *object_item = NULL;
GList *ll;
/* Find the object in this sheet view */
for (ll = object->realized_list; ll; ll = ll->next){
GnomeCanvasItem *oi = ll->data;
if (oi->canvas == GNOME_CANVAS (sheet_view->sheet_view)){
object_item = oi;
break;
}
}
if (change & POINT (0)){
set_item_x (sheet_view, 0, coords [0] + dx);
set_item_x (sheet_view, 3, coords [0] + dx);
......@@ -696,12 +716,12 @@ control_point_handle_event (GnomeCanvasItem *item, GdkEvent *event, SheetObject
set_item_y (sheet_view, 4, (coords [1] + dy + coords [3])/2);
}
sheet_view_object_unrealize (sheet_view, object);
coords [0] += change & POINT (0) ? dx : 0;
coords [1] += change & POINT (1) ? dy : 0;
coords [2] += change & POINT (2) ? dx : 0;
coords [3] += change & POINT (3) ? dy : 0;
sheet_view_object_realize (sheet_view, object);
SO_CLASS(object)->update_coords (
object,
change & POINT (0) ? dx : 0,
change & POINT (1) ? dy : 0,
change & POINT (2) ? dx : 0,
change & POINT (3) ? dy : 0);
}
break;
}
......@@ -754,12 +774,12 @@ object_event (GnomeCanvasItem *item, GdkEvent *event, SheetObject *object)
gnome_canvas_item_ungrab (item, event->button.time);
sheet_object_unrealize (object->sheet, object);
sheet_object_unrealize (object);
object->bbox_points->coords [0] += total_x;
object->bbox_points->coords [1] += total_y;
object->bbox_points->coords [2] += total_x;
object->bbox_points->coords [3] += total_y;
sheet_object_realize (object->sheet, object);
sheet_object_realize (object);
sheet_object_make_current (object->sheet, object);
break;
......
......@@ -27,6 +27,9 @@ typedef struct {
/* Virtual methods */
GnomeCanvasItem *(*realize) (SheetObject *sheet_object, SheetView *sheet_view);
void (*update) (SheetObject *sheet_object, gdouble x, gdouble y);
void (*update_coords) (SheetObject *sheet_object,
gdouble x1delta, gdouble y1delta,
gdouble x2delta, gdouble y2delta);
void (*creation_finished) (SheetObject *sheet_object);
} SheetObjectClass;
......@@ -46,11 +49,9 @@ typedef enum {
/*
* This routine creates the SheetObject in the SheetViews's Canvases.
*/
void sheet_object_realize (Sheet *sheet,
SheetObject *object);
void sheet_object_realize (SheetObject *object);
void sheet_object_unrealize (Sheet *sheet,
SheetObject *object);
void sheet_object_unrealize (SheetObject *object);
void sheet_object_make_current (Sheet *sheet,
SheetObject *object);
......
......@@ -1182,17 +1182,19 @@ readXmlObject (parseXmlContextPtr ctxt, xmlNodePtr tree)
(type == SHEET_OBJECT_ELLIPSE)){
fill_color = (char *) xmlGetValue (tree, "FillColor");
xmlGetIntValue (tree, "Pattern", &pattern);
ret = sheet_object_create_filled (ctxt->sheet, type,
x1, y1, x2, y2, fill_color, color, width);
ret = sheet_object_create_filled (
ctxt->sheet, type,
x1, y1, x2, y2, fill_color, color, width);
if (ret != NULL){
sof = SHEET_OBJECT_FILLED (ret);
sof->pattern = pattern;
}
} else {
ret = sheet_object_create_line (ctxt->sheet, type,
x1, y1, x2, y2, color, width);
ret = sheet_object_create_line (
ctxt->sheet, type,
x1, y1, x2, y2, color, width);
}
sheet_object_realize (ctxt->sheet, ret);
sheet_object_realize (ret);
return ret;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment