#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
-#include "ev-mapping.h"
+#include "ev-mapping-list.h"
#include "ev-document-forms.h"
#include "ev-document-images.h"
#include "ev-document-links.h"
+#include "ev-document-layers.h"
#include "ev-document-misc.h"
#include "ev-pixbuf-cache.h"
#include "ev-page-cache.h"
SIGNAL_EXTERNAL_LINK,
SIGNAL_POPUP_MENU,
SIGNAL_SELECTION_CHANGED,
+ SIGNAL_SYNC_SOURCE,
+ SIGNAL_ANNOT_ADDED,
+ SIGNAL_LAYERS_CHANGED,
N_SIGNALS
};
static void get_page_y_offset (EvView *view,
int page,
int *y_offset);
-static gboolean get_page_extents (EvView *view,
- gint page,
- GdkRectangle *page_area,
- GtkBorder *border);
static void view_rect_to_doc_rect (EvView *view,
GdkRectangle *view_rect,
GdkRectangle *page_area,
static AtkObject *ev_view_get_accessible (GtkWidget *widget);
/*** Drawing ***/
-static guint32 ev_gdk_color_to_rgb (const GdkColor *color);
-static void draw_rubberband (GtkWidget *widget,
- GdkWindow *window,
- const GdkRectangle *rect,
- guchar alpha);
static void highlight_find_results (EvView *view,
int page);
+static void highlight_forward_search_results (EvView *view,
+ int page);
+static void focus_annotation (EvView *view,
+ int page,
+ GdkRectangle *clip);
static void draw_one_page (EvView *view,
gint page,
cairo_t *cr,
static void hide_loading_window (EvView *view);
static void ev_view_reload_page (EvView *view,
gint page,
- GdkRegion *region);
+ cairo_region_t *region);
static void ev_view_loading_window_move (EvView *view);
/*** Callbacks ***/
static void ev_view_change_page (EvView *view,
gint new_page);
static void job_finished_cb (EvPixbufCache *pixbuf_cache,
- GdkRegion *region,
+ cairo_region_t *region,
EvView *view);
static void ev_view_page_changed_cb (EvDocumentModel *model,
gint old_page,
static void jump_to_find_page (EvView *view,
EvViewFindDirection direction,
gint shift);
-
/*** Selection ***/
static void compute_selections (EvView *view,
EvSelectionStyle style,
GtkWidget *widget = GTK_WIDGET (view);
GtkWidget *sb;
GtkWidget *swindow = gtk_widget_get_parent (GTK_WIDGET (view));
+ GtkAllocation allocation;
GtkRequisition req;
gint spacing;
if (!GTK_IS_SCROLLED_WINDOW (swindow))
return 0;
+ gtk_widget_get_allocation (widget, &allocation);
+
if (orientation == GTK_ORIENTATION_VERTICAL) {
- if (widget->allocation.height >= view->requisition.height)
+ if (allocation.height >= view->requisition.height)
sb = gtk_scrolled_window_get_vscrollbar (GTK_SCROLLED_WINDOW (swindow));
else
return 0;
} else {
- if (widget->allocation.width >= view->requisition.width)
+ if (allocation.width >= view->requisition.width)
sb = gtk_scrolled_window_get_hscrollbar (GTK_SCROLLED_WINDOW (swindow));
else
return 0;
gdouble y,
GtkOrientation orientation)
{
+ gdouble page_size;
+ gdouble upper, lower;
+
if (orientation == GTK_ORIENTATION_VERTICAL) {
+ page_size = gtk_adjustment_get_page_size (view->vadjustment);
+ upper = gtk_adjustment_get_upper (view->vadjustment);
+ lower = gtk_adjustment_get_lower (view->vadjustment);
+
if (view->continuous) {
gtk_adjustment_clamp_page (view->vadjustment,
y - view->spacing / 2,
- y + view->vadjustment->page_size);
+ y + page_size);
} else {
gtk_adjustment_set_value (view->vadjustment,
- CLAMP (y,
- view->vadjustment->lower,
- view->vadjustment->upper -
- view->vadjustment->page_size));
+ CLAMP (y, lower, upper - page_size));
}
} else {
+ page_size = gtk_adjustment_get_page_size (view->hadjustment);
+ upper = gtk_adjustment_get_upper (view->hadjustment);
+ lower = gtk_adjustment_get_lower (view->hadjustment);
+
if (view->dual_page) {
gtk_adjustment_clamp_page (view->hadjustment, x,
- x + view->hadjustment->page_size);
+ x + page_size);
} else {
gtk_adjustment_set_value (view->hadjustment,
- CLAMP (x,
- view->hadjustment->lower,
- view->hadjustment->upper -
- view->hadjustment->page_size));
+ CLAMP (x, lower, upper - page_size));
}
}
}
GdkRectangle page_area;
GtkBorder border;
- get_page_extents (view, view->current_page, &page_area, &border);
+ ev_view_get_page_extents (view, view->current_page, &page_area, &border);
x = page_area.x;
y = page_area.y;
} else {
{
GtkWidget *widget = GTK_WIDGET (view);
GtkAdjustment *adjustment;
- int requisition;
- int allocation;
-
+ GtkAllocation allocation;
+ int req_size;
+ int alloc_size;
+ gdouble page_size;
+ gdouble value;
+ gdouble upper;
double factor;
gint new_value;
+ gtk_widget_get_allocation (widget, &allocation);
+
if (orientation == GTK_ORIENTATION_HORIZONTAL) {
- requisition = view->requisition.width;
- allocation = widget->allocation.width;
+ req_size = view->requisition.width;
+ alloc_size = allocation.width;
adjustment = view->hadjustment;
} else {
- requisition = view->requisition.height;
- allocation = widget->allocation.height;
+ req_size = view->requisition.height;
+ alloc_size = allocation.height;
adjustment = view->vadjustment;
}
return;
factor = 1.0;
+ value = gtk_adjustment_get_value (adjustment);
+ upper = gtk_adjustment_get_upper (adjustment);
+ page_size = gtk_adjustment_get_page_size (adjustment);
+
switch (view->pending_scroll) {
case SCROLL_TO_KEEP_POSITION:
case SCROLL_TO_FIND_LOCATION:
- factor = (adjustment->value) / adjustment->upper;
+ factor = value / upper;
break;
case SCROLL_TO_PAGE_POSITION:
break;
case SCROLL_TO_CENTER:
- factor = (adjustment->value + adjustment->page_size * 0.5) / adjustment->upper;
+ factor = (value + page_size * 0.5) / upper;
break;
}
- adjustment->page_size = allocation;
- adjustment->step_increment = allocation * 0.1;
- adjustment->page_increment = allocation * 0.9;
- adjustment->lower = 0;
- adjustment->upper = MAX (allocation, requisition);
+ upper = MAX (alloc_size, req_size);
+ page_size = alloc_size;
+
+ gtk_adjustment_set_page_size (adjustment, page_size);
+ gtk_adjustment_set_step_increment (adjustment, alloc_size * 0.1);
+ gtk_adjustment_set_page_increment (adjustment, alloc_size * 0.9);
+ gtk_adjustment_set_lower (adjustment, 0);
+ gtk_adjustment_set_upper (adjustment, upper);
/*
* We add 0.5 to the values before to average out our rounding errors.
switch (view->pending_scroll) {
case SCROLL_TO_KEEP_POSITION:
case SCROLL_TO_FIND_LOCATION:
- new_value = CLAMP (adjustment->upper * factor + 0.5, 0, adjustment->upper - adjustment->page_size);
+ new_value = CLAMP (upper * factor + 0.5, 0, upper - page_size);
gtk_adjustment_set_value (adjustment, (int)new_value);
break;
case SCROLL_TO_PAGE_POSITION:
ev_view_scroll_to_page_position (view, orientation);
break;
case SCROLL_TO_CENTER:
- new_value = CLAMP (adjustment->upper * factor - adjustment->page_size * 0.5 + 0.5,
- 0, adjustment->upper - adjustment->page_size);
+ new_value = CLAMP (upper * factor - page_size * 0.5 + 0.5,
+ 0, upper - page_size);
gtk_adjustment_set_value (adjustment, (int)new_value);
break;
}
if (!(view->vadjustment && view->hadjustment))
return;
- current_area.x = view->hadjustment->value;
- current_area.width = view->hadjustment->page_size;
- current_area.y = view->vadjustment->value;
- current_area.height = view->vadjustment->page_size;
+ current_area.x = gtk_adjustment_get_value (view->hadjustment);
+ current_area.width = gtk_adjustment_get_page_size (view->hadjustment);
+ current_area.y = gtk_adjustment_get_value (view->vadjustment);
+ current_area.height = gtk_adjustment_get_page_size (view->vadjustment);
for (i = 0; i < ev_document_get_n_pages (view->document); i++) {
- get_page_extents (view, i, &page_area, &border);
+ ev_view_get_page_extents (view, i, &page_area, &border);
if (gdk_rectangle_intersect (¤t_area, &page_area, &unused)) {
area = unused.width * unused.height;
ev_pixbuf_cache_set_page_range (view->pixbuf_cache,
view->start_page,
view->end_page,
- view->rotation,
- view->scale,
view->selection_info.selections);
if (ev_pixbuf_cache_get_surface (view->pixbuf_cache, view->current_page))
{
GtkWidget *widget = GTK_WIDGET (view);
GtkAdjustment *adjustment = view->vadjustment;
- GdkRegion *text_region, *region;
+ cairo_region_t *text_region, *region;
+ GtkAllocation allocation;
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;
+ return gtk_adjustment_get_page_size (adjustment);
page = scroll == GTK_SCROLL_PAGE_BACKWARD ? view->start_page : view->end_page;
text_region = ev_page_cache_get_text_mapping (view->page_cache, page);
- if (!text_region || gdk_region_empty (text_region))
- return adjustment->page_size;
+ if (!text_region || cairo_region_is_empty (text_region))
+ return gtk_adjustment_get_page_size (adjustment);
- get_page_extents (view, page, &page_area, &border);
+ gtk_widget_get_allocation (widget, &allocation);
+ ev_view_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.y = view->scroll_y + (scroll == GTK_SCROLL_PAGE_BACKWARD ? 5 : allocation.height - 5);
rect.width = page_area.width;
rect.height = 1;
view_rect_to_doc_rect (view, &rect, &page_area, &doc_rect);
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);
+ region = cairo_region_create_rectangle (&rect);
- gdk_region_intersect (region, text_region);
- gdk_region_get_rectangles (region, &recs, &n_recs);
- gdk_region_destroy (region);
- if (n_recs > 0) {
+ cairo_region_intersect (region, text_region);
+ if (cairo_region_num_rectangles (region)) {
EvRenderContext *rc;
EvPage *ev_page;
+ cairo_region_t *sel_region;
+ cairo_region_get_rectangle (region, 0, &rect);
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;
+ doc_rect.x1 = doc_rect.x2 = rect.x + 0.5;
+ doc_rect.y1 = doc_rect.y2 = rect.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);
+ sel_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);
+
+ if (cairo_region_num_rectangles (sel_region) > 0) {
+ cairo_region_get_rectangle (sel_region, 0, &rect);
+ fraction = 1 - (rect.height / gtk_adjustment_get_page_size (adjustment));
}
- g_free (recs);
+ cairo_region_destroy (sel_region);
}
+ cairo_region_destroy (region);
- return adjustment->page_size * fraction;
+ return gtk_adjustment_get_page_size (adjustment) * fraction;
}
{
GtkAdjustment *adjustment;
double value, increment;
+ gdouble upper, lower;
+ gdouble page_size;
+ gdouble step_increment;
gboolean first_page = FALSE;
gboolean last_page = FALSE;
/* Assign values for increment and vertical adjustment */
adjustment = horizontal ? view->hadjustment : view->vadjustment;
- value = adjustment->value;
+ value = gtk_adjustment_get_value (adjustment);
+ upper = gtk_adjustment_get_upper (adjustment);
+ lower = gtk_adjustment_get_lower (adjustment);
+ page_size = gtk_adjustment_get_page_size (adjustment);
+ step_increment = gtk_adjustment_get_step_increment (adjustment);
/* Assign boolean for first and last page */
if (view->current_page == 0)
switch (scroll) {
case GTK_SCROLL_PAGE_BACKWARD:
/* Do not jump backwards if at the first page */
- if (value == (adjustment->lower) && first_page) {
+ if (value == lower && first_page) {
/* Do nothing */
/* At the top of a page, assign the upper bound limit of previous page */
- } else if (value == (adjustment->lower)) {
- value = adjustment->upper - adjustment->page_size;
+ } else if (value == lower) {
+ value = upper - page_size;
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);
+ value = MAX (value - increment, lower);
}
break;
case GTK_SCROLL_PAGE_FORWARD:
/* Do not jump forward if at the last page */
- if (value == (adjustment->upper - adjustment->page_size) && last_page) {
+ if (value == (upper - page_size) && last_page) {
/* Do nothing */
/* At the bottom of a page, assign the lower bound limit of next page */
- } else if (value == (adjustment->upper - adjustment->page_size)) {
+ } else if (value == (upper - page_size)) {
value = 0;
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);
+ value = MIN (value + increment, upper - page_size);
}
break;
case GTK_SCROLL_STEP_BACKWARD:
- value -= adjustment->step_increment;
+ value -= step_increment;
break;
case GTK_SCROLL_STEP_FORWARD:
- value += adjustment->step_increment;
+ value += step_increment;
break;
case GTK_SCROLL_STEP_DOWN:
- value -= adjustment->step_increment / 10;
+ value -= step_increment / 10;
break;
case GTK_SCROLL_STEP_UP:
- value += adjustment->step_increment / 10;
+ value += step_increment / 10;
break;
default:
break;
}
- value = CLAMP (value, adjustment->lower,
- adjustment->upper - adjustment->page_size);
+ value = CLAMP (value, lower, upper - page_size);
gtk_adjustment_set_value (adjustment, value);
}
{
GtkWidget *widget = GTK_WIDGET (view);
GtkAdjustment *adjustment;
+ GtkAllocation allocation;
+ gdouble adj_value;
int value;
view->pending_scroll = SCROLL_TO_FIND_LOCATION;
+ gtk_widget_get_allocation (widget, &allocation);
+
adjustment = view->vadjustment;
+ adj_value = gtk_adjustment_get_value (adjustment);
- if (rect->y < adjustment->value) {
- value = MAX (adjustment->lower, rect->y - MARGIN);
+ if (rect->y < adj_value) {
+ value = MAX (gtk_adjustment_get_lower (adjustment), rect->y - MARGIN);
gtk_adjustment_set_value (view->vadjustment, value);
- } else if (rect->y + rect->height >
- adjustment->value + widget->allocation.height) {
- value = MIN (adjustment->upper, rect->y + rect->height -
- widget->allocation.height + MARGIN);
+ } else if (rect->y + rect->height > adj_value + allocation.height) {
+ value = MIN (gtk_adjustment_get_upper (adjustment), rect->y + rect->height -
+ allocation.height + MARGIN);
gtk_adjustment_set_value (view->vadjustment, value);
}
adjustment = view->hadjustment;
+ adj_value = gtk_adjustment_get_value (adjustment);
- if (rect->x < adjustment->value) {
- value = MAX (adjustment->lower, rect->x - MARGIN);
+ if (rect->x < adj_value) {
+ value = MAX (gtk_adjustment_get_lower (adjustment), rect->x - MARGIN);
gtk_adjustment_set_value (view->hadjustment, value);
- } else if (rect->x + rect->height >
- adjustment->value + widget->allocation.width) {
- value = MIN (adjustment->upper, rect->x + rect->width -
- widget->allocation.width + MARGIN);
+ } else if (rect->x + rect->height > adj_value + allocation.width) {
+ value = MIN (gtk_adjustment_get_upper (adjustment), rect->x + rect->width -
+ allocation.width + MARGIN);
gtk_adjustment_set_value (view->hadjustment, value);
}
return;
}
-static gboolean
-get_page_extents (EvView *view,
- gint page,
- GdkRectangle *page_area,
- GtkBorder *border)
+gboolean
+ev_view_get_page_extents (EvView *view,
+ gint page,
+ GdkRectangle *page_area,
+ GtkBorder *border)
{
GtkWidget *widget;
int width, height;
+ GtkAllocation allocation;
widget = GTK_WIDGET (view);
+ gtk_widget_get_allocation (widget, &allocation);
/* Get the size of the page */
ev_view_get_page_size (view, page, &width, &height);
/* Get the location of the bounding box */
if (view->dual_page) {
x = view->spacing + ((page % 2 == get_dual_even_left (view)) ? 0 : 1) * (max_width + view->spacing);
- x = x + MAX (0, widget->allocation.width - (max_width * 2 + view->spacing * 3)) / 2;
+ x = x + MAX (0, allocation.width - (max_width * 2 + view->spacing * 3)) / 2;
if (page % 2 == get_dual_even_left (view))
x = x + (max_width - width - border->left - border->right);
} else {
x = view->spacing;
- x = x + MAX (0, widget->allocation.width - (width + view->spacing * 2)) / 2;
+ x = x + MAX (0, allocation.width - (width + view->spacing * 2)) / 2;
}
get_page_y_offset (view, page, &y);
y = y + (max_height - height)/2;
/* Adjust for extra allocation */
- x = x + MAX (0, widget->allocation.width -
+ x = x + MAX (0, allocation.width -
((max_width + overall_border.left + overall_border.right) * 2 + view->spacing * 3))/2;
- y = y + MAX (0, widget->allocation.height - (height + view->spacing * 2))/2;
+ y = y + MAX (0, allocation.height - (height + view->spacing * 2))/2;
} else {
x = view->spacing;
y = view->spacing;
/* Adjust for extra allocation */
- x = x + MAX (0, widget->allocation.width - (width + border->left + border->right + view->spacing * 2))/2;
- y = y + MAX (0, widget->allocation.height - (height + border->top + border->bottom + view->spacing * 2))/2;
+ x = x + MAX (0, allocation.width - (width + border->left + border->right + view->spacing * 2))/2;
+ y = y + MAX (0, allocation.height - (height + border->top + border->bottom + view->spacing * 2))/2;
}
page_area->x = x;
g_assert_not_reached ();
}
- get_page_extents (view, page, &page_area, &border);
+ ev_view_get_page_extents (view, page, &page_area, &border);
view_x = CLAMP (x * view->scale, 0, page_area.width);
view_y = CLAMP (y * view->scale, 0, page_area.height);
g_assert_not_reached ();
}
- get_page_extents (view, page, &page_area, &border);
+ ev_view_get_page_extents (view, page, &page_area, &border);
view_rect->x = x * view->scale + page_area.x;
view_rect->y = y * view->scale + page_area.y;
GdkRectangle page_area;
GtkBorder border;
- if (! get_page_extents (view, i, &page_area, &border))
+ if (! ev_view_get_page_extents (view, i, &page_area, &border))
continue;
if ((x >= page_area.x + border.left) &&
gdouble x,
gdouble y)
{
- GdkRegion *region;
+ cairo_region_t *region;
gint page = -1;
gint x_offset = 0, y_offset = 0;
region = ev_page_cache_get_text_mapping (view->page_cache, page);
if (region)
- return gdk_region_point_in (region, x_offset / view->scale, y_offset / view->scale);
+ return cairo_region_contains_point (region, x_offset / view->scale, y_offset / view->scale);
else
return FALSE;
}
-static int
-ev_view_get_width (EvView *view)
-{
- return GTK_WIDGET (view)->allocation.width;
-}
-
-static int
-ev_view_get_height (EvView *view)
-{
- return GTK_WIDGET (view)->allocation.height;
-}
-
static gboolean
location_in_selected_text (EvView *view,
gdouble x,
continue;
if (selection->covered_region &&
- gdk_region_point_in (selection->covered_region, x_offset, y_offset))
+ cairo_region_contains_point (selection->covered_region, x_offset, y_offset))
return TRUE;
}
}
static void
-ev_view_get_area_from_mapping (EvView *view,
- guint page,
- GList *mapping_list,
- gconstpointer data,
- GdkRectangle *area)
+ev_view_get_area_from_mapping (EvView *view,
+ guint page,
+ EvMappingList *mapping_list,
+ gconstpointer data,
+ GdkRectangle *area)
{
EvMapping *mapping;
{
gint page = -1;
gint x_new = 0, y_new = 0;
- GList *link_mapping;
+ EvMappingList *link_mapping;
if (!EV_IS_DOCUMENT_LINKS (view->document))
return NULL;
EvPoint doc_point;
gdouble zoom, left, top;
gboolean change_left, change_top;
+ GtkAllocation allocation;
+
+ gtk_widget_get_allocation (GTK_WIDGET (view), &allocation);
left = ev_link_dest_get_left (dest, &change_left);
top = ev_link_dest_get_top (dest, &change_top);
zoom = zoom_for_size_best_fit (ev_link_dest_get_right (dest) - left,
ev_link_dest_get_bottom (dest) - top,
- ev_view_get_width (view),
- ev_view_get_height (view));
+ allocation.width,
+ allocation.height);
ev_document_model_set_sizing_mode (view->model, EV_SIZING_FREE);
ev_document_model_set_scale (view->model, zoom);
gint page;
double zoom, left;
gboolean change_left;
+ GtkAllocation allocation;
+
+ gtk_widget_get_allocation (GTK_WIDGET (view), &allocation);
page = ev_link_dest_get_page (dest);
ev_document_get_page_size (view->document, page, &doc_width, &doc_height);
doc_point.y = 0;
zoom = zoom_for_size_fit_height (doc_width - doc_point.x , doc_height,
- ev_view_get_width (view),
- ev_view_get_height (view));
+ allocation.width,
+ allocation.height);
ev_document_model_set_sizing_mode (view->model, EV_SIZING_FREE);
ev_document_model_set_scale (view->model, zoom);
gint page;
gdouble zoom, top;
gboolean change_top;
+ GtkAllocation allocation;
+
+ gtk_widget_get_allocation (GTK_WIDGET (view), &allocation);
page = ev_link_dest_get_page (dest);
ev_document_get_page_size (view->document, page, &doc_width, &doc_height);
doc_point.y = change_top ? top : 0;
zoom = zoom_for_size_fit_width (doc_width, top,
- ev_view_get_width (view),
- ev_view_get_height (view));
+ allocation.width,
+ allocation.height);
ev_document_model_set_sizing_mode (view->model, EV_SIZING_FIT_WIDTH);
ev_document_model_set_scale (view->model, zoom);
double zoom;
gdouble doc_width, doc_height;
int page;
+ GtkAllocation allocation;
+
+ gtk_widget_get_allocation (GTK_WIDGET (view), &allocation);
page = ev_link_dest_get_page (dest);
ev_document_get_page_size (view->document, page, &doc_width, &doc_height);
zoom = zoom_for_size_best_fit (doc_width, doc_height,
- ev_view_get_width (view),
- ev_view_get_height (view));
+ allocation.width,
+ allocation.height);
ev_document_model_set_sizing_mode (view->model, EV_SIZING_BEST_FIT);
ev_document_model_set_scale (view->model, zoom);
ev_view_goto_dest (view, dest);
}
break;
+ case EV_LINK_ACTION_TYPE_LAYERS_STATE: {
+ GList *show, *hide, *toggle;
+ GList *l;
+ EvDocumentLayers *document_layers;
+
+ document_layers = EV_DOCUMENT_LAYERS (view->document);
+
+ show = ev_link_action_get_show_list (action);
+ for (l = show; l; l = g_list_next (l)) {
+ ev_document_layers_show_layer (document_layers, EV_LAYER (l->data));
+ }
+
+ hide = ev_link_action_get_hide_list (action);
+ for (l = hide; l; l = g_list_next (l)) {
+ ev_document_layers_hide_layer (document_layers, EV_LAYER (l->data));
+ }
+
+ toggle = ev_link_action_get_toggle_list (action);
+ for (l = toggle; l; l = g_list_next (l)) {
+ EvLayer *layer = EV_LAYER (l->data);
+
+ if (ev_document_layers_layer_is_visible (document_layers, layer)) {
+ ev_document_layers_hide_layer (document_layers, layer);
+ } else {
+ ev_document_layers_show_layer (document_layers, layer);
+ }
+ }
+
+ g_signal_emit (view, signals[SIGNAL_LAYERS_CHANGED], 0);
+ ev_view_reload_page (view, view->current_page, NULL);
+ }
+ break;
case EV_LINK_ACTION_TYPE_GOTO_REMOTE:
case EV_LINK_ACTION_TYPE_EXTERNAL_URI:
case EV_LINK_ACTION_TYPE_LAUNCH:
if (view->cursor == EV_VIEW_CURSOR_HIDDEN)
return;
+ if (view->adding_annot) {
+ if (view->cursor != EV_VIEW_CURSOR_ADD)
+ ev_view_set_cursor (view, EV_VIEW_CURSOR_ADD);
+ return;
+ }
+
if (view->drag_info.in_drag) {
if (view->cursor != EV_VIEW_CURSOR_DRAG)
ev_view_set_cursor (view, EV_VIEW_CURSOR_DRAG);
if (view->cursor == EV_VIEW_CURSOR_LINK ||
view->cursor == EV_VIEW_CURSOR_IBEAM ||
view->cursor == EV_VIEW_CURSOR_DRAG ||
- view->cursor == EV_VIEW_CURSOR_AUTOSCROLL)
+ view->cursor == EV_VIEW_CURSOR_AUTOSCROLL ||
+ view->cursor == EV_VIEW_CURSOR_ADD)
ev_view_set_cursor (view, EV_VIEW_CURSOR_NORMAL);
}
{
gint page = -1;
gint x_new = 0, y_new = 0;
- GList *image_mapping;
+ EvMappingList *image_mapping;
if (!EV_IS_DOCUMENT_IMAGES (view->document))
return NULL;
{
gint page = -1;
gint x_new = 0, y_new = 0;
- GList *forms_mapping;
+ EvMappingList *forms_mapping;
if (!EV_IS_DOCUMENT_FORMS (view->document))
return NULL;
return NULL;
}
-static GdkRegion *
+static cairo_region_t *
ev_view_form_field_get_region (EvView *view,
EvFormField *field)
{
- GdkRectangle view_area;
- GList *forms_mapping;
+ GdkRectangle view_area;
+ EvMappingList *forms_mapping;
forms_mapping = ev_page_cache_get_form_field_mapping (view->page_cache,
field->page->index);
forms_mapping,
field, &view_area);
- return gdk_region_rectangle (&view_area);
+ return cairo_region_create_rectangle (&view_area);
}
static gboolean
EvFormField *field)
{
EvFormFieldButton *field_button = EV_FORM_FIELD_BUTTON (field);
- GdkRegion *field_region = NULL;
+ cairo_region_t *field_region = NULL;
switch (field_button->type) {
case EV_FORM_FIELD_BUTTON_PUSH:
return NULL;
case EV_FORM_FIELD_BUTTON_CHECK:
case EV_FORM_FIELD_BUTTON_RADIO: {
- gboolean state;
- GList *forms_mapping, *l;
+ gboolean state;
+ EvMappingList *forms_mapping;
+ GList *l;
state = ev_document_forms_form_field_button_get_state (EV_DOCUMENT_FORMS (view->document),
field);
*/
forms_mapping = ev_page_cache_get_form_field_mapping (view->page_cache,
field->page->index);
- for (l = forms_mapping; l; l = g_list_next (l)) {
+ for (l = ev_mapping_list_get_list (forms_mapping); l; l = g_list_next (l)) {
EvFormField *button = ((EvMapping *)(l->data))->data;
- GdkRegion *button_region;
+ cairo_region_t *button_region;
if (button->id == field->id)
continue;
continue;
button_region = ev_view_form_field_get_region (view, button);
- gdk_region_union (field_region, button_region);
- gdk_region_destroy (button_region);
+ cairo_region_union (field_region, button_region);
+ cairo_region_destroy (button_region);
}
ev_document_forms_form_field_button_set_state (EV_DOCUMENT_FORMS (view->document),
}
ev_view_reload_page (view, field->page->index, field_region);
- gdk_region_destroy (field_region);
+ cairo_region_destroy (field_region);
return NULL;
}
if (field->changed) {
EvFormFieldText *field_text = EV_FORM_FIELD_TEXT (field);
- GdkRegion *field_region;
+ cairo_region_t *field_region;
field_region = ev_view_form_field_get_region (view, field);
field, field_text->text);
field->changed = FALSE;
ev_view_reload_page (view, field->page->index, field_region);
- gdk_region_destroy (field_region);
+ cairo_region_destroy (field_region);
}
}
if (field->changed) {
GList *l;
EvFormFieldChoice *field_choice = EV_FORM_FIELD_CHOICE (field);
- GdkRegion *field_region;
+ cairo_region_t *field_region;
field_region = ev_view_form_field_get_region (view, field);
}
field->changed = FALSE;
ev_view_reload_page (view, field->page->index, field_region);
- gdk_region_destroy (field_region);
+ cairo_region_destroy (field_region);
}
}
g_signal_connect (choice, "changed",
G_CALLBACK (ev_view_form_field_choice_changed),
field);
- g_signal_connect_after (GTK_BIN(choice)->child, "activate",
+ g_signal_connect_after (gtk_bin_get_child (GTK_BIN (choice)),
+ "activate",
G_CALLBACK (ev_view_form_field_destroy),
view);
} else { /* ComboBoxText */
gdouble x,
gdouble y)
{
- GtkWidget *field_widget = NULL;
- GList *form_field_mapping;
- GdkRectangle view_area;
+ GtkWidget *field_widget = NULL;
+ EvMappingList *form_field_mapping;
+ GdkRectangle view_area;
if (field->is_read_only)
return;
gint x,
gint y)
{
+ GtkAllocation allocation;
+ gint width, height;
+
+ gtk_widget_get_allocation (GTK_WIDGET (view), &allocation);
+ gtk_window_get_size (GTK_WINDOW (child->window), &width, &height);
+
child->x = x;
child->y = y;
gtk_window_move (GTK_WINDOW (child->window),
- MAX (child->parent_x, x),
- MAX (child->parent_y, y));
+ CLAMP (x, child->parent_x,
+ child->parent_x + allocation.width - width),
+ CLAMP (y, child->parent_y,
+ child->parent_y + allocation.height - height));
}
static void
continue;
wannot = ev_annotation_window_get_annotation (EV_ANNOTATION_WINDOW (child->window));
- if (wannot == annot || strcmp (wannot->name, annot->name) == 0)
+ if (ev_annotation_equal (wannot, annot))
return child;
}
view_rect.width = width;
view_rect.height = height;
- get_page_extents (view, child->page, &page_area, &border);
+ ev_view_get_page_extents (view, child->page, &page_area, &border);
view_rect_to_doc_rect (view, &view_rect, &page_area, &doc_rect);
child->orig_x = doc_rect.x1;
child->orig_y = doc_rect.y1;
}
static void
-ev_view_annotation_save (EvView *view,
- EvAnnotation *annot)
+ev_view_annotation_save_contents (EvView *view,
+ GParamSpec *pspec,
+ EvAnnotation *annot)
{
if (!view->document)
return;
- if (!annot->changed)
- return;
+ ev_document_doc_mutex_lock ();
+ ev_document_annotations_save_annotation (EV_DOCUMENT_ANNOTATIONS (view->document),
+ annot, EV_ANNOTATIONS_SAVE_CONTENTS);
+ ev_document_doc_mutex_unlock ();
+}
- ev_document_annotations_annotation_set_contents (EV_DOCUMENT_ANNOTATIONS (view->document),
- annot, annot->contents);
- annot->changed = FALSE;
+static GtkWidget *
+ev_view_create_annotation_window (EvView *view,
+ EvAnnotation *annot,
+ GtkWindow *parent)
+{
+ GtkWidget *window;
+ EvRectangle doc_rect;
+ GdkRectangle view_rect;
+ guint page;
+
+ window = ev_annotation_window_new (annot, parent);
+ g_signal_connect (window, "grab_focus",
+ G_CALLBACK (annotation_window_grab_focus),
+ view);
+ g_signal_connect (window, "closed",
+ G_CALLBACK (annotation_window_closed),
+ view);
+ g_signal_connect (window, "moved",
+ G_CALLBACK (annotation_window_moved),
+ view);
+ g_signal_connect_swapped (annot, "notify::contents",
+ G_CALLBACK (ev_view_annotation_save_contents),
+ view);
+ g_object_set_data (G_OBJECT (annot), "popup", window);
+
+ page = ev_annotation_get_page_index (annot);
+ ev_annotation_window_get_rectangle (EV_ANNOTATION_WINDOW (window), &doc_rect);
+ doc_rect_to_view_rect (view, page, &doc_rect, &view_rect);
+ view_rect.x -= view->scroll_x;
+ view_rect.y -= view->scroll_y;
+
+ ev_view_window_child_put (view, window, page,
+ view_rect.x, view_rect.y,
+ doc_rect.x1, doc_rect.y1);
+
+ return window;
}
static void
show_annotation_windows (EvView *view,
gint page)
{
- GList *annots, *l;
- GtkWindow *parent;
+ EvMappingList *annots;
+ GList *l;
+ GtkWindow *parent;
parent = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (view)));
annots = ev_page_cache_get_annot_mapping (view->page_cache, page);
- for (l = annots; l && l->data; l = g_list_next (l)) {
+ for (l = ev_mapping_list_get_list (annots); l && l->data; l = g_list_next (l)) {
EvAnnotation *annot;
EvViewWindowChild *child;
GtkWidget *window;
- EvRectangle *doc_rect;
- GdkRectangle view_rect;
annot = ((EvMapping *)(l->data))->data;
g_object_set_data (G_OBJECT (annot), "popup", window);
ev_view_window_child_move_with_parent (view, window);
} else {
- window = ev_annotation_window_new (annot, parent);
- g_signal_connect (window, "grab_focus",
- G_CALLBACK (annotation_window_grab_focus),
- view);
- g_signal_connect (window, "closed",
- G_CALLBACK (annotation_window_closed),
- view);
- g_signal_connect (window, "moved",
- G_CALLBACK (annotation_window_moved),
- view);
- g_object_set_data (G_OBJECT (annot), "popup", window);
-
- doc_rect = (EvRectangle *)ev_annotation_window_get_rectangle (EV_ANNOTATION_WINDOW (window));
- doc_rect_to_view_rect (view, page, doc_rect, &view_rect);
- view_rect.x -= view->scroll_x;
- view_rect.y -= view->scroll_y;
-
- ev_view_window_child_put (view, window, page,
- view_rect.x, view_rect.y,
- doc_rect->x1, doc_rect->y1);
-
- g_object_weak_ref (G_OBJECT (annot),
- (GWeakNotify)ev_view_annotation_save,
- view);
+ ev_view_create_annotation_window (view, annot, parent);
}
}
}
hide_annotation_windows (EvView *view,
gint page)
{
- GList *annots, *l;
+ EvMappingList *annots;
+ GList *l;
annots = ev_page_cache_get_annot_mapping (view->page_cache, page);
- for (l = annots; l && l->data; l = g_list_next (l)) {
+ for (l = ev_mapping_list_get_list (annots); l && l->data; l = g_list_next (l)) {
EvAnnotation *annot;
GtkWidget *window;
{
gint page = -1;
gint x_new = 0, y_new = 0;
- GList *annotations_mapping;
+ EvMappingList *annotations_mapping;
if (!EV_IS_DOCUMENT_ANNOTATIONS (view->document))
return NULL;
return NULL;
}
+static void
+ev_view_annotation_show_popup_window (EvView *view,
+ GtkWidget *window)
+{
+ EvViewWindowChild *child;
+
+ if (!window)
+ return;
+
+ child = ev_view_get_window_child (view, window);
+ if (!child->visible) {
+ child->visible = TRUE;
+ ev_view_window_child_move (view, child, child->x, child->y);
+ gtk_widget_show (window);
+ }
+}
+
static void
ev_view_handle_annotation (EvView *view,
EvAnnotation *annot,
GtkWidget *window;
window = g_object_get_data (G_OBJECT (annot), "popup");
- if (window) {
- EvViewWindowChild *child;
-
- child = ev_view_get_window_child (view, window);
- if (!child->visible) {
- child->visible = TRUE;
- ev_view_window_child_move (view, child, child->x, child->y);
- gtk_widget_show (window);
- }
- }
+ ev_view_annotation_show_popup_window (view, window);
}
if (EV_IS_ANNOTATION_ATTACHMENT (annot)) {
- EvAttachment *attachment = EV_ANNOTATION_ATTACHMENT (annot)->attachment;
+ EvAttachment *attachment;
+ attachment = ev_annotation_attachment_get_attachment (EV_ANNOTATION_ATTACHMENT (annot));
if (attachment) {
GError *error = NULL;
}
}
+static void
+ev_view_create_annotation (EvView *view,
+ EvAnnotationType annot_type,
+ gint x,
+ gint y)
+{
+ EvAnnotation *annot;
+ GdkPoint point;
+ GdkRectangle page_area;
+ GtkBorder border;
+ EvRectangle doc_rect, popup_rect;
+ EvPage *page;
+ GdkColor color = { 0, 65535, 65535, 0 };
+ GdkRectangle view_rect;
+ cairo_region_t *region;
+
+ point.x = x;
+ point.y = y;
+ ev_view_get_page_extents (view, view->current_page, &page_area, &border);
+ view_point_to_doc_point (view, &point, &page_area,
+ &doc_rect.x1, &doc_rect.y1);
+ doc_rect.x2 = doc_rect.x1 + 24;
+ doc_rect.y2 = doc_rect.y1 + 24;
+
+ ev_document_doc_mutex_lock ();
+ page = ev_document_get_page (view->document, view->current_page);
+ switch (annot_type) {
+ case EV_ANNOTATION_TYPE_TEXT:
+ annot = ev_annotation_text_new (page);
+ break;
+ case EV_ANNOTATION_TYPE_ATTACHMENT:
+ /* TODO */
+ g_object_unref (page);
+ ev_document_doc_mutex_unlock ();
+ return;
+ default:
+ g_assert_not_reached ();
+ }
+ g_object_unref (page);
+
+ ev_annotation_set_color (annot, &color);
+
+ if (EV_IS_ANNOTATION_MARKUP (annot)) {
+ popup_rect.x1 = doc_rect.x2;
+ popup_rect.x2 = popup_rect.x1 + 200;
+ popup_rect.y1 = doc_rect.y2;
+ popup_rect.y2 = popup_rect.y1 + 150;
+ g_object_set (annot,
+ "rectangle", &popup_rect,
+ "has_popup", TRUE,
+ "popup_is_open", FALSE,
+ "label", g_get_real_name (),
+ "opacity", 1.0,
+ NULL);
+ }
+ ev_document_annotations_add_annotation (EV_DOCUMENT_ANNOTATIONS (view->document),
+ annot, &doc_rect);
+ ev_document_doc_mutex_unlock ();
+
+ /* If the page didn't have annots, mark the cache as dirty */
+ if (!ev_page_cache_get_annot_mapping (view->page_cache, view->current_page))
+ ev_page_cache_mark_dirty (view->page_cache, view->current_page);
+
+ if (EV_IS_ANNOTATION_MARKUP (annot)) {
+ GtkWindow *parent;
+ GtkWidget *window;
+
+ parent = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (view)));
+ window = ev_view_create_annotation_window (view, annot, parent);
+
+ /* Show the annot window the first time */
+ ev_view_annotation_show_popup_window (view, window);
+ }
+
+ doc_rect_to_view_rect (view, view->current_page, &doc_rect, &view_rect);
+ view_rect.x -= view->scroll_x;
+ view_rect.y -= view->scroll_y;
+ region = cairo_region_create_rectangle (&view_rect);
+ ev_view_reload_page (view, view->current_page, region);
+ cairo_region_destroy (region);
+
+ g_signal_emit (view, signals[SIGNAL_ANNOT_ADDED], 0, annot);
+}
+
+void
+ev_view_focus_annotation (EvView *view,
+ EvMapping *annot_mapping)
+{
+ GdkRectangle view_rect;
+ EvAnnotation *annot;
+ guint page;
+
+ if (!EV_IS_DOCUMENT_ANNOTATIONS (view->document))
+ return;
+
+ if (view->focus_annotation == annot_mapping)
+ return;
+
+ view->focus_annotation = annot_mapping;
+ annot = (EvAnnotation *)annot_mapping->data;
+
+ page = ev_annotation_get_page_index (annot);
+ ev_document_model_set_page (view->model, page);
+
+ doc_rect_to_view_rect (view, page,
+ &annot_mapping->area, &view_rect);
+ ensure_rectangle_is_visible (view, &view_rect);
+ gtk_widget_queue_draw (GTK_WIDGET (view));
+}
+
+void
+ev_view_begin_add_annotation (EvView *view,
+ EvAnnotationType annot_type)
+{
+ if (annot_type == EV_ANNOTATION_TYPE_UNKNOWN)
+ return;
+
+ if (view->adding_annot)
+ return;
+
+ view->adding_annot = TRUE;
+ view->adding_annot_type = annot_type;
+ ev_view_set_cursor (view, EV_VIEW_CURSOR_ADD);
+}
+
+void
+ev_view_cancel_add_annotation (EvView *view)
+{
+ gint x, y;
+
+ if (!view->adding_annot)
+ return;
+
+ view->adding_annot = FALSE;
+ gtk_widget_get_pointer (GTK_WIDGET (view), &x, &y);
+ ev_view_handle_cursor_over_xy (view, x, y);
+}
+
+static gboolean
+ev_view_synctex_backward_search (EvView *view,
+ gdouble x,
+ gdouble y)
+{
+ gint page = -1;
+ gint x_new = 0, y_new = 0;
+ EvSourceLink *link;
+
+ if (!ev_document_has_synctex (view->document))
+ return FALSE;
+
+ if (!get_doc_point_from_location (view, x, y, &page, &x_new, &y_new))
+ return FALSE;
+
+ link = ev_document_synctex_backward_search (view->document, page, x_new, y_new);
+ if (link) {
+ g_signal_emit (view, signals[SIGNAL_SYNC_SOURCE], 0, link);
+ g_free (link);
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
/*** GtkWidget implementation ***/
static void
GtkRequisition *requisition)
{
EvView *view = EV_VIEW (widget);
-
+
if (view->document == NULL) {
view->requisition.width = 1;
view->requisition.height = 1;
if (!view->internal_size_request &&
(view->sizing_mode == EV_SIZING_FIT_WIDTH ||
view->sizing_mode == EV_SIZING_BEST_FIT)) {
+ GtkAllocation allocation;
+
+ gtk_widget_get_allocation (widget, &allocation);
ev_view_zoom_for_size (view,
- widget->allocation.width,
- widget->allocation.height);
+ allocation.width,
+ allocation.height);
}
if (view->continuous && view->dual_page)
gint root_x, root_y;
GTK_WIDGET_CLASS (ev_view_parent_class)->size_allocate (widget, allocation);
-
+
+ if (!view->document)
+ return;
+
if (view->sizing_mode == EV_SIZING_FIT_WIDTH ||
view->sizing_mode == EV_SIZING_BEST_FIT) {
GtkRequisition req;
for (l = children; l && l->data; l = g_list_next (l)) {
EvFormField *field;
GdkRectangle view_area;
- GList *form_field_mapping;
+ EvMappingList *form_field_mapping;
GtkAllocation child_allocation;
GtkRequisition child_requisition;
GtkWidget *child = (GtkWidget *)l->data;
child = (EvViewWindowChild *)l->data;
- doc_rect = *ev_annotation_window_get_rectangle (EV_ANNOTATION_WINDOW (child->window));
+ ev_annotation_window_get_rectangle (EV_ANNOTATION_WINDOW (child->window), &doc_rect);
if (child->moved) {
doc_rect.x1 = child->orig_x;
doc_rect.y1 = child->orig_y;
static void
ev_view_realize (GtkWidget *widget)
{
- EvView *view = EV_VIEW (widget);
+ EvView *view = EV_VIEW (widget);
+ GdkWindow *bin_window;
+ GtkStyle *style;
if (GTK_WIDGET_CLASS (ev_view_parent_class)->realize)
(* GTK_WIDGET_CLASS (ev_view_parent_class)->realize) (widget);
- gdk_window_set_events (view->layout.bin_window,
- (gdk_window_get_events (view->layout.bin_window) |
+ bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (view));
+ gdk_window_set_events (bin_window,
+ (gdk_window_get_events (bin_window) |
GDK_EXPOSURE_MASK |
GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK |
GDK_ENTER_NOTIFY_MASK |
GDK_LEAVE_NOTIFY_MASK));
- gdk_window_set_background (view->layout.bin_window, &widget->style->mid [GTK_STATE_NORMAL]);
+ style = gtk_widget_get_style (widget);
+ gdk_window_set_background (bin_window, &style->mid[GTK_STATE_NORMAL]);
on_adjustment_value_changed (NULL, view);
}
ev_view_expose_event (GtkWidget *widget,
GdkEventExpose *event)
{
- EvView *view = EV_VIEW (widget);
- cairo_t *cr;
- gint i;
+ EvView *view = EV_VIEW (widget);
+ GdkWindow *bin_window;
+ cairo_t *cr;
+ gint i;
if (view->loading) {
show_loading_window (view);
if (view->document == NULL)
return FALSE;
- cr = gdk_cairo_create (view->layout.bin_window);
+ bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (view));
+ cr = gdk_cairo_create (bin_window);
for (i = view->start_page; i >= 0 && i <= view->end_page; i++) {
GdkRectangle page_area;
GtkBorder border;
gboolean page_ready = TRUE;
- if (!get_page_extents (view, i, &page_area, &border))
+ if (!ev_view_get_page_extents (view, i, &page_area, &border))
continue;
page_area.x -= view->scroll_x;
highlight_find_results (view, i);
if (page_ready && EV_IS_DOCUMENT_ANNOTATIONS (view->document))
show_annotation_windows (view, i);
+ if (page_ready && view->focus_annotation)
+ focus_annotation (view, i, &event->area);
+ if (page_ready && view->synctex_result)
+ highlight_forward_search_results (view, i);
}
cairo_destroy (cr);
EvLink *link,
GdkRectangle *area)
{
- GList *link_mapping;
- gint page;
- gint x_offset = 0, y_offset = 0;
+ EvMappingList *link_mapping;
+ gint page;
+ gint x_offset = 0, y_offset = 0;
x += view->scroll_x;
y += view->scroll_y;
EvAnnotation *annot,
GdkRectangle *area)
{
- GList *annot_mapping;
- gint page;
- gint x_offset = 0, y_offset = 0;
+ EvMappingList *annot_mapping;
+ gint page;
+ gint x_offset = 0, y_offset = 0;
x += view->scroll_x;
y += view->scroll_y;
gchar *text;
annot = ev_view_get_annotation_at_location (view, x, y);
- if (annot && annot->contents) {
- GdkRectangle annot_area;
+ if (annot) {
+ const gchar *contents;
- get_annot_area (view, x, y, annot, &annot_area);
- gtk_tooltip_set_text (tooltip, annot->contents);
- gtk_tooltip_set_tip_area (tooltip, &annot_area);
+ if ((contents = ev_annotation_get_contents (annot))) {
+ GdkRectangle annot_area;
- return TRUE;
+ get_annot_area (view, x, y, annot, &annot_area);
+ gtk_tooltip_set_text (tooltip, contents);
+ gtk_tooltip_set_tip_area (tooltip, &annot_area);
+
+ return TRUE;
+ }
}
link = ev_view_get_link_at_location (view, x, y);
get_link_area (view, x, y, link, &link_area);
gtk_tooltip_set_text (tooltip, text);
gtk_tooltip_set_tip_area (tooltip, &link_area);
+ g_free (text);
+
+ return TRUE;
}
g_free (text);
- return TRUE;
+ return FALSE;
}
static void
window = EV_ANNOTATION_WINDOW (view->window_child_focus->window);
annot = ev_annotation_window_get_annotation (window);
ev_annotation_window_ungrab_focus (window);
- ev_view_annotation_save (view, annot);
view->window_child_focus = NULL;
}
view->pressed_button = event->button;
view->selection_info.in_drag = FALSE;
+ if (view->adding_annot)
+ return FALSE;
+
if (view->scroll_info.autoscrolling)
return TRUE;
EvAnnotation *annot;
EvFormField *field;
+ if (event->state & GDK_CONTROL_MASK)
+ return ev_view_synctex_backward_search (view, event->x , event->y);
+
if (EV_IS_SELECTION (view->document) && view->selection_info.selections) {
if (event->type == GDK_3BUTTON_PRESS) {
start_selection_for_event (view, event);
view->image_dnd_info.start.y = event->y + view->scroll_y;
} else {
ev_view_remove_all (view);
-
+
+ if (view->synctex_result) {
+ g_free (view->synctex_result);
+ view->synctex_result = NULL;
+ gtk_widget_queue_draw (widget);
+ }
+
+ if (view->focus_annotation)
+ view->focus_annotation = NULL;
+
if (EV_IS_SELECTION (view->document))
start_selection_for_event (view, event);
}
if (gtk_drag_get_source_widget (context) == widget)
gdk_drag_status (context, 0, time);
else
- gdk_drag_status (context, context->suggested_action, time);
+ gdk_drag_status (context, gdk_drag_context_get_suggested_action (context), time);
return TRUE;
}
{
gint x, y, shift = 0;
GtkWidget *widget = GTK_WIDGET (view);
-
+ GtkAllocation allocation;
+
+ gtk_widget_get_allocation (widget, &allocation);
gtk_widget_get_pointer (widget, &x, &y);
- if (y > widget->allocation.height) {
- shift = (y - widget->allocation.height) / 2;
+ if (y > allocation.height) {
+ shift = (y - allocation.height) / 2;
} else if (y < 0) {
shift = y / 2;
}
if (shift)
gtk_adjustment_set_value (view->vadjustment,
- CLAMP (view->vadjustment->value + shift,
- view->vadjustment->lower,
- view->vadjustment->upper -
- view->vadjustment->page_size));
+ CLAMP (gtk_adjustment_get_value (view->vadjustment) + shift,
+ gtk_adjustment_get_lower (view->vadjustment),
+ gtk_adjustment_get_upper (view->vadjustment) -
+ gtk_adjustment_get_page_size (view->vadjustment)));
- if (x > widget->allocation.width) {
- shift = (x - widget->allocation.width) / 2;
+ if (x > allocation.width) {
+ shift = (x - allocation.width) / 2;
} else if (x < 0) {
shift = x / 2;
}
if (shift)
gtk_adjustment_set_value (view->hadjustment,
- CLAMP (view->hadjustment->value + shift,
- view->hadjustment->lower,
- view->hadjustment->upper -
- view->hadjustment->page_size));
+ CLAMP (gtk_adjustment_get_value (view->hadjustment) + shift,
+ gtk_adjustment_get_lower (view->hadjustment),
+ gtk_adjustment_get_upper (view->hadjustment) -
+ gtk_adjustment_get_page_size (view->hadjustment)));
return TRUE;
}
{
gdouble dhadj_value, dvadj_value;
gdouble oldhadjustment, oldvadjustment;
+ gdouble h_page_size, v_page_size;
+ gdouble h_upper, v_upper;
+ GtkAllocation allocation;
view->drag_info.momentum.x /= 1.2;
view->drag_info.momentum.y /= 1.2; /* Alter these constants to change "friction" */
- dhadj_value = view->hadjustment->page_size *
- (gdouble)view->drag_info.momentum.x / GTK_WIDGET (view)->allocation.width;
- dvadj_value = view->vadjustment->page_size *
- (gdouble)view->drag_info.momentum.y / GTK_WIDGET (view)->allocation.height;
+ gtk_widget_get_allocation (GTK_WIDGET (view), &allocation);
+
+ h_page_size = gtk_adjustment_get_page_size (view->hadjustment);
+ v_page_size = gtk_adjustment_get_page_size (view->vadjustment);
+
+ dhadj_value = h_page_size *
+ (gdouble)view->drag_info.momentum.x / allocation.width;
+ dvadj_value = v_page_size *
+ (gdouble)view->drag_info.momentum.y / allocation.height;
oldhadjustment = gtk_adjustment_get_value (view->hadjustment);
oldvadjustment = gtk_adjustment_get_value (view->vadjustment);
- /* When we reach the edges, we need either to absorb some momentum and bounce by
- * multiplying it on -0.5 or stop scrolling by setting momentum to 0. */
- if (((oldhadjustment + dhadj_value) > (view->hadjustment->upper - view->hadjustment->page_size)) ||
- ((oldhadjustment + dhadj_value) < 0))
+ h_upper = gtk_adjustment_get_upper (view->hadjustment);
+ v_upper = gtk_adjustment_get_upper (view->vadjustment);
+
+ /* When we reach the edges, we need either to absorb some momentum and bounce by
+ * multiplying it on -0.5 or stop scrolling by setting momentum to 0. */
+ if (((oldhadjustment + dhadj_value) > (h_upper - h_page_size)) ||
+ ((oldhadjustment + dhadj_value) < 0))
view->drag_info.momentum.x = 0;
- if (((oldvadjustment + dvadj_value) > (view->vadjustment->upper - view->vadjustment->page_size)) ||
- ((oldvadjustment + dvadj_value) < 0))
+ if (((oldvadjustment + dvadj_value) > (v_upper - v_page_size)) ||
+ ((oldvadjustment + dvadj_value) < 0))
view->drag_info.momentum.y = 0;
gtk_adjustment_set_value (view->hadjustment,
- MIN (oldhadjustment + dhadj_value,
- view->hadjustment->upper - view->hadjustment->page_size));
+ MIN (oldhadjustment + dhadj_value,
+ h_upper - h_page_size));
gtk_adjustment_set_value (view->vadjustment,
- MIN (oldvadjustment + dvadj_value,
- view->vadjustment->upper - view->vadjustment->page_size));
+ MIN (oldvadjustment + dvadj_value,
+ v_upper - v_page_size));
if (((view->drag_info.momentum.x < 1) && (view->drag_info.momentum.x > -1)) &&
- ((view->drag_info.momentum.y < 1) && (view->drag_info.momentum.y > -1)))
+ ((view->drag_info.momentum.y < 1) && (view->drag_info.momentum.y > -1)))
return FALSE;
else
return TRUE;
ev_view_motion_notify_event (GtkWidget *widget,
GdkEventMotion *event)
{
- EvView *view = EV_VIEW (widget);
- gint x, y;
+ EvView *view = EV_VIEW (widget);
+ GdkWindow *bin_window;
+ gint x, y;
if (!view->document)
return FALSE;
- if (event->is_hint || event->window != view->layout.bin_window) {
+ bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (view));
+
+ if (event->is_hint || event->window != bin_window) {
gtk_widget_get_pointer (widget, &x, &y);
} else {
x = event->x;
if (view->drag_info.in_drag) {
int dx, dy;
gdouble dhadj_value, dvadj_value;
+ GtkAllocation allocation;
view->drag_info.buffer[0].x = event->x;
view->drag_info.buffer[0].y = event->y;
dx = event->x_root - view->drag_info.start.x;
dy = event->y_root - view->drag_info.start.y;
- dhadj_value = view->hadjustment->page_size *
- (gdouble)dx / widget->allocation.width;
- dvadj_value = view->vadjustment->page_size *
- (gdouble)dy / widget->allocation.height;
+ gtk_widget_get_allocation (widget, &allocation);
+
+ dhadj_value = gtk_adjustment_get_page_size (view->hadjustment) *
+ (gdouble)dx / allocation.width;
+ dvadj_value = gtk_adjustment_get_page_size (view->vadjustment) *
+ (gdouble)dy / allocation.height;
/* clamp scrolling to visible area */
gtk_adjustment_set_value (view->hadjustment,
- MIN(view->drag_info.hadj - dhadj_value,
- view->hadjustment->upper -
- view->hadjustment->page_size));
+ MIN (view->drag_info.hadj - dhadj_value,
+ gtk_adjustment_get_upper (view->hadjustment) -
+ gtk_adjustment_get_page_size (view->hadjustment)));
gtk_adjustment_set_value (view->vadjustment,
- MIN(view->drag_info.vadj - dvadj_value,
- view->vadjustment->upper -
- view->vadjustment->page_size));
+ MIN (view->drag_info.vadj - dvadj_value,
+ gtk_adjustment_get_upper (view->vadjustment) -
+ gtk_adjustment_get_page_size (view->vadjustment)));
return TRUE;
}
view->pressed_button = -1;
return TRUE;
- }
+ }
+
+ if (view->pressed_button == 1 && event->state & GDK_CONTROL_MASK) {
+ view->pressed_button = -1;
+ return TRUE;
+ }
if (view->drag_info.in_drag) {
view->drag_info.release_timeout_id =
view->drag_info.in_drag = FALSE;
+ if (view->adding_annot && view->pressed_button == 1) {
+ view->adding_annot = FALSE;
+ ev_view_handle_cursor_over_xy (view, event->x, event->y);
+ view->pressed_button = -1;
+
+ ev_view_create_annotation (view,
+ view->adding_annot_type,
+ event->x + view->scroll_x,
+ event->y + view->scroll_y);
+
+ return FALSE;
+ }
+
if (view->pressed_button == 2) {
ev_view_handle_cursor_over_xy (view, event->x, event->y);
}
new_event = (GdkEventKey *) gdk_event_copy ((GdkEvent *)event);
g_object_unref (new_event->window);
- new_event->window = g_object_ref (view->window_child_focus->window->window);
+ new_event->window = gtk_widget_get_window (view->window_child_focus->window);
+ if (new_event->window)
+ g_object_ref (new_event->window);
gtk_widget_realize (view->window_child_focus->window);
handled = gtk_widget_event (view->window_child_focus->window, (GdkEvent *)new_event);
gdk_event_free ((GdkEvent *)new_event);
/*** Drawing ***/
-static guint32
-ev_gdk_color_to_rgb (const GdkColor *color)
-{
- guint32 result;
- result = (0xff0000 | (color->red & 0xff00));
- result <<= 8;
- result |= ((color->green & 0xff00) | (color->blue >> 8));
- return result;
-}
-
static void
-draw_rubberband (GtkWidget *widget, GdkWindow *window,
- const GdkRectangle *rect, guchar alpha)
+draw_rubberband (EvView *view,
+ GdkWindow *window,
+ const GdkRectangle *rect,
+ gdouble alpha)
{
- GdkGC *gc;
- GdkPixbuf *pixbuf;
+ GtkStyle *style;
GdkColor *fill_color_gdk;
- guint fill_color;
+ gdouble r, g, b;
+ cairo_t *cr;
- fill_color_gdk = gdk_color_copy (>K_WIDGET (widget)->style->base[GTK_STATE_SELECTED]);
- fill_color = ev_gdk_color_to_rgb (fill_color_gdk) << 8 | alpha;
+ style = gtk_widget_get_style (GTK_WIDGET (view));
+ fill_color_gdk = gdk_color_copy (&style->base[GTK_STATE_SELECTED]);
+ r = fill_color_gdk->red / 65535.;
+ g = fill_color_gdk->green / 65535.;
+ b = fill_color_gdk->blue / 65535.;
- pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8,
- rect->width, rect->height);
- gdk_pixbuf_fill (pixbuf, fill_color);
+ cr = gdk_cairo_create (window);
- gdk_draw_pixbuf (window, NULL, pixbuf,
- 0, 0,
- rect->x - EV_VIEW (widget)->scroll_x, rect->y - EV_VIEW (widget)->scroll_y,
- rect->width, rect->height,
- GDK_RGB_DITHER_NONE,
- 0, 0);
+ cairo_set_source_rgba (cr, r, g, b, alpha);
+ cairo_rectangle (cr,
+ rect->x - view->scroll_x,
+ rect->y - view->scroll_y,
+ rect->width, rect->height);
+ cairo_fill_preserve (cr);
- g_object_unref (pixbuf);
+ cairo_set_line_width (cr, 0.5);
+ cairo_set_source_rgb (cr, r, g, b);
+ cairo_stroke (cr);
- gc = gdk_gc_new (window);
- gdk_gc_set_rgb_fg_color (gc, fill_color_gdk);
- gdk_draw_rectangle (window, gc, FALSE,
- rect->x - EV_VIEW (widget)->scroll_x, rect->y - EV_VIEW (widget)->scroll_y,
- rect->width - 1,
- rect->height - 1);
- g_object_unref (gc);
+ cairo_destroy (cr);
gdk_color_free (fill_color_gdk);
}
static void
highlight_find_results (EvView *view, int page)
{
- gint i, n_results = 0;
+ gint i, n_results = 0;
+ GdkWindow *bin_window;
+
+ bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (view));
n_results = ev_view_find_get_n_results (view, page);
for (i = 0; i < n_results; i++) {
EvRectangle *rectangle;
GdkRectangle view_rectangle;
- guchar alpha;
+ gdouble alpha;
if (i == view->find_result && page == view->current_page) {
- alpha = 0x90;
+ alpha = 0.6;
} else {
- alpha = 0x20;
+ alpha = 0.3;
}
rectangle = ev_view_find_get_result (view, page, i);
doc_rect_to_view_rect (view, page, rectangle, &view_rectangle);
- draw_rubberband (GTK_WIDGET (view), view->layout.bin_window,
- &view_rectangle, alpha);
+ draw_rubberband (view, bin_window, &view_rectangle, alpha);
}
}
+static void
+highlight_forward_search_results (EvView *view, int page)
+{
+ GdkWindow *bin_window;
+ GdkRectangle rect;
+ cairo_t *cr;
+ EvMapping *mapping = view->synctex_result;
+
+ if (GPOINTER_TO_INT (mapping->data) != page)
+ return;
+
+ bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (view));
+ doc_rect_to_view_rect (view, page, &mapping->area, &rect);
+
+ cr = gdk_cairo_create (bin_window);
+ cairo_set_source_rgb (cr, 1., 0., 0.);
+ cairo_rectangle (cr,
+ rect.x - view->scroll_x,
+ rect.y - view->scroll_y,
+ rect.width, rect.height);
+ cairo_stroke (cr);
+ cairo_destroy (cr);
+}
+
+static void
+focus_annotation (EvView *view,
+ gint page,
+ GdkRectangle *clip)
+{
+ GtkWidget *widget = GTK_WIDGET (view);
+ GdkRectangle rect;
+ EvMapping *mapping = view->focus_annotation;
+ EvAnnotation *annot = (EvAnnotation *)mapping->data;
+
+ if (ev_annotation_get_page_index (annot) != page)
+ return;
+
+ doc_rect_to_view_rect (view, page, &mapping->area, &rect);
+ gtk_paint_focus (gtk_widget_get_style (widget),
+ gtk_layout_get_bin_window (GTK_LAYOUT (view)),
+ gtk_widget_get_state (widget),
+ NULL, widget, NULL,
+ rect.x - view->scroll_x,
+ rect.y - view->scroll_y,
+ rect.width + 1, rect.height + 1);
+}
+
static void
ev_view_loading_window_move (EvView *view)
{
current_page = ev_document_model_get_page (view->model);
inverted_colors = ev_document_model_get_inverted_colors (view->model);
- ev_document_misc_paint_one_page (view->layout.bin_window,
+ ev_document_misc_paint_one_page (cr,
GTK_WIDGET (view),
page_area, border,
page == current_page,
cairo_surface_set_device_offset (selection_surface,
overlap.x - real_page_area.x,
overlap.y - real_page_area.y);
+
cairo_set_source_surface (cr, selection_surface, 0, 0);
cairo_paint (cr);
cairo_restore (cr);
clear_selection (view);
clear_link_selected (view);
+ if (view->synctex_result) {
+ g_free (view->synctex_result);
+ view->synctex_result = NULL;
+ }
+
if (view->image_dnd_info.image)
g_object_unref (view->image_dnd_info.image);
view->image_dnd_info.image = NULL;
factory = atk_registry_get_factory (registry,
derived_type);
derived_atk_type = atk_object_factory_get_accessible_type (factory);
- if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
- atk_registry_set_factory_type (registry,
+ if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE)) {
+ atk_registry_set_factory_type (registry,
EV_TYPE_VIEW,
ev_view_accessible_factory_get_type ());
+ EV_VIEW (widget)->a11y_enabled = TRUE;
+ }
first_time = FALSE;
}
return GTK_WIDGET_CLASS (ev_view_parent_class)->get_accessible (widget);
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0,
G_TYPE_NONE);
+ signals[SIGNAL_SYNC_SOURCE] = g_signal_new ("sync-source",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ G_STRUCT_OFFSET (EvViewClass, sync_source),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__POINTER,
+ G_TYPE_NONE, 1,
+ G_TYPE_POINTER);
+ signals[SIGNAL_ANNOT_ADDED] = g_signal_new ("annot-added",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ G_STRUCT_OFFSET (EvViewClass, annot_added),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE, 1,
+ EV_TYPE_ANNOTATION);
+ signals[SIGNAL_LAYERS_CHANGED] = g_signal_new ("layers-changed",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ G_STRUCT_OFFSET (EvViewClass, layers_changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0,
+ G_TYPE_NONE);
binding_set = gtk_binding_set_by_class (class);
static void
ev_view_init (EvView *view)
{
- GTK_WIDGET_SET_FLAGS (view, GTK_CAN_FOCUS);
+ gtk_widget_set_can_focus (GTK_WIDGET (view), TRUE);
view->start_page = -1;
view->end_page = -1;
}
static void
-job_finished_cb (EvPixbufCache *pixbuf_cache,
- GdkRegion *region,
- EvView *view)
+job_finished_cb (EvPixbufCache *pixbuf_cache,
+ cairo_region_t *region,
+ EvView *view)
{
if (region) {
- gdk_window_invalidate_region (view->layout.bin_window,
- region, TRUE);
+ GdkWindow *bin_window;
+
+ bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (view));
+#if GTK_CHECK_VERSION(2, 90, 5)
+ gdk_window_invalidate_region (bin_window, region, TRUE);
+#else
+ {
+ GdkRegion *gdk_region = gdk_region_new ();
+ guint n_recs = cairo_region_num_rectangles (region);
+ guint i;
+
+ for (i = 0; i < n_recs; i++) {
+ cairo_rectangle_int_t rect;
+
+ cairo_region_get_rectangle (region, i, &rect);
+ gdk_region_union_with_rect (gdk_region, (GdkRectangle *)&rect);
+ }
+ gdk_window_invalidate_region (bin_window, gdk_region, TRUE);
+ gdk_region_destroy (gdk_region);
+ }
+#endif
} else {
gtk_widget_queue_draw (GTK_WIDGET (view));
}
{
int dx = 0, dy = 0;
gint x, y;
+ gint value;
GList *children, *l;
if (!gtk_widget_get_realized (GTK_WIDGET (view)))
return;
if (view->hadjustment) {
- dx = view->scroll_x - (int) view->hadjustment->value;
- view->scroll_x = (int) view->hadjustment->value;
+ value = (gint) gtk_adjustment_get_value (view->hadjustment);
+ dx = view->scroll_x - value;
+ view->scroll_x = value;
} else {
view->scroll_x = 0;
}
if (view->vadjustment) {
- dy = view->scroll_y - (int) view->vadjustment->value;
- view->scroll_y = (int) view->vadjustment->value;
+ value = (gint) gtk_adjustment_get_value (view->vadjustment);
+ dy = view->scroll_y - value;
+ view->scroll_y = value;
} else {
view->scroll_y = 0;
}
ev_view_window_child_move (view, child, child->x + dx, child->y + dy);
}
- if (view->pending_resize)
+ if (view->pending_resize) {
gtk_widget_queue_draw (GTK_WIDGET (view));
- else
- gdk_window_scroll (view->layout.bin_window, dx, dy);
-
+ } else {
+ GdkWindow *bin_window;
+
+ bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (view));
+ gdk_window_scroll (bin_window, dx, dy);
+ }
+
gtk_widget_get_pointer (GTK_WIDGET (view), &x, &y);
ev_view_handle_cursor_over_xy (view, x, y);
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);
+ view->pixbuf_cache = ev_pixbuf_cache_new (GTK_WIDGET (view), view->model, view->pixbuf_cache_size);
view->page_cache = ev_page_cache_new (view->document);
+ if (view->a11y_enabled) {
+ EvJobPageDataFlags flags = ev_page_cache_get_flags (view->page_cache);
+
+ ev_page_cache_set_flags (view->page_cache,
+ flags |
+ EV_PAGE_DATA_INCLUDE_TEXT_LAYOUT |
+ EV_PAGE_DATA_INCLUDE_TEXT);
+ }
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);
}
}
+/**
+ * ev_view_set_page_cache_size:
+ * @view:
+ * @cache_size:
+ *
+ * Sets the maximum size in bytes that will be used to cache
+ * rendered pages. Use 0 to disable caching rendered pages.
+ *
+ * Note that this limit doesn't affect the current visible page range,
+ * which will always be rendered. In order to limit the total memory used
+ * you have to use ev_document_model_set_max_scale() too.
+ *
+ */
+void
+ev_view_set_page_cache_size (EvView *view,
+ gsize cache_size)
+{
+ if (view->pixbuf_cache_size == cache_size)
+ return;
+
+ view->pixbuf_cache_size = cache_size;
+ if (view->pixbuf_cache)
+ ev_pixbuf_cache_set_max_size (view->pixbuf_cache, cache_size);
+}
+
void
ev_view_set_loading (EvView *view,
gboolean loading)
{
+ if (view->loading && !loading)
+ hide_loading_window (view);
view->loading = loading;
gtk_widget_queue_draw (GTK_WIDGET (view));
}
speed = pow ((((gdouble)view->scroll_info.last_y - view->scroll_info.start_y) / 100), 3);
value = gtk_adjustment_get_value (view->vadjustment);
- value = CLAMP (value + speed, 0, view->vadjustment->upper - view->vadjustment->page_size);
+ value = CLAMP (value + speed, 0,
+ gtk_adjustment_get_upper (view->vadjustment) -
+ gtk_adjustment_get_page_size (view->vadjustment));
gtk_adjustment_set_value (view->vadjustment, value);
return TRUE;
}
static void
-ev_view_reload_page (EvView *view,
- gint page,
- GdkRegion *region)
+ev_view_reload_page (EvView *view,
+ gint page,
+ cairo_region_t *region)
{
ev_pixbuf_cache_reload_page (view->pixbuf_cache,
region,
view->find_pages = NULL;
}
+/*** Synctex ***/
+void
+ev_view_highlight_forward_search (EvView *view,
+ EvSourceLink *link)
+{
+ EvMapping *mapping;
+ gint page;
+ GdkRectangle view_rect;
+
+ if (!ev_document_has_synctex (view->document))
+ return;
+
+ mapping = ev_document_synctex_forward_search (view->document, link);
+ if (!mapping)
+ return;
+
+ if (view->synctex_result)
+ g_free (view->synctex_result);
+ view->synctex_result = mapping;
+
+ page = GPOINTER_TO_INT (mapping->data);
+ ev_document_model_set_page (view->model, page);
+
+ doc_rect_to_view_rect (view, page, &mapping->area, &view_rect);
+ ensure_rectangle_is_visible (view, &view_rect);
+ gtk_widget_queue_draw (GTK_WIDGET (view));
+}
+
/*** Selections ***/
/* compute_new_selection_rect/text calculates the area currently selected by
GdkRectangle page_area;
GtkBorder border;
- if (get_page_extents (view, i, &page_area, &border)) {
+ if (ev_view_get_page_extents (view, i, &page_area, &border)) {
GdkRectangle overlap;
if (gdk_rectangle_intersect (&page_area, &view_rect, &overlap)) {
GdkRectangle page_area;
GtkBorder border;
- get_page_extents (view, i, &page_area, &border);
+ ev_view_get_page_extents (view, i, &page_area, &border);
if (gdk_rectangle_point_in (&page_area, start) ||
gdk_rectangle_point_in (&page_area, stop)) {
if (first == n_pages)
selection->rect.x2 = width;
selection->rect.y2 = height;
- get_page_extents (view, i, &page_area, &border);
+ ev_view_get_page_extents (view, i, &page_area, &border);
if (gdk_rectangle_point_in (&page_area, start))
point = start;
while (new_list_ptr || old_list_ptr) {
EvViewSelection *old_sel, *new_sel;
int cur_page;
- GdkRegion *region = NULL;
+ cairo_region_t *region = NULL;
new_sel = (new_list_ptr) ? (new_list_ptr->data) : NULL;
old_sel = (old_list_ptr) ? (old_list_ptr->data) : NULL;
/* seed the cache with a new page. We are going to need the new
* region too. */
if (new_sel) {
- GdkRegion *tmp_region = NULL;
+ cairo_region_t *tmp_region = NULL;
ev_pixbuf_cache_get_selection_surface (view->pixbuf_cache,
cur_page,
view->scale,
&tmp_region);
- if (tmp_region && !gdk_region_empty (tmp_region)) {
- new_sel->covered_region = gdk_region_copy (tmp_region);
+ if (tmp_region && !cairo_region_is_empty (tmp_region)) {
+ new_sel->covered_region = cairo_region_reference (tmp_region);
}
}
/* We only want to redraw the areas that have
* changed, so we xor the old and new regions
* and redraw if it's different */
- region = gdk_region_copy (old_sel->covered_region);
- gdk_region_xor (region, new_sel->covered_region);
- if (gdk_region_empty (region)) {
- gdk_region_destroy (region);
+ region = cairo_region_copy (old_sel->covered_region);
+#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 9, 12)
+ cairo_region_xor (region, new_sel->covered_region);
+#else
+ cairo_region_t *tbr;
+ tbr = cairo_region_copy (new_sel->covered_region);
+
+ /* xor old_sel, new_sel*/
+ cairo_region_subtract (tbr, region);
+ cairo_region_subtract (region, new_sel->covered_region);
+ cairo_region_union (region, tbr);
+ cairo_region_destroy (tbr);
+#endif
+
+ if (cairo_region_is_empty (region)) {
+ cairo_region_destroy (region);
region = NULL;
+ } else {
+ gint num_rectangles = cairo_region_num_rectangles (region);
+ GdkRectangle r;
+
+ /* We need to make the damage region a little bigger
+ * because the edges of the old selection might change
+ */
+ cairo_region_get_rectangle (region, 0, &r);
+ r.x -= 5;
+ r.width = 5;
+ cairo_region_union_rectangle (region, &r);
+
+ cairo_region_get_rectangle (region, num_rectangles - 1, &r);
+ r.x += r.width;
+ r.width = 5;
+ cairo_region_union_rectangle (region, &r);
}
} else if (old_sel->covered_region) {
- region = gdk_region_copy (old_sel->covered_region);
+ region = cairo_region_copy (old_sel->covered_region);
} else if (new_sel->covered_region) {
- region = gdk_region_copy (new_sel->covered_region);
+ region = cairo_region_copy (new_sel->covered_region);
}
} else if (old_sel && !new_sel) {
- if (old_sel->covered_region && !gdk_region_empty (old_sel->covered_region)) {
- region = gdk_region_copy (old_sel->covered_region);
+ if (old_sel->covered_region && !cairo_region_is_empty (old_sel->covered_region)) {
+ region = cairo_region_copy (old_sel->covered_region);
}
} else if (!old_sel && new_sel) {
- if (new_sel->covered_region && !gdk_region_empty (new_sel->covered_region)) {
- region = gdk_region_copy (new_sel->covered_region);
+ if (new_sel->covered_region && !cairo_region_is_empty (new_sel->covered_region)) {
+ region = cairo_region_copy (new_sel->covered_region);
}
} else {
g_assert_not_reached ();
/* Redraw the damaged region! */
if (region) {
+ GdkWindow *bin_window;
GdkRectangle page_area;
- GtkBorder border;
+ GtkBorder border;
- /* I don't know why but the region is smaller
- * than expected. This hack fixes it, I guess
- * 10 pixels more won't hurt
- */
- gdk_region_shrink (region, -5, -5);
-
- get_page_extents (view, cur_page, &page_area, &border);
- gdk_region_offset (region,
+ bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (view));
+ ev_view_get_page_extents (view, cur_page, &page_area, &border);
+ cairo_region_translate (region,
page_area.x + border.left - view->scroll_x,
page_area.y + border.top - view->scroll_y);
- gdk_window_invalidate_region (view->layout.bin_window, region, TRUE);
- gdk_region_destroy (region);
+#if GTK_CHECK_VERSION(2, 90, 5)
+ gdk_window_invalidate_region (bin_window, region, TRUE);
+#else
+ {
+ GdkRegion *gdk_region = gdk_region_new ();
+ guint n_recs = cairo_region_num_rectangles (region);
+ guint i;
+
+ for (i = 0; i < n_recs; i++) {
+ cairo_rectangle_int_t rect;
+
+ cairo_region_get_rectangle (region, i, &rect);
+ gdk_region_union_with_rect (gdk_region, (GdkRectangle *)&rect);
+ }
+ gdk_window_invalidate_region (bin_window, gdk_region, TRUE);
+ gdk_region_destroy (gdk_region);
+ }
+#endif
+ cairo_region_destroy (region);
}
}
selection_free (EvViewSelection *selection)
{
if (selection->covered_region)
- gdk_region_destroy (selection->covered_region);
+ cairo_region_destroy (selection->covered_region);
g_free (selection);
}
{
GdkCursor *cursor = NULL;
GtkWidget *widget;
+ GdkWindow *bin_window;
if (view->cursor == new_cursor) {
return;
view->cursor = new_cursor;
+ bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (view));
widget = gtk_widget_get_toplevel (GTK_WIDGET (view));
cursor = ev_view_cursor_new (gtk_widget_get_display (widget), new_cursor);
- gdk_window_set_cursor (view->layout.bin_window, cursor);
+ gdk_window_set_cursor (bin_window, cursor);
gdk_flush ();
if (cursor)
gdk_cursor_unref (cursor);