[evince/wip/highlight: 134/145] view: preparing for interactive annotations



commit 6249c5bb0aaa818177b0f272c79e36d836a272aa
Author: Giselle Machado <gisellemnr src gnome org>
Date:   Fri Jul 25 23:35:37 2014 +0200

    view: preparing for interactive annotations
    
    Added a struct to the view that holds start and
    end points of annotations in order to support
    'click and drag' annotations. Changed the creation
    point from button_release to button_press.

 libview/ev-view-private.h |   17 ++++++++++-
 libview/ev-view.c         |   69 ++++++++++++++++++++++++++-------------------
 2 files changed, 55 insertions(+), 31 deletions(-)
---
diff --git a/libview/ev-view-private.h b/libview/ev-view-private.h
index 087f3ef..d9a062b 100644
--- a/libview/ev-view-private.h
+++ b/libview/ev-view-private.h
@@ -113,6 +113,20 @@ typedef struct _EvHeightToPageCache {
        gdouble *dual_height_to_page;
 } EvHeightToPageCache;
 
+/* Information for handling annotations */
+typedef enum {
+       MODE_NORMAL,
+       MODE_ADD,
+       MODE_DRAW
+} AnnotationModeType;
+
+typedef struct {
+       GdkPoint           start;
+       GdkPoint           stop;
+       AnnotationModeType mode;
+       EvAnnotationType   type;
+} ActiveAnnotInfo;
+
 struct _EvView {
        GtkContainer layout;
 
@@ -207,8 +221,7 @@ struct _EvView {
        /* Annotations */
        GList             *window_children;
        EvViewWindowChild *window_child_focus;
-       gboolean           adding_annot;
-       EvAnnotationType   adding_annot_type;
+       ActiveAnnotInfo    annot_info;
 
        /* Focus */
        EvMapping *focused_element;
diff --git a/libview/ev-view.c b/libview/ev-view.c
index 6b6ed52..e703656 100644
--- a/libview/ev-view.c
+++ b/libview/ev-view.c
@@ -2082,7 +2082,7 @@ ev_view_handle_cursor_over_xy (EvView *view, gint x, gint y)
        if (view->cursor == EV_VIEW_CURSOR_HIDDEN)
                return;
 
-       if (view->adding_annot) {
+       if (view->annot_info.mode != MODE_NORMAL) {
                if (view->cursor != EV_VIEW_CURSOR_ADD)
                        ev_view_set_cursor (view, EV_VIEW_CURSOR_ADD);
                return;
@@ -3188,12 +3188,11 @@ ev_view_handle_annotation (EvView       *view,
 
 static void
 ev_view_create_annotation (EvView          *view,
-                          EvAnnotationType annot_type,
-                          gint             x,
-                          gint             y)
+                          EvAnnotationType annot_type)
 {
        EvAnnotation   *annot;
-       GdkPoint        point;
+       EvPoint         begin;
+       EvPoint         end;
        GdkRectangle    page_area;
        GtkBorder       border;
        EvRectangle     doc_rect, popup_rect;
@@ -3202,20 +3201,25 @@ ev_view_create_annotation (EvView          *view,
        GdkRectangle    view_rect;
        cairo_region_t *region;
 
-       point.x = x;
-       point.y = y;
+       g_assert (view->annot_info.mode == MODE_ADD);
+
        ev_view_get_page_extents (view, view->current_page, &page_area, &border);
-       _ev_view_transform_view_point_to_doc_point (view, &point, &page_area, &border,
-                                                   &doc_rect.x1, &doc_rect.y1);
-       doc_rect.x2 = doc_rect.x1 + 24;
-       doc_rect.y2 = doc_rect.y1 + 24;
+       _ev_view_transform_view_point_to_doc_point (view, &view->annot_info.start, &page_area, &border,
+                                                   &begin.x, &begin.y);
+       _ev_view_transform_view_point_to_doc_point (view, &view->annot_info.stop, &page_area, &border,
+                                                   &end.x, &end.y);
 
        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_TEXT: {
+               doc_rect.x1 = begin.x;
+               doc_rect.y1 = begin.y;
+               doc_rect.x2 = doc_rect.x1 + 24;
+               doc_rect.y2 = doc_rect.y1 + 24;
+               annot = ev_annotation_text_new (page);
+               break;
+       }
        case EV_ANNOTATION_TYPE_ATTACHMENT:
                /* TODO */
                g_object_unref (page);
@@ -3289,11 +3293,11 @@ ev_view_begin_add_annotation (EvView          *view,
        if (annot_type == EV_ANNOTATION_TYPE_UNKNOWN)
                return;
 
-       if (view->adding_annot)
+       if (view->annot_info.mode == MODE_ADD)
                return;
 
-       view->adding_annot = TRUE;
-       view->adding_annot_type = annot_type;
+       view->annot_info.mode = MODE_ADD;
+       view->annot_info.type = annot_type;
        ev_view_set_cursor (view, EV_VIEW_CURSOR_ADD);
 }
 
@@ -3302,10 +3306,10 @@ ev_view_cancel_add_annotation (EvView *view)
 {
        gint x, y;
 
-       if (!view->adding_annot)
+       if (view->annot_info.mode == MODE_NORMAL)
                return;
 
-       view->adding_annot = FALSE;
+       view->annot_info.mode = MODE_NORMAL;
        ev_document_misc_get_pointer_position (GTK_WIDGET (view), &x, &y);
        ev_view_handle_cursor_over_xy (view, x, y);
 }
@@ -4821,9 +4825,6 @@ ev_view_button_press_event (GtkWidget      *widget,
        view->pressed_button = event->button;
        view->selection_info.in_drag = FALSE;
 
-       if (view->adding_annot)
-               return FALSE;
-
        if (view->scroll_info.autoscrolling)
                return TRUE;
 
@@ -4874,6 +4875,20 @@ ev_view_button_press_event (GtkWidget      *widget,
 
                                view->image_dnd_info.start.x = event->x + view->scroll_x;
                                view->image_dnd_info.start.y = event->y + view->scroll_y;
+                       } else if (view->annot_info.mode == MODE_ADD) {
+                               switch (view->annot_info.type) {
+                                       case EV_ANNOTATION_TYPE_TEXT:
+                                       case EV_ANNOTATION_TYPE_ATTACHMENT: {
+                                               view->annot_info.start.x = event->x + view->scroll_x;
+                                               view->annot_info.start.y = event->y + view->scroll_y;
+                                               view->annot_info.stop = view->annot_info.start;
+                                               ev_view_create_annotation (view, view->annot_info.type);
+                                               view->annot_info.mode = MODE_NORMAL;
+                                               break;
+                                       }
+                                       default:
+                                               g_assert_not_reached ();
+                               }
                        } else {
                                ev_view_remove_all (view);
                                _ev_view_set_focused_element (view, NULL, -1);
@@ -5312,16 +5327,11 @@ ev_view_button_release_event (GtkWidget      *widget,
 
        view->drag_info.in_drag = FALSE;
 
-       if (view->adding_annot && view->pressed_button == 1) {
-               view->adding_annot = FALSE;
+       if (view->annot_info.mode == MODE_DRAW && view->pressed_button == 1) {
+               view->annot_info.mode = MODE_NORMAL;
                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;
        }
 
@@ -7264,6 +7274,7 @@ ev_view_init (EvView *view)
        view->allow_links_change_zoom = TRUE;
        view->zoom_center_x = -1;
        view->zoom_center_y = -1;
+       view->annot_info.mode = MODE_NORMAL;
 
        g_signal_connect (view, "notify::scale-factor",
                          G_CALLBACK (on_notify_scale_factor), NULL);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]