+struct _Component {
+ Container *container;
+
+ BonoboClientSite *client_site;
+ BonoboViewFrame *view_frame;
+ BonoboObjectClient *server;
+};
+
+GList *containers = NULL;
+/*
+ * Static prototypes.
+ */
+extern "C" {
+ static Container *container_new (const char *fname);
+ static void container_destroy (Container *cont);
+ static void container_open_cmd (GtkWidget *widget, Container *container);
+ static void container_close_cmd (GtkWidget *widget, Container *container);
+ static void container_exit_cmd (void);
+ static void container_about_cmd (GtkWidget *widget, Container *container);
+ static Component *container_activate_component (Container *container, char *component_goad_id);
+}
+
+/*
+ * The menus.
+ */
+static GnomeUIInfo container_file_menu [] = {
+ GNOMEUIINFO_MENU_OPEN_ITEM (container_open_cmd, NULL),
+ GNOMEUIINFO_SEPARATOR,
+ GNOMEUIINFO_MENU_CLOSE_ITEM(container_close_cmd, NULL),
+ GNOMEUIINFO_SEPARATOR,
+ GNOMEUIINFO_MENU_EXIT_ITEM (container_exit_cmd, NULL),
+ GNOMEUIINFO_END
+};
+
+static GnomeUIInfo container_help_menu [] = {
+ GNOMEUIINFO_MENU_ABOUT_ITEM(container_about_cmd, NULL),
+ GNOMEUIINFO_END
+};
+
+static GnomeUIInfo container_main_menu [] = {
+ GNOMEUIINFO_MENU_FILE_TREE (container_file_menu),
+ GNOMEUIINFO_MENU_HELP_TREE (container_help_menu),
+ GNOMEUIINFO_END
+};
+
+static GnomeUIInfo container_toolbar [] = {
+ GNOMEUIINFO_ITEM_STOCK (
+ N_("Open"), N_("Opens an existing workbook"),
+ container_open_cmd, GNOME_STOCK_PIXMAP_OPEN),
+
+ GNOMEUIINFO_SEPARATOR,
+ GNOMEUIINFO_END
+};
+
+extern "C" {
+ static gboolean
+ open_pdf (Container *container, const char *name)
+ {
+ BonoboObjectClient *object;
+ BonoboStream *stream;
+ Bonobo_PersistStream persist;
+ Component *comp;
+ CORBA_Environment ev;
+
+ g_return_val_if_fail (container != NULL, FALSE);
+ g_return_val_if_fail (container->view_widget == NULL, FALSE);
+
+#if USING_OAF
+ comp = container_activate_component (container, "OAFIID:gpdf_component:892f2727-e2ec-423c-91ad-6f7b75fec6c8");
+
+#else
+ comp = container_activate_component (container, "bonobo-object:application-x-pdf");
+#endif
+ if (!comp || !(object = comp->server)) {
+ gnome_error_dialog (_("Could not launch bonobo object."));
+ return FALSE;
+ }
+
+ CORBA_exception_init (&ev);
+ persist = Bonobo_Unknown_query_interface (
+ bonobo_object_corba_objref (BONOBO_OBJECT (object)),
+ "IDL:Bonobo/PersistStream:1.0", &ev);
+
+ if (ev._major != CORBA_NO_EXCEPTION ||
+ persist == CORBA_OBJECT_NIL) {
+ gnome_error_dialog ("Panic: component doesn't implement PersistStream.");
+ return FALSE;
+ }
+
+ stream = bonobo_stream_fs_open (name, Bonobo_Storage_READ);
+
+ if (stream == NULL) {
+ char *err = g_strconcat (_("Could not open "), name, NULL);
+ gnome_error_dialog_parented (err, GTK_WINDOW(container->app));
+ g_free (err);
+ return FALSE;
+ }
+
+ Bonobo_PersistStream_load (persist,
+ (Bonobo_Stream) bonobo_object_corba_objref (BONOBO_OBJECT (stream)),
+ "application/pdf",
+ &ev);
+
+ Bonobo_Unknown_unref (persist, &ev);
+ CORBA_Object_release (persist, &ev);
+ CORBA_exception_free (&ev);