summaryrefslogtreecommitdiff
path: root/libview/ev-view.c
diff options
context:
space:
mode:
authorCarlos Garcia Campos <[email protected]>2013-06-21 12:00:09 +0200
committerraveit65 <[email protected]>2017-09-06 18:25:34 +0200
commitaca6593233a34900a78c03738ab6be829c196648 (patch)
treefe88567e0d0d6bd6d09604b140c947c7a0019464 /libview/ev-view.c
parentd4c00dabb6e31a6016150f18e216fbe7660b28e0 (diff)
downloadatril-aca6593233a34900a78c03738ab6be829c196648.tar.bz2
atril-aca6593233a34900a78c03738ab6be829c196648.tar.xz
libview: merge get_caret_cursor_rect_from_offset and get_caret_cursor_area
Into a single function and use get_caret_cursor_area everywhere. get_caret_cursor_rect_from_offset() was a bit confusing, because it didn't return the cursor_rect, but the bbox of the character where the cursor should be at. The method that actually returns the cursor_rect is get_caret_cursor_area. origin commit: https://git.gnome.org/browse/evince/commit/?h=gnome-3-10&id=13a5978
Diffstat (limited to 'libview/ev-view.c')
-rw-r--r--libview/ev-view.c56
1 files changed, 22 insertions, 34 deletions
diff --git a/libview/ev-view.c b/libview/ev-view.c
index 2cccdb6a..0bbbd670 100644
--- a/libview/ev-view.c
+++ b/libview/ev-view.c
@@ -3280,20 +3280,18 @@ get_cursor_blink_timeout_id (EvView *view)
}
static gboolean
-get_caret_cursor_rect_from_offset (EvView *view,
- gint offset,
- gint page,
- GdkRectangle *rect)
+get_caret_cursor_area (EvView *view,
+ gint page,
+ gint offset,
+ GdkRectangle *area)
{
EvRectangle *areas = NULL;
EvRectangle *doc_rect;
guint n_areas = 0;
+ gfloat cursor_aspect_ratio;
+ gint stem_width;
- if (!view->caret_enabled)
- return FALSE;
-
- /* Disable caret navigation on rotated pages */
- if (view->rotation != 0)
+ if (!view->caret_enabled || view->rotation != 0)
return FALSE;
if (!view->page_cache)
@@ -3322,34 +3320,19 @@ get_caret_cursor_rect_from_offset (EvView *view,
last_rect.x2 = prev->x2 + (prev->x2 - prev->x1);
last_rect.y2 = prev->y2;
- _ev_view_transform_doc_rect_to_view_rect (view, page, &last_rect, rect);
-
- return TRUE;
+ _ev_view_transform_doc_rect_to_view_rect (view, page, &last_rect, area);
+ } else {
+ _ev_view_transform_doc_rect_to_view_rect (view, page, doc_rect, area);
}
- _ev_view_transform_doc_rect_to_view_rect (view, page, doc_rect, rect);
-
- return TRUE;
-}
-
-static gboolean
-get_caret_cursor_area (EvView *view,
- GdkRectangle *area)
-{
- gfloat cursor_aspect_ratio;
- gint stem_width;
-
- if (!get_caret_cursor_rect_from_offset (view, view->cursor_offset, view->cursor_page, area))
- return FALSE;
-
- area->x = area->x - view->scroll_x;
- area->y = area->y - view->scroll_y;
+ area->x -= view->scroll_x;
+ area->y -= view->scroll_y;
gtk_style_context_get_style (gtk_widget_get_style_context (GTK_WIDGET (view)),
"cursor-aspect-ratio", &cursor_aspect_ratio,
NULL);
stem_width = area->height * cursor_aspect_ratio + 1;
- area->x = area->x - (stem_width / 2);
+ area->x -= (stem_width / 2);
area->width = stem_width;
return TRUE;
@@ -3366,7 +3349,8 @@ show_cursor (EvView *view)
widget = GTK_WIDGET (view);
view->cursor_visible = TRUE;
- if (gtk_widget_has_focus (widget) && get_caret_cursor_area (view, &view_rect)) {
+ if (gtk_widget_has_focus (widget) &&
+ get_caret_cursor_area (view, view->cursor_page, view->cursor_offset, &view_rect)) {
gtk_widget_queue_draw_area (widget,
view_rect.x, view_rect.y,
view_rect.width, view_rect.height);
@@ -3384,7 +3368,8 @@ hide_cursor (EvView *view)
widget = GTK_WIDGET (view);
view->cursor_visible = FALSE;
- if (gtk_widget_has_focus (widget) && get_caret_cursor_area (view, &view_rect)) {
+ if (gtk_widget_has_focus (widget) &&
+ get_caret_cursor_area (view, view->cursor_page, view->cursor_offset, &view_rect)) {
gtk_widget_queue_draw_area (widget,
view_rect.x, view_rect.y,
view_rect.width, view_rect.height);
@@ -3952,7 +3937,7 @@ draw_caret_cursor (EvView *view,
GdkRectangle view_rect;
GdkRGBA cursor_color;
- if (!get_caret_cursor_area (view, &view_rect))
+ if (!get_caret_cursor_area (view, view->cursor_page, view->cursor_offset, &view_rect))
return;
get_cursor_color (gtk_widget_get_style_context (GTK_WIDGET (view)), &cursor_color);
@@ -5256,9 +5241,12 @@ ev_view_move_cursor (EvView *view,
GdkRectangle view_rect;
/* scroll to view the caret cursor */
- if (!get_caret_cursor_rect_from_offset (view, view->cursor_offset, view->cursor_page, &view_rect))
+ if (!get_caret_cursor_area (view, view->cursor_page, view->cursor_offset, &view_rect))
return TRUE;
+ view_rect.x += view->scroll_x;
+ view_rect.y += view->scroll_y;
+
ev_document_model_set_page (view->model, view->cursor_page);
ensure_rectangle_is_visible (view, &view_rect);
gtk_widget_queue_draw (GTK_WIDGET (view));