X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;ds=sidebyside;f=shell%2Fev-view.c;h=4fda98c155989e76c65369fa5d000bbcd973e5fc;hb=8370e4fa6c0a90a4d10294e3a74ed87d90b8db94;hp=c8b17834adc2689d4ea89284d78e948e84b5ba66;hpb=784128af02ea485639dd23220b1a3f5670c30fdd;p=evince.git diff --git a/shell/ev-view.c b/shell/ev-view.c index c8b17834..4fda98c1 100644 --- a/shell/ev-view.c +++ b/shell/ev-view.c @@ -42,7 +42,9 @@ #include "ev-job-queue.h" #include "ev-page-cache.h" #include "ev-pixbuf-cache.h" +#if !GTK_CHECK_VERSION (2, 11, 7) #include "ev-tooltip.h" +#endif #include "ev-application.h" #define EV_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EV_TYPE_VIEW, EvViewClass)) @@ -217,6 +219,7 @@ static void highlight_find_results (EvView int page); static void draw_one_page (EvView *view, gint page, + cairo_t *cr, GdkRectangle *page_area, GtkBorder *border, GdkRectangle *expose_area, @@ -1454,8 +1457,10 @@ tip_from_link (EvView *view, EvLink *link) case EV_LINK_ACTION_TYPE_GOTO_DEST: page_label = ev_view_page_label_from_dest (view, ev_link_action_get_dest (action)); - msg = g_strdup_printf (_("Go to page %s"), page_label); - g_free (page_label); + if (page_label) { + msg = g_strdup_printf (_("Go to page %s"), page_label); + g_free (page_label); + } break; case EV_LINK_ACTION_TYPE_GOTO_REMOTE: if (title) { @@ -1465,7 +1470,6 @@ tip_from_link (EvView *view, EvLink *link) msg = g_strdup_printf (_("Go to file “%s”"), ev_link_action_get_filename (action)); } - break; case EV_LINK_ACTION_TYPE_EXTERNAL_URI: msg = g_strdup (ev_link_action_get_uri (action)); @@ -1496,7 +1500,8 @@ ev_view_handle_cursor_over_xy (EvView *view, gint x, gint y) return; link = ev_view_get_link_at_location (view, x, y); - + +#if !GTK_CHECK_VERSION (2, 11, 7) if (view->link_tooltip == NULL) { view->link_tooltip = ev_tooltip_new (GTK_WIDGET (view)); } @@ -1505,8 +1510,12 @@ ev_view_handle_cursor_over_xy (EvView *view, gint x, gint y) view->hovered_link = link; ev_tooltip_deactivate (EV_TOOLTIP (view->link_tooltip)); } +#endif if (link) { +#if GTK_CHECK_VERSION (2, 11, 7) + g_object_set (view, "has-tooltip", TRUE, NULL); +#else char *msg = tip_from_link (view, link); if (msg && g_utf8_validate (msg, -1, NULL)) { @@ -1517,7 +1526,7 @@ ev_view_handle_cursor_over_xy (EvView *view, gint x, gint y) ev_tooltip_activate (tooltip); } g_free (msg); - +#endif ev_view_set_cursor (view, EV_VIEW_CURSOR_LINK); } else if ((field = ev_view_get_form_field_at_location (view, x, y))) { if (field->is_read_only) { @@ -2434,8 +2443,9 @@ static gboolean ev_view_expose_event (GtkWidget *widget, GdkEventExpose *event) { - EvView *view = EV_VIEW (widget); - int i; + EvView *view = EV_VIEW (widget); + cairo_t *cr; + gint i; if (view->presentation) { switch (view->presentation_state) { @@ -2469,6 +2479,8 @@ ev_view_expose_event (GtkWidget *widget, if (view->document == NULL) return FALSE; + cr = gdk_cairo_create (view->layout.bin_window); + for (i = view->start_page; i <= view->end_page; i++) { GdkRectangle page_area; GtkBorder border; @@ -2480,12 +2492,14 @@ ev_view_expose_event (GtkWidget *widget, page_area.x -= view->scroll_x; page_area.y -= view->scroll_y; - draw_one_page (view, i, &page_area, &border, &(event->area), &page_ready); + draw_one_page (view, i, cr, &page_area, &border, &(event->area), &page_ready); if (page_ready && EV_IS_DOCUMENT_FIND (view->document)) highlight_find_results (view, i); } + cairo_destroy (cr); + if (GTK_WIDGET_CLASS (ev_view_parent_class)->expose_event) (* GTK_WIDGET_CLASS (ev_view_parent_class)->expose_event) (widget, event); @@ -2526,6 +2540,60 @@ ev_view_popup_menu (GtkWidget *widget) return ev_view_do_popup_menu (EV_VIEW (widget), x, y); } +#if GTK_CHECK_VERSION (2, 11, 7) +static void +get_link_area (EvView *view, + gint x, + gint y, + EvLink *link, + GdkRectangle *area) +{ + EvRectangle ev_rect; + GList *link_mapping; + gint page; + gint x_offset = 0, y_offset = 0; + + x += view->scroll_x; + y += view->scroll_y; + + find_page_at_location (view, x, y, &page, &x_offset, &y_offset); + + link_mapping = ev_pixbuf_cache_get_link_mapping (view->pixbuf_cache, page); + ev_link_mapping_get_area (link_mapping, link, &ev_rect); + + doc_rect_to_view_rect (view, page, &ev_rect, area); + area->y -= view->scroll_y ; +} + +static gboolean +ev_view_query_tooltip (GtkWidget *widget, + gint x, + gint y, + gboolean keyboard_tip, + GtkTooltip *tooltip) +{ + EvView *view = EV_VIEW (widget); + EvLink *link; + gchar *text; + + link = ev_view_get_link_at_location (view, x, y); + if (!link) + return FALSE; + + text = tip_from_link (view, link); + if (text && g_utf8_validate (text, -1, NULL)) { + GdkRectangle link_area; + + 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; +} +#endif /* GTK_CHECK_VERSION (2, 11, 7) */ + static gboolean ev_view_button_press_event (GtkWidget *widget, GdkEventButton *event) @@ -3259,11 +3327,13 @@ ev_view_leave_notify_event (GtkWidget *widget, GdkEventCrossing *event) view->cursor == EV_VIEW_CURSOR_IBEAM) ev_view_set_cursor (view, EV_VIEW_CURSOR_NORMAL); +#if !GTK_CHECK_VERSION (2, 11, 7) if (view->link_tooltip) { view->hovered_link = NULL; ev_tooltip_deactivate (EV_TOOLTIP (view->link_tooltip)); } - +#endif + return FALSE; } @@ -3435,6 +3505,7 @@ draw_loading_text (EvView *view, static void draw_one_page (EvView *view, gint page, + cairo_t *cr, GdkRectangle *page_area, GtkBorder *border, GdkRectangle *expose_area, @@ -3473,7 +3544,6 @@ draw_one_page (EvView *view, cairo_surface_t *page_surface = NULL; gint selection_width, selection_height; cairo_surface_t *selection_surface = NULL; - cairo_t *cr = NULL; page_surface = ev_pixbuf_cache_get_surface (view->pixbuf_cache, page); @@ -3491,16 +3561,10 @@ draw_one_page (EvView *view, view->scale, &width, &height); - cr = gdk_cairo_create (view->layout.bin_window); - - cairo_save (cr); - page_width = cairo_image_surface_get_width (page_surface); page_height = cairo_image_surface_get_height (page_surface); - - cairo_rectangle (cr, overlap.x, overlap.y, overlap.width, overlap.height); - cairo_clip (cr); - + + cairo_save (cr); cairo_translate (cr, overlap.x, overlap.y); if (width != page_width || height != page_height) { @@ -3514,10 +3578,8 @@ draw_one_page (EvView *view, cairo_surface_set_device_offset (page_surface, overlap.x - real_page_area.x, overlap.y - real_page_area.y); - cairo_set_source_surface (cr, page_surface, 0, 0); cairo_paint (cr); - cairo_restore (cr); /* Get the selection pixbuf iff we have something to draw */ @@ -3531,16 +3593,13 @@ draw_one_page (EvView *view, } if (!selection_surface) { - cairo_destroy (cr); return; } selection_width = cairo_image_surface_get_width (selection_surface); selection_height = cairo_image_surface_get_height (selection_surface); - cairo_rectangle (cr, overlap.x, overlap.y, overlap.width, overlap.height); - cairo_clip (cr); - + cairo_save (cr); cairo_translate (cr, overlap.x, overlap.y); if (width != selection_width || height != selection_height) { @@ -3554,10 +3613,9 @@ draw_one_page (EvView *view, 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_destroy (cr); + cairo_restore (cr); } } @@ -3594,11 +3652,12 @@ ev_view_destroy (GtkObject *object) view->pixbuf_cache = NULL; } +#if !GTK_CHECK_VERSION (2, 11, 7) if (view->link_tooltip) { gtk_widget_destroy (view->link_tooltip); view->link_tooltip = NULL; } - +#endif if (view->goto_window) { gtk_widget_destroy (view->goto_window); view->goto_window = NULL; @@ -3767,6 +3826,9 @@ ev_view_class_init (EvViewClass *class) widget_class->drag_motion = ev_view_drag_motion; widget_class->drag_data_received = ev_view_drag_data_received; widget_class->popup_menu = ev_view_popup_menu; +#if GTK_CHECK_VERSION (2, 11, 7) + widget_class->query_tooltip = ev_view_query_tooltip; +#endif gtk_object_class->destroy = ev_view_destroy; @@ -4351,10 +4413,19 @@ ev_view_presentation_transition_start (EvView *view) duration = ev_document_transition_get_page_duration (EV_DOCUMENT_TRANSITION (view->document), view->current_page); - if (duration > 0) - view->trans_timeout_id = g_timeout_add (duration * 1000, - (GSourceFunc) transition_next_page, - view); + if (duration > 0) { +#if GLIB_CHECK_VERSION (2, 13, 0) + view->trans_timeout_id = + g_timeout_add_seconds (duration, + (GSourceFunc) transition_next_page, + view); +#else + view->trans_timeout_id = + g_timeout_add (duration * 1000, + (GSourceFunc) transition_next_page, + view); +#endif + } } void