X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=shell%2Fev-view.c;h=8e494adedc1a527007b1860ddb634a725c1dc06a;hb=79a78d0249676255e902c9207a0eec4aba179de6;hp=b8723ccc8bc0a721500514d1191c8ae9650b10d8;hpb=391b8337a98a416103bcf27a6a54a2d2f0e15f87;p=evince.git diff --git a/shell/ev-view.c b/shell/ev-view.c index b8723ccc..8e494ade 100644 --- a/shell/ev-view.c +++ b/shell/ev-view.c @@ -29,6 +29,7 @@ #include "ev-marshal.h" #include "ev-view.h" +#include "ev-selection.h" #include "ev-document-find.h" #include "ev-document-misc.h" #include "ev-debug.h" @@ -49,10 +50,11 @@ enum { PROP_FULLSCREEN, PROP_PRESENTATION, PROP_SIZING_MODE, + PROP_ZOOM, }; enum { - SIGNAL_SCROLL_VIEW, + SIGNAL_BINDING_ACTIVATED, SIGNAL_ZOOM_INVALID, N_SIGNALS, }; @@ -76,6 +78,7 @@ static guint signals[N_SIGNALS]; typedef enum { EV_VIEW_CURSOR_NORMAL, + EV_VIEW_CURSOR_IBEAM, EV_VIEW_CURSOR_LINK, EV_VIEW_CURSOR_WAIT, EV_VIEW_CURSOR_HIDDEN, @@ -86,20 +89,23 @@ typedef enum { #define ZOOM_OUT_FACTOR (1.0/ZOOM_IN_FACTOR) #define MIN_SCALE 0.05409 -#define MAX_SCALE 6.0 +#define MAX_SCALE 4.0 +/* Information for middle clicking and moving around the doc */ typedef struct { - EvRectangle rect; - int page; -} EvViewSelection; - -typedef struct { - gboolean dragging; + gboolean in_drag; GdkPoint start; gdouble hadj; gdouble vadj; } DragInfo; +/* Information for handling selection */ +typedef struct { + gboolean in_selection; + GdkPoint start; + GList *selections; +} SelectionInfo; + typedef enum { SCROLL_TO_KEEP_POSITION, SCROLL_TO_CURRENT_PAGE, @@ -117,10 +123,14 @@ struct _EvView { gint scroll_x; gint scroll_y; + /* Information for middle clicking and dragging around. */ DragInfo drag_info; + + /* Selection */ + EvViewSelectionMode selection_mode; + SelectionInfo selection_info; + gboolean pressed_button; - GdkPoint selection_start; - GList *selections; EvViewCursor cursor; GtkAdjustment *hadjustment; @@ -140,14 +150,13 @@ struct _EvView { int spacing; double scale; - GtkBorder border; gboolean continuous; gboolean dual_page; gboolean fullscreen; gboolean presentation; EvSizingMode sizing_mode; - + PendingScroll pending_scroll; gboolean pending_resize; }; @@ -158,20 +167,19 @@ struct _EvViewClass { void (*set_scroll_adjustments) (EvView *view, GtkAdjustment *hadjustment, GtkAdjustment *vadjustment); - void (*scroll_view) (EvView *view, + void (*binding_activated) (EvView *view, GtkScrollType scroll, gboolean horizontal); void (*zoom_invalid) (EvView *view); }; /*** Scrolling ***/ -static void view_update_adjustments (EvView *view); +static void scroll_to_current_page (EvView *view, + GtkOrientation orientation); static void ev_view_set_scroll_adjustments (EvView *view, GtkAdjustment *hadjustment, GtkAdjustment *vadjustment); static void view_update_range_and_current_page (EvView *view); -static void view_scroll_to_page (EvView *view, - gint new_page); static void set_scroll_adjustment (EvView *view, GtkOrientation orientation, GtkAdjustment *adjustment); @@ -182,7 +190,7 @@ static void add_scroll_binding_keypad (GtkBindingSet guint keyval, GtkScrollType scroll, gboolean horizontal); -static void ev_view_scroll_view (EvView *view, +static void ev_view_binding_activated (EvView *view, GtkScrollType scroll, gboolean horizontal); static void ensure_rectangle_is_visible (EvView *view, @@ -193,6 +201,10 @@ static void compute_border (EvView int width, int height, GtkBorder *border); +static void get_page_y_offset (EvView *view, + int page, + double zoom, + int *y_offset); static gboolean get_page_extents (EvView *view, gint page, GdkRectangle *page_area, @@ -205,9 +217,6 @@ static void doc_rect_to_view_rect (EvView int page, EvRectangle *doc_rect, GdkRectangle *view_rect); -static void get_bounding_box_size (EvView *view, - int *max_width, - int *max_height); static void find_page_at_location (EvView *view, gdouble x, gdouble y, @@ -342,7 +351,8 @@ static void jump_to_find_page (EvView /*** Selection ***/ static void compute_selections (EvView *view, - GdkRectangle *view_rect); + GdkPoint *start, + GdkPoint *stop); static void clear_selection (EvView *view); static char* get_selected_text (EvView *ev_view); static void ev_view_primary_get_cb (GtkClipboard *clipboard, @@ -353,40 +363,43 @@ static void ev_view_primary_clear_cb (GtkClipboard gpointer data); static void ev_view_update_primary_selection (EvView *ev_view); - + G_DEFINE_TYPE (EvView, ev_view, GTK_TYPE_WIDGET) static void -view_update_adjustments (EvView *view) +scroll_to_current_page (EvView *view, GtkOrientation orientation) { - int dx = 0, dy = 0; + GdkRectangle page_area; + GtkBorder border; - if (! GTK_WIDGET_REALIZED (view)) + if (view->document == NULL) { return; - - if (view->hadjustment) { - dx = view->scroll_x - view->hadjustment->value; - view->scroll_x = view->hadjustment->value; - } else { - view->scroll_x = 0; } - if (view->vadjustment) { - dy = view->scroll_y - view->vadjustment->value; - view->scroll_y = view->vadjustment->value; + get_page_extents (view, view->current_page, &page_area, &border); + + if (orientation == GTK_ORIENTATION_VERTICAL) { + if (view->continuous) { + gtk_adjustment_clamp_page (view->vadjustment, + page_area.y - view->spacing, + page_area.y + view->vadjustment->page_size); + } else { + gtk_adjustment_set_value (view->vadjustment, + view->vadjustment->lower); + } } else { - view->scroll_y = 0; + if (view->dual_page) { + gtk_adjustment_clamp_page (view->hadjustment, + page_area.x, + page_area.x + view->hadjustment->page_size); + } else { + gtk_adjustment_set_value (view->hadjustment, + CLAMP (view->hadjustment->value, + view->hadjustment->lower, + view->hadjustment->upper - + view->hadjustment->page_size)); + } } - - - if (view->pending_resize) - gtk_widget_queue_draw (GTK_WIDGET (view)); - else - gdk_window_scroll (GTK_WIDGET (view)->window, dx, dy); - - - if (view->document) - view_update_range_and_current_page (view); } static void @@ -413,15 +426,15 @@ view_set_adjustment_values (EvView *view, if (!adjustment) return; - + factor = 1.0; switch (view->pending_scroll) { - case SCROLL_TO_KEEP_POSITION: - factor = adjustment->value / adjustment->upper; + case SCROLL_TO_KEEP_POSITION: + factor = (adjustment->value) / adjustment->upper; break; - case SCROLL_TO_CURRENT_PAGE: + case SCROLL_TO_CURRENT_PAGE: break; - case SCROLL_TO_CENTER: + case SCROLL_TO_CENTER: factor = (adjustment->value + adjustment->page_size * 0.5) / adjustment->upper; break; } @@ -432,19 +445,21 @@ view_set_adjustment_values (EvView *view, adjustment->lower = 0; adjustment->upper = MAX (allocation, requisition); + /* + * We add 0.5 to the values before to average out our rounding errors. + */ switch (view->pending_scroll) { - case SCROLL_TO_KEEP_POSITION: - new_value = CLAMP (adjustment->upper * factor, 0, adjustment->upper - adjustment->page_size); - gtk_adjustment_set_value (adjustment, new_value); + case SCROLL_TO_KEEP_POSITION: + new_value = CLAMP (adjustment->upper * factor + 0.5, 0, adjustment->upper - adjustment->page_size); + gtk_adjustment_set_value (adjustment, (int)new_value); break; - case SCROLL_TO_CURRENT_PAGE: - if (orientation == GTK_ORIENTATION_VERTICAL) { - view_scroll_to_page (view, view->current_page); - } + case SCROLL_TO_CURRENT_PAGE: + scroll_to_current_page (view, orientation); break; - case SCROLL_TO_CENTER: - new_value = CLAMP (adjustment->upper * factor - adjustment->page_size * 0.5, 0, adjustment->upper - adjustment->page_size); - gtk_adjustment_set_value (adjustment, new_value); + case SCROLL_TO_CENTER: + new_value = CLAMP (adjustment->upper * factor - adjustment->page_size * 0.5 + 0.5, + 0, adjustment->upper - adjustment->page_size); + gtk_adjustment_set_value (adjustment, (int)new_value); break; } @@ -460,51 +475,33 @@ view_update_range_and_current_page (EvView *view) view->end_page = view->current_page; } else if (view->continuous) { GdkRectangle current_area, unused, page_area; + GtkBorder border; gint current_page; gboolean found = FALSE; int i; - - get_bounding_box_size (view, &(page_area.width), &(page_area.height)); - page_area.x = view->spacing; - page_area.y = view->spacing; - if (view->hadjustment) { - current_area.x = view->hadjustment->value; - current_area.width = view->hadjustment->page_size; - } else { - current_area.x = page_area.x; - current_area.width = page_area.width; - } + if (!(view->vadjustment && view->hadjustment)) + return; - if (view->vadjustment) { - current_area.y = view->vadjustment->value; - current_area.height = view->vadjustment->page_size; - } else { - current_area.y = page_area.y; - current_area.height = page_area.height; - } + current_area.x = view->hadjustment->value; + current_area.width = view->hadjustment->upper; + current_area.y = view->vadjustment->value; + current_area.height = view->vadjustment->page_size; for (i = 0; i < ev_page_cache_get_n_pages (view->page_cache); i++) { + + get_page_extents (view, i, &page_area, &border); + if (gdk_rectangle_intersect (¤t_area, &page_area, &unused)) { if (! found) { view->start_page = i; found = TRUE; - + } view->end_page = i; } else if (found) { break; } - if (view->dual_page) { - if (i % 2 == 0) { - page_area.x += page_area.width + view->spacing; - } else { - page_area.x = view->spacing; - page_area.y += page_area.height + view->spacing; - } - } else { - page_area.y += page_area.height + view->spacing; - } } current_page = ev_page_cache_get_current_page (view->page_cache); @@ -512,7 +509,7 @@ view_update_range_and_current_page (EvView *view) if (current_page < view->start_page || current_page > view->end_page) { view->current_page = view->start_page; ev_page_cache_set_current_page (view->page_cache, view->start_page); - } + } } else { if (view->dual_page) { if (view->current_page % 2 == 0) { @@ -532,75 +529,8 @@ view_update_range_and_current_page (EvView *view) ev_pixbuf_cache_set_page_range (view->pixbuf_cache, view->start_page, view->end_page, - view->scale); -} - -static void -view_scroll_to_page (EvView *view, gint new_page) -{ - EvPageCache *page_cache = view->page_cache; - int old_width, old_height; - int new_width, new_height; - int max_height, max_width, n_rows; - - ev_page_cache_get_size (page_cache, - view->current_page, - view->scale, - &old_width, &old_height); - - ev_page_cache_get_size (page_cache, - new_page, - view->scale, - &new_width, &new_height); - - compute_border (view, new_width, new_height, &(view->border)); - - if (new_width != old_width || new_height != old_height) - gtk_widget_queue_resize (GTK_WIDGET (view)); - else - gtk_widget_queue_draw (GTK_WIDGET (view)); - - get_bounding_box_size (view, &max_width, &max_height); - - if (view->vadjustment) { - if (view->continuous) { - - n_rows = view->dual_page ? new_page / 2 : new_page; - - gtk_adjustment_clamp_page(view->vadjustment, - (max_height + view->spacing) * n_rows, - (max_height + view->spacing) * n_rows + - view->vadjustment->page_size); - } else { - gtk_adjustment_set_value (view->vadjustment, - view->vadjustment->lower); - } - } - - if (view->hadjustment) { - if (view->dual_page) { - if (new_page % 2 == 0) { - gtk_adjustment_set_value (view->hadjustment, - view->hadjustment->lower); - } else { - gtk_adjustment_clamp_page (view->hadjustment, - view->hadjustment->lower + - max_width + view->spacing, - view->hadjustment->lower + - max_width + view->spacing + - view->hadjustment->page_size); - } - } else { - gtk_adjustment_set_value (view->hadjustment, - CLAMP (view->hadjustment->value, - view->hadjustment->lower, - view->hadjustment->upper - - view->hadjustment->page_size)); - } - } - - view->current_page = new_page; - view_update_range_and_current_page (view); + view->scale, + view->selection_info.selections); } static void @@ -642,7 +572,7 @@ ev_view_set_scroll_adjustments (EvView *view, set_scroll_adjustment (view, GTK_ORIENTATION_HORIZONTAL, hadjustment); set_scroll_adjustment (view, GTK_ORIENTATION_VERTICAL, vadjustment); - view_update_adjustments (view); + on_adjustment_value_changed (NULL, view); } static void @@ -654,11 +584,11 @@ add_scroll_binding_keypad (GtkBindingSet *binding_set, guint keypad_keyval = keyval - GDK_Left + GDK_KP_Left; gtk_binding_entry_add_signal (binding_set, keyval, 0, - "scroll_view", 2, + "binding_activated", 2, GTK_TYPE_SCROLL_TYPE, scroll, G_TYPE_BOOLEAN, horizontal); gtk_binding_entry_add_signal (binding_set, keypad_keyval, 0, - "scroll_view", 2, + "binding_activated", 2, GTK_TYPE_SCROLL_TYPE, scroll, G_TYPE_BOOLEAN, horizontal); } @@ -718,13 +648,27 @@ ev_view_scroll (EvView *view, } static void -ev_view_scroll_view (EvView *view, - GtkScrollType scroll, - gboolean horizontal) +ev_view_binding_activated (EvView *view, + GtkScrollType scroll, + gboolean horizontal) { GtkAdjustment *adjustment; double value; + if (view->presentation) { + switch (scroll) { + case GTK_SCROLL_STEP_BACKWARD: + ev_page_cache_prev_page (view->page_cache); + break; + case GTK_SCROLL_STEP_FORWARD: + ev_page_cache_next_page (view->page_cache); + break; + default: + break; + } + return; + } + if (horizontal) { adjustment = view->hadjustment; } else { @@ -799,6 +743,32 @@ compute_border (EvView *view, int width, int height, GtkBorder *border) } } +static void get_page_y_offset (EvView *view, + int page, + double zoom, + int *y_offset) +{ + int max_width, offset; + GtkBorder border; + + g_return_if_fail (y_offset != NULL); + + ev_page_cache_get_max_width (view->page_cache, zoom, &max_width); + + compute_border (view, max_width, max_width, &border); + + if (view->dual_page) { + ev_page_cache_get_height_to_page (view->page_cache, page, zoom, NULL, &offset); + offset += (page / 2 + 1) * view->spacing + (page / 2) * (border.top + border.bottom); + } else { + ev_page_cache_get_height_to_page (view->page_cache, page, zoom, &offset, NULL); + offset += (page + 1) * view->spacing + page * (border.top + border.bottom); + } + + *y_offset = offset; + return; +} + static gboolean get_page_extents (EvView *view, gint page, @@ -810,22 +780,6 @@ get_page_extents (EvView *view, widget = GTK_WIDGET (view); - /* Quick sanity check */ - if (view->presentation) { - if (view->current_page != page) - return FALSE; - } else if (view->continuous) { - if (page < view->start_page || - page > view->end_page) - return FALSE; - } else if (view->dual_page) { - if (ABS (page - view->current_page) > 1) - return FALSE; - } else { - if (view->current_page != page) - return FALSE; - } - /* Get the size of the page */ ev_page_cache_get_size (view->page_cache, page, view->scale, @@ -838,20 +792,24 @@ get_page_extents (EvView *view, page_area->x = (MAX (0, widget->allocation.width - width))/2; page_area->y = (MAX (0, widget->allocation.height - height))/2; } else if (view->continuous) { - gint max_width, max_height; + gint max_width; gint x, y; - get_bounding_box_size (view, &max_width, &max_height); + ev_page_cache_get_max_width (view->page_cache, view->scale, &max_width); + max_width = max_width + border->left + border->right; /* Get the location of the bounding box */ if (view->dual_page) { x = view->spacing + (page % 2) * (max_width + view->spacing); - y = view->spacing + (page / 2) * (max_height + view->spacing); - x = x + MAX (0, widget->allocation.width - (max_width * 2 + view->spacing * 3))/2; + x = x + MAX (0, widget->allocation.width - (max_width * 2 + view->spacing * 3)) / 2; + if (page % 2 == 0) + x = x + (max_width - width - border->left - border->right); } else { x = view->spacing; - y = view->spacing + page * (max_height + view->spacing); - x = x + MAX (0, widget->allocation.width - (max_width + view->spacing * 2))/2; + x = x + MAX (0, widget->allocation.width - (width + view->spacing * 2)) / 2; } + + get_page_y_offset (view, page, view->scale, &y); + page_area->x = x; page_area->y = y; } else { @@ -868,7 +826,7 @@ get_page_extents (EvView *view, /* First, we get the bounding box of the two pages */ if (other_page < ev_page_cache_get_n_pages (view->page_cache)) { ev_page_cache_get_size (view->page_cache, - page + 1, + other_page, view->scale, &width_2, &height_2); if (width_2 > width) @@ -899,8 +857,8 @@ get_page_extents (EvView *view, y = view->spacing; /* Adjust for extra allocation */ - x = x + MAX (0, widget->allocation.width - (width + view->spacing * 2))/2; - y = y + MAX (0, widget->allocation.height - (height + view->spacing * 2))/2; + 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; } page_area->x = x; @@ -910,16 +868,27 @@ get_page_extents (EvView *view, return TRUE; } +static void +view_point_to_doc_point (EvView *view, + GdkPoint *view_point, + GdkRectangle *page_area, + double *doc_point_x, + double *doc_point_y) +{ + *doc_point_x = (double) (view_point->x - page_area->x) / view->scale; + *doc_point_y = (double) (view_point->y - page_area->y) / view->scale; +} + static void view_rect_to_doc_rect (EvView *view, GdkRectangle *view_rect, GdkRectangle *page_area, EvRectangle *doc_rect) { - doc_rect->x1 = floor ((view_rect->x - page_area->x) / view->scale); - doc_rect->y1 = floor ((view_rect->y - page_area->y) / view->scale); - doc_rect->x2 = doc_rect->x1 + ceil (view_rect->width / view->scale); - doc_rect->y2 = doc_rect->y1 + ceil (view_rect->height / view->scale); + doc_rect->x1 = (double) (view_rect->x - page_area->x) / view->scale; + doc_rect->y1 = (double) (view_rect->y - page_area->y) / view->scale; + doc_rect->x2 = doc_rect->x1 + (double) view_rect->width / view->scale; + doc_rect->y2 = doc_rect->y1 + (double) view_rect->height / view->scale; } static void @@ -942,30 +911,6 @@ doc_rect_to_view_rect (EvView *view, view_rect->height = ceil (height * view->scale); } -static void -get_bounding_box_size (EvView *view, int *max_width, int *max_height) -{ - GtkBorder border; - int width, height; - - if (max_width) { - ev_page_cache_get_max_width_size (view->page_cache, - view->scale, - &width, &height); - compute_border (view, width, height, &border); - *max_width = width + border.left + border.right; - } - - - if (max_height) { - ev_page_cache_get_max_height_size (view->page_cache, - view->scale, - &width, &height); - compute_border (view, width, height, &border); - *max_height = height + border.top + border.bottom; - } -} - static void find_page_at_location (EvView *view, gdouble x, @@ -1004,6 +949,28 @@ find_page_at_location (EvView *view, *page = -1; } +static gboolean +location_in_text (EvView *view, + gdouble x, + gdouble y) +{ + GdkRegion *region; + gint page = -1; + gint x_offset = 0, y_offset = 0; + + find_page_at_location (view, x, y, &page, &x_offset, &y_offset); + + if (page == -1) + return FALSE; + + region = ev_pixbuf_cache_get_text_mapping (view->pixbuf_cache, page); + + if (region) + return gdk_region_point_in (region, x_offset / view->scale, y_offset / view->scale); + else + return FALSE; +} + /*** Hyperref ***/ static EvLink * get_link_at_location (EvView *view, @@ -1085,17 +1052,19 @@ status_message_from_link (EvView *view, EvLink *link) static void ev_view_size_request_continuous_dual_page (EvView *view, - GtkRequisition *requisition) + GtkRequisition *requisition) { - int max_width, max_height; - int n_rows; + int max_width; + gint n_pages; + GtkBorder border; - get_bounding_box_size (view, &max_width, &max_height); + ev_page_cache_get_max_width (view->page_cache, view->scale, &max_width); + compute_border (view, max_width, max_width, &border); - n_rows = (1 + ev_page_cache_get_n_pages (view->page_cache)) / 2; + n_pages = ev_page_cache_get_n_pages (view->page_cache) + 1; - requisition->width = (max_width * 2) + (view->spacing * 3); - requisition->height = max_height * n_rows + (view->spacing * (n_rows + 1)); + requisition->width = (max_width + border.left + border.right) * 2 + (view->spacing * 3); + get_page_y_offset (view, n_pages, view->scale, &requisition->height); if (view->sizing_mode == EV_SIZING_FIT_WIDTH) { requisition->width = 1; @@ -1111,15 +1080,17 @@ static void ev_view_size_request_continuous (EvView *view, GtkRequisition *requisition) { - int max_width, max_height; + int max_width; int n_pages; + GtkBorder border; - get_bounding_box_size (view, &max_width, &max_height); + ev_page_cache_get_max_width (view->page_cache, view->scale, &max_width); n_pages = ev_page_cache_get_n_pages (view->page_cache); + compute_border (view, max_width, max_width, &border); - requisition->width = max_width + (view->spacing * 2); - requisition->height = max_height * n_pages + (view->spacing * (n_pages + 1)); + requisition->width = max_width + (view->spacing * 2) + border.left + border.right; + get_page_y_offset (view, n_pages, view->scale, &requisition->height); if (view->sizing_mode == EV_SIZING_FIT_WIDTH) { requisition->width = 1; @@ -1227,15 +1198,15 @@ ev_view_size_allocate (GtkWidget *widget, GtkAllocation *allocation) { EvView *view = EV_VIEW (widget); - + if (view->sizing_mode == EV_SIZING_FIT_WIDTH || view->sizing_mode == EV_SIZING_BEST_FIT) { g_signal_emit (view, signals[SIGNAL_ZOOM_INVALID], 0); - + ev_view_size_request (widget, &widget->requisition); } - + view_set_adjustment_values (view, GTK_ORIENTATION_HORIZONTAL); view_set_adjustment_values (view, GTK_ORIENTATION_VERTICAL); @@ -1243,7 +1214,7 @@ ev_view_size_allocate (GtkWidget *widget, view->pending_resize = FALSE; if (view->document) - view_update_range_and_current_page (view); + view_update_range_and_current_page (view); GTK_WIDGET_CLASS (ev_view_parent_class)->size_allocate (widget, allocation); } @@ -1297,24 +1268,26 @@ ev_view_unrealize (GtkWidget *widget) static gboolean ev_view_scroll_event (GtkWidget *widget, GdkEventScroll *event) { - EvView *view = EV_VIEW (widget); - - if ((event->state & GDK_CONTROL_MASK) != 0) { + EvView *view = EV_VIEW (widget); - ev_view_set_sizing_mode (view, EV_SIZING_FREE); + if ((event->state & GDK_CONTROL_MASK) != 0) { - if ((event->direction == GDK_SCROLL_UP || - event->direction == GDK_SCROLL_LEFT) && - ev_view_can_zoom_in (view)) { - ev_view_zoom_in (view); - } else if (ev_view_can_zoom_out (view)) { - ev_view_zoom_out (view); - } + ev_view_set_sizing_mode (view, EV_SIZING_FREE); + if (event->direction == GDK_SCROLL_UP || + event->direction == GDK_SCROLL_LEFT) { + if (ev_view_can_zoom_in (view)) { + ev_view_zoom_in (view); + } + } else { + if (ev_view_can_zoom_out (view)) { + ev_view_zoom_out (view); + } + } return TRUE; } - - if ((event->state & GDK_SHIFT_MASK) != 0) { + + if ((event->state & GDK_SHIFT_MASK) != 0) { if (event->direction == GDK_SCROLL_UP) event->direction = GDK_SCROLL_LEFT; if (event->direction == GDK_SCROLL_DOWN) @@ -1324,13 +1297,29 @@ ev_view_scroll_event (GtkWidget *widget, GdkEventScroll *event) return FALSE; } +static EvViewSelection * +find_selection_for_page (EvView *view, + gint page) +{ + GList *list; + + for (list = view->selection_info.selections; list != NULL; list = list->next) { + EvViewSelection *selection; + + selection = (EvViewSelection *) list->data; + + if (selection->page == page) + return selection; + } + + return NULL; +} + static gboolean ev_view_expose_event (GtkWidget *widget, GdkEventExpose *event) { EvView *view = EV_VIEW (widget); - GdkRectangle rubberband; - GList *l; int i; if (view->document == NULL) @@ -1342,26 +1331,14 @@ ev_view_expose_event (GtkWidget *widget, if (!get_page_extents (view, i, &page_area, &border)) continue; - + page_area.x -= view->scroll_x; page_area.y -= view->scroll_y; - + draw_one_page (view, i, &page_area, &border, &(event->area)); - if (EV_IS_DOCUMENT_FIND (view->document)) { + if (EV_IS_DOCUMENT_FIND (view->document)) highlight_find_results (view, i); - } - } - - for (l = view->selections; l != NULL; l = l->next) { - EvViewSelection *selection = (EvViewSelection *)l->data; - - doc_rect_to_view_rect (view, selection->page, - &selection->rect, &rubberband); - if (rubberband.width > 0 && rubberband.height > 0) { - draw_rubberband (GTK_WIDGET (view), GTK_WIDGET(view)->window, - &rubberband, 0x40); - } } return FALSE; @@ -1381,13 +1358,13 @@ ev_view_button_press_event (GtkWidget *widget, switch (event->button) { case 1: - if (view->selections) { + if (view->selection_info.selections) { clear_selection (view); gtk_widget_queue_draw (widget); } - view->selection_start.x = event->x; - view->selection_start.y = event->y; + view->selection_info.start.x = event->x + view->scroll_x; + view->selection_info.start.y = event->y + view->scroll_y; return TRUE; case 2: /* use root coordinates as reference point because @@ -1411,21 +1388,20 @@ ev_view_motion_notify_event (GtkWidget *widget, { EvView *view = EV_VIEW (widget); - if (view->pressed_button == 1) { - GdkRectangle selection; - - selection.x = MIN (view->selection_start.x, event->x) + view->scroll_x; - selection.y = MIN (view->selection_start.y, event->y) + view->scroll_y; - selection.width = ABS (view->selection_start.x - event->x) + 1; - selection.height = ABS (view->selection_start.y - event->y) + 1; + if (!view->document) + return FALSE; - compute_selections (view, &selection); + if (view->pressed_button == 1) { + GdkPoint point; - gtk_widget_queue_draw (widget); + view->selection_info.in_selection = TRUE; + point.x = event->x + view->scroll_x; + point.y = event->y + view->scroll_y; + compute_selections (view, &view->selection_info.start, &point); return TRUE; } else if (view->pressed_button == 2) { - if (!view->drag_info.dragging) { + if (!view->drag_info.in_drag) { gboolean start; start = gtk_drag_check_threshold (widget, @@ -1433,10 +1409,10 @@ ev_view_motion_notify_event (GtkWidget *widget, view->drag_info.start.y, event->x_root, event->y_root); - view->drag_info.dragging = start; + view->drag_info.in_drag = start; } - if (view->drag_info.dragging) { + if (view->drag_info.in_drag) { int dx, dy; gdouble dhadj_value, dvadj_value; @@ -1460,7 +1436,7 @@ ev_view_motion_notify_event (GtkWidget *widget, return TRUE; } - } else if (view->pressed_button <= 0 && view->document) { + } else if (view->pressed_button <= 0) { EvLink *link; link = get_link_at_location (view, event->x + view->scroll_x, event->y + view->scroll_y); @@ -1471,11 +1447,13 @@ ev_view_motion_notify_event (GtkWidget *widget, ev_view_set_status (view, msg); ev_view_set_cursor (view, EV_VIEW_CURSOR_LINK); g_free (msg); + } else if (location_in_text (view, event->x + view->scroll_x, event->y + view->scroll_y)) { + ev_view_set_cursor (view, EV_VIEW_CURSOR_IBEAM); } else { ev_view_set_status (view, NULL); - if (view->cursor == EV_VIEW_CURSOR_LINK) { + if (view->cursor == EV_VIEW_CURSOR_LINK || + view->cursor == EV_VIEW_CURSOR_IBEAM) ev_view_set_cursor (view, EV_VIEW_CURSOR_NORMAL); - } } return TRUE; } @@ -1494,9 +1472,9 @@ ev_view_button_release_event (GtkWidget *widget, } view->pressed_button = -1; - view->drag_info.dragging = FALSE; + view->drag_info.in_drag = FALSE; - if (view->selections) { + if (view->selection_info.selections) { ev_view_update_primary_selection (view); } else if (view->document) { EvLink *link; @@ -1530,7 +1508,7 @@ draw_rubberband (GtkWidget *widget, GdkWindow *window, GdkPixbuf *pixbuf; GdkColor *fill_color_gdk; guint fill_color; - + 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; @@ -1591,27 +1569,26 @@ highlight_find_results (EvView *view, int page) } static void -draw_one_page (EvView *view, - gint page, - GdkRectangle *page_area, - GtkBorder *border, - GdkRectangle *expose_area) +draw_one_page (EvView *view, + gint page, + GdkRectangle *page_area, + GtkBorder *border, + GdkRectangle *expose_area) { gint width, height; - GdkPixbuf *scaled_image; GdkPixbuf *current_pixbuf; GdkRectangle overlap; GdkRectangle real_page_area; + EvViewSelection *selection; g_assert (view->document); - - if (!gdk_rectangle_intersect (page_area, expose_area, &overlap)) + if (! gdk_rectangle_intersect (page_area, expose_area, &overlap)) return; + selection = find_selection_for_page (view, page); ev_page_cache_get_size (view->page_cache, page, view->scale, &width, &height); - /* Render the document itself */ real_page_area = *page_area; @@ -1620,36 +1597,72 @@ draw_one_page (EvView *view, real_page_area.width -= (border->left + border->right); real_page_area.height -= (border->top + border->bottom); - if (! gdk_rectangle_intersect (&real_page_area, expose_area, &overlap)) - return; - ev_document_misc_paint_one_page (GTK_WIDGET(view)->window, GTK_WIDGET (view), page_area, border); - current_pixbuf = ev_pixbuf_cache_get_pixbuf (view->pixbuf_cache, page); + if (gdk_rectangle_intersect (&real_page_area, expose_area, &overlap)) { + GdkPixbuf *selection_pixbuf = NULL; + GdkPixbuf *scaled_image; + GdkPixbuf *scaled_selection; - if (current_pixbuf == NULL) - scaled_image = NULL; - else if (width == gdk_pixbuf_get_width (current_pixbuf) && - height == gdk_pixbuf_get_height (current_pixbuf)) - scaled_image = g_object_ref (current_pixbuf); - else - scaled_image = gdk_pixbuf_scale_simple (current_pixbuf, - width, height, - GDK_INTERP_NEAREST); + current_pixbuf = ev_pixbuf_cache_get_pixbuf (view->pixbuf_cache, page); + + /* Get the selection pixbuf iff we have something to draw */ + if (current_pixbuf && view->selection_mode == EV_VIEW_SELECTION_TEXT && selection) + selection_pixbuf = ev_pixbuf_cache_get_selection_pixbuf (view->pixbuf_cache, + page, + view->scale); + + if (current_pixbuf == NULL) + scaled_image = NULL; + else if (width == gdk_pixbuf_get_width (current_pixbuf) && + height == gdk_pixbuf_get_height (current_pixbuf)) + scaled_image = g_object_ref (current_pixbuf); + else + /* FIXME: We don't want to scale the whole area, just the right + * area of it */ + scaled_image = gdk_pixbuf_scale_simple (current_pixbuf, + width, height, + GDK_INTERP_NEAREST); + + if (selection_pixbuf == NULL) + scaled_selection = NULL; + else if (width == gdk_pixbuf_get_width (selection_pixbuf) && + height == gdk_pixbuf_get_height (selection_pixbuf)) + scaled_selection = g_object_ref (selection_pixbuf); + else + /* FIXME: We don't want to scale the whole area, just the right + * area of it */ + scaled_selection = gdk_pixbuf_scale_simple (selection_pixbuf, + width, height, + GDK_INTERP_NEAREST); + + if (scaled_image) { + gdk_draw_pixbuf (GTK_WIDGET(view)->window, + GTK_WIDGET (view)->style->fg_gc[GTK_STATE_NORMAL], + scaled_image, + overlap.x - real_page_area.x, + overlap.y - real_page_area.y, + overlap.x, overlap.y, + overlap.width, overlap.height, + GDK_RGB_DITHER_NORMAL, + 0, 0); + g_object_unref (scaled_image); + } - if (scaled_image) { - gdk_draw_pixbuf (GTK_WIDGET(view)->window, - GTK_WIDGET (view)->style->fg_gc[GTK_STATE_NORMAL], - scaled_image, - overlap.x - real_page_area.x, - overlap.y - real_page_area.y, - overlap.x, overlap.y, - overlap.width, overlap.height, - GDK_RGB_DITHER_NORMAL, - 0, 0); - g_object_unref (scaled_image); + if (scaled_selection) { + gdk_draw_pixbuf (GTK_WIDGET(view)->window, + GTK_WIDGET (view)->style->fg_gc[GTK_STATE_NORMAL], + scaled_selection, + overlap.x - real_page_area.x, + overlap.y - real_page_area.y, + overlap.x, overlap.y, + overlap.width, overlap.height, + GDK_RGB_DITHER_NORMAL, + 0, 0); + g_object_unref (scaled_selection); + } } } @@ -1713,6 +1726,9 @@ ev_view_set_property (GObject *object, case PROP_SIZING_MODE: ev_view_set_sizing_mode (view, g_value_get_enum (value)); break; + case PROP_ZOOM: + ev_view_set_zoom (view, g_value_get_double (value), FALSE); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } @@ -1749,6 +1765,9 @@ ev_view_get_property (GObject *object, case PROP_SIZING_MODE: g_value_set_enum (value, view->sizing_mode); break; + case PROP_ZOOM: + g_value_set_double (value, view->scale); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } @@ -1778,9 +1797,9 @@ ev_view_class_init (EvViewClass *class) gtk_object_class->destroy = ev_view_destroy; class->set_scroll_adjustments = ev_view_set_scroll_adjustments; - class->scroll_view = ev_view_scroll_view; + class->binding_activated = ev_view_binding_activated; - widget_class->set_scroll_adjustments_signal = + widget_class->set_scroll_adjustments_signal = g_signal_new ("set-scroll-adjustments", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, @@ -1791,10 +1810,10 @@ ev_view_class_init (EvViewClass *class) GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT); - signals[SIGNAL_SCROLL_VIEW] = g_signal_new ("scroll-view", + signals[SIGNAL_BINDING_ACTIVATED] = g_signal_new ("binding_activated", G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, - G_STRUCT_OFFSET (EvViewClass, scroll_view), + G_STRUCT_OFFSET (EvViewClass, binding_activated), NULL, NULL, ev_marshal_VOID__ENUM_BOOLEAN, G_TYPE_NONE, 2, @@ -1864,6 +1883,16 @@ ev_view_class_init (EvViewClass *class) EV_SIZING_FIT_WIDTH, G_PARAM_READWRITE)); + g_object_class_install_property (object_class, + PROP_ZOOM, + g_param_spec_double ("zoom", + "Zoom factor", + "Zoom factor", + MIN_SCALE, + MAX_SCALE, + 1.0, + G_PARAM_READWRITE)); + binding_set = gtk_binding_set_by_class (class); add_scroll_binding_keypad (binding_set, GDK_Left, GTK_SCROLL_STEP_BACKWARD, TRUE); @@ -1877,13 +1906,15 @@ ev_view_init (EvView *view) { GTK_WIDGET_SET_FLAGS (view, GTK_CAN_FOCUS); - view->spacing = 10; + view->spacing = 5; view->scale = 1.0; view->current_page = 0; view->pressed_button = -1; view->cursor = EV_VIEW_CURSOR_NORMAL; - view->drag_info.dragging = FALSE; + view->drag_info.in_drag = FALSE; + view->selection_info.in_selection = FALSE; + view->selection_mode = EV_VIEW_SELECTION_TEXT; view->continuous = TRUE; view->dual_page = FALSE; view->presentation = FALSE; @@ -1919,13 +1950,9 @@ page_changed_cb (EvPageCache *page_cache, { if (view->current_page != new_page) { - if (view->pending_scroll != SCROLL_TO_CURRENT_PAGE) { - /* Should scroll right now */ - view_scroll_to_page (view, new_page); - } else { - /* We'll scroll to new page on allocate */ - view->current_page = new_page; - } + view->current_page = new_page; + view->pending_scroll = SCROLL_TO_CURRENT_PAGE; + gtk_widget_queue_resize (GTK_WIDGET (view)); if (EV_IS_DOCUMENT_FIND (view->document)) { view->find_page = new_page; @@ -1938,7 +1965,34 @@ page_changed_cb (EvPageCache *page_cache, static void on_adjustment_value_changed (GtkAdjustment *adjustment, EvView *view) { - view_update_adjustments (view); + int dx = 0, dy = 0; + + if (! GTK_WIDGET_REALIZED (view)) + return; + + if (view->hadjustment) { + dx = view->scroll_x - (int) view->hadjustment->value; + view->scroll_x = (int) view->hadjustment->value; + } else { + view->scroll_x = 0; + } + + if (view->vadjustment) { + dy = view->scroll_y - (int) view->vadjustment->value; + view->scroll_y = (int) view->vadjustment->value; + } else { + view->scroll_y = 0; + } + + + if (view->pending_resize) + gtk_widget_queue_draw (GTK_WIDGET (view)); + else + gdk_window_scroll (GTK_WIDGET (view)->window, dx, dy); + + + if (view->document) + view_update_range_and_current_page (view); } GtkWidget* @@ -1951,6 +2005,28 @@ ev_view_new (void) return view; } +static void +setup_caches (EvView *view) +{ + view->page_cache = ev_page_cache_get (view->document); + g_signal_connect (view->page_cache, "page-changed", G_CALLBACK (page_changed_cb), view); + view->pixbuf_cache = ev_pixbuf_cache_new (view->document); + g_signal_connect (view->pixbuf_cache, "job-finished", G_CALLBACK (job_finished_cb), view); +} + +static void +clear_caches (EvView *view) +{ + if (view->pixbuf_cache) { + g_object_unref (view->pixbuf_cache); + view->pixbuf_cache = NULL; + } + + if (view->document) { + ev_page_cache_clear (view->document); + } +} + void ev_view_set_document (EvView *view, EvDocument *document) @@ -1958,6 +2034,8 @@ ev_view_set_document (EvView *view, g_return_if_fail (EV_IS_VIEW (view)); if (document != view->document) { + clear_caches (view); + if (view->document) { g_signal_handlers_disconnect_by_func (view->document, find_changed_cb, @@ -1979,11 +2057,8 @@ ev_view_set_document (EvView *view, G_CALLBACK (find_changed_cb), view); } - view->page_cache = ev_document_get_page_cache (view->document); - view->pending_scroll = SCROLL_TO_CURRENT_PAGE; - g_signal_connect (view->page_cache, "page-changed", G_CALLBACK (page_changed_cb), view); - view->pixbuf_cache = ev_pixbuf_cache_new (view->document); - g_signal_connect (view->pixbuf_cache, "job-finished", G_CALLBACK (job_finished_cb), view); + + setup_caches (view); } gtk_widget_queue_resize (GTK_WIDGET (view)); @@ -2009,10 +2084,13 @@ ev_view_set_zoom (EvView *view, if (ABS (view->scale - scale) < EPSILON) return; + view->scale = scale; view->pending_resize = TRUE; gtk_widget_queue_resize (GTK_WIDGET (view)); + + g_object_notify (G_OBJECT (view), "zoom"); } double @@ -2021,6 +2099,14 @@ ev_view_get_zoom (EvView *view) return view->scale; } +gboolean +ev_view_get_continuous (EvView *view) +{ + g_return_val_if_fail (EV_IS_VIEW (view), FALSE); + + return view->continuous; +} + void ev_view_set_continuous (EvView *view, gboolean continuous) @@ -2038,6 +2124,14 @@ ev_view_set_continuous (EvView *view, g_object_notify (G_OBJECT (view), "continuous"); } +gboolean +ev_view_get_dual_page (EvView *view) +{ + g_return_val_if_fail (EV_IS_VIEW (view), FALSE); + + return view->dual_page; +} + void ev_view_set_dual_page (EvView *view, gboolean dual_page) @@ -2048,7 +2142,7 @@ ev_view_set_dual_page (EvView *view, if (view->dual_page == dual_page) return; - + view->pending_scroll = SCROLL_TO_CURRENT_PAGE; view->dual_page = dual_page; /* FIXME: if we're keeping the pixbuf cache around, we should extend the @@ -2067,11 +2161,12 @@ ev_view_set_fullscreen (EvView *view, fullscreen = fullscreen != FALSE; - if (view->fullscreen != fullscreen) { - view->fullscreen = fullscreen; - gtk_widget_queue_resize (GTK_WIDGET (view)); - } - + if (view->fullscreen == fullscreen) + return; + + view->fullscreen = fullscreen; + gtk_widget_queue_resize (GTK_WIDGET (view)); + g_object_notify (G_OBJECT (view), "fullscreen"); } @@ -2095,7 +2190,9 @@ ev_view_set_presentation (EvView *view, return; view->presentation = presentation; + view->pending_scroll = SCROLL_TO_CURRENT_PAGE; gtk_widget_queue_resize (GTK_WIDGET (view)); + if (GTK_WIDGET_REALIZED (view)) { if (view->presentation) gdk_window_set_background (GTK_WIDGET(view)->window, @@ -2128,7 +2225,7 @@ ev_view_set_sizing_mode (EvView *view, view->sizing_mode = sizing_mode; gtk_widget_queue_resize (GTK_WIDGET (view)); - + g_object_notify (G_OBJECT (view), "sizing-mode"); } @@ -2156,7 +2253,7 @@ void ev_view_zoom_in (EvView *view) { g_return_if_fail (view->sizing_mode == EV_SIZING_FREE); - + view->pending_scroll = SCROLL_TO_CENTER; ev_view_set_zoom (view, ZOOM_IN_FACTOR, TRUE); } @@ -2170,6 +2267,54 @@ ev_view_zoom_out (EvView *view) ev_view_set_zoom (view, ZOOM_OUT_FACTOR, TRUE); } +static void +ev_view_set_orientation (EvView *view, + EvOrientation orientation) +{ + ev_document_set_orientation (view->document, orientation); + + clear_caches (view); + setup_caches (view); + + gtk_widget_queue_resize (GTK_WIDGET (view)); +} + +void +ev_view_rotate_right (EvView *view) +{ + EvOrientation orientation, new_orientation; + + orientation = ev_document_get_orientation (view->document); + if (orientation == EV_ORIENTATION_PORTRAIT) { + new_orientation = EV_ORIENTATION_LANDSCAPE; + } else if (orientation == EV_ORIENTATION_LANDSCAPE) { + new_orientation = EV_ORIENTATION_UPSIDEDOWN; + } else if (orientation == EV_ORIENTATION_UPSIDEDOWN) { + new_orientation = EV_ORIENTATION_SEASCAPE; + } else { + new_orientation = EV_ORIENTATION_PORTRAIT; + } + ev_view_set_orientation (view, new_orientation); +} + +void +ev_view_rotate_left (EvView *view) +{ + EvOrientation orientation, new_orientation; + + orientation = ev_document_get_orientation (view->document); + if (orientation == EV_ORIENTATION_PORTRAIT) { + new_orientation = EV_ORIENTATION_SEASCAPE; + } else if (orientation == EV_ORIENTATION_SEASCAPE) { + new_orientation = EV_ORIENTATION_UPSIDEDOWN; + } else if (orientation == EV_ORIENTATION_UPSIDEDOWN) { + new_orientation = EV_ORIENTATION_LANDSCAPE; + } else { + new_orientation = EV_ORIENTATION_PORTRAIT; + } + ev_view_set_orientation (view, new_orientation); +} + static double zoom_for_size_fit_width (int doc_width, int doc_height, @@ -2238,12 +2383,12 @@ ev_view_zoom_for_size_continuous_and_dual_page (EvView *view, GtkBorder border; gdouble scale; - ev_page_cache_get_max_width_size (view->page_cache, - 1.0, - &doc_width, NULL); - ev_page_cache_get_max_height_size (view->page_cache, - 1.0, - NULL, &doc_height); + ev_page_cache_get_max_width (view->page_cache, + 1.0, + &doc_width); + ev_page_cache_get_max_height (view->page_cache, + 1.0, + &doc_height); compute_border (view, doc_width, doc_height, &border); doc_width = doc_width * 2; @@ -2274,12 +2419,12 @@ ev_view_zoom_for_size_continuous (EvView *view, GtkBorder border; gdouble scale; - ev_page_cache_get_max_width_size (view->page_cache, - 1.0, - &doc_width, NULL); - ev_page_cache_get_max_height_size (view->page_cache, - 1.0, - NULL, &doc_height); + ev_page_cache_get_max_width (view->page_cache, + 1.0, + &doc_width); + ev_page_cache_get_max_height (view->page_cache, + 1.0, + &doc_height); compute_border (view, doc_width, doc_height, &border); width -= (border.left + border.right + 2 * view->spacing); @@ -2383,7 +2528,7 @@ ev_view_set_zoom_for_size (EvView *view, int height, int vsb_width, int hsb_height) -{ +{ g_return_if_fail (view->sizing_mode == EV_SIZING_FIT_WIDTH || view->sizing_mode == EV_SIZING_BEST_FIT); g_return_if_fail (width >= 0); @@ -2447,10 +2592,8 @@ update_find_status_message (EvView *view) } else { double percent; - ev_document_doc_mutex_lock (); percent = ev_document_find_get_progress (EV_DOCUMENT_FIND (view->document)); - ev_document_doc_mutex_unlock (); if (percent >= (1.0 - 1e-10)) { message = g_strdup (_("Not found")); } else { @@ -2460,6 +2603,7 @@ update_find_status_message (EvView *view) } ev_view_set_find_status (view, message); + g_free (message); } const char * @@ -2491,15 +2635,11 @@ jump_to_find_result (EvView *view) int n_results; int page = view->find_page; - ev_document_doc_mutex_lock (); n_results = ev_document_find_get_n_results (find, page); - ev_document_doc_mutex_unlock (); if (n_results > view->find_result) { - ev_document_doc_mutex_lock (); ev_document_find_get_result (find, page, view->find_result, &rect); - ev_document_doc_mutex_unlock (); doc_rect_to_view_rect (view, page, &rect, &view_rect); ensure_rectangle_is_visible (view, &view_rect); @@ -2543,9 +2683,7 @@ ev_view_can_find_next (EvView *view) if (EV_IS_DOCUMENT_FIND (view->document)) { EvDocumentFind *find = EV_DOCUMENT_FIND (view->document); - ev_document_doc_mutex_lock (); n_results = ev_document_find_get_n_results (find, view->current_page); - ev_document_doc_mutex_unlock (); } return n_results > 0; @@ -2558,10 +2696,8 @@ ev_view_find_next (EvView *view) int n_results, n_pages; EvDocumentFind *find = EV_DOCUMENT_FIND (view->document); - page_cache = ev_document_get_page_cache (view->document); - ev_document_doc_mutex_lock (); + page_cache = ev_page_cache_get (view->document); n_results = ev_document_find_get_n_results (find, view->current_page); - ev_document_doc_mutex_unlock (); n_pages = ev_page_cache_get_n_pages (page_cache); @@ -2589,11 +2725,9 @@ ev_view_find_previous (EvView *view) EvDocumentFind *find = EV_DOCUMENT_FIND (view->document); EvPageCache *page_cache; - page_cache = ev_document_get_page_cache (view->document); + page_cache = ev_page_cache_get (view->document); - ev_document_doc_mutex_lock (); n_results = ev_document_find_get_n_results (find, view->current_page); - ev_document_doc_mutex_unlock (); n_pages = ev_page_cache_get_n_pages (page_cache); @@ -2616,22 +2750,35 @@ ev_view_find_previous (EvView *view) /*** Selections ***/ -static void -compute_selections (EvView *view, GdkRectangle *view_rect) +/* compute_new_selection_rect/text calculates the area currently selected by + * view_rect. each handles a different mode; + */ +static GList * +compute_new_selection_rect (EvView *view, + GdkPoint *start, + GdkPoint *stop) { + GdkRectangle view_rect; int n_pages, i; + GList *list = NULL; - clear_selection (view); + g_assert (view->selection_mode == EV_VIEW_SELECTION_RECTANGLE); + + view_rect.x = MIN (start->x, stop->x); + view_rect.y = MIN (start->y, stop->y); + view_rect.width = MAX (start->x, stop->x) - view_rect.x; + view_rect.width = MAX (start->y, stop->y) - view_rect.y; n_pages = ev_page_cache_get_n_pages (view->page_cache); + for (i = 0; i < n_pages; i++) { GdkRectangle page_area; GtkBorder border; - + if (get_page_extents (view, i, &page_area, &border)) { GdkRectangle overlap; - if (gdk_rectangle_intersect (&page_area, view_rect, &overlap)) { + if (gdk_rectangle_intersect (&page_area, &view_rect, &overlap)) { EvViewSelection *selection; selection = g_new0 (EvViewSelection, 1); @@ -2639,18 +2786,148 @@ compute_selections (EvView *view, GdkRectangle *view_rect) view_rect_to_doc_rect (view, &overlap, &page_area, &(selection->rect)); - view->selections = g_list_append - (view->selections, selection); + list = g_list_append (list, selection); } } } + + return list; +} + +static gboolean +gdk_rectangle_point_in (GdkRectangle *rectangle, + GdkPoint *point) +{ + return rectangle->x <= point->x && + rectangle->y <= point->y && + point->x < rectangle->x + rectangle->width && + point->y < rectangle->y + rectangle->height; +} + +static GList * +compute_new_selection_text (EvView *view, + GdkPoint *start, + GdkPoint *stop) +{ + int n_pages, i, first, last; + GList *list = NULL; + EvViewSelection *selection; + gint width, height; + + g_assert (view->selection_mode == EV_VIEW_SELECTION_TEXT); + + n_pages = ev_page_cache_get_n_pages (view->page_cache); + + /* First figure out the range of pages the selection + * affects. */ + first = n_pages; + last = 0; + for (i = 0; i < n_pages; i++) { + GdkRectangle page_area; + GtkBorder border; + + 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) + first = i; + last = i; + } + + } + + + + /* Now create a list of EvViewSelection's for the affected + * pages. This could be an empty list, a list of just one + * page or a number of pages.*/ + for (i = first; i < last + 1; i++) { + GdkRectangle page_area; + GtkBorder border; + GdkPoint *point; + + ev_page_cache_get_size (view->page_cache, i, + 1.0, &width, &height); + + selection = g_new0 (EvViewSelection, 1); + selection->page = i; + selection->rect.x1 = selection->rect.y1 = 0; + selection->rect.x2 = width; + selection->rect.y2 = height; + + get_page_extents (view, i, &page_area, &border); + + if (gdk_rectangle_point_in (&page_area, start)) + point = start; + else + point = stop; + + if (i == first) + view_point_to_doc_point (view, point, &page_area, + &selection->rect.x1, + &selection->rect.y1); + + /* If the selection is contained within just one page, + * make sure we don't write 'start' into both points + * in selection->rect. */ + if (first == last) + point = stop; + + if (i == last) + view_point_to_doc_point (view, point, &page_area, + &selection->rect.x2, + &selection->rect.y2); + + list = g_list_append (list, selection); + } + + return list; +} + +/* This function takes the newly calculated list, and figures out which regions + * have changed. It then queues a redraw approporiately. + */ +static void +merge_selection_region (EvView *view, + GList *list) +{ + + /* FIXME: actually write... */ + clear_selection (view); + gtk_widget_queue_draw (GTK_WIDGET (view)); + + view->selection_info.selections = list; + ev_pixbuf_cache_set_selection_list (view->pixbuf_cache, list); +} + +static void +compute_selections (EvView *view, + GdkPoint *start, + GdkPoint *stop) +{ + GList *list; + + if (view->selection_mode == EV_VIEW_SELECTION_RECTANGLE) + list = compute_new_selection_rect (view, start, stop); + else + list = compute_new_selection_text (view, start, stop); + merge_selection_region (view, list); +} + +/* Free's the selection. It's up to the caller to queue redraws if needed. + */ +static void +selection_free (EvViewSelection *selection) +{ + g_free (selection); } static void clear_selection (EvView *view) { - g_list_foreach (view->selections, (GFunc)g_free, NULL); - view->selections = NULL; + g_list_foreach (view->selection_info.selections, (GFunc)selection_free, NULL); + view->selection_info.selections = NULL; + view->selection_info.in_selection = FALSE; } @@ -2675,9 +2952,10 @@ ev_view_select_all (EvView *view) selection->rect.x2 = width; selection->rect.y2 = height; - view->selections = g_list_append (view->selections, selection); + view->selection_info.selections = g_list_append (view->selection_info.selections, selection); } + ev_pixbuf_cache_set_selection_list (view->pixbuf_cache, view->selection_info.selections); gtk_widget_queue_draw (GTK_WIDGET (view)); } @@ -2691,7 +2969,7 @@ get_selected_text (EvView *ev_view) ev_document_doc_mutex_lock (); - for (l = ev_view->selections; l != NULL; l = l->next) { + for (l = ev_view->selection_info.selections; l != NULL; l = l->next) { EvViewSelection *selection = (EvViewSelection *)l->data; char *tmp; @@ -2759,7 +3037,7 @@ ev_view_update_primary_selection (EvView *ev_view) clipboard = gtk_widget_get_clipboard (GTK_WIDGET (ev_view), GDK_SELECTION_PRIMARY); - if (ev_view->selections) { + if (ev_view->selection_info.selections) { if (!gtk_clipboard_set_with_owner (clipboard, targets, G_N_ELEMENTS (targets), @@ -2806,6 +3084,9 @@ ev_view_set_cursor (EvView *view, EvViewCursor new_cursor) case EV_VIEW_CURSOR_NORMAL: gdk_window_set_cursor (widget->window, NULL); break; + case EV_VIEW_CURSOR_IBEAM: + cursor = gdk_cursor_new_for_display (display, GDK_XTERM); + break; case EV_VIEW_CURSOR_LINK: cursor = gdk_cursor_new_for_display (display, GDK_HAND2); break;