From 84f1bcf0902ae1c2be671450954edc2dfb71d6db Mon Sep 17 00:00:00 2001 From: pmasoudi Date: Thu, 31 Jul 2003 14:54:14 +0000 Subject: [PATCH] * added first version of persist stream implementation (not yet working) * added test for property bag (read-only for now) --- helm/gtkmathview-bonobo/src/Makefile.am | 6 +- helm/gtkmathview-bonobo/src/control-factory.c | 19 +- helm/gtkmathview-bonobo/src/persist-file.c | 9 +- helm/gtkmathview-bonobo/src/persist-file.h | 13 +- helm/gtkmathview-bonobo/src/persist-stream.c | 190 ++++++++++ helm/gtkmathview-bonobo/src/persist-stream.h | 38 ++ helm/gtkmathview-bonobo/test/main.c | 336 ++++++++++++++++-- 7 files changed, 570 insertions(+), 41 deletions(-) create mode 100644 helm/gtkmathview-bonobo/src/persist-stream.c create mode 100644 helm/gtkmathview-bonobo/src/persist-stream.h diff --git a/helm/gtkmathview-bonobo/src/Makefile.am b/helm/gtkmathview-bonobo/src/Makefile.am index e211a3861..0a887c22e 100644 --- a/helm/gtkmathview-bonobo/src/Makefile.am +++ b/helm/gtkmathview-bonobo/src/Makefile.am @@ -12,11 +12,13 @@ libgtkmathview_bonobo_la_LDFLAGS = -version-info @GTKMATHVIEW_CONTROL_VERSION_IN libgtkmathview_bonobo_la_SOURCES = \ control-factory.c \ - persist-file.c + persist-file.c \ + persist-stream.c pkginclude_HEADERS = \ control-factory.h \ - persist-file.h + persist-file.h \ + persist-stream.h server_DATA = $(server_in_files:.server.in.in=.server) $(server_in_files:.server.in.in=.server): $(server_in_files:.server.in.in=.server.in) Makefile diff --git a/helm/gtkmathview-bonobo/src/control-factory.c b/helm/gtkmathview-bonobo/src/control-factory.c index 5039e34ac..025e645e9 100644 --- a/helm/gtkmathview-bonobo/src/control-factory.c +++ b/helm/gtkmathview-bonobo/src/control-factory.c @@ -1,9 +1,6 @@ - #include #include - #include - #include "control-factory.h" enum { @@ -108,8 +105,9 @@ get_prop(BonoboPropertyBag *bag, } break; case MATH_VIEW_FONT_MANAGER: - {gint i = (gint) gtk_math_view_get_font_manager_type(math_view); - BONOBO_ARG_SET_INT(arg,i); + { + gint i = (gint) gtk_math_view_get_font_manager_type(math_view); + BONOBO_ARG_SET_INT(arg,i); } break; default: @@ -201,7 +199,8 @@ set_prop(BonoboPropertyBag *bag, } break; default: - g_assert(FALSE); + bonobo_exception_set (ev, ex_Bonobo_PropertyBag_NotFound); + break; } } @@ -212,6 +211,7 @@ gtk_math_view_control_factory(BonoboGenericFactory* factory, const gchar* compon BonoboPropertyBag *prop_bag; GtkWidget *math_view; BonoboObject *persist_file; + BonoboObject *persist_stream; math_view = gtk_math_view_new(NULL,NULL); gtk_widget_show(math_view); @@ -221,6 +221,9 @@ gtk_math_view_control_factory(BonoboGenericFactory* factory, const gchar* compon persist_file = gtk_math_view_persist_file_new(GTK_MATH_VIEW(math_view)); bonobo_object_add_interface(BONOBO_OBJECT(control), persist_file); + persist_stream = gtk_math_view_persist_stream_new(GTK_MATH_VIEW(math_view)); + bonobo_object_add_interface(BONOBO_OBJECT(control), persist_stream); + prop_bag = bonobo_property_bag_new(get_prop, set_prop, math_view); bonobo_control_set_properties(control, BONOBO_OBJREF(prop_bag), NULL); @@ -240,10 +243,12 @@ gtk_math_view_control_factory(BonoboGenericFactory* factory, const gchar* compon NULL,"transparency",0); bonobo_property_bag_add(prop_bag,"verbosity",MATH_VIEW_VERBOSITY,BONOBO_ARG_INT, NULL,"verbosity",0); - bonobo_property_bag_add(prop_bag,"font_manager",MATH_VIEW_FONT_MANAGER,BONOBO_ARG_NULL, + bonobo_property_bag_add(prop_bag,"font_manager",MATH_VIEW_FONT_MANAGER,BONOBO_ARG_INT, NULL,"font_manager",0); bonobo_object_unref(BONOBO_OBJECT(prop_bag)); + //bonobo_object_unref(BONOBO_OBJECT(persist_file)); + //bonobo_object_unref(BONOBO_OBJECT(persist_stream)); return BONOBO_OBJECT(control); } diff --git a/helm/gtkmathview-bonobo/src/persist-file.c b/helm/gtkmathview-bonobo/src/persist-file.c index 68914ded4..36b4536a4 100644 --- a/helm/gtkmathview-bonobo/src/persist-file.c +++ b/helm/gtkmathview-bonobo/src/persist-file.c @@ -39,7 +39,9 @@ gtk_math_view_persist_file_class_init(GtkMathViewPersistFileClass *klass) BonoboPersistClass *persist_class = BONOBO_PERSIST_CLASS(klass); POA_Bonobo_PersistFile__epv *epv = &klass->epv; +#ifdef DEBUG printf("persist file class init\n"); +#endif gtk_math_view_persist_file_parent_class = g_type_class_peek_parent(klass); epv->load = load_implementation; @@ -53,7 +55,9 @@ GType gtk_math_view_persist_file_get_type(void) { static GType type = 0; +#ifdef DEBUG printf("persist file get type\n"); +#endif if(!type){ GTypeInfo info = { sizeof(GtkMathViewPersistFileClass), @@ -103,11 +107,14 @@ load_implementation(PortableServer_Servant servant,const gchar *path,CORBA_Envir { CORBA_exception_set(ev,CORBA_USER_EXCEPTION,ex_Bonobo_Persist_WrongDataType,NULL); } + bonobo_object_unref(BONOBO_OBJECT(file)); return ; } static void -save_implementation(PortableServer_Servant servant,const gchar *path,CORBA_Environment *ev) +save_implementation(PortableServer_Servant servant, + const gchar *path, + CORBA_Environment *ev) { bonobo_exception_set(ev,"save_exception"); bonobo_exception_add_handler_str("save_exception", diff --git a/helm/gtkmathview-bonobo/src/persist-file.h b/helm/gtkmathview-bonobo/src/persist-file.h index eb2b113f4..0ed7bcbf9 100644 --- a/helm/gtkmathview-bonobo/src/persist-file.h +++ b/helm/gtkmathview-bonobo/src/persist-file.h @@ -1,5 +1,5 @@ -#ifndef _GTK_MATH_VIEW_PERSIST_FILE_H_ -#define _GTK_MATH_VIEW_PERSIST_FILE_H_ +#ifndef __GTK_MATH_VIEW_PERSIST_FILE_H__ +#define __GTK_MATH_VIEW_PERSIST_FILE_H__ #include #include @@ -12,15 +12,12 @@ typedef struct _GtkMathViewPersistFilePrivate GtkMathViewPersistFilePrivate; #define GTK_MATH_VIEW_TYPE_PERSIST_FILE (gtk_math_view_persist_file_get_type()) -#define GTK_MATH_VIEW_PERSIST_FILE(o) (G_TYPE_CHECK_INSTANCE_CAST((o), GTK_MATH_VIEW_TYPE_PERSIST_FILE, \ +#define GTK_MATH_VIEW_PERSIST_FILE(object) (G_TYPE_CHECK_INSTANCE_CAST((object), GTK_MATH_VIEW_TYPE_PERSIST_FILE, \ GtkMathViewPersistFile)) -#define GTK_HTML_IS_PERSIST_FILE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k),\ - GTK_MATH_VIEW_TYPE_PERSIST_FILE,\ - GtkMathViewPersistFileClass)) -#define GTK_MATH_VIEW_IS_PERSIST_FILE(o) (G_TYPE_CHECK_INSTANCE_TYPE((o),\ +#define GTK_MATH_VIEW_IS_PERSIST_FILE(object) (G_TYPE_CHECK_INSTANCE_TYPE((object),\ GTK_MATH_VIEW_TYPE_PERSIST_FILE)) -#define GTK_MATH_VIEW_IS_PERSIST_FILE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k),\ +#define GTK_MATH_VIEW_IS_PERSIST_FILE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),\ GTK_MATH_VIEW_TYPE_PERSIST_FILE)) struct _GtkMathViewPersistFile{ diff --git a/helm/gtkmathview-bonobo/src/persist-stream.c b/helm/gtkmathview-bonobo/src/persist-stream.c new file mode 100644 index 000000000..815606bde --- /dev/null +++ b/helm/gtkmathview-bonobo/src/persist-stream.c @@ -0,0 +1,190 @@ +#include +#include +#include +#include "persist-stream.h" +#include "control-factory.h" + +#define DEBUG + +static BonoboObjectClass *gtk_math_view_persist_stream_parent_class; + +static void load_implementation(PortableServer_Servant servant, + const Bonobo_Stream stream, + const CORBA_char *type, + CORBA_Environment *ev); + +static void save_implementation(PortableServer_Servant servant, + const Bonobo_Stream stream, + const CORBA_char *type, + CORBA_Environment *ev); + +static void finalize(GObject *object) +{ + GtkMathViewPersistStream *stream = GTK_MATH_VIEW_PERSIST_STREAM(object); + + if(stream->math_view){ + g_object_unref(stream->math_view); + stream->math_view = NULL; + } + + G_OBJECT_CLASS(gtk_math_view_persist_stream_parent_class)->finalize(object); +} + +static Bonobo_Persist_ContentTypeList * +get_content_types(BonoboPersist *persist,CORBA_Environment *ev) +{ + //FIXME:il tipo di dato non e` noto + return bonobo_persist_generate_content_types(0); +} + +static void +gtk_math_view_persist_stream_class_init(GtkMathViewPersistStreamClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS(klass); + BonoboPersistClass *persist_class = BONOBO_PERSIST_CLASS(klass); + POA_Bonobo_PersistStream__epv *epv = &klass->epv; + +#ifdef DEBUG + printf("persist stream class init\n"); +#endif + gtk_math_view_persist_stream_parent_class = g_type_class_peek_parent(klass); + + epv->load = load_implementation; + epv->save = save_implementation; + + object_class->finalize = finalize; + persist_class->get_content_types = get_content_types; +} + +GType +gtk_math_view_persist_stream_get_type(void) +{ + static GType type = 0; +#ifdef DEBUG + printf("persist stream get type\n"); +#endif + if(!type){ + GTypeInfo info={ + sizeof(GtkMathViewPersistStreamClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) gtk_math_view_persist_stream_class_init, + NULL, /*class finalize */ + NULL, /*class data */ + sizeof(GtkMathViewPersistStream), + 0, /* n_preallocs */ + (GInstanceInitFunc) NULL + }; + + type = bonobo_type_unique( + BONOBO_TYPE_PERSIST, + POA_Bonobo_PersistStream__init,POA_Bonobo_PersistStream__fini, + G_STRUCT_OFFSET(GtkMathViewPersistStreamClass,epv), + &info,"GtkMathViewPersistStream"); + } + return type; +} + +BonoboObject * +gtk_math_view_persist_stream_new(GtkMathView *math_view) +{ + BonoboObject *stream; + +#ifdef DEBUG + printf("persist stream new\n"); +#endif + stream = g_object_new(gtk_math_view_persist_stream_get_type(),NULL); + bonobo_persist_construct(BONOBO_PERSIST(stream),CONTROL_FACTORY_ID); + + g_object_ref(math_view); + GTK_MATH_VIEW_PERSIST_STREAM(stream)->math_view = math_view; + + return stream; +} + +static FILE* +create_tmp_file(GtkMathViewPersistStream *persist) +{ + FILE *tmpfile; + int fd; + + persist->tmp_path_name = g_strconcat(g_get_tmp_dir(), "/ggvXXXXXX", NULL); + if((fd = mkstemp(persist->tmp_path_name)) < 0) { + g_free(persist->tmp_path_name), + persist->tmp_path_name = NULL; + return NULL; + } + tmpfile = fdopen(fd, "w"); + if(!tmpfile) { + close(fd); + return NULL; + } + return tmpfile; +} + + +static void +load_implementation(PortableServer_Servant servant, + Bonobo_PersistStream stream, + const CORBA_char *type, + CORBA_Environment *ev) +{ + GtkMathViewPersistStream *persist = GTK_MATH_VIEW_PERSIST_STREAM (bonobo_object_from_servant (servant)); + Bonobo_Stream_iobuf *buffer; + GtkMathViewPersistStream *handle; + CORBA_long len_read; + gboolean result; + FILE *tmpfile; + +#ifdef DEBUG + printf("persist stream loading\n"); +#endif + + if (strcmp (type, "application/mathml+xml") != 0) { + CORBA_exception_set (ev, CORBA_USER_EXCEPTION, + ex_Bonobo_Persist_WrongDataType, NULL); + return; + } + + tmpfile = create_tmp_file(persist); + do { + Bonobo_Stream_read (stream, 4096, &buffer, ev); + + if (ev->_major != CORBA_NO_EXCEPTION || buffer->_length <= 0) { + CORBA_free (buffer); + goto clean; + } + + len_read = buffer->_length; + if (buffer->_buffer && len_read) + if(fwrite(buffer->_buffer, 1, len_read, tmpfile) != len_read) { + CORBA_free (buffer); + goto clean; + } + + CORBA_free (buffer); + } while (1); + + fclose(tmpfile); + result = gtk_math_view_load_uri(persist->math_view,persist->tmp_path_name); + if(!result) + { + CORBA_exception_set(ev,CORBA_USER_EXCEPTION,ex_Bonobo_Persist_WrongDataType,NULL); + } + //FIXME non sono sicuro di questo + bonobo_object_unref(BONOBO_OBJECT(stream)); + return ; + +clean: + fclose (tmpfile); + return; +} + +static void +save_implementation(PortableServer_Servant servant,const Bonobo_Stream stream,const CORBA_char *type,CORBA_Environment *ev) +{ + bonobo_exception_set(ev,"save_exception"); + bonobo_exception_add_handler_str("save_exception", + "Save option is not valid"); + return; +} diff --git a/helm/gtkmathview-bonobo/src/persist-stream.h b/helm/gtkmathview-bonobo/src/persist-stream.h new file mode 100644 index 000000000..88e3682ab --- /dev/null +++ b/helm/gtkmathview-bonobo/src/persist-stream.h @@ -0,0 +1,38 @@ +#ifndef __GTK_MATH_VIEW_PERSIST_STREAM_H__ +#define __GTK_MATH_VIEW_PERSIST_STREAM_H__ + +#include +#include + +G_BEGIN_DECLS + +struct _GtkMathViewPersistStream; +typedef struct _GtkMathViewPersistStream GtkMathViewPersistStream; +typedef struct _GtkMathViewPersistStreamPrivate GtkMathViewPersistStreamPrivate; + +#define GTK_MATH_VIEW_TYPE_PERSIST_STREAM (gtk_math_view_persist_stream_get_type()) + +#define GTK_MATH_VIEW_PERSIST_STREAM(object) (G_TYPE_CHECK_INSTANCE_CAST((object), GTK_MATH_VIEW_TYPE_PERSIST_STREAM,GtkMathViewPersistStream)) + +#define GTK_MATH_VIEW_IS_PERSIST_STREAM(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), GTK_MATH_VIEW_TYPE_PERSIST_STREAM)) + +#define GTK_MATH_VIEW_IS_PERSIST_STREAM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GTK_MATH_VIEW_TYPE_PERSIST_STREAM)) + +struct _GtkMathViewPersistStream{ + BonoboPersist parent; + GtkMathView *math_view; + const gchar* tmp_path_name; +}; + +typedef struct{ + BonoboPersistClass parent_class; + + POA_Bonobo_PersistStream__epv epv; +}GtkMathViewPersistStreamClass; + +GType gtk_math_view_persist_stream_get_type(void); +BonoboObject *gtk_math_view_persist_stream_new(GtkMathView *math_view); + +G_END_DECLS + +#endif diff --git a/helm/gtkmathview-bonobo/test/main.c b/helm/gtkmathview-bonobo/test/main.c index 41ec0a9fe..fc9715e6d 100644 --- a/helm/gtkmathview-bonobo/test/main.c +++ b/helm/gtkmathview-bonobo/test/main.c @@ -1,21 +1,30 @@ - #include - #include #include - #include #include "control-factory.h" static GtkWidget *control; +typedef enum{LOAD_STREAM,LOAD_FILE,NONE}FileSelectionOp; + struct FileSelectionInfo { BonoboWidget* control; GtkWidget* widget; + + FileSelectionOp Operations; }; -static struct FileSelectionInfo file_selection_info = { NULL, NULL }; + +static struct FileSelectionInfo file_selection_info = { NULL, NULL,NONE}; + +static void +file_selection_destroy_cb (GtkWidget *widget,gpointer data) +{ + file_selection_info.widget = NULL; +} + static void load_through_persist_file (const gchar *filename, @@ -29,6 +38,28 @@ load_through_persist_file (const gchar *filename, CORBA_exception_free (&ev); } +static void +load_through_persist_stream(const gchar *filename, + Bonobo_PersistStream pstream) +{ + BonoboObject *stream = NULL; + CORBA_Environment ev; + CORBA_exception_init (&ev); + + /*if (stream == NULL) + { + g_warning ("Couldn't load `%s'\n", filename); + } else*/ { + Bonobo_Stream corba_stream; + //corba_stream = bonobo_object_corba_objref (stream); + //Bonobo_Stream_truncate (corba_stream, 0, &ev); + Bonobo_PersistStream_load (pstream, corba_stream,"",&ev); + } + Bonobo_Unknown_unref (pstream, &ev); + CORBA_Object_release (pstream, &ev); + CORBA_exception_free (&ev); +} + static void file_selection_ok_cb (GtkWidget *widget, gpointer data) @@ -37,7 +68,11 @@ file_selection_ok_cb (GtkWidget *widget, const gchar *interface_name; CORBA_Environment ev; - interface_name = "IDL:Bonobo/PersistFile:1.0"; + if (file_selection_info.Operations == LOAD_FILE) + interface_name = "IDL:Bonobo/PersistFile:1.0"; + else if(file_selection_info.Operations == LOAD_STREAM) + interface_name = "IDL:Bonobo/PersistStream:1.0"; + else printf("failed to get operation type\n"); CORBA_exception_init (&ev); interface = Bonobo_Unknown_queryInterface (bonobo_widget_get_objref (file_selection_info.control), @@ -50,22 +85,25 @@ file_selection_ok_cb (GtkWidget *widget, } else { - const gchar *fname = gtk_file_selection_get_filename (GTK_FILE_SELECTION (file_selection_info.widget)); - load_through_persist_file (fname, interface); + const gchar *fname; + fname = gtk_file_selection_get_filename + (GTK_FILE_SELECTION (file_selection_info.widget)); + switch (file_selection_info.Operations) { + case LOAD_STREAM: + load_through_persist_stream (fname, interface); + break; + case LOAD_FILE: + load_through_persist_file (fname, interface); + break; + } } gtk_widget_destroy (file_selection_info.widget); } static void -file_selection_destroy_cb (GtkWidget *widget, - gpointer data) -{ - file_selection_info.widget = NULL; -} - -static void -open_dialog (BonoboWindow *app) +open_dialog (BonoboWindow *app, + FileSelectionOp operation) { GtkWidget *widget; BonoboWidget *control; @@ -77,17 +115,23 @@ open_dialog (BonoboWindow *app) return; } - widget = gtk_file_selection_new (_("Open file...")); + if(operation == LOAD_STREAM) + widget = gtk_file_selection_new(_("Open Stream....")); + if(operation == LOAD_FILE) + widget = gtk_file_selection_new (_("Open file...")); gtk_window_set_transient_for (GTK_WINDOW (widget), GTK_WINDOW (app)); file_selection_info.widget = widget; file_selection_info.control = control; + file_selection_info.Operations = operation; g_signal_connect_object (GTK_FILE_SELECTION (widget)->cancel_button, "clicked", G_CALLBACK (gtk_widget_destroy), widget, G_CONNECT_AFTER); + g_signal_connect (GTK_FILE_SELECTION (widget)->ok_button, "clicked", G_CALLBACK (file_selection_ok_cb), NULL); + g_signal_connect (file_selection_info.widget, "destroy", G_CALLBACK (file_selection_destroy_cb), NULL); gtk_widget_show (file_selection_info.widget); @@ -98,7 +142,14 @@ static void open_through_persist_file_cb (GtkWidget *widget, gpointer data) { - open_dialog (BONOBO_WINDOW (data)); + open_dialog (BONOBO_WINDOW (data),LOAD_FILE); +} + +static void +open_through_persist_stream_cb(GtkWidget *widget, + gpointer data) +{ + open_dialog(BONOBO_WINDOW(data),LOAD_STREAM); } static void @@ -109,10 +160,167 @@ exit_cb (GtkWidget *widget, bonobo_main_quit (); } +static void +get_size(GtkWidget *widget, + gpointer data) +{ + gint width,height; + BonoboWidget* control; + BonoboControlFrame* control_frame; + + Bonobo_PropertyBag prop_bag; + + control = BONOBO_WIDGET (bonobo_window_get_contents (BONOBO_WINDOW (data))); + control_frame = bonobo_widget_get_control_frame(BONOBO_WIDGET(control)); + prop_bag = bonobo_control_frame_get_control_property_bag(control_frame, NULL); + + width = bonobo_pbclient_get_long(prop_bag,"width",NULL); + height = bonobo_pbclient_get_long(prop_bag,"height",NULL); + + printf("Width: %d Height: %d\n",width,height); + + bonobo_object_release_unref (prop_bag,NULL); + +}; + +static void +get_top(GtkWidget *widget, + gpointer data) +{ + gint top_x,top_y; + BonoboWidget* control; + BonoboControlFrame* control_frame; + Bonobo_PropertyBag prop_bag; + + control = BONOBO_WIDGET(bonobo_window_get_contents(BONOBO_WINDOW(data))); + control_frame = bonobo_widget_get_control_frame(BONOBO_WIDGET(control)); + prop_bag = bonobo_control_frame_get_control_property_bag(control_frame,NULL); + + top_x = bonobo_pbclient_get_long(prop_bag,"top_x",NULL); + top_y = bonobo_pbclient_get_long(prop_bag,"top_y",NULL); + + printf("Top X: %d ,Top Y: %d\n",top_x,top_y); + + bonobo_object_release_unref(prop_bag,NULL); +} + +static void +get_font_size(GtkWidget *widget, + gpointer data) +{ + gint font_size; + BonoboWidget* control; + BonoboControlFrame* control_frame; + Bonobo_PropertyBag prop_bag; + + control = BONOBO_WIDGET(bonobo_window_get_contents(BONOBO_WINDOW(data))); + control_frame = bonobo_widget_get_control_frame(BONOBO_WIDGET(control)); + prop_bag = bonobo_control_frame_get_control_property_bag(control_frame,NULL); + + font_size = bonobo_pbclient_get_long(prop_bag,"font_size",NULL); + + printf("FontSize : %d\n",font_size); + + bonobo_object_release_unref(prop_bag,NULL); +} + +static void +get_antialiasing(GtkWidget *widget, + gpointer data) +{ + gboolean antialiasing; + BonoboWidget* control; + BonoboControlFrame* control_frame; + Bonobo_PropertyBag prop_bag; + + control = BONOBO_WIDGET(bonobo_window_get_contents(BONOBO_WINDOW(data))); + control_frame = bonobo_widget_get_control_frame(BONOBO_WIDGET(control)); + prop_bag = bonobo_control_frame_get_control_property_bag(control_frame,NULL); + + antialiasing = bonobo_pbclient_get_boolean(prop_bag,"anti_aliasing",NULL); + + if(antialiasing == TRUE) + printf("Antialiasing is set\n"); + else if(antialiasing == FALSE) + printf("Antialiasing is not set\n"); + + bonobo_object_release_unref(prop_bag,NULL); +} + +static void +get_transparency(GtkWidget *widget, + gpointer data) +{ + gboolean transparency; + BonoboWidget* control; + BonoboControlFrame* control_frame; + Bonobo_PropertyBag prop_bag; + + control = BONOBO_WIDGET(bonobo_window_get_contents(BONOBO_WINDOW(data))); + control_frame = bonobo_widget_get_control_frame(BONOBO_WIDGET(control)); + prop_bag = bonobo_control_frame_get_control_property_bag(control_frame,NULL); + + transparency = bonobo_pbclient_get_boolean(prop_bag,"transparency",NULL); + + if(transparency == TRUE) + printf("Transparency is set\n"); + else if(transparency == FALSE) + printf("Transparency is not set\n"); + + bonobo_object_release_unref(prop_bag,NULL); +} + +static void +get_verbosity(GtkWidget *widget, + gpointer data) +{ + gint verbosity; + BonoboWidget* control; + BonoboControlFrame* control_frame; + Bonobo_PropertyBag prop_bag; + + control = BONOBO_WIDGET(bonobo_window_get_contents(BONOBO_WINDOW(data))); + control_frame = bonobo_widget_get_control_frame(BONOBO_WIDGET(control)); + prop_bag = bonobo_control_frame_get_control_property_bag(control_frame,NULL); + + verbosity = bonobo_pbclient_get_long(prop_bag,"verbosity",NULL); + + printf("Verbosity: %d\n",verbosity); + + bonobo_object_release_unref(prop_bag,NULL); +} + +static void +get_font_manager(GtkWidget *widget, + gpointer data) +{ + gint font_manager; + BonoboWidget* control; + BonoboControlFrame* control_frame; + Bonobo_PropertyBag prop_bag; + + control = BONOBO_WIDGET(bonobo_window_get_contents(BONOBO_WINDOW(data))); + control_frame = bonobo_widget_get_control_frame(BONOBO_WIDGET(control)); + prop_bag = bonobo_control_frame_get_control_property_bag(control_frame,NULL); + + font_manager = bonobo_pbclient_get_long(prop_bag,"font_manager",NULL); + + printf("Font_manager: %d\n",font_manager); + + bonobo_object_release_unref(prop_bag,NULL); +} + static BonoboUIVerb verbs [] = { BONOBO_UI_UNSAFE_VERB ("OpenFile", open_through_persist_file_cb), + BONOBO_UI_UNSAFE_VERB ("OpenStream", open_through_persist_stream_cb), + BONOBO_UI_UNSAFE_VERB ("Size", get_size), + BONOBO_UI_UNSAFE_VERB ("Top", get_top), + BONOBO_UI_UNSAFE_VERB ("Font Size", get_font_size), + BONOBO_UI_UNSAFE_VERB ("AntiAliasing", get_antialiasing), + BONOBO_UI_UNSAFE_VERB ("Transparency", get_transparency), + BONOBO_UI_UNSAFE_VERB ("Verbosity", get_verbosity), + BONOBO_UI_UNSAFE_VERB ("Font Manager", get_font_manager), BONOBO_UI_UNSAFE_VERB ("FileExit", exit_cb), - BONOBO_UI_VERB_END }; @@ -131,8 +339,8 @@ static char ui [] = " " " " -" " +" " " " " " " " " " -" " -" " +" " +" " + +" " + +" " + +" " + +" " + +" " + +" " + " " " " " " @@ -172,6 +400,7 @@ container_create (void) BonoboUIComponent *component; BonoboUIContainer *container; CORBA_Environment ev; + win = bonobo_window_new ("test-editor", "GtkMathView Control Test"); @@ -190,7 +419,7 @@ container_create (void) bonobo_ui_component_set_container (component, BONOBO_OBJREF (container), NULL); bonobo_ui_component_add_verb_list_with_data (component, verbs, win); bonobo_ui_component_set_translate (component, "/", ui, NULL); - + control = bonobo_widget_new_control (CONTROL_ID, BONOBO_OBJREF (container)); if (control == NULL) @@ -221,6 +450,67 @@ load_file (const gchar *fname) return FALSE; } +static gint +load_file_stream(const gchar *fname) +{ + CORBA_Object interface; + CORBA_Environment ev; + + printf("loading with stream %s\n",fname); + CORBA_exception_init(&ev); + interface = Bonobo_Unknown_queryInterface(bonobo_widget_get_objref(BONOBO_WIDGET(control)), + "IDL:Bonobo/PersistStream:1.0",&ev); + + CORBA_exception_free(&ev); + load_through_persist_stream(fname,interface); + + return FALSE; +} + +/* +static void +install_property_bag_listener (BonoboWidget *control, BonoboWindow *bonobo_win) +{ + Bonobo_Listener corba_listener; + BonoboListener *listener; + BonoboControlFrame *control_frame; + CORBA_Environment ev; + Bonobo_PropertyBag prop_bag; + + CORBA_exception_init(&ev); + + control_frame = bonobo_widget_get_control_frame(BONOBO_WIDGET(control)); + if(!control_frame) + g_error("can't find control frame\n"); + + prop_bag = bonobo_control_frame_get_control_property_bag(control_frame, NULL); + if(prop_bag == CORBA_OBJECT_NIL) + g_error("can't connect to property bag\n"); + + //connect a listener to the property bag + bonobo_event_source_client_add_listener(prop_bag, (BonoboListenerCallbackFn) width_changed, + "Bonobo/Property:change:width",NULL,bonobo_win); + + bonobo_event_source_client_add_listener(prop_bag, (BonoboListenerCallbackFn)height_changed, + "Bonobo/Property:change:height",NULL,bonobo_win); + bonobo_event_source_client_add_listener(prop_bag, (BonoboListenerCallbackFn)top_x_changed, + "Bonobo/Property:change:top_x",NULL,bonobo_win); + bonobo_event_source_client_add_listener(prop_bag, (BonoboListenerCallbackFn)top_y_changed, + "Bonobo/Property:change:top_y",NULL,bonobo_win); + bonobo_event_source_client_add_listener(prop_bag, (BonoboListenerCallbackFn)font_size_changed, + "Bonobo/Property:change:font_size",NULL,bonobo_win); + bonobo_event_source_client_add_listener(prop_bag, (BonoboListenerCallbackFn)anti_aliasing_changed, + "Bonobo/Property:change:anti_aliasing",NULL,bonobo_win); + bonobo_event_source_client_add_listener(prop_bag, (BonoboListenerCallbackFn)transparency_changed, + "Bonobo/Property:change:transparency",NULL,bonobo_win); + bonobo_event_source_client_add_listener(prop_bag, (BonoboListenerCallbackFn)verbosity_changed, + "Bonobo/Property:change:verbosity",NULL,bonobo_win); + bonobo_event_source_client_add_listener(prop_bag, (BonoboListenerCallbackFn)font_manager_changed, + "Bonobo/Property:change:font_manager",NULL,bonobo_win); + CORBA_exception_free(&ev); +}*/ + + int main (int argc, char **argv) { -- 2.39.2