]> www.fi.muni.cz Git - evince.git/blobdiff - pdf/xpdf/gpdf.cc
Gesture support + various improvements.
[evince.git] / pdf / xpdf / gpdf.cc
index 0db774b6caf3e07ecad4c60bb626f90409501478..02c9dc3077f646e0f5dc490fb1317e4c85dd6472 100644 (file)
@@ -18,28 +18,8 @@ extern "C" {
 #include <bonobo/gnome-bonobo.h>
 #undef  GString 
 }
 #include <bonobo/gnome-bonobo.h>
 #undef  GString 
 }
-#include <sys/stat.h>
-#include <unistd.h>
-#include "gtypes.h"
-#include "GString.h"
-#include "parseargs.h"
-#include "gfile.h"
-#include "gmem.h"
-#include "Object.h"
-#include "Stream.h"
-#include "Array.h"
-#include "Dict.h"
-#include "XRef.h"
-#include "Catalog.h"
-#include "Page.h"
-#include "Link.h"
-#include "PDFDoc.h"
-#include "GOutputDev.h"
-#include "PSOutputDev.h"
-#include "TextOutputDev.h"
-#include "Params.h"
-#include "Error.h"
 #include "config.h"
 #include "config.h"
+#include "bonobo-application-x-pdf.h"
 
 poptContext ctx;
 gint  gpdf_debug=0;
 
 poptContext ctx;
 gint  gpdf_debug=0;
@@ -58,13 +38,10 @@ struct _Container {
   GnomeContainer    *container;
   GnomeUIHandler    *uih;
   
   GnomeContainer    *container;
   GnomeUIHandler    *uih;
   
-  GnomeViewFrame    *active_view_frame;
-  
   GtkWidget        *app;
   GtkScrolledWindow *scroll;
   GtkWidget        *view_widget;
   Component         *component;
   GtkWidget        *app;
   GtkScrolledWindow *scroll;
   GtkWidget        *view_widget;
   Component         *component;
-  gdouble zoom;
 };
 
 struct  _Component {
 };
 
 struct  _Component {
@@ -87,9 +64,6 @@ extern "C" {
   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       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);
 }
 
 /*
 }
 
 /*
@@ -104,16 +78,6 @@ static GnomeUIInfo container_file_menu [] = {
        GNOMEUIINFO_END
 };
 
        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 },
-       GNOMEUIINFO_END
-};
-
 static GnomeUIInfo container_help_menu [] = {
         GNOMEUIINFO_MENU_ABOUT_ITEM(container_about_cmd, NULL),
        GNOMEUIINFO_END
 static GnomeUIInfo container_help_menu [] = {
         GNOMEUIINFO_MENU_ABOUT_ITEM(container_about_cmd, NULL),
        GNOMEUIINFO_END
@@ -121,7 +85,6 @@ static GnomeUIInfo container_help_menu [] = {
 
 static GnomeUIInfo container_main_menu [] = {
        GNOMEUIINFO_MENU_FILE_TREE (container_file_menu),
 
 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
 };
        GNOMEUIINFO_MENU_HELP_TREE (container_help_menu),
        GNOMEUIINFO_END
 };
@@ -177,11 +140,11 @@ extern "C" {
     GNOME_PersistStream_load (persist,
                              (GNOME_Stream) gnome_object_corba_objref (GNOME_OBJECT (stream)), &ev);
 
     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_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;
   }
   
     return TRUE;
   }
   
@@ -259,40 +222,72 @@ extern "C" {
   component_destroy (Component *component)
   {
     CORBA_Environment ev;
   component_destroy (Component *component)
   {
     CORBA_Environment ev;
+    Container *container;
     g_return_if_fail (component != NULL);
 
     CORBA_exception_init (&ev);
     g_return_if_fail (component != NULL);
 
     CORBA_exception_init (&ev);
-    
+
+    /* Kill merged menus et al. */
+    gnome_view_frame_view_deactivate (component->view_frame);
+
+    container = component->container;
+    gtk_widget_destroy (container->view_widget);
+    container->view_widget = NULL;
+
     if (component->server)
       GNOME_Unknown_unref (
        gnome_object_corba_objref (GNOME_OBJECT (component->server)), &ev);
     component->server = NULL;
 
     CORBA_exception_free (&ev);
     if (component->server)
       GNOME_Unknown_unref (
        gnome_object_corba_objref (GNOME_OBJECT (component->server)), &ev);
     component->server = NULL;
 
     CORBA_exception_free (&ev);
+
+    g_free (component);
   }
 
   static void
   container_destroy (Container *cont)
   {
   }
 
   static void
   container_destroy (Container *cont)
   {
+    g_return_if_fail (g_list_find (containers, cont) != NULL);
+
     containers = g_list_remove (containers, cont);
     if (cont->app)
       gtk_widget_destroy (cont->app);
     containers = g_list_remove (containers, cont);
     if (cont->app)
       gtk_widget_destroy (cont->app);
+    cont->app = NULL;
     
     if (cont->component)
       component_destroy (cont->component);
     cont->component = NULL;
     
     
     if (cont->component)
       component_destroy (cont->component);
     cont->component = NULL;
     
-    cont->app = NULL;
-    
     g_free (cont);
     g_free (cont);
+
     if (!containers)
       gtk_main_quit ();
   }
     if (!containers)
       gtk_main_quit ();
   }
+
+  static void
+  container_close (Container *cont)
+  {
+    g_return_if_fail (g_list_find (containers, cont) != NULL);
+    
+    if (cont->component) {
+      component_destroy (cont->component);
+      cont->component = NULL;
+    } else
+      container_destroy (cont);
+  }
+
   
   static void
   container_close_cmd (GtkWidget *widget, Container *cont)
   
   static void
   container_close_cmd (GtkWidget *widget, Container *cont)
+  {
+    container_close (cont);
+  }
+  
+  static int
+  container_destroy_cb (GtkWidget *widget, GdkEvent *event, Container *cont)
   {
     container_destroy (cont);
   {
     container_destroy (cont);
+    return 1;
   }
   
   static void
   }
   
   static void
@@ -302,7 +297,6 @@ extern "C" {
       container_destroy ((Container *)containers->data);
   }
 
       container_destroy ((Container *)containers->data);
   }
 
-
 static void
 container_about_cmd (GtkWidget *widget, Container *container)
 {
 static void
 container_about_cmd (GtkWidget *widget, Container *container)
 {
@@ -310,6 +304,7 @@ container_about_cmd (GtkWidget *widget, Container *container)
   int i;
 
   const gchar *authors[] = {
   int i;
 
   const gchar *authors[] = {
+    N_("Derek B. Noonburg, main author"),
     N_("Michael Meeks, GNOME port maintainer."),
     N_("Miguel de Icaza."),
     N_("Nat Friedman."),
     N_("Michael Meeks, GNOME port maintainer."),
     N_("Miguel de Icaza."),
     N_("Nat Friedman."),
@@ -329,39 +324,6 @@ container_about_cmd (GtkWidget *widget, Container *container)
   gnome_dialog_set_close (GNOME_DIALOG (about), TRUE);
   gtk_widget_show (about);
 }
   gnome_dialog_set_close (GNOME_DIALOG (about), TRUE);
   gtk_widget_show (about);
 }
-
-  /*
-   * 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
 }
 
 static void
@@ -400,6 +362,7 @@ container_set_view (Container *container, Component *component)
         * Activate it ( get it to merge menus etc. )
         */
        gnome_view_frame_view_activate (view_frame);
         * Activate it ( get it to merge menus etc. )
         */
        gnome_view_frame_view_activate (view_frame);
+       gnome_view_frame_set_covered   (view_frame, FALSE);
 
        gtk_widget_show_all (GTK_WIDGET (container->scroll));
 }
 
        gtk_widget_show_all (GTK_WIDGET (container->scroll));
 }
@@ -441,33 +404,6 @@ container_launch_component (GnomeClientSite *client_site,
        return object_server;
 }
 
        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)
 extern "C" {
   static Component *
   container_activate_component (Container *container, char *component_goad_id)
@@ -541,6 +477,107 @@ extern "C" {
       tmp_list = g_list_next (tmp_list);
     }
   }
       tmp_list = g_list_next (tmp_list);
     }
   }
+  
+  /*
+   * GtkWidget key_press method override
+   *
+   * Scrolls the window on keypress
+   */
+  static gint
+  key_press_event_cb (GtkWidget *widget, GdkEventKey *event)
+  {
+    Container *container = (Container *) gtk_object_get_data (GTK_OBJECT (widget), "container_data");
+    Component *component;
+    GtkScrolledWindow *win;
+    float              delta;
+
+    g_return_val_if_fail (container != NULL, FALSE);
+
+    win       = container->scroll;
+    component = container->component;
+    if (component == NULL || win == NULL)
+      return FALSE;
+
+    /*
+     * Scrolling the view.
+     */
+    if (event->keyval == GDK_Up) {
+      GtkAdjustment *adj = gtk_scrolled_window_get_vadjustment (win);
+
+      if (event->state & GDK_CONTROL_MASK)
+       delta = adj->step_increment * 3;
+      else
+       delta = adj->step_increment;
+
+      adj->value = CLAMP (adj->value - delta,
+                         adj->lower, adj->upper - adj->page_size);
+
+      gtk_adjustment_value_changed (adj);
+      return TRUE;
+    } else if (event->keyval == GDK_Down) {
+      GtkAdjustment *adj = gtk_scrolled_window_get_vadjustment (win);
+
+      if (event->state & GDK_CONTROL_MASK)
+       delta = adj->step_increment * 3;
+      else
+       delta = adj->step_increment;
+
+      adj->value = CLAMP (adj->value + delta,
+                         adj->lower, adj->upper - adj->page_size);
+      gtk_adjustment_value_changed (adj);
+      return TRUE;
+    } else if (event->keyval == GDK_Left) {
+      GtkAdjustment *adj = gtk_scrolled_window_get_hadjustment (win);
+
+      if (event->state & GDK_CONTROL_MASK)
+       delta = adj->step_increment * 3;
+      else
+       delta = adj->step_increment;
+
+      adj->value = CLAMP (adj->value - delta,
+                         adj->lower, adj->upper - adj->page_size);
+      gtk_adjustment_value_changed (adj);
+      return TRUE;
+    } else if (event->keyval == GDK_Right) {
+      GtkAdjustment *adj = gtk_scrolled_window_get_hadjustment (win);
+
+      if (event->state & GDK_CONTROL_MASK)
+       delta = adj->step_increment * 3;
+      else
+       delta = adj->step_increment;
+
+      adj->value = CLAMP (adj->value + delta,
+                         adj->lower, adj->upper - adj->page_size);
+      gtk_adjustment_value_changed (adj);
+      return TRUE;
+
+      /*
+       * Various shortcuts mapped to verbs.
+       */
+
+    } else if (event->keyval == GDK_Home) {
+      gnome_view_frame_view_do_verb (component->view_frame, VERB_FIRST);
+      return TRUE;
+    } else if (event->keyval == GDK_End) {
+      gnome_view_frame_view_do_verb (component->view_frame, VERB_LAST);
+      return TRUE;
+    } else if (event->keyval == GDK_Page_Down ||
+              event->keyval == GDK_Next) {
+      gnome_view_frame_view_do_verb (component->view_frame, VERB_NEXT);
+      return TRUE;
+    } else if (event->keyval == GDK_Page_Up ||
+              event->keyval == GDK_Prior) {
+      gnome_view_frame_view_do_verb (component->view_frame, VERB_PREV);
+      return TRUE;
+    } else if (event->keyval == GDK_plus ||
+              event->keyval == GDK_equal) {
+      gnome_view_frame_view_do_verb (component->view_frame, VERB_Z_IN);
+    } else if (event->keyval == GDK_underscore ||
+              event->keyval == GDK_minus) {
+      gnome_view_frame_view_do_verb (component->view_frame, VERB_Z_OUT);
+    }    
+    return FALSE;
+  }
 }
 
 static void
 }
 
 static void
@@ -565,7 +602,7 @@ container_create_toolbar (Container *container)
 
        gnome_ui_handler_create_toolbar (container->uih, "pdf");
        toolbar = gnome_ui_handler_toolbar_parse_uiinfo_list_with_data (container_toolbar, container);
 
        gnome_ui_handler_create_toolbar (container->uih, "pdf");
        toolbar = gnome_ui_handler_toolbar_parse_uiinfo_list_with_data (container_toolbar, container);
-       gnome_ui_handler_toolbar_add_list (container->uih, "/", toolbar);
+       gnome_ui_handler_toolbar_add_list (container->uih, "/pdf/", toolbar);
        gnome_ui_handler_toolbar_free_list (toolbar);
 }
 
        gnome_ui_handler_toolbar_free_list (toolbar);
 }
 
@@ -581,9 +618,8 @@ container_new (const char *fname)
        
        container = g_new0 (Container, 1);
 
        
        container = g_new0 (Container, 1);
 
-       container->app  = gnome_app_new ("pdf-viewer",
+       container->app = gnome_app_new ("pdf-viewer",
                                         "GNOME PDF viewer");
                                         "GNOME PDF viewer");
-       container->zoom = 86.0;
 
        gtk_drag_dest_set (container->app,
                           GTK_DEST_DEFAULT_ALL,
 
        gtk_drag_dest_set (container->app,
                           GTK_DEST_DEFAULT_ALL,
@@ -592,7 +628,8 @@ container_new (const char *fname)
 
        gtk_signal_connect (GTK_OBJECT(container->app),
                            "drag_data_received",
 
        gtk_signal_connect (GTK_OBJECT(container->app),
                            "drag_data_received",
-                           GTK_SIGNAL_FUNC(filenames_dropped), (gpointer)container);
+                           GTK_SIGNAL_FUNC(filenames_dropped),
+                           (gpointer)container);
 
        gtk_window_set_default_size (GTK_WINDOW (container->app), 600, 600);
        gtk_window_set_policy (GTK_WINDOW (container->app), TRUE, TRUE, FALSE);
 
        gtk_window_set_default_size (GTK_WINDOW (container->app), 600, 600);
        gtk_window_set_policy (GTK_WINDOW (container->app), TRUE, TRUE, FALSE);
@@ -600,10 +637,16 @@ container_new (const char *fname)
        container->container   = gnome_container_new ();
        container->view_widget = NULL;
        container->scroll = GTK_SCROLLED_WINDOW (gtk_scrolled_window_new (NULL, NULL));
        container->container   = gnome_container_new ();
        container->view_widget = NULL;
        container->scroll = GTK_SCROLLED_WINDOW (gtk_scrolled_window_new (NULL, NULL));
-       gtk_scrolled_window_set_policy (container->scroll, GTK_POLICY_AUTOMATIC,
-                                       GTK_POLICY_AUTOMATIC);
+       gtk_scrolled_window_set_policy (container->scroll, GTK_POLICY_ALWAYS,
+                                       GTK_POLICY_ALWAYS);
        gnome_app_set_contents (GNOME_APP (container->app), GTK_WIDGET (container->scroll));
 
        gnome_app_set_contents (GNOME_APP (container->app), GTK_WIDGET (container->scroll));
 
+       gtk_object_set_data (GTK_OBJECT (container->app), "container_data", container);
+       gtk_signal_connect  (GTK_OBJECT (container->app), "key_press_event",
+                            GTK_SIGNAL_FUNC (key_press_event_cb), NULL);
+       gtk_signal_connect  (GTK_OBJECT (container->app), "delete_event",
+                            GTK_SIGNAL_FUNC (container_destroy_cb), container);
+
        /*
         * Create the GnomeUIHandler object which will be used to
         * create the container's menus and toolbars.  The UIHandler
        /*
         * Create the GnomeUIHandler object which will be used to
         * create the container's menus and toolbars.  The UIHandler
@@ -636,7 +679,7 @@ main (int argc, char **argv)
 {
   CORBA_Environment ev;
   CORBA_ORB         orb;
 {
   CORBA_Environment ev;
   CORBA_ORB         orb;
-  char            **view_files = NULL;
+  const char      **view_files = NULL;
   gboolean          loaded;
   int               i;
   
   gboolean          loaded;
   int               i;
   
@@ -662,8 +705,11 @@ main (int argc, char **argv)
   loaded = FALSE;
   if (view_files) {
     for (i = 0; view_files[i]; i++)
   loaded = FALSE;
   if (view_files) {
     for (i = 0; view_files[i]; i++)
-      if (container_new (view_files[i]))
+      if (container_new (view_files[i])) {
        loaded = TRUE;
        loaded = TRUE;
+       while (gtk_events_pending ())
+         gtk_main_iteration ();
+      }
   }
   if ((i == 0) || !loaded)
     container_new (NULL);
   }
   if ((i == 0) || !loaded)
     container_new (NULL);