]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/gtkmathview-bonobo/test/main.c
ocaml 3.09 transition
[helm.git] / helm / gtkmathview-bonobo / test / main.c
index d0d646a946086e3e23bab8cebb6accf3adfcdb6b..e737329ec7ac1b93417d589ed2f777053ef6bbcc 100644 (file)
@@ -1,21 +1,70 @@
-
 #include <config.h>
-
 #include <gnome.h>
 #include <bonobo.h>
 #include <glib.h>
 
 #include "control-factory.h"
+#include "GtkMathView.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,
+                                          Bonobo_PersistFile pfile)
+{
+       CORBA_Environment ev;
+       CORBA_exception_init (&ev);
+       Bonobo_PersistFile_load (pfile, filename, &ev);
+       if (ev._major != CORBA_NO_EXCEPTION)
+                  g_warning ("Cannot load.");
+       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 0
+    stream = bonobo_stream_open ("fs", filename,
+                                Bonobo_Storage_READ, 0);
+#endif
+
+    /*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, "application/mathml+xml", &ev);
+    }
+    Bonobo_Unknown_unref (pstream, &ev);
+    CORBA_Object_release (pstream, &ev);
+    CORBA_exception_free (&ev);
+}
 
 static void
 file_selection_ok_cb (GtkWidget *widget,
@@ -25,7 +74,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),
@@ -38,23 +91,24 @@ 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); */
-      /* todo */
+       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;
@@ -66,17 +120,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);
@@ -87,7 +147,44 @@ 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
+test_view(GtkWidget* widget, gpointer data)
+{
+  CORBA_Object interface;
+  CORBA_Environment ev;
+
+  CORBA_exception_init (&ev);
+  interface = Bonobo_Unknown_queryInterface (bonobo_widget_get_objref (BONOBO_WIDGET (bonobo_window_get_contents (BONOBO_WINDOW(data)))),
+                                            "IDL:GNOME/GtkMathView/View:1.0", &ev);
+  CORBA_exception_free (&ev);
+
+  if (interface == CORBA_OBJECT_NIL)
+    {
+      g_warning ("The Control does not seem to support `View'.");
+    }
+
+  CORBA_exception_init (&ev);
+  GNOME_GtkMathView_View_freeze(interface, &ev);
+  CORBA_exception_free (&ev);
+
+  CORBA_exception_init (&ev);
+  GNOME_GtkMathView_View_thaw(interface, &ev);
+  CORBA_exception_free (&ev);
+
+  CORBA_exception_init (&ev);
+  Bonobo_Unknown_unref (interface, &ev);
+  CORBA_Object_release (interface, &ev);
+  CORBA_exception_free (&ev);
 }
 
 static void
@@ -98,10 +195,99 @@ 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_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 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 ("TestView", test_view),
+  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 ("Verbosity", get_verbosity),
   BONOBO_UI_UNSAFE_VERB ("FileExit", exit_cb),
-
   BONOBO_UI_VERB_END
 };
 
@@ -117,27 +303,26 @@ static char ui [] =
 "              <submenu name=\"File\" _label=\"_File\">"
 "                      <menuitem name=\"OpenFile\" verb=\"\" _label=\"Open (PersistFile)\" _tip=\"Open using the PersistFile interface\""
 "                      pixtype=\"stock\" pixname=\"Open\"/>"
-"                      <menuitem name=\"SaveFile\" verb=\"\" _label=\"Save (PersistFile)\" _tip=\"Save using the PersistFile interface\""
-"                      pixtype=\"stock\" pixname=\"Save\"/>"
+"                      <menuitem name=\"OpenStream\" verb=\"\" _label=\"_Open Stream (PersistStream)\" _tip=\"Open using the PersistStream interface\""
+"                      pixtype=\"stock\" pixname=\"Open Stream\"/>"
 "                      <separator/>"
-"                      <menuitem name=\"OpenStream\" verb=\"\" _label=\"_Open (PersistStream)\" _tip=\"Open using the PersistStream interface\""
-"                      pixtype=\"stock\" pixname=\"Open\"/>"
-"                      <menuitem name=\"SaveStream\" verb=\"\" _label=\"_Save (PersistStream)\" _tip=\"Save using the PersistStream interface\""
-"                      pixtype=\"stock\" pixname=\"Save\"/>"
-"                      <menuitem name=\"SavePlainStream\" verb=\"\" _label=\"Save _plain(PersistStream)\" _tip=\"Save using the PersistStream interface\""
-"                      pixtype=\"stock\" pixname=\"Save\"/>"
-"                      <separator/>"
-"                       <menuitem name=\"ViewHTMLSource\" verb=\"\" _label=\"View HTML Source\" _tip=\"View the html source of the current document\"/>"
-"                       <menuitem name=\"ViewHTMLSourceHTML\" verb=\"\" _label=\"View HTML Output\" _tip=\"View the html source of the current document as html\"/>"
-"                       <menuitem name=\"ViewPlainSource\" verb=\"\" _label=\"View PLAIN Source\" _tip=\"View the plain text source of the current document\"/>"
+"                       <menuitem name=\"TestView\" verb=\"\" _label=\"Test View\" _tip=\"Test the View interface\"/>"
 "                      <separator/>"
 "                      <menuitem name=\"FileExit\" verb=\"\" _label=\"E_xit\"/>"
 "              </submenu>"
 "              <placeholder name=\"Component\"/>"
-"              <submenu name=\"Format\" _label=\"For_mat\">"
-"                      <menuitem name=\"FormatHTML\" verb=\"\"/>"
-"                       <separator/>"
-"                       <placeholder name=\"FormatParagraph\"/>"
+"              <submenu name=\"PropertyBags\" _label=\"Property_Bag\">"
+"                      <menuitem name=\"Size\" verb=\"\" _label=\"Size(PropertyBag)\" _tip=\"Get size\""
+"                      pixtype=\"stock\" pixname=\"Get Size\"/>"
+
+"                      <menuitem name=\"Top\" verb=\"\" _label=\"Top(PropertyBag)\" _tip=\"Get Top\""
+"                      pixtype=\"stock\" pixname=\"Get Top\"/>"
+
+"                      <menuitem name=\"Font Size\" verb=\"\" _label=\"Font Size(PropertyBag)\" _tip=\"Get FontSize\""
+"                      pixtype=\"stock\" pixname=\"Get FontSize\"/>"
+
+"                      <menuitem name=\"Verbosity\" verb=\"\" _label=\"Verbosity(PropertyBag)\" _tip=\"Get Verbosity\""
+"                      pixtype=\"stock\" pixname=\"Get Verbosity\"/>"
 "               </submenu>"
 "      </menu>"
 "      <dockitem name=\"Toolbar\" behavior=\"exclusive\">"
@@ -161,6 +346,7 @@ container_create (void)
   BonoboUIComponent *component;
   BonoboUIContainer *container;
   CORBA_Environment ev;
+  
 
   win = bonobo_window_new ("test-editor",
                           "GtkMathView Control Test");
@@ -179,7 +365,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)
@@ -205,12 +391,68 @@ load_file (const gchar *fname)
   interface = Bonobo_Unknown_queryInterface (bonobo_widget_get_objref (BONOBO_WIDGET (control)),
                                             "IDL:Bonobo/PersistFile:1.0", &ev);
   CORBA_exception_free (&ev);
-  /* load_through_persist_file (fname, interface); */
-  /* TODO */
+  load_through_persist_file (fname, interface);
 
   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: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)
 {