]> www.fi.muni.cz Git - evince.git/blobdiff - pdf/xpdf/gpdf.cc
more sensible menu merging.
[evince.git] / pdf / xpdf / gpdf.cc
index da85e0fc4616514c73b426f4bf28baa05122c799..d77db661418a5c973c1dc39776afabc712a7c426 100644 (file)
@@ -1,21 +1,25 @@
-//========================================================================
-//
-// gpdf.cc
-//
-// Copyright 1996 Derek B. Noonburg
-// Copyright 1999 Michael Meeks.
-// Copyright 1999 Miguel de Icaza
-//
-//========================================================================
-
+/*
+ * PDF viewer Bonobo container.
+ *
+ * Author:
+ *   Michael Meeks <michael@imaginator.com>
+ *
+ */
 #include <stdio.h>
 #include <stdlib.h>
 #include <stddef.h>
 #include <string.h>
+extern "C" {
 #define GString G_String
 #include <gnome.h>
-#include <glade/glade.h>
+#include <libgnorba/gnorba.h>
+#include <gdk/gdkprivate.h>
+#include <gdk/gdkx.h>
+#include <bonobo/gnome-bonobo.h>
 #undef  GString 
+}
+#include <sys/stat.h>
+#include <unistd.h>
 #include "gtypes.h"
 #include "GString.h"
 #include "parseargs.h"
 #include "Error.h"
 #include "config.h"
 
-GBool printCommands = gFalse;
-gint  gpdf_debug=1;
 poptContext ctx;
-
-#define DEV_DEBUG 0
-
-#define DOC_ROOT_TAG "xpdf_doc_root"
-struct DOC_ROOT {
-  GString        *title;
-  PDFDoc         *pdf;
-  Catalog        *cat;
-  GtkDrawingArea *area;
-  GtkPixmap      *pixmap;
-  OutputDev      *out;
-  GdkColor        paper;
-  GtkScrolledWindow *scroll;
-  GtkWidget      *mainframe;
-  GladeXML       *gui;
-
-  double          zoom;
-  gint            page;
-};
-
-GList *documents = NULL;
+gint  gpdf_debug=1;
 
 const struct poptOption gpdf_popt_options [] = {
   { "debug", '\0', POPT_ARG_INT, &gpdf_debug, 0,
@@ -68,322 +50,584 @@ const struct poptOption gpdf_popt_options [] = {
   { NULL, '\0', 0, NULL, 0 }
 };
 
-extern "C" {
-  static void connect_signals (DOC_ROOT *doc);
-}
-
-//------------------------------------------------------------------------
-// loadFile / displayPage
-//------------------------------------------------------------------------
-
-static GtkPixmap *
-setup_pixmap (DOC_ROOT *doc, GdkWindow *window)
-{
-  GdkGCValues  gcValues;
-  GdkGC       *strokeGC;
-  PDFDoc      *pdf = doc->pdf;
-  int          w, h;
-  GdkPixmap   *pixmap = NULL;
-
-  w = (int)((pdf->getPageWidth  (doc->page) * doc->zoom) / 72.0);
-  h = (int)((pdf->getPageHeight (doc->page) * doc->zoom) / 72.0);
-
-  pixmap = gdk_pixmap_new (window, w, h, -1);
-
-  gdk_color_white (gtk_widget_get_default_colormap(), &doc->paper);
-  doc->out    = new GOutputDev (pixmap, doc->paper, window);
-
-  gdk_color_white (gtk_widget_get_default_colormap (), &gcValues.foreground);
-  gdk_color_black (gtk_widget_get_default_colormap (), &gcValues.background);
-  gcValues.line_width = 1;
-  gcValues.line_style = GDK_LINE_SOLID;
-  strokeGC = gdk_gc_new_with_values (
-    pixmap, &gcValues, 
-    (enum GdkGCValuesMask)(GDK_GC_FOREGROUND | GDK_GC_BACKGROUND | GDK_GC_LINE_WIDTH | GDK_GC_LINE_STYLE));
-  
-  gdk_draw_rectangle (pixmap, strokeGC,
-                     TRUE, 0, 0,
-                     w, h);
-
-  return GTK_PIXMAP (gtk_pixmap_new (pixmap, NULL));
-}
-
-static void
-render_page (DOC_ROOT *doc)
-{
-  doc->pdf->displayPage(doc->out, doc->page, doc->zoom, 0, gTrue);
-}
-
-/*static void displayPage(int page1, int zoom1, int rotate1) {
-  char s[20];
-
-  // check for document
-  if (!doc)
-    return;
-
-  // busy cursor
-  if (win)
-    win->setBusyCursor(gTrue);
-
-  // new page/zoom/rotate values
-  page = page1;
-  zoom = zoom1;
-  rotate = rotate1;
-
-  // initialize mouse-related stuff
-  linkAction = NULL;
-  win->setDefaultCursor();
-  linkLabel->setText(NULL);
-  selectXMin = selectXMax = 0;
-  selectYMin = selectYMax = 0;
-  lastDragLeft = lastDragTop = gTrue;
-
-  // draw the page
-  doc->displayPage(out, page, zoomDPI[zoom - minZoom], rotate, gTrue);
-  layoutCbk(win);
-
-  // update page number display
-  sprintf(s, "%d", page);
-  pageNumText->setText(s);
+typedef struct {
+       GnomeContainer  *container;
+       GnomeUIHandler  *uih;
 
-  // back to regular cursor
-  win->setBusyCursor(gFalse);
-  }*/
+       GnomeViewFrame  *active_view_frame;
 
-static PDFDoc *
-getPDF (GString *fname)
-{
-  PDFDoc *pdf;
-  pdf = new PDFDoc(fname);
-  if (!pdf->isOk()) {
-    delete pdf;
-    return NULL;
-  }
-  g_return_val_if_fail (pdf->getCatalog(), NULL);
-  return pdf;
-}
+       GtkWidget       *app;
+       GtkWidget       *vbox;
+} Container;
 
-static DOC_ROOT *
-doc_root_new (GString *fileName)
-{
-  DOC_ROOT *doc = new DOC_ROOT();
-  GtkVBox  *pane;
-
-  // open PDF file
-  doc->pdf = getPDF (fileName);
-  if (!doc->pdf) {
-    delete doc;
-    return NULL;
-  }
+typedef struct {
+       Container         *container;
 
-  doc->gui = glade_xml_new (GPDF_GLADE_DIR "/gpdf.glade", NULL);
-  if (!doc->gui ||
-      !(doc->mainframe = glade_xml_get_widget (doc->gui, "gpdf")) ||
-      !(pane = GTK_VBOX (glade_xml_get_widget (doc->gui, "pane")))) {
-    printf ("Couldn't find " GPDF_GLADE_DIR "/gpdf.glade\n");
-    delete doc->pdf;
-    delete doc;
-    return NULL;
-  }
-
-  doc->zoom = 86.0;
-  doc->page = 1;
+       GnomeClientSite   *client_site;
+       GnomeViewFrame    *view_frame;
+       GnomeObjectClient *server;
 
-  connect_signals (doc);
+       GtkWidget         *views_hbox;
+} Component;
 
-  gtk_object_set_data (GTK_OBJECT (doc->mainframe), DOC_ROOT_TAG, doc);
-
-  doc->pixmap = setup_pixmap (doc, gtk_widget_get_parent_window (GTK_WIDGET (pane)));
-  
-  doc->scroll = GTK_SCROLLED_WINDOW (gtk_scrolled_window_new (NULL, NULL));
-  gtk_scrolled_window_set_policy (doc->scroll, GTK_POLICY_AUTOMATIC,
-                                 GTK_POLICY_AUTOMATIC);
-  render_page (doc);
-  gtk_scrolled_window_add_with_viewport (doc->scroll, GTK_WIDGET (doc->pixmap));
-  gtk_box_pack_start (GTK_BOX (pane), GTK_WIDGET (doc->scroll), TRUE, TRUE, 0);
-
-  gtk_widget_show_all (doc->mainframe);
-
-  documents = g_list_append (documents, doc);
-
-  return doc;
+GList *containers = NULL;
+/*
+ * Static prototypes.
+ */
+extern "C" {
+  static Container *container_new       (void);
+  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 Component *container_activate_component (Container *container, char *component_goad_id);
 }
 
-static void
-doc_root_destroy (DOC_ROOT *doc)
-{
-    gtk_widget_destroy (doc->mainframe);
-    gtk_object_destroy (GTK_OBJECT (doc->gui));
-    
-    documents = g_list_remove (documents, doc);
-    if (g_list_length (documents) == 0)
-      gtk_main_quit ();
-    delete (doc);
-}
+/*
+ * 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
+};
 
-//------------------------------------------------------------------------
-//                          Signal handlers
-//------------------------------------------------------------------------
+static GnomeUIInfo container_main_menu [] = {
+       GNOMEUIINFO_MENU_FILE_TREE (container_file_menu),
+       GNOMEUIINFO_END
+};
 
 extern "C" {
-  void
-  do_close (GtkWidget *menuitem, DOC_ROOT *doc)
-  {
-    doc_root_destroy (doc);
-  }
-
-  void
-  do_exit (GtkWidget *menuitem, DOC_ROOT *doc)
+  static void
+  open_pdf (Container *container, const char *name)
   {
-    GList *l;
-    while ((l=documents))
-      doc_root_destroy ((DOC_ROOT *)l->data);
+    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
-  do_about_box (GtkWidget *w, DOC_ROOT *doc)
+  set_ok (GtkWidget *widget, gboolean *dialog_result)
   {
-    GladeXML *gui = glade_xml_new (GPDF_GLADE_DIR "/about.glade", NULL);
-    g_return_if_fail (gui);
-    GtkWidget *wi = glade_xml_get_widget (gui, "about_box");
-    g_return_if_fail (wi);
-    gtk_widget_show  (wi);
-    gtk_object_destroy (GTK_OBJECT (gui));
+    *dialog_result = TRUE;
+    gtk_main_quit ();
   }
-
-  static void
-  do_forward_button (GtkWidget *w, DOC_ROOT *doc)
+  
+  static guint
+  file_dialog_delete_event (GtkWidget *widget, GdkEventAny *event)
   {
-    if (doc->page < doc->pdf->getNumPages()) {
-      doc->page++;
-      render_page (doc);
-      gtk_widget_queue_draw (GTK_WIDGET (doc->scroll));
-    }
+    gtk_main_quit ();
+    return TRUE;
   }
-
+  
   static void
-  do_back_button (GtkWidget *w, DOC_ROOT *doc)
+  container_open_cmd (GtkWidget *widget, Container *app)
   {
-    if (doc->page > 1) {
-      doc->page--;
-      render_page (doc);
-      gtk_widget_queue_draw (GTK_WIDGET (doc->pixmap));
+    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));
   }
 
   static void
-  do_first_button (GtkWidget *w, DOC_ROOT *doc)
+  container_destroy (Container *cont)
   {
-    if (doc->page != 1) {
-      doc->page = 1;
-      render_page (doc);
-      gtk_widget_queue_draw (GTK_WIDGET (doc->pixmap));
-    }
+    containers = g_list_remove (containers, cont);
+    gtk_widget_destroy (cont->app);
+    g_free (cont);
+    if (!containers)
+      gtk_main_quit ();
   }
-
+  
   static void
-  do_last_button (GtkWidget *w, DOC_ROOT *doc)
+  container_close_cmd (GtkWidget *widget, Container *cont)
   {
-    if (doc->page != doc->pdf->getNumPages()) {
-      doc->page = doc->pdf->getNumPages();
-      render_page (doc);
-      gtk_widget_queue_draw (GTK_WIDGET (doc->pixmap));
-    }
+    container_destroy (cont);
   }
-
+  
   static void
-  do_larger_button (GtkWidget *w, DOC_ROOT *doc)
+  container_exit_cmd (void)
   {
-    if (doc->zoom < 200) {
-      doc->zoom *= 1.2;
-      render_page (doc);
-      gtk_widget_queue_draw (GTK_WIDGET (doc->pixmap));
-    }
+    while (containers)
+      container_destroy ((Container *)containers->data);
   }
 
   static void
-  do_smaller_button (GtkWidget *w, DOC_ROOT *doc)
+  component_user_activate_request_cb (GnomeViewFrame *view_frame, gpointer data)
   {
-    if (doc->zoom < 200) {
-      doc->zoom /= 1.2;
-      render_page (doc);
-      gtk_widget_queue_draw (GTK_WIDGET (doc->pixmap));
+    Component *component = (Component *) data;
+    Container *container = component->container;
+    
+    /*
+     * If there is a
+     * If there is already an active View, deactivate it.
+     */
+    if (container->active_view_frame != NULL) {
+      /*
+       * This just sends a notice to the embedded View that
+       * it is being deactivated.  We will also forcibly
+       * cover it so that it does not receive any Gtk
+       * events.
+       */
+      gnome_view_frame_view_deactivate (container->active_view_frame);
+      
+      /*
+       * Here we manually cover it if it hasn't acquiesced.
+       * If it has consented to be deactivated, then it will
+       * already have notified us that it is inactive, and
+       * we will have covered it and set active_view_frame
+       * to NULL.  Which is why this check is here.
+       */
+      if (container->active_view_frame != NULL)
+       gnome_view_frame_set_covered (container->active_view_frame, TRUE);
+      
+      container->active_view_frame = NULL;
     }
+    
+    /*
+     * Activate the View which the user clicked on.  This just
+     * sends a request to the embedded View to activate itself.
+     * When it agrees to be activated, it will notify its
+     * ViewFrame, and our view_activated_cb callback will be
+     * called.
+     *
+     * We do not uncover the View here, because it may not wish to
+     * be activated, and so we wait until it notifies us that it
+     * has been activated to uncover it.
+     */
+    gnome_view_frame_view_activate (view_frame);
   }
   
   static void
-  simple_menu_connect (DOC_ROOT *doc, const char *name, GtkSignalFunc func)
+  component_view_activated_cb (GnomeViewFrame *view_frame, gboolean activated, gpointer data)
   {
-    GtkWidget *w;
-    w = glade_xml_get_widget (doc->gui, name);
-    g_return_if_fail (w);
-    gtk_signal_connect (GTK_OBJECT (w), "activate", func, doc);
+    Component *component = (Component *) data;
+    Container *container = component->container;
+    
+    if (activated) {
+      /*
+       * If the View is requesting to be activated, then we
+       * check whether or not there is already an active
+       * View.
+       */
+      if (container->active_view_frame != NULL) {
+       g_warning ("View requested to be activated but there is already "
+                  "an active View!\n");
+       return;
+      }
+      
+      /*
+       * Otherwise, uncover it so that it can receive
+       * events, and set it as the active View.
+       */
+      gnome_view_frame_set_covered (view_frame, FALSE);
+      container->active_view_frame = view_frame;
+    } else {
+      /*
+       * If the View is asking to be deactivated, always
+       * oblige.  We may have already deactivated it (see
+       * user_activation_request_cb), but there's no harm in
+       * doing it again.  There is always the possibility
+       * that a View will ask to be deactivated when we have
+       * not told it to deactivate itself, and that is
+       * why we cover the view here.
+       */
+      gnome_view_frame_set_covered (view_frame, TRUE);
+      
+      if (view_frame == container->active_view_frame)
+       container->active_view_frame = NULL;
+    }                                                                       
   }
   
   static void
-  simple_button_connect (DOC_ROOT *doc, const char *name, GtkSignalFunc func)
+  component_user_context_cb (GnomeViewFrame *view_frame, gpointer data)
   {
-    GtkWidget *w;
-    w = glade_xml_get_widget (doc->gui, name);
-    g_return_if_fail (w);
-    gtk_signal_connect (GTK_OBJECT (w), "clicked", func, doc);
+    Component *component = (Component *) data;
+    char *executed_verb;
+    GList *l;
+    
+    /*
+     * See if the remote GnomeEmbeddable supports any verbs at
+     * all.
+     */
+    l = gnome_client_site_get_verbs (component->client_site);
+    if (l == NULL)
+      return;
+    gnome_client_site_free_verbs (l);
+    
+    /*
+     * Popup the verb popup and execute the chosen verb.  This
+     * function saves us the work of creating the menu, connecting
+     * the callback, and executing the verb on the remove
+     * GnomeView.  We could implement all this functionality
+     * ourselves if we wanted.
+     */
+    executed_verb = gnome_view_frame_popup_verbs (view_frame);
+    
+    g_free (executed_verb);
   }
+}
 
-  static void
-  connect_signals (DOC_ROOT *doc)
-  {
-    GtkWidget *w;
-
-    simple_menu_connect (doc, "about_menu", GTK_SIGNAL_FUNC (do_about_box)); 
-    simple_menu_connect (doc, "close_menu", GTK_SIGNAL_FUNC (do_close));
-    simple_menu_connect (doc, "exit_menu",  GTK_SIGNAL_FUNC (do_exit));
-
-    simple_button_connect (doc, "forward", GTK_SIGNAL_FUNC (do_forward_button));
-    simple_button_connect (doc, "back",    GTK_SIGNAL_FUNC (do_back_button));
-    simple_button_connect (doc, "first",   GTK_SIGNAL_FUNC (do_first_button));
-    simple_button_connect (doc, "last",    GTK_SIGNAL_FUNC (do_last_button));
-/*    simple_button_connect (doc, "larger",  GTK_SIGNAL_FUNC (do_larger_button)); need to resize the gtkpixmap...
-      simple_button_connect (doc, "smaller", GTK_SIGNAL_FUNC (do_smaller_button)); but bed first. */
-
-    gtk_signal_connect (GTK_OBJECT (doc->mainframe), "destroy",
-                       GTK_SIGNAL_FUNC (do_close), doc);
- }
+static void
+component_add_view (Component *component)
+{
+       GnomeViewFrame *view_frame;
+       GtkWidget *view_widget;
+
+       /*
+        * Create the remote view and the local ViewFrame.
+        */
+       view_frame = gnome_client_site_embeddable_new_view (component->client_site);
+       component->view_frame = view_frame;
+
+       /*
+        * Set the GnomeUIHandler for this ViewFrame.  That way, the
+        * embedded component can get access to our UIHandler server
+        * so that it can merge menu and toolbar items when it gets
+        * activated.
+        */
+       gnome_view_frame_set_ui_handler (view_frame, component->container->uih);
+
+       /*
+        * Embed the view frame into the application.
+        */
+       view_widget = gnome_view_frame_get_wrapper (view_frame);
+       gtk_box_pack_start (GTK_BOX (component->views_hbox), view_widget,
+                           FALSE, FALSE, 5);
+
+       /*
+        * The "user_activate" signal will be emitted when the user
+        * double clicks on the "cover".  The cover is a transparent
+        * window which sits on top of the component and keeps any
+        * events (mouse, keyboard) from reaching it.  When the user
+        * double clicks on the cover, the container (that's us)
+        * can choose to activate the component.
+        */
+       gtk_signal_connect (GTK_OBJECT (view_frame), "user_activate",
+                           GTK_SIGNAL_FUNC (component_user_activate_request_cb), component);
+
+       /*
+        * In-place activation of a component is a two-step process.
+        * After the user double clicks on the component, our signal
+        * callback (compoennt_user_activate_request_cb()) asks the
+        * component to activate itself (see
+        * gnome_view_frame_view_activate()).  The component can then
+        * choose to either accept or refuse activation.  When an
+        * embedded component notifies us of its decision to change
+        * its activation state, the "view_activated" signal is
+        * emitted from the view frame.  It is at that point that we
+        * actually remove the cover so that events can get through.
+        */
+       gtk_signal_connect (GTK_OBJECT (view_frame), "view_activated",
+                           GTK_SIGNAL_FUNC (component_view_activated_cb), component);
+
+       /*
+        * The "user_context" signal is emitted when the user right
+        * clicks on the wrapper.  We use it to pop up a verb menu.
+        */
+       gtk_signal_connect (GTK_OBJECT (view_frame), "user_context",
+                           GTK_SIGNAL_FUNC (component_user_context_cb), component);
+
+       /*
+        * Show the component.
+        */
+       gtk_widget_show_all (view_widget);
 }
 
-int
-main (int argc, char *argv [])
+static void
+component_new_view_cb (GtkWidget *button, gpointer data)
 {
-  char **view_files = NULL;
-  int    i;
-  
-  gnome_init_with_popt_table (
-    "gpdf", "0.1", argc, argv,
-    gpdf_popt_options, 0, &ctx);
+       Component *component = (Component *) data;
 
-  errorInit();
-  
-  initParams (xpdfConfigFile); /* Init font path */
+       component_add_view (component);
+}
+
+static GnomeObjectClient *
+container_launch_component (GnomeClientSite *client_site,
+                           GnomeContainer *container,
+                           char *component_goad_id)
+{
+       GnomeObjectClient *object_server;
+
+       /*
+        * Launch the component.
+        */
+       object_server = gnome_object_activate_with_goad_id (
+               NULL, component_goad_id, 0, NULL);
+
+       if (object_server == NULL)
+               return NULL;
+
+       /*
+        * Bind it to the local ClientSite.  Every embedded component
+        * has a local GnomeClientSite object which serves as a
+        * container-side point of contact for the embeddable.  The
+        * container talks to the embeddable through its ClientSite
+        */
+       if (!gnome_client_site_bind_embeddable (client_site, object_server)) {
+               gnome_object_unref (GNOME_OBJECT (object_server));
+               return NULL;
+       }
+
+       /*
+        * The GnomeContainer object maintains a list of the
+        * ClientSites which it manages.  Here we add the new
+        * ClientSite to that list.
+        */
+       gnome_container_add (container, GNOME_OBJECT (client_site));
+
+       return object_server;
+}
+
+/*
+ * Use query_interface to see if `obj' has `interface'.
+ */
+static gboolean
+gnome_object_has_interface (GnomeObject *obj, char *interface)
+{
+       CORBA_Environment ev;
+       CORBA_Object requested_interface;
 
-  glade_gnome_init ();
+       CORBA_exception_init (&ev);
 
-  view_files = poptGetArgs (ctx);
-  /* Load files */
-  if (view_files) {
-    for (i = 0; view_files[i]; i++) {
-      GString *name = new GString (view_files[i]);
-      if (!name || !doc_root_new (name))
-       printf ("Error loading '%s'\n", view_files[i]);
+       requested_interface = GNOME_Unknown_query_interface (
+               gnome_object_corba_objref (obj), interface, &ev);
+
+       CORBA_exception_free (&ev);
+
+       if (!CORBA_Object_is_nil(requested_interface, &ev) &&
+           ev._major == CORBA_NO_EXCEPTION)
+       {
+               /* Get rid of the interface we've been passed */
+               CORBA_Object_release (requested_interface, &ev);
+               return TRUE;
+       }
+
+       return FALSE;
+}
+
+static void
+container_create_component_frame (Container *container, Component *component, char *name)
+{
+       /*
+        * This hbox will store all the views of the component.
+        */
+       component->views_hbox = gtk_hbox_new (FALSE, 2);
+
+       gtk_box_pack_start (GTK_BOX (container->vbox), component->views_hbox,
+                           TRUE, FALSE, 5);
+       gtk_widget_show_all (component->views_hbox);
+}
+
+extern "C" {
+  static Component *
+  container_activate_component (Container *container, char *component_goad_id)
+  {
+    Component *component;
+    GnomeClientSite *client_site;
+    GnomeObjectClient *server;
+    
+    /*
+     * The ClientSite is the container-side point of contact for
+     * the Embeddable.  So there is a one-to-one correspondence
+     * between GnomeClientSites and GnomeEmbeddables.  */
+    client_site = gnome_client_site_new (container->container);
+    
+    /*
+     * A GnomeObjectClient is a simple wrapper for a remote
+     * GnomeObject (a server supporting GNOME::Unknown).
+     */
+    server = container_launch_component (client_site, container->container,
+                                        component_goad_id);
+    if (server == NULL) {
+      char *error_msg;
+      
+      error_msg = g_strdup_printf (_("Could not launch Embeddable %s!"),
+                                  component_goad_id);
+      gnome_warning_dialog (error_msg);
+      g_free (error_msg);
+      
+      return NULL;
     }
-  } else {
-    printf ("Need filenames...\n");
-    exit (0);
+    
+    /*
+     * Create the internal data structure which we will use to
+     * keep track of this component.
+     */
+    component = g_new0 (Component, 1);
+    component->container = container;
+    component->client_site = client_site;
+    component->server = server;
+    
+    /*
+     * Now we have a GnomeEmbeddable bound to our local
+     * ClientSite.  Here we create a little on-screen box to store
+     * the embeddable in, when the user adds views for it.
+     */
+    container_create_component_frame (container, component, component_goad_id);
+    
+    component_add_view (component);
+
+    return component;
   }
+}
+
+static void
+container_create_menus (Container *container)
+{
+       GnomeUIHandlerMenuItem *menu_list;
+
+       gnome_ui_handler_create_menubar (container->uih);
+
+       /*
+        * Create the basic menus out of UIInfo structures.
+        */
+       menu_list = gnome_ui_handler_menu_parse_uiinfo_list_with_data (container_main_menu, container);
+       gnome_ui_handler_menu_add_list (container->uih, "/", menu_list);
+       gnome_ui_handler_menu_free_list (menu_list);
+}
+
+static void
+container_create (void)
+{
+       Container *container;
+
+       container = g_new0 (Container, 1);
+
+       container->app = gnome_app_new ("pdf-viewer",
+                                       "GNOME PDF viewer");
+
+       gtk_window_set_default_size (GTK_WINDOW (container->app), 400, 400);
+       gtk_window_set_policy (GTK_WINDOW (container->app), TRUE, TRUE, FALSE);
+
+       container->container = gnome_container_new ();
+
+       /*
+        * This is the VBox we will stuff embedded components into.
+        */
+       container->vbox = gtk_vbox_new (FALSE, 0);
+       gnome_app_set_contents (GNOME_APP (container->app), container->vbox);
+
+       /*
+        * Create the GnomeUIHandler object which will be used to
+        * create the container's menus and toolbars.  The UIHandler
+        * also creates a CORBA server which embedded components use
+        * to do menu/toolbar merging.
+        */
+       container->uih = gnome_ui_handler_new ();
+       gnome_ui_handler_set_app (container->uih, GNOME_APP (container->app));
+
+       /*
+        * Create the menus.
+        */
+       container_create_menus (container);
+       
+       gtk_widget_show_all (container->app);
+}
+
+int
+main (int argc, char **argv)
+{
+       CORBA_Environment ev;
+       CORBA_ORB orb;
+
+       CORBA_exception_init (&ev);
+
+       gnome_CORBA_init ("gnome_xpdf_viewer", "0.1", &argc, argv, 0, &ev);
+
+       CORBA_exception_free (&ev);
+
+       orb = gnome_CORBA_ORB ();
 
-  poptFreeContext (ctx);
+       if (bonobo_init (orb, NULL, NULL) == FALSE)
+               g_error (_("Could not initialize Bonobo!\n"));
 
-  gtk_main ();
+       container_create ();
 
-  freeParams();
+       gtk_main ();
 
-  /* Destroy files */
+       return 0;
 }