]> www.fi.muni.cz Git - evince.git/commitdiff
[libview] Add ev_view_focus_annotation() to focus the given annotation
authorCarlos Garcia Campos <carlosgc@gnome.org>
Mon, 12 Jul 2010 17:06:21 +0000 (19:06 +0200)
committerCarlos Garcia Campos <carlosgc@gnome.org>
Mon, 12 Jul 2010 17:12:02 +0000 (19:12 +0200)
libview/ev-view-private.h
libview/ev-view.c
libview/ev-view.h

index 79e6cdb769d325c6eb1a5ffca4faeb42460768a4..06309082f476fe87a76fd9f226db5246f5f2afb8 100644 (file)
@@ -184,6 +184,7 @@ struct _EvView {
        /* Annotations */
        GList             *window_children;
        EvViewWindowChild *window_child_focus;
+       EvMapping         *focus_annotation;
 
        /* Synctex */
        EvMapping *synctex_result;
index 1d6377f7f9feb2b8940aa299150f67321b56f37d..61e4c0c6441cc76e87fb282bcaa74c9304b076ac 100644 (file)
@@ -178,6 +178,9 @@ static void       highlight_find_results                     (EvView
                                                              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,
@@ -2746,6 +2749,30 @@ ev_view_handle_annotation (EvView       *view,
        }
 }
 
+void
+ev_view_focus_annotation (EvView    *view,
+                         EvMapping *annot_mapping)
+{
+       GdkRectangle  view_rect;
+       EvAnnotation *annot;
+
+       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;
+
+       ev_document_model_set_page (view->model, annot->page->index);
+
+       doc_rect_to_view_rect (view, annot->page->index,
+                              &annot_mapping->area, &view_rect);
+       ensure_rectangle_is_visible (view, &view_rect);
+       gtk_widget_queue_draw (GTK_WIDGET (view));
+}
+
 static gboolean
 ev_view_synctex_backward_search (EvView *view,
                                 gdouble x,
@@ -3175,6 +3202,8 @@ ev_view_expose_event (GtkWidget      *widget,
                        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);
        }
@@ -3411,6 +3440,9 @@ ev_view_button_press_event (GtkWidget      *widget,
                                        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);
                        }
@@ -4052,6 +4084,29 @@ highlight_forward_search_results (EvView *view, int page)
        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 (annot->page->index != 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)
 {
index d4ee577e7fc5b307b6dedb4bbf8930517cf3ace5..712d5546c339e65307f8aa4d3d528f4d5baf2a1b 100644 (file)
@@ -104,6 +104,9 @@ gboolean       ev_view_get_page_extents   (EvView       *view,
                                            GdkRectangle *page_area,
                                            GtkBorder    *border);
 
+void           ev_view_focus_annotation   (EvView       *view,
+                                          EvMapping    *annot_mapping);
+
 G_END_DECLS
 
 #endif /* __EV_VIEW_H__ */