1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
2 /* this file is part of evince, a gnome document viewer
4 * Copyright (C) 2004 Red Hat, Inc
6 * Evince is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * Evince is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 #include <glib/gi18n-lib.h>
29 #include <gdk/gdkkeysyms.h>
31 #include "ev-mapping-list.h"
32 #include "ev-document-forms.h"
33 #include "ev-document-images.h"
34 #include "ev-document-links.h"
35 #include "ev-document-misc.h"
36 #include "ev-pixbuf-cache.h"
37 #include "ev-page-cache.h"
38 #include "ev-view-marshal.h"
39 #include "ev-document-annotations.h"
40 #include "ev-annotation-window.h"
41 #include "ev-loading-window.h"
43 #include "ev-view-accessible.h"
44 #include "ev-view-private.h"
45 #include "ev-view-type-builtins.h"
47 #define EV_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EV_TYPE_VIEW, EvViewClass))
48 #define EV_IS_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EV_TYPE_VIEW))
49 #define EV_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EV_TYPE_VIEW, EvViewClass))
52 SIGNAL_BINDING_ACTIVATED,
56 SIGNAL_SELECTION_CHANGED,
68 static guint signals[N_SIGNALS];
73 } EvViewFindDirection;
75 #define ZOOM_IN_FACTOR 1.2
76 #define ZOOM_OUT_FACTOR (1.0/ZOOM_IN_FACTOR)
78 #define SCROLL_TIME 150
81 static void ev_view_set_scroll_adjustments (GtkLayout *layout,
82 GtkAdjustment *hadjustment,
83 GtkAdjustment *vadjustment);
84 static void view_update_range_and_current_page (EvView *view);
85 static void set_scroll_adjustment (EvView *view,
86 GtkOrientation orientation,
87 GtkAdjustment *adjustment);
88 static void add_scroll_binding_keypad (GtkBindingSet *binding_set,
90 GdkModifierType modifiers,
93 static void ensure_rectangle_is_visible (EvView *view,
96 /*** Geometry computations ***/
97 static void compute_border (EvView *view,
101 static void get_page_y_offset (EvView *view,
104 static void view_rect_to_doc_rect (EvView *view,
105 GdkRectangle *view_rect,
106 GdkRectangle *page_area,
107 EvRectangle *doc_rect);
108 static void doc_rect_to_view_rect (EvView *view,
110 EvRectangle *doc_rect,
111 GdkRectangle *view_rect);
112 static gboolean get_dual_even_left (EvView *view);
113 static void find_page_at_location (EvView *view,
119 static void doc_point_to_view_point (EvView *view,
122 GdkPoint *view_point);
124 static EvLink * ev_view_get_link_at_location (EvView *view,
127 static char* tip_from_link (EvView *view,
130 static EvFormField *ev_view_get_form_field_at_location (EvView *view,
134 /*** Annotations ***/
135 static EvAnnotation *ev_view_get_annotation_at_location (EvView *view,
138 static void show_annotation_windows (EvView *view,
140 static void hide_annotation_windows (EvView *view,
142 /*** GtkWidget implementation ***/
143 static void ev_view_size_request_continuous_dual_page (EvView *view,
144 GtkRequisition *requisition);
145 static void ev_view_size_request_continuous (EvView *view,
146 GtkRequisition *requisition);
147 static void ev_view_size_request_dual_page (EvView *view,
148 GtkRequisition *requisition);
149 static void ev_view_size_request_single_page (EvView *view,
150 GtkRequisition *requisition);
151 static void ev_view_size_request (GtkWidget *widget,
152 GtkRequisition *requisition);
153 static void ev_view_size_allocate (GtkWidget *widget,
154 GtkAllocation *allocation);
155 static void ev_view_realize (GtkWidget *widget);
156 static gboolean ev_view_scroll_event (GtkWidget *widget,
157 GdkEventScroll *event);
158 static gboolean ev_view_expose_event (GtkWidget *widget,
159 GdkEventExpose *event);
160 static gboolean ev_view_popup_menu (GtkWidget *widget);
161 static gboolean ev_view_button_press_event (GtkWidget *widget,
162 GdkEventButton *event);
163 static gboolean ev_view_motion_notify_event (GtkWidget *widget,
164 GdkEventMotion *event);
165 static gboolean ev_view_button_release_event (GtkWidget *widget,
166 GdkEventButton *event);
167 static gboolean ev_view_enter_notify_event (GtkWidget *widget,
168 GdkEventCrossing *event);
169 static gboolean ev_view_leave_notify_event (GtkWidget *widget,
170 GdkEventCrossing *event);
171 static void ev_view_style_set (GtkWidget *widget,
172 GtkStyle *old_style);
173 static void ev_view_remove_all (EvView *view);
175 static AtkObject *ev_view_get_accessible (GtkWidget *widget);
178 static void highlight_find_results (EvView *view,
180 static void highlight_forward_search_results (EvView *view,
182 static void focus_annotation (EvView *view,
185 static void draw_one_page (EvView *view,
188 GdkRectangle *page_area,
190 GdkRectangle *expose_area,
191 gboolean *page_ready);
192 static void show_loading_window (EvView *view);
193 static void hide_loading_window (EvView *view);
194 static void ev_view_reload_page (EvView *view,
196 cairo_region_t *region);
197 static void ev_view_loading_window_move (EvView *view);
200 static void ev_view_change_page (EvView *view,
202 static void job_finished_cb (EvPixbufCache *pixbuf_cache,
203 cairo_region_t *region,
205 static void ev_view_page_changed_cb (EvDocumentModel *model,
209 static void on_adjustment_value_changed (GtkAdjustment *adjustment,
213 static void ev_view_finalize (GObject *object);
214 static void ev_view_destroy (GtkObject *object);
215 static void ev_view_class_init (EvViewClass *class);
216 static void ev_view_init (EvView *view);
218 /*** Zoom and sizing ***/
219 static double zoom_for_size_fit_width (gdouble doc_width,
223 static double zoom_for_size_fit_height (gdouble doc_width,
227 static double zoom_for_size_best_fit (gdouble doc_width,
231 static void ev_view_zoom_for_size (EvView *view,
234 static void ev_view_zoom_for_size_continuous_and_dual_page (EvView *view,
237 static void ev_view_zoom_for_size_continuous (EvView *view,
240 static void ev_view_zoom_for_size_dual_page (EvView *view,
243 static void ev_view_zoom_for_size_single_page (EvView *view,
247 static void ev_view_set_cursor (EvView *view,
248 EvViewCursor new_cursor);
249 static void ev_view_handle_cursor_over_xy (EvView *view,
254 static gint ev_view_find_get_n_results (EvView *view,
256 static EvRectangle *ev_view_find_get_result (EvView *view,
259 static void jump_to_find_result (EvView *view);
260 static void jump_to_find_page (EvView *view,
261 EvViewFindDirection direction,
264 static void compute_selections (EvView *view,
265 EvSelectionStyle style,
268 static void clear_selection (EvView *view);
269 static void clear_link_selected (EvView *view);
270 static void selection_free (EvViewSelection *selection);
271 static char* get_selected_text (EvView *ev_view);
272 static void ev_view_primary_get_cb (GtkClipboard *clipboard,
273 GtkSelectionData *selection_data,
276 static void ev_view_primary_clear_cb (GtkClipboard *clipboard,
278 static void ev_view_update_primary_selection (EvView *ev_view);
280 G_DEFINE_TYPE (EvView, ev_view, GTK_TYPE_LAYOUT)
282 /* HeightToPage cache */
283 #define EV_HEIGHT_TO_PAGE_CACHE_KEY "ev-height-to-page-cache"
286 build_height_to_page (EvHeightToPageCache *cache,
287 EvDocument *document,
290 gboolean swap, uniform, dual_even_left;
292 double uniform_height, page_height, next_page_height;
294 gdouble u_width, u_height;
297 swap = (rotation == 90 || rotation == 270);
299 uniform = ev_document_is_page_size_uniform (document);
300 n_pages = ev_document_get_n_pages (document);
301 dual_even_left = (n_pages > 2);
303 g_free (cache->height_to_page);
304 g_free (cache->dual_height_to_page);
306 cache->rotation = rotation;
307 cache->height_to_page = g_new0 (gdouble, n_pages + 1);
308 cache->dual_height_to_page = g_new0 (gdouble, n_pages + 2);
311 ev_document_get_page_size (document, 0, &u_width, &u_height);
314 for (i = 0; i <= n_pages; i++) {
316 uniform_height = swap ? u_width : u_height;
317 cache->height_to_page[i] = i * uniform_height;
322 ev_document_get_page_size (document, i, &w, &h);
323 page_height = swap ? w : h;
327 cache->height_to_page[i] = saved_height;
328 saved_height += page_height;
332 if (dual_even_left && !uniform) {
335 ev_document_get_page_size (document, 0, &w, &h);
336 saved_height = swap ? w : h;
341 for (i = dual_even_left; i < n_pages + 2; i += 2) {
343 uniform_height = swap ? u_width : u_height;
344 cache->dual_height_to_page[i] = ((i + dual_even_left) / 2) * uniform_height;
345 if (i + 1 < n_pages + 2)
346 cache->dual_height_to_page[i + 1] = ((i + dual_even_left) / 2) * uniform_height;
348 if (i + 1 < n_pages) {
351 ev_document_get_page_size (document, i + 1, &w, &h);
352 next_page_height = swap ? w : h;
354 next_page_height = 0;
360 ev_document_get_page_size (document, i, &w, &h);
361 page_height = swap ? w : h;
366 if (i + 1 < n_pages + 2) {
367 cache->dual_height_to_page[i] = saved_height;
368 cache->dual_height_to_page[i + 1] = saved_height;
369 saved_height += MAX(page_height, next_page_height);
371 cache->dual_height_to_page[i] = saved_height;
378 ev_height_to_page_cache_get_height (EvHeightToPageCache *cache,
379 EvDocument *document,
383 gdouble *dual_height)
385 if (cache->rotation != rotation)
386 build_height_to_page (cache, document, rotation);
388 *height = cache->height_to_page[page];
389 *dual_height = cache->dual_height_to_page[page];
393 ev_height_to_page_cache_free (EvHeightToPageCache *cache)
395 if (cache->height_to_page) {
396 g_free (cache->height_to_page);
397 cache->height_to_page = NULL;
400 if (cache->dual_height_to_page) {
401 g_free (cache->dual_height_to_page);
402 cache->dual_height_to_page = NULL;
407 static EvHeightToPageCache *
408 ev_view_get_height_to_page_cache (EvView *view)
410 EvHeightToPageCache *cache;
415 cache = g_object_get_data (G_OBJECT (view->document), EV_HEIGHT_TO_PAGE_CACHE_KEY);
417 cache = g_new0 (EvHeightToPageCache, 1);
418 build_height_to_page (cache, view->document, view->rotation);
419 g_object_set_data_full (G_OBJECT (view->document),
420 EV_HEIGHT_TO_PAGE_CACHE_KEY,
422 (GDestroyNotify)ev_height_to_page_cache_free);
429 ev_view_get_height_to_page (EvView *view,
436 if (!view->height_to_page_cache)
439 ev_height_to_page_cache_get_height (view->height_to_page_cache,
445 *height = (gint)(h * view->scale + 0.5);
448 *dual_height = (gint)(dh * view->scale + 0.5);
452 ev_view_get_scrollbar_size (EvView *view,
453 GtkOrientation orientation)
455 GtkWidget *widget = GTK_WIDGET (view);
457 GtkWidget *swindow = gtk_widget_get_parent (GTK_WIDGET (view));
458 GtkAllocation allocation;
462 if (!GTK_IS_SCROLLED_WINDOW (swindow))
465 gtk_widget_get_allocation (widget, &allocation);
467 if (orientation == GTK_ORIENTATION_VERTICAL) {
468 if (allocation.height >= view->requisition.height)
469 sb = gtk_scrolled_window_get_vscrollbar (GTK_SCROLLED_WINDOW (swindow));
473 if (allocation.width >= view->requisition.width)
474 sb = gtk_scrolled_window_get_hscrollbar (GTK_SCROLLED_WINDOW (swindow));
479 gtk_widget_style_get (swindow, "scrollbar_spacing", &spacing, NULL);
480 gtk_widget_size_request (sb, &req);
482 return (orientation == GTK_ORIENTATION_VERTICAL ? req.width : req.height) + spacing;
486 scroll_to_point (EvView *view,
489 GtkOrientation orientation)
492 gdouble upper, lower;
494 if (orientation == GTK_ORIENTATION_VERTICAL) {
495 page_size = gtk_adjustment_get_page_size (view->vadjustment);
496 upper = gtk_adjustment_get_upper (view->vadjustment);
497 lower = gtk_adjustment_get_lower (view->vadjustment);
499 if (view->continuous) {
500 gtk_adjustment_clamp_page (view->vadjustment,
501 y - view->spacing / 2,
504 gtk_adjustment_set_value (view->vadjustment,
505 CLAMP (y, lower, upper - page_size));
508 page_size = gtk_adjustment_get_page_size (view->hadjustment);
509 upper = gtk_adjustment_get_upper (view->hadjustment);
510 lower = gtk_adjustment_get_lower (view->hadjustment);
512 if (view->dual_page) {
513 gtk_adjustment_clamp_page (view->hadjustment, x,
516 gtk_adjustment_set_value (view->hadjustment,
517 CLAMP (x, lower, upper - page_size));
523 ev_view_scroll_to_page_position (EvView *view, GtkOrientation orientation)
530 if ((orientation == GTK_ORIENTATION_VERTICAL && view->pending_point.y == 0) ||
531 (orientation == GTK_ORIENTATION_HORIZONTAL && view->pending_point.x == 0)) {
532 GdkRectangle page_area;
535 ev_view_get_page_extents (view, view->current_page, &page_area, &border);
541 doc_point_to_view_point (view, view->current_page,
542 &view->pending_point, &view_point);
547 scroll_to_point (view, x, y, orientation);
551 view_set_adjustment_values (EvView *view,
552 GtkOrientation orientation)
554 GtkWidget *widget = GTK_WIDGET (view);
555 GtkAdjustment *adjustment;
556 GtkAllocation allocation;
565 gtk_widget_get_allocation (widget, &allocation);
567 if (orientation == GTK_ORIENTATION_HORIZONTAL) {
568 req_size = view->requisition.width;
569 alloc_size = allocation.width;
570 adjustment = view->hadjustment;
572 req_size = view->requisition.height;
573 alloc_size = allocation.height;
574 adjustment = view->vadjustment;
581 value = gtk_adjustment_get_value (adjustment);
582 upper = gtk_adjustment_get_upper (adjustment);
583 page_size = gtk_adjustment_get_page_size (adjustment);
585 switch (view->pending_scroll) {
586 case SCROLL_TO_KEEP_POSITION:
587 case SCROLL_TO_FIND_LOCATION:
588 factor = value / upper;
590 case SCROLL_TO_PAGE_POSITION:
592 case SCROLL_TO_CENTER:
593 factor = (value + page_size * 0.5) / upper;
597 upper = MAX (alloc_size, req_size);
598 page_size = alloc_size;
600 gtk_adjustment_set_page_size (adjustment, page_size);
601 gtk_adjustment_set_step_increment (adjustment, alloc_size * 0.1);
602 gtk_adjustment_set_page_increment (adjustment, alloc_size * 0.9);
603 gtk_adjustment_set_lower (adjustment, 0);
604 gtk_adjustment_set_upper (adjustment, upper);
607 * We add 0.5 to the values before to average out our rounding errors.
609 switch (view->pending_scroll) {
610 case SCROLL_TO_KEEP_POSITION:
611 case SCROLL_TO_FIND_LOCATION:
612 new_value = CLAMP (upper * factor + 0.5, 0, upper - page_size);
613 gtk_adjustment_set_value (adjustment, (int)new_value);
615 case SCROLL_TO_PAGE_POSITION:
616 ev_view_scroll_to_page_position (view, orientation);
618 case SCROLL_TO_CENTER:
619 new_value = CLAMP (upper * factor - page_size * 0.5 + 0.5,
620 0, upper - page_size);
621 gtk_adjustment_set_value (adjustment, (int)new_value);
625 gtk_adjustment_changed (adjustment);
629 view_update_range_and_current_page (EvView *view)
631 gint start = view->start_page;
632 gint end = view->end_page;
634 if (ev_document_get_n_pages (view->document) <= 0 ||
635 !ev_document_check_dimensions (view->document))
638 if (view->continuous) {
639 GdkRectangle current_area, unused, page_area;
641 gboolean found = FALSE;
642 gint area_max = -1, area;
643 gint best_current_page = -1;
646 if (!(view->vadjustment && view->hadjustment))
649 current_area.x = gtk_adjustment_get_value (view->hadjustment);
650 current_area.width = gtk_adjustment_get_page_size (view->hadjustment);
651 current_area.y = gtk_adjustment_get_value (view->vadjustment);
652 current_area.height = gtk_adjustment_get_page_size (view->vadjustment);
654 for (i = 0; i < ev_document_get_n_pages (view->document); i++) {
656 ev_view_get_page_extents (view, i, &page_area, &border);
658 if (gdk_rectangle_intersect (¤t_area, &page_area, &unused)) {
659 area = unused.width * unused.height;
663 view->start_page = i;
665 best_current_page = i;
667 if (area > area_max) {
668 best_current_page = (area == area_max) ? MIN (i, best_current_page) : i;
674 } else if (found && view->current_page <= view->end_page) {
675 if (view->dual_page && j < 1) {
676 /* In dual mode we stop searching
677 * after two consecutive non-visible pages.
686 if (view->pending_scroll == SCROLL_TO_KEEP_POSITION) {
687 best_current_page = MAX (best_current_page, view->start_page);
689 if (view->current_page != best_current_page) {
690 view->current_page = best_current_page;
691 hide_loading_window (view);
692 ev_document_model_set_page (view->model, best_current_page);
695 } else if (view->dual_page) {
696 if (view->current_page % 2 == get_dual_even_left (view)) {
697 view->start_page = view->current_page;
698 if (view->current_page + 1 < ev_document_get_n_pages (view->document))
699 view->end_page = view->start_page + 1;
701 view->end_page = view->start_page;
703 if (view->current_page < 1)
704 view->start_page = view->current_page;
706 view->start_page = view->current_page - 1;
707 view->end_page = view->current_page;
710 view->start_page = view->current_page;
711 view->end_page = view->current_page;
714 if (view->start_page == -1 || view->end_page == -1)
717 if (start != view->start_page || end != view->end_page) {
720 for (i = start; i < view->start_page && start != -1; i++) {
721 hide_annotation_windows (view, i);
724 for (i = end; i > view->end_page && end != -1; i--) {
725 hide_annotation_windows (view, i);
729 ev_page_cache_set_page_range (view->page_cache,
732 ev_pixbuf_cache_set_page_range (view->pixbuf_cache,
735 view->selection_info.selections);
737 if (ev_pixbuf_cache_get_surface (view->pixbuf_cache, view->current_page))
738 gtk_widget_queue_draw (GTK_WIDGET (view));
742 set_scroll_adjustment (EvView *view,
743 GtkOrientation orientation,
744 GtkAdjustment *adjustment)
746 GtkAdjustment **to_set;
748 if (orientation == GTK_ORIENTATION_HORIZONTAL)
749 to_set = &view->hadjustment;
751 to_set = &view->vadjustment;
753 if (*to_set != adjustment) {
755 g_signal_handlers_disconnect_by_func (*to_set,
756 (gpointer) on_adjustment_value_changed,
758 g_object_unref (*to_set);
761 *to_set = adjustment;
762 view_set_adjustment_values (view, orientation);
765 g_object_ref (*to_set);
766 g_signal_connect (*to_set, "value_changed",
767 G_CALLBACK (on_adjustment_value_changed), view);
773 ev_view_set_scroll_adjustments (GtkLayout *layout,
774 GtkAdjustment *hadjustment,
775 GtkAdjustment *vadjustment)
777 EvView *view = EV_VIEW (layout);
779 set_scroll_adjustment (view, GTK_ORIENTATION_HORIZONTAL, hadjustment);
780 set_scroll_adjustment (view, GTK_ORIENTATION_VERTICAL, vadjustment);
782 on_adjustment_value_changed (NULL, view);
786 add_scroll_binding_keypad (GtkBindingSet *binding_set,
788 GdkModifierType modifiers,
789 GtkScrollType scroll,
792 guint keypad_keyval = keyval - GDK_Left + GDK_KP_Left;
794 gtk_binding_entry_add_signal (binding_set, keyval, modifiers,
795 "binding_activated", 2,
796 GTK_TYPE_SCROLL_TYPE, scroll,
797 G_TYPE_BOOLEAN, horizontal);
798 gtk_binding_entry_add_signal (binding_set, keypad_keyval, modifiers,
799 "binding_activated", 2,
800 GTK_TYPE_SCROLL_TYPE, scroll,
801 G_TYPE_BOOLEAN, horizontal);
805 compute_scroll_increment (EvView *view,
806 GtkScrollType scroll)
808 GtkWidget *widget = GTK_WIDGET (view);
809 GtkAdjustment *adjustment = view->vadjustment;
810 cairo_region_t *text_region, *region;
811 GtkAllocation allocation;
814 EvRectangle doc_rect;
815 GdkRectangle page_area;
817 gdouble fraction = 1.0;
819 if (scroll != GTK_SCROLL_PAGE_BACKWARD && scroll != GTK_SCROLL_PAGE_FORWARD)
820 return gtk_adjustment_get_page_size (adjustment);
822 page = scroll == GTK_SCROLL_PAGE_BACKWARD ? view->start_page : view->end_page;
824 text_region = ev_page_cache_get_text_mapping (view->page_cache, page);
825 if (!text_region || cairo_region_is_empty (text_region))
826 return gtk_adjustment_get_page_size (adjustment);
828 gtk_widget_get_allocation (widget, &allocation);
829 ev_view_get_page_extents (view, page, &page_area, &border);
830 rect.x = page_area.x + view->scroll_x;
831 rect.y = view->scroll_y + (scroll == GTK_SCROLL_PAGE_BACKWARD ? 5 : allocation.height - 5);
832 rect.width = page_area.width;
834 view_rect_to_doc_rect (view, &rect, &page_area, &doc_rect);
836 /* Convert the doc rectangle into a GdkRectangle */
837 rect.x = doc_rect.x1;
838 rect.y = doc_rect.y1;
839 rect.width = doc_rect.x2 - doc_rect.x1;
840 rect.height = MAX (1, doc_rect.y2 - doc_rect.y1);
841 region = cairo_region_create_rectangle (&rect);
843 cairo_region_intersect (region, text_region);
844 if (cairo_region_num_rectangles (region)) {
847 cairo_region_t *sel_region;
849 cairo_region_get_rectangle (region, 0, &rect);
850 ev_page = ev_document_get_page (view->document, page);
851 rc = ev_render_context_new (ev_page, view->rotation, view->scale);
852 g_object_unref (ev_page);
853 /* Get the selection region to know the height of the line */
854 doc_rect.x1 = doc_rect.x2 = rect.x + 0.5;
855 doc_rect.y1 = doc_rect.y2 = rect.y + 0.5;
857 ev_document_doc_mutex_lock ();
858 sel_region = ev_selection_get_selection_region (EV_SELECTION (view->document),
859 rc, EV_SELECTION_STYLE_LINE,
861 ev_document_doc_mutex_unlock ();
865 if (cairo_region_num_rectangles (sel_region) > 0) {
866 cairo_region_get_rectangle (sel_region, 0, &rect);
867 fraction = 1 - (rect.height / gtk_adjustment_get_page_size (adjustment));
869 cairo_region_destroy (sel_region);
871 cairo_region_destroy (region);
873 return gtk_adjustment_get_page_size (adjustment) * fraction;
878 ev_view_scroll (EvView *view,
879 GtkScrollType scroll,
882 GtkAdjustment *adjustment;
883 double value, increment;
884 gdouble upper, lower;
886 gdouble step_increment;
887 gboolean first_page = FALSE;
888 gboolean last_page = FALSE;
890 view->jump_to_find_result = FALSE;
892 if (view->sizing_mode == EV_SIZING_BEST_FIT) {
894 case GTK_SCROLL_PAGE_BACKWARD:
895 case GTK_SCROLL_STEP_BACKWARD:
896 ev_view_previous_page (view);
898 case GTK_SCROLL_PAGE_FORWARD:
899 case GTK_SCROLL_STEP_FORWARD:
900 ev_view_next_page (view);
908 /* Assign values for increment and vertical adjustment */
909 adjustment = horizontal ? view->hadjustment : view->vadjustment;
910 value = gtk_adjustment_get_value (adjustment);
911 upper = gtk_adjustment_get_upper (adjustment);
912 lower = gtk_adjustment_get_lower (adjustment);
913 page_size = gtk_adjustment_get_page_size (adjustment);
914 step_increment = gtk_adjustment_get_step_increment (adjustment);
916 /* Assign boolean for first and last page */
917 if (view->current_page == 0)
919 if (view->current_page == ev_document_get_n_pages (view->document) - 1)
923 case GTK_SCROLL_PAGE_BACKWARD:
924 /* Do not jump backwards if at the first page */
925 if (value == lower && first_page) {
927 /* At the top of a page, assign the upper bound limit of previous page */
928 } else if (value == lower) {
929 value = upper - page_size;
930 ev_view_previous_page (view);
931 /* Jump to the top */
933 increment = compute_scroll_increment (view, GTK_SCROLL_PAGE_BACKWARD);
934 value = MAX (value - increment, lower);
937 case GTK_SCROLL_PAGE_FORWARD:
938 /* Do not jump forward if at the last page */
939 if (value == (upper - page_size) && last_page) {
941 /* At the bottom of a page, assign the lower bound limit of next page */
942 } else if (value == (upper - page_size)) {
944 ev_view_next_page (view);
945 /* Jump to the bottom */
947 increment = compute_scroll_increment (view, GTK_SCROLL_PAGE_FORWARD);
948 value = MIN (value + increment, upper - page_size);
951 case GTK_SCROLL_STEP_BACKWARD:
952 value -= step_increment;
954 case GTK_SCROLL_STEP_FORWARD:
955 value += step_increment;
957 case GTK_SCROLL_STEP_DOWN:
958 value -= step_increment / 10;
960 case GTK_SCROLL_STEP_UP:
961 value += step_increment / 10;
967 value = CLAMP (value, lower, upper - page_size);
969 gtk_adjustment_set_value (adjustment, value);
975 ensure_rectangle_is_visible (EvView *view, GdkRectangle *rect)
977 GtkWidget *widget = GTK_WIDGET (view);
978 GtkAdjustment *adjustment;
979 GtkAllocation allocation;
983 view->pending_scroll = SCROLL_TO_FIND_LOCATION;
985 gtk_widget_get_allocation (widget, &allocation);
987 adjustment = view->vadjustment;
988 adj_value = gtk_adjustment_get_value (adjustment);
990 if (rect->y < adj_value) {
991 value = MAX (gtk_adjustment_get_lower (adjustment), rect->y - MARGIN);
992 gtk_adjustment_set_value (view->vadjustment, value);
993 } else if (rect->y + rect->height > adj_value + allocation.height) {
994 value = MIN (gtk_adjustment_get_upper (adjustment), rect->y + rect->height -
995 allocation.height + MARGIN);
996 gtk_adjustment_set_value (view->vadjustment, value);
999 adjustment = view->hadjustment;
1000 adj_value = gtk_adjustment_get_value (adjustment);
1002 if (rect->x < adj_value) {
1003 value = MAX (gtk_adjustment_get_lower (adjustment), rect->x - MARGIN);
1004 gtk_adjustment_set_value (view->hadjustment, value);
1005 } else if (rect->x + rect->height > adj_value + allocation.width) {
1006 value = MIN (gtk_adjustment_get_upper (adjustment), rect->x + rect->width -
1007 allocation.width + MARGIN);
1008 gtk_adjustment_set_value (view->hadjustment, value);
1011 gtk_widget_queue_resize (GTK_WIDGET (view));
1014 /*** Geometry computations ***/
1017 compute_border (EvView *view, int width, int height, GtkBorder *border)
1019 ev_document_misc_get_page_border_size (width, height, border);
1023 _get_page_size_for_scale_and_rotation (EvDocument *document,
1033 ev_document_get_page_size (document, page, &w, &h);
1035 width = (gint)(w * scale + 0.5);
1036 height = (gint)(h * scale + 0.5);
1039 *page_width = (rotation == 0 || rotation == 180) ? width : height;
1041 *page_height = (rotation == 0 || rotation == 180) ? height : width;
1045 ev_view_get_page_size (EvView *view,
1050 _get_page_size_for_scale_and_rotation (view->document,
1059 ev_view_get_max_page_size (EvView *view,
1066 ev_document_get_max_page_size (view->document, &w, &h);
1068 width = (gint)(w * view->scale + 0.5);
1069 height = (gint)(h * view->scale + 0.5);
1072 *max_width = (view->rotation == 0 || view->rotation == 180) ? width : height;
1074 *max_height = (view->rotation == 0 || view->rotation == 180) ? height : width;
1078 get_page_y_offset (EvView *view, int page, int *y_offset)
1080 int max_width, offset;
1083 g_return_if_fail (y_offset != NULL);
1085 ev_view_get_max_page_size (view, &max_width, NULL);
1086 compute_border (view, max_width, max_width, &border);
1088 if (view->dual_page) {
1089 ev_view_get_height_to_page (view, page, NULL, &offset);
1090 offset += ((page + get_dual_even_left (view)) / 2 + 1) * view->spacing +
1091 ((page + get_dual_even_left (view)) / 2 ) * (border.top + border.bottom);
1093 ev_view_get_height_to_page (view, page, &offset, NULL);
1094 offset += (page + 1) * view->spacing + page * (border.top + border.bottom);
1102 ev_view_get_page_extents (EvView *view,
1104 GdkRectangle *page_area,
1109 GtkAllocation allocation;
1111 widget = GTK_WIDGET (view);
1112 gtk_widget_get_allocation (widget, &allocation);
1114 /* Get the size of the page */
1115 ev_view_get_page_size (view, page, &width, &height);
1116 compute_border (view, width, height, border);
1117 page_area->width = width + border->left + border->right;
1118 page_area->height = height + border->top + border->bottom;
1120 if (view->continuous) {
1124 ev_view_get_max_page_size (view, &max_width, NULL);
1125 max_width = max_width + border->left + border->right;
1126 /* Get the location of the bounding box */
1127 if (view->dual_page) {
1128 x = view->spacing + ((page % 2 == get_dual_even_left (view)) ? 0 : 1) * (max_width + view->spacing);
1129 x = x + MAX (0, allocation.width - (max_width * 2 + view->spacing * 3)) / 2;
1130 if (page % 2 == get_dual_even_left (view))
1131 x = x + (max_width - width - border->left - border->right);
1134 x = x + MAX (0, allocation.width - (width + view->spacing * 2)) / 2;
1137 get_page_y_offset (view, page, &y);
1143 if (view->dual_page) {
1144 gint width_2, height_2;
1145 gint max_width = width;
1146 gint max_height = height;
1147 GtkBorder overall_border;
1150 other_page = (page % 2 == get_dual_even_left (view)) ? page + 1: page - 1;
1152 /* First, we get the bounding box of the two pages */
1153 if (other_page < ev_document_get_n_pages (view->document)
1154 && (0 <= other_page)) {
1155 ev_view_get_page_size (view, other_page,
1156 &width_2, &height_2);
1157 if (width_2 > width)
1158 max_width = width_2;
1159 if (height_2 > height)
1160 max_height = height_2;
1162 compute_border (view, max_width, max_height, &overall_border);
1164 /* Find the offsets */
1168 /* Adjust for being the left or right page */
1169 if (page % 2 == get_dual_even_left (view))
1170 x = x + max_width - width;
1172 x = x + (max_width + overall_border.left + overall_border.right) + view->spacing;
1174 y = y + (max_height - height)/2;
1176 /* Adjust for extra allocation */
1177 x = x + MAX (0, allocation.width -
1178 ((max_width + overall_border.left + overall_border.right) * 2 + view->spacing * 3))/2;
1179 y = y + MAX (0, allocation.height - (height + view->spacing * 2))/2;
1184 /* Adjust for extra allocation */
1185 x = x + MAX (0, allocation.width - (width + border->left + border->right + view->spacing * 2))/2;
1186 y = y + MAX (0, allocation.height - (height + border->top + border->bottom + view->spacing * 2))/2;
1197 get_doc_page_size (EvView *view,
1204 ev_document_get_page_size (view->document, page, &w, &h);
1205 if (view->rotation == 0 || view->rotation == 180) {
1206 if (width) *width = w;
1207 if (height) *height = h;
1209 if (width) *width = h;
1210 if (height) *height = w;
1215 view_point_to_doc_point (EvView *view,
1216 GdkPoint *view_point,
1217 GdkRectangle *page_area,
1218 double *doc_point_x,
1219 double *doc_point_y)
1221 *doc_point_x = (double) (view_point->x - page_area->x) / view->scale;
1222 *doc_point_y = (double) (view_point->y - page_area->y) / view->scale;
1226 view_rect_to_doc_rect (EvView *view,
1227 GdkRectangle *view_rect,
1228 GdkRectangle *page_area,
1229 EvRectangle *doc_rect)
1231 doc_rect->x1 = (double) (view_rect->x - page_area->x) / view->scale;
1232 doc_rect->y1 = (double) (view_rect->y - page_area->y) / view->scale;
1233 doc_rect->x2 = doc_rect->x1 + (double) view_rect->width / view->scale;
1234 doc_rect->y2 = doc_rect->y1 + (double) view_rect->height / view->scale;
1238 doc_point_to_view_point (EvView *view,
1241 GdkPoint *view_point)
1243 GdkRectangle page_area;
1245 double x, y, view_x, view_y;
1246 gdouble width, height;
1248 get_doc_page_size (view, page, &width, &height);
1250 if (view->rotation == 0) {
1253 } else if (view->rotation == 90) {
1254 x = width - doc_point->y;
1256 } else if (view->rotation == 180) {
1257 x = width - doc_point->x;
1258 y = height - doc_point->y;
1259 } else if (view->rotation == 270) {
1261 y = height - doc_point->x;
1263 g_assert_not_reached ();
1266 ev_view_get_page_extents (view, page, &page_area, &border);
1268 view_x = CLAMP (x * view->scale, 0, page_area.width);
1269 view_y = CLAMP (y * view->scale, 0, page_area.height);
1270 view_point->x = view_x + page_area.x;
1271 view_point->y = view_y + page_area.y;
1275 doc_rect_to_view_rect (EvView *view,
1277 EvRectangle *doc_rect,
1278 GdkRectangle *view_rect)
1280 GdkRectangle page_area;
1283 gdouble width, height;
1285 get_doc_page_size (view, page, &width, &height);
1287 if (view->rotation == 0) {
1290 w = doc_rect->x2 - doc_rect->x1;
1291 h = doc_rect->y2 - doc_rect->y1;
1292 } else if (view->rotation == 90) {
1293 x = width - doc_rect->y2;
1295 w = doc_rect->y2 - doc_rect->y1;
1296 h = doc_rect->x2 - doc_rect->x1;
1297 } else if (view->rotation == 180) {
1298 x = width - doc_rect->x2;
1299 y = height - doc_rect->y2;
1300 w = doc_rect->x2 - doc_rect->x1;
1301 h = doc_rect->y2 - doc_rect->y1;
1302 } else if (view->rotation == 270) {
1304 y = height - doc_rect->x2;
1305 w = doc_rect->y2 - doc_rect->y1;
1306 h = doc_rect->x2 - doc_rect->x1;
1308 g_assert_not_reached ();
1311 ev_view_get_page_extents (view, page, &page_area, &border);
1313 view_rect->x = x * view->scale + page_area.x;
1314 view_rect->y = y * view->scale + page_area.y;
1315 view_rect->width = w * view->scale;
1316 view_rect->height = h * view->scale;
1320 get_dual_even_left (EvView *view)
1322 return (ev_document_get_n_pages (view->document) > 2);
1326 find_page_at_location (EvView *view,
1335 if (view->document == NULL)
1339 g_assert (x_offset);
1340 g_assert (y_offset);
1342 for (i = view->start_page; i >= 0 && i <= view->end_page; i++) {
1343 GdkRectangle page_area;
1346 if (! ev_view_get_page_extents (view, i, &page_area, &border))
1349 if ((x >= page_area.x + border.left) &&
1350 (x < page_area.x + page_area.width - border.right) &&
1351 (y >= page_area.y + border.top) &&
1352 (y < page_area.y + page_area.height - border.bottom)) {
1354 *x_offset = x - (page_area.x + border.left);
1355 *y_offset = y - (page_area.y + border.top);
1364 location_in_text (EvView *view,
1368 cairo_region_t *region;
1370 gint x_offset = 0, y_offset = 0;
1372 find_page_at_location (view, x, y, &page, &x_offset, &y_offset);
1377 region = ev_page_cache_get_text_mapping (view->page_cache, page);
1380 return cairo_region_contains_point (region, x_offset / view->scale, y_offset / view->scale);
1386 location_in_selected_text (EvView *view,
1391 gint x_offset = 0, y_offset = 0;
1392 EvViewSelection *selection;
1395 for (l = view->selection_info.selections; l != NULL; l = l->next) {
1396 selection = (EvViewSelection *)l->data;
1398 find_page_at_location (view, x, y, &page, &x_offset, &y_offset);
1400 if (page != selection->page)
1403 if (selection->covered_region &&
1404 cairo_region_contains_point (selection->covered_region, x_offset, y_offset))
1412 get_doc_point_from_offset (EvView *view,
1419 gdouble width, height;
1422 get_doc_page_size (view, page, &width, &height);
1424 x_offset = x_offset / view->scale;
1425 y_offset = y_offset / view->scale;
1427 if (view->rotation == 0) {
1430 } else if (view->rotation == 90) {
1432 y = width - x_offset;
1433 } else if (view->rotation == 180) {
1434 x = width - x_offset;
1435 y = height - y_offset;
1436 } else if (view->rotation == 270) {
1437 x = height - y_offset;
1440 g_assert_not_reached ();
1450 get_doc_point_from_location (EvView *view,
1457 gint x_offset = 0, y_offset = 0;
1459 x += view->scroll_x;
1460 y += view->scroll_y;
1461 find_page_at_location (view, x, y, page, &x_offset, &y_offset);
1465 return get_doc_point_from_offset (view, *page, x_offset, y_offset, x_new, y_new);
1469 ev_view_get_area_from_mapping (EvView *view,
1471 EvMappingList *mapping_list,
1477 mapping = ev_mapping_list_find (mapping_list, data);
1478 doc_rect_to_view_rect (view, page, &mapping->area, area);
1479 area->x -= view->scroll_x;
1480 area->y -= view->scroll_y;
1486 ev_view_get_link_at_location (EvView *view,
1491 gint x_new = 0, y_new = 0;
1492 EvMappingList *link_mapping;
1494 if (!EV_IS_DOCUMENT_LINKS (view->document))
1497 if (!get_doc_point_from_location (view, x, y, &page, &x_new, &y_new))
1500 link_mapping = ev_page_cache_get_link_mapping (view->page_cache, page);
1503 return ev_mapping_list_get_data (link_mapping, x_new, y_new);
1509 goto_fitr_dest (EvView *view, EvLinkDest *dest)
1512 gdouble zoom, left, top;
1513 gboolean change_left, change_top;
1514 GtkAllocation allocation;
1516 gtk_widget_get_allocation (GTK_WIDGET (view), &allocation);
1518 left = ev_link_dest_get_left (dest, &change_left);
1519 top = ev_link_dest_get_top (dest, &change_top);
1521 zoom = zoom_for_size_best_fit (ev_link_dest_get_right (dest) - left,
1522 ev_link_dest_get_bottom (dest) - top,
1526 ev_document_model_set_sizing_mode (view->model, EV_SIZING_FREE);
1527 ev_document_model_set_scale (view->model, zoom);
1529 doc_point.x = change_left ? left : 0;
1530 doc_point.y = change_top ? top : 0;
1531 view->pending_point = doc_point;
1533 ev_view_change_page (view, ev_link_dest_get_page (dest));
1537 goto_fitv_dest (EvView *view, EvLinkDest *dest)
1540 gdouble doc_width, doc_height;
1543 gboolean change_left;
1544 GtkAllocation allocation;
1546 gtk_widget_get_allocation (GTK_WIDGET (view), &allocation);
1548 page = ev_link_dest_get_page (dest);
1549 ev_document_get_page_size (view->document, page, &doc_width, &doc_height);
1551 left = ev_link_dest_get_left (dest, &change_left);
1552 doc_point.x = change_left ? left : 0;
1555 zoom = zoom_for_size_fit_height (doc_width - doc_point.x , doc_height,
1559 ev_document_model_set_sizing_mode (view->model, EV_SIZING_FREE);
1560 ev_document_model_set_scale (view->model, zoom);
1562 view->pending_point = doc_point;
1564 ev_view_change_page (view, page);
1568 goto_fith_dest (EvView *view, EvLinkDest *dest)
1571 gdouble doc_width, doc_height;
1574 gboolean change_top;
1575 GtkAllocation allocation;
1577 gtk_widget_get_allocation (GTK_WIDGET (view), &allocation);
1579 page = ev_link_dest_get_page (dest);
1580 ev_document_get_page_size (view->document, page, &doc_width, &doc_height);
1582 top = ev_link_dest_get_top (dest, &change_top);
1585 doc_point.y = change_top ? top : 0;
1587 zoom = zoom_for_size_fit_width (doc_width, top,
1591 ev_document_model_set_sizing_mode (view->model, EV_SIZING_FIT_WIDTH);
1592 ev_document_model_set_scale (view->model, zoom);
1594 view->pending_point = doc_point;
1596 ev_view_change_page (view, page);
1600 goto_fit_dest (EvView *view, EvLinkDest *dest)
1603 gdouble doc_width, doc_height;
1605 GtkAllocation allocation;
1607 gtk_widget_get_allocation (GTK_WIDGET (view), &allocation);
1609 page = ev_link_dest_get_page (dest);
1610 ev_document_get_page_size (view->document, page, &doc_width, &doc_height);
1612 zoom = zoom_for_size_best_fit (doc_width, doc_height,
1616 ev_document_model_set_sizing_mode (view->model, EV_SIZING_BEST_FIT);
1617 ev_document_model_set_scale (view->model, zoom);
1619 ev_view_change_page (view, page);
1623 goto_xyz_dest (EvView *view, EvLinkDest *dest)
1627 gdouble zoom, left, top;
1628 gboolean change_zoom, change_left, change_top;
1630 zoom = ev_link_dest_get_zoom (dest, &change_zoom);
1631 page = ev_link_dest_get_page (dest);
1633 if (change_zoom && zoom > 1) {
1634 ev_document_model_set_sizing_mode (view->model, EV_SIZING_FREE);
1635 ev_document_model_set_scale (view->model, zoom);
1638 left = ev_link_dest_get_left (dest, &change_left);
1639 top = ev_link_dest_get_top (dest, &change_top);
1641 doc_point.x = change_left ? left : 0;
1642 doc_point.y = change_top ? top : 0;
1643 view->pending_point = doc_point;
1645 ev_view_change_page (view, page);
1649 goto_dest (EvView *view, EvLinkDest *dest)
1651 EvLinkDestType type;
1652 int page, n_pages, current_page;
1654 page = ev_link_dest_get_page (dest);
1655 n_pages = ev_document_get_n_pages (view->document);
1657 if (page < 0 || page >= n_pages)
1660 current_page = view->current_page;
1662 type = ev_link_dest_get_dest_type (dest);
1665 case EV_LINK_DEST_TYPE_PAGE:
1666 ev_document_model_set_page (view->model, page);
1668 case EV_LINK_DEST_TYPE_FIT:
1669 goto_fit_dest (view, dest);
1671 case EV_LINK_DEST_TYPE_FITH:
1672 goto_fith_dest (view, dest);
1674 case EV_LINK_DEST_TYPE_FITV:
1675 goto_fitv_dest (view, dest);
1677 case EV_LINK_DEST_TYPE_FITR:
1678 goto_fitr_dest (view, dest);
1680 case EV_LINK_DEST_TYPE_XYZ:
1681 goto_xyz_dest (view, dest);
1683 case EV_LINK_DEST_TYPE_PAGE_LABEL:
1684 ev_document_model_set_page_by_label (view->model, ev_link_dest_get_page_label (dest));
1687 g_assert_not_reached ();
1690 if (current_page != view->current_page)
1691 ev_document_model_set_page (view->model, view->current_page);
1695 ev_view_goto_dest (EvView *view, EvLinkDest *dest)
1697 EvLinkDestType type;
1699 type = ev_link_dest_get_dest_type (dest);
1701 if (type == EV_LINK_DEST_TYPE_NAMED) {
1703 const gchar *named_dest;
1705 named_dest = ev_link_dest_get_named_dest (dest);
1706 dest2 = ev_document_links_find_link_dest (EV_DOCUMENT_LINKS (view->document),
1709 goto_dest (view, dest2);
1710 g_object_unref (dest2);
1716 goto_dest (view, dest);
1720 ev_view_handle_link (EvView *view, EvLink *link)
1722 EvLinkAction *action = NULL;
1723 EvLinkActionType type;
1725 action = ev_link_get_action (link);
1729 type = ev_link_action_get_action_type (action);
1732 case EV_LINK_ACTION_TYPE_GOTO_DEST: {
1735 g_signal_emit (view, signals[SIGNAL_HANDLE_LINK], 0, link);
1737 dest = ev_link_action_get_dest (action);
1738 ev_view_goto_dest (view, dest);
1741 case EV_LINK_ACTION_TYPE_GOTO_REMOTE:
1742 case EV_LINK_ACTION_TYPE_EXTERNAL_URI:
1743 case EV_LINK_ACTION_TYPE_LAUNCH:
1744 case EV_LINK_ACTION_TYPE_NAMED:
1745 g_signal_emit (view, signals[SIGNAL_EXTERNAL_LINK], 0, action);
1751 tip_from_action_named (EvLinkAction *action)
1753 const gchar *name = ev_link_action_get_name (action);
1755 if (g_ascii_strcasecmp (name, "FirstPage") == 0) {
1756 return g_strdup (_("Go to first page"));
1757 } else if (g_ascii_strcasecmp (name, "PrevPage") == 0) {
1758 return g_strdup (_("Go to previous page"));
1759 } else if (g_ascii_strcasecmp (name, "NextPage") == 0) {
1760 return g_strdup (_("Go to next page"));
1761 } else if (g_ascii_strcasecmp (name, "LastPage") == 0) {
1762 return g_strdup (_("Go to last page"));
1763 } else if (g_ascii_strcasecmp (name, "GoToPage") == 0) {
1764 return g_strdup (_("Go to page"));
1765 } else if (g_ascii_strcasecmp (name, "Find") == 0) {
1766 return g_strdup (_("Find"));
1773 tip_from_link (EvView *view, EvLink *link)
1775 EvLinkAction *action;
1776 EvLinkActionType type;
1781 action = ev_link_get_action (link);
1782 title = ev_link_get_title (link);
1785 return title ? g_strdup (title) : NULL;
1787 type = ev_link_action_get_action_type (action);
1790 case EV_LINK_ACTION_TYPE_GOTO_DEST:
1791 page_label = ev_document_links_get_dest_page_label (EV_DOCUMENT_LINKS (view->document),
1792 ev_link_action_get_dest (action));
1794 msg = g_strdup_printf (_("Go to page %s"), page_label);
1795 g_free (page_label);
1798 case EV_LINK_ACTION_TYPE_GOTO_REMOTE:
1800 msg = g_strdup_printf (_("Go to %s on file “%s”"), title,
1801 ev_link_action_get_filename (action));
1803 msg = g_strdup_printf (_("Go to file “%s”"),
1804 ev_link_action_get_filename (action));
1807 case EV_LINK_ACTION_TYPE_EXTERNAL_URI:
1808 msg = g_strdup (ev_link_action_get_uri (action));
1810 case EV_LINK_ACTION_TYPE_LAUNCH:
1811 msg = g_strdup_printf (_("Launch %s"),
1812 ev_link_action_get_filename (action));
1814 case EV_LINK_ACTION_TYPE_NAMED:
1815 msg = tip_from_action_named (action);
1819 msg = g_strdup (title);
1827 ev_view_handle_cursor_over_xy (EvView *view, gint x, gint y)
1831 EvAnnotation *annot = NULL;
1833 if (view->cursor == EV_VIEW_CURSOR_HIDDEN)
1836 if (view->adding_annot) {
1837 if (view->cursor != EV_VIEW_CURSOR_ADD)
1838 ev_view_set_cursor (view, EV_VIEW_CURSOR_ADD);
1842 if (view->drag_info.in_drag) {
1843 if (view->cursor != EV_VIEW_CURSOR_DRAG)
1844 ev_view_set_cursor (view, EV_VIEW_CURSOR_DRAG);
1848 if (view->scroll_info.autoscrolling) {
1849 if (view->cursor != EV_VIEW_CURSOR_AUTOSCROLL)
1850 ev_view_set_cursor (view, EV_VIEW_CURSOR_AUTOSCROLL);
1854 link = ev_view_get_link_at_location (view, x, y);
1856 ev_view_set_cursor (view, EV_VIEW_CURSOR_LINK);
1857 } else if ((field = ev_view_get_form_field_at_location (view, x, y))) {
1858 if (field->is_read_only) {
1859 if (view->cursor == EV_VIEW_CURSOR_LINK ||
1860 view->cursor == EV_VIEW_CURSOR_IBEAM ||
1861 view->cursor == EV_VIEW_CURSOR_DRAG)
1862 ev_view_set_cursor (view, EV_VIEW_CURSOR_NORMAL);
1863 } else if (EV_IS_FORM_FIELD_TEXT (field)) {
1864 ev_view_set_cursor (view, EV_VIEW_CURSOR_IBEAM);
1866 ev_view_set_cursor (view, EV_VIEW_CURSOR_LINK);
1868 } else if ((annot = ev_view_get_annotation_at_location (view, x, y))) {
1869 ev_view_set_cursor (view, EV_VIEW_CURSOR_LINK);
1870 } else if (location_in_text (view, x + view->scroll_x, y + view->scroll_y)) {
1871 ev_view_set_cursor (view, EV_VIEW_CURSOR_IBEAM);
1873 if (view->cursor == EV_VIEW_CURSOR_LINK ||
1874 view->cursor == EV_VIEW_CURSOR_IBEAM ||
1875 view->cursor == EV_VIEW_CURSOR_DRAG ||
1876 view->cursor == EV_VIEW_CURSOR_AUTOSCROLL ||
1877 view->cursor == EV_VIEW_CURSOR_ADD)
1878 ev_view_set_cursor (view, EV_VIEW_CURSOR_NORMAL);
1882 g_object_set (view, "has-tooltip", TRUE, NULL);
1887 ev_view_get_image_at_location (EvView *view,
1892 gint x_new = 0, y_new = 0;
1893 EvMappingList *image_mapping;
1895 if (!EV_IS_DOCUMENT_IMAGES (view->document))
1898 if (!get_doc_point_from_location (view, x, y, &page, &x_new, &y_new))
1901 image_mapping = ev_page_cache_get_image_mapping (view->page_cache, page);
1904 return ev_mapping_list_get_data (image_mapping, x_new, y_new);
1910 static EvFormField *
1911 ev_view_get_form_field_at_location (EvView *view,
1916 gint x_new = 0, y_new = 0;
1917 EvMappingList *forms_mapping;
1919 if (!EV_IS_DOCUMENT_FORMS (view->document))
1922 if (!get_doc_point_from_location (view, x, y, &page, &x_new, &y_new))
1925 forms_mapping = ev_page_cache_get_form_field_mapping (view->page_cache, page);
1928 return ev_mapping_list_get_data (forms_mapping, x_new, y_new);
1933 static cairo_region_t *
1934 ev_view_form_field_get_region (EvView *view,
1937 GdkRectangle view_area;
1938 EvMappingList *forms_mapping;
1940 forms_mapping = ev_page_cache_get_form_field_mapping (view->page_cache,
1941 field->page->index);
1942 ev_view_get_area_from_mapping (view, field->page->index,
1946 return cairo_region_create_rectangle (&view_area);
1950 ev_view_forms_remove_widgets (EvView *view)
1952 ev_view_remove_all (view);
1958 ev_view_form_field_destroy (GtkWidget *widget,
1961 g_idle_add ((GSourceFunc)ev_view_forms_remove_widgets, view);
1965 ev_view_form_field_button_create_widget (EvView *view,
1968 EvFormFieldButton *field_button = EV_FORM_FIELD_BUTTON (field);
1969 cairo_region_t *field_region = NULL;
1971 switch (field_button->type) {
1972 case EV_FORM_FIELD_BUTTON_PUSH:
1974 case EV_FORM_FIELD_BUTTON_CHECK:
1975 case EV_FORM_FIELD_BUTTON_RADIO: {
1977 EvMappingList *forms_mapping;
1980 state = ev_document_forms_form_field_button_get_state (EV_DOCUMENT_FORMS (view->document),
1983 /* FIXME: it actually depends on NoToggleToOff flags */
1984 if (field_button->type == EV_FORM_FIELD_BUTTON_RADIO &&
1985 state && field_button->state)
1988 field_region = ev_view_form_field_get_region (view, field);
1990 /* For radio buttons and checkbox buttons that are in a set
1991 * we need to update also the region for the current selected item
1993 forms_mapping = ev_page_cache_get_form_field_mapping (view->page_cache,
1994 field->page->index);
1995 for (l = ev_mapping_list_get_list (forms_mapping); l; l = g_list_next (l)) {
1996 EvFormField *button = ((EvMapping *)(l->data))->data;
1997 cairo_region_t *button_region;
1999 if (button->id == field->id)
2002 /* FIXME: only buttons in the same group should be updated */
2003 if (!EV_IS_FORM_FIELD_BUTTON (button) ||
2004 EV_FORM_FIELD_BUTTON (button)->type != field_button->type ||
2005 EV_FORM_FIELD_BUTTON (button)->state != TRUE)
2008 button_region = ev_view_form_field_get_region (view, button);
2009 cairo_region_union (field_region, button_region);
2010 cairo_region_destroy (button_region);
2013 ev_document_forms_form_field_button_set_state (EV_DOCUMENT_FORMS (view->document),
2015 field_button->state = !state;
2020 ev_view_reload_page (view, field->page->index, field_region);
2021 cairo_region_destroy (field_region);
2027 ev_view_form_field_text_save (EvView *view,
2032 if (!view->document)
2035 field = g_object_get_data (G_OBJECT (widget), "form-field");
2037 if (field->changed) {
2038 EvFormFieldText *field_text = EV_FORM_FIELD_TEXT (field);
2039 cairo_region_t *field_region;
2041 field_region = ev_view_form_field_get_region (view, field);
2043 ev_document_forms_form_field_text_set_text (EV_DOCUMENT_FORMS (view->document),
2044 field, field_text->text);
2045 field->changed = FALSE;
2046 ev_view_reload_page (view, field->page->index, field_region);
2047 cairo_region_destroy (field_region);
2052 ev_view_form_field_text_changed (GtkWidget *widget,
2055 EvFormFieldText *field_text = EV_FORM_FIELD_TEXT (field);
2058 if (GTK_IS_ENTRY (widget)) {
2059 text = g_strdup (gtk_entry_get_text (GTK_ENTRY (widget)));
2060 } else if (GTK_IS_TEXT_BUFFER (widget)) {
2061 GtkTextIter start, end;
2063 gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (widget), &start, &end);
2064 text = gtk_text_buffer_get_text (GTK_TEXT_BUFFER (widget),
2065 &start, &end, FALSE);
2068 if (!field_text->text ||
2069 (field_text->text && g_ascii_strcasecmp (field_text->text, text) != 0)) {
2070 g_free (field_text->text);
2071 field_text->text = text;
2072 field->changed = TRUE;
2077 ev_view_form_field_text_create_widget (EvView *view,
2080 EvFormFieldText *field_text = EV_FORM_FIELD_TEXT (field);
2081 GtkWidget *text = NULL;
2084 txt = ev_document_forms_form_field_text_get_text (EV_DOCUMENT_FORMS (view->document),
2087 switch (field_text->type) {
2088 case EV_FORM_FIELD_TEXT_FILE_SELECT:
2090 case EV_FORM_FIELD_TEXT_NORMAL:
2091 text = gtk_entry_new ();
2092 gtk_entry_set_has_frame (GTK_ENTRY (text), FALSE);
2093 gtk_entry_set_max_length (GTK_ENTRY (text), field_text->max_len);
2094 gtk_entry_set_visibility (GTK_ENTRY (text), !field_text->is_password);
2097 gtk_entry_set_text (GTK_ENTRY (text), txt);
2101 g_signal_connect (text, "changed",
2102 G_CALLBACK (ev_view_form_field_text_changed),
2104 g_signal_connect_after (text, "activate",
2105 G_CALLBACK (ev_view_form_field_destroy),
2108 case EV_FORM_FIELD_TEXT_MULTILINE: {
2109 GtkTextBuffer *buffer;
2111 text = gtk_text_view_new ();
2112 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text));
2115 gtk_text_buffer_set_text (buffer, txt, -1);
2119 g_signal_connect (buffer, "changed",
2120 G_CALLBACK (ev_view_form_field_text_changed),
2126 g_object_weak_ref (G_OBJECT (text),
2127 (GWeakNotify)ev_view_form_field_text_save,
2134 ev_view_form_field_choice_save (EvView *view,
2139 if (!view->document)
2142 field = g_object_get_data (G_OBJECT (widget), "form-field");
2144 if (field->changed) {
2146 EvFormFieldChoice *field_choice = EV_FORM_FIELD_CHOICE (field);
2147 cairo_region_t *field_region;
2149 field_region = ev_view_form_field_get_region (view, field);
2151 if (field_choice->is_editable) {
2152 ev_document_forms_form_field_choice_set_text (EV_DOCUMENT_FORMS (view->document),
2153 field, field_choice->text);
2155 ev_document_forms_form_field_choice_unselect_all (EV_DOCUMENT_FORMS (view->document), field);
2156 for (l = field_choice->selected_items; l; l = g_list_next (l)) {
2157 ev_document_forms_form_field_choice_select_item (EV_DOCUMENT_FORMS (view->document),
2159 GPOINTER_TO_INT (l->data));
2162 field->changed = FALSE;
2163 ev_view_reload_page (view, field->page->index, field_region);
2164 cairo_region_destroy (field_region);
2169 ev_view_form_field_choice_changed (GtkWidget *widget,
2172 EvFormFieldChoice *field_choice = EV_FORM_FIELD_CHOICE (field);
2174 if (GTK_IS_COMBO_BOX (widget)) {
2177 item = gtk_combo_box_get_active (GTK_COMBO_BOX (widget));
2178 if (!field_choice->selected_items ||
2179 GPOINTER_TO_INT (field_choice->selected_items->data) != item) {
2180 g_list_free (field_choice->selected_items);
2181 field_choice->selected_items = NULL;
2182 field_choice->selected_items = g_list_prepend (field_choice->selected_items,
2183 GINT_TO_POINTER (item));
2184 field->changed = TRUE;
2187 if (GTK_IS_COMBO_BOX_ENTRY (widget)) {
2190 text = gtk_combo_box_get_active_text (GTK_COMBO_BOX (widget));
2191 if (!field_choice->text ||
2192 (field_choice->text && g_ascii_strcasecmp (field_choice->text, text) != 0)) {
2193 g_free (field_choice->text);
2194 field_choice->text = text;
2195 field->changed = TRUE;
2198 } else if (GTK_IS_TREE_SELECTION (widget)) {
2199 GtkTreeSelection *selection = GTK_TREE_SELECTION (widget);
2200 GtkTreeModel *model;
2203 items = gtk_tree_selection_get_selected_rows (selection, &model);
2204 g_list_free (field_choice->selected_items);
2205 field_choice->selected_items = NULL;
2207 for (l = items; l && l->data; l = g_list_next (l)) {
2209 GtkTreePath *path = (GtkTreePath *)l->data;
2212 gtk_tree_model_get_iter (model, &iter, path);
2213 gtk_tree_model_get (model, &iter, 1, &item, -1);
2215 field_choice->selected_items = g_list_prepend (field_choice->selected_items,
2216 GINT_TO_POINTER (item));
2218 gtk_tree_path_free (path);
2221 g_list_free (items);
2223 field->changed = TRUE;
2228 ev_view_form_field_choice_create_widget (EvView *view,
2231 EvFormFieldChoice *field_choice = EV_FORM_FIELD_CHOICE (field);
2233 GtkTreeModel *model;
2235 gint selected_item = 0;
2237 n_items = ev_document_forms_form_field_choice_get_n_items (EV_DOCUMENT_FORMS (view->document),
2239 model = GTK_TREE_MODEL (gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT));
2240 for (i = 0; i < n_items; i++) {
2244 item = ev_document_forms_form_field_choice_get_item (EV_DOCUMENT_FORMS (view->document),
2246 if (ev_document_forms_form_field_choice_is_item_selected (
2247 EV_DOCUMENT_FORMS (view->document), field, i)) {
2249 /* FIXME: we need a get_selected_items function in poppler */
2250 field_choice->selected_items = g_list_prepend (field_choice->selected_items,
2251 GINT_TO_POINTER (i));
2255 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
2256 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
2264 if (field_choice->type == EV_FORM_FIELD_CHOICE_LIST) {
2265 GtkCellRenderer *renderer;
2266 GtkWidget *tree_view;
2267 GtkTreeSelection *selection;
2269 tree_view = gtk_tree_view_new_with_model (model);
2270 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tree_view), FALSE);
2272 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
2273 if (field_choice->multi_select) {
2274 gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
2277 /* TODO: set selected items */
2279 renderer = gtk_cell_renderer_text_new ();
2280 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
2286 choice = gtk_scrolled_window_new (NULL, NULL);
2287 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (choice),
2288 GTK_POLICY_AUTOMATIC,
2289 GTK_POLICY_AUTOMATIC);
2290 gtk_container_add (GTK_CONTAINER (choice), tree_view);
2291 gtk_widget_show (tree_view);
2293 g_signal_connect (selection, "changed",
2294 G_CALLBACK (ev_view_form_field_choice_changed),
2296 g_signal_connect_after (selection, "changed",
2297 G_CALLBACK (ev_view_form_field_destroy),
2299 } else if (field_choice->is_editable) { /* ComboBoxEntry */
2302 choice = gtk_combo_box_entry_new_with_model (model, 0);
2303 text = ev_document_forms_form_field_choice_get_text (EV_DOCUMENT_FORMS (view->document), field);
2305 gtk_entry_set_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (choice))), text);
2309 g_signal_connect (choice, "changed",
2310 G_CALLBACK (ev_view_form_field_choice_changed),
2312 g_signal_connect_after (gtk_bin_get_child (GTK_BIN (choice)),
2314 G_CALLBACK (ev_view_form_field_destroy),
2316 } else { /* ComboBoxText */
2317 GtkCellRenderer *renderer;
2319 choice = gtk_combo_box_new_with_model (model);
2320 renderer = gtk_cell_renderer_text_new ();
2321 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (choice),
2323 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (choice),
2327 gtk_combo_box_set_active (GTK_COMBO_BOX (choice), selected_item);
2328 gtk_combo_box_popup (GTK_COMBO_BOX (choice));
2330 g_signal_connect (choice, "changed",
2331 G_CALLBACK (ev_view_form_field_choice_changed),
2333 g_signal_connect_after (choice, "changed",
2334 G_CALLBACK (ev_view_form_field_destroy),
2338 g_object_unref (model);
2340 g_object_weak_ref (G_OBJECT (choice),
2341 (GWeakNotify)ev_view_form_field_choice_save,
2348 ev_view_handle_form_field (EvView *view,
2353 GtkWidget *field_widget = NULL;
2354 EvMappingList *form_field_mapping;
2355 GdkRectangle view_area;
2357 if (field->is_read_only)
2360 if (EV_IS_FORM_FIELD_BUTTON (field)) {
2361 field_widget = ev_view_form_field_button_create_widget (view, field);
2362 } else if (EV_IS_FORM_FIELD_TEXT (field)) {
2363 field_widget = ev_view_form_field_text_create_widget (view, field);
2364 } else if (EV_IS_FORM_FIELD_CHOICE (field)) {
2365 field_widget = ev_view_form_field_choice_create_widget (view, field);
2366 } else if (EV_IS_FORM_FIELD_SIGNATURE (field)) {
2370 /* Form field doesn't require a widget */
2374 g_object_set_data_full (G_OBJECT (field_widget), "form-field",
2375 g_object_ref (field),
2376 (GDestroyNotify)g_object_unref);
2378 form_field_mapping = ev_page_cache_get_form_field_mapping (view->page_cache,
2379 field->page->index);
2380 ev_view_get_area_from_mapping (view, field->page->index,
2384 gtk_layout_put (GTK_LAYOUT (view), field_widget, view_area.x, view_area.y);
2385 gtk_widget_show (field_widget);
2386 gtk_widget_grab_focus (field_widget);
2390 static EvViewWindowChild *
2391 ev_view_get_window_child (EvView *view,
2394 GList *children = view->window_children;
2397 EvViewWindowChild *child;
2399 child = (EvViewWindowChild *)children->data;
2400 children = children->next;
2402 if (child->window == window)
2410 ev_view_window_child_move (EvView *view,
2411 EvViewWindowChild *child,
2415 GtkAllocation allocation;
2418 gtk_widget_get_allocation (GTK_WIDGET (view), &allocation);
2419 gtk_window_get_size (GTK_WINDOW (child->window), &width, &height);
2423 gtk_window_move (GTK_WINDOW (child->window),
2424 CLAMP (x, child->parent_x,
2425 child->parent_x + allocation.width - width),
2426 CLAMP (y, child->parent_y,
2427 child->parent_y + allocation.height - height));
2431 ev_view_window_child_move_with_parent (EvView *view,
2434 EvViewWindowChild *child;
2435 gint root_x, root_y;
2437 child = ev_view_get_window_child (view, window);
2438 gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (view)),
2440 if (root_x != child->parent_x || root_y != child->parent_y) {
2441 gint dest_x, dest_y;
2443 dest_x = child->x + (root_x - child->parent_x);
2444 dest_y = child->y + (root_y - child->parent_y);
2445 child->parent_x = root_x;
2446 child->parent_y = root_y;
2447 ev_view_window_child_move (view, child, dest_x, dest_y);
2450 if (child->visible && !gtk_widget_get_visible (window))
2451 gtk_widget_show (window);
2455 ev_view_window_child_put (EvView *view,
2463 EvViewWindowChild *child;
2464 gint root_x, root_y;
2466 gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (view)),
2469 child = g_new0 (EvViewWindowChild, 1);
2470 child->window = window;
2472 child->orig_x = orig_x;
2473 child->orig_y = orig_y;
2474 child->parent_x = root_x;
2475 child->parent_y = root_y;
2476 child->visible = ev_annotation_window_is_open (EV_ANNOTATION_WINDOW (window));
2477 ev_view_window_child_move (view, child, x + root_x, y + root_y);
2480 gtk_widget_show (window);
2482 gtk_widget_hide (window);
2484 view->window_children = g_list_append (view->window_children, child);
2487 static EvViewWindowChild *
2488 ev_view_find_window_child_for_annot (EvView *view,
2490 EvAnnotation *annot)
2492 GList *children = view->window_children;
2495 EvViewWindowChild *child;
2496 EvAnnotation *wannot;
2498 child = (EvViewWindowChild *)children->data;
2499 children = children->next;
2501 if (child->page != page)
2504 wannot = ev_annotation_window_get_annotation (EV_ANNOTATION_WINDOW (child->window));
2505 if (ev_annotation_equal (wannot, annot))
2513 ev_view_window_children_free (EvView *view)
2517 if (!view->window_children)
2520 for (l = view->window_children; l && l->data; l = g_list_next (l)) {
2521 EvViewWindowChild *child;
2523 child = (EvViewWindowChild *)l->data;
2524 gtk_widget_destroy (GTK_WIDGET (child->window));
2527 g_list_free (view->window_children);
2528 view->window_children = NULL;
2529 view->window_child_focus = NULL;
2533 annotation_window_grab_focus (GtkWidget *widget,
2536 if (view->window_child_focus)
2537 ev_annotation_window_ungrab_focus (EV_ANNOTATION_WINDOW (view->window_child_focus->window));
2538 view->window_child_focus = ev_view_get_window_child (view, widget);
2542 annotation_window_closed (EvAnnotationWindow *window,
2545 EvViewWindowChild *child;
2547 child = ev_view_get_window_child (view, GTK_WIDGET (window));
2548 child->visible = FALSE;
2552 annotation_window_moved (EvAnnotationWindow *window,
2557 EvViewWindowChild *child;
2558 GdkRectangle page_area;
2560 GdkRectangle view_rect;
2561 EvRectangle doc_rect;
2564 child = ev_view_get_window_child (view, GTK_WIDGET (window));
2565 if (child->x == x && child->y == y)
2568 child->moved = TRUE;
2572 /* Window has been moved by the user,
2573 * we have to set a new origin in doc coords
2575 gtk_window_get_size (GTK_WINDOW (window), &width, &height);
2576 view_rect.x = (x - child->parent_x) + view->scroll_x;
2577 view_rect.y = (y - child->parent_y) + view->scroll_y;
2578 view_rect.width = width;
2579 view_rect.height = height;
2581 ev_view_get_page_extents (view, child->page, &page_area, &border);
2582 view_rect_to_doc_rect (view, &view_rect, &page_area, &doc_rect);
2583 child->orig_x = doc_rect.x1;
2584 child->orig_y = doc_rect.y1;
2588 ev_view_annotation_save_contents (EvView *view,
2590 EvAnnotation *annot)
2592 if (!view->document)
2595 ev_document_doc_mutex_lock ();
2596 ev_document_annotations_save_annotation (EV_DOCUMENT_ANNOTATIONS (view->document),
2597 annot, EV_ANNOTATIONS_SAVE_CONTENTS);
2598 ev_document_doc_mutex_unlock ();
2602 ev_view_create_annotation_window (EvView *view,
2603 EvAnnotation *annot,
2607 EvRectangle doc_rect;
2608 GdkRectangle view_rect;
2611 window = ev_annotation_window_new (annot, parent);
2612 g_signal_connect (window, "grab_focus",
2613 G_CALLBACK (annotation_window_grab_focus),
2615 g_signal_connect (window, "closed",
2616 G_CALLBACK (annotation_window_closed),
2618 g_signal_connect (window, "moved",
2619 G_CALLBACK (annotation_window_moved),
2621 g_signal_connect_swapped (annot, "notify::contents",
2622 G_CALLBACK (ev_view_annotation_save_contents),
2624 g_object_set_data (G_OBJECT (annot), "popup", window);
2626 page = ev_annotation_get_page_index (annot);
2627 ev_annotation_window_get_rectangle (EV_ANNOTATION_WINDOW (window), &doc_rect);
2628 doc_rect_to_view_rect (view, page, &doc_rect, &view_rect);
2629 view_rect.x -= view->scroll_x;
2630 view_rect.y -= view->scroll_y;
2632 ev_view_window_child_put (view, window, page,
2633 view_rect.x, view_rect.y,
2634 doc_rect.x1, doc_rect.y1);
2640 show_annotation_windows (EvView *view,
2643 EvMappingList *annots;
2647 parent = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (view)));
2649 annots = ev_page_cache_get_annot_mapping (view->page_cache, page);
2651 for (l = ev_mapping_list_get_list (annots); l && l->data; l = g_list_next (l)) {
2652 EvAnnotation *annot;
2653 EvViewWindowChild *child;
2656 annot = ((EvMapping *)(l->data))->data;
2658 if (!EV_IS_ANNOTATION_MARKUP (annot))
2661 if (!ev_annotation_markup_has_popup (EV_ANNOTATION_MARKUP (annot)))
2664 window = g_object_get_data (G_OBJECT (annot), "popup");
2666 ev_view_window_child_move_with_parent (view, window);
2670 /* Look if we already have a popup for this annot */
2671 child = ev_view_find_window_child_for_annot (view, page, annot);
2672 window = child ? child->window : NULL;
2674 ev_annotation_window_set_annotation (EV_ANNOTATION_WINDOW (window), annot);
2675 g_object_set_data (G_OBJECT (annot), "popup", window);
2676 ev_view_window_child_move_with_parent (view, window);
2678 ev_view_create_annotation_window (view, annot, parent);
2684 hide_annotation_windows (EvView *view,
2687 EvMappingList *annots;
2690 annots = ev_page_cache_get_annot_mapping (view->page_cache, page);
2692 for (l = ev_mapping_list_get_list (annots); l && l->data; l = g_list_next (l)) {
2693 EvAnnotation *annot;
2696 annot = ((EvMapping *)(l->data))->data;
2698 if (!EV_IS_ANNOTATION_MARKUP (annot))
2701 window = g_object_get_data (G_OBJECT (annot), "popup");
2703 gtk_widget_hide (window);
2707 static EvAnnotation *
2708 ev_view_get_annotation_at_location (EvView *view,
2713 gint x_new = 0, y_new = 0;
2714 EvMappingList *annotations_mapping;
2716 if (!EV_IS_DOCUMENT_ANNOTATIONS (view->document))
2719 if (!get_doc_point_from_location (view, x, y, &page, &x_new, &y_new))
2722 annotations_mapping = ev_page_cache_get_annot_mapping (view->page_cache, page);
2724 if (annotations_mapping)
2725 return ev_mapping_list_get_data (annotations_mapping, x_new, y_new);
2731 ev_view_annotation_show_popup_window (EvView *view,
2734 EvViewWindowChild *child;
2739 child = ev_view_get_window_child (view, window);
2740 if (!child->visible) {
2741 child->visible = TRUE;
2742 ev_view_window_child_move (view, child, child->x, child->y);
2743 gtk_widget_show (window);
2748 ev_view_handle_annotation (EvView *view,
2749 EvAnnotation *annot,
2754 if (EV_IS_ANNOTATION_MARKUP (annot)) {
2757 window = g_object_get_data (G_OBJECT (annot), "popup");
2758 ev_view_annotation_show_popup_window (view, window);
2761 if (EV_IS_ANNOTATION_ATTACHMENT (annot)) {
2762 EvAttachment *attachment;
2764 attachment = ev_annotation_attachment_get_attachment (EV_ANNOTATION_ATTACHMENT (annot));
2766 GError *error = NULL;
2768 ev_attachment_open (attachment,
2769 gtk_widget_get_screen (GTK_WIDGET (view)),
2774 g_warning ("%s", error->message);
2775 g_error_free (error);
2782 ev_view_create_annotation (EvView *view,
2783 EvAnnotationType annot_type,
2787 EvAnnotation *annot;
2789 GdkRectangle page_area;
2791 EvRectangle doc_rect, popup_rect;
2793 GdkColor color = { 0, 65535, 65535, 0 };
2794 GdkRectangle view_rect;
2795 cairo_region_t *region;
2799 ev_view_get_page_extents (view, view->current_page, &page_area, &border);
2800 view_point_to_doc_point (view, &point, &page_area,
2801 &doc_rect.x1, &doc_rect.y1);
2802 doc_rect.x2 = doc_rect.x1 + 24;
2803 doc_rect.y2 = doc_rect.y1 + 24;
2805 ev_document_doc_mutex_lock ();
2806 page = ev_document_get_page (view->document, view->current_page);
2807 switch (annot_type) {
2808 case EV_ANNOTATION_TYPE_TEXT:
2809 annot = ev_annotation_text_new (page);
2811 case EV_ANNOTATION_TYPE_ATTACHMENT:
2813 g_object_unref (page);
2814 ev_document_doc_mutex_unlock ();
2817 g_assert_not_reached ();
2819 g_object_unref (page);
2821 ev_annotation_set_color (annot, &color);
2823 if (EV_IS_ANNOTATION_MARKUP (annot)) {
2824 popup_rect.x1 = doc_rect.x2;
2825 popup_rect.x2 = popup_rect.x1 + 200;
2826 popup_rect.y1 = doc_rect.y2;
2827 popup_rect.y2 = popup_rect.y1 + 150;
2828 g_object_set (annot,
2829 "rectangle", &popup_rect,
2831 "popup_is_open", FALSE,
2832 "label", g_get_real_name (),
2836 ev_document_annotations_add_annotation (EV_DOCUMENT_ANNOTATIONS (view->document),
2838 ev_document_doc_mutex_unlock ();
2840 /* If the page didn't have annots, mark the cache as dirty */
2841 if (!ev_page_cache_get_annot_mapping (view->page_cache, view->current_page))
2842 ev_page_cache_mark_dirty (view->page_cache, view->current_page);
2844 if (EV_IS_ANNOTATION_MARKUP (annot)) {
2848 parent = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (view)));
2849 window = ev_view_create_annotation_window (view, annot, parent);
2851 /* Show the annot window the first time */
2852 ev_view_annotation_show_popup_window (view, window);
2855 doc_rect_to_view_rect (view, view->current_page, &doc_rect, &view_rect);
2856 view_rect.x -= view->scroll_x;
2857 view_rect.y -= view->scroll_y;
2858 region = cairo_region_create_rectangle (&view_rect);
2859 ev_view_reload_page (view, view->current_page, region);
2860 cairo_region_destroy (region);
2862 g_signal_emit (view, signals[SIGNAL_ANNOT_ADDED], 0, annot);
2866 ev_view_focus_annotation (EvView *view,
2867 EvMapping *annot_mapping)
2869 GdkRectangle view_rect;
2870 EvAnnotation *annot;
2873 if (!EV_IS_DOCUMENT_ANNOTATIONS (view->document))
2876 if (view->focus_annotation == annot_mapping)
2879 view->focus_annotation = annot_mapping;
2880 annot = (EvAnnotation *)annot_mapping->data;
2882 page = ev_annotation_get_page_index (annot);
2883 ev_document_model_set_page (view->model, page);
2885 doc_rect_to_view_rect (view, page,
2886 &annot_mapping->area, &view_rect);
2887 ensure_rectangle_is_visible (view, &view_rect);
2888 gtk_widget_queue_draw (GTK_WIDGET (view));
2892 ev_view_begin_add_annotation (EvView *view,
2893 EvAnnotationType annot_type)
2895 if (annot_type == EV_ANNOTATION_TYPE_UNKNOWN)
2898 if (view->adding_annot)
2901 view->adding_annot = TRUE;
2902 view->adding_annot_type = annot_type;
2903 ev_view_set_cursor (view, EV_VIEW_CURSOR_ADD);
2907 ev_view_cancel_add_annotation (EvView *view)
2911 if (!view->adding_annot)
2914 view->adding_annot = FALSE;
2915 gtk_widget_get_pointer (GTK_WIDGET (view), &x, &y);
2916 ev_view_handle_cursor_over_xy (view, x, y);
2920 ev_view_synctex_backward_search (EvView *view,
2925 gint x_new = 0, y_new = 0;
2928 if (!ev_document_has_synctex (view->document))
2931 if (!get_doc_point_from_location (view, x, y, &page, &x_new, &y_new))
2934 link = ev_document_synctex_backward_search (view->document, page, x_new, y_new);
2936 g_signal_emit (view, signals[SIGNAL_SYNC_SOURCE], 0, link);
2945 /*** GtkWidget implementation ***/
2948 ev_view_size_request_continuous_dual_page (EvView *view,
2949 GtkRequisition *requisition)
2953 n_pages = ev_document_get_n_pages (view->document) + 1;
2954 get_page_y_offset (view, n_pages, &requisition->height);
2956 switch (view->sizing_mode) {
2957 case EV_SIZING_FIT_WIDTH:
2958 case EV_SIZING_BEST_FIT:
2959 requisition->width = 1;
2962 case EV_SIZING_FREE: {
2966 ev_view_get_max_page_size (view, &max_width, NULL);
2967 compute_border (view, max_width, max_width, &border);
2968 requisition->width = (max_width + border.left + border.right) * 2 + (view->spacing * 3);
2972 g_assert_not_reached ();
2977 ev_view_size_request_continuous (EvView *view,
2978 GtkRequisition *requisition)
2982 n_pages = ev_document_get_n_pages (view->document);
2983 get_page_y_offset (view, n_pages, &requisition->height);
2985 switch (view->sizing_mode) {
2986 case EV_SIZING_FIT_WIDTH:
2987 case EV_SIZING_BEST_FIT:
2988 requisition->width = 1;
2991 case EV_SIZING_FREE: {
2995 ev_view_get_max_page_size (view, &max_width, NULL);
2996 compute_border (view, max_width, max_width, &border);
2997 requisition->width = max_width + (view->spacing * 2) + border.left + border.right;
3001 g_assert_not_reached ();
3006 ev_view_size_request_dual_page (EvView *view,
3007 GtkRequisition *requisition)
3012 if (view->sizing_mode == EV_SIZING_BEST_FIT) {
3013 requisition->width = 1;
3014 requisition->height = 1;
3019 /* Find the largest of the two. */
3020 ev_view_get_page_size (view,
3023 if (view->current_page + 1 < ev_document_get_n_pages (view->document)) {
3024 gint width_2, height_2;
3025 ev_view_get_page_size (view,
3026 view->current_page + 1,
3027 &width_2, &height_2);
3028 if (width_2 > width) {
3033 compute_border (view, width, height, &border);
3035 requisition->width = view->sizing_mode == EV_SIZING_FIT_WIDTH ? 1 :
3036 ((width + border.left + border.right) * 2) + (view->spacing * 3);
3037 requisition->height = (height + border.top + border.bottom) + (view->spacing * 2);
3041 ev_view_size_request_single_page (EvView *view,
3042 GtkRequisition *requisition)
3047 if (view->sizing_mode == EV_SIZING_BEST_FIT) {
3048 requisition->width = 1;
3049 requisition->height = 1;
3054 ev_view_get_page_size (view, view->current_page, &width, &height);
3055 compute_border (view, width, height, &border);
3057 requisition->width = view->sizing_mode == EV_SIZING_FIT_WIDTH ? 1 :
3058 width + border.left + border.right + (2 * view->spacing);
3059 requisition->height = height + border.top + border.bottom + (2 * view->spacing);
3063 ev_view_size_request (GtkWidget *widget,
3064 GtkRequisition *requisition)
3066 EvView *view = EV_VIEW (widget);
3068 if (view->document == NULL) {
3069 view->requisition.width = 1;
3070 view->requisition.height = 1;
3072 *requisition = view->requisition;
3077 /* Get zoom for size here when not called from
3078 * ev_view_size_allocate()
3080 if (!view->internal_size_request &&
3081 (view->sizing_mode == EV_SIZING_FIT_WIDTH ||
3082 view->sizing_mode == EV_SIZING_BEST_FIT)) {
3083 GtkAllocation allocation;
3085 gtk_widget_get_allocation (widget, &allocation);
3086 ev_view_zoom_for_size (view,
3091 if (view->continuous && view->dual_page)
3092 ev_view_size_request_continuous_dual_page (view, &view->requisition);
3093 else if (view->continuous)
3094 ev_view_size_request_continuous (view, &view->requisition);
3095 else if (view->dual_page)
3096 ev_view_size_request_dual_page (view, &view->requisition);
3098 ev_view_size_request_single_page (view, &view->requisition);
3100 *requisition = view->requisition;
3104 ev_view_size_allocate (GtkWidget *widget,
3105 GtkAllocation *allocation)
3107 EvView *view = EV_VIEW (widget);
3108 GList *children, *l;
3109 gint root_x, root_y;
3111 GTK_WIDGET_CLASS (ev_view_parent_class)->size_allocate (widget, allocation);
3113 if (!view->document)
3116 if (view->sizing_mode == EV_SIZING_FIT_WIDTH ||
3117 view->sizing_mode == EV_SIZING_BEST_FIT) {
3120 ev_view_zoom_for_size (view,
3122 allocation->height);
3123 view->internal_size_request = TRUE;
3124 ev_view_size_request (widget, &req);
3125 view->internal_size_request = FALSE;
3128 view_set_adjustment_values (view, GTK_ORIENTATION_HORIZONTAL);
3129 view_set_adjustment_values (view, GTK_ORIENTATION_VERTICAL);
3132 view_update_range_and_current_page (view);
3134 view->pending_scroll = SCROLL_TO_KEEP_POSITION;
3135 view->pending_resize = FALSE;
3136 view->pending_point.x = 0;
3137 view->pending_point.y = 0;
3139 children = gtk_container_get_children (GTK_CONTAINER (widget));
3140 for (l = children; l && l->data; l = g_list_next (l)) {
3142 GdkRectangle view_area;
3143 EvMappingList *form_field_mapping;
3144 GtkAllocation child_allocation;
3145 GtkRequisition child_requisition;
3146 GtkWidget *child = (GtkWidget *)l->data;
3148 field = g_object_get_data (G_OBJECT (child), "form-field");
3152 form_field_mapping = ev_page_cache_get_form_field_mapping (view->page_cache,
3153 field->page->index);
3154 ev_view_get_area_from_mapping (view, field->page->index,
3158 gtk_widget_size_request (child, &child_requisition);
3159 if (child_requisition.width != view_area.width ||
3160 child_requisition.height != view_area.height)
3161 gtk_widget_set_size_request (child, view_area.width, view_area.height);
3163 gtk_container_child_get (GTK_CONTAINER (widget),
3165 "x", &child_allocation.x,
3166 "y", &child_allocation.y,
3168 if (child_allocation.x != view_area.x ||
3169 child_allocation.y != view_area.y) {
3170 gtk_layout_move (GTK_LAYOUT (widget), child, view_area.x, view_area.y);
3173 g_list_free (children);
3175 if (view->window_children)
3176 gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (view)),
3179 for (l = view->window_children; l && l->data; l = g_list_next (l)) {
3180 EvViewWindowChild *child;
3181 EvRectangle doc_rect;
3182 GdkRectangle view_rect;
3184 child = (EvViewWindowChild *)l->data;
3186 ev_annotation_window_get_rectangle (EV_ANNOTATION_WINDOW (child->window), &doc_rect);
3188 doc_rect.x1 = child->orig_x;
3189 doc_rect.y1 = child->orig_y;
3191 doc_rect_to_view_rect (view, child->page, &doc_rect, &view_rect);
3192 view_rect.x -= view->scroll_x;
3193 view_rect.y -= view->scroll_y;
3195 if (view_rect.x != child->orig_x || view_rect.y != child->orig_y) {
3196 child->parent_x = root_x;
3197 child->parent_y = root_y;
3198 ev_view_window_child_move (view, child, view_rect.x + root_x, view_rect.y + root_y);
3204 ev_view_realize (GtkWidget *widget)
3206 EvView *view = EV_VIEW (widget);
3207 GdkWindow *bin_window;
3210 if (GTK_WIDGET_CLASS (ev_view_parent_class)->realize)
3211 (* GTK_WIDGET_CLASS (ev_view_parent_class)->realize) (widget);
3213 bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (view));
3214 gdk_window_set_events (bin_window,
3215 (gdk_window_get_events (bin_window) |
3217 GDK_BUTTON_PRESS_MASK |
3218 GDK_BUTTON_RELEASE_MASK |
3220 GDK_KEY_PRESS_MASK |
3221 GDK_POINTER_MOTION_MASK |
3222 GDK_POINTER_MOTION_HINT_MASK |
3223 GDK_ENTER_NOTIFY_MASK |
3224 GDK_LEAVE_NOTIFY_MASK));
3226 style = gtk_widget_get_style (widget);
3227 gdk_window_set_background (bin_window, &style->mid[GTK_STATE_NORMAL]);
3229 on_adjustment_value_changed (NULL, view);
3233 ev_view_scroll_event (GtkWidget *widget, GdkEventScroll *event)
3235 EvView *view = EV_VIEW (widget);
3238 state = event->state & gtk_accelerator_get_default_mod_mask ();
3240 if (state == GDK_CONTROL_MASK) {
3241 ev_document_model_set_sizing_mode (view->model, EV_SIZING_FREE);
3242 if (event->direction == GDK_SCROLL_UP ||
3243 event->direction == GDK_SCROLL_LEFT) {
3244 if (ev_view_can_zoom_in (view)) {
3245 ev_view_zoom_in (view);
3248 if (ev_view_can_zoom_out (view)) {
3249 ev_view_zoom_out (view);
3256 view->jump_to_find_result = FALSE;
3258 /* Shift+Wheel scrolls the in the perpendicular direction */
3259 if (state & GDK_SHIFT_MASK) {
3260 if (event->direction == GDK_SCROLL_UP)
3261 event->direction = GDK_SCROLL_LEFT;
3262 else if (event->direction == GDK_SCROLL_LEFT)
3263 event->direction = GDK_SCROLL_UP;
3264 else if (event->direction == GDK_SCROLL_DOWN)
3265 event->direction = GDK_SCROLL_RIGHT;
3266 else if (event->direction == GDK_SCROLL_RIGHT)
3267 event->direction = GDK_SCROLL_DOWN;
3269 event->state &= ~GDK_SHIFT_MASK;
3270 state &= ~GDK_SHIFT_MASK;
3273 if (state == 0 && view->sizing_mode == EV_SIZING_BEST_FIT && !view->continuous) {
3274 switch (event->direction) {
3275 case GDK_SCROLL_DOWN:
3276 case GDK_SCROLL_RIGHT:
3277 ev_view_next_page (view);
3280 case GDK_SCROLL_LEFT:
3281 ev_view_previous_page (view);
3291 static EvViewSelection *
3292 find_selection_for_page (EvView *view,
3297 for (list = view->selection_info.selections; list != NULL; list = list->next) {
3298 EvViewSelection *selection;
3300 selection = (EvViewSelection *) list->data;
3302 if (selection->page == page)
3310 ev_view_expose_event (GtkWidget *widget,
3311 GdkEventExpose *event)
3313 EvView *view = EV_VIEW (widget);
3314 GdkWindow *bin_window;
3318 if (view->loading) {
3319 show_loading_window (view);
3320 } else if (view->loading_window &&
3321 gtk_widget_get_visible (view->loading_window)) {
3322 ev_view_loading_window_move (view);
3325 if (view->document == NULL)
3328 bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (view));
3329 cr = gdk_cairo_create (bin_window);
3331 for (i = view->start_page; i >= 0 && i <= view->end_page; i++) {
3332 GdkRectangle page_area;
3334 gboolean page_ready = TRUE;
3336 if (!ev_view_get_page_extents (view, i, &page_area, &border))
3339 page_area.x -= view->scroll_x;
3340 page_area.y -= view->scroll_y;
3342 draw_one_page (view, i, cr, &page_area, &border, &(event->area), &page_ready);
3344 if (page_ready && view->find_pages && view->highlight_find_results)
3345 highlight_find_results (view, i);
3346 if (page_ready && EV_IS_DOCUMENT_ANNOTATIONS (view->document))
3347 show_annotation_windows (view, i);
3348 if (page_ready && view->focus_annotation)
3349 focus_annotation (view, i, &event->area);
3350 if (page_ready && view->synctex_result)
3351 highlight_forward_search_results (view, i);
3356 if (GTK_WIDGET_CLASS (ev_view_parent_class)->expose_event)
3357 (* GTK_WIDGET_CLASS (ev_view_parent_class)->expose_event) (widget, event);
3363 ev_view_do_popup_menu (EvView *view,
3367 GList *items = NULL;
3370 EvAnnotation *annot;
3372 image = ev_view_get_image_at_location (view, x, y);
3374 items = g_list_prepend (items, image);
3376 link = ev_view_get_link_at_location (view, x, y);
3378 items = g_list_prepend (items, link);
3380 annot = ev_view_get_annotation_at_location (view, x, y);
3382 items = g_list_prepend (items, annot);
3384 g_signal_emit (view, signals[SIGNAL_POPUP_MENU], 0, items);
3386 g_list_free (items);
3392 ev_view_popup_menu (GtkWidget *widget)
3396 gtk_widget_get_pointer (widget, &x, &y);
3397 return ev_view_do_popup_menu (EV_VIEW (widget), x, y);
3401 get_link_area (EvView *view,
3407 EvMappingList *link_mapping;
3409 gint x_offset = 0, y_offset = 0;
3411 x += view->scroll_x;
3412 y += view->scroll_y;
3414 find_page_at_location (view, x, y, &page, &x_offset, &y_offset);
3416 link_mapping = ev_page_cache_get_link_mapping (view->page_cache, page);
3417 ev_view_get_area_from_mapping (view, page,
3423 get_annot_area (EvView *view,
3426 EvAnnotation *annot,
3429 EvMappingList *annot_mapping;
3431 gint x_offset = 0, y_offset = 0;
3433 x += view->scroll_x;
3434 y += view->scroll_y;
3436 find_page_at_location (view, x, y, &page, &x_offset, &y_offset);
3438 annot_mapping = ev_page_cache_get_annot_mapping (view->page_cache, page);
3439 ev_view_get_area_from_mapping (view, page,
3445 ev_view_query_tooltip (GtkWidget *widget,
3448 gboolean keyboard_tip,
3449 GtkTooltip *tooltip)
3451 EvView *view = EV_VIEW (widget);
3453 EvAnnotation *annot;
3456 annot = ev_view_get_annotation_at_location (view, x, y);
3458 const gchar *contents;
3460 if ((contents = ev_annotation_get_contents (annot))) {
3461 GdkRectangle annot_area;
3463 get_annot_area (view, x, y, annot, &annot_area);
3464 gtk_tooltip_set_text (tooltip, contents);
3465 gtk_tooltip_set_tip_area (tooltip, &annot_area);
3471 link = ev_view_get_link_at_location (view, x, y);
3475 text = tip_from_link (view, link);
3476 if (text && g_utf8_validate (text, -1, NULL)) {
3477 GdkRectangle link_area;
3479 get_link_area (view, x, y, link, &link_area);
3480 gtk_tooltip_set_text (tooltip, text);
3481 gtk_tooltip_set_tip_area (tooltip, &link_area);
3489 start_selection_for_event (EvView *view,
3490 GdkEventButton *event)
3492 clear_selection (view);
3494 view->selection_info.start.x = event->x + view->scroll_x;
3495 view->selection_info.start.y = event->y + view->scroll_y;
3497 switch (event->type) {
3498 case GDK_2BUTTON_PRESS:
3499 view->selection_info.style = EV_SELECTION_STYLE_WORD;
3501 case GDK_3BUTTON_PRESS:
3502 view->selection_info.style = EV_SELECTION_STYLE_LINE;
3505 view->selection_info.style = EV_SELECTION_STYLE_GLYPH;
3509 /* In case of WORD or LINE, compute selections now */
3510 compute_selections (view,
3511 view->selection_info.style,
3512 &(view->selection_info.start),
3513 &(view->selection_info.start));
3517 ev_view_button_press_event (GtkWidget *widget,
3518 GdkEventButton *event)
3520 EvView *view = EV_VIEW (widget);
3522 if (!view->document)
3525 if (!gtk_widget_has_focus (widget)) {
3526 gtk_widget_grab_focus (widget);
3529 if (view->window_child_focus) {
3530 EvAnnotationWindow *window;
3531 EvAnnotation *annot;
3533 window = EV_ANNOTATION_WINDOW (view->window_child_focus->window);
3534 annot = ev_annotation_window_get_annotation (window);
3535 ev_annotation_window_ungrab_focus (window);
3536 view->window_child_focus = NULL;
3539 view->pressed_button = event->button;
3540 view->selection_info.in_drag = FALSE;
3542 if (view->adding_annot)
3545 if (view->scroll_info.autoscrolling)
3548 switch (event->button) {
3551 EvAnnotation *annot;
3554 if (event->state & GDK_CONTROL_MASK)
3555 return ev_view_synctex_backward_search (view, event->x , event->y);
3557 if (EV_IS_SELECTION (view->document) && view->selection_info.selections) {
3558 if (event->type == GDK_3BUTTON_PRESS) {
3559 start_selection_for_event (view, event);
3560 } else if (location_in_selected_text (view,
3561 event->x + view->scroll_x,
3562 event->y + view->scroll_y)) {
3563 view->selection_info.in_drag = TRUE;
3565 start_selection_for_event (view, event);
3568 gtk_widget_queue_draw (widget);
3569 } else if ((annot = ev_view_get_annotation_at_location (view, event->x, event->y))) {
3570 ev_view_handle_annotation (view, annot, event->x, event->y, event->time);
3571 } else if ((field = ev_view_get_form_field_at_location (view, event->x, event->y))) {
3572 ev_view_remove_all (view);
3573 ev_view_handle_form_field (view, field, event->x, event->y);
3574 } else if (!location_in_text (view, event->x + view->scroll_x, event->y + view->scroll_y) &&
3575 (image = ev_view_get_image_at_location (view, event->x, event->y))) {
3576 if (view->image_dnd_info.image)
3577 g_object_unref (view->image_dnd_info.image);
3578 view->image_dnd_info.image = g_object_ref (image);
3579 view->image_dnd_info.in_drag = TRUE;
3581 view->image_dnd_info.start.x = event->x + view->scroll_x;
3582 view->image_dnd_info.start.y = event->y + view->scroll_y;
3584 ev_view_remove_all (view);
3586 if (view->synctex_result) {
3587 g_free (view->synctex_result);
3588 view->synctex_result = NULL;
3589 gtk_widget_queue_draw (widget);
3592 if (view->focus_annotation)
3593 view->focus_annotation = NULL;
3595 if (EV_IS_SELECTION (view->document))
3596 start_selection_for_event (view, event);
3601 /* use root coordinates as reference point because
3602 * scrolling changes window relative coordinates */
3603 view->drag_info.start.x = event->x_root;
3604 view->drag_info.start.y = event->y_root;
3605 view->drag_info.hadj = gtk_adjustment_get_value (view->hadjustment);
3606 view->drag_info.vadj = gtk_adjustment_get_value (view->vadjustment);
3608 ev_view_set_cursor (view, EV_VIEW_CURSOR_DRAG);
3612 view->scroll_info.start_y = event->y;
3613 return ev_view_do_popup_menu (view, event->x, event->y);
3620 ev_view_remove_all (EvView *view)
3622 GList *children, *child;
3624 children = gtk_container_get_children (GTK_CONTAINER (view));
3625 for (child = children; child && child->data; child = g_list_next (child)) {
3626 gtk_container_remove (GTK_CONTAINER (view),
3627 GTK_WIDGET (child->data));
3629 g_list_free (children);
3632 /*** Drag and Drop ***/
3634 ev_view_drag_data_get (GtkWidget *widget,
3635 GdkDragContext *context,
3636 GtkSelectionData *selection_data,
3640 EvView *view = EV_VIEW (widget);
3643 case TARGET_DND_TEXT:
3644 if (EV_IS_SELECTION (view->document) &&
3645 view->selection_info.selections) {
3648 text = get_selected_text (view);
3649 gtk_selection_data_set_text (selection_data,
3655 case TARGET_DND_IMAGE:
3656 if (view->image_dnd_info.image) {
3659 ev_document_doc_mutex_lock ();
3660 pixbuf = ev_document_images_get_image (EV_DOCUMENT_IMAGES (view->document),
3661 view->image_dnd_info.image);
3662 ev_document_doc_mutex_unlock ();
3664 gtk_selection_data_set_pixbuf (selection_data, pixbuf);
3665 g_object_unref (pixbuf);
3668 case TARGET_DND_URI:
3669 if (view->image_dnd_info.image) {
3671 const gchar *tmp_uri;
3674 ev_document_doc_mutex_lock ();
3675 pixbuf = ev_document_images_get_image (EV_DOCUMENT_IMAGES (view->document),
3676 view->image_dnd_info.image);
3677 ev_document_doc_mutex_unlock ();
3679 tmp_uri = ev_image_save_tmp (view->image_dnd_info.image, pixbuf);
3680 g_object_unref (pixbuf);
3682 uris[0] = (gchar *)tmp_uri;
3684 gtk_selection_data_set_uris (selection_data, uris);
3690 ev_view_drag_motion (GtkWidget *widget,
3691 GdkDragContext *context,
3696 if (gtk_drag_get_source_widget (context) == widget)
3697 gdk_drag_status (context, 0, time);
3699 gdk_drag_status (context, gdk_drag_context_get_suggested_action (context), time);
3705 selection_update_idle_cb (EvView *view)
3707 compute_selections (view,
3708 view->selection_info.style,
3709 &view->selection_info.start,
3711 view->selection_update_id = 0;
3716 selection_scroll_timeout_cb (EvView *view)
3718 gint x, y, shift = 0;
3719 GtkWidget *widget = GTK_WIDGET (view);
3720 GtkAllocation allocation;
3722 gtk_widget_get_allocation (widget, &allocation);
3723 gtk_widget_get_pointer (widget, &x, &y);
3725 if (y > allocation.height) {
3726 shift = (y - allocation.height) / 2;
3732 gtk_adjustment_set_value (view->vadjustment,
3733 CLAMP (gtk_adjustment_get_value (view->vadjustment) + shift,
3734 gtk_adjustment_get_lower (view->vadjustment),
3735 gtk_adjustment_get_upper (view->vadjustment) -
3736 gtk_adjustment_get_page_size (view->vadjustment)));
3738 if (x > allocation.width) {
3739 shift = (x - allocation.width) / 2;
3745 gtk_adjustment_set_value (view->hadjustment,
3746 CLAMP (gtk_adjustment_get_value (view->hadjustment) + shift,
3747 gtk_adjustment_get_lower (view->hadjustment),
3748 gtk_adjustment_get_upper (view->hadjustment) -
3749 gtk_adjustment_get_page_size (view->hadjustment)));
3755 ev_view_drag_update_momentum (EvView *view)
3758 if (!view->drag_info.in_drag)
3761 for (i = DRAG_HISTORY - 1; i > 0; i--) {
3762 view->drag_info.buffer[i].x = view->drag_info.buffer[i-1].x;
3763 view->drag_info.buffer[i].y = view->drag_info.buffer[i-1].y;
3766 /* Momentum is a moving average of 10ms granularity over
3767 * the last 100ms with each 10ms stored in buffer.
3770 view->drag_info.momentum.x = (view->drag_info.buffer[DRAG_HISTORY - 1].x - view->drag_info.buffer[0].x);
3771 view->drag_info.momentum.y = (view->drag_info.buffer[DRAG_HISTORY - 1].y - view->drag_info.buffer[0].y);
3777 ev_view_scroll_drag_release (EvView *view)
3779 gdouble dhadj_value, dvadj_value;
3780 gdouble oldhadjustment, oldvadjustment;
3781 gdouble h_page_size, v_page_size;
3782 gdouble h_upper, v_upper;
3783 GtkAllocation allocation;
3785 view->drag_info.momentum.x /= 1.2;
3786 view->drag_info.momentum.y /= 1.2; /* Alter these constants to change "friction" */
3788 gtk_widget_get_allocation (GTK_WIDGET (view), &allocation);
3790 h_page_size = gtk_adjustment_get_page_size (view->hadjustment);
3791 v_page_size = gtk_adjustment_get_page_size (view->vadjustment);
3793 dhadj_value = h_page_size *
3794 (gdouble)view->drag_info.momentum.x / allocation.width;
3795 dvadj_value = v_page_size *
3796 (gdouble)view->drag_info.momentum.y / allocation.height;
3798 oldhadjustment = gtk_adjustment_get_value (view->hadjustment);
3799 oldvadjustment = gtk_adjustment_get_value (view->vadjustment);
3801 h_upper = gtk_adjustment_get_upper (view->hadjustment);
3802 v_upper = gtk_adjustment_get_upper (view->vadjustment);
3804 /* When we reach the edges, we need either to absorb some momentum and bounce by
3805 * multiplying it on -0.5 or stop scrolling by setting momentum to 0. */
3806 if (((oldhadjustment + dhadj_value) > (h_upper - h_page_size)) ||
3807 ((oldhadjustment + dhadj_value) < 0))
3808 view->drag_info.momentum.x = 0;
3809 if (((oldvadjustment + dvadj_value) > (v_upper - v_page_size)) ||
3810 ((oldvadjustment + dvadj_value) < 0))
3811 view->drag_info.momentum.y = 0;
3813 gtk_adjustment_set_value (view->hadjustment,
3814 MIN (oldhadjustment + dhadj_value,
3815 h_upper - h_page_size));
3816 gtk_adjustment_set_value (view->vadjustment,
3817 MIN (oldvadjustment + dvadj_value,
3818 v_upper - v_page_size));
3820 if (((view->drag_info.momentum.x < 1) && (view->drag_info.momentum.x > -1)) &&
3821 ((view->drag_info.momentum.y < 1) && (view->drag_info.momentum.y > -1)))
3828 ev_view_motion_notify_event (GtkWidget *widget,
3829 GdkEventMotion *event)
3831 EvView *view = EV_VIEW (widget);
3832 GdkWindow *bin_window;
3835 if (!view->document)
3838 bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (view));
3840 if (event->is_hint || event->window != bin_window) {
3841 gtk_widget_get_pointer (widget, &x, &y);
3847 if (view->scroll_info.autoscrolling) {
3848 view->scroll_info.last_y = y;
3852 if (view->selection_info.in_drag) {
3853 if (gtk_drag_check_threshold (widget,
3854 view->selection_info.start.x,
3855 view->selection_info.start.y,
3857 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
3859 gtk_target_list_add_text_targets (target_list, TARGET_DND_TEXT);
3861 gtk_drag_begin (widget, target_list,
3863 1, (GdkEvent *)event);
3865 view->selection_info.in_drag = FALSE;
3867 gtk_target_list_unref (target_list);
3871 } else if (view->image_dnd_info.in_drag) {
3872 if (gtk_drag_check_threshold (widget,
3873 view->selection_info.start.x,
3874 view->selection_info.start.y,
3876 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
3878 gtk_target_list_add_uri_targets (target_list, TARGET_DND_URI);
3879 gtk_target_list_add_image_targets (target_list, TARGET_DND_IMAGE, TRUE);
3881 gtk_drag_begin (widget, target_list,
3883 1, (GdkEvent *)event);
3885 view->image_dnd_info.in_drag = FALSE;
3887 gtk_target_list_unref (target_list);
3893 switch (view->pressed_button) {
3895 /* For the Evince 0.4.x release, we limit selection to un-rotated
3898 if (view->rotation != 0)
3901 /* Schedule timeout to scroll during selection and additionally
3902 * scroll once to allow arbitrary speed. */
3903 if (!view->selection_scroll_id)
3904 view->selection_scroll_id = g_timeout_add (SCROLL_TIME,
3905 (GSourceFunc)selection_scroll_timeout_cb,
3908 selection_scroll_timeout_cb (view);
3910 view->selection_info.in_selection = TRUE;
3911 view->motion.x = x + view->scroll_x;
3912 view->motion.y = y + view->scroll_y;
3914 /* Queue an idle to handle the motion. We do this because
3915 * handling any selection events in the motion could be slower
3916 * than new motion events reach us. We always put it in the
3917 * idle to make sure we catch up and don't visibly lag the
3919 if (!view->selection_update_id)
3920 view->selection_update_id = g_idle_add ((GSourceFunc)selection_update_idle_cb, view);
3924 if (!view->drag_info.in_drag) {
3928 start = gtk_drag_check_threshold (widget,
3929 view->drag_info.start.x,
3930 view->drag_info.start.y,
3933 view->drag_info.in_drag = start;
3934 view->drag_info.drag_timeout_id = g_timeout_add (10,
3935 (GSourceFunc)ev_view_drag_update_momentum, view);
3936 /* Set 100 to choose how long it takes to build up momentum */
3937 /* Clear out previous momentum info: */
3938 for (i = 0; i < DRAG_HISTORY; i++) {
3939 view->drag_info.buffer[i].x = event->x;
3940 view->drag_info.buffer[i].y = event->y;
3942 view->drag_info.momentum.x = 0;
3943 view->drag_info.momentum.y = 0;
3946 if (view->drag_info.in_drag) {
3948 gdouble dhadj_value, dvadj_value;
3949 GtkAllocation allocation;
3951 view->drag_info.buffer[0].x = event->x;
3952 view->drag_info.buffer[0].y = event->y;
3954 dx = event->x_root - view->drag_info.start.x;
3955 dy = event->y_root - view->drag_info.start.y;
3957 gtk_widget_get_allocation (widget, &allocation);
3959 dhadj_value = gtk_adjustment_get_page_size (view->hadjustment) *
3960 (gdouble)dx / allocation.width;
3961 dvadj_value = gtk_adjustment_get_page_size (view->vadjustment) *
3962 (gdouble)dy / allocation.height;
3964 /* clamp scrolling to visible area */
3965 gtk_adjustment_set_value (view->hadjustment,
3966 MIN (view->drag_info.hadj - dhadj_value,
3967 gtk_adjustment_get_upper (view->hadjustment) -
3968 gtk_adjustment_get_page_size (view->hadjustment)));
3969 gtk_adjustment_set_value (view->vadjustment,
3970 MIN (view->drag_info.vadj - dvadj_value,
3971 gtk_adjustment_get_upper (view->vadjustment) -
3972 gtk_adjustment_get_page_size (view->vadjustment)));
3979 ev_view_handle_cursor_over_xy (view, x, y);
3986 ev_view_button_release_event (GtkWidget *widget,
3987 GdkEventButton *event)
3989 EvView *view = EV_VIEW (widget);
3990 EvLink *link = NULL;
3992 view->image_dnd_info.in_drag = FALSE;
3994 if (view->scroll_info.autoscrolling) {
3995 ev_view_autoscroll_stop (view);
3996 view->pressed_button = -1;
4001 if (view->pressed_button == 1 && event->state & GDK_CONTROL_MASK) {
4002 view->pressed_button = -1;
4006 if (view->drag_info.in_drag) {
4007 view->drag_info.release_timeout_id =
4009 (GSourceFunc)ev_view_scroll_drag_release, view);
4012 if (view->document && !view->drag_info.in_drag && view->pressed_button != 3) {
4013 link = ev_view_get_link_at_location (view, event->x, event->y);
4016 view->drag_info.in_drag = FALSE;
4018 if (view->adding_annot && view->pressed_button == 1) {
4019 view->adding_annot = FALSE;
4020 ev_view_handle_cursor_over_xy (view, event->x, event->y);
4021 view->pressed_button = -1;
4023 ev_view_create_annotation (view,
4024 view->adding_annot_type,
4025 event->x + view->scroll_x,
4026 event->y + view->scroll_y);
4031 if (view->pressed_button == 2) {
4032 ev_view_handle_cursor_over_xy (view, event->x, event->y);
4035 view->pressed_button = -1;
4037 if (view->selection_scroll_id) {
4038 g_source_remove (view->selection_scroll_id);
4039 view->selection_scroll_id = 0;
4041 if (view->selection_update_id) {
4042 g_source_remove (view->selection_update_id);
4043 view->selection_update_id = 0;
4046 if (view->selection_info.selections) {
4047 clear_link_selected (view);
4048 ev_view_update_primary_selection (view);
4050 if (view->selection_info.in_drag) {
4051 clear_selection (view);
4052 gtk_widget_queue_draw (widget);
4055 view->selection_info.in_drag = FALSE;
4057 if (event->button == 2) {
4058 EvLinkAction *action;
4059 EvLinkActionType type;
4061 action = ev_link_get_action (link);
4065 type = ev_link_action_get_action_type (action);
4066 if (type == EV_LINK_ACTION_TYPE_GOTO_DEST) {
4067 g_signal_emit (view,
4068 signals[SIGNAL_EXTERNAL_LINK],
4072 ev_view_handle_link (view, link);
4080 ev_view_key_press_event (GtkWidget *widget,
4083 EvView *view = EV_VIEW (widget);
4085 if (!view->document)
4088 if (!gtk_widget_has_focus (widget)) {
4089 /* Forward key events to current focused window child */
4090 if (view->window_child_focus) {
4091 GdkEventKey *new_event;
4094 new_event = (GdkEventKey *) gdk_event_copy ((GdkEvent *)event);
4095 g_object_unref (new_event->window);
4096 new_event->window = gtk_widget_get_window (view->window_child_focus->window);
4097 if (new_event->window)
4098 g_object_ref (new_event->window);
4099 gtk_widget_realize (view->window_child_focus->window);
4100 handled = gtk_widget_event (view->window_child_focus->window, (GdkEvent *)new_event);
4101 gdk_event_free ((GdkEvent *)new_event);
4109 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
4113 ev_view_focus_in (GtkWidget *widget,
4114 GdkEventFocus *event)
4116 if (EV_VIEW (widget)->pixbuf_cache)
4117 ev_pixbuf_cache_style_changed (EV_VIEW (widget)->pixbuf_cache);
4118 gtk_widget_queue_draw (widget);
4124 ev_view_focus_out (GtkWidget *widget,
4125 GdkEventFocus *event)
4127 if (EV_VIEW (widget)->pixbuf_cache)
4128 ev_pixbuf_cache_style_changed (EV_VIEW (widget)->pixbuf_cache);
4129 gtk_widget_queue_draw (widget);
4135 ev_view_leave_notify_event (GtkWidget *widget, GdkEventCrossing *event)
4137 EvView *view = EV_VIEW (widget);
4139 if (view->cursor != EV_VIEW_CURSOR_NORMAL)
4140 ev_view_set_cursor (view, EV_VIEW_CURSOR_NORMAL);
4146 ev_view_enter_notify_event (GtkWidget *widget, GdkEventCrossing *event)
4148 EvView *view = EV_VIEW (widget);
4150 ev_view_handle_cursor_over_xy (view, event->x, event->y);
4156 ev_view_style_set (GtkWidget *widget,
4157 GtkStyle *old_style)
4159 if (EV_VIEW (widget)->pixbuf_cache)
4160 ev_pixbuf_cache_style_changed (EV_VIEW (widget)->pixbuf_cache);
4162 GTK_WIDGET_CLASS (ev_view_parent_class)->style_set (widget, old_style);
4168 draw_rubberband (EvView *view,
4170 const GdkRectangle *rect,
4174 GdkColor *fill_color_gdk;
4178 style = gtk_widget_get_style (GTK_WIDGET (view));
4179 fill_color_gdk = gdk_color_copy (&style->base[GTK_STATE_SELECTED]);
4180 r = fill_color_gdk->red / 65535.;
4181 g = fill_color_gdk->green / 65535.;
4182 b = fill_color_gdk->blue / 65535.;
4184 cr = gdk_cairo_create (window);
4186 cairo_set_source_rgba (cr, r, g, b, alpha);
4187 cairo_rectangle (cr,
4188 rect->x - view->scroll_x,
4189 rect->y - view->scroll_y,
4190 rect->width, rect->height);
4191 cairo_fill_preserve (cr);
4193 cairo_set_line_width (cr, 0.5);
4194 cairo_set_source_rgb (cr, r, g, b);
4199 gdk_color_free (fill_color_gdk);
4204 highlight_find_results (EvView *view, int page)
4206 gint i, n_results = 0;
4207 GdkWindow *bin_window;
4209 bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (view));
4211 n_results = ev_view_find_get_n_results (view, page);
4213 for (i = 0; i < n_results; i++) {
4214 EvRectangle *rectangle;
4215 GdkRectangle view_rectangle;
4218 if (i == view->find_result && page == view->current_page) {
4224 rectangle = ev_view_find_get_result (view, page, i);
4225 doc_rect_to_view_rect (view, page, rectangle, &view_rectangle);
4226 draw_rubberband (view, bin_window, &view_rectangle, alpha);
4231 highlight_forward_search_results (EvView *view, int page)
4233 GdkWindow *bin_window;
4236 EvMapping *mapping = view->synctex_result;
4238 if (GPOINTER_TO_INT (mapping->data) != page)
4241 bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (view));
4242 doc_rect_to_view_rect (view, page, &mapping->area, &rect);
4244 cr = gdk_cairo_create (bin_window);
4245 cairo_set_source_rgb (cr, 1., 0., 0.);
4246 cairo_rectangle (cr,
4247 rect.x - view->scroll_x,
4248 rect.y - view->scroll_y,
4249 rect.width, rect.height);
4255 focus_annotation (EvView *view,
4259 GtkWidget *widget = GTK_WIDGET (view);
4261 EvMapping *mapping = view->focus_annotation;
4262 EvAnnotation *annot = (EvAnnotation *)mapping->data;
4264 if (ev_annotation_get_page_index (annot) != page)
4267 doc_rect_to_view_rect (view, page, &mapping->area, &rect);
4268 gtk_paint_focus (gtk_widget_get_style (widget),
4269 gtk_layout_get_bin_window (GTK_LAYOUT (view)),
4270 gtk_widget_get_state (widget),
4272 rect.x - view->scroll_x,
4273 rect.y - view->scroll_y,
4274 rect.width + 1, rect.height + 1);
4278 ev_view_loading_window_move (EvView *view)
4280 GtkWidget *widget = GTK_WIDGET (view);
4281 EvLoadingWindow *window = EV_LOADING_WINDOW (view->loading_window);
4282 gint root_x, root_y;
4284 GtkAllocation allocation;
4286 gtk_widget_get_allocation (widget, &allocation);
4287 gdk_window_get_origin (gtk_widget_get_window (widget), &root_x, &root_y);
4288 ev_loading_window_get_size (window, &window_width, NULL);
4290 root_x += allocation.width - window_width - 10;
4293 ev_loading_window_move (window, root_x, root_y);
4297 show_loading_window_cb (EvView *view)
4299 if (!view->loading_window) {
4303 parent = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (view)));
4304 view->loading_window = ev_loading_window_new (parent);
4306 /* Show the window off screen to get a valid size asap */
4307 screen = gtk_widget_get_screen (GTK_WIDGET (view));
4308 gtk_window_move (GTK_WINDOW (view->loading_window),
4309 gdk_screen_get_width (screen) + 1,
4310 gdk_screen_get_height (screen) + 1);
4311 gtk_widget_show (view->loading_window);
4314 ev_view_loading_window_move (view);
4316 gtk_widget_show (view->loading_window);
4318 view->loading_timeout = 0;
4324 show_loading_window (EvView *view)
4326 if (view->loading_window && gtk_widget_get_visible (view->loading_window)) {
4327 ev_view_loading_window_move (view);
4331 if (!view->loading_timeout) {
4332 view->loading_timeout =
4333 g_timeout_add_full (G_PRIORITY_LOW,
4334 0.5, (GSourceFunc)show_loading_window_cb,
4340 hide_loading_window (EvView *view)
4342 if (view->loading_timeout) {
4343 g_source_remove (view->loading_timeout);
4344 view->loading_timeout = 0;
4347 if (view->loading_window && gtk_widget_get_visible (view->loading_window)) {
4348 gtk_widget_hide (view->loading_window);
4353 draw_one_page (EvView *view,
4356 GdkRectangle *page_area,
4358 GdkRectangle *expose_area,
4359 gboolean *page_ready)
4361 GdkWindow *bin_window;
4362 GdkRectangle overlap;
4363 GdkRectangle real_page_area;
4365 gboolean inverted_colors;
4367 g_assert (view->document);
4369 if (! gdk_rectangle_intersect (page_area, expose_area, &overlap))
4372 /* Render the document itself */
4373 real_page_area = *page_area;
4375 real_page_area.x += border->left;
4376 real_page_area.y += border->top;
4377 real_page_area.width -= (border->left + border->right);
4378 real_page_area.height -= (border->top + border->bottom);
4381 bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (view));
4382 current_page = ev_document_model_get_page (view->model);
4383 inverted_colors = ev_document_model_get_inverted_colors (view->model);
4384 ev_document_misc_paint_one_page (cr,
4387 page == current_page,
4390 if (gdk_rectangle_intersect (&real_page_area, expose_area, &overlap)) {
4392 gint page_width, page_height;
4393 cairo_surface_t *page_surface = NULL;
4394 gint selection_width, selection_height;
4395 cairo_surface_t *selection_surface = NULL;
4397 page_surface = ev_pixbuf_cache_get_surface (view->pixbuf_cache, page);
4399 if (!page_surface) {
4400 if (page == current_page)
4401 show_loading_window (view);
4403 *page_ready = FALSE;
4408 if (page == current_page)
4409 hide_loading_window (view);
4411 ev_view_get_page_size (view, page, &width, &height);
4413 page_width = cairo_image_surface_get_width (page_surface);
4414 page_height = cairo_image_surface_get_height (page_surface);
4417 cairo_translate (cr, overlap.x, overlap.y);
4419 if (width != page_width || height != page_height) {
4420 cairo_pattern_set_filter (cairo_get_source (cr),
4423 (gdouble)width / page_width,
4424 (gdouble)height / page_height);
4427 cairo_surface_set_device_offset (page_surface,
4428 overlap.x - real_page_area.x,
4429 overlap.y - real_page_area.y);
4430 cairo_set_source_surface (cr, page_surface, 0, 0);
4434 /* Get the selection pixbuf iff we have something to draw */
4435 if (find_selection_for_page (view, page) &&
4436 view->selection_mode == EV_VIEW_SELECTION_TEXT) {
4438 ev_pixbuf_cache_get_selection_surface (view->pixbuf_cache,
4444 if (!selection_surface) {
4448 selection_width = cairo_image_surface_get_width (selection_surface);
4449 selection_height = cairo_image_surface_get_height (selection_surface);
4452 cairo_translate (cr, overlap.x, overlap.y);
4454 if (width != selection_width || height != selection_height) {
4455 cairo_pattern_set_filter (cairo_get_source (cr),
4458 (gdouble)width / selection_width,
4459 (gdouble)height / selection_height);
4462 cairo_surface_set_device_offset (selection_surface,
4463 overlap.x - real_page_area.x,
4464 overlap.y - real_page_area.y);
4466 cairo_set_source_surface (cr, selection_surface, 0, 0);
4472 /*** GObject functions ***/
4475 ev_view_finalize (GObject *object)
4477 EvView *view = EV_VIEW (object);
4479 clear_selection (view);
4480 clear_link_selected (view);
4482 if (view->synctex_result) {
4483 g_free (view->synctex_result);
4484 view->synctex_result = NULL;
4487 if (view->image_dnd_info.image)
4488 g_object_unref (view->image_dnd_info.image);
4489 view->image_dnd_info.image = NULL;
4491 G_OBJECT_CLASS (ev_view_parent_class)->finalize (object);
4495 ev_view_destroy (GtkObject *object)
4497 EvView *view = EV_VIEW (object);
4500 g_object_unref (view->model);
4504 if (view->pixbuf_cache) {
4505 g_object_unref (view->pixbuf_cache);
4506 view->pixbuf_cache = NULL;
4509 if (view->document) {
4510 g_object_unref (view->document);
4511 view->document = NULL;
4514 if (view->page_cache) {
4515 g_object_unref (view->page_cache);
4516 view->page_cache = NULL;
4519 ev_view_window_children_free (view);
4521 if (view->selection_scroll_id) {
4522 g_source_remove (view->selection_scroll_id);
4523 view->selection_scroll_id = 0;
4526 if (view->selection_update_id) {
4527 g_source_remove (view->selection_update_id);
4528 view->selection_update_id = 0;
4531 if (view->scroll_info.timeout_id) {
4532 g_source_remove (view->scroll_info.timeout_id);
4533 view->scroll_info.timeout_id = 0;
4536 if (view->drag_info.drag_timeout_id) {
4537 g_source_remove (view->drag_info.drag_timeout_id);
4538 view->drag_info.drag_timeout_id = 0;
4541 if (view->drag_info.release_timeout_id) {
4542 g_source_remove (view->drag_info.release_timeout_id);
4543 view->drag_info.release_timeout_id = 0;
4546 if (view->loading_timeout) {
4547 g_source_remove (view->loading_timeout);
4548 view->loading_timeout = 0;
4551 ev_view_set_scroll_adjustments (GTK_LAYOUT (view), NULL, NULL);
4553 GTK_OBJECT_CLASS (ev_view_parent_class)->destroy (object);
4557 ev_view_get_accessible (GtkWidget *widget)
4559 static gboolean first_time = TRUE;
4562 AtkObjectFactory *factory;
4563 AtkRegistry *registry;
4565 GType derived_atk_type;
4568 * Figure out whether accessibility is enabled by looking at the
4569 * type of the accessible object which would be created for
4570 * the parent type of EvView.
4572 derived_type = g_type_parent (EV_TYPE_VIEW);
4574 registry = atk_get_default_registry ();
4575 factory = atk_registry_get_factory (registry,
4577 derived_atk_type = atk_object_factory_get_accessible_type (factory);
4578 if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE)) {
4579 atk_registry_set_factory_type (registry,
4581 ev_view_accessible_factory_get_type ());
4582 EV_VIEW (widget)->a11y_enabled = TRUE;
4586 return GTK_WIDGET_CLASS (ev_view_parent_class)->get_accessible (widget);
4590 ev_view_class_init (EvViewClass *class)
4592 GObjectClass *object_class = G_OBJECT_CLASS (class);
4593 GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (class);
4594 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
4595 GtkLayoutClass *layout_class = GTK_LAYOUT_CLASS (class);
4596 GtkBindingSet *binding_set;
4598 object_class->finalize = ev_view_finalize;
4600 widget_class->expose_event = ev_view_expose_event;
4601 widget_class->button_press_event = ev_view_button_press_event;
4602 widget_class->motion_notify_event = ev_view_motion_notify_event;
4603 widget_class->button_release_event = ev_view_button_release_event;
4604 widget_class->key_press_event = ev_view_key_press_event;
4605 widget_class->focus_in_event = ev_view_focus_in;
4606 widget_class->focus_out_event = ev_view_focus_out;
4607 widget_class->get_accessible = ev_view_get_accessible;
4608 widget_class->size_request = ev_view_size_request;
4609 widget_class->size_allocate = ev_view_size_allocate;
4610 widget_class->realize = ev_view_realize;
4611 widget_class->scroll_event = ev_view_scroll_event;
4612 widget_class->enter_notify_event = ev_view_enter_notify_event;
4613 widget_class->leave_notify_event = ev_view_leave_notify_event;
4614 widget_class->style_set = ev_view_style_set;
4615 widget_class->drag_data_get = ev_view_drag_data_get;
4616 widget_class->drag_motion = ev_view_drag_motion;
4617 widget_class->popup_menu = ev_view_popup_menu;
4618 widget_class->query_tooltip = ev_view_query_tooltip;
4620 gtk_object_class->destroy = ev_view_destroy;
4622 layout_class->set_scroll_adjustments = ev_view_set_scroll_adjustments;
4624 class->binding_activated = ev_view_scroll;
4626 signals[SIGNAL_BINDING_ACTIVATED] = g_signal_new ("binding_activated",
4627 G_TYPE_FROM_CLASS (object_class),
4628 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
4629 G_STRUCT_OFFSET (EvViewClass, binding_activated),
4631 ev_view_marshal_VOID__ENUM_BOOLEAN,
4633 GTK_TYPE_SCROLL_TYPE,
4635 signals[SIGNAL_HANDLE_LINK] = g_signal_new ("handle-link",
4636 G_TYPE_FROM_CLASS (object_class),
4637 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
4638 G_STRUCT_OFFSET (EvViewClass, handle_link),
4640 g_cclosure_marshal_VOID__OBJECT,
4643 signals[SIGNAL_EXTERNAL_LINK] = g_signal_new ("external-link",
4644 G_TYPE_FROM_CLASS (object_class),
4645 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
4646 G_STRUCT_OFFSET (EvViewClass, external_link),
4648 g_cclosure_marshal_VOID__OBJECT,
4651 signals[SIGNAL_POPUP_MENU] = g_signal_new ("popup",
4652 G_TYPE_FROM_CLASS (object_class),
4653 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
4654 G_STRUCT_OFFSET (EvViewClass, popup_menu),
4656 g_cclosure_marshal_VOID__POINTER,
4659 signals[SIGNAL_SELECTION_CHANGED] = g_signal_new ("selection-changed",
4660 G_TYPE_FROM_CLASS (object_class),
4661 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
4662 G_STRUCT_OFFSET (EvViewClass, selection_changed),
4664 g_cclosure_marshal_VOID__VOID,
4667 signals[SIGNAL_SYNC_SOURCE] = g_signal_new ("sync-source",
4668 G_TYPE_FROM_CLASS (object_class),
4669 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
4670 G_STRUCT_OFFSET (EvViewClass, sync_source),
4672 g_cclosure_marshal_VOID__POINTER,
4675 signals[SIGNAL_ANNOT_ADDED] = g_signal_new ("annot-added",
4676 G_TYPE_FROM_CLASS (object_class),
4677 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
4678 G_STRUCT_OFFSET (EvViewClass, annot_added),
4680 g_cclosure_marshal_VOID__OBJECT,
4682 EV_TYPE_ANNOTATION);
4684 binding_set = gtk_binding_set_by_class (class);
4686 add_scroll_binding_keypad (binding_set, GDK_Left, 0, GTK_SCROLL_STEP_BACKWARD, TRUE);
4687 add_scroll_binding_keypad (binding_set, GDK_Right, 0, GTK_SCROLL_STEP_FORWARD, TRUE);
4688 add_scroll_binding_keypad (binding_set, GDK_Left, GDK_MOD1_MASK, GTK_SCROLL_STEP_DOWN, TRUE);
4689 add_scroll_binding_keypad (binding_set, GDK_Right, GDK_MOD1_MASK, GTK_SCROLL_STEP_UP, TRUE);
4690 add_scroll_binding_keypad (binding_set, GDK_Up, 0, GTK_SCROLL_STEP_BACKWARD, FALSE);
4691 add_scroll_binding_keypad (binding_set, GDK_Down, 0, GTK_SCROLL_STEP_FORWARD, FALSE);
4692 add_scroll_binding_keypad (binding_set, GDK_Up, GDK_MOD1_MASK, GTK_SCROLL_STEP_DOWN, FALSE);
4693 add_scroll_binding_keypad (binding_set, GDK_Down, GDK_MOD1_MASK, GTK_SCROLL_STEP_UP, FALSE);
4694 gtk_binding_entry_add_signal (binding_set, GDK_H, 0, "binding_activated", 2, GTK_TYPE_SCROLL_TYPE,
4695 GTK_SCROLL_STEP_BACKWARD, G_TYPE_BOOLEAN, TRUE);
4696 gtk_binding_entry_add_signal (binding_set, GDK_J, 0, "binding_activated", 2, GTK_TYPE_SCROLL_TYPE,
4697 GTK_SCROLL_STEP_FORWARD, G_TYPE_BOOLEAN, FALSE);
4698 gtk_binding_entry_add_signal (binding_set, GDK_K, 0, "binding_activated", 2, GTK_TYPE_SCROLL_TYPE,
4699 GTK_SCROLL_STEP_BACKWARD, G_TYPE_BOOLEAN, FALSE);
4700 gtk_binding_entry_add_signal (binding_set, GDK_L, 0, "binding_activated", 2, GTK_TYPE_SCROLL_TYPE,
4701 GTK_SCROLL_STEP_FORWARD, G_TYPE_BOOLEAN, TRUE);
4706 ev_view_init (EvView *view)
4708 gtk_widget_set_can_focus (GTK_WIDGET (view), TRUE);
4710 view->start_page = -1;
4711 view->end_page = -1;
4714 view->current_page = 0;
4715 view->pressed_button = -1;
4716 view->cursor = EV_VIEW_CURSOR_NORMAL;
4717 view->drag_info.in_drag = FALSE;
4718 view->scroll_info.autoscrolling = FALSE;
4719 view->selection_info.selections = NULL;
4720 view->selection_info.in_selection = FALSE;
4721 view->selection_info.in_drag = FALSE;
4722 view->selection_mode = EV_VIEW_SELECTION_TEXT;
4723 view->continuous = TRUE;
4724 view->dual_page = FALSE;
4725 view->fullscreen = FALSE;
4726 view->sizing_mode = EV_SIZING_FIT_WIDTH;
4727 view->pending_scroll = SCROLL_TO_KEEP_POSITION;
4728 view->jump_to_find_result = TRUE;
4729 view->highlight_find_results = FALSE;
4731 gtk_layout_set_hadjustment (GTK_LAYOUT (view), NULL);
4732 gtk_layout_set_vadjustment (GTK_LAYOUT (view), NULL);
4738 ev_view_change_page (EvView *view,
4743 view->current_page = new_page;
4744 view->pending_scroll = SCROLL_TO_PAGE_POSITION;
4746 hide_loading_window (view);
4748 gtk_widget_get_pointer (GTK_WIDGET (view), &x, &y);
4749 ev_view_handle_cursor_over_xy (view, x, y);
4751 gtk_widget_queue_resize (GTK_WIDGET (view));
4755 job_finished_cb (EvPixbufCache *pixbuf_cache,
4756 cairo_region_t *region,
4760 GdkWindow *bin_window;
4762 bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (view));
4763 gdk_window_invalidate_region (bin_window, region, TRUE);
4765 gtk_widget_queue_draw (GTK_WIDGET (view));
4770 ev_view_page_changed_cb (EvDocumentModel *model,
4775 if (!view->document)
4778 if (view->current_page != new_page) {
4779 ev_view_change_page (view, new_page);
4781 gtk_widget_queue_draw (GTK_WIDGET (view));
4784 view->find_result = 0;
4788 on_adjustment_value_changed (GtkAdjustment *adjustment,
4794 GList *children, *l;
4796 if (!gtk_widget_get_realized (GTK_WIDGET (view)))
4799 if (view->hadjustment) {
4800 value = (gint) gtk_adjustment_get_value (view->hadjustment);
4801 dx = view->scroll_x - value;
4802 view->scroll_x = value;
4807 if (view->vadjustment) {
4808 value = (gint) gtk_adjustment_get_value (view->vadjustment);
4809 dy = view->scroll_y - value;
4810 view->scroll_y = value;
4815 children = gtk_container_get_children (GTK_CONTAINER (view));
4816 for (l = children; l && l->data; l = g_list_next (l)) {
4817 gint child_x, child_y;
4818 GtkWidget *child = (GtkWidget *)l->data;
4820 gtk_container_child_get (GTK_CONTAINER (view),
4825 gtk_layout_move (GTK_LAYOUT (view), child, child_x + dx, child_y + dy);
4827 g_list_free (children);
4829 for (l = view->window_children; l && l->data; l = g_list_next (l)) {
4830 EvViewWindowChild *child;
4832 child = (EvViewWindowChild *)l->data;
4834 ev_view_window_child_move (view, child, child->x + dx, child->y + dy);
4837 if (view->pending_resize) {
4838 gtk_widget_queue_draw (GTK_WIDGET (view));
4840 GdkWindow *bin_window;
4842 bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (view));
4843 gdk_window_scroll (bin_window, dx, dy);
4846 gtk_widget_get_pointer (GTK_WIDGET (view), &x, &y);
4847 ev_view_handle_cursor_over_xy (view, x, y);
4850 view_update_range_and_current_page (view);
4858 view = g_object_new (EV_TYPE_VIEW, NULL);
4864 setup_caches (EvView *view)
4866 gboolean inverted_colors;
4868 view->height_to_page_cache = ev_view_get_height_to_page_cache (view);
4869 view->pixbuf_cache = ev_pixbuf_cache_new (GTK_WIDGET (view), view->model, view->pixbuf_cache_size);
4870 view->page_cache = ev_page_cache_new (view->document);
4871 if (view->a11y_enabled) {
4872 EvJobPageDataFlags flags = ev_page_cache_get_flags (view->page_cache);
4874 ev_page_cache_set_flags (view->page_cache,
4876 EV_PAGE_DATA_INCLUDE_TEXT_LAYOUT |
4877 EV_PAGE_DATA_INCLUDE_TEXT);
4879 inverted_colors = ev_document_model_get_inverted_colors (view->model);
4880 ev_pixbuf_cache_set_inverted_colors (view->pixbuf_cache, inverted_colors);
4881 g_signal_connect (view->pixbuf_cache, "job-finished", G_CALLBACK (job_finished_cb), view);
4885 clear_caches (EvView *view)
4887 if (view->pixbuf_cache) {
4888 g_object_unref (view->pixbuf_cache);
4889 view->pixbuf_cache = NULL;
4892 if (view->page_cache) {
4893 g_object_unref (view->page_cache);
4894 view->page_cache = NULL;
4899 * ev_view_set_page_cache_size:
4903 * Sets the maximum size in bytes that will be used to cache
4904 * rendered pages. Use 0 to disable caching rendered pages.
4906 * Note that this limit doesn't affect the current visible page range,
4907 * which will always be rendered. In order to limit the total memory used
4908 * you have to use ev_document_model_set_max_scale() too.
4912 ev_view_set_page_cache_size (EvView *view,
4915 if (view->pixbuf_cache_size == cache_size)
4918 view->pixbuf_cache_size = cache_size;
4919 if (view->pixbuf_cache)
4920 ev_pixbuf_cache_set_max_size (view->pixbuf_cache, cache_size);
4924 ev_view_set_loading (EvView *view,
4927 if (view->loading && !loading)
4928 hide_loading_window (view);
4929 view->loading = loading;
4930 gtk_widget_queue_draw (GTK_WIDGET (view));
4934 ev_view_autoscroll_cb (EvView *view)
4936 gdouble speed, value;
4938 /* If the user stops autoscrolling, autoscrolling will be
4939 * set to false but the timeout will continue; stop the timeout: */
4940 if (!view->scroll_info.autoscrolling) {
4941 view->scroll_info.timeout_id = 0;
4945 if (view->scroll_info.last_y > view->scroll_info.start_y &&
4946 (view->scroll_info.last_y < view->scroll_info.start_y))
4949 /* Replace 100 with your speed of choice: The lower the faster.
4950 * Replace 3 with another speed of choice: The higher, the faster it accelerated
4951 * based on the distance of the starting point from the mouse
4952 * (All also effected by the timeout interval of this callback) */
4954 if (view->scroll_info.start_y > view->scroll_info.last_y)
4955 speed = -pow ((((gdouble)view->scroll_info.start_y - view->scroll_info.last_y) / 100), 3);
4957 speed = pow ((((gdouble)view->scroll_info.last_y - view->scroll_info.start_y) / 100), 3);
4959 value = gtk_adjustment_get_value (view->vadjustment);
4960 value = CLAMP (value + speed, 0,
4961 gtk_adjustment_get_upper (view->vadjustment) -
4962 gtk_adjustment_get_page_size (view->vadjustment));
4963 gtk_adjustment_set_value (view->vadjustment, value);
4970 ev_view_autoscroll_start (EvView *view)
4974 g_return_if_fail (EV_IS_VIEW (view));
4976 if (view->scroll_info.autoscrolling)
4979 view->scroll_info.autoscrolling = TRUE;
4980 view->scroll_info.timeout_id =
4981 g_timeout_add (20, (GSourceFunc)ev_view_autoscroll_cb,
4984 gtk_widget_get_pointer (GTK_WIDGET (view), &x, &y);
4985 ev_view_handle_cursor_over_xy (view, x, y);
4989 ev_view_autoscroll_stop (EvView *view)
4993 g_return_if_fail (EV_IS_VIEW (view));
4995 if (!view->scroll_info.autoscrolling)
4998 view->scroll_info.autoscrolling = FALSE;
4999 if (view->scroll_info.timeout_id) {
5000 g_source_remove (view->scroll_info.timeout_id);
5001 view->scroll_info.timeout_id = 0;
5004 gtk_widget_get_pointer (GTK_WIDGET (view), &x, &y);
5005 ev_view_handle_cursor_over_xy (view, x, y);
5009 ev_view_document_changed_cb (EvDocumentModel *model,
5013 EvDocument *document = ev_document_model_get_document (model);
5015 if (document != view->document) {
5018 clear_caches (view);
5020 if (view->document) {
5021 g_object_unref (view->document);
5024 view->document = document;
5025 view->find_result = 0;
5027 if (view->document) {
5028 view->loading = FALSE;
5029 g_object_ref (view->document);
5030 setup_caches (view);
5033 current_page = ev_document_model_get_page (model);
5034 if (view->current_page != current_page) {
5035 ev_view_change_page (view, current_page);
5037 view->pending_scroll = SCROLL_TO_KEEP_POSITION;
5038 gtk_widget_queue_resize (GTK_WIDGET (view));
5044 ev_view_rotation_changed_cb (EvDocumentModel *model,
5048 gint rotation = ev_document_model_get_rotation (model);
5050 view->rotation = rotation;
5052 if (view->pixbuf_cache) {
5053 ev_pixbuf_cache_clear (view->pixbuf_cache);
5054 if (!ev_document_is_page_size_uniform (view->document))
5055 view->pending_scroll = SCROLL_TO_PAGE_POSITION;
5056 gtk_widget_queue_resize (GTK_WIDGET (view));
5059 ev_view_remove_all (view);
5062 clear_selection (view);
5066 ev_view_inverted_colors_changed_cb (EvDocumentModel *model,
5070 if (view->pixbuf_cache) {
5071 gboolean inverted_colors;
5073 inverted_colors = ev_document_model_get_inverted_colors (model);
5074 ev_pixbuf_cache_set_inverted_colors (view->pixbuf_cache, inverted_colors);
5075 gtk_widget_queue_draw (GTK_WIDGET (view));
5080 ev_view_sizing_mode_changed_cb (EvDocumentModel *model,
5084 EvSizingMode mode = ev_document_model_get_sizing_mode (model);
5086 view->sizing_mode = mode;
5087 if (mode != EV_SIZING_FREE)
5088 gtk_widget_queue_resize (GTK_WIDGET (view));
5091 #define EPSILON 0.0000001
5093 ev_view_scale_changed_cb (EvDocumentModel *model,
5097 gdouble scale = ev_document_model_get_scale (model);
5099 if (ABS (view->scale - scale) < EPSILON)
5102 view->scale = scale;
5104 view->pending_resize = TRUE;
5105 if (view->sizing_mode == EV_SIZING_FREE)
5106 gtk_widget_queue_resize (GTK_WIDGET (view));
5110 ev_view_continuous_changed_cb (EvDocumentModel *model,
5114 gboolean continuous = ev_document_model_get_continuous (model);
5116 view->continuous = continuous;
5117 view->pending_scroll = SCROLL_TO_PAGE_POSITION;
5118 gtk_widget_queue_resize (GTK_WIDGET (view));
5122 ev_view_dual_page_changed_cb (EvDocumentModel *model,
5126 gboolean dual_page = ev_document_model_get_dual_page (model);
5128 view->dual_page = dual_page;
5129 view->pending_scroll = SCROLL_TO_PAGE_POSITION;
5130 /* FIXME: if we're keeping the pixbuf cache around, we should extend the
5131 * preload_cache_size to be 2 if dual_page is set.
5133 gtk_widget_queue_resize (GTK_WIDGET (view));
5137 ev_view_fullscreen_changed_cb (EvDocumentModel *model,
5141 gboolean fullscreen = ev_document_model_get_fullscreen (model);
5143 view->fullscreen = fullscreen;
5144 gtk_widget_queue_resize (GTK_WIDGET (view));
5148 ev_view_set_model (EvView *view,
5149 EvDocumentModel *model)
5151 g_return_if_fail (EV_IS_VIEW (view));
5152 g_return_if_fail (EV_IS_DOCUMENT_MODEL (model));
5154 if (model == view->model)
5158 g_signal_handlers_disconnect_by_func (view->model,
5159 ev_view_document_changed_cb,
5161 g_signal_handlers_disconnect_by_func (view->model,
5162 ev_view_page_changed_cb,
5164 g_object_unref (view->model);
5166 view->model = g_object_ref (model);
5168 /* Initialize view from model */
5169 view->rotation = ev_document_model_get_rotation (view->model);
5170 view->sizing_mode = ev_document_model_get_sizing_mode (view->model);
5171 view->scale = ev_document_model_get_scale (view->model);
5172 view->continuous = ev_document_model_get_continuous (view->model);
5173 view->dual_page = ev_document_model_get_dual_page (view->model);
5174 view->fullscreen = ev_document_model_get_fullscreen (view->model);
5175 ev_view_document_changed_cb (view->model, NULL, view);
5177 g_signal_connect (view->model, "notify::document",
5178 G_CALLBACK (ev_view_document_changed_cb),
5180 g_signal_connect (view->model, "notify::rotation",
5181 G_CALLBACK (ev_view_rotation_changed_cb),
5183 g_signal_connect (view->model, "notify::inverted-colors",
5184 G_CALLBACK (ev_view_inverted_colors_changed_cb),
5186 g_signal_connect (view->model, "notify::sizing-mode",
5187 G_CALLBACK (ev_view_sizing_mode_changed_cb),
5189 g_signal_connect (view->model, "notify::scale",
5190 G_CALLBACK (ev_view_scale_changed_cb),
5192 g_signal_connect (view->model, "notify::continuous",
5193 G_CALLBACK (ev_view_continuous_changed_cb),
5195 g_signal_connect (view->model, "notify::dual-page",
5196 G_CALLBACK (ev_view_dual_page_changed_cb),
5198 g_signal_connect (view->model, "notify::fullscreen",
5199 G_CALLBACK (ev_view_fullscreen_changed_cb),
5201 g_signal_connect (view->model, "page-changed",
5202 G_CALLBACK (ev_view_page_changed_cb),
5207 ev_view_reload_page (EvView *view,
5209 cairo_region_t *region)
5211 ev_pixbuf_cache_reload_page (view->pixbuf_cache,
5219 ev_view_reload (EvView *view)
5221 ev_pixbuf_cache_clear (view->pixbuf_cache);
5222 view_update_range_and_current_page (view);
5225 /*** Zoom and sizing mode ***/
5228 ev_view_can_zoom_in (EvView *view)
5230 return view->scale * ZOOM_IN_FACTOR <= ev_document_model_get_max_scale (view->model);
5234 ev_view_can_zoom_out (EvView *view)
5236 return view->scale * ZOOM_OUT_FACTOR >= ev_document_model_get_min_scale (view->model);
5240 ev_view_zoom_in (EvView *view)
5244 g_return_if_fail (view->sizing_mode == EV_SIZING_FREE);
5246 view->pending_scroll = SCROLL_TO_CENTER;
5247 scale = ev_document_model_get_scale (view->model) * ZOOM_IN_FACTOR;
5248 ev_document_model_set_scale (view->model, scale);
5252 ev_view_zoom_out (EvView *view)
5256 g_return_if_fail (view->sizing_mode == EV_SIZING_FREE);
5258 view->pending_scroll = SCROLL_TO_CENTER;
5259 scale = ev_document_model_get_scale (view->model) * ZOOM_OUT_FACTOR;
5260 ev_document_model_set_scale (view->model, scale);
5264 zoom_for_size_fit_width (gdouble doc_width,
5269 return (double)target_width / doc_width;
5273 zoom_for_size_fit_height (gdouble doc_width,
5278 return (double)target_height / doc_height;
5282 zoom_for_size_best_fit (gdouble doc_width,
5290 w_scale = (double)target_width / doc_width;
5291 h_scale = (double)target_height / doc_height;
5293 return MIN (w_scale, h_scale);
5297 ev_view_zoom_for_size_continuous_and_dual_page (EvView *view,
5301 gdouble doc_width, doc_height;
5306 ev_document_get_max_page_size (view->document, &doc_width, &doc_height);
5307 if (view->rotation == 90 || view->rotation == 270) {
5311 doc_width = doc_height;
5315 compute_border (view, doc_width, doc_height, &border);
5318 width -= (2 * (border.left + border.right) + 3 * view->spacing);
5319 height -= (border.top + border.bottom + 2 * view->spacing - 1);
5321 sb_size = ev_view_get_scrollbar_size (view, GTK_ORIENTATION_VERTICAL);
5323 if (view->sizing_mode == EV_SIZING_FIT_WIDTH) {
5324 scale = zoom_for_size_fit_width (doc_width, doc_height, width - sb_size, height);
5325 } else if (view->sizing_mode == EV_SIZING_BEST_FIT)
5326 scale = zoom_for_size_best_fit (doc_width, doc_height, width - sb_size, height);
5328 g_assert_not_reached ();
5330 ev_document_model_set_scale (view->model, scale);
5334 ev_view_zoom_for_size_continuous (EvView *view,
5338 gdouble doc_width, doc_height;
5343 ev_document_get_max_page_size (view->document, &doc_width, &doc_height);
5344 if (view->rotation == 90 || view->rotation == 270) {
5348 doc_width = doc_height;
5352 compute_border (view, doc_width, doc_height, &border);
5354 width -= (border.left + border.right + 2 * view->spacing);
5355 height -= (border.top + border.bottom + 2 * view->spacing - 1);
5357 sb_size = ev_view_get_scrollbar_size (view, GTK_ORIENTATION_VERTICAL);
5359 if (view->sizing_mode == EV_SIZING_FIT_WIDTH) {
5360 scale = zoom_for_size_fit_width (doc_width, doc_height, width - sb_size, height);
5361 } else if (view->sizing_mode == EV_SIZING_BEST_FIT)
5362 scale = zoom_for_size_best_fit (doc_width, doc_height, width - sb_size, height);
5364 g_assert_not_reached ();
5366 ev_document_model_set_scale (view->model, scale);
5370 ev_view_zoom_for_size_dual_page (EvView *view,
5375 gdouble doc_width, doc_height;
5379 other_page = view->current_page ^ 1;
5381 /* Find the largest of the two. */
5382 get_doc_page_size (view, view->current_page, &doc_width, &doc_height);
5383 if (other_page < ev_document_get_n_pages (view->document)) {
5384 gdouble width_2, height_2;
5386 get_doc_page_size (view, other_page, &width_2, &height_2);
5387 if (width_2 > doc_width)
5388 doc_width = width_2;
5389 if (height_2 > doc_height)
5390 doc_height = height_2;
5392 compute_border (view, width, height, &border);
5394 doc_width = doc_width * 2;
5395 width -= ((border.left + border.right)* 2 + 3 * view->spacing);
5396 height -= (border.top + border.bottom + 2 * view->spacing);
5398 if (view->sizing_mode == EV_SIZING_FIT_WIDTH) {
5401 sb_size = ev_view_get_scrollbar_size (view, GTK_ORIENTATION_VERTICAL);
5402 scale = zoom_for_size_fit_width (doc_width, doc_height, width - sb_size, height);
5403 } else if (view->sizing_mode == EV_SIZING_BEST_FIT)
5404 scale = zoom_for_size_best_fit (doc_width, doc_height, width, height);
5406 g_assert_not_reached ();
5408 ev_document_model_set_scale (view->model, scale);
5412 ev_view_zoom_for_size_single_page (EvView *view,
5416 gdouble doc_width, doc_height;
5420 get_doc_page_size (view, view->current_page, &doc_width, &doc_height);
5422 /* Get an approximate border */
5423 compute_border (view, width, height, &border);
5425 width -= (border.left + border.right + 2 * view->spacing);
5426 height -= (border.top + border.bottom + 2 * view->spacing);
5428 if (view->sizing_mode == EV_SIZING_FIT_WIDTH) {
5431 sb_size = ev_view_get_scrollbar_size (view, GTK_ORIENTATION_VERTICAL);
5432 scale = zoom_for_size_fit_width (doc_width, doc_height, width - sb_size, height);
5433 } else if (view->sizing_mode == EV_SIZING_BEST_FIT)
5434 scale = zoom_for_size_best_fit (doc_width, doc_height, width, height);
5436 g_assert_not_reached ();
5438 ev_document_model_set_scale (view->model, scale);
5442 ev_view_zoom_for_size (EvView *view,
5446 g_return_if_fail (EV_IS_VIEW (view));
5447 g_return_if_fail (view->sizing_mode == EV_SIZING_FIT_WIDTH ||
5448 view->sizing_mode == EV_SIZING_BEST_FIT);
5449 g_return_if_fail (width >= 0);
5450 g_return_if_fail (height >= 0);
5452 if (view->document == NULL)
5455 if (view->continuous && view->dual_page)
5456 ev_view_zoom_for_size_continuous_and_dual_page (view, width, height);
5457 else if (view->continuous)
5458 ev_view_zoom_for_size_continuous (view, width, height);
5459 else if (view->dual_page)
5460 ev_view_zoom_for_size_dual_page (view, width, height);
5462 ev_view_zoom_for_size_single_page (view, width, height);
5467 ev_view_find_get_n_results (EvView *view, gint page)
5469 return view->find_pages ? g_list_length (view->find_pages[page]) : 0;
5472 static EvRectangle *
5473 ev_view_find_get_result (EvView *view, gint page, gint result)
5475 return view->find_pages ? (EvRectangle *) g_list_nth_data (view->find_pages[page], result) : NULL;
5479 jump_to_find_result (EvView *view)
5482 gint page = view->current_page;
5484 n_results = ev_view_find_get_n_results (view, page);
5486 if (n_results > 0 && view->find_result < n_results) {
5488 GdkRectangle view_rect;
5490 rect = ev_view_find_get_result (view, page, view->find_result);
5491 doc_rect_to_view_rect (view, page, rect, &view_rect);
5492 ensure_rectangle_is_visible (view, &view_rect);
5493 view->jump_to_find_result = FALSE;
5499 * @view: #EvView instance
5500 * @direction: Direction to look
5501 * @shift: Shift from current page
5503 * Jumps to the first page that has occurences of searched word.
5504 * Uses a direction where to look and a shift from current page.
5508 jump_to_find_page (EvView *view, EvViewFindDirection direction, gint shift)
5512 n_pages = ev_document_get_n_pages (view->document);
5514 for (i = 0; i < n_pages; i++) {
5517 if (direction == EV_VIEW_FIND_NEXT)
5518 page = view->current_page + i;
5520 page = view->current_page - i;
5523 if (page >= n_pages) {
5524 page = page - n_pages;
5525 } else if (page < 0)
5526 page = page + n_pages;
5528 if (ev_view_find_get_n_results (view, page) > 0) {
5529 ev_document_model_set_page (view->model, page);
5536 ev_view_find_changed (EvView *view, GList **results, gint page)
5538 view->find_pages = results;
5540 if (view->jump_to_find_result == TRUE) {
5541 jump_to_find_page (view, EV_VIEW_FIND_NEXT, 0);
5542 jump_to_find_result (view);
5545 if (view->current_page == page)
5546 gtk_widget_queue_draw (GTK_WIDGET (view));
5550 ev_view_find_next (EvView *view)
5554 n_results = ev_view_find_get_n_results (view, view->current_page);
5555 view->find_result++;
5557 if (view->find_result >= n_results) {
5558 view->find_result = 0;
5559 jump_to_find_page (view, EV_VIEW_FIND_NEXT, 1);
5560 jump_to_find_result (view);
5562 jump_to_find_result (view);
5563 gtk_widget_queue_draw (GTK_WIDGET (view));
5568 ev_view_find_previous (EvView *view)
5570 view->find_result--;
5572 if (view->find_result < 0) {
5573 jump_to_find_page (view, EV_VIEW_FIND_PREV, -1);
5574 view->find_result = MAX (0, ev_view_find_get_n_results (view, view->current_page) - 1);
5575 jump_to_find_result (view);
5577 jump_to_find_result (view);
5578 gtk_widget_queue_draw (GTK_WIDGET (view));
5583 ev_view_find_search_changed (EvView *view)
5585 /* search string has changed, focus on new search result */
5586 view->jump_to_find_result = TRUE;
5587 view->find_pages = NULL;
5591 ev_view_find_set_highlight_search (EvView *view, gboolean value)
5593 view->highlight_find_results = value;
5594 gtk_widget_queue_draw (GTK_WIDGET (view));
5598 ev_view_find_cancel (EvView *view)
5600 view->find_pages = NULL;
5605 ev_view_highlight_forward_search (EvView *view,
5610 GdkRectangle view_rect;
5612 if (!ev_document_has_synctex (view->document))
5615 mapping = ev_document_synctex_forward_search (view->document, link);
5619 if (view->synctex_result)
5620 g_free (view->synctex_result);
5621 view->synctex_result = mapping;
5623 page = GPOINTER_TO_INT (mapping->data);
5624 ev_document_model_set_page (view->model, page);
5626 doc_rect_to_view_rect (view, page, &mapping->area, &view_rect);
5627 ensure_rectangle_is_visible (view, &view_rect);
5628 gtk_widget_queue_draw (GTK_WIDGET (view));
5631 /*** Selections ***/
5633 /* compute_new_selection_rect/text calculates the area currently selected by
5634 * view_rect. each handles a different mode;
5637 compute_new_selection_rect (EvView *view,
5641 GdkRectangle view_rect;
5645 g_assert (view->selection_mode == EV_VIEW_SELECTION_RECTANGLE);
5647 view_rect.x = MIN (start->x, stop->x);
5648 view_rect.y = MIN (start->y, stop->y);
5649 view_rect.width = MAX (start->x, stop->x) - view_rect.x;
5650 view_rect.width = MAX (start->y, stop->y) - view_rect.y;
5652 n_pages = ev_document_get_n_pages (view->document);
5654 for (i = 0; i < n_pages; i++) {
5655 GdkRectangle page_area;
5658 if (ev_view_get_page_extents (view, i, &page_area, &border)) {
5659 GdkRectangle overlap;
5661 if (gdk_rectangle_intersect (&page_area, &view_rect, &overlap)) {
5662 EvViewSelection *selection;
5664 selection = g_new0 (EvViewSelection, 1);
5665 selection->page = i;
5666 view_rect_to_doc_rect (view, &overlap, &page_area,
5667 &(selection->rect));
5669 list = g_list_append (list, selection);
5678 gdk_rectangle_point_in (GdkRectangle *rectangle,
5681 return rectangle->x <= point->x &&
5682 rectangle->y <= point->y &&
5683 point->x < rectangle->x + rectangle->width &&
5684 point->y < rectangle->y + rectangle->height;
5688 compute_new_selection_text (EvView *view,
5689 EvSelectionStyle style,
5693 int n_pages, i, first, last;
5695 EvViewSelection *selection;
5696 gdouble width, height;
5697 int start_page, end_page;
5699 g_assert (view->selection_mode == EV_VIEW_SELECTION_TEXT);
5701 n_pages = ev_document_get_n_pages (view->document);
5703 /* First figure out the range of pages the selection
5707 if (view->continuous) {
5710 } else if (view->dual_page) {
5711 start_page = view->start_page;
5712 end_page = view->end_page + 1;
5714 start_page = view->current_page;
5715 end_page = view->current_page + 1;
5718 for (i = start_page; i < end_page; i++) {
5719 GdkRectangle page_area;
5722 ev_view_get_page_extents (view, i, &page_area, &border);
5723 if (gdk_rectangle_point_in (&page_area, start) ||
5724 gdk_rectangle_point_in (&page_area, stop)) {
5725 if (first == n_pages)
5732 /* Now create a list of EvViewSelection's for the affected
5733 * pages. This could be an empty list, a list of just one
5734 * page or a number of pages.*/
5735 for (i = first; i < last + 1; i++) {
5736 GdkRectangle page_area;
5740 get_doc_page_size (view, i, &width, &height);
5742 selection = g_new0 (EvViewSelection, 1);
5743 selection->page = i;
5744 selection->style = style;
5745 selection->rect.x1 = selection->rect.y1 = 0;
5746 selection->rect.x2 = width;
5747 selection->rect.y2 = height;
5749 ev_view_get_page_extents (view, i, &page_area, &border);
5751 if (gdk_rectangle_point_in (&page_area, start))
5757 view_point_to_doc_point (view, point, &page_area,
5758 &selection->rect.x1,
5759 &selection->rect.y1);
5761 /* If the selection is contained within just one page,
5762 * make sure we don't write 'start' into both points
5763 * in selection->rect. */
5768 view_point_to_doc_point (view, point, &page_area,
5769 &selection->rect.x2,
5770 &selection->rect.y2);
5772 list = g_list_append (list, selection);
5778 /* This function takes the newly calculated list, and figures out which regions
5779 * have changed. It then queues a redraw approporiately.
5782 merge_selection_region (EvView *view,
5786 GList *new_list_ptr, *old_list_ptr;
5788 /* Update the selection */
5789 old_list = ev_pixbuf_cache_get_selection_list (view->pixbuf_cache);
5790 g_list_foreach (view->selection_info.selections, (GFunc)selection_free, NULL);
5791 g_list_free (view->selection_info.selections);
5792 view->selection_info.selections = new_list;
5793 ev_pixbuf_cache_set_selection_list (view->pixbuf_cache, new_list);
5794 g_signal_emit (view, signals[SIGNAL_SELECTION_CHANGED], 0, NULL);
5796 new_list_ptr = new_list;
5797 old_list_ptr = old_list;
5799 while (new_list_ptr || old_list_ptr) {
5800 EvViewSelection *old_sel, *new_sel;
5802 cairo_region_t *region = NULL;
5804 new_sel = (new_list_ptr) ? (new_list_ptr->data) : NULL;
5805 old_sel = (old_list_ptr) ? (old_list_ptr->data) : NULL;
5807 /* Assume that the lists are in order, and we run through them
5808 * comparing them, one page at a time. We come out with the
5809 * first page we see. */
5810 if (new_sel && old_sel) {
5811 if (new_sel->page < old_sel->page) {
5812 new_list_ptr = new_list_ptr->next;
5814 } else if (new_sel->page > old_sel->page) {
5815 old_list_ptr = old_list_ptr->next;
5818 new_list_ptr = new_list_ptr->next;
5819 old_list_ptr = old_list_ptr->next;
5821 } else if (new_sel) {
5822 new_list_ptr = new_list_ptr->next;
5823 } else if (old_sel) {
5824 old_list_ptr = old_list_ptr->next;
5827 g_assert (new_sel || old_sel);
5829 /* is the page we're looking at on the screen?*/
5830 cur_page = new_sel ? new_sel->page : old_sel->page;
5831 if (cur_page < view->start_page || cur_page > view->end_page)
5834 /* seed the cache with a new page. We are going to need the new
5837 cairo_region_t *tmp_region = NULL;
5839 ev_pixbuf_cache_get_selection_surface (view->pixbuf_cache,
5844 if (tmp_region && !cairo_region_is_empty (tmp_region)) {
5845 new_sel->covered_region = cairo_region_reference (tmp_region);
5849 /* Now we figure out what needs redrawing */
5850 if (old_sel && new_sel) {
5851 if (old_sel->covered_region && new_sel->covered_region) {
5852 /* We only want to redraw the areas that have
5853 * changed, so we xor the old and new regions
5854 * and redraw if it's different */
5855 region = cairo_region_copy (old_sel->covered_region);
5856 #if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 9, 12)
5857 cairo_region_xor (region, new_sel->covered_region);
5859 cairo_region_t *tbr;
5860 tbr = cairo_region_copy (new_sel->covered_region);
5862 /* xor old_sel, new_sel*/
5863 cairo_region_subtract (tbr, region);
5864 cairo_region_subtract (region, new_sel->covered_region);
5865 cairo_region_union (region, tbr);
5866 cairo_region_destroy (tbr);
5869 if (cairo_region_is_empty (region)) {
5870 cairo_region_destroy (region);
5873 gint num_rectangles = cairo_region_num_rectangles (region);
5876 /* We need to make the damage region a little bigger
5877 * because the edges of the old selection might change
5879 cairo_region_get_rectangle (region, 0, &r);
5882 cairo_region_union_rectangle (region, &r);
5884 cairo_region_get_rectangle (region, num_rectangles - 1, &r);
5887 cairo_region_union_rectangle (region, &r);
5889 } else if (old_sel->covered_region) {
5890 region = cairo_region_copy (old_sel->covered_region);
5891 } else if (new_sel->covered_region) {
5892 region = cairo_region_copy (new_sel->covered_region);
5894 } else if (old_sel && !new_sel) {
5895 if (old_sel->covered_region && !cairo_region_is_empty (old_sel->covered_region)) {
5896 region = cairo_region_copy (old_sel->covered_region);
5898 } else if (!old_sel && new_sel) {
5899 if (new_sel->covered_region && !cairo_region_is_empty (new_sel->covered_region)) {
5900 region = cairo_region_copy (new_sel->covered_region);
5903 g_assert_not_reached ();
5906 /* Redraw the damaged region! */
5908 GdkWindow *bin_window;
5909 GdkRectangle page_area;
5912 bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (view));
5913 ev_view_get_page_extents (view, cur_page, &page_area, &border);
5914 cairo_region_translate (region,
5915 page_area.x + border.left - view->scroll_x,
5916 page_area.y + border.top - view->scroll_y);
5917 gdk_window_invalidate_region (bin_window, region, TRUE);
5918 cairo_region_destroy (region);
5922 /* Free the old list, now that we're done with it. */
5923 g_list_foreach (old_list, (GFunc) selection_free, NULL);
5924 g_list_free (old_list);
5928 compute_selections (EvView *view,
5929 EvSelectionStyle style,
5935 if (view->selection_mode == EV_VIEW_SELECTION_RECTANGLE)
5936 list = compute_new_selection_rect (view, start, stop);
5938 list = compute_new_selection_text (view, style, start, stop);
5939 merge_selection_region (view, list);
5942 /* Free's the selection. It's up to the caller to queue redraws if needed.
5945 selection_free (EvViewSelection *selection)
5947 if (selection->covered_region)
5948 cairo_region_destroy (selection->covered_region);
5953 clear_selection (EvView *view)
5955 if (view->selection_info.selections) {
5956 g_list_foreach (view->selection_info.selections, (GFunc)selection_free, NULL);
5957 g_list_free (view->selection_info.selections);
5958 view->selection_info.selections = NULL;
5960 g_signal_emit (view, signals[SIGNAL_SELECTION_CHANGED], 0, NULL);
5962 view->selection_info.in_selection = FALSE;
5963 if (view->pixbuf_cache)
5964 ev_pixbuf_cache_set_selection_list (view->pixbuf_cache, NULL);
5968 ev_view_select_all (EvView *view)
5970 GList *selections = NULL;
5973 /* Disable selection on rotated pages for the 0.4.0 series */
5974 if (view->rotation != 0)
5977 clear_selection (view);
5979 n_pages = ev_document_get_n_pages (view->document);
5980 for (i = 0; i < n_pages; i++) {
5981 gdouble width, height;
5982 EvViewSelection *selection;
5984 get_doc_page_size (view, i, &width, &height);
5986 selection = g_new0 (EvViewSelection, 1);
5987 selection->page = i;
5988 selection->style = EV_SELECTION_STYLE_GLYPH;
5989 selection->rect.x1 = selection->rect.y1 = 0;
5990 selection->rect.x2 = width;
5991 selection->rect.y2 = height;
5993 selections = g_list_append (selections, selection);
5996 merge_selection_region (view, selections);
5997 gtk_widget_queue_draw (GTK_WIDGET (view));
6001 ev_view_get_has_selection (EvView *view)
6003 return view->selection_info.selections != NULL;
6007 get_selected_text (EvView *view)
6011 gchar *normalized_text;
6013 text = g_string_new (NULL);
6015 ev_document_doc_mutex_lock ();
6017 for (l = view->selection_info.selections; l != NULL; l = l->next) {
6018 EvViewSelection *selection = (EvViewSelection *)l->data;
6022 page = ev_document_get_page (view->document, selection->page);
6023 tmp = ev_selection_get_selected_text (EV_SELECTION (view->document),
6024 page, selection->style,
6025 &(selection->rect));
6026 g_object_unref (page);
6027 g_string_append (text, tmp);
6031 ev_document_doc_mutex_unlock ();
6033 normalized_text = g_utf8_normalize (text->str, text->len, G_NORMALIZE_NFKC);
6034 g_string_free (text, TRUE);
6035 return normalized_text;
6039 ev_view_clipboard_copy (EvView *view,
6042 GtkClipboard *clipboard;
6044 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (view),
6045 GDK_SELECTION_CLIPBOARD);
6046 gtk_clipboard_set_text (clipboard, text, -1);
6050 ev_view_copy (EvView *ev_view)
6054 if (!EV_IS_SELECTION (ev_view->document))
6057 text = get_selected_text (ev_view);
6058 ev_view_clipboard_copy (ev_view, text);
6063 ev_view_primary_get_cb (GtkClipboard *clipboard,
6064 GtkSelectionData *selection_data,
6068 EvView *ev_view = EV_VIEW (data);
6070 if (ev_view->link_selected) {
6071 gtk_selection_data_set_text (selection_data,
6072 ev_link_action_get_uri (ev_view->link_selected),
6074 } else if (EV_IS_SELECTION (ev_view->document) &&
6075 ev_view->selection_info.selections) {
6078 text = get_selected_text (ev_view);
6080 gtk_selection_data_set_text (selection_data, text, -1);
6087 ev_view_primary_clear_cb (GtkClipboard *clipboard,
6090 EvView *view = EV_VIEW (data);
6092 clear_selection (view);
6093 clear_link_selected (view);
6097 ev_view_update_primary_selection (EvView *ev_view)
6099 GtkClipboard *clipboard;
6101 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (ev_view),
6102 GDK_SELECTION_PRIMARY);
6104 if (ev_view->selection_info.selections || ev_view->link_selected) {
6105 GtkTargetList *target_list;
6106 GtkTargetEntry *targets;
6109 target_list = gtk_target_list_new (NULL, 0);
6110 gtk_target_list_add_text_targets (target_list, 0);
6111 targets = gtk_target_table_new_from_list (target_list, &n_targets);
6112 gtk_target_list_unref (target_list);
6114 if (!gtk_clipboard_set_with_owner (clipboard,
6116 ev_view_primary_get_cb,
6117 ev_view_primary_clear_cb,
6118 G_OBJECT (ev_view)))
6119 ev_view_primary_clear_cb (clipboard, ev_view);
6121 gtk_target_table_free (targets, n_targets);
6123 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (ev_view))
6124 gtk_clipboard_clear (clipboard);
6129 clear_link_selected (EvView *view)
6131 if (view->link_selected) {
6132 g_object_unref (view->link_selected);
6133 view->link_selected = NULL;
6138 ev_view_copy_link_address (EvView *view,
6139 EvLinkAction *action)
6141 clear_link_selected (view);
6143 ev_view_clipboard_copy (view, ev_link_action_get_uri (action));
6145 view->link_selected = g_object_ref (action);
6146 ev_view_update_primary_selection (view);
6149 /*** Cursor operations ***/
6151 ev_view_set_cursor (EvView *view, EvViewCursor new_cursor)
6153 GdkCursor *cursor = NULL;
6155 GdkWindow *bin_window;
6157 if (view->cursor == new_cursor) {
6161 view->cursor = new_cursor;
6163 bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (view));
6164 widget = gtk_widget_get_toplevel (GTK_WIDGET (view));
6165 cursor = ev_view_cursor_new (gtk_widget_get_display (widget), new_cursor);
6166 gdk_window_set_cursor (bin_window, cursor);
6169 gdk_cursor_unref (cursor);
6173 ev_view_hide_cursor (EvView *view)
6175 ev_view_set_cursor (view, EV_VIEW_CURSOR_HIDDEN);
6179 ev_view_show_cursor (EvView *view)
6181 ev_view_set_cursor (view, EV_VIEW_CURSOR_NORMAL);
6185 ev_view_next_page (EvView *view)
6189 g_return_val_if_fail (EV_IS_VIEW (view), FALSE);
6191 if (!view->document)
6194 page = ev_document_model_get_page (view->model);
6195 n_pages = ev_document_get_n_pages (view->document);
6197 if (view->dual_page)
6202 if (page < n_pages) {
6203 ev_document_model_set_page (view->model, page);
6205 } else if (view->dual_page && page == n_pages) {
6206 ev_document_model_set_page (view->model, page - 1);
6214 ev_view_previous_page (EvView *view)
6218 g_return_val_if_fail (EV_IS_VIEW (view), FALSE);
6220 if (!view->document)
6223 page = ev_document_model_get_page (view->model);
6225 if (view->dual_page)
6231 ev_document_model_set_page (view->model, page);
6233 } else if (view->dual_page && page == -1) {
6234 ev_document_model_set_page (view->model, 0);