-//------------------------------------------------------------------------
-// loadFile / displayPage
-//------------------------------------------------------------------------
-
-static gint
-doc_config_event (GtkWidget *widget, void *ugly)
-{
- DOC_ROOT *doc = hack_global;
-
- g_return_val_if_fail (doc, FALSE);
- g_return_val_if_fail (doc->magic == DOC_ROOT_MAGIC, FALSE);
-
- if (doc->pixmap)
- gdk_pixmap_unref(doc->pixmap);
-
- doc->pixmap = gdk_pixmap_new(widget->window,
- widget->allocation.width,
- widget->allocation.height,
- -1);
-
- printf ("Creating pixmap of size %d %d\n",
- widget->allocation.width, widget->allocation.height);
- gdk_color_white (gtk_widget_get_default_colormap(), &doc->paper);
- doc->out = new GOutputDev (doc->pixmap, doc->paper);
+extern "C" {
+ static void
+ open_pdf (Container *container, const char *name)
+ {
+ GnomeObjectClient *object;
+ GnomeStream *stream;
+ GNOME_PersistStream persist;
+ Component *comp;
+ CORBA_Environment ev;
+
+ comp = container_activate_component (container, "bonobo-object:image-x-pdf");
+ if (!comp || !(object = comp->server)) {
+ gnome_error_dialog (_("Could not launch bonobo object."));
+ return;
+ }
+
+ CORBA_exception_init (&ev);
+ persist = GNOME_Unknown_query_interface (
+ gnome_object_corba_objref (GNOME_OBJECT (object)),
+ "IDL:GNOME/PersistStream:1.0", &ev);
+
+ if (ev._major != CORBA_NO_EXCEPTION ||
+ persist == CORBA_OBJECT_NIL) {
+ gnome_error_dialog ("Panic: component is well broken.");
+ return;
+ }
+
+ stream = gnome_stream_fs_open (name, GNOME_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;
+ }
+
+ GNOME_PersistStream_load (persist,
+ (GNOME_Stream) gnome_object_corba_objref (GNOME_OBJECT (stream)), &ev);
+
+ GNOME_Unknown_unref (persist, &ev);
+ CORBA_Object_release (persist, &ev);
+ CORBA_exception_free (&ev);
+/* app->contains_pdf = TRUE; */
+ }
+
+ static void
+ set_ok (GtkWidget *widget, gboolean *dialog_result)
+ {
+ *dialog_result = TRUE;
+ gtk_main_quit ();
+ }
+
+ static guint
+ file_dialog_delete_event (GtkWidget *widget, GdkEventAny *event)
+ {
+ gtk_main_quit ();
+ return TRUE;
+ }
+
+ static void
+ container_open_cmd (GtkWidget *widget, Container *app)
+ {
+ GtkFileSelection *fsel;
+ gboolean accepted = FALSE;
+
+ fsel = GTK_FILE_SELECTION (gtk_file_selection_new (_("Load file")));
+ gtk_window_set_modal (GTK_WINDOW (fsel), TRUE);
+
+ gtk_window_set_transient_for (GTK_WINDOW (fsel),
+ GTK_WINDOW (app->app));
+
+ /* Connect the signals for Ok and Cancel */
+ gtk_signal_connect (GTK_OBJECT (fsel->ok_button), "clicked",
+ GTK_SIGNAL_FUNC (set_ok), &accepted);
+ gtk_signal_connect (GTK_OBJECT (fsel->cancel_button), "clicked",
+ GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
+ gtk_window_set_position (GTK_WINDOW (fsel), GTK_WIN_POS_MOUSE);
+
+ /*
+ * Make sure that we quit the main loop if the window is destroyed
+ */
+ gtk_signal_connect (GTK_OBJECT (fsel), "delete_event",
+ GTK_SIGNAL_FUNC (file_dialog_delete_event), NULL);
+
+ /* Run the dialog */
+ gtk_widget_show (GTK_WIDGET (fsel));
+ gtk_grab_add (GTK_WIDGET (fsel));
+ gtk_main ();
+
+ if (accepted) {
+ char *name = gtk_file_selection_get_filename (fsel);
+
+ if (name [strlen (name)-1] != '/') {
+/* if (app->contains_pdf)
+ app = application_new ();*/
+ char *fname = g_strdup (name);
+ open_pdf (app, fname);
+ g_free (fname);
+ } else {
+ GtkWidget *dialog;
+ dialog = gnome_message_box_new ("Can't open a directory",
+ GNOME_MESSAGE_BOX_ERROR,
+ GNOME_STOCK_BUTTON_OK, NULL);
+ gnome_dialog_set_parent (GNOME_DIALOG (dialog),
+ GTK_WINDOW (app->app));
+ gnome_dialog_run (GNOME_DIALOG (dialog));
+ }
+ }
+
+ gtk_widget_destroy (GTK_WIDGET (fsel));
+ }