]> www.fi.muni.cz Git - evince.git/blobdiff - shell/ev-view.c
Updated Spanish translation (QA)
[evince.git] / shell / ev-view.c
index c7125d9eab95275f84acdee26b4f7122a756de60..a9418dac2337e6a2d9ed3e99238731e1869295b4 100644 (file)
@@ -19,6 +19,7 @@
  */
 
 #include <math.h>
+#include <string.h>
 #include <gtk/gtkalignment.h>
 #include <glib/gi18n.h>
 #include <gtk/gtkbindings.h>
@@ -29,6 +30,7 @@
 
 #include "ev-marshal.h"
 #include "ev-view.h"
+#include "ev-view-private.h"
 #include "ev-utils.h"
 #include "ev-selection.h"
 #include "ev-document-find.h"
@@ -55,11 +57,13 @@ enum {
        PROP_SIZING_MODE,
        PROP_ZOOM,
        PROP_ROTATION,
+       PROP_HAS_SELECTION,
 };
 
 enum {
        SIGNAL_BINDING_ACTIVATED,
        SIGNAL_ZOOM_INVALID,
+       SIGNAL_EXTERNAL_LINK,
        N_SIGNALS,
 };
 
@@ -80,15 +84,6 @@ static const GtkTargetEntry targets[] = {
 
 static guint signals[N_SIGNALS];
 
-typedef enum {
-       EV_VIEW_CURSOR_NORMAL,
-       EV_VIEW_CURSOR_IBEAM,
-       EV_VIEW_CURSOR_LINK,
-       EV_VIEW_CURSOR_WAIT,
-       EV_VIEW_CURSOR_HIDDEN,
-       EV_VIEW_CURSOR_DRAG
-} EvViewCursor;
-
 typedef enum {
        EV_VIEW_FIND_NEXT,
        EV_VIEW_FIND_PREV
@@ -100,96 +95,6 @@ typedef enum {
 #define MIN_SCALE 0.05409
 #define MAX_SCALE 4.0
 
-/* Information for middle clicking and moving around the doc */
-typedef struct {
-        gboolean in_drag;
-       GdkPoint start;
-       gdouble hadj;
-       gdouble vadj;
-} DragInfo;
-
-/* Information for handling selection */
-typedef struct {
-       gboolean in_selection;
-       GdkPoint start;
-       GList *selections;
-} SelectionInfo;
-
-typedef enum {
-       SCROLL_TO_KEEP_POSITION,
-       SCROLL_TO_CURRENT_PAGE,
-       SCROLL_TO_CENTER
-} PendingScroll;
-
-struct _EvView {
-       GtkWidget parent_instance;
-
-       EvDocument *document;
-
-       char *status;
-       char *find_status;
-
-       /* Scrolling */
-       GtkAdjustment *hadjustment;
-       GtkAdjustment *vadjustment;
-
-       gint scroll_x;
-       gint scroll_y;
-
-       /* Information for middle clicking and dragging around. */
-       DragInfo drag_info;
-
-       /* Selection */
-       gint motion_x;
-       gint motion_y;
-       guint selection_update_id;
-
-       EvViewSelectionMode selection_mode;
-       SelectionInfo selection_info;
-
-       int pressed_button;
-       EvViewCursor cursor;
-       GtkWidget *link_tooltip;
-       EvLink *hovered_link;
-
-       EvPageCache *page_cache;
-       EvPixbufCache *pixbuf_cache;
-
-       gint start_page;
-       gint end_page;
-       gint current_page;
-
-       EvJobRender *current_job;
-
-       int find_page;
-       int find_result;
-       int spacing;
-
-       int rotation;
-       double scale;
-
-       gboolean continuous;
-       gboolean dual_page;
-       gboolean fullscreen;
-       gboolean presentation;
-       EvSizingMode sizing_mode;
-
-       PendingScroll pending_scroll;
-       gboolean pending_resize;
-};
-
-struct _EvViewClass {
-       GtkWidgetClass parent_class;
-
-       void    (*set_scroll_adjustments) (EvView         *view,
-                                          GtkAdjustment  *hadjustment,
-                                          GtkAdjustment  *vadjustment);
-       void    (*binding_activated)      (EvView         *view,
-                                          GtkScrollType   scroll,
-                                          gboolean        horizontal);
-       void    (*zoom_invalid)           (EvView         *view);
-};
-
 /*** Scrolling ***/
 static void       scroll_to_current_page                    (EvView *view,
                                                              GtkOrientation orientation);
@@ -281,6 +186,8 @@ static gboolean   ev_view_leave_notify_event                 (GtkWidget
 static void       ev_view_style_set                          (GtkWidget          *widget,
                                                              GtkStyle           *old_style);
 
+static AtkObject *ev_view_get_accessible                     (GtkWidget *widget);
+
 /*** Drawing ***/
 static guint32    ev_gdk_color_to_rgb                        (const GdkColor     *color);
 static void       draw_rubberband                            (GtkWidget          *widget,
@@ -327,6 +234,11 @@ static double   zoom_for_size_fit_width                         (int doc_width,
                                                              int target_width,
                                                              int target_height,
                                                              int vsb_width);
+static double   zoom_for_size_fit_height                    (int doc_width,
+                                                             int doc_height,
+                                                             int target_width,
+                                                             int target_height,
+                                                             int vsb_height);
 static double  zoom_for_size_best_fit                       (int doc_width,
                                                              int doc_height,
                                                              int target_width,
@@ -926,7 +838,7 @@ view_rect_to_doc_rect (EvView *view,
        doc_rect->y2 = doc_rect->y1 + (double) view_rect->height / view->scale;
 }
 
-static void
+static gboolean
 doc_point_to_view_point (EvView       *view,
                          int           page,
                         EvPoint      *doc_point,
@@ -934,7 +846,7 @@ doc_point_to_view_point (EvView       *view,
 {
        GdkRectangle page_area;
        GtkBorder border;
-       double x, y;
+       double x, y, view_x, view_y;
        int width, height;
 
        ev_page_cache_get_size (view->page_cache, page,
@@ -960,8 +872,13 @@ doc_point_to_view_point (EvView       *view,
 
        get_page_extents (view, page, &page_area, &border);
 
-       view_point->x = x * view->scale + page_area.x;
-       view_point->y = y * view->scale + page_area.y;
+       view_x = x * view->scale;
+       view_y = y * view->scale;
+       view_point->x = view_x + page_area.x;
+       view_point->y = view_y + page_area.y;
+
+       return (view_x > 0 && view_x <= page_area.width &&
+               view_y > 0 && view_y <= page_area.height);
 }
 
 static void
@@ -1072,6 +989,44 @@ location_in_text (EvView  *view,
                return FALSE;
 }
 
+static int
+ev_view_get_width (EvView *view)
+{
+       return GTK_WIDGET (view)->allocation.width;
+}
+
+static int
+ev_view_get_height (EvView *view)
+{
+       return GTK_WIDGET (view)->allocation.height;
+}
+
+static gboolean
+location_in_selected_text (EvView  *view,
+                          gdouble  x,
+                          gdouble  y)
+{
+       gint page = -1;
+       gint x_offset = 0, y_offset = 0;
+       EvViewSelection *selection;
+       GList *l = NULL;
+
+       for (l = view->selection_info.selections; l != NULL; l = l->next) {
+               selection = (EvViewSelection *)l->data;
+               
+               find_page_at_location (view, x, y, &page, &x_offset, &y_offset);
+               
+               if (page != selection->page)
+                       continue;
+               
+               if (selection->covered_region &&
+                   gdk_region_point_in (selection->covered_region, x_offset, y_offset))
+                       return TRUE;
+       }
+
+       return FALSE;
+}
+
 /*** Hyperref ***/
 static EvLink *
 get_link_at_location (EvView  *view,
@@ -1096,21 +1051,59 @@ get_link_at_location (EvView  *view,
 }
 
 static void
-goto_fitv_link (EvView *view, EvLink *link)
+goto_fitr_link (EvView *view, EvLink *link)
 {
        GdkPoint view_point;
        EvPoint doc_point;
-       int page;
+       int doc_width, doc_height, page;
+       double zoom;
 
        page = ev_link_get_page (link);
+       ev_page_cache_get_size (view->page_cache, page, 0, 1.0, &doc_width, &doc_height);
+
+       doc_point.x = ev_link_get_left (link);
+       doc_point.y = ev_link_get_top (link);
+
+       zoom = zoom_for_size_best_fit (ev_link_get_right (link) - ev_link_get_left (link),
+                                      ev_link_get_top (link) - ev_link_get_bottom (link),
+                                      ev_view_get_width (view),
+                                      ev_view_get_height (view), 0, 0);
 
-       ev_view_set_sizing_mode (view, EV_SIZING_FIT_HEIGHT);
+       ev_view_set_sizing_mode (view, EV_SIZING_FREE);
+       ev_view_set_zoom (view, zoom, FALSE);
+       ev_page_cache_set_current_page (view->page_cache, page);
+
+       if (doc_point_to_view_point (view, page, &doc_point, &view_point)) {
+               gtk_adjustment_set_value (view->hadjustment, view_point.x);
+               gtk_adjustment_set_value (view->vadjustment, view_point.y);
+       }
+}
+
+static void
+goto_fitv_link (EvView *view, EvLink *link)
+{
+       GdkPoint view_point;
+       EvPoint doc_point;
+       int doc_width, doc_height, page;
+       double zoom;
+
+       page = ev_link_get_page (link);
+       ev_page_cache_get_size (view->page_cache, page, 0, 1.0, &doc_width, &doc_height);
 
        doc_point.x = ev_link_get_left (link);
        doc_point.y = 0;
-       doc_point_to_view_point (view, page, &doc_point, &view_point);
 
-       gtk_adjustment_set_value (view->hadjustment, view_point.x);
+       zoom = zoom_for_size_fit_height (doc_width - doc_point.x , doc_height,
+                                        ev_view_get_width (view),
+                                        ev_view_get_height (view), 0);
+
+       ev_view_set_sizing_mode (view, EV_SIZING_FREE);
+       ev_view_set_zoom (view, zoom, FALSE);
+       ev_page_cache_set_current_page (view->page_cache, page);
+
+       if (doc_point_to_view_point (view, page, &doc_point, &view_point)) {
+               gtk_adjustment_set_value (view->hadjustment, view_point.x);
+       }
 }
 
 static void
@@ -1118,18 +1111,45 @@ goto_fith_link (EvView *view, EvLink *link)
 {
        GdkPoint view_point;
        EvPoint doc_point;
-       int height, page;
+       int doc_width, doc_height, page;
+       double zoom;
 
        page = ev_link_get_page (link);
-       ev_page_cache_get_size (view->page_cache, page, 0, 1.0, NULL, &height);
-
-       ev_view_set_sizing_mode (view, EV_SIZING_FIT_WIDTH);
+       ev_page_cache_get_size (view->page_cache, page, 0, 1.0, &doc_width, &doc_height);
 
        doc_point.x = 0;
-       doc_point.y = height - ev_link_get_top (link);
-       doc_point_to_view_point (view, page, &doc_point, &view_point);
+       doc_point.y = doc_height - ev_link_get_top (link);
+
+       zoom = zoom_for_size_fit_width (doc_width, ev_link_get_top (link),
+                                       ev_view_get_width (view),
+                                       ev_view_get_height (view), 0);
 
-       gtk_adjustment_set_value (view->vadjustment, view_point.y);
+       ev_view_set_sizing_mode (view, EV_SIZING_FREE);
+       ev_view_set_zoom (view, zoom, FALSE);
+
+       if (doc_point_to_view_point (view, page, &doc_point, &view_point)) {
+               gtk_adjustment_set_value (view->vadjustment, view_point.y);
+       } else {
+               ev_page_cache_set_current_page (view->page_cache, page);
+       }
+}
+
+static void
+goto_fit_link (EvView *view, EvLink *link)
+{
+       double zoom;
+       int doc_width, doc_height;
+       int page;
+
+       page = ev_link_get_page (link);
+       ev_page_cache_get_size (view->page_cache, page, 0, 1.0, &doc_width, &doc_height);
+
+       zoom = zoom_for_size_best_fit (doc_width, doc_height, ev_view_get_width (view),
+                                      ev_view_get_height (view), 0, 0);
+
+       ev_view_set_sizing_mode (view, EV_SIZING_FREE);
+       ev_view_set_zoom (view, zoom, FALSE);
+       ev_page_cache_set_current_page (view->page_cache, page);
 }
 
 static void
@@ -1151,17 +1171,19 @@ goto_xyz_link (EvView *view, EvLink *link)
 
        doc_point.x = ev_link_get_left (link);
        doc_point.y = height - ev_link_get_top (link);
-       doc_point_to_view_point (view, page, &doc_point, &view_point);
 
-       gtk_adjustment_set_value (view->hadjustment, view_point.x);
-       gtk_adjustment_set_value (view->vadjustment, view_point.y);
+       if (doc_point_to_view_point (view, page, &doc_point, &view_point)) {
+               gtk_adjustment_set_value (view->hadjustment, view_point.x);
+               gtk_adjustment_set_value (view->vadjustment, view_point.y);
+       } else {
+               ev_page_cache_set_current_page (view->page_cache, page);
+       }
 }
 
 void
 ev_view_goto_link (EvView *view, EvLink *link)
 {
        EvLinkType type;
-       const char *uri;
        int page;
 
        type = ev_link_get_link_type (link);
@@ -1174,9 +1196,7 @@ ev_view_goto_link (EvView *view, EvLink *link)
                        ev_page_cache_set_current_page (view->page_cache, page);
                        break;
                case EV_LINK_TYPE_PAGE_FIT:
-                       page = ev_link_get_page (link);
-                       ev_page_cache_set_current_page (view->page_cache, page);
-                       ev_view_set_sizing_mode (view, EV_SIZING_BEST_FIT);
+                       goto_fit_link (view, link);
                        break;
                case EV_LINK_TYPE_PAGE_FITH:
                        goto_fith_link (view, link);
@@ -1184,12 +1204,15 @@ ev_view_goto_link (EvView *view, EvLink *link)
                case EV_LINK_TYPE_PAGE_FITV:
                        goto_fitv_link (view, link);
                        break;
+               case EV_LINK_TYPE_PAGE_FITR:
+                       goto_fitr_link (view, link);
+                       break;
                case EV_LINK_TYPE_PAGE_XYZ:
                        goto_xyz_link (view, link);
                        break;
                case EV_LINK_TYPE_EXTERNAL_URI:
-                       uri = ev_link_get_uri (link);
-                       gnome_vfs_url_show (uri);
+               case EV_LINK_TYPE_LAUNCH:
+                       g_signal_emit (view, signals[SIGNAL_EXTERNAL_LINK], 0, link);
                        break;
        }
 }
@@ -1243,9 +1266,13 @@ handle_link_over_xy (EvView *view, gint x, gint y)
         if (link) {
                char *msg = tip_from_link (view, link);
 
-               ev_tooltip_set_position (EV_TOOLTIP (view->link_tooltip), x, y);
-               ev_tooltip_set_text (EV_TOOLTIP (view->link_tooltip), msg);
-               ev_tooltip_activate (EV_TOOLTIP (view->link_tooltip));
+               if (msg && g_utf8_validate (msg, -1, NULL)) {
+                       EvTooltip *tooltip = EV_TOOLTIP (view->link_tooltip);
+
+                       ev_tooltip_set_position (tooltip, x, y);
+                       ev_tooltip_set_text (tooltip, msg);
+                       ev_tooltip_activate (tooltip);
+               }
                g_free (msg);
 
                ev_view_set_cursor (view, EV_VIEW_CURSOR_LINK);
@@ -1281,8 +1308,6 @@ ev_view_size_request_continuous_dual_page (EvView         *view,
 
        if (view->sizing_mode == EV_SIZING_FIT_WIDTH) {
                requisition->width = 1;
-       } else if (view->sizing_mode == EV_SIZING_FIT_HEIGHT) {
-               requisition->height = 1;
        } else if (view->sizing_mode == EV_SIZING_BEST_FIT) {
                requisition->width = 1;
                /* FIXME: This could actually be set on one page docs or docs
@@ -1310,8 +1335,6 @@ ev_view_size_request_continuous (EvView         *view,
 
        if (view->sizing_mode == EV_SIZING_FIT_WIDTH) {
                requisition->width = 1;
-       } else if (view->sizing_mode == EV_SIZING_FIT_HEIGHT) {
-               requisition->height = 1;
        } else if (view->sizing_mode == EV_SIZING_BEST_FIT) {
                requisition->width = 1;
                /* FIXME: This could actually be set on one page docs or docs
@@ -1354,8 +1377,6 @@ ev_view_size_request_dual_page (EvView         *view,
 
        if (view->sizing_mode == EV_SIZING_FIT_WIDTH) {
                requisition->width = 1;
-       } else if (view->sizing_mode == EV_SIZING_FIT_HEIGHT) {
-               requisition->height = 1;
        } else if (view->sizing_mode == EV_SIZING_BEST_FIT) {
                requisition->width = 1;
                requisition->height = 1;
@@ -1382,8 +1403,6 @@ ev_view_size_request_single_page (EvView         *view,
        if (view->sizing_mode == EV_SIZING_FIT_WIDTH) {
                requisition->width = 1;
                requisition->height = height + border.top + border.bottom + (2 * view->spacing);
-       } else if (view->sizing_mode == EV_SIZING_FIT_HEIGHT) {
-               requisition->height = 1;
        } else if (view->sizing_mode == EV_SIZING_BEST_FIT) {
                requisition->width = 1;
                requisition->height = 1;
@@ -1425,7 +1444,6 @@ ev_view_size_allocate (GtkWidget      *widget,
        EvView *view = EV_VIEW (widget);
 
        if (view->sizing_mode == EV_SIZING_FIT_WIDTH ||
-           view->sizing_mode == EV_SIZING_FIT_HEIGHT ||
            view->sizing_mode == EV_SIZING_BEST_FIT) {
 
                g_signal_emit (view, signals[SIGNAL_ZOOM_INVALID], 0);
@@ -1596,22 +1614,31 @@ ev_view_button_press_event (GtkWidget      *widget,
                            GdkEventButton *event)
 {
        EvView *view = EV_VIEW (widget);
-
+       
        if (!GTK_WIDGET_HAS_FOCUS (widget)) {
                gtk_widget_grab_focus (widget);
        }
-
+       
        view->pressed_button = event->button;
-
+       view->selection_info.in_drag = FALSE;
+       
        switch (event->button) {
-               case 1:
+               case 1:
                        if (view->selection_info.selections) {
-                               clear_selection (view);
+                               if (location_in_selected_text (view,
+                                                              event->x + view->scroll_x,
+                                                              event->y + view->scroll_y)) {
+                                       view->selection_info.in_drag = TRUE;
+                               } else {
+                                       clear_selection (view);
+                               }
+                               
                                gtk_widget_queue_draw (widget);
                        }
 
                        view->selection_info.start.x = event->x + view->scroll_x;
                        view->selection_info.start.y = event->y + view->scroll_y;
+                       
                        return TRUE;
                case 2:
                        /* use root coordinates as reference point because
@@ -1625,10 +1652,30 @@ ev_view_button_press_event (GtkWidget      *widget,
 
                        return TRUE;
        }
-
+       
        return FALSE;
 }
 
+static void
+ev_view_drag_data_get (GtkWidget        *widget,
+                      GdkDragContext   *context,
+                      GtkSelectionData *selection_data,
+                      guint             info,
+                      guint             time)
+{
+       EvView *view = EV_VIEW (widget);
+
+       if (view->selection_info.selections &&
+           ev_document_can_get_text (view->document)) {
+               gchar *text;
+
+               text = get_selected_text (view);
+
+               gtk_selection_data_set_text (selection_data, text, strlen (text));
+
+               g_free (text);
+       }
+}
 
 static gboolean
 selection_update_idle_cb (EvView *view)
@@ -1651,19 +1698,40 @@ ev_view_motion_notify_event (GtkWidget      *widget,
        if (!view->document)
                return FALSE;
 
+       if (view->selection_info.in_drag) {
+               if (gtk_drag_check_threshold (widget,
+                                             view->selection_info.start.x,
+                                             view->selection_info.start.y,
+                                             event->x, event->y)) {
+                       GdkDragContext *context;
+                       GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
+
+                       gtk_target_list_add_text_targets (target_list, 0);
+
+                       context = gtk_drag_begin (widget, target_list,
+                                                 GDK_ACTION_COPY,
+                                                 1, (GdkEvent *)event);
+
+                       view->selection_info.in_drag = FALSE;
+
+                       gtk_target_list_unref (target_list);
+
+                       return TRUE;
+               }
+       }
+       
        /* For the Evince 0.4.x release, we limit selection to un-rotated
         * documents only.
         */
-       if (view->pressed_button == 1 &&
-           view->rotation == 0) {
+       if (view->pressed_button == 1 && view->rotation == 0) {
                view->selection_info.in_selection = TRUE;
                view->motion_x = event->x + view->scroll_x;
                view->motion_y = event->y + view->scroll_y;
 
-               /* Queue an idle to handle the motion.  We do this because
-                * handling any selection events in the motion could be slower
-                * than new motion events reach us.  We always put it in the
-                * idle to make sure we catch up and don't visibly lag the
+               /* Queue an idle to handle the motion.  We do this because      
+                * handling any selection events in the motion could be slower  
+                * than new motion events reach us.  We always put it in the    
+                * idle to make sure we catch up and don't visibly lag the      
                 * mouse. */
                if (! view->selection_update_id)
                        view->selection_update_id = g_idle_add ((GSourceFunc)selection_update_idle_cb, view);
@@ -1740,6 +1808,13 @@ ev_view_button_release_event (GtkWidget      *widget,
 
        if (view->selection_info.selections) {
                ev_view_update_primary_selection (view);
+               
+               if (view->selection_info.in_drag) {
+                       clear_selection (view);
+                       gtk_widget_queue_draw (widget);
+               }
+               
+               view->selection_info.in_drag = FALSE;
        } else if (link) {
                ev_view_goto_link (view, link);
        } else if (view->presentation) {
@@ -1817,7 +1892,6 @@ ev_view_style_set (GtkWidget *widget,
        GTK_WIDGET_CLASS (ev_view_parent_class)->style_set (widget, old_style);
 }
 
-
 /*** Drawing ***/
 
 static guint32
@@ -2123,6 +2197,37 @@ ev_view_set_property (GObject      *object,
        }
 }
 
+static AtkObject *
+ev_view_get_accessible (GtkWidget *widget)
+{
+       static gboolean first_time = TRUE;
+
+       if (first_time) {
+               AtkObjectFactory *factory;
+               AtkRegistry *registry;
+               GType derived_type; 
+               GType derived_atk_type; 
+
+               /*
+                * Figure out whether accessibility is enabled by looking at the
+                * type of the accessible object which would be created for
+                * the parent type of EvView.
+                */
+               derived_type = g_type_parent (EV_TYPE_VIEW);
+
+               registry = atk_get_default_registry ();
+               factory = atk_registry_get_factory (registry,
+                                                   derived_type);
+               derived_atk_type = atk_object_factory_get_accessible_type (factory);
+               if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE)) 
+                       atk_registry_set_factory_type (registry, 
+                                                      EV_TYPE_VIEW,
+                                                      ev_view_accessible_factory_get_type ());
+               first_time = FALSE;
+       } 
+       return GTK_WIDGET_CLASS (ev_view_parent_class)->get_accessible (widget);
+}
+
 static void
 ev_view_get_property (GObject *object,
                      guint prop_id,
@@ -2160,6 +2265,10 @@ ev_view_get_property (GObject *object,
        case PROP_ROTATION:
                g_value_set_int (value, view->rotation);
                break;
+       case PROP_HAS_SELECTION:
+               g_value_set_boolean (value,
+                                    view->selection_info.selections != NULL);
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
        }
@@ -2183,6 +2292,7 @@ ev_view_class_init (EvViewClass *class)
        widget_class->button_release_event = ev_view_button_release_event;
        widget_class->focus_in_event = ev_view_focus_in;
        widget_class->focus_out_event = ev_view_focus_out;
+       widget_class->get_accessible = ev_view_get_accessible;
        widget_class->size_request = ev_view_size_request;
        widget_class->size_allocate = ev_view_size_allocate;
        widget_class->realize = ev_view_realize;
@@ -2190,6 +2300,7 @@ ev_view_class_init (EvViewClass *class)
        widget_class->enter_notify_event = ev_view_enter_notify_event;
        widget_class->leave_notify_event = ev_view_leave_notify_event;
        widget_class->style_set = ev_view_style_set;
+       widget_class->drag_data_get = ev_view_drag_data_get;
        gtk_object_class->destroy = ev_view_destroy;
 
        class->set_scroll_adjustments = ev_view_set_scroll_adjustments;
@@ -2223,6 +2334,14 @@ ev_view_class_init (EvViewClass *class)
                         NULL, NULL,
                         ev_marshal_VOID__VOID,
                         G_TYPE_NONE, 0, G_TYPE_NONE);
+       signals[SIGNAL_EXTERNAL_LINK] = g_signal_new ("external-link",
+                        G_TYPE_FROM_CLASS (object_class),
+                        G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+                        G_STRUCT_OFFSET (EvViewClass, external_link),
+                        NULL, NULL,
+                        g_cclosure_marshal_VOID__OBJECT,
+                        G_TYPE_NONE, 1,
+                        G_TYPE_OBJECT);
 
        g_object_class_install_property (object_class,
                                         PROP_STATUS,
@@ -2297,6 +2416,13 @@ ev_view_class_init (EvViewClass *class)
                                                               360,
                                                               0,
                                                               G_PARAM_READWRITE));
+       g_object_class_install_property (object_class,
+                                        PROP_HAS_SELECTION,
+                                        g_param_spec_boolean ("has-selection",
+                                                              "Has selection",
+                                                              "The view has selections",
+                                                              FALSE,
+                                                              G_PARAM_READABLE));
 
        binding_set = gtk_binding_set_by_class (class);
 
@@ -2317,7 +2443,9 @@ ev_view_init (EvView *view)
        view->pressed_button = -1;
        view->cursor = EV_VIEW_CURSOR_NORMAL;
        view->drag_info.in_drag = FALSE;
+       view->selection_info.selections = NULL;
        view->selection_info.in_selection = FALSE;
+       view->selection_info.in_drag = FALSE;
        view->selection_mode = EV_VIEW_SELECTION_TEXT;
        view->continuous = TRUE;
        view->dual_page = FALSE;
@@ -2822,8 +2950,6 @@ ev_view_zoom_for_size_continuous_and_dual_page (EvView *view,
         * now.  We need to fix this. */
        if (view->sizing_mode == EV_SIZING_FIT_WIDTH)
                scale = zoom_for_size_fit_width (doc_width, doc_height, width - vsb_width, height, 0);
-       else if (view->sizing_mode == EV_SIZING_FIT_HEIGHT)
-                scale = zoom_for_size_fit_height (doc_width, doc_height, width - vsb_width, height, hsb_height);
        else if (view->sizing_mode == EV_SIZING_BEST_FIT)
                scale = zoom_for_size_best_fit (doc_width, doc_height, width - vsb_width, height, 0, hsb_height);
        else
@@ -2861,8 +2987,6 @@ ev_view_zoom_for_size_continuous (EvView *view,
         * now.  We need to fix this. */
        if (view->sizing_mode == EV_SIZING_FIT_WIDTH)
                scale = zoom_for_size_fit_width (doc_width, doc_height, width - vsb_width, height, 0);
-       else if (view->sizing_mode == EV_SIZING_FIT_HEIGHT)
-               scale = zoom_for_size_fit_height (doc_width, doc_height, width - vsb_width, height, hsb_height);
        else if (view->sizing_mode == EV_SIZING_BEST_FIT)
                scale = zoom_for_size_best_fit (doc_width, doc_height, width - vsb_width, height, 0, hsb_height);
        else
@@ -2912,8 +3036,6 @@ ev_view_zoom_for_size_dual_page (EvView *view,
 
        if (view->sizing_mode == EV_SIZING_FIT_WIDTH)
                scale = zoom_for_size_fit_width (doc_width, doc_height, width, height, vsb_width);
-       else if (view->sizing_mode == EV_SIZING_FIT_HEIGHT)
-               scale = zoom_for_size_fit_height (doc_width, doc_height, width, height, hsb_height);
        else if (view->sizing_mode == EV_SIZING_BEST_FIT)
                scale = zoom_for_size_best_fit (doc_width, doc_height, width, height, vsb_width, hsb_height);
        else
@@ -2947,8 +3069,6 @@ ev_view_zoom_for_size_single_page (EvView *view,
 
        if (view->sizing_mode == EV_SIZING_FIT_WIDTH)
                scale = zoom_for_size_fit_width (doc_width, doc_height, width, height, vsb_width);
-       else if (view->sizing_mode == EV_SIZING_FIT_HEIGHT)
-               scale = zoom_for_size_fit_height (doc_width, doc_height, width, height, hsb_height);
        else if (view->sizing_mode == EV_SIZING_BEST_FIT)
                scale = zoom_for_size_best_fit (doc_width, doc_height, width, height, vsb_width, hsb_height);
        else
@@ -2965,7 +3085,6 @@ ev_view_set_zoom_for_size (EvView *view,
                           int     hsb_height)
 {
        g_return_if_fail (view->sizing_mode == EV_SIZING_FIT_WIDTH ||
-                         view->sizing_mode == EV_SIZING_FIT_HEIGHT ||
                          view->sizing_mode == EV_SIZING_BEST_FIT);
        g_return_if_fail (width >= 0);
        g_return_if_fail (height >= 0);
@@ -3358,6 +3477,7 @@ merge_selection_region (EvView *view,
        g_list_foreach (view->selection_info.selections, (GFunc)selection_free, NULL);
        view->selection_info.selections = new_list;
        ev_pixbuf_cache_set_selection_list (view->pixbuf_cache, new_list);
+       g_object_notify (G_OBJECT (view), "has-selection");
 
        new_list_ptr = new_list;
        old_list_ptr = old_list;
@@ -3488,6 +3608,7 @@ clear_selection (EvView *view)
        g_list_foreach (view->selection_info.selections, (GFunc)selection_free, NULL);
        view->selection_info.selections = NULL;
        view->selection_info.in_selection = FALSE;
+       g_object_notify (G_OBJECT (view), "has-selection");
 }
 
 
@@ -3522,9 +3643,16 @@ ev_view_select_all (EvView *view)
        }
 
        ev_pixbuf_cache_set_selection_list (view->pixbuf_cache, view->selection_info.selections);
+       g_object_notify (G_OBJECT (view), "has-selection");
        gtk_widget_queue_draw (GTK_WIDGET (view));
 }
 
+gboolean
+ev_view_get_has_selection (EvView *view)
+{
+       return view->selection_info.selections != NULL;
+}
+
 static char *
 get_selected_text (EvView *ev_view)
 {
@@ -3731,7 +3859,6 @@ ev_sizing_mode_get_type (void)
   if (etype == 0) {
     static const GEnumValue values[] = {
       { EV_SIZING_FIT_WIDTH, "EV_SIZING_FIT_WIDTH", "fit-width" },
-      { EV_SIZING_FIT_HEIGHT, "EV_SIZING_FIT_HEIGHT", "fit-height" },
       { EV_SIZING_BEST_FIT, "EV_SIZING_BEST_FIT", "best-fit" },
       { EV_SIZING_FREE, "EV_SIZING_FREE", "free" },
       { 0, NULL, NULL }