]> www.fi.muni.cz Git - evince.git/blobdiff - pdf/xpdf/gpdf.cc
Clean some redundant code.
[evince.git] / pdf / xpdf / gpdf.cc
index 05bdad905876f017db24918243fe1aad24710722..69c1ab2294951dec91f31e70f11cf0bba324d66d 100644 (file)
@@ -64,7 +64,6 @@ struct _Container {
   GtkScrolledWindow *scroll;
   GtkWidget        *view_widget;
   Component         *component;
-  gdouble zoom;
 };
 
 struct  _Component {
@@ -85,10 +84,8 @@ extern "C" {
   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);
-  static void       zoom_in_cmd         (GtkWidget *widget, Container *container);
-  static void       zoom_out_cmd        (GtkWidget *widget, Container *container);
-  static void       zoom_set            (Container *container);
 }
 
 /*
@@ -103,19 +100,14 @@ static GnomeUIInfo container_file_menu [] = {
        GNOMEUIINFO_END
 };
 
-static GnomeUIInfo container_menu_zoom [] = {
-       { GNOME_APP_UI_ITEM, N_("_Zoom in"),
-         N_("Increase the size of objects in the PDF"),
-         zoom_in_cmd },
-       { GNOME_APP_UI_ITEM, N_("_Zoom out"),
-         N_("Decrease the size of objects in the PDF"),
-         zoom_out_cmd },
+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),
-       { GNOME_APP_UI_SUBTREE, N_("_Zoom"), NULL, container_menu_zoom },
+       GNOMEUIINFO_MENU_HELP_TREE (container_help_menu),
        GNOMEUIINFO_END
 };
 
@@ -141,7 +133,7 @@ extern "C" {
     g_return_val_if_fail (container != NULL, FALSE);
     g_return_val_if_fail (container->view_widget == NULL, FALSE);
 
-    comp = container_activate_component (container, "bonobo-object:image-x-pdf");
+    comp = container_activate_component (container, "bonobo-object:application-x-pdf");
     if (!comp || !(object = comp->server)) {
       gnome_error_dialog (_("Could not launch bonobo object."));
       return FALSE;
@@ -170,11 +162,11 @@ extern "C" {
     GNOME_PersistStream_load (persist,
                              (GNOME_Stream) gnome_object_corba_objref (GNOME_OBJECT (stream)), &ev);
 
-    zoom_set (container);
-        
     GNOME_Unknown_unref (persist, &ev);
     CORBA_Object_release (persist, &ev);
     CORBA_exception_free (&ev);
+
+/*    gnome_view_frame_view_do_verb (comp->view_frame, "ZoomFit"); */
     return TRUE;
   }
   
@@ -229,8 +221,10 @@ extern "C" {
        char *fname = g_strdup (name);
        if (container->view_widget) /* any sort of MDI sucks :-] */
          container = container_new (fname);
-       else
-         open_pdf (container, fname);
+       else {
+         if (!open_pdf (container, fname))
+           container_destroy (container);
+       }
        g_free (fname);
       } else {
        GtkWidget *dialog;
@@ -246,11 +240,35 @@ extern "C" {
     gtk_widget_destroy (GTK_WIDGET (fsel));
   }
 
+  static void 
+  component_destroy (Component *component)
+  {
+    CORBA_Environment ev;
+    g_return_if_fail (component != NULL);
+
+    CORBA_exception_init (&ev);
+    
+    if (component->server)
+      GNOME_Unknown_unref (
+       gnome_object_corba_objref (GNOME_OBJECT (component->server)), &ev);
+    component->server = NULL;
+
+    CORBA_exception_free (&ev);
+  }
+
   static void
   container_destroy (Container *cont)
   {
     containers = g_list_remove (containers, cont);
-    gtk_widget_destroy (cont->app);
+    if (cont->app)
+      gtk_widget_destroy (cont->app);
+    
+    if (cont->component)
+      component_destroy (cont->component);
+    cont->component = NULL;
+    
+    cont->app = NULL;
+    
     g_free (cont);
     if (!containers)
       gtk_main_quit ();
@@ -269,38 +287,34 @@ extern "C" {
       container_destroy ((Container *)containers->data);
   }
 
-  /*
-   * Enforces the containers zoom factor.
-   */
-  static void
-  zoom_set (Container *container)
-  {
-    g_return_if_fail (container != NULL);
-    g_return_if_fail (container->component != NULL);
-
-    gnome_view_frame_set_zoom_factor (container->component->view_frame,
-                                     container->zoom);
-  }
-
-  static void
-  zoom_in_cmd (GtkWidget *widget, Container *container)
-  {
-    g_return_if_fail (container != NULL);
-    if (container->zoom < 180.0) {
-      container->zoom *= 1.4;
-      zoom_set (container);
-    }
-  }
 
-  static void
-  zoom_out_cmd (GtkWidget *widget, Container *container)
-  {
-    g_return_if_fail (container != NULL);
-    if (container->zoom > 10.0) {
-      container->zoom /= 1.4;
-      zoom_set (container);
-    }
-  }
+static void
+container_about_cmd (GtkWidget *widget, Container *container)
+{
+  GtkWidget *about;
+  int i;
+
+  const gchar *authors[] = {
+    N_("Derek B. Noonburg, main author"),
+    N_("Michael Meeks, GNOME port maintainer."),
+    N_("Miguel de Icaza."),
+    N_("Nat Friedman."),
+    NULL
+  };
+  
+#ifdef ENABLE_NLS
+  for (i = 0; authors[i] != NULL; i++)
+    authors [i] = _(authors [i]);
+#endif
+  
+  about = gnome_about_new (_("GPDF"), VERSION,
+                          _("(C) 1996-1999 Derek B. Noonburg."),
+                          authors, NULL, NULL);
+  
+  gnome_dialog_set_parent (GNOME_DIALOG (about), GTK_WINDOW (container->app));
+  gnome_dialog_set_close (GNOME_DIALOG (about), TRUE);
+  gtk_widget_show (about);
+}
 }
 
 static void
@@ -380,33 +394,6 @@ container_launch_component (GnomeClientSite *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;
-
-       CORBA_exception_init (&ev);
-
-       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;
-}
-
 extern "C" {
   static Component *
   container_activate_component (Container *container, char *component_goad_id)
@@ -522,7 +509,6 @@ container_new (const char *fname)
 
        container->app  = gnome_app_new ("pdf-viewer",
                                         "GNOME PDF viewer");
-       container->zoom = 86.0;
 
        gtk_drag_dest_set (container->app,
                           GTK_DEST_DEFAULT_ALL,
@@ -574,9 +560,10 @@ int
 main (int argc, char **argv)
 {
   CORBA_Environment ev;
-  CORBA_ORB orb;
-  char **view_files = NULL;
-  int    i;
+  CORBA_ORB         orb;
+  char            **view_files = NULL;
+  gboolean          loaded;
+  int               i;
   
   CORBA_exception_init (&ev);
   
@@ -597,11 +584,13 @@ main (int argc, char **argv)
 
   /* Load files */
   i = 0;
+  loaded = FALSE;
   if (view_files) {
     for (i = 0; view_files[i]; i++)
-      container_new (view_files[i]);
+      if (container_new (view_files[i]))
+       loaded = TRUE;
   }
-  if (i == 0)
+  if ((i == 0) || !loaded)
     container_new (NULL);
   
   poptFreeContext (ctx);