Commit 3b3fe4c9 authored by Miguel de Icaza's avatar Miguel de Icaza Committed by Arturo Espinosa
Browse files

Load content from bonobo objects here. (sheet_view_object_unrealize): Keep

1999-09-26  Miguel de Icaza  <miguel@gnu.org>

	* src/sheet-object.c (sheet_button_release): Load content from
	bonobo objects here.
	(sheet_view_object_unrealize): Keep the bookkeeping of realized
	objects in the GnomeCanvasItem destroy handler.

	* src/sheet-object-bonobo.c (sheet_object_bonobo_load_from_file):
	New base class for SheetObjectContainer and SheetObjectBonobo

	* src/sheet-object-container.c: Redid for reusing the new
	hierarchy SheetObjectBonobo hierarchy.

1999-09-25  Miguel de Icaza  <miguel@gnu.org>

	* src/sheet-object.c (create_object): handle
	SHEET_MODE_CREATE_CANVAS_ITEM.

	* src/sheet.h (Sheet::mode_data): new field to keep per-mode data
	during the lifetime of the mode.

	* src/sheet-object-item.c: New sheet-object type.  This one is
	used for embedding Bonobo-based CanvasItems.
parent 06fd61f3
1999-09-26 Miguel de Icaza <miguel@gnu.org>
* src/sheet-object.c (sheet_button_release): Load content from
bonobo objects here.
(sheet_view_object_unrealize): Keep the bookkeeping of realized
objects in the GnomeCanvasItem destroy handler.
* src/sheet-object-bonobo.c (sheet_object_bonobo_load_from_file):
New base class for SheetObjectContainer and SheetObjectBonobo
* src/sheet-object-container.c: Redid for reusing the new
hierarchy SheetObjectBonobo hierarchy.
1999-09-25 Miguel de Icaza <miguel@gnu.org>
* src/sheet-object.c (create_object): handle
SHEET_MODE_CREATE_CANVAS_ITEM.
* src/sheet.h (Sheet::mode_data): new field to keep per-mode data
during the lifetime of the mode.
* src/sheet-object-item.c: New sheet-object type. This one is
used for embedding Bonobo-based CanvasItems.
1999-09-23 Lauris Kaplinski <lauris@ariman.ee>
* configure.in: add et to ALL_LINGUAS
......
1999-09-26 Miguel de Icaza <miguel@gnu.org>
* src/sheet-object.c (sheet_button_release): Load content from
bonobo objects here.
(sheet_view_object_unrealize): Keep the bookkeeping of realized
objects in the GnomeCanvasItem destroy handler.
* src/sheet-object-bonobo.c (sheet_object_bonobo_load_from_file):
New base class for SheetObjectContainer and SheetObjectBonobo
* src/sheet-object-container.c: Redid for reusing the new
hierarchy SheetObjectBonobo hierarchy.
1999-09-25 Miguel de Icaza <miguel@gnu.org>
* src/sheet-object.c (create_object): handle
SHEET_MODE_CREATE_CANVAS_ITEM.
* src/sheet.h (Sheet::mode_data): new field to keep per-mode data
during the lifetime of the mode.
* src/sheet-object-item.c: New sheet-object type. This one is
used for embedding Bonobo-based CanvasItems.
1999-09-23 Lauris Kaplinski <lauris@ariman.ee>
* configure.in: add et to ALL_LINGUAS
......
......@@ -101,7 +101,7 @@ ms_obj_realize (MSObj *obj, ExcelWorkbook *wb, ExcelSheet *sheet)
anchor[0], anchor[1],
anchor[2], anchor[3],
blip->reproid);
if (!sheet_object_container_load (so, blip->stream, FALSE))
if (!sheet_object_bonobo_load (SHEET_OBJECT_BONOBO (so), blip->stream))
g_warning ("Failed to load '%s' from stream",
blip->reproid);
#endif
......
......@@ -166,8 +166,12 @@ endif
GNUMERIC_BONOBO_SOURCES = \
embeddable-grid.c \
embeddable-grid.h \
sheet-object-bonobo.c \
sheet-object-bonobo.h \
sheet-object-container.c \
sheet-object-container.h
sheet-object-container.h \
sheet-object-item.c \
sheet-object-item.h
BUILT_SOURCES = $(GNUMERIC_CORBA_GENERATED)
......
......@@ -108,9 +108,9 @@ FunctionDefinition *function_add_nodes (FunctionCategory *parent,
GList *function_categories_get (void);
typedef struct {
GPtrArray *sections ;
char *help_copy ;
FunctionDefinition *fd ;
GPtrArray *sections;
char *help_copy;
FunctionDefinition *fd;
} TokenizedHelp;
typedef struct {
......
/*
* sheet-object-container.c:
* SheetObject abstract class for Bonobo-based embeddings
*
* See sheet-object-container.c for Gnome::View based embeddings
* See sheet-object-item.c for Gnome::Canvas based embeddings
*
* Author:
* Miguel de Icaza (miguel@kernel.org)
* Michael Meeks (mmeeks@gnu.org)
*
* TODO:
*
* Perhaps we should relay "realize" and get from the Bonobo
* versions both the GnomeCanvasItem to use for the gnumeric
* display and the GnomeViewFrame that logically "controls" this
* to keep track of the view frames.
*/
#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-bonobo.h"
#include <bonobo/gnome-container.h>
#include <bonobo/gnome-view-frame.h>
#include <bonobo/gnome-client-site.h>
#include <bonobo/gnome-embeddable.h>
static SheetObject *sheet_object_bonobo_parent_class;
#define SOB_CLASS(o) SHEET_OBJECT_CLASS (GTK_OBJECT (o)->klass)
static void
sheet_object_bonobo_destroy (GtkObject *object)
{
SheetObjectBonobo *sob = SHEET_OBJECT_BONOBO (object);
if (sob->client_site)
gnome_object_destroy (GNOME_OBJECT (sob->client_site));
sob->client_site = NULL;
/* Call parent's destroy method */
GTK_OBJECT_CLASS (sheet_object_bonobo_parent_class)->destroy (object);
}
static char *
get_file_name (void)
{
GtkFileSelection *fs;
gchar *filename;
fs = GTK_FILE_SELECTION (gtk_file_selection_new ("Select filename"));
gtk_signal_connect (GTK_OBJECT (fs->ok_button),
"clicked",
GTK_SIGNAL_FUNC(gtk_main_quit), NULL);
gtk_signal_connect (GTK_OBJECT (fs->cancel_button),
"clicked",
GTK_SIGNAL_FUNC(gtk_main_quit), NULL);
gtk_widget_show (GTK_WIDGET (fs));
gtk_main ();
filename = g_strdup (gtk_file_selection_get_filename (fs));
gtk_object_destroy (GTK_OBJECT (fs));
return filename;
}
/**
* sheet_object_bonobo_load_from_file:
* @sob: A SheetBonoboObject
* @fname: File from which the state is loaded for @sob
*
* Loads the state for the Bonobo component from @fname
*
* Returns TRUE on success, FALSE on failure.
*/
gboolean
sheet_object_bonobo_load_from_file (SheetObjectBonobo *sob, const char *fname)
{
CORBA_Environment ev;
GNOME_PersistFile pf;
GNOME_PersistStream ps;
CORBA_exception_init (&ev);
pf = GNOME_Unknown_query_interface (
gnome_object_corba_objref (GNOME_OBJECT (sob->object_server)),
"IDL:GNOME/PersistFile:1.0", &ev);
if (ev._major == CORBA_NO_EXCEPTION && pf != CORBA_OBJECT_NIL){
char *file;
if (!fname)
file = get_file_name ();
else
file = g_strdup (fname);
if (file)
GNOME_PersistFile_load (pf, file, &ev);
GNOME_Unknown_unref ((GNOME_Unknown) pf, &ev);
CORBA_Object_release (pf, &ev);
g_free (file);
goto finish;
}
ps = GNOME_Unknown_query_interface (
gnome_object_corba_objref (GNOME_OBJECT (sob->object_server)),
"IDL:GNOME/PersistStream:1.0", &ev);
if (ev._major == CORBA_NO_EXCEPTION && ps != CORBA_OBJECT_NIL){
char *file;
if (!fname)
file = get_file_name ();
else
file = g_strdup (fname);
if (file) {
GnomeStream *stream;
stream = gnome_stream_fs_open (file, GNOME_Storage_READ);
if (stream) {
GNOME_PersistStream_load (
ps,
(GNOME_Stream) gnome_object_corba_objref (
GNOME_OBJECT (stream)), &ev);
}
}
GNOME_Unknown_unref ((GNOME_Unknown) ps, &ev);
CORBA_Object_release (ps, &ev);
g_free (file);
goto finish;
}
CORBA_exception_free (&ev);
return FALSE;
finish:
sheet_object_realize (SHEET_OBJECT (sob));
CORBA_exception_free (&ev);
return TRUE;
}
/**
* sheet_object_bonobo_load:
* @sob: SheetObject Bonobo component
* @stream: Stream used to load the state of the @sob component
*/
gboolean
sheet_object_bonobo_load (SheetObjectBonobo *sob,
GnomeStream *stream)
{
CORBA_Environment ev;
GNOME_PersistStream ret;
g_return_val_if_fail (sob != NULL, FALSE);
g_return_val_if_fail (IS_SHEET_OBJECT_BONOBO (sob), FALSE);
g_return_val_if_fail (sob->client_site == NULL, FALSE);
sob->client_site = gnome_client_site_new (
SHEET_OBJECT (sob)->sheet->workbook->gnome_container);
CORBA_exception_init (&ev);
ret = GNOME_Unknown_query_interface (
gnome_object_corba_objref (GNOME_OBJECT (sob->object_server)),
"IDL:GNOME/PersistStream:1.0", &ev);
if (ev._major == CORBA_NO_EXCEPTION && ret != CORBA_OBJECT_NIL) {
if (stream) {
GNOME_PersistStream_load (
ret,
(GNOME_Stream) gnome_object_corba_objref (
GNOME_OBJECT (stream)), &ev);
}
GNOME_Unknown_unref ((GNOME_Unknown) ret, &ev);
CORBA_Object_release (ret, &ev);
} else {
CORBA_exception_free (&ev);
return FALSE;
}
CORBA_exception_free (&ev);
sheet_object_realize (SHEET_OBJECT (sob));
return TRUE;
}
void
sheet_object_bonobo_query_size (SheetObjectBonobo *sob)
{
#if 0
int dx = -1, dy = -1;
gnome_view_frame_size_request (view_frame, &dx, &dy);
if (dx > 0 && dy > 0) {
double tlx, tly, brx, bry;
sheet_object_get_bounds (so, &tlx, &tly, &brx, &bry);
sheet_object_set_bounds (so, tlx, tly, tlx + dx, tly + dy);
}
#else
g_warning ("We need to get our hands on the ViewFrame :-)");
#endif
}
static void
sheet_object_bonobo_class_init (GtkObjectClass *object_class)
{
sheet_object_bonobo_parent_class = gtk_type_class (sheet_object_get_type ());
/* Object class method overrides */
object_class->destroy = sheet_object_bonobo_destroy;
}
GtkType
sheet_object_bonobo_get_type (void)
{
static GtkType type = 0;
if (!type){
GtkTypeInfo info = {
"SheetObjectBonobo",
sizeof (SheetObjectBonobo),
sizeof (SheetObjectBonoboClass),
(GtkClassInitFunc) sheet_object_bonobo_class_init,
(GtkObjectInitFunc) NULL,
NULL, /* reserved 1 */
NULL, /* reserved 2 */
(GtkClassInitFunc) NULL
};
type = gtk_type_unique (sheet_object_get_type (), &info);
}
return type;
}
SheetObjectBonobo *
sheet_object_bonobo_construct (SheetObjectBonobo *sob, Sheet *sheet,
GnomeObjectClient *object_server,
double x1, double y1,
double x2, double y2)
{
g_return_val_if_fail (sob != NULL, NULL);
g_return_val_if_fail (object_server != NULL, NULL);
g_return_val_if_fail (sheet != NULL, NULL);
g_return_val_if_fail (IS_SHEET (sheet), NULL);
g_return_val_if_fail (IS_SHEET_OBJECT_BONOBO (sob), NULL);
g_return_val_if_fail (GNOME_IS_OBJECT_CLIENT (object_server), NULL);
sheet_object_construct (SHEET_OBJECT (sob), sheet);
sheet_object_set_bounds (SHEET_OBJECT (sob), x1, y1, x2, y2);
sob->object_server = object_server;
sob->client_site = gnome_client_site_new (sheet->workbook->gnome_container);
if (!gnome_client_site_bind_embeddable (sob->client_site, sob->object_server)){
gtk_object_destroy (GTK_OBJECT (sob));
return NULL;
}
return sob;
}
#ifndef GNUMERIC_SHEET_OBJECT_BONOBO_H
#define GNUMERIC_SHEET_OBJECT_BONOBO_H
#include "sheet-object.h"
#include <bonobo/gnome-client-site.h>
/*
* SheetObjectBonobo:
*
* SheetObject abstract class for embedding Bonobo components.
* The sheet-object-container implements a window-based Gnome::View embedder
* The sheet-object-item implements a canvas-based Gnome::Canvas
*/
#define SHEET_OBJECT_BONOBO_TYPE (sheet_object_bonobo_get_type ())
#define SHEET_OBJECT_BONOBO(obj) (GTK_CHECK_CAST((obj), SHEET_OBJECT_BONOBO_TYPE, SheetObjectBonobo))
#define SHEET_OBJECT_BONOBO_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), SHEET_OBJECT_BONOBO_TYPE, SheetObjectBonoboClass))
#define IS_SHEET_OBJECT_BONOBO(o) (GTK_CHECK_TYPE((o), SHEET_OBJECT_BONOBO_TYPE))
typedef struct {
SheetObject parent_object;
/*
* The ClientSite for the bonobo object
*
* If this is NULL the object has not yet been
* activated/bound to this site
*/
GnomeClientSite *client_site;
/*
* Points to the object server that implements this SheetObjectBonobo
*/
GnomeObjectClient *object_server;
} SheetObjectBonobo;
typedef struct {
SheetObjectClass parent_class;
} SheetObjectBonoboClass;
/*
* Bonobo Items.
*/
GtkType sheet_object_bonobo_get_type (void);
SheetObjectBonobo *sheet_object_bonobo_construct (SheetObjectBonobo *sob,
Sheet *sheet,
GnomeObjectClient *object_server,
double x1, double y1,
double x2, double y2);
gboolean sheet_object_bonobo_load_from_file (SheetObjectBonobo *sob,
const char *fname);
gboolean sheet_object_bonobo_load (SheetObjectBonobo *sob,
GnomeStream *stream);
void sheet_object_bonobo_query_size (SheetObjectBonobo *sob);
#endif /* GNUMERIC_SHEET_OBJECT_ITEM_H */
......@@ -20,29 +20,8 @@
#include <bonobo/gnome-client-site.h>
#include <bonobo/gnome-embeddable.h>
#if 0
#include "PlotComponent.h"
#endif
static SheetObject *sheet_object_container_parent_class;
static void
sheet_object_container_destroy (GtkObject *object)
{
SheetObjectContainer *soc = SHEET_OBJECT_CONTAINER (object);
if (soc->repoid)
g_free (soc->repoid);
soc->repoid = NULL;
if (soc->client_site)
gnome_object_destroy (GNOME_OBJECT (soc->client_site));
soc->client_site = NULL;
/* Call parent's destroy method */
GTK_OBJECT_CLASS (sheet_object_container_parent_class)->destroy (object);
}
static GnomeCanvasItem *
make_container_item (SheetObject *so, SheetView *sheet_view, GtkWidget *w)
{
......@@ -66,20 +45,6 @@ make_container_item (SheetObject *so, SheetView *sheet_view, GtkWidget *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;
}
static gint
user_activation_request_cb (GnomeViewFrame *view_frame, SheetObject *so)
{
......@@ -135,283 +100,13 @@ view_activated_cb (GnomeViewFrame *view_frame, gboolean activated, SheetObject *
return FALSE;
}
static char *
get_file_name (void)
{
GtkFileSelection *fs;
gchar *filename;
fs = GTK_FILE_SELECTION (gtk_file_selection_new ("Select filename"));
gtk_signal_connect (GTK_OBJECT (fs->ok_button),
"clicked",
GTK_SIGNAL_FUNC(gtk_main_quit), NULL);
gtk_signal_connect (GTK_OBJECT (fs->cancel_button),
"clicked",
GTK_SIGNAL_FUNC(gtk_main_quit), NULL);
gtk_widget_show (GTK_WIDGET (fs));
gtk_main ();
filename = g_strdup (gtk_file_selection_get_filename (fs));
gtk_object_destroy (GTK_OBJECT (fs));
return filename;
}
/**
* sheet_object_container_land:
* @so: Sheet Object
* @fname: Optional file name
* @own_size: Whether the component is sized to the size it
* requests.
*
* Creates client site for object, and binds object to it.
* Loads data from specified file. If no filename specified
* we are prompted for it.
*
* Returns: success.
**/
gboolean
sheet_object_container_land (SheetObject *so, const gchar *fname,
gboolean own_size)
{
SheetObjectContainer *soc;
GList *l;
g_return_val_if_fail (so != NULL, FALSE);
g_return_val_if_fail (IS_SHEET_OBJECT (so), FALSE);
soc = SHEET_OBJECT_CONTAINER (so);
g_return_val_if_fail (soc->client_site == NULL, FALSE);
/*
* 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 (!soc->repoid)
soc->repoid = gnome_bonobo_select_goad_id (_("Select an object"), NULL);
if (!soc->repoid)
return FALSE;
soc->object_server = gnome_object_activate_with_goad_id (NULL, soc->repoid, 0, NULL);
if (!soc->object_server)
return FALSE;
if (!gnome_client_site_bind_embeddable (soc->client_site, soc->object_server))
return FALSE;
/*
* 3.a
*/
{
CORBA_Environment ev;
GNOME_PersistFile ret;
CORBA_exception_init (&ev);
ret = GNOME_Unknown_query_interface (
gnome_object_corba_objref (GNOME_OBJECT (soc->object_server)),
"IDL:GNOME/PersistFile:1.0", &ev);
if (ev._major == CORBA_NO_EXCEPTION && ret != CORBA_OBJECT_NIL){
char *file;
if (!fname)
file = get_file_name ();
else
file = g_strdup (fname);
if (file)
GNOME_PersistFile_load (ret, file, &ev);
GNOME_Unknown_unref ((GNOME_Unknown) ret, &ev);
CORBA_Object_release (ret, &ev);
g_free (file);
} else {
GNOME_PersistStream ret;
ret = GNOME_Unknown_query_interface (
gnome_object_corba_objref (GNOME_OBJECT (soc->object_server)),
"IDL:GNOME/PersistStream:1.0", &ev);
if (ev._major == CORBA_NO_EXCEPTION){
if (ret != CORBA_OBJECT_NIL){
char *file;
if (!fname)
file = get_file_name ();
else
file = g_strdup (fname);
if (file) {
GnomeStream *stream;
stream = gnome_stream_fs_open (file, GNOME_Storage_READ);
if (stream) {
GNOME_PersistStream_load (
ret,
(GNOME_Stream) gnome_object_corba_objref (
GNOME_OBJECT (stream)), &ev);
}
}
GNOME_Unknown_unref ((GNOME_Unknown) ret, &ev);
CORBA_Object_release (ret, &ev);
g_free (file);
}
}
}
CORBA_exception_free (&ev);
}
/*
* 4. Instatiate the views of the object across the sheet views
*/
for (l = so->sheet->sheet_views; l; l = l->next){
GnomeCanvasItem *item;