]> www.fi.muni.cz Git - evince.git/blobdiff - pdf/xpdf/gpdf.cc
Auto activate, Scrolled panel, functioning zoom.
[evince.git] / pdf / xpdf / gpdf.cc
index 37112ae7d3bedb7250bf3deaa5b7116a45017e75..ae4ca75f1282fbc70590576d512f85c09978b6ca 100644 (file)
@@ -50,25 +50,30 @@ const struct poptOption gpdf_popt_options [] = {
   { NULL, '\0', 0, NULL, 0 }
 };
 
   { NULL, '\0', 0, NULL, 0 }
 };
 
+typedef struct _Component Component;
+typedef struct _Container Container;
 /* NB. there is a 1 to 1 Container -> Component mapping, this
    is due to how much MDI sucks; unutterably */
 /* NB. there is a 1 to 1 Container -> Component mapping, this
    is due to how much MDI sucks; unutterably */
-typedef struct {
-       GnomeContainer  *container;
-       GnomeUIHandler  *uih;
-
-       GnomeViewFrame  *active_view_frame;
-
-       GtkWidget       *app;
-       GtkWidget       *view_widget;
-} Container;
+struct _Container {
+  GnomeContainer    *container;
+  GnomeUIHandler    *uih;
+  
+  GnomeViewFrame    *active_view_frame;
+  
+  GtkWidget        *app;
+  GtkScrolledWindow *scroll;
+  GtkWidget        *view_widget;
+  Component         *component;
+  gdouble zoom;
+};
 
 
-typedef struct {
+struct  _Component {
        Container         *container;
 
        GnomeClientSite   *client_site;
        GnomeViewFrame    *view_frame;
        GnomeObjectClient *server;
        Container         *container;
 
        GnomeClientSite   *client_site;
        GnomeViewFrame    *view_frame;
        GnomeObjectClient *server;
-} Component;
+};
 
 GList *containers = NULL;
 /*
 
 GList *containers = NULL;
 /*
@@ -81,6 +86,9 @@ extern "C" {
   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       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       zoom_in_cmd         (GtkWidget *widget, Container *container);
+  static void       zoom_out_cmd        (GtkWidget *widget, Container *container);
+  static void       zoom_set            (Container *container);
 }
 
 /*
 }
 
 /*
@@ -95,8 +103,28 @@ 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_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_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
 };
 
        GNOMEUIINFO_END
 };
 
@@ -141,6 +169,8 @@ 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);
+
+    
     
     GNOME_Unknown_unref (persist, &ev);
     CORBA_Object_release (persist, &ev);
     
     GNOME_Unknown_unref (persist, &ev);
     CORBA_Object_release (persist, &ev);
@@ -239,50 +269,37 @@ extern "C" {
       container_destroy ((Container *)containers->data);
   }
 
       container_destroy ((Container *)containers->data);
   }
 
+  /*
+   * Enforces the containers zoom factor.
+   */
   static void
   static void
-  component_user_activate_request_cb (GnomeViewFrame *view_frame, gpointer data)
+  zoom_set (Container *container)
   {
   {
-    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;
+    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);
     }
     }
-    
-    /*
-     * 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
   }
   
   static void
@@ -364,7 +381,7 @@ container_set_view (Container *container, Component *component)
        /*
         * Create the remote view and the local ViewFrame.
         */
        /*
         * Create the remote view and the local ViewFrame.
         */
-       view_frame = gnome_client_site_embeddable_new_view (component->client_site);
+       view_frame = gnome_client_site_new_view (component->client_site);
        component->view_frame = view_frame;
 
        /*
        component->view_frame = view_frame;
 
        /*
@@ -380,19 +397,7 @@ container_set_view (Container *container, Component *component)
         */
        view_widget = gnome_view_frame_get_wrapper (view_frame);
        container->view_widget = view_widget;
         */
        view_widget = gnome_view_frame_get_wrapper (view_frame);
        container->view_widget = view_widget;
-/*     gtk_box_pack_start (GTK_BOX (container->app), view_widget,
-       FALSE, FALSE, 5);*/
-       gnome_app_set_contents (GNOME_APP (container->app), view_widget);
-       /*
-        * 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);
+       container->component   = component;
 
        /*
         * In-place activation of a component is a two-step process.
 
        /*
         * In-place activation of a component is a two-step process.
@@ -419,7 +424,14 @@ container_set_view (Container *container, Component *component)
        /*
         * Show the component.
         */
        /*
         * Show the component.
         */
-       gtk_widget_show_all (view_widget);
+       gtk_scrolled_window_add_with_viewport (container->scroll, view_widget);
+
+       /*
+        * Activate it ( get it to merge menus etc.
+        */
+       gnome_view_frame_view_activate (view_frame);
+
+       gtk_widget_show_all (GTK_WIDGET (container->scroll));
 }
 
 static GnomeObjectClient *
 }
 
 static GnomeObjectClient *
@@ -433,7 +445,7 @@ container_launch_component (GnomeClientSite *client_site,
         * Launch the component.
         */
        object_server = gnome_object_activate_with_goad_id (
         * Launch the component.
         */
        object_server = gnome_object_activate_with_goad_id (
-               NULL, component_goad_id, 0, NULL);
+               NULL, component_goad_id, GOAD_ACTIVATE_SHLIB, NULL);
 
        if (object_server == NULL)
                return NULL;
 
        if (object_server == NULL)
                return NULL;
@@ -547,6 +559,17 @@ container_create_menus (Container *container)
        gnome_ui_handler_menu_free_list (menu_list);
 }
 
        gnome_ui_handler_menu_free_list (menu_list);
 }
 
+static void
+container_create_toolbar (Container *container)
+{
+       GnomeUIHandlerToolbarItem *toolbar;
+
+       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_free_list (toolbar);
+}
+
 static Container *
 container_new (const char *fname)
 {
 static Container *
 container_new (const char *fname)
 {
@@ -554,14 +577,19 @@ container_new (const char *fname)
 
        container = g_new0 (Container, 1);
 
 
        container = g_new0 (Container, 1);
 
-       container->app = gnome_app_new ("pdf-viewer",
-                                       "GNOME PDF viewer");
+       container->app  = gnome_app_new ("pdf-viewer",
+                                        "GNOME PDF viewer");
+       container->zoom = 86.0;
 
        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 ();
        container->view_widget = NULL;
 
        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 ();
        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);
+       gnome_app_set_contents (GNOME_APP (container->app), GTK_WIDGET (container->scroll));
 
        /*
         * Create the GnomeUIHandler object which will be used to
 
        /*
         * Create the GnomeUIHandler object which will be used to
@@ -572,10 +600,8 @@ container_new (const char *fname)
        container->uih = gnome_ui_handler_new ();
        gnome_ui_handler_set_app (container->uih, GNOME_APP (container->app));
 
        container->uih = gnome_ui_handler_new ();
        gnome_ui_handler_set_app (container->uih, GNOME_APP (container->app));
 
-       /*
-        * Create the menus.
-        */
-       container_create_menus (container);
+       container_create_menus   (container);
+       container_create_toolbar (container);
 
        gtk_widget_show_all (container->app);
 
 
        gtk_widget_show_all (container->app);
 
@@ -586,6 +612,7 @@ container_new (const char *fname)
          }
 
        containers = g_list_append (containers, container);
          }
 
        containers = g_list_append (containers, container);
+       zoom_set (container);
 
        gtk_widget_show_all (container->app);
 
 
        gtk_widget_show_all (container->app);
 
@@ -613,6 +640,7 @@ main (int argc, char **argv)
 
   if (bonobo_init (orb, NULL, NULL) == FALSE)
     g_error (_("Could not initialize Bonobo!\n"));
 
   if (bonobo_init (orb, NULL, NULL) == FALSE)
     g_error (_("Could not initialize Bonobo!\n"));
+  bonobo_activate ();
 
   view_files = poptGetArgs (ctx);
 
 
   view_files = poptGetArgs (ctx);
 
@@ -626,7 +654,7 @@ main (int argc, char **argv)
     container_new (NULL);
   
   poptFreeContext (ctx);
     container_new (NULL);
   
   poptFreeContext (ctx);
-  
+
   gtk_main ();
        
   return 0;
   gtk_main ();
        
   return 0;