*dual_height = (gint)(dh * view->scale + 0.5);
}
+static gint
+ev_view_get_scrollbar_size (EvView *view,
+ GtkOrientation orientation)
+{
+ GtkWidget *widget = GTK_WIDGET (view);
+ GtkWidget *sb;
+ GtkWidget *swindow = gtk_widget_get_parent (GTK_WIDGET (view));
+ GtkRequisition req;
+ gint spacing;
+
+ if (!GTK_IS_SCROLLED_WINDOW (swindow))
+ return 0;
+
+ if (orientation == GTK_ORIENTATION_VERTICAL) {
+ if (widget->allocation.height >= widget->requisition.height)
+ sb = gtk_scrolled_window_get_vscrollbar (GTK_SCROLLED_WINDOW (swindow));
+ else
+ return 0;
+ } else {
+ if (widget->allocation.width >= widget->requisition.width)
+ sb = gtk_scrolled_window_get_hscrollbar (GTK_SCROLLED_WINDOW (swindow));
+ else
+ return 0;
+ }
+
+ gtk_widget_style_get (swindow, "scrollbar_spacing", &spacing, NULL);
+ gtk_widget_size_request (sb, &req);
+
+ return (orientation == GTK_ORIENTATION_VERTICAL ? req.width : req.height) + spacing;
+}
+
static void
scroll_to_point (EvView *view,
gdouble x,
static void
view_update_range_and_current_page (EvView *view)
{
- gint current_page;
- gint best_current_page = -1;
gint start = view->start_page;
gint end = view->end_page;
GtkBorder border;
gboolean found = FALSE;
gint area_max = -1, area;
- int i;
+ gint best_current_page = -1;
+ int i, j = 0;
if (!(view->vadjustment && view->hadjustment))
return;
current_area.x = view->hadjustment->value;
- current_area.width = view->hadjustment->upper;
+ current_area.width = view->hadjustment->page_size;
current_area.y = view->vadjustment->value;
current_area.height = view->vadjustment->page_size;
}
view->end_page = i;
+ j = 0;
} else if (found && view->current_page <= view->end_page) {
+ if (view->dual_page && j < 1) {
+ /* In dual mode we stop searching
+ * after two consecutive non-visible pages.
+ */
+ j++;
+ continue;
+ }
break;
}
}
+ if (view->pending_scroll == SCROLL_TO_KEEP_POSITION) {
+ best_current_page = MAX (best_current_page, view->start_page);
+
+ if (view->current_page != best_current_page) {
+ view->current_page = best_current_page;
+ ev_document_model_set_page (view->model, best_current_page);
+ }
+ }
} else if (view->dual_page) {
if (view->current_page % 2 == get_dual_even_left (view)) {
view->start_page = view->current_page;
if (view->current_page + 1 < ev_document_get_n_pages (view->document))
view->end_page = view->start_page + 1;
- else
+ else
view->end_page = view->start_page;
} else {
if (view->current_page < 1)
view->end_page = view->current_page;
}
- best_current_page = MAX (best_current_page, view->start_page);
- current_page = ev_document_model_get_page (view->model);
-
- if ((current_page != best_current_page) && (view->pending_scroll == SCROLL_TO_KEEP_POSITION)) {
- view->current_page = best_current_page;
- ev_document_model_set_page (view->model, best_current_page);
- }
-
if (start != view->start_page || end != view->end_page) {
gint i;
view->rotation,
view->scale,
view->selection_info.selections);
+
+ if (ev_pixbuf_cache_get_surface (view->pixbuf_cache, view->current_page))
+ gtk_widget_queue_draw (GTK_WIDGET (view));
}
static void
G_TYPE_BOOLEAN, horizontal);
}
+static gdouble
+compute_scroll_increment (EvView *view,
+ GtkScrollType scroll)
+{
+ GtkWidget *widget = GTK_WIDGET (view);
+ GtkAdjustment *adjustment = view->vadjustment;
+ GdkRegion *text_region, *region;
+ gint page;
+ GdkRectangle rect;
+ EvRectangle doc_rect;
+ GdkRectangle page_area;
+ GtkBorder border;
+ GdkRectangle *recs;
+ gint n_recs;
+ gdouble fraction = 1.0;
+
+ if (scroll != GTK_SCROLL_PAGE_BACKWARD && scroll != GTK_SCROLL_PAGE_FORWARD)
+ return adjustment->page_size;
+
+ page = scroll == GTK_SCROLL_PAGE_BACKWARD ? view->start_page : view->end_page;
+
+ text_region = ev_pixbuf_cache_get_text_mapping (view->pixbuf_cache, page);
+ if (!text_region || gdk_region_empty (text_region))
+ return adjustment->page_size;
+
+ get_page_extents (view, page, &page_area, &border);
+ rect.x = page_area.x + view->scroll_x;
+ rect.y = view->scroll_y + (scroll == GTK_SCROLL_PAGE_BACKWARD ? 5 : widget->allocation.height - 5);
+ rect.width = page_area.width;
+ rect.height = 1;
+ view_rect_to_doc_rect (view, &rect, &page_area, &doc_rect);
+
+ /* Convert the doc rectangle into a GdkRectangle */
+ rect.x = doc_rect.x1;
+ rect.y = doc_rect.y1;
+ rect.width = doc_rect.x2 - doc_rect.x1;
+ rect.height = MAX (1, doc_rect.y2 - doc_rect.y1);
+ region = gdk_region_rectangle (&rect);
+
+ gdk_region_intersect (region, text_region);
+ gdk_region_get_rectangles (region, &recs, &n_recs);
+ gdk_region_destroy (region);
+ if (n_recs > 0) {
+ EvRenderContext *rc;
+ EvPage *ev_page;
+
+ ev_page = ev_document_get_page (view->document, page);
+ rc = ev_render_context_new (ev_page, view->rotation, view->scale);
+ g_object_unref (ev_page);
+ /* Get the selection region to know the height of the line */
+ doc_rect.x1 = doc_rect.x2 = recs[0].x + 0.5;
+ doc_rect.y1 = doc_rect.y2 = recs[0].y + 0.5;
+
+ ev_document_doc_mutex_lock ();
+ region = ev_selection_get_selection_region (EV_SELECTION (view->document),
+ rc, EV_SELECTION_STYLE_LINE,
+ &doc_rect);
+ ev_document_doc_mutex_unlock ();
+
+ g_object_unref (rc);
+ g_free (recs);
+ gdk_region_get_rectangles (region, &recs, &n_recs);
+ gdk_region_destroy (region);
+ if (n_recs > 0) {
+ fraction = 1 - (recs[0].height / adjustment->page_size);
+ }
+ g_free (recs);
+ }
+
+ return adjustment->page_size * fraction;
+
+}
+
void
ev_view_scroll (EvView *view,
GtkScrollType scroll,
/* Assign values for increment and vertical adjustment */
adjustment = horizontal ? view->hadjustment : view->vadjustment;
- increment = adjustment->page_size * 0.75;
value = adjustment->value;
/* Assign boolean for first and last page */
ev_view_previous_page (view);
/* Jump to the top */
} else {
+ increment = compute_scroll_increment (view, GTK_SCROLL_PAGE_BACKWARD);
value = MAX (value - increment, adjustment->lower);
}
break;
ev_view_next_page (view);
/* Jump to the bottom */
} else {
+ increment = compute_scroll_increment (view, GTK_SCROLL_PAGE_FORWARD);
value = MIN (value + increment, adjustment->upper - adjustment->page_size);
}
break;
ev_view_handle_annotation (EvView *view,
EvAnnotation *annot,
gdouble x,
- gdouble y)
+ gdouble y,
+ guint32 timestamp)
{
if (EV_IS_ANNOTATION_MARKUP (annot)) {
GtkWidget *window;
}
}
}
+
+ if (EV_IS_ANNOTATION_ATTACHMENT (annot)) {
+ EvAttachment *attachment = EV_ANNOTATION_ATTACHMENT (annot)->attachment;
+
+ if (attachment) {
+ GError *error = NULL;
+
+ ev_attachment_open (attachment,
+ gtk_widget_get_screen (GTK_WIDGET (view)),
+ timestamp,
+ &error);
+
+ if (error) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ }
+ }
+ }
}
/*** GtkWidget implementation ***/
ev_view_size_request_continuous_dual_page (EvView *view,
GtkRequisition *requisition)
{
- int max_width;
gint n_pages;
- GtkBorder border;
-
- ev_view_get_max_page_size (view, &max_width, NULL);
- compute_border (view, max_width, max_width, &border);
n_pages = ev_document_get_n_pages (view->document) + 1;
-
- requisition->width = (max_width + border.left + border.right) * 2 + (view->spacing * 3);
get_page_y_offset (view, n_pages, &requisition->height);
- if (view->sizing_mode == EV_SIZING_FIT_WIDTH) {
- requisition->width = 1;
- } else if (view->sizing_mode == EV_SIZING_BEST_FIT) {
- requisition->width = 1;
- /* FIXME: This could actually be set on one page docs or docs
- * with a strange aspect ratio. */
- /* requisition->height = 1;*/
+ switch (view->sizing_mode) {
+ case EV_SIZING_FIT_WIDTH:
+ case EV_SIZING_BEST_FIT:
+ requisition->width = 1;
+
+ break;
+ case EV_SIZING_FREE: {
+ gint max_width;
+ GtkBorder border;
+
+ ev_view_get_max_page_size (view, &max_width, NULL);
+ compute_border (view, max_width, max_width, &border);
+ requisition->width = (max_width + border.left + border.right) * 2 + (view->spacing * 3);
+ }
+ break;
+ default:
+ g_assert_not_reached ();
}
}
ev_view_size_request_continuous (EvView *view,
GtkRequisition *requisition)
{
- int max_width;
- int n_pages;
- GtkBorder border;
+ gint n_pages;
- ev_view_get_max_page_size (view, &max_width, NULL);
n_pages = ev_document_get_n_pages (view->document);
- compute_border (view, max_width, max_width, &border);
-
- requisition->width = max_width + (view->spacing * 2) + border.left + border.right;
get_page_y_offset (view, n_pages, &requisition->height);
- if (view->sizing_mode == EV_SIZING_FIT_WIDTH) {
- requisition->width = 1;
- } else if (view->sizing_mode == EV_SIZING_BEST_FIT) {
- requisition->width = 1;
- /* FIXME: This could actually be set on one page docs or docs
- * with a strange aspect ratio. */
- /* requisition->height = 1;*/
+ switch (view->sizing_mode) {
+ case EV_SIZING_FIT_WIDTH:
+ case EV_SIZING_BEST_FIT:
+ requisition->width = 1;
+
+ break;
+ case EV_SIZING_FREE: {
+ gint max_width;
+ GtkBorder border;
+
+ ev_view_get_max_page_size (view, &max_width, NULL);
+ compute_border (view, max_width, max_width, &border);
+ requisition->width = max_width + (view->spacing * 2) + border.left + border.right;
+ }
+ break;
+ default:
+ g_assert_not_reached ();
}
}
GtkBorder border;
gint width, height;
+ if (view->sizing_mode == EV_SIZING_BEST_FIT) {
+ requisition->width = 1;
+ requisition->height = 1;
+
+ return;
+ }
+
/* Find the largest of the two. */
ev_view_get_page_size (view,
view->current_page,
}
compute_border (view, width, height, &border);
- requisition->width = ((width + border.left + border.right) * 2) +
- (view->spacing * 3);
- requisition->height = (height + border.top + border.bottom) +
- (view->spacing * 2);
-
- if (view->sizing_mode == EV_SIZING_FIT_WIDTH) {
- requisition->width = 1;
- } else if (view->sizing_mode == EV_SIZING_BEST_FIT) {
- requisition->width = 1;
- requisition->height = 1;
- }
+ requisition->width = view->sizing_mode == EV_SIZING_FIT_WIDTH ? 1 :
+ ((width + border.left + border.right) * 2) + (view->spacing * 3);
+ requisition->height = (height + border.top + border.bottom) + (view->spacing * 2);
}
static void
GtkBorder border;
gint width, height;
+ if (view->sizing_mode == EV_SIZING_BEST_FIT) {
+ requisition->width = 1;
+ requisition->height = 1;
+
+ return;
+ }
+
ev_view_get_page_size (view, view->current_page, &width, &height);
compute_border (view, width, height, &border);
- requisition->width = width + border.left + border.right + (2 * view->spacing);
+ requisition->width = view->sizing_mode == EV_SIZING_FIT_WIDTH ? 1 :
+ width + border.left + border.right + (2 * view->spacing);
requisition->height = height + border.top + border.bottom + (2 * view->spacing);
-
- if (view->sizing_mode == EV_SIZING_FIT_WIDTH) {
- requisition->width = 1;
- requisition->height = height + border.top + border.bottom + (2 * view->spacing);
- } else if (view->sizing_mode == EV_SIZING_BEST_FIT) {
- requisition->width = 1;
- requisition->height = 1;
- }
}
static void
state = event->state & gtk_accelerator_get_default_mod_mask ();
if (state == GDK_CONTROL_MASK && view->presentation == FALSE) {
- ev_view_set_sizing_mode (view, EV_SIZING_FREE);
-
+ ev_document_model_set_sizing_mode (view->model, EV_SIZING_FREE);
if (event->direction == GDK_SCROLL_UP ||
event->direction == GDK_SCROLL_LEFT) {
if (ev_view_can_zoom_in (view)) {
gdouble x,
gdouble y)
{
- EvLink *link;
- EvImage *image;
+ EvLink *link;
+ EvImage *image;
+ EvAnnotation *annot;
image = ev_view_get_image_at_location (view, x, y);
if (image) {
return TRUE;
}
+ annot = ev_view_get_annotation_at_location (view, x, y);
+ if (annot) {
+ g_signal_emit (view, signals[SIGNAL_POPUP_MENU], 0, annot);
+ return TRUE;
+ }
+
g_signal_emit (view, signals[SIGNAL_POPUP_MENU], 0, NULL);
return TRUE;
gtk_widget_queue_draw (widget);
} else if ((annot = ev_view_get_annotation_at_location (view, event->x, event->y))) {
- ev_view_handle_annotation (view, annot, event->x, event->y);
+ ev_view_handle_annotation (view, annot, event->x, event->y, event->time);
} else if ((field = ev_view_get_form_field_at_location (view, event->x, event->y))) {
ev_view_remove_all (view);
ev_view_handle_form_field (view, field, event->x, event->y);
static void
setup_caches (EvView *view)
{
+ gboolean inverted_colors;
+
view->height_to_page_cache = ev_view_get_height_to_page_cache (view);
view->pixbuf_cache = ev_pixbuf_cache_new (GTK_WIDGET (view), view->document);
+ inverted_colors = ev_document_model_get_inverted_colors (view->model);
+ ev_pixbuf_cache_set_inverted_colors (view->pixbuf_cache, inverted_colors);
g_signal_connect (view->pixbuf_cache, "job-finished", G_CALLBACK (job_finished_cb), view);
}
view->loading = FALSE;
if (document != view->document) {
+ gint current_page;
+
clear_caches (view);
if (view->document) {
setup_caches (view);
}
- ev_view_change_page (view,
- ev_document_model_get_page (model),
- TRUE);
+ current_page = ev_document_model_get_page (model);
+ if (view->current_page != current_page) {
+ ev_view_change_page (view, current_page, TRUE);
+ } else {
+ view->pending_scroll = SCROLL_TO_KEEP_POSITION;
+ gtk_widget_queue_resize (GTK_WIDGET (view));
+ }
}
}
clear_selection (view);
}
+static void
+ev_view_inverted_colors_changed_cb (EvDocumentModel *model,
+ GParamSpec *pspec,
+ EvView *view)
+{
+ if (view->pixbuf_cache) {
+ gboolean inverted_colors;
+
+ inverted_colors = ev_document_model_get_inverted_colors (model);
+ ev_pixbuf_cache_set_inverted_colors (view->pixbuf_cache, inverted_colors);
+ gtk_widget_queue_draw (GTK_WIDGET (view));
+ }
+}
+
static void
ev_view_sizing_mode_changed_cb (EvDocumentModel *model,
GParamSpec *pspec,
ev_view_set_zoom (view, scale);
view->pending_resize = TRUE;
- gtk_widget_queue_resize (GTK_WIDGET (view));
+ if (view->sizing_mode == EV_SIZING_FREE)
+ gtk_widget_queue_resize (GTK_WIDGET (view));
}
static void
g_signal_connect (view->model, "notify::rotation",
G_CALLBACK (ev_view_rotation_changed_cb),
view);
+ g_signal_connect (view->model, "notify::inverted-colors",
+ G_CALLBACK (ev_view_inverted_colors_changed_cb),
+ view);
g_signal_connect (view->model, "notify::sizing-mode",
G_CALLBACK (ev_view_sizing_mode_changed_cb),
view);
if (presentation) {
view->sizing_mode_saved = view->sizing_mode;
view->scale_saved = view->scale;
- ev_view_set_sizing_mode (view, EV_SIZING_BEST_FIT);
+ ev_document_model_set_sizing_mode (view->model, EV_SIZING_BEST_FIT);
} else {
ev_document_model_set_sizing_mode (view->model, view->sizing_mode_saved);
ev_document_model_set_scale (view->model, view->scale_saved);
int target_width,
int target_height)
{
- double scale;
-
- scale = (double)target_width / doc_width;
-
- if (doc_height * scale > target_height)
- scale = (double)target_width / doc_width;
-
- return scale;
+ return (double)target_width / doc_width;
}
static double
int target_width,
int target_height)
{
- double scale;
-
- scale = (double)target_height / doc_height;
-
- if (doc_width * scale > target_width)
- scale = (double)target_height / doc_height;
-
- return scale;
+ return (double)target_height / doc_height;
}
static double
w_scale = (double)target_width / doc_width;
h_scale = (double)target_height / doc_height;
- if (doc_height * w_scale > target_height)
- w_scale = (double)target_width / doc_width;
- if (doc_width * h_scale > target_width)
- h_scale = (double)target_height / doc_height;
-
return MIN (w_scale, h_scale);
}
width -= (2 * (border.left + border.right) + 3 * view->spacing);
height -= (border.top + border.bottom + 2 * view->spacing - 1);
- if (view->sizing_mode == EV_SIZING_FIT_WIDTH)
- scale = zoom_for_size_fit_width (doc_width, doc_height, width, height);
- else if (view->sizing_mode == EV_SIZING_BEST_FIT)
+ if (view->sizing_mode == EV_SIZING_FIT_WIDTH) {
+ gint sb_size;
+
+ sb_size = ev_view_get_scrollbar_size (view, GTK_ORIENTATION_VERTICAL);
+ scale = zoom_for_size_fit_width (doc_width, doc_height, width - sb_size, height);
+ } else if (view->sizing_mode == EV_SIZING_BEST_FIT)
scale = zoom_for_size_best_fit (doc_width, doc_height, width, height);
else
g_assert_not_reached ();
width -= (border.left + border.right + 2 * view->spacing);
height -= (border.top + border.bottom + 2 * view->spacing - 1);
- if (view->sizing_mode == EV_SIZING_FIT_WIDTH)
- scale = zoom_for_size_fit_width (doc_width, doc_height, width, height);
- else if (view->sizing_mode == EV_SIZING_BEST_FIT)
+ if (view->sizing_mode == EV_SIZING_FIT_WIDTH) {
+ gint sb_size;
+
+ sb_size = ev_view_get_scrollbar_size (view, GTK_ORIENTATION_VERTICAL);
+ scale = zoom_for_size_fit_width (doc_width, doc_height, width - sb_size, height);
+ } else if (view->sizing_mode == EV_SIZING_BEST_FIT)
scale = zoom_for_size_best_fit (doc_width, doc_height, width, height);
else
g_assert_not_reached ();
width -= ((border.left + border.right)* 2 + 3 * view->spacing);
height -= (border.top + border.bottom + 2 * view->spacing);
- if (view->sizing_mode == EV_SIZING_FIT_WIDTH)
- scale = zoom_for_size_fit_width (doc_width, doc_height, width, height);
- else if (view->sizing_mode == EV_SIZING_BEST_FIT)
+ if (view->sizing_mode == EV_SIZING_FIT_WIDTH) {
+ gint sb_size;
+
+ sb_size = ev_view_get_scrollbar_size (view, GTK_ORIENTATION_VERTICAL);
+ scale = zoom_for_size_fit_width (doc_width, doc_height, width - sb_size, height);
+ } else if (view->sizing_mode == EV_SIZING_BEST_FIT)
scale = zoom_for_size_best_fit (doc_width, doc_height, width, height);
else
g_assert_not_reached ();
width -= (border.left + border.right + 2 * view->spacing);
height -= (border.top + border.bottom + 2 * view->spacing);
- if (view->sizing_mode == EV_SIZING_FIT_WIDTH)
- scale = zoom_for_size_fit_width (doc_width, doc_height, width, height);
- else if (view->sizing_mode == EV_SIZING_BEST_FIT)
+ if (view->sizing_mode == EV_SIZING_FIT_WIDTH) {
+ gint sb_size;
+
+ sb_size = ev_view_get_scrollbar_size (view, GTK_ORIENTATION_VERTICAL);
+ scale = zoom_for_size_fit_width (doc_width, doc_height, width - sb_size, height);
+ } else if (view->sizing_mode == EV_SIZING_BEST_FIT)
scale = zoom_for_size_best_fit (doc_width, doc_height, width, height);
else
g_assert_not_reached ();