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-layers.h"
36 #include "ev-document-misc.h"
37 #include "ev-pixbuf-cache.h"
38 #include "ev-page-cache.h"
39 #include "ev-view-marshal.h"
40 #include "ev-document-annotations.h"
41 #include "ev-annotation-window.h"
42 #include "ev-loading-window.h"
44 #include "ev-view-accessible.h"
45 #include "ev-view-private.h"
46 #include "ev-view-type-builtins.h"
48 #define EV_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EV_TYPE_VIEW, EvViewClass))
49 #define EV_IS_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EV_TYPE_VIEW))
50 #define EV_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EV_TYPE_VIEW, EvViewClass))
53 SIGNAL_BINDING_ACTIVATED,
57 SIGNAL_SELECTION_CHANGED,
60 SIGNAL_LAYERS_CHANGED,
78 static guint signals[N_SIGNALS];
83 } EvViewFindDirection;
85 #define ZOOM_IN_FACTOR 1.2
86 #define ZOOM_OUT_FACTOR (1.0/ZOOM_IN_FACTOR)
88 #define SCROLL_TIME 150
91 static void view_update_range_and_current_page (EvView *view);
92 static void add_scroll_binding_keypad (GtkBindingSet *binding_set,
94 GdkModifierType modifiers,
97 static void ensure_rectangle_is_visible (EvView *view,
100 /*** Geometry computations ***/
101 static void compute_border (EvView *view,
105 static void get_page_y_offset (EvView *view,
108 static void view_rect_to_doc_rect (EvView *view,
109 GdkRectangle *view_rect,
110 GdkRectangle *page_area,
111 EvRectangle *doc_rect);
112 static void doc_rect_to_view_rect (EvView *view,
114 EvRectangle *doc_rect,
115 GdkRectangle *view_rect);
116 static gboolean get_dual_even_left (EvView *view);
117 static void find_page_at_location (EvView *view,
123 static void doc_point_to_view_point (EvView *view,
126 GdkPoint *view_point);
128 static EvLink * ev_view_get_link_at_location (EvView *view,
131 static char* tip_from_link (EvView *view,
134 static EvFormField *ev_view_get_form_field_at_location (EvView *view,
138 /*** Annotations ***/
139 static EvAnnotation *ev_view_get_annotation_at_location (EvView *view,
142 static void show_annotation_windows (EvView *view,
144 static void hide_annotation_windows (EvView *view,
146 /*** GtkWidget implementation ***/
147 static void ev_view_size_request_continuous_dual_page (EvView *view,
148 GtkRequisition *requisition);
149 static void ev_view_size_request_continuous (EvView *view,
150 GtkRequisition *requisition);
151 static void ev_view_size_request_dual_page (EvView *view,
152 GtkRequisition *requisition);
153 static void ev_view_size_request_single_page (EvView *view,
154 GtkRequisition *requisition);
155 static void ev_view_size_request (GtkWidget *widget,
156 GtkRequisition *requisition);
157 static void ev_view_size_allocate (GtkWidget *widget,
158 GtkAllocation *allocation);
159 static gboolean ev_view_scroll_event (GtkWidget *widget,
160 GdkEventScroll *event);
161 static gboolean ev_view_draw (GtkWidget *widget,
163 static gboolean ev_view_popup_menu (GtkWidget *widget);
164 static gboolean ev_view_button_press_event (GtkWidget *widget,
165 GdkEventButton *event);
166 static gboolean ev_view_motion_notify_event (GtkWidget *widget,
167 GdkEventMotion *event);
168 static gboolean ev_view_button_release_event (GtkWidget *widget,
169 GdkEventButton *event);
170 static gboolean ev_view_enter_notify_event (GtkWidget *widget,
171 GdkEventCrossing *event);
172 static gboolean ev_view_leave_notify_event (GtkWidget *widget,
173 GdkEventCrossing *event);
174 static void ev_view_style_set (GtkWidget *widget,
175 GtkStyle *old_style);
176 static void ev_view_remove_all (EvView *view);
178 static AtkObject *ev_view_get_accessible (GtkWidget *widget);
181 static void highlight_find_results (EvView *view,
184 static void highlight_forward_search_results (EvView *view,
187 static void focus_annotation (EvView *view,
191 static void draw_one_page (EvView *view,
194 GdkRectangle *page_area,
196 GdkRectangle *expose_area,
197 gboolean *page_ready);
198 static void show_loading_window (EvView *view);
199 static void hide_loading_window (EvView *view);
200 static void ev_view_reload_page (EvView *view,
202 cairo_region_t *region);
203 static void ev_view_loading_window_move (EvView *view);
206 static void ev_view_change_page (EvView *view,
208 static void job_finished_cb (EvPixbufCache *pixbuf_cache,
209 cairo_region_t *region,
211 static void ev_view_page_changed_cb (EvDocumentModel *model,
215 static void on_adjustment_value_changed (GtkAdjustment *adjustment,
219 static void ev_view_finalize (GObject *object);
220 static void ev_view_dispose (GObject *object);
221 static void ev_view_class_init (EvViewClass *class);
222 static void ev_view_init (EvView *view);
224 /*** Zoom and sizing ***/
225 static double zoom_for_size_fit_width (gdouble doc_width,
229 static double zoom_for_size_fit_height (gdouble doc_width,
233 static double zoom_for_size_best_fit (gdouble doc_width,
237 static void ev_view_zoom_for_size (EvView *view,
240 static void ev_view_zoom_for_size_continuous_and_dual_page (EvView *view,
243 static void ev_view_zoom_for_size_continuous (EvView *view,
246 static void ev_view_zoom_for_size_dual_page (EvView *view,
249 static void ev_view_zoom_for_size_single_page (EvView *view,
253 static void ev_view_set_cursor (EvView *view,
254 EvViewCursor new_cursor);
255 static void ev_view_handle_cursor_over_xy (EvView *view,
260 static gint ev_view_find_get_n_results (EvView *view,
262 static EvRectangle *ev_view_find_get_result (EvView *view,
265 static void jump_to_find_result (EvView *view);
266 static void jump_to_find_page (EvView *view,
267 EvViewFindDirection direction,
270 static void compute_selections (EvView *view,
271 EvSelectionStyle style,
274 static void clear_selection (EvView *view);
275 static void clear_link_selected (EvView *view);
276 static void selection_free (EvViewSelection *selection);
277 static char* get_selected_text (EvView *ev_view);
278 static void ev_view_primary_get_cb (GtkClipboard *clipboard,
279 GtkSelectionData *selection_data,
282 static void ev_view_primary_clear_cb (GtkClipboard *clipboard,
284 static void ev_view_update_primary_selection (EvView *ev_view);
286 G_DEFINE_TYPE_WITH_CODE (EvView, ev_view, GTK_TYPE_FIXED,
287 G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL))
289 /* HeightToPage cache */
290 #define EV_HEIGHT_TO_PAGE_CACHE_KEY "ev-height-to-page-cache"
293 build_height_to_page (EvHeightToPageCache *cache,
294 EvDocument *document,
297 gboolean swap, uniform, dual_even_left;
299 double uniform_height, page_height, next_page_height;
301 gdouble u_width, u_height;
304 swap = (rotation == 90 || rotation == 270);
306 uniform = ev_document_is_page_size_uniform (document);
307 n_pages = ev_document_get_n_pages (document);
308 dual_even_left = (n_pages > 2);
310 g_free (cache->height_to_page);
311 g_free (cache->dual_height_to_page);
313 cache->rotation = rotation;
314 cache->height_to_page = g_new0 (gdouble, n_pages + 1);
315 cache->dual_height_to_page = g_new0 (gdouble, n_pages + 2);
318 ev_document_get_page_size (document, 0, &u_width, &u_height);
321 for (i = 0; i <= n_pages; i++) {
323 uniform_height = swap ? u_width : u_height;
324 cache->height_to_page[i] = i * uniform_height;
329 ev_document_get_page_size (document, i, &w, &h);
330 page_height = swap ? w : h;
334 cache->height_to_page[i] = saved_height;
335 saved_height += page_height;
339 if (dual_even_left && !uniform) {
342 ev_document_get_page_size (document, 0, &w, &h);
343 saved_height = swap ? w : h;
348 for (i = dual_even_left; i < n_pages + 2; i += 2) {
350 uniform_height = swap ? u_width : u_height;
351 cache->dual_height_to_page[i] = ((i + dual_even_left) / 2) * uniform_height;
352 if (i + 1 < n_pages + 2)
353 cache->dual_height_to_page[i + 1] = ((i + dual_even_left) / 2) * uniform_height;
355 if (i + 1 < n_pages) {
358 ev_document_get_page_size (document, i + 1, &w, &h);
359 next_page_height = swap ? w : h;
361 next_page_height = 0;
367 ev_document_get_page_size (document, i, &w, &h);
368 page_height = swap ? w : h;
373 if (i + 1 < n_pages + 2) {
374 cache->dual_height_to_page[i] = saved_height;
375 cache->dual_height_to_page[i + 1] = saved_height;
376 saved_height += MAX(page_height, next_page_height);
378 cache->dual_height_to_page[i] = saved_height;
385 ev_height_to_page_cache_get_height (EvHeightToPageCache *cache,
386 EvDocument *document,
390 gdouble *dual_height)
392 if (cache->rotation != rotation)
393 build_height_to_page (cache, document, rotation);
395 *height = cache->height_to_page[page];
396 *dual_height = cache->dual_height_to_page[page];
400 ev_height_to_page_cache_free (EvHeightToPageCache *cache)
402 if (cache->height_to_page) {
403 g_free (cache->height_to_page);
404 cache->height_to_page = NULL;
407 if (cache->dual_height_to_page) {
408 g_free (cache->dual_height_to_page);
409 cache->dual_height_to_page = NULL;
414 static EvHeightToPageCache *
415 ev_view_get_height_to_page_cache (EvView *view)
417 EvHeightToPageCache *cache;
422 cache = g_object_get_data (G_OBJECT (view->document), EV_HEIGHT_TO_PAGE_CACHE_KEY);
424 cache = g_new0 (EvHeightToPageCache, 1);
425 build_height_to_page (cache, view->document, view->rotation);
426 g_object_set_data_full (G_OBJECT (view->document),
427 EV_HEIGHT_TO_PAGE_CACHE_KEY,
429 (GDestroyNotify)ev_height_to_page_cache_free);
436 ev_view_get_height_to_page (EvView *view,
443 if (!view->height_to_page_cache)
446 ev_height_to_page_cache_get_height (view->height_to_page_cache,
452 *height = (gint)(h * view->scale + 0.5);
455 *dual_height = (gint)(dh * view->scale + 0.5);
459 ev_view_get_scrollbar_size (EvView *view,
460 GtkOrientation orientation)
462 GtkWidget *widget = GTK_WIDGET (view);
464 GtkWidget *swindow = gtk_widget_get_parent (GTK_WIDGET (view));
465 GtkAllocation allocation;
469 if (!GTK_IS_SCROLLED_WINDOW (swindow))
472 gtk_widget_get_allocation (widget, &allocation);
474 if (orientation == GTK_ORIENTATION_VERTICAL) {
475 if (allocation.height >= view->requisition.height)
476 sb = gtk_scrolled_window_get_vscrollbar (GTK_SCROLLED_WINDOW (swindow));
480 if (allocation.width >= view->requisition.width)
481 sb = gtk_scrolled_window_get_hscrollbar (GTK_SCROLLED_WINDOW (swindow));
486 gtk_widget_style_get (swindow, "scrollbar_spacing", &spacing, NULL);
487 gtk_widget_size_request (sb, &req);
489 return (orientation == GTK_ORIENTATION_VERTICAL ? req.width : req.height) + spacing;
493 scroll_to_point (EvView *view,
496 GtkOrientation orientation)
499 gdouble upper, lower;
501 if (orientation == GTK_ORIENTATION_VERTICAL) {
502 page_size = gtk_adjustment_get_page_size (view->vadjustment);
503 upper = gtk_adjustment_get_upper (view->vadjustment);
504 lower = gtk_adjustment_get_lower (view->vadjustment);
506 if (view->continuous) {
507 gtk_adjustment_clamp_page (view->vadjustment,
508 y - view->spacing / 2,
511 gtk_adjustment_set_value (view->vadjustment,
512 CLAMP (y, lower, upper - page_size));
515 page_size = gtk_adjustment_get_page_size (view->hadjustment);
516 upper = gtk_adjustment_get_upper (view->hadjustment);
517 lower = gtk_adjustment_get_lower (view->hadjustment);
519 if (view->dual_page) {
520 gtk_adjustment_clamp_page (view->hadjustment, x,
523 gtk_adjustment_set_value (view->hadjustment,
524 CLAMP (x, lower, upper - page_size));
530 ev_view_scroll_to_page_position (EvView *view, GtkOrientation orientation)
537 if ((orientation == GTK_ORIENTATION_VERTICAL && view->pending_point.y == 0) ||
538 (orientation == GTK_ORIENTATION_HORIZONTAL && view->pending_point.x == 0)) {
539 GdkRectangle page_area;
542 ev_view_get_page_extents (view, view->current_page, &page_area, &border);
548 doc_point_to_view_point (view, view->current_page,
549 &view->pending_point, &view_point);
554 scroll_to_point (view, x, y, orientation);
558 ev_view_set_adjustment_values (EvView *view,
559 GtkOrientation orientation)
561 GtkWidget *widget = GTK_WIDGET (view);
562 GtkAdjustment *adjustment;
563 GtkAllocation allocation;
572 gtk_widget_get_allocation (widget, &allocation);
574 if (orientation == GTK_ORIENTATION_HORIZONTAL) {
575 req_size = view->requisition.width;
576 alloc_size = allocation.width;
577 adjustment = view->hadjustment;
579 req_size = view->requisition.height;
580 alloc_size = allocation.height;
581 adjustment = view->vadjustment;
588 value = gtk_adjustment_get_value (adjustment);
589 upper = gtk_adjustment_get_upper (adjustment);
590 page_size = gtk_adjustment_get_page_size (adjustment);
592 switch (view->pending_scroll) {
593 case SCROLL_TO_KEEP_POSITION:
594 case SCROLL_TO_FIND_LOCATION:
595 factor = value / upper;
597 case SCROLL_TO_PAGE_POSITION:
599 case SCROLL_TO_CENTER:
600 factor = (value + page_size * 0.5) / upper;
604 upper = MAX (alloc_size, req_size);
605 page_size = alloc_size;
607 gtk_adjustment_set_page_size (adjustment, page_size);
608 gtk_adjustment_set_step_increment (adjustment, alloc_size * 0.1);
609 gtk_adjustment_set_page_increment (adjustment, alloc_size * 0.9);
610 gtk_adjustment_set_lower (adjustment, 0);
611 gtk_adjustment_set_upper (adjustment, upper);
614 * We add 0.5 to the values before to average out our rounding errors.
616 switch (view->pending_scroll) {
617 case SCROLL_TO_KEEP_POSITION:
618 case SCROLL_TO_FIND_LOCATION:
619 new_value = CLAMP (upper * factor + 0.5, 0, upper - page_size);
620 gtk_adjustment_set_value (adjustment, (int)new_value);
622 case SCROLL_TO_PAGE_POSITION:
623 ev_view_scroll_to_page_position (view, orientation);
625 case SCROLL_TO_CENTER:
626 new_value = CLAMP (upper * factor - page_size * 0.5 + 0.5,
627 0, upper - page_size);
628 gtk_adjustment_set_value (adjustment, (int)new_value);
632 gtk_adjustment_changed (adjustment);
636 view_update_range_and_current_page (EvView *view)
638 gint start = view->start_page;
639 gint end = view->end_page;
641 if (ev_document_get_n_pages (view->document) <= 0 ||
642 !ev_document_check_dimensions (view->document))
645 if (view->continuous) {
646 GdkRectangle current_area, unused, page_area;
648 gboolean found = FALSE;
649 gint area_max = -1, area;
650 gint best_current_page = -1;
653 if (!(view->vadjustment && view->hadjustment))
656 current_area.x = gtk_adjustment_get_value (view->hadjustment);
657 current_area.width = gtk_adjustment_get_page_size (view->hadjustment);
658 current_area.y = gtk_adjustment_get_value (view->vadjustment);
659 current_area.height = gtk_adjustment_get_page_size (view->vadjustment);
661 for (i = 0; i < ev_document_get_n_pages (view->document); i++) {
663 ev_view_get_page_extents (view, i, &page_area, &border);
665 if (gdk_rectangle_intersect (¤t_area, &page_area, &unused)) {
666 area = unused.width * unused.height;
670 view->start_page = i;
672 best_current_page = i;
674 if (area > area_max) {
675 best_current_page = (area == area_max) ? MIN (i, best_current_page) : i;
681 } else if (found && view->current_page <= view->end_page) {
682 if (view->dual_page && j < 1) {
683 /* In dual mode we stop searching
684 * after two consecutive non-visible pages.
693 if (view->pending_scroll == SCROLL_TO_KEEP_POSITION) {
694 best_current_page = MAX (best_current_page, view->start_page);
696 if (view->current_page != best_current_page) {
697 view->current_page = best_current_page;
698 hide_loading_window (view);
699 ev_document_model_set_page (view->model, best_current_page);
702 } else if (view->dual_page) {
703 if (view->current_page % 2 == get_dual_even_left (view)) {
704 view->start_page = view->current_page;
705 if (view->current_page + 1 < ev_document_get_n_pages (view->document))
706 view->end_page = view->start_page + 1;
708 view->end_page = view->start_page;
710 if (view->current_page < 1)
711 view->start_page = view->current_page;
713 view->start_page = view->current_page - 1;
714 view->end_page = view->current_page;
717 view->start_page = view->current_page;
718 view->end_page = view->current_page;
721 if (view->start_page == -1 || view->end_page == -1)
724 if (start != view->start_page || end != view->end_page) {
727 for (i = start; i < view->start_page && start != -1; i++) {
728 hide_annotation_windows (view, i);
731 for (i = end; i > view->end_page && end != -1; i--) {
732 hide_annotation_windows (view, i);
736 ev_page_cache_set_page_range (view->page_cache,
739 ev_pixbuf_cache_set_page_range (view->pixbuf_cache,
742 view->selection_info.selections);
744 if (ev_pixbuf_cache_get_surface (view->pixbuf_cache, view->current_page))
745 gtk_widget_queue_draw (GTK_WIDGET (view));
749 ev_view_set_scroll_adjustment (EvView *view,
750 GtkOrientation orientation,
751 GtkAdjustment *adjustment)
753 GtkAdjustment **to_set;
754 const gchar *prop_name;
756 if (orientation == GTK_ORIENTATION_HORIZONTAL) {
757 to_set = &view->hadjustment;
758 prop_name = "hadjustment";
760 to_set = &view->vadjustment;
761 prop_name = "vadjustment";
764 if (adjustment && adjustment == *to_set)
768 g_signal_handlers_disconnect_by_func (*to_set,
769 (gpointer) on_adjustment_value_changed,
771 g_object_unref (*to_set);
775 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
776 g_signal_connect (adjustment, "value_changed",
777 G_CALLBACK (on_adjustment_value_changed),
779 *to_set = g_object_ref_sink (adjustment);
780 ev_view_set_adjustment_values (view, orientation);
782 g_object_notify (G_OBJECT (view), prop_name);
786 add_scroll_binding_keypad (GtkBindingSet *binding_set,
788 GdkModifierType modifiers,
789 GtkScrollType scroll,
792 guint keypad_keyval = keyval - GDK_KEY_Left + GDK_KEY_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_LAYERS_STATE: {
1742 GList *show, *hide, *toggle;
1744 EvDocumentLayers *document_layers;
1746 document_layers = EV_DOCUMENT_LAYERS (view->document);
1748 show = ev_link_action_get_show_list (action);
1749 for (l = show; l; l = g_list_next (l)) {
1750 ev_document_layers_show_layer (document_layers, EV_LAYER (l->data));
1753 hide = ev_link_action_get_hide_list (action);
1754 for (l = hide; l; l = g_list_next (l)) {
1755 ev_document_layers_hide_layer (document_layers, EV_LAYER (l->data));
1758 toggle = ev_link_action_get_toggle_list (action);
1759 for (l = toggle; l; l = g_list_next (l)) {
1760 EvLayer *layer = EV_LAYER (l->data);
1762 if (ev_document_layers_layer_is_visible (document_layers, layer)) {
1763 ev_document_layers_hide_layer (document_layers, layer);
1765 ev_document_layers_show_layer (document_layers, layer);
1769 g_signal_emit (view, signals[SIGNAL_LAYERS_CHANGED], 0);
1770 ev_view_reload_page (view, view->current_page, NULL);
1773 case EV_LINK_ACTION_TYPE_GOTO_REMOTE:
1774 case EV_LINK_ACTION_TYPE_EXTERNAL_URI:
1775 case EV_LINK_ACTION_TYPE_LAUNCH:
1776 case EV_LINK_ACTION_TYPE_NAMED:
1777 g_signal_emit (view, signals[SIGNAL_EXTERNAL_LINK], 0, action);
1783 tip_from_action_named (EvLinkAction *action)
1785 const gchar *name = ev_link_action_get_name (action);
1787 if (g_ascii_strcasecmp (name, "FirstPage") == 0) {
1788 return g_strdup (_("Go to first page"));
1789 } else if (g_ascii_strcasecmp (name, "PrevPage") == 0) {
1790 return g_strdup (_("Go to previous page"));
1791 } else if (g_ascii_strcasecmp (name, "NextPage") == 0) {
1792 return g_strdup (_("Go to next page"));
1793 } else if (g_ascii_strcasecmp (name, "LastPage") == 0) {
1794 return g_strdup (_("Go to last page"));
1795 } else if (g_ascii_strcasecmp (name, "GoToPage") == 0) {
1796 return g_strdup (_("Go to page"));
1797 } else if (g_ascii_strcasecmp (name, "Find") == 0) {
1798 return g_strdup (_("Find"));
1805 tip_from_link (EvView *view, EvLink *link)
1807 EvLinkAction *action;
1808 EvLinkActionType type;
1813 action = ev_link_get_action (link);
1814 title = ev_link_get_title (link);
1817 return title ? g_strdup (title) : NULL;
1819 type = ev_link_action_get_action_type (action);
1822 case EV_LINK_ACTION_TYPE_GOTO_DEST:
1823 page_label = ev_document_links_get_dest_page_label (EV_DOCUMENT_LINKS (view->document),
1824 ev_link_action_get_dest (action));
1826 msg = g_strdup_printf (_("Go to page %s"), page_label);
1827 g_free (page_label);
1830 case EV_LINK_ACTION_TYPE_GOTO_REMOTE:
1832 msg = g_strdup_printf (_("Go to %s on file “%s”"), title,
1833 ev_link_action_get_filename (action));
1835 msg = g_strdup_printf (_("Go to file “%s”"),
1836 ev_link_action_get_filename (action));
1839 case EV_LINK_ACTION_TYPE_EXTERNAL_URI:
1840 msg = g_strdup (ev_link_action_get_uri (action));
1842 case EV_LINK_ACTION_TYPE_LAUNCH:
1843 msg = g_strdup_printf (_("Launch %s"),
1844 ev_link_action_get_filename (action));
1846 case EV_LINK_ACTION_TYPE_NAMED:
1847 msg = tip_from_action_named (action);
1851 msg = g_strdup (title);
1859 ev_view_handle_cursor_over_xy (EvView *view, gint x, gint y)
1863 EvAnnotation *annot = NULL;
1865 if (view->cursor == EV_VIEW_CURSOR_HIDDEN)
1868 if (view->adding_annot) {
1869 if (view->cursor != EV_VIEW_CURSOR_ADD)
1870 ev_view_set_cursor (view, EV_VIEW_CURSOR_ADD);
1874 if (view->drag_info.in_drag) {
1875 if (view->cursor != EV_VIEW_CURSOR_DRAG)
1876 ev_view_set_cursor (view, EV_VIEW_CURSOR_DRAG);
1880 if (view->scroll_info.autoscrolling) {
1881 if (view->cursor != EV_VIEW_CURSOR_AUTOSCROLL)
1882 ev_view_set_cursor (view, EV_VIEW_CURSOR_AUTOSCROLL);
1886 link = ev_view_get_link_at_location (view, x, y);
1888 ev_view_set_cursor (view, EV_VIEW_CURSOR_LINK);
1889 } else if ((field = ev_view_get_form_field_at_location (view, x, y))) {
1890 if (field->is_read_only) {
1891 if (view->cursor == EV_VIEW_CURSOR_LINK ||
1892 view->cursor == EV_VIEW_CURSOR_IBEAM ||
1893 view->cursor == EV_VIEW_CURSOR_DRAG)
1894 ev_view_set_cursor (view, EV_VIEW_CURSOR_NORMAL);
1895 } else if (EV_IS_FORM_FIELD_TEXT (field)) {
1896 ev_view_set_cursor (view, EV_VIEW_CURSOR_IBEAM);
1898 ev_view_set_cursor (view, EV_VIEW_CURSOR_LINK);
1900 } else if ((annot = ev_view_get_annotation_at_location (view, x, y))) {
1901 ev_view_set_cursor (view, EV_VIEW_CURSOR_LINK);
1902 } else if (location_in_text (view, x + view->scroll_x, y + view->scroll_y)) {
1903 ev_view_set_cursor (view, EV_VIEW_CURSOR_IBEAM);
1905 if (view->cursor == EV_VIEW_CURSOR_LINK ||
1906 view->cursor == EV_VIEW_CURSOR_IBEAM ||
1907 view->cursor == EV_VIEW_CURSOR_DRAG ||
1908 view->cursor == EV_VIEW_CURSOR_AUTOSCROLL ||
1909 view->cursor == EV_VIEW_CURSOR_ADD)
1910 ev_view_set_cursor (view, EV_VIEW_CURSOR_NORMAL);
1914 g_object_set (view, "has-tooltip", TRUE, NULL);
1919 ev_view_get_image_at_location (EvView *view,
1924 gint x_new = 0, y_new = 0;
1925 EvMappingList *image_mapping;
1927 if (!EV_IS_DOCUMENT_IMAGES (view->document))
1930 if (!get_doc_point_from_location (view, x, y, &page, &x_new, &y_new))
1933 image_mapping = ev_page_cache_get_image_mapping (view->page_cache, page);
1936 return ev_mapping_list_get_data (image_mapping, x_new, y_new);
1942 static EvFormField *
1943 ev_view_get_form_field_at_location (EvView *view,
1948 gint x_new = 0, y_new = 0;
1949 EvMappingList *forms_mapping;
1951 if (!EV_IS_DOCUMENT_FORMS (view->document))
1954 if (!get_doc_point_from_location (view, x, y, &page, &x_new, &y_new))
1957 forms_mapping = ev_page_cache_get_form_field_mapping (view->page_cache, page);
1960 return ev_mapping_list_get_data (forms_mapping, x_new, y_new);
1965 static cairo_region_t *
1966 ev_view_form_field_get_region (EvView *view,
1969 GdkRectangle view_area;
1970 EvMappingList *forms_mapping;
1972 forms_mapping = ev_page_cache_get_form_field_mapping (view->page_cache,
1973 field->page->index);
1974 ev_view_get_area_from_mapping (view, field->page->index,
1978 return cairo_region_create_rectangle (&view_area);
1982 ev_view_forms_remove_widgets (EvView *view)
1984 ev_view_remove_all (view);
1990 ev_view_form_field_destroy (GtkWidget *widget,
1993 g_idle_add ((GSourceFunc)ev_view_forms_remove_widgets, view);
1997 ev_view_form_field_button_create_widget (EvView *view,
2000 EvFormFieldButton *field_button = EV_FORM_FIELD_BUTTON (field);
2001 cairo_region_t *field_region = NULL;
2003 switch (field_button->type) {
2004 case EV_FORM_FIELD_BUTTON_PUSH:
2006 case EV_FORM_FIELD_BUTTON_CHECK:
2007 case EV_FORM_FIELD_BUTTON_RADIO: {
2009 EvMappingList *forms_mapping;
2012 state = ev_document_forms_form_field_button_get_state (EV_DOCUMENT_FORMS (view->document),
2015 /* FIXME: it actually depends on NoToggleToOff flags */
2016 if (field_button->type == EV_FORM_FIELD_BUTTON_RADIO &&
2017 state && field_button->state)
2020 field_region = ev_view_form_field_get_region (view, field);
2022 /* For radio buttons and checkbox buttons that are in a set
2023 * we need to update also the region for the current selected item
2025 forms_mapping = ev_page_cache_get_form_field_mapping (view->page_cache,
2026 field->page->index);
2027 for (l = ev_mapping_list_get_list (forms_mapping); l; l = g_list_next (l)) {
2028 EvFormField *button = ((EvMapping *)(l->data))->data;
2029 cairo_region_t *button_region;
2031 if (button->id == field->id)
2034 /* FIXME: only buttons in the same group should be updated */
2035 if (!EV_IS_FORM_FIELD_BUTTON (button) ||
2036 EV_FORM_FIELD_BUTTON (button)->type != field_button->type ||
2037 EV_FORM_FIELD_BUTTON (button)->state != TRUE)
2040 button_region = ev_view_form_field_get_region (view, button);
2041 cairo_region_union (field_region, button_region);
2042 cairo_region_destroy (button_region);
2045 ev_document_forms_form_field_button_set_state (EV_DOCUMENT_FORMS (view->document),
2047 field_button->state = !state;
2052 ev_view_reload_page (view, field->page->index, field_region);
2053 cairo_region_destroy (field_region);
2059 ev_view_form_field_text_save (EvView *view,
2064 if (!view->document)
2067 field = g_object_get_data (G_OBJECT (widget), "form-field");
2069 if (field->changed) {
2070 EvFormFieldText *field_text = EV_FORM_FIELD_TEXT (field);
2071 cairo_region_t *field_region;
2073 field_region = ev_view_form_field_get_region (view, field);
2075 ev_document_forms_form_field_text_set_text (EV_DOCUMENT_FORMS (view->document),
2076 field, field_text->text);
2077 field->changed = FALSE;
2078 ev_view_reload_page (view, field->page->index, field_region);
2079 cairo_region_destroy (field_region);
2084 ev_view_form_field_text_changed (GtkWidget *widget,
2087 EvFormFieldText *field_text = EV_FORM_FIELD_TEXT (field);
2090 if (GTK_IS_ENTRY (widget)) {
2091 text = g_strdup (gtk_entry_get_text (GTK_ENTRY (widget)));
2092 } else if (GTK_IS_TEXT_BUFFER (widget)) {
2093 GtkTextIter start, end;
2095 gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (widget), &start, &end);
2096 text = gtk_text_buffer_get_text (GTK_TEXT_BUFFER (widget),
2097 &start, &end, FALSE);
2100 if (!field_text->text ||
2101 (field_text->text && g_ascii_strcasecmp (field_text->text, text) != 0)) {
2102 g_free (field_text->text);
2103 field_text->text = text;
2104 field->changed = TRUE;
2109 ev_view_form_field_text_create_widget (EvView *view,
2112 EvFormFieldText *field_text = EV_FORM_FIELD_TEXT (field);
2113 GtkWidget *text = NULL;
2116 txt = ev_document_forms_form_field_text_get_text (EV_DOCUMENT_FORMS (view->document),
2119 switch (field_text->type) {
2120 case EV_FORM_FIELD_TEXT_FILE_SELECT:
2122 case EV_FORM_FIELD_TEXT_NORMAL:
2123 text = gtk_entry_new ();
2124 gtk_entry_set_has_frame (GTK_ENTRY (text), FALSE);
2125 gtk_entry_set_max_length (GTK_ENTRY (text), field_text->max_len);
2126 gtk_entry_set_visibility (GTK_ENTRY (text), !field_text->is_password);
2129 gtk_entry_set_text (GTK_ENTRY (text), txt);
2133 g_signal_connect (text, "changed",
2134 G_CALLBACK (ev_view_form_field_text_changed),
2136 g_signal_connect_after (text, "activate",
2137 G_CALLBACK (ev_view_form_field_destroy),
2140 case EV_FORM_FIELD_TEXT_MULTILINE: {
2141 GtkTextBuffer *buffer;
2143 text = gtk_text_view_new ();
2144 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text));
2147 gtk_text_buffer_set_text (buffer, txt, -1);
2151 g_signal_connect (buffer, "changed",
2152 G_CALLBACK (ev_view_form_field_text_changed),
2158 g_object_weak_ref (G_OBJECT (text),
2159 (GWeakNotify)ev_view_form_field_text_save,
2166 ev_view_form_field_choice_save (EvView *view,
2171 if (!view->document)
2174 field = g_object_get_data (G_OBJECT (widget), "form-field");
2176 if (field->changed) {
2178 EvFormFieldChoice *field_choice = EV_FORM_FIELD_CHOICE (field);
2179 cairo_region_t *field_region;
2181 field_region = ev_view_form_field_get_region (view, field);
2183 if (field_choice->is_editable) {
2184 ev_document_forms_form_field_choice_set_text (EV_DOCUMENT_FORMS (view->document),
2185 field, field_choice->text);
2187 ev_document_forms_form_field_choice_unselect_all (EV_DOCUMENT_FORMS (view->document), field);
2188 for (l = field_choice->selected_items; l; l = g_list_next (l)) {
2189 ev_document_forms_form_field_choice_select_item (EV_DOCUMENT_FORMS (view->document),
2191 GPOINTER_TO_INT (l->data));
2194 field->changed = FALSE;
2195 ev_view_reload_page (view, field->page->index, field_region);
2196 cairo_region_destroy (field_region);
2201 ev_view_form_field_choice_changed (GtkWidget *widget,
2204 EvFormFieldChoice *field_choice = EV_FORM_FIELD_CHOICE (field);
2206 if (GTK_IS_COMBO_BOX (widget)) {
2209 item = gtk_combo_box_get_active (GTK_COMBO_BOX (widget));
2210 if (!field_choice->selected_items ||
2211 GPOINTER_TO_INT (field_choice->selected_items->data) != item) {
2212 g_list_free (field_choice->selected_items);
2213 field_choice->selected_items = NULL;
2214 field_choice->selected_items = g_list_prepend (field_choice->selected_items,
2215 GINT_TO_POINTER (item));
2216 field->changed = TRUE;
2219 if (gtk_combo_box_get_has_entry (GTK_COMBO_BOX (widget))) {
2222 text = gtk_entry_get_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (widget))));
2223 if (!field_choice->text ||
2224 (field_choice->text && g_ascii_strcasecmp (field_choice->text, text) != 0)) {
2225 g_free (field_choice->text);
2226 field_choice->text = g_strdup (text);
2227 field->changed = TRUE;
2230 } else if (GTK_IS_TREE_SELECTION (widget)) {
2231 GtkTreeSelection *selection = GTK_TREE_SELECTION (widget);
2232 GtkTreeModel *model;
2235 items = gtk_tree_selection_get_selected_rows (selection, &model);
2236 g_list_free (field_choice->selected_items);
2237 field_choice->selected_items = NULL;
2239 for (l = items; l && l->data; l = g_list_next (l)) {
2241 GtkTreePath *path = (GtkTreePath *)l->data;
2244 gtk_tree_model_get_iter (model, &iter, path);
2245 gtk_tree_model_get (model, &iter, 1, &item, -1);
2247 field_choice->selected_items = g_list_prepend (field_choice->selected_items,
2248 GINT_TO_POINTER (item));
2250 gtk_tree_path_free (path);
2253 g_list_free (items);
2255 field->changed = TRUE;
2260 ev_view_form_field_choice_create_widget (EvView *view,
2263 EvFormFieldChoice *field_choice = EV_FORM_FIELD_CHOICE (field);
2265 GtkTreeModel *model;
2267 gint selected_item = 0;
2269 n_items = ev_document_forms_form_field_choice_get_n_items (EV_DOCUMENT_FORMS (view->document),
2271 model = GTK_TREE_MODEL (gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT));
2272 for (i = 0; i < n_items; i++) {
2276 item = ev_document_forms_form_field_choice_get_item (EV_DOCUMENT_FORMS (view->document),
2278 if (ev_document_forms_form_field_choice_is_item_selected (
2279 EV_DOCUMENT_FORMS (view->document), field, i)) {
2281 /* FIXME: we need a get_selected_items function in poppler */
2282 field_choice->selected_items = g_list_prepend (field_choice->selected_items,
2283 GINT_TO_POINTER (i));
2287 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
2288 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
2296 if (field_choice->type == EV_FORM_FIELD_CHOICE_LIST) {
2297 GtkCellRenderer *renderer;
2298 GtkWidget *tree_view;
2299 GtkTreeSelection *selection;
2301 tree_view = gtk_tree_view_new_with_model (model);
2302 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tree_view), FALSE);
2304 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
2305 if (field_choice->multi_select) {
2306 gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
2309 /* TODO: set selected items */
2311 renderer = gtk_cell_renderer_text_new ();
2312 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
2318 choice = gtk_scrolled_window_new (NULL, NULL);
2319 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (choice),
2320 GTK_POLICY_AUTOMATIC,
2321 GTK_POLICY_AUTOMATIC);
2322 gtk_container_add (GTK_CONTAINER (choice), tree_view);
2323 gtk_widget_show (tree_view);
2325 g_signal_connect (selection, "changed",
2326 G_CALLBACK (ev_view_form_field_choice_changed),
2328 g_signal_connect_after (selection, "changed",
2329 G_CALLBACK (ev_view_form_field_destroy),
2331 } else if (field_choice->is_editable) { /* ComboBoxEntry */
2334 /* FIXME once gtk bug 633050 is fixed */
2335 choice = g_object_new (GTK_TYPE_COMBO_BOX, "has-entry", TRUE, "model", model, NULL);
2337 text = ev_document_forms_form_field_choice_get_text (EV_DOCUMENT_FORMS (view->document), field);
2339 gtk_entry_set_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (choice))), text);
2343 g_signal_connect (choice, "changed",
2344 G_CALLBACK (ev_view_form_field_choice_changed),
2346 g_signal_connect_after (gtk_bin_get_child (GTK_BIN (choice)),
2348 G_CALLBACK (ev_view_form_field_destroy),
2350 } else { /* ComboBoxText */
2351 GtkCellRenderer *renderer;
2353 choice = gtk_combo_box_new_with_model (model);
2354 renderer = gtk_cell_renderer_text_new ();
2355 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (choice),
2357 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (choice),
2361 gtk_combo_box_set_active (GTK_COMBO_BOX (choice), selected_item);
2362 gtk_combo_box_popup (GTK_COMBO_BOX (choice));
2364 g_signal_connect (choice, "changed",
2365 G_CALLBACK (ev_view_form_field_choice_changed),
2367 g_signal_connect_after (choice, "changed",
2368 G_CALLBACK (ev_view_form_field_destroy),
2372 g_object_unref (model);
2374 g_object_weak_ref (G_OBJECT (choice),
2375 (GWeakNotify)ev_view_form_field_choice_save,
2382 ev_view_handle_form_field (EvView *view,
2387 GtkWidget *field_widget = NULL;
2388 EvMappingList *form_field_mapping;
2389 GdkRectangle view_area;
2391 if (field->is_read_only)
2394 if (EV_IS_FORM_FIELD_BUTTON (field)) {
2395 field_widget = ev_view_form_field_button_create_widget (view, field);
2396 } else if (EV_IS_FORM_FIELD_TEXT (field)) {
2397 field_widget = ev_view_form_field_text_create_widget (view, field);
2398 } else if (EV_IS_FORM_FIELD_CHOICE (field)) {
2399 field_widget = ev_view_form_field_choice_create_widget (view, field);
2400 } else if (EV_IS_FORM_FIELD_SIGNATURE (field)) {
2404 /* Form field doesn't require a widget */
2408 g_object_set_data_full (G_OBJECT (field_widget), "form-field",
2409 g_object_ref (field),
2410 (GDestroyNotify)g_object_unref);
2412 form_field_mapping = ev_page_cache_get_form_field_mapping (view->page_cache,
2413 field->page->index);
2414 ev_view_get_area_from_mapping (view, field->page->index,
2418 gtk_fixed_put (GTK_FIXED (view), field_widget, view_area.x, view_area.y);
2419 gtk_widget_show (field_widget);
2420 gtk_widget_grab_focus (field_widget);
2424 static EvViewWindowChild *
2425 ev_view_get_window_child (EvView *view,
2428 GList *children = view->window_children;
2431 EvViewWindowChild *child;
2433 child = (EvViewWindowChild *)children->data;
2434 children = children->next;
2436 if (child->window == window)
2444 ev_view_window_child_move (EvView *view,
2445 EvViewWindowChild *child,
2449 GtkAllocation allocation;
2452 gtk_widget_get_allocation (GTK_WIDGET (view), &allocation);
2453 gtk_window_get_size (GTK_WINDOW (child->window), &width, &height);
2457 gtk_window_move (GTK_WINDOW (child->window),
2458 CLAMP (x, child->parent_x,
2459 child->parent_x + allocation.width - width),
2460 CLAMP (y, child->parent_y,
2461 child->parent_y + allocation.height - height));
2465 ev_view_window_child_move_with_parent (EvView *view,
2468 EvViewWindowChild *child;
2469 gint root_x, root_y;
2471 child = ev_view_get_window_child (view, window);
2472 gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (view)),
2474 if (root_x != child->parent_x || root_y != child->parent_y) {
2475 gint dest_x, dest_y;
2477 dest_x = child->x + (root_x - child->parent_x);
2478 dest_y = child->y + (root_y - child->parent_y);
2479 child->parent_x = root_x;
2480 child->parent_y = root_y;
2481 ev_view_window_child_move (view, child, dest_x, dest_y);
2484 if (child->visible && !gtk_widget_get_visible (window))
2485 gtk_widget_show (window);
2489 ev_view_window_child_put (EvView *view,
2497 EvViewWindowChild *child;
2498 gint root_x, root_y;
2500 gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (view)),
2503 child = g_new0 (EvViewWindowChild, 1);
2504 child->window = window;
2506 child->orig_x = orig_x;
2507 child->orig_y = orig_y;
2508 child->parent_x = root_x;
2509 child->parent_y = root_y;
2510 child->visible = ev_annotation_window_is_open (EV_ANNOTATION_WINDOW (window));
2511 ev_view_window_child_move (view, child, x + root_x, y + root_y);
2514 gtk_widget_show (window);
2516 gtk_widget_hide (window);
2518 view->window_children = g_list_append (view->window_children, child);
2521 static EvViewWindowChild *
2522 ev_view_find_window_child_for_annot (EvView *view,
2524 EvAnnotation *annot)
2526 GList *children = view->window_children;
2529 EvViewWindowChild *child;
2530 EvAnnotation *wannot;
2532 child = (EvViewWindowChild *)children->data;
2533 children = children->next;
2535 if (child->page != page)
2538 wannot = ev_annotation_window_get_annotation (EV_ANNOTATION_WINDOW (child->window));
2539 if (ev_annotation_equal (wannot, annot))
2547 ev_view_window_children_free (EvView *view)
2551 if (!view->window_children)
2554 for (l = view->window_children; l && l->data; l = g_list_next (l)) {
2555 EvViewWindowChild *child;
2557 child = (EvViewWindowChild *)l->data;
2558 gtk_widget_destroy (GTK_WIDGET (child->window));
2561 g_list_free (view->window_children);
2562 view->window_children = NULL;
2563 view->window_child_focus = NULL;
2567 annotation_window_grab_focus (GtkWidget *widget,
2570 if (view->window_child_focus)
2571 ev_annotation_window_ungrab_focus (EV_ANNOTATION_WINDOW (view->window_child_focus->window));
2572 view->window_child_focus = ev_view_get_window_child (view, widget);
2576 annotation_window_closed (EvAnnotationWindow *window,
2579 EvViewWindowChild *child;
2581 child = ev_view_get_window_child (view, GTK_WIDGET (window));
2582 child->visible = FALSE;
2586 annotation_window_moved (EvAnnotationWindow *window,
2591 EvViewWindowChild *child;
2592 GdkRectangle page_area;
2594 GdkRectangle view_rect;
2595 EvRectangle doc_rect;
2598 child = ev_view_get_window_child (view, GTK_WIDGET (window));
2599 if (child->x == x && child->y == y)
2602 child->moved = TRUE;
2606 /* Window has been moved by the user,
2607 * we have to set a new origin in doc coords
2609 gtk_window_get_size (GTK_WINDOW (window), &width, &height);
2610 view_rect.x = (x - child->parent_x) + view->scroll_x;
2611 view_rect.y = (y - child->parent_y) + view->scroll_y;
2612 view_rect.width = width;
2613 view_rect.height = height;
2615 ev_view_get_page_extents (view, child->page, &page_area, &border);
2616 view_rect_to_doc_rect (view, &view_rect, &page_area, &doc_rect);
2617 child->orig_x = doc_rect.x1;
2618 child->orig_y = doc_rect.y1;
2622 ev_view_annotation_save_contents (EvView *view,
2624 EvAnnotation *annot)
2626 if (!view->document)
2629 ev_document_doc_mutex_lock ();
2630 ev_document_annotations_save_annotation (EV_DOCUMENT_ANNOTATIONS (view->document),
2631 annot, EV_ANNOTATIONS_SAVE_CONTENTS);
2632 ev_document_doc_mutex_unlock ();
2636 ev_view_create_annotation_window (EvView *view,
2637 EvAnnotation *annot,
2641 EvRectangle doc_rect;
2642 GdkRectangle view_rect;
2645 window = ev_annotation_window_new (annot, parent);
2646 g_signal_connect (window, "grab_focus",
2647 G_CALLBACK (annotation_window_grab_focus),
2649 g_signal_connect (window, "closed",
2650 G_CALLBACK (annotation_window_closed),
2652 g_signal_connect (window, "moved",
2653 G_CALLBACK (annotation_window_moved),
2655 g_signal_connect_swapped (annot, "notify::contents",
2656 G_CALLBACK (ev_view_annotation_save_contents),
2658 g_object_set_data (G_OBJECT (annot), "popup", window);
2660 page = ev_annotation_get_page_index (annot);
2661 ev_annotation_window_get_rectangle (EV_ANNOTATION_WINDOW (window), &doc_rect);
2662 doc_rect_to_view_rect (view, page, &doc_rect, &view_rect);
2663 view_rect.x -= view->scroll_x;
2664 view_rect.y -= view->scroll_y;
2666 ev_view_window_child_put (view, window, page,
2667 view_rect.x, view_rect.y,
2668 doc_rect.x1, doc_rect.y1);
2674 show_annotation_windows (EvView *view,
2677 EvMappingList *annots;
2681 parent = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (view)));
2683 annots = ev_page_cache_get_annot_mapping (view->page_cache, page);
2685 for (l = ev_mapping_list_get_list (annots); l && l->data; l = g_list_next (l)) {
2686 EvAnnotation *annot;
2687 EvViewWindowChild *child;
2690 annot = ((EvMapping *)(l->data))->data;
2692 if (!EV_IS_ANNOTATION_MARKUP (annot))
2695 if (!ev_annotation_markup_has_popup (EV_ANNOTATION_MARKUP (annot)))
2698 window = g_object_get_data (G_OBJECT (annot), "popup");
2700 ev_view_window_child_move_with_parent (view, window);
2704 /* Look if we already have a popup for this annot */
2705 child = ev_view_find_window_child_for_annot (view, page, annot);
2706 window = child ? child->window : NULL;
2708 ev_annotation_window_set_annotation (EV_ANNOTATION_WINDOW (window), annot);
2709 g_object_set_data (G_OBJECT (annot), "popup", window);
2710 ev_view_window_child_move_with_parent (view, window);
2712 ev_view_create_annotation_window (view, annot, parent);
2718 hide_annotation_windows (EvView *view,
2721 EvMappingList *annots;
2724 annots = ev_page_cache_get_annot_mapping (view->page_cache, page);
2726 for (l = ev_mapping_list_get_list (annots); l && l->data; l = g_list_next (l)) {
2727 EvAnnotation *annot;
2730 annot = ((EvMapping *)(l->data))->data;
2732 if (!EV_IS_ANNOTATION_MARKUP (annot))
2735 window = g_object_get_data (G_OBJECT (annot), "popup");
2737 gtk_widget_hide (window);
2741 static EvAnnotation *
2742 ev_view_get_annotation_at_location (EvView *view,
2747 gint x_new = 0, y_new = 0;
2748 EvMappingList *annotations_mapping;
2750 if (!EV_IS_DOCUMENT_ANNOTATIONS (view->document))
2753 if (!get_doc_point_from_location (view, x, y, &page, &x_new, &y_new))
2756 annotations_mapping = ev_page_cache_get_annot_mapping (view->page_cache, page);
2758 if (annotations_mapping)
2759 return ev_mapping_list_get_data (annotations_mapping, x_new, y_new);
2765 ev_view_annotation_show_popup_window (EvView *view,
2768 EvViewWindowChild *child;
2773 child = ev_view_get_window_child (view, window);
2774 if (!child->visible) {
2775 child->visible = TRUE;
2776 ev_view_window_child_move (view, child, child->x, child->y);
2777 gtk_widget_show (window);
2782 ev_view_handle_annotation (EvView *view,
2783 EvAnnotation *annot,
2788 if (EV_IS_ANNOTATION_MARKUP (annot)) {
2791 window = g_object_get_data (G_OBJECT (annot), "popup");
2792 ev_view_annotation_show_popup_window (view, window);
2795 if (EV_IS_ANNOTATION_ATTACHMENT (annot)) {
2796 EvAttachment *attachment;
2798 attachment = ev_annotation_attachment_get_attachment (EV_ANNOTATION_ATTACHMENT (annot));
2800 GError *error = NULL;
2802 ev_attachment_open (attachment,
2803 gtk_widget_get_screen (GTK_WIDGET (view)),
2808 g_warning ("%s", error->message);
2809 g_error_free (error);
2816 ev_view_create_annotation (EvView *view,
2817 EvAnnotationType annot_type,
2821 EvAnnotation *annot;
2823 GdkRectangle page_area;
2825 EvRectangle doc_rect, popup_rect;
2827 GdkColor color = { 0, 65535, 65535, 0 };
2828 GdkRectangle view_rect;
2829 cairo_region_t *region;
2833 ev_view_get_page_extents (view, view->current_page, &page_area, &border);
2834 view_point_to_doc_point (view, &point, &page_area,
2835 &doc_rect.x1, &doc_rect.y1);
2836 doc_rect.x2 = doc_rect.x1 + 24;
2837 doc_rect.y2 = doc_rect.y1 + 24;
2839 ev_document_doc_mutex_lock ();
2840 page = ev_document_get_page (view->document, view->current_page);
2841 switch (annot_type) {
2842 case EV_ANNOTATION_TYPE_TEXT:
2843 annot = ev_annotation_text_new (page);
2845 case EV_ANNOTATION_TYPE_ATTACHMENT:
2847 g_object_unref (page);
2848 ev_document_doc_mutex_unlock ();
2851 g_assert_not_reached ();
2853 g_object_unref (page);
2855 ev_annotation_set_color (annot, &color);
2857 if (EV_IS_ANNOTATION_MARKUP (annot)) {
2858 popup_rect.x1 = doc_rect.x2;
2859 popup_rect.x2 = popup_rect.x1 + 200;
2860 popup_rect.y1 = doc_rect.y2;
2861 popup_rect.y2 = popup_rect.y1 + 150;
2862 g_object_set (annot,
2863 "rectangle", &popup_rect,
2865 "popup_is_open", FALSE,
2866 "label", g_get_real_name (),
2870 ev_document_annotations_add_annotation (EV_DOCUMENT_ANNOTATIONS (view->document),
2872 ev_document_doc_mutex_unlock ();
2874 /* If the page didn't have annots, mark the cache as dirty */
2875 if (!ev_page_cache_get_annot_mapping (view->page_cache, view->current_page))
2876 ev_page_cache_mark_dirty (view->page_cache, view->current_page);
2878 if (EV_IS_ANNOTATION_MARKUP (annot)) {
2882 parent = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (view)));
2883 window = ev_view_create_annotation_window (view, annot, parent);
2885 /* Show the annot window the first time */
2886 ev_view_annotation_show_popup_window (view, window);
2889 doc_rect_to_view_rect (view, view->current_page, &doc_rect, &view_rect);
2890 view_rect.x -= view->scroll_x;
2891 view_rect.y -= view->scroll_y;
2892 region = cairo_region_create_rectangle (&view_rect);
2893 ev_view_reload_page (view, view->current_page, region);
2894 cairo_region_destroy (region);
2896 g_signal_emit (view, signals[SIGNAL_ANNOT_ADDED], 0, annot);
2900 ev_view_focus_annotation (EvView *view,
2901 EvMapping *annot_mapping)
2903 GdkRectangle view_rect;
2904 EvAnnotation *annot;
2907 if (!EV_IS_DOCUMENT_ANNOTATIONS (view->document))
2910 if (view->focus_annotation == annot_mapping)
2913 view->focus_annotation = annot_mapping;
2914 annot = (EvAnnotation *)annot_mapping->data;
2916 page = ev_annotation_get_page_index (annot);
2917 ev_document_model_set_page (view->model, page);
2919 doc_rect_to_view_rect (view, page,
2920 &annot_mapping->area, &view_rect);
2921 ensure_rectangle_is_visible (view, &view_rect);
2922 gtk_widget_queue_draw (GTK_WIDGET (view));
2926 ev_view_begin_add_annotation (EvView *view,
2927 EvAnnotationType annot_type)
2929 if (annot_type == EV_ANNOTATION_TYPE_UNKNOWN)
2932 if (view->adding_annot)
2935 view->adding_annot = TRUE;
2936 view->adding_annot_type = annot_type;
2937 ev_view_set_cursor (view, EV_VIEW_CURSOR_ADD);
2941 ev_view_cancel_add_annotation (EvView *view)
2945 if (!view->adding_annot)
2948 view->adding_annot = FALSE;
2949 gtk_widget_get_pointer (GTK_WIDGET (view), &x, &y);
2950 ev_view_handle_cursor_over_xy (view, x, y);
2954 ev_view_synctex_backward_search (EvView *view,
2959 gint x_new = 0, y_new = 0;
2962 if (!ev_document_has_synctex (view->document))
2965 if (!get_doc_point_from_location (view, x, y, &page, &x_new, &y_new))
2968 link = ev_document_synctex_backward_search (view->document, page, x_new, y_new);
2970 g_signal_emit (view, signals[SIGNAL_SYNC_SOURCE], 0, link);
2979 /*** GtkWidget implementation ***/
2982 ev_view_size_request_continuous_dual_page (EvView *view,
2983 GtkRequisition *requisition)
2987 n_pages = ev_document_get_n_pages (view->document) + 1;
2988 get_page_y_offset (view, n_pages, &requisition->height);
2990 switch (view->sizing_mode) {
2991 case EV_SIZING_FIT_WIDTH:
2992 case EV_SIZING_BEST_FIT:
2993 requisition->width = 1;
2996 case EV_SIZING_FREE: {
3000 ev_view_get_max_page_size (view, &max_width, NULL);
3001 compute_border (view, max_width, max_width, &border);
3002 requisition->width = (max_width + border.left + border.right) * 2 + (view->spacing * 3);
3006 g_assert_not_reached ();
3011 ev_view_size_request_continuous (EvView *view,
3012 GtkRequisition *requisition)
3016 n_pages = ev_document_get_n_pages (view->document);
3017 get_page_y_offset (view, n_pages, &requisition->height);
3019 switch (view->sizing_mode) {
3020 case EV_SIZING_FIT_WIDTH:
3021 case EV_SIZING_BEST_FIT:
3022 requisition->width = 1;
3025 case EV_SIZING_FREE: {
3029 ev_view_get_max_page_size (view, &max_width, NULL);
3030 compute_border (view, max_width, max_width, &border);
3031 requisition->width = max_width + (view->spacing * 2) + border.left + border.right;
3035 g_assert_not_reached ();
3040 ev_view_size_request_dual_page (EvView *view,
3041 GtkRequisition *requisition)
3046 if (view->sizing_mode == EV_SIZING_BEST_FIT) {
3047 requisition->width = 1;
3048 requisition->height = 1;
3053 /* Find the largest of the two. */
3054 ev_view_get_page_size (view,
3057 if (view->current_page + 1 < ev_document_get_n_pages (view->document)) {
3058 gint width_2, height_2;
3059 ev_view_get_page_size (view,
3060 view->current_page + 1,
3061 &width_2, &height_2);
3062 if (width_2 > width) {
3067 compute_border (view, width, height, &border);
3069 requisition->width = view->sizing_mode == EV_SIZING_FIT_WIDTH ? 1 :
3070 ((width + border.left + border.right) * 2) + (view->spacing * 3);
3071 requisition->height = (height + border.top + border.bottom) + (view->spacing * 2);
3075 ev_view_size_request_single_page (EvView *view,
3076 GtkRequisition *requisition)
3081 if (view->sizing_mode == EV_SIZING_BEST_FIT) {
3082 requisition->width = 1;
3083 requisition->height = 1;
3088 ev_view_get_page_size (view, view->current_page, &width, &height);
3089 compute_border (view, width, height, &border);
3091 requisition->width = view->sizing_mode == EV_SIZING_FIT_WIDTH ? 1 :
3092 width + border.left + border.right + (2 * view->spacing);
3093 requisition->height = height + border.top + border.bottom + (2 * view->spacing);
3097 ev_view_size_request (GtkWidget *widget,
3098 GtkRequisition *requisition)
3100 EvView *view = EV_VIEW (widget);
3102 if (view->document == NULL) {
3103 view->requisition.width = 1;
3104 view->requisition.height = 1;
3106 *requisition = view->requisition;
3111 /* Get zoom for size here when not called from
3112 * ev_view_size_allocate()
3114 if (!view->internal_size_request &&
3115 (view->sizing_mode == EV_SIZING_FIT_WIDTH ||
3116 view->sizing_mode == EV_SIZING_BEST_FIT)) {
3117 GtkAllocation allocation;
3119 gtk_widget_get_allocation (widget, &allocation);
3120 ev_view_zoom_for_size (view,
3125 if (view->continuous && view->dual_page)
3126 ev_view_size_request_continuous_dual_page (view, &view->requisition);
3127 else if (view->continuous)
3128 ev_view_size_request_continuous (view, &view->requisition);
3129 else if (view->dual_page)
3130 ev_view_size_request_dual_page (view, &view->requisition);
3132 ev_view_size_request_single_page (view, &view->requisition);
3134 *requisition = view->requisition;
3138 ev_view_get_preferred_width (GtkWidget *widget,
3142 GtkRequisition requisition;
3144 ev_view_size_request (widget, &requisition);
3146 *minimum = *natural = requisition.width;
3150 ev_view_get_preferred_height (GtkWidget *widget,
3154 GtkRequisition requisition;
3156 ev_view_size_request (widget, &requisition);
3158 *minimum = *natural = requisition.height;
3162 ev_view_size_allocate (GtkWidget *widget,
3163 GtkAllocation *allocation)
3165 EvView *view = EV_VIEW (widget);
3166 GList *children, *l;
3167 gint root_x, root_y;
3169 GTK_WIDGET_CLASS (ev_view_parent_class)->size_allocate (widget, allocation);
3171 if (!view->document)
3174 if (view->sizing_mode == EV_SIZING_FIT_WIDTH ||
3175 view->sizing_mode == EV_SIZING_BEST_FIT) {
3178 ev_view_zoom_for_size (view,
3180 allocation->height);
3181 view->internal_size_request = TRUE;
3182 ev_view_size_request (widget, &req);
3183 view->internal_size_request = FALSE;
3186 ev_view_set_adjustment_values (view, GTK_ORIENTATION_HORIZONTAL);
3187 ev_view_set_adjustment_values (view, GTK_ORIENTATION_VERTICAL);
3190 view_update_range_and_current_page (view);
3192 view->pending_scroll = SCROLL_TO_KEEP_POSITION;
3193 view->pending_resize = FALSE;
3194 view->pending_point.x = 0;
3195 view->pending_point.y = 0;
3197 children = gtk_container_get_children (GTK_CONTAINER (widget));
3198 for (l = children; l && l->data; l = g_list_next (l)) {
3200 GdkRectangle view_area;
3201 EvMappingList *form_field_mapping;
3202 GtkAllocation child_allocation;
3203 GtkRequisition child_requisition;
3204 GtkWidget *child = (GtkWidget *)l->data;
3206 field = g_object_get_data (G_OBJECT (child), "form-field");
3210 form_field_mapping = ev_page_cache_get_form_field_mapping (view->page_cache,
3211 field->page->index);
3212 ev_view_get_area_from_mapping (view, field->page->index,
3216 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
3217 if (child_requisition.width != view_area.width ||
3218 child_requisition.height != view_area.height)
3219 gtk_widget_set_size_request (child, view_area.width, view_area.height);
3221 gtk_container_child_get (GTK_CONTAINER (widget),
3223 "x", &child_allocation.x,
3224 "y", &child_allocation.y,
3226 if (child_allocation.x != view_area.x ||
3227 child_allocation.y != view_area.y) {
3228 gtk_fixed_move (GTK_FIXED (widget), child, view_area.x, view_area.y);
3231 g_list_free (children);
3233 if (view->window_children)
3234 gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (view)),
3237 for (l = view->window_children; l && l->data; l = g_list_next (l)) {
3238 EvViewWindowChild *child;
3239 EvRectangle doc_rect;
3240 GdkRectangle view_rect;
3242 child = (EvViewWindowChild *)l->data;
3244 ev_annotation_window_get_rectangle (EV_ANNOTATION_WINDOW (child->window), &doc_rect);
3246 doc_rect.x1 = child->orig_x;
3247 doc_rect.y1 = child->orig_y;
3249 doc_rect_to_view_rect (view, child->page, &doc_rect, &view_rect);
3250 view_rect.x -= view->scroll_x;
3251 view_rect.y -= view->scroll_y;
3253 if (view_rect.x != child->orig_x || view_rect.y != child->orig_y) {
3254 child->parent_x = root_x;
3255 child->parent_y = root_y;
3256 ev_view_window_child_move (view, child, view_rect.x + root_x, view_rect.y + root_y);
3262 ev_view_scroll_event (GtkWidget *widget, GdkEventScroll *event)
3264 EvView *view = EV_VIEW (widget);
3267 state = event->state & gtk_accelerator_get_default_mod_mask ();
3269 if (state == GDK_CONTROL_MASK) {
3270 ev_document_model_set_sizing_mode (view->model, EV_SIZING_FREE);
3271 if (event->direction == GDK_SCROLL_UP ||
3272 event->direction == GDK_SCROLL_LEFT) {
3273 if (ev_view_can_zoom_in (view)) {
3274 ev_view_zoom_in (view);
3277 if (ev_view_can_zoom_out (view)) {
3278 ev_view_zoom_out (view);
3285 view->jump_to_find_result = FALSE;
3287 /* Shift+Wheel scrolls the in the perpendicular direction */
3288 if (state & GDK_SHIFT_MASK) {
3289 if (event->direction == GDK_SCROLL_UP)
3290 event->direction = GDK_SCROLL_LEFT;
3291 else if (event->direction == GDK_SCROLL_LEFT)
3292 event->direction = GDK_SCROLL_UP;
3293 else if (event->direction == GDK_SCROLL_DOWN)
3294 event->direction = GDK_SCROLL_RIGHT;
3295 else if (event->direction == GDK_SCROLL_RIGHT)
3296 event->direction = GDK_SCROLL_DOWN;
3298 event->state &= ~GDK_SHIFT_MASK;
3299 state &= ~GDK_SHIFT_MASK;
3302 if (state == 0 && view->sizing_mode == EV_SIZING_BEST_FIT && !view->continuous) {
3303 switch (event->direction) {
3304 case GDK_SCROLL_DOWN:
3305 case GDK_SCROLL_RIGHT:
3306 ev_view_next_page (view);
3309 case GDK_SCROLL_LEFT:
3310 ev_view_previous_page (view);
3320 static EvViewSelection *
3321 find_selection_for_page (EvView *view,
3326 for (list = view->selection_info.selections; list != NULL; list = list->next) {
3327 EvViewSelection *selection;
3329 selection = (EvViewSelection *) list->data;
3331 if (selection->page == page)
3339 ev_view_draw (GtkWidget *widget,
3342 EvView *view = EV_VIEW (widget);
3344 GdkRectangle clip_rect;
3346 if (view->loading) {
3347 show_loading_window (view);
3348 } else if (view->loading_window &&
3349 gtk_widget_get_visible (view->loading_window)) {
3350 ev_view_loading_window_move (view);
3353 if (view->document == NULL)
3356 if (!gdk_cairo_get_clip_rectangle (cr, &clip_rect))
3359 for (i = view->start_page; i >= 0 && i <= view->end_page; i++) {
3360 GdkRectangle page_area;
3362 gboolean page_ready = TRUE;
3364 if (!ev_view_get_page_extents (view, i, &page_area, &border))
3367 page_area.x -= view->scroll_x;
3368 page_area.y -= view->scroll_y;
3370 draw_one_page (view, i, cr, &page_area, &border, &clip_rect, &page_ready);
3372 if (page_ready && view->find_pages && view->highlight_find_results)
3373 highlight_find_results (view, cr, i);
3374 if (page_ready && EV_IS_DOCUMENT_ANNOTATIONS (view->document))
3375 show_annotation_windows (view, i);
3376 if (page_ready && view->focus_annotation)
3377 focus_annotation (view, cr, i, &clip_rect);
3378 if (page_ready && view->synctex_result)
3379 highlight_forward_search_results (view, cr, i);
3382 if (GTK_WIDGET_CLASS (ev_view_parent_class)->draw)
3383 GTK_WIDGET_CLASS (ev_view_parent_class)->draw (widget, cr);
3389 ev_view_do_popup_menu (EvView *view,
3393 GList *items = NULL;
3396 EvAnnotation *annot;
3398 image = ev_view_get_image_at_location (view, x, y);
3400 items = g_list_prepend (items, image);
3402 link = ev_view_get_link_at_location (view, x, y);
3404 items = g_list_prepend (items, link);
3406 annot = ev_view_get_annotation_at_location (view, x, y);
3408 items = g_list_prepend (items, annot);
3410 g_signal_emit (view, signals[SIGNAL_POPUP_MENU], 0, items);
3412 g_list_free (items);
3418 ev_view_popup_menu (GtkWidget *widget)
3422 gtk_widget_get_pointer (widget, &x, &y);
3423 return ev_view_do_popup_menu (EV_VIEW (widget), x, y);
3427 get_link_area (EvView *view,
3433 EvMappingList *link_mapping;
3435 gint x_offset = 0, y_offset = 0;
3437 x += view->scroll_x;
3438 y += view->scroll_y;
3440 find_page_at_location (view, x, y, &page, &x_offset, &y_offset);
3442 link_mapping = ev_page_cache_get_link_mapping (view->page_cache, page);
3443 ev_view_get_area_from_mapping (view, page,
3449 get_annot_area (EvView *view,
3452 EvAnnotation *annot,
3455 EvMappingList *annot_mapping;
3457 gint x_offset = 0, y_offset = 0;
3459 x += view->scroll_x;
3460 y += view->scroll_y;
3462 find_page_at_location (view, x, y, &page, &x_offset, &y_offset);
3464 annot_mapping = ev_page_cache_get_annot_mapping (view->page_cache, page);
3465 ev_view_get_area_from_mapping (view, page,
3471 ev_view_query_tooltip (GtkWidget *widget,
3474 gboolean keyboard_tip,
3475 GtkTooltip *tooltip)
3477 EvView *view = EV_VIEW (widget);
3479 EvAnnotation *annot;
3482 annot = ev_view_get_annotation_at_location (view, x, y);
3484 const gchar *contents;
3486 if ((contents = ev_annotation_get_contents (annot))) {
3487 GdkRectangle annot_area;
3489 get_annot_area (view, x, y, annot, &annot_area);
3490 gtk_tooltip_set_text (tooltip, contents);
3491 gtk_tooltip_set_tip_area (tooltip, &annot_area);
3497 link = ev_view_get_link_at_location (view, x, y);
3501 text = tip_from_link (view, link);
3502 if (text && g_utf8_validate (text, -1, NULL)) {
3503 GdkRectangle link_area;
3505 get_link_area (view, x, y, link, &link_area);
3506 gtk_tooltip_set_text (tooltip, text);
3507 gtk_tooltip_set_tip_area (tooltip, &link_area);
3518 start_selection_for_event (EvView *view,
3519 GdkEventButton *event)
3521 clear_selection (view);
3523 view->selection_info.start.x = event->x + view->scroll_x;
3524 view->selection_info.start.y = event->y + view->scroll_y;
3526 switch (event->type) {
3527 case GDK_2BUTTON_PRESS:
3528 view->selection_info.style = EV_SELECTION_STYLE_WORD;
3530 case GDK_3BUTTON_PRESS:
3531 view->selection_info.style = EV_SELECTION_STYLE_LINE;
3534 view->selection_info.style = EV_SELECTION_STYLE_GLYPH;
3538 /* In case of WORD or LINE, compute selections now */
3539 compute_selections (view,
3540 view->selection_info.style,
3541 &(view->selection_info.start),
3542 &(view->selection_info.start));
3546 ev_view_button_press_event (GtkWidget *widget,
3547 GdkEventButton *event)
3549 EvView *view = EV_VIEW (widget);
3551 if (!view->document)
3554 if (!gtk_widget_has_focus (widget)) {
3555 gtk_widget_grab_focus (widget);
3558 if (view->window_child_focus) {
3559 EvAnnotationWindow *window;
3560 EvAnnotation *annot;
3562 window = EV_ANNOTATION_WINDOW (view->window_child_focus->window);
3563 annot = ev_annotation_window_get_annotation (window);
3564 ev_annotation_window_ungrab_focus (window);
3565 view->window_child_focus = NULL;
3568 view->pressed_button = event->button;
3569 view->selection_info.in_drag = FALSE;
3571 if (view->adding_annot)
3574 if (view->scroll_info.autoscrolling)
3577 switch (event->button) {
3580 EvAnnotation *annot;
3583 if (event->state & GDK_CONTROL_MASK)
3584 return ev_view_synctex_backward_search (view, event->x , event->y);
3586 if (EV_IS_SELECTION (view->document) && view->selection_info.selections) {
3587 if (event->type == GDK_3BUTTON_PRESS) {
3588 start_selection_for_event (view, event);
3589 } else if (location_in_selected_text (view,
3590 event->x + view->scroll_x,
3591 event->y + view->scroll_y)) {
3592 view->selection_info.in_drag = TRUE;
3594 start_selection_for_event (view, event);
3597 gtk_widget_queue_draw (widget);
3598 } else if ((annot = ev_view_get_annotation_at_location (view, event->x, event->y))) {
3599 ev_view_handle_annotation (view, annot, event->x, event->y, event->time);
3600 } else if ((field = ev_view_get_form_field_at_location (view, event->x, event->y))) {
3601 ev_view_remove_all (view);
3602 ev_view_handle_form_field (view, field, event->x, event->y);
3603 } else if (!location_in_text (view, event->x + view->scroll_x, event->y + view->scroll_y) &&
3604 (image = ev_view_get_image_at_location (view, event->x, event->y))) {
3605 if (view->image_dnd_info.image)
3606 g_object_unref (view->image_dnd_info.image);
3607 view->image_dnd_info.image = g_object_ref (image);
3608 view->image_dnd_info.in_drag = TRUE;
3610 view->image_dnd_info.start.x = event->x + view->scroll_x;
3611 view->image_dnd_info.start.y = event->y + view->scroll_y;
3613 ev_view_remove_all (view);
3615 if (view->synctex_result) {
3616 g_free (view->synctex_result);
3617 view->synctex_result = NULL;
3618 gtk_widget_queue_draw (widget);
3621 if (view->focus_annotation)
3622 view->focus_annotation = NULL;
3624 if (EV_IS_SELECTION (view->document))
3625 start_selection_for_event (view, event);
3630 /* use root coordinates as reference point because
3631 * scrolling changes window relative coordinates */
3632 view->drag_info.start.x = event->x_root;
3633 view->drag_info.start.y = event->y_root;
3634 view->drag_info.hadj = gtk_adjustment_get_value (view->hadjustment);
3635 view->drag_info.vadj = gtk_adjustment_get_value (view->vadjustment);
3637 ev_view_set_cursor (view, EV_VIEW_CURSOR_DRAG);
3641 view->scroll_info.start_y = event->y;
3642 return ev_view_do_popup_menu (view, event->x, event->y);
3649 ev_view_remove_all (EvView *view)
3651 GList *children, *child;
3653 children = gtk_container_get_children (GTK_CONTAINER (view));
3654 for (child = children; child && child->data; child = g_list_next (child)) {
3655 gtk_container_remove (GTK_CONTAINER (view),
3656 GTK_WIDGET (child->data));
3658 g_list_free (children);
3661 /*** Drag and Drop ***/
3663 ev_view_drag_data_get (GtkWidget *widget,
3664 GdkDragContext *context,
3665 GtkSelectionData *selection_data,
3669 EvView *view = EV_VIEW (widget);
3672 case TARGET_DND_TEXT:
3673 if (EV_IS_SELECTION (view->document) &&
3674 view->selection_info.selections) {
3677 text = get_selected_text (view);
3678 gtk_selection_data_set_text (selection_data,
3684 case TARGET_DND_IMAGE:
3685 if (view->image_dnd_info.image) {
3688 ev_document_doc_mutex_lock ();
3689 pixbuf = ev_document_images_get_image (EV_DOCUMENT_IMAGES (view->document),
3690 view->image_dnd_info.image);
3691 ev_document_doc_mutex_unlock ();
3693 gtk_selection_data_set_pixbuf (selection_data, pixbuf);
3694 g_object_unref (pixbuf);
3697 case TARGET_DND_URI:
3698 if (view->image_dnd_info.image) {
3700 const gchar *tmp_uri;
3703 ev_document_doc_mutex_lock ();
3704 pixbuf = ev_document_images_get_image (EV_DOCUMENT_IMAGES (view->document),
3705 view->image_dnd_info.image);
3706 ev_document_doc_mutex_unlock ();
3708 tmp_uri = ev_image_save_tmp (view->image_dnd_info.image, pixbuf);
3709 g_object_unref (pixbuf);
3711 uris[0] = (gchar *)tmp_uri;
3713 gtk_selection_data_set_uris (selection_data, uris);
3719 ev_view_drag_motion (GtkWidget *widget,
3720 GdkDragContext *context,
3725 if (gtk_drag_get_source_widget (context) == widget)
3726 gdk_drag_status (context, 0, time);
3728 gdk_drag_status (context, gdk_drag_context_get_suggested_action (context), time);
3734 selection_update_idle_cb (EvView *view)
3736 compute_selections (view,
3737 view->selection_info.style,
3738 &view->selection_info.start,
3740 view->selection_update_id = 0;
3745 selection_scroll_timeout_cb (EvView *view)
3747 gint x, y, shift = 0;
3748 GtkWidget *widget = GTK_WIDGET (view);
3749 GtkAllocation allocation;
3751 gtk_widget_get_allocation (widget, &allocation);
3752 gtk_widget_get_pointer (widget, &x, &y);
3754 if (y > allocation.height) {
3755 shift = (y - allocation.height) / 2;
3761 gtk_adjustment_set_value (view->vadjustment,
3762 CLAMP (gtk_adjustment_get_value (view->vadjustment) + shift,
3763 gtk_adjustment_get_lower (view->vadjustment),
3764 gtk_adjustment_get_upper (view->vadjustment) -
3765 gtk_adjustment_get_page_size (view->vadjustment)));
3767 if (x > allocation.width) {
3768 shift = (x - allocation.width) / 2;
3774 gtk_adjustment_set_value (view->hadjustment,
3775 CLAMP (gtk_adjustment_get_value (view->hadjustment) + shift,
3776 gtk_adjustment_get_lower (view->hadjustment),
3777 gtk_adjustment_get_upper (view->hadjustment) -
3778 gtk_adjustment_get_page_size (view->hadjustment)));
3784 ev_view_drag_update_momentum (EvView *view)
3787 if (!view->drag_info.in_drag)
3790 for (i = DRAG_HISTORY - 1; i > 0; i--) {
3791 view->drag_info.buffer[i].x = view->drag_info.buffer[i-1].x;
3792 view->drag_info.buffer[i].y = view->drag_info.buffer[i-1].y;
3795 /* Momentum is a moving average of 10ms granularity over
3796 * the last 100ms with each 10ms stored in buffer.
3799 view->drag_info.momentum.x = (view->drag_info.buffer[DRAG_HISTORY - 1].x - view->drag_info.buffer[0].x);
3800 view->drag_info.momentum.y = (view->drag_info.buffer[DRAG_HISTORY - 1].y - view->drag_info.buffer[0].y);
3806 ev_view_scroll_drag_release (EvView *view)
3808 gdouble dhadj_value, dvadj_value;
3809 gdouble oldhadjustment, oldvadjustment;
3810 gdouble h_page_size, v_page_size;
3811 gdouble h_upper, v_upper;
3812 GtkAllocation allocation;
3814 view->drag_info.momentum.x /= 1.2;
3815 view->drag_info.momentum.y /= 1.2; /* Alter these constants to change "friction" */
3817 gtk_widget_get_allocation (GTK_WIDGET (view), &allocation);
3819 h_page_size = gtk_adjustment_get_page_size (view->hadjustment);
3820 v_page_size = gtk_adjustment_get_page_size (view->vadjustment);
3822 dhadj_value = h_page_size *
3823 (gdouble)view->drag_info.momentum.x / allocation.width;
3824 dvadj_value = v_page_size *
3825 (gdouble)view->drag_info.momentum.y / allocation.height;
3827 oldhadjustment = gtk_adjustment_get_value (view->hadjustment);
3828 oldvadjustment = gtk_adjustment_get_value (view->vadjustment);
3830 h_upper = gtk_adjustment_get_upper (view->hadjustment);
3831 v_upper = gtk_adjustment_get_upper (view->vadjustment);
3833 /* When we reach the edges, we need either to absorb some momentum and bounce by
3834 * multiplying it on -0.5 or stop scrolling by setting momentum to 0. */
3835 if (((oldhadjustment + dhadj_value) > (h_upper - h_page_size)) ||
3836 ((oldhadjustment + dhadj_value) < 0))
3837 view->drag_info.momentum.x = 0;
3838 if (((oldvadjustment + dvadj_value) > (v_upper - v_page_size)) ||
3839 ((oldvadjustment + dvadj_value) < 0))
3840 view->drag_info.momentum.y = 0;
3842 gtk_adjustment_set_value (view->hadjustment,
3843 MIN (oldhadjustment + dhadj_value,
3844 h_upper - h_page_size));
3845 gtk_adjustment_set_value (view->vadjustment,
3846 MIN (oldvadjustment + dvadj_value,
3847 v_upper - v_page_size));
3849 if (((view->drag_info.momentum.x < 1) && (view->drag_info.momentum.x > -1)) &&
3850 ((view->drag_info.momentum.y < 1) && (view->drag_info.momentum.y > -1)))
3857 ev_view_motion_notify_event (GtkWidget *widget,
3858 GdkEventMotion *event)
3860 EvView *view = EV_VIEW (widget);
3864 if (!view->document)
3867 window = gtk_widget_get_window (widget);
3869 if (event->is_hint || event->window != window) {
3870 gtk_widget_get_pointer (widget, &x, &y);
3876 if (view->scroll_info.autoscrolling) {
3877 view->scroll_info.last_y = y;
3881 if (view->selection_info.in_drag) {
3882 if (gtk_drag_check_threshold (widget,
3883 view->selection_info.start.x,
3884 view->selection_info.start.y,
3886 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
3888 gtk_target_list_add_text_targets (target_list, TARGET_DND_TEXT);
3890 gtk_drag_begin (widget, target_list,
3892 1, (GdkEvent *)event);
3894 view->selection_info.in_drag = FALSE;
3896 gtk_target_list_unref (target_list);
3900 } else if (view->image_dnd_info.in_drag) {
3901 if (gtk_drag_check_threshold (widget,
3902 view->selection_info.start.x,
3903 view->selection_info.start.y,
3905 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
3907 gtk_target_list_add_uri_targets (target_list, TARGET_DND_URI);
3908 gtk_target_list_add_image_targets (target_list, TARGET_DND_IMAGE, TRUE);
3910 gtk_drag_begin (widget, target_list,
3912 1, (GdkEvent *)event);
3914 view->image_dnd_info.in_drag = FALSE;
3916 gtk_target_list_unref (target_list);
3922 switch (view->pressed_button) {
3924 /* For the Evince 0.4.x release, we limit selection to un-rotated
3927 if (view->rotation != 0)
3930 /* Schedule timeout to scroll during selection and additionally
3931 * scroll once to allow arbitrary speed. */
3932 if (!view->selection_scroll_id)
3933 view->selection_scroll_id = g_timeout_add (SCROLL_TIME,
3934 (GSourceFunc)selection_scroll_timeout_cb,
3937 selection_scroll_timeout_cb (view);
3939 view->selection_info.in_selection = TRUE;
3940 view->motion.x = x + view->scroll_x;
3941 view->motion.y = y + view->scroll_y;
3943 /* Queue an idle to handle the motion. We do this because
3944 * handling any selection events in the motion could be slower
3945 * than new motion events reach us. We always put it in the
3946 * idle to make sure we catch up and don't visibly lag the
3948 if (!view->selection_update_id)
3949 view->selection_update_id = g_idle_add ((GSourceFunc)selection_update_idle_cb, view);
3953 if (!view->drag_info.in_drag) {
3957 start = gtk_drag_check_threshold (widget,
3958 view->drag_info.start.x,
3959 view->drag_info.start.y,
3962 view->drag_info.in_drag = start;
3963 view->drag_info.drag_timeout_id = g_timeout_add (10,
3964 (GSourceFunc)ev_view_drag_update_momentum, view);
3965 /* Set 100 to choose how long it takes to build up momentum */
3966 /* Clear out previous momentum info: */
3967 for (i = 0; i < DRAG_HISTORY; i++) {
3968 view->drag_info.buffer[i].x = event->x;
3969 view->drag_info.buffer[i].y = event->y;
3971 view->drag_info.momentum.x = 0;
3972 view->drag_info.momentum.y = 0;
3975 if (view->drag_info.in_drag) {
3977 gdouble dhadj_value, dvadj_value;
3978 GtkAllocation allocation;
3980 view->drag_info.buffer[0].x = event->x;
3981 view->drag_info.buffer[0].y = event->y;
3983 dx = event->x_root - view->drag_info.start.x;
3984 dy = event->y_root - view->drag_info.start.y;
3986 gtk_widget_get_allocation (widget, &allocation);
3988 dhadj_value = gtk_adjustment_get_page_size (view->hadjustment) *
3989 (gdouble)dx / allocation.width;
3990 dvadj_value = gtk_adjustment_get_page_size (view->vadjustment) *
3991 (gdouble)dy / allocation.height;
3993 /* clamp scrolling to visible area */
3994 gtk_adjustment_set_value (view->hadjustment,
3995 MIN (view->drag_info.hadj - dhadj_value,
3996 gtk_adjustment_get_upper (view->hadjustment) -
3997 gtk_adjustment_get_page_size (view->hadjustment)));
3998 gtk_adjustment_set_value (view->vadjustment,
3999 MIN (view->drag_info.vadj - dvadj_value,
4000 gtk_adjustment_get_upper (view->vadjustment) -
4001 gtk_adjustment_get_page_size (view->vadjustment)));
4008 ev_view_handle_cursor_over_xy (view, x, y);
4015 ev_view_button_release_event (GtkWidget *widget,
4016 GdkEventButton *event)
4018 EvView *view = EV_VIEW (widget);
4019 EvLink *link = NULL;
4021 view->image_dnd_info.in_drag = FALSE;
4023 if (view->scroll_info.autoscrolling) {
4024 ev_view_autoscroll_stop (view);
4025 view->pressed_button = -1;
4030 if (view->pressed_button == 1 && event->state & GDK_CONTROL_MASK) {
4031 view->pressed_button = -1;
4035 if (view->drag_info.in_drag) {
4036 view->drag_info.release_timeout_id =
4038 (GSourceFunc)ev_view_scroll_drag_release, view);
4041 if (view->document && !view->drag_info.in_drag && view->pressed_button != 3) {
4042 link = ev_view_get_link_at_location (view, event->x, event->y);
4045 view->drag_info.in_drag = FALSE;
4047 if (view->adding_annot && view->pressed_button == 1) {
4048 view->adding_annot = FALSE;
4049 ev_view_handle_cursor_over_xy (view, event->x, event->y);
4050 view->pressed_button = -1;
4052 ev_view_create_annotation (view,
4053 view->adding_annot_type,
4054 event->x + view->scroll_x,
4055 event->y + view->scroll_y);
4060 if (view->pressed_button == 2) {
4061 ev_view_handle_cursor_over_xy (view, event->x, event->y);
4064 view->pressed_button = -1;
4066 if (view->selection_scroll_id) {
4067 g_source_remove (view->selection_scroll_id);
4068 view->selection_scroll_id = 0;
4070 if (view->selection_update_id) {
4071 g_source_remove (view->selection_update_id);
4072 view->selection_update_id = 0;
4075 if (view->selection_info.selections) {
4076 clear_link_selected (view);
4077 ev_view_update_primary_selection (view);
4079 if (view->selection_info.in_drag) {
4080 clear_selection (view);
4081 gtk_widget_queue_draw (widget);
4084 view->selection_info.in_drag = FALSE;
4086 if (event->button == 2) {
4087 EvLinkAction *action;
4088 EvLinkActionType type;
4090 action = ev_link_get_action (link);
4094 type = ev_link_action_get_action_type (action);
4095 if (type == EV_LINK_ACTION_TYPE_GOTO_DEST) {
4096 g_signal_emit (view,
4097 signals[SIGNAL_EXTERNAL_LINK],
4101 ev_view_handle_link (view, link);
4109 ev_view_key_press_event (GtkWidget *widget,
4112 EvView *view = EV_VIEW (widget);
4114 if (!view->document)
4117 if (!gtk_widget_has_focus (widget)) {
4118 /* Forward key events to current focused window child */
4119 if (view->window_child_focus) {
4120 GdkEventKey *new_event;
4123 new_event = (GdkEventKey *) gdk_event_copy ((GdkEvent *)event);
4124 g_object_unref (new_event->window);
4125 new_event->window = gtk_widget_get_window (view->window_child_focus->window);
4126 if (new_event->window)
4127 g_object_ref (new_event->window);
4128 gtk_widget_realize (view->window_child_focus->window);
4129 handled = gtk_widget_event (view->window_child_focus->window, (GdkEvent *)new_event);
4130 gdk_event_free ((GdkEvent *)new_event);
4138 return gtk_bindings_activate_event (G_OBJECT (widget), event);
4142 ev_view_focus_in (GtkWidget *widget,
4143 GdkEventFocus *event)
4145 if (EV_VIEW (widget)->pixbuf_cache)
4146 ev_pixbuf_cache_style_changed (EV_VIEW (widget)->pixbuf_cache);
4147 gtk_widget_queue_draw (widget);
4153 ev_view_focus_out (GtkWidget *widget,
4154 GdkEventFocus *event)
4156 if (EV_VIEW (widget)->pixbuf_cache)
4157 ev_pixbuf_cache_style_changed (EV_VIEW (widget)->pixbuf_cache);
4158 gtk_widget_queue_draw (widget);
4164 ev_view_leave_notify_event (GtkWidget *widget, GdkEventCrossing *event)
4166 EvView *view = EV_VIEW (widget);
4168 if (view->cursor != EV_VIEW_CURSOR_NORMAL)
4169 ev_view_set_cursor (view, EV_VIEW_CURSOR_NORMAL);
4175 ev_view_enter_notify_event (GtkWidget *widget, GdkEventCrossing *event)
4177 EvView *view = EV_VIEW (widget);
4179 ev_view_handle_cursor_over_xy (view, event->x, event->y);
4185 ev_view_style_set (GtkWidget *widget,
4186 GtkStyle *old_style)
4188 if (EV_VIEW (widget)->pixbuf_cache)
4189 ev_pixbuf_cache_style_changed (EV_VIEW (widget)->pixbuf_cache);
4191 GTK_WIDGET_CLASS (ev_view_parent_class)->style_set (widget, old_style);
4197 draw_rubberband (EvView *view,
4199 const GdkRectangle *rect,
4203 const GdkColor *fill_color_gdk;
4206 style = gtk_widget_get_style (GTK_WIDGET (view));
4207 fill_color_gdk = &style->base[GTK_STATE_SELECTED];
4208 r = fill_color_gdk->red / 65535.;
4209 g = fill_color_gdk->green / 65535.;
4210 b = fill_color_gdk->blue / 65535.;
4214 cairo_set_source_rgba (cr, r, g, b, alpha);
4215 cairo_rectangle (cr,
4216 rect->x - view->scroll_x,
4217 rect->y - view->scroll_y,
4218 rect->width, rect->height);
4219 cairo_fill_preserve (cr);
4221 cairo_set_line_width (cr, 0.5);
4222 cairo_set_source_rgb (cr, r, g, b);
4230 highlight_find_results (EvView *view,
4234 gint i, n_results = 0;
4235 n_results = ev_view_find_get_n_results (view, page);
4237 for (i = 0; i < n_results; i++) {
4238 EvRectangle *rectangle;
4239 GdkRectangle view_rectangle;
4242 if (i == view->find_result && page == view->current_page) {
4248 rectangle = ev_view_find_get_result (view, page, i);
4249 doc_rect_to_view_rect (view, page, rectangle, &view_rectangle);
4250 draw_rubberband (view, cr, &view_rectangle, alpha);
4255 highlight_forward_search_results (EvView *view,
4260 EvMapping *mapping = view->synctex_result;
4262 if (GPOINTER_TO_INT (mapping->data) != page)
4265 doc_rect_to_view_rect (view, page, &mapping->area, &rect);
4268 cairo_set_source_rgb (cr, 1., 0., 0.);
4269 cairo_rectangle (cr,
4270 rect.x - view->scroll_x,
4271 rect.y - view->scroll_y,
4272 rect.width, rect.height);
4278 focus_annotation (EvView *view,
4283 GtkWidget *widget = GTK_WIDGET (view);
4285 EvMapping *mapping = view->focus_annotation;
4286 EvAnnotation *annot = (EvAnnotation *)mapping->data;
4288 if (ev_annotation_get_page_index (annot) != page)
4291 doc_rect_to_view_rect (view, page, &mapping->area, &rect);
4293 gtk_paint_focus (gtk_widget_get_style (widget),
4295 gtk_widget_get_state (widget),
4297 rect.x - view->scroll_x,
4298 rect.y - view->scroll_y,
4299 rect.width + 1, rect.height + 1);
4303 ev_view_loading_window_move (EvView *view)
4305 GtkWidget *widget = GTK_WIDGET (view);
4306 EvLoadingWindow *window = EV_LOADING_WINDOW (view->loading_window);
4307 gint root_x, root_y;
4309 GtkAllocation allocation;
4311 gtk_widget_get_allocation (widget, &allocation);
4312 gdk_window_get_origin (gtk_widget_get_window (widget), &root_x, &root_y);
4313 ev_loading_window_get_size (window, &window_width, NULL);
4315 root_x += allocation.width - window_width - 10;
4318 ev_loading_window_move (window, root_x, root_y);
4322 show_loading_window_cb (EvView *view)
4324 if (!view->loading_window) {
4328 parent = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (view)));
4329 view->loading_window = ev_loading_window_new (parent);
4331 /* Show the window off screen to get a valid size asap */
4332 screen = gtk_widget_get_screen (GTK_WIDGET (view));
4333 gtk_window_move (GTK_WINDOW (view->loading_window),
4334 gdk_screen_get_width (screen) + 1,
4335 gdk_screen_get_height (screen) + 1);
4336 gtk_widget_show (view->loading_window);
4339 ev_view_loading_window_move (view);
4341 gtk_widget_show (view->loading_window);
4343 view->loading_timeout = 0;
4349 show_loading_window (EvView *view)
4351 if (view->loading_window && gtk_widget_get_visible (view->loading_window)) {
4352 ev_view_loading_window_move (view);
4356 if (!view->loading_timeout) {
4357 view->loading_timeout =
4358 g_timeout_add_full (G_PRIORITY_LOW,
4359 0.5, (GSourceFunc)show_loading_window_cb,
4365 hide_loading_window (EvView *view)
4367 if (view->loading_timeout) {
4368 g_source_remove (view->loading_timeout);
4369 view->loading_timeout = 0;
4372 if (view->loading_window && gtk_widget_get_visible (view->loading_window)) {
4373 gtk_widget_hide (view->loading_window);
4378 draw_one_page (EvView *view,
4381 GdkRectangle *page_area,
4383 GdkRectangle *expose_area,
4384 gboolean *page_ready)
4386 GdkRectangle overlap;
4387 GdkRectangle real_page_area;
4389 gboolean inverted_colors;
4391 g_assert (view->document);
4393 if (! gdk_rectangle_intersect (page_area, expose_area, &overlap))
4396 /* Render the document itself */
4397 real_page_area = *page_area;
4399 real_page_area.x += border->left;
4400 real_page_area.y += border->top;
4401 real_page_area.width -= (border->left + border->right);
4402 real_page_area.height -= (border->top + border->bottom);
4405 current_page = ev_document_model_get_page (view->model);
4406 inverted_colors = ev_document_model_get_inverted_colors (view->model);
4407 ev_document_misc_paint_one_page (cr,
4410 page == current_page,
4413 if (gdk_rectangle_intersect (&real_page_area, expose_area, &overlap)) {
4415 gint page_width, page_height;
4416 cairo_surface_t *page_surface = NULL;
4417 gint selection_width, selection_height;
4418 cairo_surface_t *selection_surface = NULL;
4420 page_surface = ev_pixbuf_cache_get_surface (view->pixbuf_cache, page);
4422 if (!page_surface) {
4423 if (page == current_page)
4424 show_loading_window (view);
4426 *page_ready = FALSE;
4431 if (page == current_page)
4432 hide_loading_window (view);
4434 ev_view_get_page_size (view, page, &width, &height);
4436 page_width = cairo_image_surface_get_width (page_surface);
4437 page_height = cairo_image_surface_get_height (page_surface);
4440 cairo_translate (cr, overlap.x, overlap.y);
4442 if (width != page_width || height != page_height) {
4443 cairo_pattern_set_filter (cairo_get_source (cr),
4446 (gdouble)width / page_width,
4447 (gdouble)height / page_height);
4450 cairo_surface_set_device_offset (page_surface,
4451 overlap.x - real_page_area.x,
4452 overlap.y - real_page_area.y);
4453 cairo_set_source_surface (cr, page_surface, 0, 0);
4457 /* Get the selection pixbuf iff we have something to draw */
4458 if (find_selection_for_page (view, page) &&
4459 view->selection_mode == EV_VIEW_SELECTION_TEXT) {
4461 ev_pixbuf_cache_get_selection_surface (view->pixbuf_cache,
4467 if (!selection_surface) {
4471 selection_width = cairo_image_surface_get_width (selection_surface);
4472 selection_height = cairo_image_surface_get_height (selection_surface);
4475 cairo_translate (cr, overlap.x, overlap.y);
4477 if (width != selection_width || height != selection_height) {
4478 cairo_pattern_set_filter (cairo_get_source (cr),
4481 (gdouble)width / selection_width,
4482 (gdouble)height / selection_height);
4485 cairo_surface_set_device_offset (selection_surface,
4486 overlap.x - real_page_area.x,
4487 overlap.y - real_page_area.y);
4489 cairo_set_source_surface (cr, selection_surface, 0, 0);
4495 /*** GObject functions ***/
4498 ev_view_finalize (GObject *object)
4500 EvView *view = EV_VIEW (object);
4502 clear_selection (view);
4503 clear_link_selected (view);
4505 if (view->synctex_result) {
4506 g_free (view->synctex_result);
4507 view->synctex_result = NULL;
4510 if (view->image_dnd_info.image)
4511 g_object_unref (view->image_dnd_info.image);
4512 view->image_dnd_info.image = NULL;
4514 G_OBJECT_CLASS (ev_view_parent_class)->finalize (object);
4518 ev_view_dispose (GObject *object)
4520 EvView *view = EV_VIEW (object);
4523 g_object_unref (view->model);
4527 if (view->pixbuf_cache) {
4528 g_object_unref (view->pixbuf_cache);
4529 view->pixbuf_cache = NULL;
4532 if (view->document) {
4533 g_object_unref (view->document);
4534 view->document = NULL;
4537 if (view->page_cache) {
4538 g_object_unref (view->page_cache);
4539 view->page_cache = NULL;
4542 ev_view_window_children_free (view);
4544 if (view->selection_scroll_id) {
4545 g_source_remove (view->selection_scroll_id);
4546 view->selection_scroll_id = 0;
4549 if (view->selection_update_id) {
4550 g_source_remove (view->selection_update_id);
4551 view->selection_update_id = 0;
4554 if (view->scroll_info.timeout_id) {
4555 g_source_remove (view->scroll_info.timeout_id);
4556 view->scroll_info.timeout_id = 0;
4559 if (view->drag_info.drag_timeout_id) {
4560 g_source_remove (view->drag_info.drag_timeout_id);
4561 view->drag_info.drag_timeout_id = 0;
4564 if (view->drag_info.release_timeout_id) {
4565 g_source_remove (view->drag_info.release_timeout_id);
4566 view->drag_info.release_timeout_id = 0;
4569 if (view->loading_timeout) {
4570 g_source_remove (view->loading_timeout);
4571 view->loading_timeout = 0;
4574 gtk_scrollable_set_hadjustment (GTK_SCROLLABLE (view), NULL);
4575 gtk_scrollable_set_vadjustment (GTK_SCROLLABLE (view), NULL);
4577 G_OBJECT_CLASS (ev_view_parent_class)->dispose (object);
4581 ev_view_get_property (GObject *object,
4586 EvView *view = EV_VIEW (object);
4589 case PROP_HADJUSTMENT:
4590 g_value_set_object (value, view->hadjustment);
4592 case PROP_VADJUSTMENT:
4593 g_value_set_object (value, view->vadjustment);
4595 case PROP_HSCROLL_POLICY:
4596 g_value_set_enum (value, view->hscroll_policy);
4598 case PROP_VSCROLL_POLICY:
4599 g_value_set_enum (value, view->vscroll_policy);
4602 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
4608 ev_view_set_property (GObject *object,
4610 const GValue *value,
4613 EvView *view = EV_VIEW (object);
4616 case PROP_HADJUSTMENT:
4617 ev_view_set_scroll_adjustment (view, GTK_ORIENTATION_HORIZONTAL,
4618 (GtkAdjustment *) g_value_get_object (value));
4620 case PROP_VADJUSTMENT:
4621 ev_view_set_scroll_adjustment (view, GTK_ORIENTATION_VERTICAL,
4622 (GtkAdjustment *) g_value_get_object (value));
4624 case PROP_HSCROLL_POLICY:
4625 view->hscroll_policy = g_value_get_enum (value);
4626 gtk_widget_queue_resize (GTK_WIDGET (view));
4628 case PROP_VSCROLL_POLICY:
4629 view->vscroll_policy = g_value_get_enum (value);
4630 gtk_widget_queue_resize (GTK_WIDGET (view));
4633 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
4639 ev_view_get_accessible (GtkWidget *widget)
4641 static gboolean first_time = TRUE;
4644 AtkObjectFactory *factory;
4645 AtkRegistry *registry;
4647 GType derived_atk_type;
4650 * Figure out whether accessibility is enabled by looking at the
4651 * type of the accessible object which would be created for
4652 * the parent type of EvView.
4654 derived_type = g_type_parent (EV_TYPE_VIEW);
4656 registry = atk_get_default_registry ();
4657 factory = atk_registry_get_factory (registry,
4659 derived_atk_type = atk_object_factory_get_accessible_type (factory);
4660 if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE)) {
4661 atk_registry_set_factory_type (registry,
4663 ev_view_accessible_factory_get_type ());
4664 EV_VIEW (widget)->a11y_enabled = TRUE;
4668 return GTK_WIDGET_CLASS (ev_view_parent_class)->get_accessible (widget);
4672 ev_view_class_init (EvViewClass *class)
4674 GObjectClass *object_class = G_OBJECT_CLASS (class);
4675 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
4676 GtkBindingSet *binding_set;
4678 object_class->get_property = ev_view_get_property;
4679 object_class->set_property = ev_view_set_property;
4680 object_class->dispose = ev_view_dispose;
4681 object_class->finalize = ev_view_finalize;
4683 widget_class->draw = ev_view_draw;
4684 widget_class->button_press_event = ev_view_button_press_event;
4685 widget_class->motion_notify_event = ev_view_motion_notify_event;
4686 widget_class->button_release_event = ev_view_button_release_event;
4687 widget_class->key_press_event = ev_view_key_press_event;
4688 widget_class->focus_in_event = ev_view_focus_in;
4689 widget_class->focus_out_event = ev_view_focus_out;
4690 widget_class->get_accessible = ev_view_get_accessible;
4691 widget_class->get_preferred_width = ev_view_get_preferred_width;
4692 widget_class->get_preferred_height = ev_view_get_preferred_height;
4693 widget_class->size_allocate = ev_view_size_allocate;
4694 widget_class->scroll_event = ev_view_scroll_event;
4695 widget_class->enter_notify_event = ev_view_enter_notify_event;
4696 widget_class->leave_notify_event = ev_view_leave_notify_event;
4697 widget_class->style_set = ev_view_style_set;
4698 widget_class->drag_data_get = ev_view_drag_data_get;
4699 widget_class->drag_motion = ev_view_drag_motion;
4700 widget_class->popup_menu = ev_view_popup_menu;
4701 widget_class->query_tooltip = ev_view_query_tooltip;
4703 class->binding_activated = ev_view_scroll;
4705 /* Scrollable interface */
4706 g_object_class_override_property (object_class, PROP_HADJUSTMENT, "hadjustment");
4707 g_object_class_override_property (object_class, PROP_VADJUSTMENT, "vadjustment");
4708 g_object_class_override_property (object_class, PROP_HSCROLL_POLICY, "hscroll-policy");
4709 g_object_class_override_property (object_class, PROP_VSCROLL_POLICY, "vscroll-policy");
4711 signals[SIGNAL_BINDING_ACTIVATED] = g_signal_new ("binding_activated",
4712 G_TYPE_FROM_CLASS (object_class),
4713 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
4714 G_STRUCT_OFFSET (EvViewClass, binding_activated),
4716 ev_view_marshal_VOID__ENUM_BOOLEAN,
4718 GTK_TYPE_SCROLL_TYPE,
4720 signals[SIGNAL_HANDLE_LINK] = g_signal_new ("handle-link",
4721 G_TYPE_FROM_CLASS (object_class),
4722 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
4723 G_STRUCT_OFFSET (EvViewClass, handle_link),
4725 g_cclosure_marshal_VOID__OBJECT,
4728 signals[SIGNAL_EXTERNAL_LINK] = g_signal_new ("external-link",
4729 G_TYPE_FROM_CLASS (object_class),
4730 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
4731 G_STRUCT_OFFSET (EvViewClass, external_link),
4733 g_cclosure_marshal_VOID__OBJECT,
4736 signals[SIGNAL_POPUP_MENU] = g_signal_new ("popup",
4737 G_TYPE_FROM_CLASS (object_class),
4738 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
4739 G_STRUCT_OFFSET (EvViewClass, popup_menu),
4741 g_cclosure_marshal_VOID__POINTER,
4744 signals[SIGNAL_SELECTION_CHANGED] = g_signal_new ("selection-changed",
4745 G_TYPE_FROM_CLASS (object_class),
4746 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
4747 G_STRUCT_OFFSET (EvViewClass, selection_changed),
4749 g_cclosure_marshal_VOID__VOID,
4752 signals[SIGNAL_SYNC_SOURCE] = g_signal_new ("sync-source",
4753 G_TYPE_FROM_CLASS (object_class),
4754 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
4755 G_STRUCT_OFFSET (EvViewClass, sync_source),
4757 g_cclosure_marshal_VOID__POINTER,
4760 signals[SIGNAL_ANNOT_ADDED] = g_signal_new ("annot-added",
4761 G_TYPE_FROM_CLASS (object_class),
4762 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
4763 G_STRUCT_OFFSET (EvViewClass, annot_added),
4765 g_cclosure_marshal_VOID__OBJECT,
4767 EV_TYPE_ANNOTATION);
4768 signals[SIGNAL_LAYERS_CHANGED] = g_signal_new ("layers-changed",
4769 G_TYPE_FROM_CLASS (object_class),
4770 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
4771 G_STRUCT_OFFSET (EvViewClass, layers_changed),
4773 g_cclosure_marshal_VOID__VOID,
4777 binding_set = gtk_binding_set_by_class (class);
4779 add_scroll_binding_keypad (binding_set, GDK_KEY_Left, 0, GTK_SCROLL_STEP_BACKWARD, TRUE);
4780 add_scroll_binding_keypad (binding_set, GDK_KEY_Right, 0, GTK_SCROLL_STEP_FORWARD, TRUE);
4781 add_scroll_binding_keypad (binding_set, GDK_KEY_Left, GDK_MOD1_MASK, GTK_SCROLL_STEP_DOWN, TRUE);
4782 add_scroll_binding_keypad (binding_set, GDK_KEY_Right, GDK_MOD1_MASK, GTK_SCROLL_STEP_UP, TRUE);
4783 add_scroll_binding_keypad (binding_set, GDK_KEY_Up, 0, GTK_SCROLL_STEP_BACKWARD, FALSE);
4784 add_scroll_binding_keypad (binding_set, GDK_KEY_Down, 0, GTK_SCROLL_STEP_FORWARD, FALSE);
4785 add_scroll_binding_keypad (binding_set, GDK_KEY_Up, GDK_MOD1_MASK, GTK_SCROLL_STEP_DOWN, FALSE);
4786 add_scroll_binding_keypad (binding_set, GDK_KEY_Down, GDK_MOD1_MASK, GTK_SCROLL_STEP_UP, FALSE);
4787 gtk_binding_entry_add_signal (binding_set, GDK_KEY_H, 0, "binding_activated", 2, GTK_TYPE_SCROLL_TYPE,
4788 GTK_SCROLL_STEP_BACKWARD, G_TYPE_BOOLEAN, TRUE);
4789 gtk_binding_entry_add_signal (binding_set, GDK_KEY_J, 0, "binding_activated", 2, GTK_TYPE_SCROLL_TYPE,
4790 GTK_SCROLL_STEP_FORWARD, G_TYPE_BOOLEAN, FALSE);
4791 gtk_binding_entry_add_signal (binding_set, GDK_KEY_K, 0, "binding_activated", 2, GTK_TYPE_SCROLL_TYPE,
4792 GTK_SCROLL_STEP_BACKWARD, G_TYPE_BOOLEAN, FALSE);
4793 gtk_binding_entry_add_signal (binding_set, GDK_KEY_L, 0, "binding_activated", 2, GTK_TYPE_SCROLL_TYPE,
4794 GTK_SCROLL_STEP_FORWARD, G_TYPE_BOOLEAN, TRUE);
4799 ev_view_init (EvView *view)
4801 gtk_widget_set_has_window (GTK_WIDGET (view), TRUE);
4802 gtk_widget_set_can_focus (GTK_WIDGET (view), TRUE);
4803 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (view), FALSE);
4804 gtk_container_set_resize_mode (GTK_CONTAINER (view), GTK_RESIZE_QUEUE);
4806 gtk_widget_set_events (GTK_WIDGET (view),
4808 GDK_BUTTON_PRESS_MASK |
4809 GDK_BUTTON_RELEASE_MASK |
4811 GDK_KEY_PRESS_MASK |
4812 GDK_POINTER_MOTION_MASK |
4813 GDK_POINTER_MOTION_HINT_MASK |
4814 GDK_ENTER_NOTIFY_MASK |
4815 GDK_LEAVE_NOTIFY_MASK);
4817 view->start_page = -1;
4818 view->end_page = -1;
4821 view->current_page = 0;
4822 view->pressed_button = -1;
4823 view->cursor = EV_VIEW_CURSOR_NORMAL;
4824 view->drag_info.in_drag = FALSE;
4825 view->scroll_info.autoscrolling = FALSE;
4826 view->selection_info.selections = NULL;
4827 view->selection_info.in_selection = FALSE;
4828 view->selection_info.in_drag = FALSE;
4829 view->selection_mode = EV_VIEW_SELECTION_TEXT;
4830 view->continuous = TRUE;
4831 view->dual_page = FALSE;
4832 view->fullscreen = FALSE;
4833 view->sizing_mode = EV_SIZING_FIT_WIDTH;
4834 view->pending_scroll = SCROLL_TO_KEEP_POSITION;
4835 view->jump_to_find_result = TRUE;
4836 view->highlight_find_results = FALSE;
4842 ev_view_change_page (EvView *view,
4847 view->current_page = new_page;
4848 view->pending_scroll = SCROLL_TO_PAGE_POSITION;
4850 hide_loading_window (view);
4852 gtk_widget_get_pointer (GTK_WIDGET (view), &x, &y);
4853 ev_view_handle_cursor_over_xy (view, x, y);
4855 gtk_widget_queue_resize (GTK_WIDGET (view));
4859 job_finished_cb (EvPixbufCache *pixbuf_cache,
4860 cairo_region_t *region,
4864 gdk_window_invalidate_region (gtk_widget_get_window (GTK_WIDGET (view)), region, TRUE);
4866 gtk_widget_queue_draw (GTK_WIDGET (view));
4871 ev_view_page_changed_cb (EvDocumentModel *model,
4876 if (!view->document)
4879 if (view->current_page != new_page) {
4880 ev_view_change_page (view, new_page);
4882 gtk_widget_queue_draw (GTK_WIDGET (view));
4885 view->find_result = 0;
4889 on_adjustment_value_changed (GtkAdjustment *adjustment,
4895 GList *children, *l;
4897 if (!gtk_widget_get_realized (GTK_WIDGET (view)))
4900 if (view->hadjustment) {
4901 value = (gint) gtk_adjustment_get_value (view->hadjustment);
4902 dx = view->scroll_x - value;
4903 view->scroll_x = value;
4908 if (view->vadjustment) {
4909 value = (gint) gtk_adjustment_get_value (view->vadjustment);
4910 dy = view->scroll_y - value;
4911 view->scroll_y = value;
4916 children = gtk_container_get_children (GTK_CONTAINER (view));
4917 for (l = children; l && l->data; l = g_list_next (l)) {
4918 gint child_x, child_y;
4919 GtkWidget *child = (GtkWidget *)l->data;
4921 gtk_container_child_get (GTK_CONTAINER (view),
4926 gtk_fixed_move (GTK_FIXED (view), child, child_x + dx, child_y + dy);
4928 g_list_free (children);
4930 for (l = view->window_children; l && l->data; l = g_list_next (l)) {
4931 EvViewWindowChild *child;
4933 child = (EvViewWindowChild *)l->data;
4935 ev_view_window_child_move (view, child, child->x + dx, child->y + dy);
4938 if (view->pending_resize) {
4939 gtk_widget_queue_draw (GTK_WIDGET (view));
4941 gdk_window_scroll (gtk_widget_get_window (GTK_WIDGET (view)), dx, dy);
4944 gtk_widget_get_pointer (GTK_WIDGET (view), &x, &y);
4945 ev_view_handle_cursor_over_xy (view, x, y);
4948 view_update_range_and_current_page (view);
4956 view = g_object_new (EV_TYPE_VIEW, NULL);
4962 setup_caches (EvView *view)
4964 gboolean inverted_colors;
4966 view->height_to_page_cache = ev_view_get_height_to_page_cache (view);
4967 view->pixbuf_cache = ev_pixbuf_cache_new (GTK_WIDGET (view), view->model, view->pixbuf_cache_size);
4968 view->page_cache = ev_page_cache_new (view->document);
4969 if (view->a11y_enabled) {
4970 EvJobPageDataFlags flags = ev_page_cache_get_flags (view->page_cache);
4972 ev_page_cache_set_flags (view->page_cache,
4974 EV_PAGE_DATA_INCLUDE_TEXT_LAYOUT |
4975 EV_PAGE_DATA_INCLUDE_TEXT);
4977 inverted_colors = ev_document_model_get_inverted_colors (view->model);
4978 ev_pixbuf_cache_set_inverted_colors (view->pixbuf_cache, inverted_colors);
4979 g_signal_connect (view->pixbuf_cache, "job-finished", G_CALLBACK (job_finished_cb), view);
4983 clear_caches (EvView *view)
4985 if (view->pixbuf_cache) {
4986 g_object_unref (view->pixbuf_cache);
4987 view->pixbuf_cache = NULL;
4990 if (view->page_cache) {
4991 g_object_unref (view->page_cache);
4992 view->page_cache = NULL;
4997 * ev_view_set_page_cache_size:
5001 * Sets the maximum size in bytes that will be used to cache
5002 * rendered pages. Use 0 to disable caching rendered pages.
5004 * Note that this limit doesn't affect the current visible page range,
5005 * which will always be rendered. In order to limit the total memory used
5006 * you have to use ev_document_model_set_max_scale() too.
5010 ev_view_set_page_cache_size (EvView *view,
5013 if (view->pixbuf_cache_size == cache_size)
5016 view->pixbuf_cache_size = cache_size;
5017 if (view->pixbuf_cache)
5018 ev_pixbuf_cache_set_max_size (view->pixbuf_cache, cache_size);
5022 ev_view_set_loading (EvView *view,
5025 if (view->loading && !loading)
5026 hide_loading_window (view);
5027 view->loading = loading;
5028 gtk_widget_queue_draw (GTK_WIDGET (view));
5032 ev_view_autoscroll_cb (EvView *view)
5034 gdouble speed, value;
5036 /* If the user stops autoscrolling, autoscrolling will be
5037 * set to false but the timeout will continue; stop the timeout: */
5038 if (!view->scroll_info.autoscrolling) {
5039 view->scroll_info.timeout_id = 0;
5043 if (view->scroll_info.last_y > view->scroll_info.start_y &&
5044 (view->scroll_info.last_y < view->scroll_info.start_y))
5047 /* Replace 100 with your speed of choice: The lower the faster.
5048 * Replace 3 with another speed of choice: The higher, the faster it accelerated
5049 * based on the distance of the starting point from the mouse
5050 * (All also effected by the timeout interval of this callback) */
5052 if (view->scroll_info.start_y > view->scroll_info.last_y)
5053 speed = -pow ((((gdouble)view->scroll_info.start_y - view->scroll_info.last_y) / 100), 3);
5055 speed = pow ((((gdouble)view->scroll_info.last_y - view->scroll_info.start_y) / 100), 3);
5057 value = gtk_adjustment_get_value (view->vadjustment);
5058 value = CLAMP (value + speed, 0,
5059 gtk_adjustment_get_upper (view->vadjustment) -
5060 gtk_adjustment_get_page_size (view->vadjustment));
5061 gtk_adjustment_set_value (view->vadjustment, value);
5068 ev_view_autoscroll_start (EvView *view)
5072 g_return_if_fail (EV_IS_VIEW (view));
5074 if (view->scroll_info.autoscrolling)
5077 view->scroll_info.autoscrolling = TRUE;
5078 view->scroll_info.timeout_id =
5079 g_timeout_add (20, (GSourceFunc)ev_view_autoscroll_cb,
5082 gtk_widget_get_pointer (GTK_WIDGET (view), &x, &y);
5083 ev_view_handle_cursor_over_xy (view, x, y);
5087 ev_view_autoscroll_stop (EvView *view)
5091 g_return_if_fail (EV_IS_VIEW (view));
5093 if (!view->scroll_info.autoscrolling)
5096 view->scroll_info.autoscrolling = FALSE;
5097 if (view->scroll_info.timeout_id) {
5098 g_source_remove (view->scroll_info.timeout_id);
5099 view->scroll_info.timeout_id = 0;
5102 gtk_widget_get_pointer (GTK_WIDGET (view), &x, &y);
5103 ev_view_handle_cursor_over_xy (view, x, y);
5107 ev_view_document_changed_cb (EvDocumentModel *model,
5111 EvDocument *document = ev_document_model_get_document (model);
5113 if (document != view->document) {
5116 clear_caches (view);
5118 if (view->document) {
5119 g_object_unref (view->document);
5122 view->document = document;
5123 view->find_result = 0;
5125 if (view->document) {
5126 view->loading = FALSE;
5127 g_object_ref (view->document);
5128 setup_caches (view);
5131 current_page = ev_document_model_get_page (model);
5132 if (view->current_page != current_page) {
5133 ev_view_change_page (view, current_page);
5135 view->pending_scroll = SCROLL_TO_KEEP_POSITION;
5136 gtk_widget_queue_resize (GTK_WIDGET (view));
5142 ev_view_rotation_changed_cb (EvDocumentModel *model,
5146 gint rotation = ev_document_model_get_rotation (model);
5148 view->rotation = rotation;
5150 if (view->pixbuf_cache) {
5151 ev_pixbuf_cache_clear (view->pixbuf_cache);
5152 if (!ev_document_is_page_size_uniform (view->document))
5153 view->pending_scroll = SCROLL_TO_PAGE_POSITION;
5154 gtk_widget_queue_resize (GTK_WIDGET (view));
5157 ev_view_remove_all (view);
5160 clear_selection (view);
5164 ev_view_inverted_colors_changed_cb (EvDocumentModel *model,
5168 if (view->pixbuf_cache) {
5169 gboolean inverted_colors;
5171 inverted_colors = ev_document_model_get_inverted_colors (model);
5172 ev_pixbuf_cache_set_inverted_colors (view->pixbuf_cache, inverted_colors);
5173 gtk_widget_queue_draw (GTK_WIDGET (view));
5178 ev_view_sizing_mode_changed_cb (EvDocumentModel *model,
5182 EvSizingMode mode = ev_document_model_get_sizing_mode (model);
5184 view->sizing_mode = mode;
5185 if (mode != EV_SIZING_FREE)
5186 gtk_widget_queue_resize (GTK_WIDGET (view));
5189 #define EPSILON 0.0000001
5191 ev_view_scale_changed_cb (EvDocumentModel *model,
5195 gdouble scale = ev_document_model_get_scale (model);
5197 if (ABS (view->scale - scale) < EPSILON)
5200 view->scale = scale;
5202 view->pending_resize = TRUE;
5203 if (view->sizing_mode == EV_SIZING_FREE)
5204 gtk_widget_queue_resize (GTK_WIDGET (view));
5208 ev_view_continuous_changed_cb (EvDocumentModel *model,
5212 gboolean continuous = ev_document_model_get_continuous (model);
5214 view->continuous = continuous;
5215 view->pending_scroll = SCROLL_TO_PAGE_POSITION;
5216 gtk_widget_queue_resize (GTK_WIDGET (view));
5220 ev_view_dual_page_changed_cb (EvDocumentModel *model,
5224 gboolean dual_page = ev_document_model_get_dual_page (model);
5226 view->dual_page = dual_page;
5227 view->pending_scroll = SCROLL_TO_PAGE_POSITION;
5228 /* FIXME: if we're keeping the pixbuf cache around, we should extend the
5229 * preload_cache_size to be 2 if dual_page is set.
5231 gtk_widget_queue_resize (GTK_WIDGET (view));
5235 ev_view_fullscreen_changed_cb (EvDocumentModel *model,
5239 gboolean fullscreen = ev_document_model_get_fullscreen (model);
5241 view->fullscreen = fullscreen;
5242 gtk_widget_queue_resize (GTK_WIDGET (view));
5246 ev_view_set_model (EvView *view,
5247 EvDocumentModel *model)
5249 g_return_if_fail (EV_IS_VIEW (view));
5250 g_return_if_fail (EV_IS_DOCUMENT_MODEL (model));
5252 if (model == view->model)
5256 g_signal_handlers_disconnect_by_func (view->model,
5257 ev_view_document_changed_cb,
5259 g_signal_handlers_disconnect_by_func (view->model,
5260 ev_view_page_changed_cb,
5262 g_object_unref (view->model);
5264 view->model = g_object_ref (model);
5266 /* Initialize view from model */
5267 view->rotation = ev_document_model_get_rotation (view->model);
5268 view->sizing_mode = ev_document_model_get_sizing_mode (view->model);
5269 view->scale = ev_document_model_get_scale (view->model);
5270 view->continuous = ev_document_model_get_continuous (view->model);
5271 view->dual_page = ev_document_model_get_dual_page (view->model);
5272 view->fullscreen = ev_document_model_get_fullscreen (view->model);
5273 ev_view_document_changed_cb (view->model, NULL, view);
5275 g_signal_connect (view->model, "notify::document",
5276 G_CALLBACK (ev_view_document_changed_cb),
5278 g_signal_connect (view->model, "notify::rotation",
5279 G_CALLBACK (ev_view_rotation_changed_cb),
5281 g_signal_connect (view->model, "notify::inverted-colors",
5282 G_CALLBACK (ev_view_inverted_colors_changed_cb),
5284 g_signal_connect (view->model, "notify::sizing-mode",
5285 G_CALLBACK (ev_view_sizing_mode_changed_cb),
5287 g_signal_connect (view->model, "notify::scale",
5288 G_CALLBACK (ev_view_scale_changed_cb),
5290 g_signal_connect (view->model, "notify::continuous",
5291 G_CALLBACK (ev_view_continuous_changed_cb),
5293 g_signal_connect (view->model, "notify::dual-page",
5294 G_CALLBACK (ev_view_dual_page_changed_cb),
5296 g_signal_connect (view->model, "notify::fullscreen",
5297 G_CALLBACK (ev_view_fullscreen_changed_cb),
5299 g_signal_connect (view->model, "page-changed",
5300 G_CALLBACK (ev_view_page_changed_cb),
5305 ev_view_reload_page (EvView *view,
5307 cairo_region_t *region)
5309 ev_pixbuf_cache_reload_page (view->pixbuf_cache,
5317 ev_view_reload (EvView *view)
5319 ev_pixbuf_cache_clear (view->pixbuf_cache);
5320 view_update_range_and_current_page (view);
5323 /*** Zoom and sizing mode ***/
5326 ev_view_can_zoom_in (EvView *view)
5328 return view->scale * ZOOM_IN_FACTOR <= ev_document_model_get_max_scale (view->model);
5332 ev_view_can_zoom_out (EvView *view)
5334 return view->scale * ZOOM_OUT_FACTOR >= ev_document_model_get_min_scale (view->model);
5338 ev_view_zoom_in (EvView *view)
5342 g_return_if_fail (view->sizing_mode == EV_SIZING_FREE);
5344 view->pending_scroll = SCROLL_TO_CENTER;
5345 scale = ev_document_model_get_scale (view->model) * ZOOM_IN_FACTOR;
5346 ev_document_model_set_scale (view->model, scale);
5350 ev_view_zoom_out (EvView *view)
5354 g_return_if_fail (view->sizing_mode == EV_SIZING_FREE);
5356 view->pending_scroll = SCROLL_TO_CENTER;
5357 scale = ev_document_model_get_scale (view->model) * ZOOM_OUT_FACTOR;
5358 ev_document_model_set_scale (view->model, scale);
5362 zoom_for_size_fit_width (gdouble doc_width,
5367 return (double)target_width / doc_width;
5371 zoom_for_size_fit_height (gdouble doc_width,
5376 return (double)target_height / doc_height;
5380 zoom_for_size_best_fit (gdouble doc_width,
5388 w_scale = (double)target_width / doc_width;
5389 h_scale = (double)target_height / doc_height;
5391 return MIN (w_scale, h_scale);
5395 ev_view_zoom_for_size_continuous_and_dual_page (EvView *view,
5399 gdouble doc_width, doc_height;
5404 ev_document_get_max_page_size (view->document, &doc_width, &doc_height);
5405 if (view->rotation == 90 || view->rotation == 270) {
5409 doc_width = doc_height;
5413 compute_border (view, doc_width, doc_height, &border);
5416 width -= (2 * (border.left + border.right) + 3 * view->spacing);
5417 height -= (border.top + border.bottom + 2 * view->spacing - 1);
5419 sb_size = ev_view_get_scrollbar_size (view, GTK_ORIENTATION_VERTICAL);
5421 if (view->sizing_mode == EV_SIZING_FIT_WIDTH) {
5422 scale = zoom_for_size_fit_width (doc_width, doc_height, width - sb_size, height);
5423 } else if (view->sizing_mode == EV_SIZING_BEST_FIT)
5424 scale = zoom_for_size_best_fit (doc_width, doc_height, width - sb_size, height);
5426 g_assert_not_reached ();
5428 ev_document_model_set_scale (view->model, scale);
5432 ev_view_zoom_for_size_continuous (EvView *view,
5436 gdouble doc_width, doc_height;
5441 ev_document_get_max_page_size (view->document, &doc_width, &doc_height);
5442 if (view->rotation == 90 || view->rotation == 270) {
5446 doc_width = doc_height;
5450 compute_border (view, doc_width, doc_height, &border);
5452 width -= (border.left + border.right + 2 * view->spacing);
5453 height -= (border.top + border.bottom + 2 * view->spacing - 1);
5455 sb_size = ev_view_get_scrollbar_size (view, GTK_ORIENTATION_VERTICAL);
5457 if (view->sizing_mode == EV_SIZING_FIT_WIDTH) {
5458 scale = zoom_for_size_fit_width (doc_width, doc_height, width - sb_size, height);
5459 } else if (view->sizing_mode == EV_SIZING_BEST_FIT)
5460 scale = zoom_for_size_best_fit (doc_width, doc_height, width - sb_size, height);
5462 g_assert_not_reached ();
5464 ev_document_model_set_scale (view->model, scale);
5468 ev_view_zoom_for_size_dual_page (EvView *view,
5473 gdouble doc_width, doc_height;
5477 other_page = view->current_page ^ 1;
5479 /* Find the largest of the two. */
5480 get_doc_page_size (view, view->current_page, &doc_width, &doc_height);
5481 if (other_page < ev_document_get_n_pages (view->document)) {
5482 gdouble width_2, height_2;
5484 get_doc_page_size (view, other_page, &width_2, &height_2);
5485 if (width_2 > doc_width)
5486 doc_width = width_2;
5487 if (height_2 > doc_height)
5488 doc_height = height_2;
5490 compute_border (view, width, height, &border);
5492 doc_width = doc_width * 2;
5493 width -= ((border.left + border.right)* 2 + 3 * view->spacing);
5494 height -= (border.top + border.bottom + 2 * view->spacing);
5496 if (view->sizing_mode == EV_SIZING_FIT_WIDTH) {
5499 sb_size = ev_view_get_scrollbar_size (view, GTK_ORIENTATION_VERTICAL);
5500 scale = zoom_for_size_fit_width (doc_width, doc_height, width - sb_size, height);
5501 } else if (view->sizing_mode == EV_SIZING_BEST_FIT)
5502 scale = zoom_for_size_best_fit (doc_width, doc_height, width, height);
5504 g_assert_not_reached ();
5506 ev_document_model_set_scale (view->model, scale);
5510 ev_view_zoom_for_size_single_page (EvView *view,
5514 gdouble doc_width, doc_height;
5518 get_doc_page_size (view, view->current_page, &doc_width, &doc_height);
5520 /* Get an approximate border */
5521 compute_border (view, width, height, &border);
5523 width -= (border.left + border.right + 2 * view->spacing);
5524 height -= (border.top + border.bottom + 2 * view->spacing);
5526 if (view->sizing_mode == EV_SIZING_FIT_WIDTH) {
5529 sb_size = ev_view_get_scrollbar_size (view, GTK_ORIENTATION_VERTICAL);
5530 scale = zoom_for_size_fit_width (doc_width, doc_height, width - sb_size, height);
5531 } else if (view->sizing_mode == EV_SIZING_BEST_FIT)
5532 scale = zoom_for_size_best_fit (doc_width, doc_height, width, height);
5534 g_assert_not_reached ();
5536 ev_document_model_set_scale (view->model, scale);
5540 ev_view_zoom_for_size (EvView *view,
5544 g_return_if_fail (EV_IS_VIEW (view));
5545 g_return_if_fail (view->sizing_mode == EV_SIZING_FIT_WIDTH ||
5546 view->sizing_mode == EV_SIZING_BEST_FIT);
5547 g_return_if_fail (width >= 0);
5548 g_return_if_fail (height >= 0);
5550 if (view->document == NULL)
5553 if (view->continuous && view->dual_page)
5554 ev_view_zoom_for_size_continuous_and_dual_page (view, width, height);
5555 else if (view->continuous)
5556 ev_view_zoom_for_size_continuous (view, width, height);
5557 else if (view->dual_page)
5558 ev_view_zoom_for_size_dual_page (view, width, height);
5560 ev_view_zoom_for_size_single_page (view, width, height);
5565 ev_view_find_get_n_results (EvView *view, gint page)
5567 return view->find_pages ? g_list_length (view->find_pages[page]) : 0;
5570 static EvRectangle *
5571 ev_view_find_get_result (EvView *view, gint page, gint result)
5573 return view->find_pages ? (EvRectangle *) g_list_nth_data (view->find_pages[page], result) : NULL;
5577 jump_to_find_result (EvView *view)
5580 gint page = view->current_page;
5582 n_results = ev_view_find_get_n_results (view, page);
5584 if (n_results > 0 && view->find_result < n_results) {
5586 GdkRectangle view_rect;
5588 rect = ev_view_find_get_result (view, page, view->find_result);
5589 doc_rect_to_view_rect (view, page, rect, &view_rect);
5590 ensure_rectangle_is_visible (view, &view_rect);
5591 view->jump_to_find_result = FALSE;
5597 * @view: #EvView instance
5598 * @direction: Direction to look
5599 * @shift: Shift from current page
5601 * Jumps to the first page that has occurences of searched word.
5602 * Uses a direction where to look and a shift from current page.
5606 jump_to_find_page (EvView *view, EvViewFindDirection direction, gint shift)
5610 n_pages = ev_document_get_n_pages (view->document);
5612 for (i = 0; i < n_pages; i++) {
5615 if (direction == EV_VIEW_FIND_NEXT)
5616 page = view->current_page + i;
5618 page = view->current_page - i;
5621 if (page >= n_pages) {
5622 page = page - n_pages;
5623 } else if (page < 0)
5624 page = page + n_pages;
5626 if (ev_view_find_get_n_results (view, page) > 0) {
5627 ev_document_model_set_page (view->model, page);
5634 ev_view_find_changed (EvView *view, GList **results, gint page)
5636 view->find_pages = results;
5638 if (view->jump_to_find_result == TRUE) {
5639 jump_to_find_page (view, EV_VIEW_FIND_NEXT, 0);
5640 jump_to_find_result (view);
5643 if (view->current_page == page)
5644 gtk_widget_queue_draw (GTK_WIDGET (view));
5648 ev_view_find_next (EvView *view)
5652 n_results = ev_view_find_get_n_results (view, view->current_page);
5653 view->find_result++;
5655 if (view->find_result >= n_results) {
5656 view->find_result = 0;
5657 jump_to_find_page (view, EV_VIEW_FIND_NEXT, 1);
5658 jump_to_find_result (view);
5660 jump_to_find_result (view);
5661 gtk_widget_queue_draw (GTK_WIDGET (view));
5666 ev_view_find_previous (EvView *view)
5668 view->find_result--;
5670 if (view->find_result < 0) {
5671 jump_to_find_page (view, EV_VIEW_FIND_PREV, -1);
5672 view->find_result = MAX (0, ev_view_find_get_n_results (view, view->current_page) - 1);
5673 jump_to_find_result (view);
5675 jump_to_find_result (view);
5676 gtk_widget_queue_draw (GTK_WIDGET (view));
5681 ev_view_find_search_changed (EvView *view)
5683 /* search string has changed, focus on new search result */
5684 view->jump_to_find_result = TRUE;
5685 view->find_pages = NULL;
5689 ev_view_find_set_highlight_search (EvView *view, gboolean value)
5691 view->highlight_find_results = value;
5692 gtk_widget_queue_draw (GTK_WIDGET (view));
5696 ev_view_find_cancel (EvView *view)
5698 view->find_pages = NULL;
5703 ev_view_highlight_forward_search (EvView *view,
5708 GdkRectangle view_rect;
5710 if (!ev_document_has_synctex (view->document))
5713 mapping = ev_document_synctex_forward_search (view->document, link);
5717 if (view->synctex_result)
5718 g_free (view->synctex_result);
5719 view->synctex_result = mapping;
5721 page = GPOINTER_TO_INT (mapping->data);
5722 ev_document_model_set_page (view->model, page);
5724 doc_rect_to_view_rect (view, page, &mapping->area, &view_rect);
5725 ensure_rectangle_is_visible (view, &view_rect);
5726 gtk_widget_queue_draw (GTK_WIDGET (view));
5729 /*** Selections ***/
5731 /* compute_new_selection_rect/text calculates the area currently selected by
5732 * view_rect. each handles a different mode;
5735 compute_new_selection_rect (EvView *view,
5739 GdkRectangle view_rect;
5743 g_assert (view->selection_mode == EV_VIEW_SELECTION_RECTANGLE);
5745 view_rect.x = MIN (start->x, stop->x);
5746 view_rect.y = MIN (start->y, stop->y);
5747 view_rect.width = MAX (start->x, stop->x) - view_rect.x;
5748 view_rect.width = MAX (start->y, stop->y) - view_rect.y;
5750 n_pages = ev_document_get_n_pages (view->document);
5752 for (i = 0; i < n_pages; i++) {
5753 GdkRectangle page_area;
5756 if (ev_view_get_page_extents (view, i, &page_area, &border)) {
5757 GdkRectangle overlap;
5759 if (gdk_rectangle_intersect (&page_area, &view_rect, &overlap)) {
5760 EvViewSelection *selection;
5762 selection = g_new0 (EvViewSelection, 1);
5763 selection->page = i;
5764 view_rect_to_doc_rect (view, &overlap, &page_area,
5765 &(selection->rect));
5767 list = g_list_append (list, selection);
5776 gdk_rectangle_point_in (GdkRectangle *rectangle,
5779 return rectangle->x <= point->x &&
5780 rectangle->y <= point->y &&
5781 point->x < rectangle->x + rectangle->width &&
5782 point->y < rectangle->y + rectangle->height;
5786 compute_new_selection_text (EvView *view,
5787 EvSelectionStyle style,
5791 int n_pages, i, first, last;
5793 EvViewSelection *selection;
5794 gdouble width, height;
5795 int start_page, end_page;
5797 g_assert (view->selection_mode == EV_VIEW_SELECTION_TEXT);
5799 n_pages = ev_document_get_n_pages (view->document);
5801 /* First figure out the range of pages the selection
5805 if (view->continuous) {
5808 } else if (view->dual_page) {
5809 start_page = view->start_page;
5810 end_page = view->end_page + 1;
5812 start_page = view->current_page;
5813 end_page = view->current_page + 1;
5816 for (i = start_page; i < end_page; i++) {
5817 GdkRectangle page_area;
5820 ev_view_get_page_extents (view, i, &page_area, &border);
5821 if (gdk_rectangle_point_in (&page_area, start) ||
5822 gdk_rectangle_point_in (&page_area, stop)) {
5823 if (first == n_pages)
5830 /* Now create a list of EvViewSelection's for the affected
5831 * pages. This could be an empty list, a list of just one
5832 * page or a number of pages.*/
5833 for (i = first; i < last + 1; i++) {
5834 GdkRectangle page_area;
5838 get_doc_page_size (view, i, &width, &height);
5840 selection = g_new0 (EvViewSelection, 1);
5841 selection->page = i;
5842 selection->style = style;
5843 selection->rect.x1 = selection->rect.y1 = 0;
5844 selection->rect.x2 = width;
5845 selection->rect.y2 = height;
5847 ev_view_get_page_extents (view, i, &page_area, &border);
5849 if (gdk_rectangle_point_in (&page_area, start))
5855 view_point_to_doc_point (view, point, &page_area,
5856 &selection->rect.x1,
5857 &selection->rect.y1);
5859 /* If the selection is contained within just one page,
5860 * make sure we don't write 'start' into both points
5861 * in selection->rect. */
5866 view_point_to_doc_point (view, point, &page_area,
5867 &selection->rect.x2,
5868 &selection->rect.y2);
5870 list = g_list_append (list, selection);
5876 /* This function takes the newly calculated list, and figures out which regions
5877 * have changed. It then queues a redraw approporiately.
5880 merge_selection_region (EvView *view,
5884 GList *new_list_ptr, *old_list_ptr;
5886 /* Update the selection */
5887 old_list = ev_pixbuf_cache_get_selection_list (view->pixbuf_cache);
5888 g_list_foreach (view->selection_info.selections, (GFunc)selection_free, NULL);
5889 g_list_free (view->selection_info.selections);
5890 view->selection_info.selections = new_list;
5891 ev_pixbuf_cache_set_selection_list (view->pixbuf_cache, new_list);
5892 g_signal_emit (view, signals[SIGNAL_SELECTION_CHANGED], 0, NULL);
5894 new_list_ptr = new_list;
5895 old_list_ptr = old_list;
5897 while (new_list_ptr || old_list_ptr) {
5898 EvViewSelection *old_sel, *new_sel;
5900 cairo_region_t *region = NULL;
5902 new_sel = (new_list_ptr) ? (new_list_ptr->data) : NULL;
5903 old_sel = (old_list_ptr) ? (old_list_ptr->data) : NULL;
5905 /* Assume that the lists are in order, and we run through them
5906 * comparing them, one page at a time. We come out with the
5907 * first page we see. */
5908 if (new_sel && old_sel) {
5909 if (new_sel->page < old_sel->page) {
5910 new_list_ptr = new_list_ptr->next;
5912 } else if (new_sel->page > old_sel->page) {
5913 old_list_ptr = old_list_ptr->next;
5916 new_list_ptr = new_list_ptr->next;
5917 old_list_ptr = old_list_ptr->next;
5919 } else if (new_sel) {
5920 new_list_ptr = new_list_ptr->next;
5921 } else if (old_sel) {
5922 old_list_ptr = old_list_ptr->next;
5925 g_assert (new_sel || old_sel);
5927 /* is the page we're looking at on the screen?*/
5928 cur_page = new_sel ? new_sel->page : old_sel->page;
5929 if (cur_page < view->start_page || cur_page > view->end_page)
5932 /* seed the cache with a new page. We are going to need the new
5935 cairo_region_t *tmp_region = NULL;
5937 ev_pixbuf_cache_get_selection_surface (view->pixbuf_cache,
5942 if (tmp_region && !cairo_region_is_empty (tmp_region)) {
5943 new_sel->covered_region = cairo_region_reference (tmp_region);
5947 /* Now we figure out what needs redrawing */
5948 if (old_sel && new_sel) {
5949 if (old_sel->covered_region && new_sel->covered_region) {
5950 /* We only want to redraw the areas that have
5951 * changed, so we xor the old and new regions
5952 * and redraw if it's different */
5953 region = cairo_region_copy (old_sel->covered_region);
5954 #if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 9, 12)
5955 cairo_region_xor (region, new_sel->covered_region);
5957 cairo_region_t *tbr;
5958 tbr = cairo_region_copy (new_sel->covered_region);
5960 /* xor old_sel, new_sel*/
5961 cairo_region_subtract (tbr, region);
5962 cairo_region_subtract (region, new_sel->covered_region);
5963 cairo_region_union (region, tbr);
5964 cairo_region_destroy (tbr);
5967 if (cairo_region_is_empty (region)) {
5968 cairo_region_destroy (region);
5971 gint num_rectangles = cairo_region_num_rectangles (region);
5974 /* We need to make the damage region a little bigger
5975 * because the edges of the old selection might change
5977 cairo_region_get_rectangle (region, 0, &r);
5980 cairo_region_union_rectangle (region, &r);
5982 cairo_region_get_rectangle (region, num_rectangles - 1, &r);
5985 cairo_region_union_rectangle (region, &r);
5987 } else if (old_sel->covered_region) {
5988 region = cairo_region_copy (old_sel->covered_region);
5989 } else if (new_sel->covered_region) {
5990 region = cairo_region_copy (new_sel->covered_region);
5992 } else if (old_sel && !new_sel) {
5993 if (old_sel->covered_region && !cairo_region_is_empty (old_sel->covered_region)) {
5994 region = cairo_region_copy (old_sel->covered_region);
5996 } else if (!old_sel && new_sel) {
5997 if (new_sel->covered_region && !cairo_region_is_empty (new_sel->covered_region)) {
5998 region = cairo_region_copy (new_sel->covered_region);
6001 g_assert_not_reached ();
6004 /* Redraw the damaged region! */
6006 GdkRectangle page_area;
6009 ev_view_get_page_extents (view, cur_page, &page_area, &border);
6010 cairo_region_translate (region,
6011 page_area.x + border.left - view->scroll_x,
6012 page_area.y + border.top - view->scroll_y);
6013 gdk_window_invalidate_region (gtk_widget_get_window (GTK_WIDGET (view)), region, TRUE);
6014 cairo_region_destroy (region);
6018 /* Free the old list, now that we're done with it. */
6019 g_list_foreach (old_list, (GFunc) selection_free, NULL);
6020 g_list_free (old_list);
6024 compute_selections (EvView *view,
6025 EvSelectionStyle style,
6031 if (view->selection_mode == EV_VIEW_SELECTION_RECTANGLE)
6032 list = compute_new_selection_rect (view, start, stop);
6034 list = compute_new_selection_text (view, style, start, stop);
6035 merge_selection_region (view, list);
6038 /* Free's the selection. It's up to the caller to queue redraws if needed.
6041 selection_free (EvViewSelection *selection)
6043 if (selection->covered_region)
6044 cairo_region_destroy (selection->covered_region);
6049 clear_selection (EvView *view)
6051 if (view->selection_info.selections) {
6052 g_list_foreach (view->selection_info.selections, (GFunc)selection_free, NULL);
6053 g_list_free (view->selection_info.selections);
6054 view->selection_info.selections = NULL;
6056 g_signal_emit (view, signals[SIGNAL_SELECTION_CHANGED], 0, NULL);
6058 view->selection_info.in_selection = FALSE;
6059 if (view->pixbuf_cache)
6060 ev_pixbuf_cache_set_selection_list (view->pixbuf_cache, NULL);
6064 ev_view_select_all (EvView *view)
6066 GList *selections = NULL;
6069 /* Disable selection on rotated pages for the 0.4.0 series */
6070 if (view->rotation != 0)
6073 clear_selection (view);
6075 n_pages = ev_document_get_n_pages (view->document);
6076 for (i = 0; i < n_pages; i++) {
6077 gdouble width, height;
6078 EvViewSelection *selection;
6080 get_doc_page_size (view, i, &width, &height);
6082 selection = g_new0 (EvViewSelection, 1);
6083 selection->page = i;
6084 selection->style = EV_SELECTION_STYLE_GLYPH;
6085 selection->rect.x1 = selection->rect.y1 = 0;
6086 selection->rect.x2 = width;
6087 selection->rect.y2 = height;
6089 selections = g_list_append (selections, selection);
6092 merge_selection_region (view, selections);
6093 gtk_widget_queue_draw (GTK_WIDGET (view));
6097 ev_view_get_has_selection (EvView *view)
6099 return view->selection_info.selections != NULL;
6103 get_selected_text (EvView *view)
6107 gchar *normalized_text;
6109 text = g_string_new (NULL);
6111 ev_document_doc_mutex_lock ();
6113 for (l = view->selection_info.selections; l != NULL; l = l->next) {
6114 EvViewSelection *selection = (EvViewSelection *)l->data;
6118 page = ev_document_get_page (view->document, selection->page);
6119 tmp = ev_selection_get_selected_text (EV_SELECTION (view->document),
6120 page, selection->style,
6121 &(selection->rect));
6122 g_object_unref (page);
6123 g_string_append (text, tmp);
6127 ev_document_doc_mutex_unlock ();
6129 normalized_text = g_utf8_normalize (text->str, text->len, G_NORMALIZE_NFKC);
6130 g_string_free (text, TRUE);
6131 return normalized_text;
6135 ev_view_clipboard_copy (EvView *view,
6138 GtkClipboard *clipboard;
6140 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (view),
6141 GDK_SELECTION_CLIPBOARD);
6142 gtk_clipboard_set_text (clipboard, text, -1);
6146 ev_view_copy (EvView *ev_view)
6150 if (!EV_IS_SELECTION (ev_view->document))
6153 text = get_selected_text (ev_view);
6154 ev_view_clipboard_copy (ev_view, text);
6159 ev_view_primary_get_cb (GtkClipboard *clipboard,
6160 GtkSelectionData *selection_data,
6164 EvView *ev_view = EV_VIEW (data);
6166 if (ev_view->link_selected) {
6167 gtk_selection_data_set_text (selection_data,
6168 ev_link_action_get_uri (ev_view->link_selected),
6170 } else if (EV_IS_SELECTION (ev_view->document) &&
6171 ev_view->selection_info.selections) {
6174 text = get_selected_text (ev_view);
6176 gtk_selection_data_set_text (selection_data, text, -1);
6183 ev_view_primary_clear_cb (GtkClipboard *clipboard,
6186 EvView *view = EV_VIEW (data);
6188 clear_selection (view);
6189 clear_link_selected (view);
6193 ev_view_update_primary_selection (EvView *ev_view)
6195 GtkClipboard *clipboard;
6197 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (ev_view),
6198 GDK_SELECTION_PRIMARY);
6200 if (ev_view->selection_info.selections || ev_view->link_selected) {
6201 GtkTargetList *target_list;
6202 GtkTargetEntry *targets;
6205 target_list = gtk_target_list_new (NULL, 0);
6206 gtk_target_list_add_text_targets (target_list, 0);
6207 targets = gtk_target_table_new_from_list (target_list, &n_targets);
6208 gtk_target_list_unref (target_list);
6210 if (!gtk_clipboard_set_with_owner (clipboard,
6212 ev_view_primary_get_cb,
6213 ev_view_primary_clear_cb,
6214 G_OBJECT (ev_view)))
6215 ev_view_primary_clear_cb (clipboard, ev_view);
6217 gtk_target_table_free (targets, n_targets);
6219 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (ev_view))
6220 gtk_clipboard_clear (clipboard);
6225 clear_link_selected (EvView *view)
6227 if (view->link_selected) {
6228 g_object_unref (view->link_selected);
6229 view->link_selected = NULL;
6234 ev_view_copy_link_address (EvView *view,
6235 EvLinkAction *action)
6237 clear_link_selected (view);
6239 ev_view_clipboard_copy (view, ev_link_action_get_uri (action));
6241 view->link_selected = g_object_ref (action);
6242 ev_view_update_primary_selection (view);
6245 /*** Cursor operations ***/
6247 ev_view_set_cursor (EvView *view, EvViewCursor new_cursor)
6249 GdkCursor *cursor = NULL;
6253 if (view->cursor == new_cursor) {
6257 view->cursor = new_cursor;
6259 window = gtk_widget_get_window (GTK_WIDGET (view));
6260 widget = gtk_widget_get_toplevel (GTK_WIDGET (view));
6261 cursor = ev_view_cursor_new (gtk_widget_get_display (widget), new_cursor);
6262 gdk_window_set_cursor (window, cursor);
6265 gdk_cursor_unref (cursor);
6269 ev_view_hide_cursor (EvView *view)
6271 ev_view_set_cursor (view, EV_VIEW_CURSOR_HIDDEN);
6275 ev_view_show_cursor (EvView *view)
6277 ev_view_set_cursor (view, EV_VIEW_CURSOR_NORMAL);
6281 ev_view_next_page (EvView *view)
6285 g_return_val_if_fail (EV_IS_VIEW (view), FALSE);
6287 if (!view->document)
6290 page = ev_document_model_get_page (view->model);
6291 n_pages = ev_document_get_n_pages (view->document);
6293 if (view->dual_page)
6298 if (page < n_pages) {
6299 ev_document_model_set_page (view->model, page);
6301 } else if (view->dual_page && page == n_pages) {
6302 ev_document_model_set_page (view->model, page - 1);
6310 ev_view_previous_page (EvView *view)
6314 g_return_val_if_fail (EV_IS_VIEW (view), FALSE);
6316 if (!view->document)
6319 page = ev_document_model_get_page (view->model);
6321 if (view->dual_page)
6327 ev_document_model_set_page (view->model, page);
6329 } else if (view->dual_page && page == -1) {
6330 ev_document_model_set_page (view->model, 0);