]> matita.cs.unibo.it Git - helm.git/commitdiff
* added simple test program
authorLuca Padovani <luca.padovani@unito.it>
Thu, 17 Jul 2003 10:23:24 +0000 (10:23 +0000)
committerLuca Padovani <luca.padovani@unito.it>
Thu, 17 Jul 2003 10:23:24 +0000 (10:23 +0000)
helm/gtkmathview-bonobo/test/.cvsignore [new file with mode: 0644]
helm/gtkmathview-bonobo/test/Makefile.am [new file with mode: 0644]
helm/gtkmathview-bonobo/test/main.c [new file with mode: 0644]

diff --git a/helm/gtkmathview-bonobo/test/.cvsignore b/helm/gtkmathview-bonobo/test/.cvsignore
new file mode 100644 (file)
index 0000000..d34cbfb
--- /dev/null
@@ -0,0 +1,5 @@
+.deps
+.libs
+viewer
+Makefile
+makefile.in
diff --git a/helm/gtkmathview-bonobo/test/Makefile.am b/helm/gtkmathview-bonobo/test/Makefile.am
new file mode 100644 (file)
index 0000000..7dd730e
--- /dev/null
@@ -0,0 +1,22 @@
+
+noinst_PROGRAMS = viewer
+
+viewer_SOURCES = main.c
+
+viewer_LDADD = \
+  $(BONOBOUI_LIBS) \
+  $(BONOBO_LIBS) \
+  $(GNOMEUI_LIBS)
+
+AM_CFLAGS = \
+ -DPREFIX=\""$(prefix)"\" \
+ -DSYSCONFDIR=\""$(sysconfdir)"\" \
+ -DDATADIR=\""$(datadir)"\" \
+ -DLIBDIR=\""$(datadir)"\"
+
+INCLUDES = \
+  $(BONOBOUI_CFLAGS) \
+  $(BONOBO_CFLAGS) \
+  $(GNOMEUI_CFLAGS) \
+  -I$(top_srcdir)/src
+
diff --git a/helm/gtkmathview-bonobo/test/main.c b/helm/gtkmathview-bonobo/test/main.c
new file mode 100644 (file)
index 0000000..d0d646a
--- /dev/null
@@ -0,0 +1,234 @@
+
+#include <config.h>
+
+#include <gnome.h>
+#include <bonobo.h>
+#include <glib.h>
+
+#include "control-factory.h"
+
+static GtkWidget *control;
+
+struct FileSelectionInfo {
+  BonoboWidget* control;
+  GtkWidget* widget;
+};
+
+static struct FileSelectionInfo file_selection_info = { NULL, NULL };
+
+static void
+file_selection_ok_cb (GtkWidget *widget,
+                     gpointer data)
+{
+  CORBA_Object interface;
+  const gchar *interface_name;
+  CORBA_Environment ev;
+
+  interface_name = "IDL:Bonobo/PersistFile:1.0";
+
+  CORBA_exception_init (&ev);
+  interface = Bonobo_Unknown_queryInterface (bonobo_widget_get_objref (file_selection_info.control),
+                                            interface_name, &ev);
+  CORBA_exception_free (&ev);
+
+  if (interface == CORBA_OBJECT_NIL)
+    {
+      g_warning ("The Control does not seem to support `%s'.", interface_name);
+    } 
+  else         
+    {
+      const gchar *fname = gtk_file_selection_get_filename (GTK_FILE_SELECTION (file_selection_info.widget));
+      /* load_through_persist_file (fname, interface); */
+      /* todo */
+    }
+  
+  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)
+{
+  GtkWidget    *widget;
+  BonoboWidget *control;
+
+  control = BONOBO_WIDGET (bonobo_window_get_contents (app));
+
+  if (file_selection_info.widget != NULL) {
+    gdk_window_show (GTK_WIDGET (file_selection_info.widget)->window);
+    return;
+  }
+
+  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;
+
+  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);
+}
+
+/* "Open through persist file" dialog.  */
+static void
+open_through_persist_file_cb (GtkWidget *widget,
+                             gpointer data)
+{
+  open_dialog (BONOBO_WINDOW (data));
+}
+
+static void
+exit_cb (GtkWidget *widget,
+        gpointer data)
+{
+  gtk_widget_destroy (GTK_WIDGET (data));
+  bonobo_main_quit ();
+}
+
+static BonoboUIVerb verbs [] = {
+  BONOBO_UI_UNSAFE_VERB ("OpenFile", open_through_persist_file_cb),
+  BONOBO_UI_UNSAFE_VERB ("FileExit", exit_cb),
+
+  BONOBO_UI_VERB_END
+};
+
+/* A dirty, non-translatable hack */
+static char ui [] = 
+"<Root>"
+"      <commands>"
+"              <cmd name=\"FileExit\" _label=\"Exit\" _tip=\"Exit the program\""
+"               pixtype=\"stock\" pixname=\"Exit\" accel=\"*Control*q\"/>"
+"              <cmd name=\"FormatHTML\" _label=\"HTML mode\" type=\"toggle\" _tip=\"HTML Format switch\"/>"
+"      </commands>"
+"      <menu>"
+"              <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\"/>"
+"                      <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\"/>"
+"                      <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>"
+"      </menu>"
+"      <dockitem name=\"Toolbar\" behavior=\"exclusive\">"
+"      </dockitem>"
+"</Root>";
+
+static int
+app_delete_cb (GtkWidget *widget, GdkEvent *event, gpointer dummy)
+{
+  gtk_widget_destroy (GTK_WIDGET (widget));
+  bonobo_main_quit ();
+
+  return FALSE;
+}
+
+static guint
+container_create (void)
+{
+  GtkWidget *win;
+  GtkWindow *window;
+  BonoboUIComponent *component;
+  BonoboUIContainer *container;
+  CORBA_Environment ev;
+
+  win = bonobo_window_new ("test-editor",
+                          "GtkMathView Control Test");
+  window = GTK_WINDOW (win);
+
+  container = bonobo_window_get_ui_container (BONOBO_WINDOW (win));
+
+  g_signal_connect (window, "delete_event", G_CALLBACK (app_delete_cb), NULL);
+
+  gtk_window_set_default_size (window, 600, 440);
+  gtk_window_set_resizable (window, TRUE);
+
+  component = bonobo_ui_component_new ("test");
+  bonobo_running_context_auto_exit_unref (BONOBO_OBJECT (component));
+
+  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)
+    g_error ("Cannot get `%s'.", CONTROL_ID);
+
+  bonobo_window_set_contents (BONOBO_WINDOW (win), control);
+
+  gtk_widget_show_all (GTK_WIDGET (window));
+
+  CORBA_exception_init (&ev);
+
+  return FALSE;
+}
+
+static gint
+load_file (const gchar *fname)
+{
+  CORBA_Object interface;
+  CORBA_Environment ev;
+
+  printf ("loading: %s\n", fname);
+  CORBA_exception_init (&ev);
+  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 */
+
+  return FALSE;
+}
+
+int
+main (int argc, char **argv)
+{
+  gnome_program_init("test-editor", VERSION, LIBGNOMEUI_MODULE, argc, argv, 
+                    GNOME_PROGRAM_STANDARD_PROPERTIES,
+                    GNOME_PARAM_HUMAN_READABLE_NAME, _("GtkMathView Test Container"),                     
+                    NULL);
+
+  bonobo_activate ();
+
+  /* We can't make any CORBA calls unless we're in the main loop.  So we
+     delay creating the container here. */
+  gtk_idle_add ((GtkFunction) container_create, NULL);
+  if (argc > 1 && *argv [argc - 1] != '-')
+    gtk_idle_add ((GtkFunction) load_file, argv [argc - 1]);
+
+  bonobo_activate ();
+  bonobo_main ();
+
+  return bonobo_ui_debug_shutdown ();
+}