From 8004ad69750afcf6e42f969fb579cf6bc9acf64d Mon Sep 17 00:00:00 2001 From: Luca Padovani Date: Thu, 17 Jul 2003 10:23:24 +0000 Subject: [PATCH] * added simple test program --- helm/gtkmathview-bonobo/test/.cvsignore | 5 + helm/gtkmathview-bonobo/test/Makefile.am | 22 +++ helm/gtkmathview-bonobo/test/main.c | 234 +++++++++++++++++++++++ 3 files changed, 261 insertions(+) create mode 100644 helm/gtkmathview-bonobo/test/.cvsignore create mode 100644 helm/gtkmathview-bonobo/test/Makefile.am create mode 100644 helm/gtkmathview-bonobo/test/main.c diff --git a/helm/gtkmathview-bonobo/test/.cvsignore b/helm/gtkmathview-bonobo/test/.cvsignore new file mode 100644 index 000000000..d34cbfb4f --- /dev/null +++ b/helm/gtkmathview-bonobo/test/.cvsignore @@ -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 index 000000000..7dd730e7e --- /dev/null +++ b/helm/gtkmathview-bonobo/test/Makefile.am @@ -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 index 000000000..d0d646a94 --- /dev/null +++ b/helm/gtkmathview-bonobo/test/main.c @@ -0,0 +1,234 @@ + +#include + +#include +#include + +#include + +#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 [] = +"" +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +""; + +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 (); +} -- 2.39.2