]> www.fi.muni.cz Git - evince.git/blobdiff - shell/ev-view.c
Fix a free() that should be an iks_free(). Fix an array overflow in the
[evince.git] / shell / ev-view.c
index 28a21393b7ba3c4738815a8a097aa8bed5453a03..d107df965b19b1d73577b63918a2479c70bed4e8 100644 (file)
@@ -320,6 +320,7 @@ static void       compute_selections                         (EvView
                                                              GdkPoint           *start,
                                                              GdkPoint           *stop);
 static void       clear_selection                            (EvView             *view);
+static void       clear_link_selected                        (EvView             *view);
 static void       selection_free                             (EvViewSelection    *selection);
 static char*      get_selected_text                          (EvView             *ev_view);
 static void       ev_view_primary_get_cb                     (GtkClipboard       *clipboard,
@@ -1658,9 +1659,9 @@ ev_view_form_field_get_region (EvView      *view,
        GList       *forms_mapping;
 
        forms_mapping = ev_pixbuf_cache_get_form_field_mapping (view->pixbuf_cache,
-                                                               field->page);
+                                                               field->page->index);
        ev_form_field_mapping_get_area (forms_mapping, field, &field_area);
-       doc_rect_to_view_rect (view, field->page, &field_area, &view_area);
+       doc_rect_to_view_rect (view, field->page->index, &field_area, &view_area);
        view_area.x -= view->scroll_x;
        view_area.y -= view->scroll_y;
 
@@ -1711,7 +1712,7 @@ ev_view_form_field_button_create_widget (EvView      *view,
                         * we need to update also the region for the current selected item
                         */
                        forms_mapping = ev_pixbuf_cache_get_form_field_mapping (view->pixbuf_cache,
-                                                                               field->page);
+                                                                               field->page->index);
                        for (l = forms_mapping; l; l = g_list_next (l)) {
                                EvFormField *button = ((EvFormFieldMapping *)(l->data))->field;
                                GdkRegion   *button_region;
@@ -1739,7 +1740,7 @@ ev_view_form_field_button_create_widget (EvView      *view,
 
        ev_pixbuf_cache_reload_page (view->pixbuf_cache,
                                     field_region,
-                                    field->page,
+                                    field->page->index,
                                     view->rotation,
                                     view->scale);
        gdk_region_destroy (field_region);
@@ -1769,7 +1770,7 @@ ev_view_form_field_text_save (EvView    *view,
                field->changed = FALSE;
                ev_pixbuf_cache_reload_page (view->pixbuf_cache,
                                             field_region,
-                                            field->page,
+                                            field->page->index,
                                             view->rotation,
                                             view->scale);
                gdk_region_destroy (field_region);
@@ -1890,7 +1891,7 @@ ev_view_form_field_choice_save (EvView    *view,
                field->changed = FALSE;
                ev_pixbuf_cache_reload_page (view->pixbuf_cache,
                                             field_region,
-                                            field->page,
+                                            field->page->index,
                                             view->rotation,
                                             view->scale);
                gdk_region_destroy (field_region);
@@ -1907,7 +1908,8 @@ ev_view_form_field_choice_changed (GtkWidget   *widget,
                gint item;
                
                item = gtk_combo_box_get_active (GTK_COMBO_BOX (widget));
-               if (GPOINTER_TO_INT (field_choice->selected_items->data) != item) {
+               if (!field_choice->selected_items ||
+                   GPOINTER_TO_INT (field_choice->selected_items->data) != item) {
                        g_list_free (field_choice->selected_items);
                        field_choice->selected_items = NULL;
                        field_choice->selected_items = g_list_prepend (field_choice->selected_items,
@@ -2106,10 +2108,10 @@ ev_view_handle_form_field (EvView      *view,
                                g_object_ref (field),
                                (GDestroyNotify)g_object_unref);
 
-       form_field_mapping = ev_pixbuf_cache_get_form_field_mapping (view->pixbuf_cache, field->page);
+       form_field_mapping = ev_pixbuf_cache_get_form_field_mapping (view->pixbuf_cache, field->page->index);
        ev_form_field_mapping_get_area (form_field_mapping, field, &field_area);
        
-       doc_rect_to_view_rect (view, field->page, &field_area, &view_area);
+       doc_rect_to_view_rect (view, field->page->index, &field_area, &view_area);
        view_area.x -= view->scroll_x;
        view_area.y -= view->scroll_y;
 
@@ -2309,10 +2311,10 @@ ev_view_size_allocate (GtkWidget      *widget,
                        continue;
 
                form_field_mapping = ev_pixbuf_cache_get_form_field_mapping (view->pixbuf_cache,
-                                                                            field->page);
+                                                                            field->page->index);
                ev_form_field_mapping_get_area (form_field_mapping, field, &field_area);
 
-               doc_rect_to_view_rect (view, field->page, &field_area, &view_area);
+               doc_rect_to_view_rect (view, field->page->index, &field_area, &view_area);
                view_area.x -= view->scroll_x;
                view_area.y -= view->scroll_y;
 
@@ -2482,7 +2484,7 @@ ev_view_expose_event (GtkWidget      *widget,
        cairo_t *cr;
        gint     i;
 
-       if (view->animation) {
+       if (view->animation && ev_transition_animation_ready (view->animation)) {
                GdkRectangle page_area;
                GtkBorder    border;
 
@@ -3132,31 +3134,30 @@ ev_view_button_release_event (GtkWidget      *widget,
        EvView *view = EV_VIEW (widget);
        EvLink *link = NULL;
 
-       view->drag_info.in_drag = FALSE;
        view->image_dnd_info.in_drag = FALSE;
 
        if (view->scroll_info.autoscrolling) {
-               view->scroll_info.autoscrolling = FALSE;
-               if (view->scroll_info.timeout_id) {
-                       g_source_remove (view->scroll_info.timeout_id);
-                       view->scroll_info.timeout_id = 0;
-               }
-               ev_view_handle_cursor_over_xy (view, event->x, event->y);
+               ev_view_autoscroll_stop (view);
                view->pressed_button = -1;
 
                return TRUE;
        } 
-       
-       view->drag_info.release_timeout_id = g_timeout_add (20,
-                       (GSourceFunc)ev_view_scroll_drag_release, view);
 
-       if (view->pressed_button == 2) {
-               ev_view_handle_cursor_over_xy (view, event->x, event->y);
+       if (view->drag_info.in_drag) {
+               view->drag_info.release_timeout_id =
+                       g_timeout_add (20,
+                                      (GSourceFunc)ev_view_scroll_drag_release, view);
        }
 
-       if (view->document && view->pressed_button != 3) {
+       if (view->document && !view->drag_info.in_drag && view->pressed_button != 3) {
                link = ev_view_get_link_at_location (view, event->x, event->y);
        }
+       
+       view->drag_info.in_drag = FALSE;
+
+       if (view->pressed_button == 2) {
+               ev_view_handle_cursor_over_xy (view, event->x, event->y);
+       }
 
        view->pressed_button = -1;
 
@@ -3178,6 +3179,7 @@ ev_view_button_release_event (GtkWidget      *widget,
        }
 
        if (view->selection_info.selections) {
+               clear_link_selected (view);
                ev_view_update_primary_selection (view);
                
                if (view->selection_info.in_drag) {
@@ -3739,9 +3741,12 @@ draw_one_page (EvView       *view,
                page_surface = ev_pixbuf_cache_get_surface (view->pixbuf_cache, page);
 
                if (!page_surface) {
-                       draw_loading_text (view,
-                                          &real_page_area,
-                                          expose_area);
+                       if (!view->presentation) {
+                               draw_loading_text (view,
+                                                  &real_page_area,
+                                                  expose_area);
+                       }
+
                        *page_ready = FALSE;
 
                        return;
@@ -3820,6 +3825,7 @@ ev_view_finalize (GObject *object)
        g_free (view->find_status);
 
        clear_selection (view);
+       clear_link_selected (view);
 
        if (view->image_dnd_info.image)
                g_object_unref (view->image_dnd_info.image);
@@ -4463,10 +4469,42 @@ ev_view_autoscroll_cb (EvView *view)
 }
 
 void
-ev_view_autoscroll (EvView *view)
+ev_view_autoscroll_start (EvView *view)
 {
+       gint x, y;
+       
+       g_return_if_fail (EV_IS_VIEW (view));
+
+       if (view->scroll_info.autoscrolling)
+               return;
+       
        view->scroll_info.autoscrolling = TRUE;
-       view->scroll_info.timeout_id = g_timeout_add (20, (GSourceFunc)(ev_view_autoscroll_cb), view);
+       view->scroll_info.timeout_id =
+               g_timeout_add (20, (GSourceFunc)ev_view_autoscroll_cb,
+                              view);
+       
+       gtk_widget_get_pointer (GTK_WIDGET (view), &x, &y);
+       ev_view_handle_cursor_over_xy (view, x, y);
+}
+
+void
+ev_view_autoscroll_stop (EvView *view)
+{
+       gint x, y;
+       
+       g_return_if_fail (EV_IS_VIEW (view));
+
+       if (!view->scroll_info.autoscrolling)
+               return;
+
+       view->scroll_info.autoscrolling = FALSE;
+       if (view->scroll_info.timeout_id) {
+               g_source_remove (view->scroll_info.timeout_id);
+               view->scroll_info.timeout_id = 0;
+       }
+
+       gtk_widget_get_pointer (GTK_WIDGET (view), &x, &y);
+       ev_view_handle_cursor_over_xy (view, x, y);
 }
 
 void
@@ -4728,17 +4766,10 @@ ev_view_presentation_transition_start (EvView *view)
        duration = ev_document_transition_get_page_duration (EV_DOCUMENT_TRANSITION (view->document),
                                                             view->current_page);
        if (duration > 0) {
-#if GLIB_CHECK_VERSION (2, 13, 0)
                view->trans_timeout_id =
                        g_timeout_add_seconds (duration,
                                               (GSourceFunc) transition_next_page,
                                               view);
-#else
-               view->trans_timeout_id =
-                       g_timeout_add (duration * 1000,
-                                      (GSourceFunc) transition_next_page,
-                                      view);
-#endif
        }
 }
 
@@ -5305,18 +5336,30 @@ ev_view_find_previous (EvView *view)
        }
 }
 
-void ev_view_search_changed (EvView *view)
+void
+ev_view_search_changed (EvView *view)
 {
        /* search string has changed, focus on new search result */
        view->jump_to_find_result = TRUE;
 }
 
-void ev_view_set_highlight_search (EvView *view, gboolean value)
+void
+ev_view_set_highlight_search (EvView *view, gboolean value)
 {
        view->highlight_find_results = value;
        gtk_widget_queue_draw (GTK_WIDGET (view));
 }
 
+void
+ev_view_find_cancel (EvView *view)
+{
+       if (EV_IS_DOCUMENT_FIND (view->document)) {
+               EvDocumentFind *find = EV_DOCUMENT_FIND (view->document);
+
+               ev_document_find_cancel (find);
+       }
+}
+
 /*** Selections ***/
 
 /* compute_new_selection_rect/text calculates the area currently selected by
@@ -5676,15 +5719,19 @@ get_selected_text (EvView *view)
        EvRenderContext *rc;
 
        text = g_string_new (NULL);
-       rc = ev_render_context_new (view->rotation, 1, view->scale);
+       rc = ev_render_context_new (NULL, view->rotation, view->scale);
 
        ev_document_doc_mutex_lock ();
 
        for (l = view->selection_info.selections; l != NULL; l = l->next) {
                EvViewSelection *selection = (EvViewSelection *)l->data;
+               EvPage *page;
                gchar *tmp;
 
-               ev_render_context_set_page (rc, selection->page);
+               page = ev_document_get_page (view->document, selection->page);
+               ev_render_context_set_page (rc, page);
+               g_object_unref (page);
+               
                tmp = ev_selection_get_selected_text (EV_SELECTION (view->document),
                                                      rc, selection->style,
                                                      &(selection->rect));
@@ -5693,28 +5740,36 @@ get_selected_text (EvView *view)
                g_free (tmp);
        }
 
-       ev_document_doc_mutex_unlock ();
-
        g_object_unref (rc);
        
+       ev_document_doc_mutex_unlock ();
+       
        normalized_text = g_utf8_normalize (text->str, text->len, G_NORMALIZE_NFKC);
        g_string_free (text, TRUE);
        return normalized_text;
 }
 
+static void
+ev_view_clipboard_copy (EvView      *view,
+                       const gchar *text)
+{
+       GtkClipboard *clipboard;
+
+       clipboard = gtk_widget_get_clipboard (GTK_WIDGET (view),
+                                             GDK_SELECTION_CLIPBOARD);
+       gtk_clipboard_set_text (clipboard, text, -1);
+}
+
 void
 ev_view_copy (EvView *ev_view)
 {
-       GtkClipboard *clipboard;
        char *text;
 
        if (!EV_IS_SELECTION (ev_view->document))
                return;
 
        text = get_selected_text (ev_view);
-       clipboard = gtk_widget_get_clipboard (GTK_WIDGET (ev_view),
-                                             GDK_SELECTION_CLIPBOARD);
-       gtk_clipboard_set_text (clipboard, text, -1);
+       ev_view_clipboard_copy (ev_view, text);
        g_free (text);
 }
 
@@ -5725,15 +5780,20 @@ ev_view_primary_get_cb (GtkClipboard     *clipboard,
                        gpointer          data)
 {
        EvView *ev_view = EV_VIEW (data);
-       char *text;
-
-       if (!EV_IS_SELECTION (ev_view->document))
-               return;
 
-       text = get_selected_text (ev_view);
-       if (text) {
-               gtk_selection_data_set_text (selection_data, text, -1);
-               g_free (text);
+       if (ev_view->link_selected) {
+               gtk_selection_data_set_text (selection_data,
+                                            ev_link_action_get_uri (ev_view->link_selected),
+                                            -1);
+       } else if (EV_IS_SELECTION (ev_view->document) &&
+                  ev_view->selection_info.selections) {
+               gchar *text;
+               
+               text = get_selected_text (ev_view);
+               if (text) {
+                       gtk_selection_data_set_text (selection_data, text, -1);
+                       g_free (text);
+               }
        }
 }
 
@@ -5744,6 +5804,7 @@ ev_view_primary_clear_cb (GtkClipboard *clipboard,
        EvView *view = EV_VIEW (data);
 
        clear_selection (view);
+       clear_link_selected (view);
 }
 
 static void
@@ -5754,7 +5815,7 @@ ev_view_update_primary_selection (EvView *ev_view)
        clipboard = gtk_widget_get_clipboard (GTK_WIDGET (ev_view),
                                               GDK_SELECTION_PRIMARY);
 
-       if (ev_view->selection_info.selections) {
+       if (ev_view->selection_info.selections || ev_view->link_selected) {
                if (!gtk_clipboard_set_with_owner (clipboard,
                                                   clipboard_targets,
                                                   G_N_ELEMENTS (clipboard_targets),
@@ -5768,6 +5829,27 @@ ev_view_update_primary_selection (EvView *ev_view)
        }
 }
 
+static void
+clear_link_selected (EvView *view)
+{
+       if (view->link_selected) {
+               g_object_unref (view->link_selected);
+               view->link_selected = NULL;
+       }
+}
+
+void
+ev_view_copy_link_address (EvView       *view,
+                          EvLinkAction *action)
+{
+       clear_link_selected (view);
+       
+       ev_view_clipboard_copy (view, ev_link_action_get_uri (action));
+       
+       view->link_selected = g_object_ref (action);
+       ev_view_update_primary_selection (view);
+}
+
 /*** Cursor operations ***/
 
 static GdkCursor *