#include "ev-job-queue.h"
#include "ev-page-cache.h"
#include "ev-pixbuf-cache.h"
+#include "ev-tooltip.h"
#define EV_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EV_TYPE_VIEW, EvViewClass))
#define EV_IS_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EV_TYPE_VIEW))
PROP_PRESENTATION,
PROP_SIZING_MODE,
PROP_ZOOM,
+ PROP_ROTATION,
};
enum {
int pressed_button;
EvViewCursor cursor;
+ GtkWidget *link_tooltip;
+ EvLink *hovered_link;
EvPageCache *page_cache;
EvPixbufCache *pixbuf_cache;
static EvLink* get_link_at_location (EvView *view,
gdouble x,
gdouble y);
-static void go_to_link (EvView *view,
+static char* tip_from_link (EvView *view,
EvLink *link);
-static char* status_message_from_link (EvView *view,
- EvLink *link);
-
+static void handle_link_over_xy (EvView *view,
+ gint x,
+ gint y);
/*** GtkWidget implementation ***/
static void ev_view_size_request_continuous_dual_page (EvView *view,
GtkRequisition *requisition);
GdkEventMotion *event);
static gboolean ev_view_button_release_event (GtkWidget *widget,
GdkEventButton *event);
+static gboolean ev_view_enter_notify_event (GtkWidget *widget,
+ GdkEventCrossing *event);
static gboolean ev_view_leave_notify_event (GtkWidget *widget,
GdkEventCrossing *event);
static void ev_view_style_set (GtkWidget *widget,
doc_rect->y2 = doc_rect->y1 + (double) view_rect->height / view->scale;
}
+static void
+doc_point_to_view_point (EvView *view,
+ int page,
+ EvPoint *doc_point,
+ GdkPoint *view_point)
+{
+ GdkRectangle page_area;
+ GtkBorder border;
+ double x, y;
+ int width, height;
+
+ ev_page_cache_get_size (view->page_cache, page,
+ view->rotation,
+ 1.0,
+ &width, &height);
+
+ if (view->rotation == 0) {
+ x = doc_point->x;
+ y = doc_point->y;
+ } else if (view->rotation == 90) {
+ x = width - doc_point->y;
+ y = doc_point->x;
+ } else if (view->rotation == 180) {
+ x = width - doc_point->x;
+ y = height - doc_point->y;
+ } else if (view->rotation == 270) {
+ x = doc_point->y;
+ y = height - doc_point->x;
+ } else {
+ g_assert_not_reached ();
+ }
+
+ get_page_extents (view, page, &page_area, &border);
+
+ view_point->x = x * view->scale + page_area.x;
+ view_point->y = y * view->scale + page_area.y;
+}
+
static void
doc_rect_to_view_rect (EvView *view,
int page,
return NULL;
}
-/* FIXME: standardize this sometime */
static void
-go_to_link (EvView *view, EvLink *link)
+goto_xyz_link (EvView *view, EvLink *link)
+{
+ GdkPoint view_point;
+ EvPoint doc_point;
+ int height, page;
+ double zoom;
+
+ zoom = ev_link_get_zoom (link);
+ page = ev_link_get_page (link);
+ ev_page_cache_get_size (view->page_cache, page, 0, 1.0, NULL, &height);
+
+ ev_view_set_sizing_mode (view, EV_SIZING_FREE);
+ if (zoom != 0) {
+ ev_view_set_zoom (view, zoom, FALSE);
+ }
+
+ doc_point.x = ev_link_get_left (link);
+ doc_point.y = height - ev_link_get_top (link);
+ doc_point_to_view_point (view, page, &doc_point, &view_point);
+
+ gtk_adjustment_set_value (view->hadjustment, view_point.x);
+ gtk_adjustment_set_value (view->vadjustment, view_point.y);
+}
+
+void
+ev_view_goto_link (EvView *view, EvLink *link)
{
EvLinkType type;
const char *uri;
page = ev_link_get_page (link);
ev_page_cache_set_current_page (view->page_cache, page);
break;
+ case EV_LINK_TYPE_PAGE_XYZ:
+ goto_xyz_link (view, link);
+ break;
case EV_LINK_TYPE_EXTERNAL_URI:
uri = ev_link_get_uri (link);
gnome_vfs_url_show (uri);
}
static char *
-status_message_from_link (EvView *view, EvLink *link)
+tip_from_link (EvView *view, EvLink *link)
{
EvLinkType type;
char *msg = NULL;
msg = g_strdup (ev_link_get_title (link));
break;
case EV_LINK_TYPE_PAGE:
+ case EV_LINK_TYPE_PAGE_XYZ:
page_label = ev_page_cache_get_page_label (view->page_cache, ev_link_get_page (link));
msg = g_strdup_printf (_("Go to page %s"), page_label);
g_free (page_label);
return msg;
}
+static void
+handle_link_over_xy (EvView *view, gint x, gint y)
+{
+ EvLink *link;
+
+ link = get_link_at_location (view, x + view->scroll_x, y + view->scroll_y);
+
+ if (view->link_tooltip == NULL) {
+ view->link_tooltip = ev_tooltip_new (GTK_WIDGET (view));
+ }
+
+ if (view->hovered_link != link) {
+ view->hovered_link = link;
+ ev_tooltip_deactivate (EV_TOOLTIP (view->link_tooltip));
+ }
+
+ if (link) {
+ char *msg = tip_from_link (view, link);
+
+ ev_tooltip_set_position (EV_TOOLTIP (view->link_tooltip), x, y);
+ ev_tooltip_set_text (EV_TOOLTIP (view->link_tooltip), msg);
+ ev_tooltip_activate (EV_TOOLTIP (view->link_tooltip));
+ g_free (msg);
+
+ ev_view_set_cursor (view, EV_VIEW_CURSOR_LINK);
+ } else if (location_in_text (view, x + view->scroll_x, 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 ||
+ view->cursor == EV_VIEW_CURSOR_IBEAM)
+ ev_view_set_cursor (view, EV_VIEW_CURSOR_NORMAL);
+ }
+ return;
+}
/*** GtkWidget implementation ***/
GDK_SCROLL_MASK |
GDK_KEY_PRESS_MASK |
GDK_POINTER_MOTION_MASK |
+ GDK_ENTER_NOTIFY_MASK |
GDK_LEAVE_NOTIFY_MASK;
widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
if (!view->document)
return FALSE;
- if (view->pressed_button == 1) {
+ /* For the Evince 0.4.x release, we limit selection to un-rotated
+ * documents only.
+ */
+ if (view->pressed_button == 1 &&
+ view->rotation == 0) {
view->selection_info.in_selection = TRUE;
view->motion_x = event->x + view->scroll_x;
view->motion_y = event->y + view->scroll_y;
return TRUE;
}
- } else if (view->pressed_button <= 0) {
- EvLink *link;
-
- link = get_link_at_location (view, event->x + view->scroll_x, event->y + view->scroll_y);
- if (link) {
- char *msg;
-
- msg = status_message_from_link (view, link);
- 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 ||
- view->cursor == EV_VIEW_CURSOR_IBEAM)
- ev_view_set_cursor (view, EV_VIEW_CURSOR_NORMAL);
- }
+ /* For the Evince 0.4.x release, we limit links to un-rotated documents
+ * only.
+ */
+ } else if (view->pressed_button <= 0 &&
+ view->rotation == 0) {
+ handle_link_over_xy (view, event->x, event->y);
return TRUE;
}
link = get_link_at_location (view, event->x + view->scroll_x, event->y + view->scroll_y);
if (link) {
- go_to_link (view, link);
+ ev_view_goto_link (view, link);
}
}
view->cursor == EV_VIEW_CURSOR_IBEAM)
ev_view_set_cursor (view, EV_VIEW_CURSOR_NORMAL);
+ if (view->link_tooltip) {
+ view->hovered_link = NULL;
+ ev_tooltip_deactivate (EV_TOOLTIP (view->link_tooltip));
+ }
+
+ return FALSE;
+}
+
+static gboolean
+ev_view_enter_notify_event (GtkWidget *widget, GdkEventCrossing *event)
+{
+ EvView *view = EV_VIEW (widget);
+
+ handle_link_over_xy (view, event->x, event->y);
+
return FALSE;
}
}
}
+static void
+draw_loading_text (EvView *view,
+ GdkRectangle *page_area,
+ GdkRectangle *expose_area)
+{
+ PangoLayout *layout;
+ PangoFontDescription *font_desc;
+ PangoRectangle logical_rect;
+ double real_scale;
+ int target_width;
+
+ const char *loading_text = _("Loading...");
+
+ layout = gtk_widget_create_pango_layout (GTK_WIDGET (view), loading_text);
+
+ font_desc = pango_font_description_new ();
+
+
+ /* We set the font to be 10 points, get the size, and scale appropriately */
+ pango_font_description_set_size (font_desc, 10 * PANGO_SCALE);
+ pango_layout_set_font_description (layout, font_desc);
+ pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
+
+ /* Make sure we fit the middle of the page */
+ target_width = MAX (page_area->width / 2, 1);
+ real_scale = ((double)target_width / (double) logical_rect.width) * (PANGO_SCALE * 10);
+ pango_font_description_set_size (font_desc, (int)real_scale);
+ pango_layout_set_font_description (layout, font_desc);
+ pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
+
+ gtk_paint_layout (GTK_WIDGET (view)->style,
+ GTK_WIDGET (view)->window,
+ GTK_WIDGET_STATE (view),
+ FALSE,
+ page_area,
+ GTK_WIDGET (view),
+ NULL,
+ page_area->x + (target_width/2),
+ page_area->y + (page_area->height - logical_rect.height) / 2,
+ layout);
+
+ pango_font_description_free (font_desc);
+ g_object_unref (layout);
+}
+
static void
draw_one_page (EvView *view,
gint page,
GDK_RGB_DITHER_NORMAL,
0, 0);
g_object_unref (scaled_image);
+ } else {
+ draw_loading_text (view,
+ &real_page_area,
+ expose_area);
}
if (scaled_selection) {
g_object_unref (view->document);
view->document = NULL;
}
+
if (view->pixbuf_cache) {
g_object_unref (view->pixbuf_cache);
view->pixbuf_cache = NULL;
}
+
+ if (view->link_tooltip) {
+ gtk_widget_destroy (view->link_tooltip);
+ }
+
ev_view_set_scroll_adjustments (view, NULL, NULL);
GTK_OBJECT_CLASS (ev_view_parent_class)->destroy (object);
case PROP_ZOOM:
ev_view_set_zoom (view, g_value_get_double (value), FALSE);
break;
+ case PROP_ROTATION:
+ ev_view_set_rotation (view, g_value_get_int (value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
case PROP_ZOOM:
g_value_set_double (value, view->scale);
break;
+ case PROP_ROTATION:
+ g_value_set_int (value, view->rotation);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
widget_class->realize = ev_view_realize;
widget_class->unrealize = ev_view_unrealize;
widget_class->scroll_event = ev_view_scroll_event;
+ widget_class->enter_notify_event = ev_view_enter_notify_event;
widget_class->leave_notify_event = ev_view_leave_notify_event;
widget_class->style_set = ev_view_style_set;
gtk_object_class->destroy = ev_view_destroy;
MAX_SCALE,
1.0,
G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_ROTATION,
+ g_param_spec_double ("rotation",
+ "Rotation",
+ "Rotation",
+ 0,
+ 360,
+ 0,
+ G_PARAM_READWRITE));
binding_set = gtk_binding_set_by_class (class);
view->cursor = EV_VIEW_CURSOR_NORMAL;
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;
}
if (view->page_cache) {
- g_object_unref (view->page_cache);
view->page_cache = NULL;
}
}
ev_pixbuf_cache_clear (view->pixbuf_cache);
gtk_widget_queue_resize (GTK_WIDGET (view));
}
+
+ if (rotation != 0)
+ clear_selection (view);
+
+ g_object_notify (G_OBJECT (view), "rotation");
}
int
{
int n_pages, i;
+ /* Disable selection on rotated pages for the 0.4.0 series */
+ if (view->rotation != 0)
+ return;
+
clear_selection (view);
n_pages = ev_page_cache_get_n_pages (view->page_cache);