+static gboolean
+get_page_extents (EvView *view,
+ gint page,
+ GdkRectangle *page_area,
+ GtkBorder *border)
+{
+ GtkWidget *widget;
+ int width, height;
+
+ widget = GTK_WIDGET (view);
+
+ /* Get the size of the page */
+ ev_page_cache_get_size (view->page_cache, page,
+ view->rotation,
+ view->scale,
+ &width, &height);
+ compute_border (view, width, height, border);
+ page_area->width = width + border->left + border->right;
+ page_area->height = height + border->top + border->bottom;
+
+ if (view->presentation) {
+ page_area->x = (MAX (0, widget->allocation.width - width))/2;
+ page_area->y = (MAX (0, widget->allocation.height - height))/2;
+ } else if (view->continuous) {
+ gint max_width;
+ gint x, y;
+
+ ev_page_cache_get_max_width (view->page_cache, view->rotation,
+ view->scale, &max_width);
+ max_width = max_width + border->left + border->right;
+ /* Get the location of the bounding box */
+ if (view->dual_page) {
+ x = view->spacing + (page % 2) * (max_width + view->spacing);
+ x = x + MAX (0, widget->allocation.width - (max_width * 2 + view->spacing * 3)) / 2;
+ if (page % 2 == 0)
+ x = x + (max_width - width - border->left - border->right);
+ } else {
+ x = view->spacing;
+ x = x + MAX (0, widget->allocation.width - (width + view->spacing * 2)) / 2;
+ }
+
+ get_page_y_offset (view, page, view->scale, &y);
+
+ page_area->x = x;
+ page_area->y = y;
+ } else {
+ gint x, y;
+ if (view->dual_page) {
+ gint width_2, height_2;
+ gint max_width = width;
+ gint max_height = height;
+ GtkBorder overall_border;
+ gint other_page;
+
+ other_page = page ^ 1;
+
+ /* First, we get the bounding box of the two pages */
+ if (other_page < ev_page_cache_get_n_pages (view->page_cache)) {
+ ev_page_cache_get_size (view->page_cache,
+ other_page,
+ view->rotation,
+ view->scale,
+ &width_2, &height_2);
+ if (width_2 > width)
+ max_width = width_2;
+ if (height_2 > height)
+ max_height = height_2;
+ }
+ compute_border (view, max_width, max_height, &overall_border);
+
+ /* Find the offsets */
+ x = view->spacing;
+ y = view->spacing;
+
+ /* Adjust for being the left or right page */
+ if (page % 2 == 0)
+ x = x + max_width - width;
+ else
+ x = x + (max_width + overall_border.left + overall_border.right) + view->spacing;
+
+ y = y + (max_height - height)/2;
+
+ /* Adjust for extra allocation */
+ x = x + MAX (0, widget->allocation.width -
+ ((max_width + overall_border.left + overall_border.right) * 2 + view->spacing * 3))/2;
+ y = y + MAX (0, widget->allocation.height - (height + view->spacing * 2))/2;
+ } else {
+ x = view->spacing;
+ y = view->spacing;
+
+ /* Adjust for extra allocation */
+ x = x + MAX (0, widget->allocation.width - (width + border->left + border->right + view->spacing * 2))/2;
+ y = y + MAX (0, widget->allocation.height - (height + border->top + border->bottom + view->spacing * 2))/2;
+ }
+
+ page_area->x = x;
+ page_area->y = y;
+ }
+
+ return TRUE;
+}
+
+static void
+view_point_to_doc_point (EvView *view,
+ GdkPoint *view_point,
+ GdkRectangle *page_area,
+ double *doc_point_x,
+ double *doc_point_y)
+{
+ *doc_point_x = (double) (view_point->x - page_area->x) / view->scale;
+ *doc_point_y = (double) (view_point->y - page_area->y) / view->scale;
+}
+
+static void
+view_rect_to_doc_rect (EvView *view,
+ GdkRectangle *view_rect,
+ GdkRectangle *page_area,
+ EvRectangle *doc_rect)
+{
+ doc_rect->x1 = (double) (view_rect->x - page_area->x) / view->scale;
+ doc_rect->y1 = (double) (view_rect->y - page_area->y) / view->scale;
+ doc_rect->x2 = doc_rect->x1 + (double) view_rect->width / view->scale;
+ doc_rect->y2 = doc_rect->y1 + (double) view_rect->height / view->scale;
+}
+
+static void
+doc_rect_to_view_rect (EvView *view,
+ int page,
+ EvRectangle *doc_rect,
+ GdkRectangle *view_rect)
+{
+ GdkRectangle page_area;
+ GtkBorder border;
+ double x, y, w, h;
+ int width, height;
+
+ ev_page_cache_get_size (view->page_cache, page,
+ view->rotation,
+ 1.0,
+ &width, &height);
+
+ if (view->rotation == 0) {
+ x = doc_rect->x1;
+ y = doc_rect->y1;
+ w = doc_rect->x2 - doc_rect->x1;
+ h = doc_rect->y2 - doc_rect->y1;
+ } else if (view->rotation == 90) {
+ x = width - doc_rect->y2;
+ y = doc_rect->x1;
+ w = doc_rect->y2 - doc_rect->y1;
+ h = doc_rect->x2 - doc_rect->x1;
+ } else if (view->rotation == 180) {
+ x = width - doc_rect->x2;
+ y = height - doc_rect->y2;
+ w = doc_rect->x2 - doc_rect->x1;
+ h = doc_rect->y2 - doc_rect->y1;
+ } else if (view->rotation == 270) {
+ x = doc_rect->y1;
+ y = height - doc_rect->x2;
+ w = doc_rect->y2 - doc_rect->y1;
+ h = doc_rect->x2 - doc_rect->x1;
+ } else {
+ g_assert_not_reached ();
+ }
+
+ get_page_extents (view, page, &page_area, &border);
+
+ view_rect->x = x * view->scale + page_area.x;
+ view_rect->y = y * view->scale + page_area.y;
+ view_rect->width = w * view->scale;
+ view_rect->height = h * view->scale;
+}
+
+static void
+find_page_at_location (EvView *view,
+ gdouble x,
+ gdouble y,
+ gint *page,
+ gint *x_offset,
+ gint *y_offset)
+{
+ int i;
+
+ if (view->document == NULL)
+ return;
+
+ g_assert (page);
+ g_assert (x_offset);
+ g_assert (y_offset);
+
+ for (i = view->start_page; i <= view->end_page; i++) {
+ GdkRectangle page_area;
+ GtkBorder border;
+
+ if (! get_page_extents (view, i, &page_area, &border))
+ continue;
+
+ if ((x >= page_area.x + border.left) &&
+ (x < page_area.x + page_area.width - border.right) &&
+ (y >= page_area.y + border.top) &&
+ (y < page_area.y + page_area.height - border.bottom)) {
+ *page = i;
+ *x_offset = x - (page_area.x + border.left);
+ *y_offset = y - (page_area.y + border.top);
+ return;
+ }
+ }
+
+ *page = -1;
+}
+
+static gboolean
+location_in_text (EvView *view,
+ gdouble x,
+ gdouble y)
+{
+ GdkRegion *region;
+ gint page = -1;
+ gint x_offset = 0, y_offset = 0;
+
+ find_page_at_location (view, x, y, &page, &x_offset, &y_offset);
+
+ if (page == -1)
+ return FALSE;
+
+ region = ev_pixbuf_cache_get_text_mapping (view->pixbuf_cache, page);
+
+ if (region)
+ return gdk_region_point_in (region, x_offset / view->scale, y_offset / view->scale);
+ else
+ return FALSE;
+}
+
+/*** Hyperref ***/
+static EvLink *
+get_link_at_location (EvView *view,
+ gdouble x,
+ gdouble y)
+{
+ gint page = -1;
+ gint x_offset = 0, y_offset = 0;
+ GList *link_mapping;
+
+ find_page_at_location (view, x, y, &page, &x_offset, &y_offset);
+
+ if (page == -1)
+ return NULL;
+
+ link_mapping = ev_pixbuf_cache_get_link_mapping (view->pixbuf_cache, page);
+
+ if (link_mapping)
+ return ev_link_mapping_find (link_mapping, x_offset / view->scale, y_offset / view->scale);
+ else
+ return NULL;
+}
+
+/* FIXME: standardize this sometime */
+static void
+go_to_link (EvView *view, EvLink *link)
+{
+ EvLinkType type;
+ const char *uri;
+ int page;
+
+ type = ev_link_get_link_type (link);
+
+ switch (type) {
+ case EV_LINK_TYPE_TITLE:
+ break;
+ case EV_LINK_TYPE_PAGE:
+ page = ev_link_get_page (link);
+ ev_page_cache_set_current_page (view->page_cache, page);
+ break;
+ case EV_LINK_TYPE_EXTERNAL_URI:
+ uri = ev_link_get_uri (link);
+ gnome_vfs_url_show (uri);
+ break;
+ }
+}
+
+static char *
+status_message_from_link (EvView *view, EvLink *link)
+{
+ EvLinkType type;
+ char *msg = NULL;
+ char *page_label;
+
+ type = ev_link_get_link_type (link);
+
+ switch (type) {
+ case EV_LINK_TYPE_TITLE:
+ if (ev_link_get_title (link))
+ msg = g_strdup (ev_link_get_title (link));
+ break;
+ case EV_LINK_TYPE_PAGE:
+ 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);
+ break;
+ case EV_LINK_TYPE_EXTERNAL_URI:
+ msg = g_strdup (ev_link_get_uri (link));
+ break;
+ default:
+ break;
+ }
+
+ return msg;
+}
+
+
+/*** GtkWidget implementation ***/
+
+static void
+ev_view_size_request_continuous_dual_page (EvView *view,
+ GtkRequisition *requisition)
+{
+ int max_width;
+ gint n_pages;
+ GtkBorder border;
+
+ ev_page_cache_get_max_width (view->page_cache, view->rotation,
+ view->scale, &max_width);
+ compute_border (view, max_width, max_width, &border);
+
+ n_pages = ev_page_cache_get_n_pages (view->page_cache) + 1;
+
+ requisition->width = (max_width + border.left + border.right) * 2 + (view->spacing * 3);
+ get_page_y_offset (view, n_pages, view->scale, &requisition->height);
+
+ if (view->sizing_mode == EV_SIZING_FIT_WIDTH) {
+ requisition->width = 1;
+ } else if (view->sizing_mode == EV_SIZING_BEST_FIT) {
+ requisition->width = 1;
+ /* FIXME: This could actually be set on one page docs or docs
+ * with a strange aspect ratio. */
+ /* requisition->height = 1;*/
+ }
+}
+
+static void
+ev_view_size_request_continuous (EvView *view,
+ GtkRequisition *requisition)
+{
+ int max_width;
+ int n_pages;
+ GtkBorder border;
+
+
+ ev_page_cache_get_max_width (view->page_cache, view->rotation,
+ view->scale, &max_width);
+ n_pages = ev_page_cache_get_n_pages (view->page_cache);
+ compute_border (view, max_width, max_width, &border);
+
+ requisition->width = max_width + (view->spacing * 2) + border.left + border.right;
+ get_page_y_offset (view, n_pages, view->scale, &requisition->height);
+
+ if (view->sizing_mode == EV_SIZING_FIT_WIDTH) {
+ requisition->width = 1;
+ } else if (view->sizing_mode == EV_SIZING_BEST_FIT) {
+ requisition->width = 1;
+ /* FIXME: This could actually be set on one page docs or docs
+ * with a strange aspect ratio. */
+ /* requisition->height = 1;*/
+ }
+}
+
+static void
+ev_view_size_request_dual_page (EvView *view,
+ GtkRequisition *requisition)
+{
+ GtkBorder border;
+ gint width, height;
+
+ /* Find the largest of the two. */
+ ev_page_cache_get_size (view->page_cache,
+ view->current_page,
+ view->rotation,
+ view->scale,
+ &width, &height);
+ if (view->current_page + 1 < ev_page_cache_get_n_pages (view->page_cache)) {
+ gint width_2, height_2;
+ ev_page_cache_get_size (view->page_cache,
+ view->current_page + 1,
+ view->rotation,
+ view->scale,
+ &width_2, &height_2);
+ if (width_2 > width) {
+ width = width_2;
+ height = height_2;
+ }
+ }
+ compute_border (view, width, height, &border);
+
+ requisition->width = ((width + border.left + border.right) * 2) +
+ (view->spacing * 3);
+ requisition->height = (height + border.top + border.bottom) +
+ (view->spacing * 2);
+
+ if (view->sizing_mode == EV_SIZING_FIT_WIDTH) {
+ requisition->width = 1;
+ } else if (view->sizing_mode == EV_SIZING_BEST_FIT) {
+ requisition->width = 1;
+ requisition->height = 1;
+ }
+}
+
+static void
+ev_view_size_request_single_page (EvView *view,
+ GtkRequisition *requisition)
+{
+ GtkBorder border;
+ gint width, height;
+
+ ev_page_cache_get_size (view->page_cache,
+ view->current_page,
+ view->rotation,
+ view->scale,
+ &width, &height);
+ compute_border (view, width, height, &border);
+
+ requisition->width = width + border.left + border.right + (2 * view->spacing);
+ requisition->height = height + border.top + border.bottom + (2 * view->spacing);
+
+ if (view->sizing_mode == EV_SIZING_FIT_WIDTH) {
+ requisition->width = 1;
+ requisition->height = height + border.top + border.bottom + (2 * view->spacing);
+ } else if (view->sizing_mode == EV_SIZING_BEST_FIT) {
+ requisition->width = 1;
+ requisition->height = 1;
+ }
+}
+
+static void
+ev_view_size_request (GtkWidget *widget,
+ GtkRequisition *requisition)
+{
+ EvView *view = EV_VIEW (widget);
+
+ if (view->document == NULL) {
+ requisition->width = 1;
+ requisition->height = 1;
+ return;
+ }
+
+ if (view->presentation) {
+ requisition->width = 1;
+ requisition->height = 1;
+ return;
+ }
+
+ if (view->continuous && view->dual_page)
+ ev_view_size_request_continuous_dual_page (view, requisition);
+ else if (view->continuous)
+ ev_view_size_request_continuous (view, requisition);
+ else if (view->dual_page)
+ ev_view_size_request_dual_page (view, requisition);
+ else
+ ev_view_size_request_single_page (view, requisition);
+}
+
+static void
+ev_view_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation)
+{
+ EvView *view = EV_VIEW (widget);
+
+ if (view->sizing_mode == EV_SIZING_FIT_WIDTH ||
+ view->sizing_mode == EV_SIZING_BEST_FIT) {
+
+ g_signal_emit (view, signals[SIGNAL_ZOOM_INVALID], 0);
+
+ ev_view_size_request (widget, &widget->requisition);
+ }
+
+ view_set_adjustment_values (view, GTK_ORIENTATION_HORIZONTAL);
+ view_set_adjustment_values (view, GTK_ORIENTATION_VERTICAL);
+
+ view->pending_scroll = SCROLL_TO_KEEP_POSITION;
+ view->pending_resize = FALSE;
+
+ if (view->document)
+ view_update_range_and_current_page (view);
+
+ GTK_WIDGET_CLASS (ev_view_parent_class)->size_allocate (widget, allocation);
+}
+
+static void
+ev_view_realize (GtkWidget *widget)
+{
+ EvView *view = EV_VIEW (widget);
+ GdkWindowAttr attributes;
+
+ GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
+
+
+ attributes.window_type = GDK_WINDOW_CHILD;
+ attributes.wclass = GDK_INPUT_OUTPUT;
+ attributes.visual = gtk_widget_get_visual (widget);
+ attributes.colormap = gtk_widget_get_colormap (widget);
+
+ attributes.x = widget->allocation.x;
+ attributes.y = widget->allocation.y;
+ attributes.width = widget->allocation.width;
+ attributes.height = widget->allocation.height;
+ attributes.event_mask = GDK_EXPOSURE_MASK |
+ GDK_BUTTON_PRESS_MASK |
+ GDK_BUTTON_RELEASE_MASK |
+ GDK_SCROLL_MASK |
+ GDK_KEY_PRESS_MASK |
+ GDK_POINTER_MOTION_MASK |
+ GDK_LEAVE_NOTIFY_MASK;
+
+ widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
+ &attributes,
+ GDK_WA_X | GDK_WA_Y |
+ GDK_WA_COLORMAP |
+ GDK_WA_VISUAL);
+ gdk_window_set_user_data (widget->window, widget);
+ widget->style = gtk_style_attach (widget->style, widget->window);
+
+ if (view->presentation)
+ gdk_window_set_background (widget->window, &widget->style->black);
+ else
+ gdk_window_set_background (widget->window, &widget->style->mid [GTK_STATE_NORMAL]);
+}
+
+static void
+ev_view_unrealize (GtkWidget *widget)
+{
+ GTK_WIDGET_CLASS (ev_view_parent_class)->unrealize (widget);
+}
+
+static gboolean
+ev_view_scroll_event (GtkWidget *widget, GdkEventScroll *event)
+{
+ EvView *view = EV_VIEW (widget);
+
+ if ((event->state & GDK_CONTROL_MASK) != 0) {
+
+ ev_view_set_sizing_mode (view, EV_SIZING_FREE);
+
+ if (event->direction == GDK_SCROLL_UP ||
+ event->direction == GDK_SCROLL_LEFT) {
+ if (ev_view_can_zoom_in (view)) {
+ ev_view_zoom_in (view);
+ }
+ } else {
+ if (ev_view_can_zoom_out (view)) {
+ ev_view_zoom_out (view);
+ }
+ }
+ return TRUE;
+ }
+
+ if ((event->state & GDK_SHIFT_MASK) != 0) {
+ if (event->direction == GDK_SCROLL_UP)
+ event->direction = GDK_SCROLL_LEFT;
+ if (event->direction == GDK_SCROLL_DOWN)
+ event->direction = GDK_SCROLL_RIGHT;
+ }
+
+ return FALSE;
+}
+
+static EvViewSelection *
+find_selection_for_page (EvView *view,
+ gint page)
+{
+ GList *list;
+
+ for (list = view->selection_info.selections; list != NULL; list = list->next) {
+ EvViewSelection *selection;
+
+ selection = (EvViewSelection *) list->data;
+
+ if (selection->page == page)
+ return selection;
+ }
+
+ return NULL;
+}
+
+static gboolean
+ev_view_expose_event (GtkWidget *widget,
+ GdkEventExpose *event)
+{
+ EvView *view = EV_VIEW (widget);
+ int i;
+
+ if (view->document == NULL)
+ return FALSE;
+
+ for (i = view->start_page; i <= view->end_page; i++) {
+ GdkRectangle page_area;
+ GtkBorder border;
+
+ if (!get_page_extents (view, i, &page_area, &border))
+ continue;
+
+ page_area.x -= view->scroll_x;
+ page_area.y -= view->scroll_y;
+
+ draw_one_page (view, i, &page_area, &border, &(event->area));
+
+ if (EV_IS_DOCUMENT_FIND (view->document))
+ highlight_find_results (view, i);
+ }
+
+ return FALSE;
+}
+
+static gboolean
+ev_view_button_press_event (GtkWidget *widget,
+ GdkEventButton *event)
+{
+ EvView *view = EV_VIEW (widget);
+
+ if (!GTK_WIDGET_HAS_FOCUS (widget)) {
+ gtk_widget_grab_focus (widget);
+ }
+
+ view->pressed_button = event->button;
+
+ switch (event->button) {
+ case 1:
+ if (view->selection_info.selections) {
+ clear_selection (view);
+ gtk_widget_queue_draw (widget);
+ }
+
+ view->selection_info.start.x = event->x + view->scroll_x;
+ view->selection_info.start.y = event->y + view->scroll_y;
+ return TRUE;
+ case 2:
+ /* use root coordinates as reference point because
+ * scrolling changes window relative coordinates */
+ view->drag_info.start.x = event->x_root;
+ view->drag_info.start.y = event->y_root;
+ view->drag_info.hadj = gtk_adjustment_get_value (view->hadjustment);
+ view->drag_info.vadj = gtk_adjustment_get_value (view->vadjustment);
+
+ ev_view_set_cursor (view, EV_VIEW_CURSOR_DRAG);
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+
+static gboolean
+selection_update_idle_cb (EvView *view)
+{
+ GdkPoint point;
+ point.x = view->motion_x;
+ point.y = view->motion_y;
+ compute_selections (view, &view->selection_info.start, &point);
+
+ view->selection_update_id = 0;
+ return FALSE;
+}
+
+static gboolean
+ev_view_motion_notify_event (GtkWidget *widget,
+ GdkEventMotion *event)
+{
+ EvView *view = EV_VIEW (widget);
+
+ if (!view->document)
+ return FALSE;
+
+ /* 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;
+
+ /* Queue an idle to handle the motion. We do this because
+ * handling any selection events in the motion could be slower
+ * than new motion events reach us. We always put it in the
+ * idle to make sure we catch up and don't visibly lag the
+ * mouse. */
+ if (! view->selection_update_id)
+ view->selection_update_id = g_idle_add ((GSourceFunc)selection_update_idle_cb, view);
+
+ return TRUE;
+ } else if (view->pressed_button == 2) {
+ if (!view->drag_info.in_drag) {
+ gboolean start;
+
+ start = gtk_drag_check_threshold (widget,
+ view->drag_info.start.x,
+ view->drag_info.start.y,
+ event->x_root,
+ event->y_root);
+ view->drag_info.in_drag = start;
+ }
+
+ if (view->drag_info.in_drag) {
+ int dx, dy;
+ gdouble dhadj_value, dvadj_value;
+
+ dx = event->x_root - view->drag_info.start.x;
+ dy = event->y_root - view->drag_info.start.y;
+
+ dhadj_value = view->hadjustment->page_size *
+ (gdouble)dx / widget->allocation.width;
+ dvadj_value = view->vadjustment->page_size *
+ (gdouble)dy / widget->allocation.height;
+
+ /* clamp scrolling to visible area */
+ gtk_adjustment_set_value (view->hadjustment,
+ MIN(view->drag_info.hadj - dhadj_value,
+ view->hadjustment->upper -
+ view->hadjustment->page_size));
+ gtk_adjustment_set_value (view->vadjustment,
+ MIN(view->drag_info.vadj - dvadj_value,
+ view->vadjustment->upper -
+ view->vadjustment->page_size));
+
+ return TRUE;
+ }
+ /* For the Evince 0.4.x release, we limit links to un-rotated documents
+ * only.
+ */
+ } else if (view->pressed_button <= 0 &&
+ view->rotation == 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);
+ }
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static gboolean
+ev_view_button_release_event (GtkWidget *widget,
+ GdkEventButton *event)
+{
+ EvView *view = EV_VIEW (widget);
+
+ if (view->pressed_button == 2) {
+ ev_view_set_cursor (view, EV_VIEW_CURSOR_NORMAL);
+ }
+
+ view->pressed_button = -1;
+ view->drag_info.in_drag = FALSE;
+
+ if (view->selection_info.selections) {
+ ev_view_update_primary_selection (view);
+ } else if (view->document) {
+ EvLink *link;
+
+ link = get_link_at_location (view, event->x + view->scroll_x, event->y + view->scroll_y);
+ if (link) {
+ go_to_link (view, link);
+ }
+ }
+
+ return FALSE;
+}
+
+static gint
+ev_view_focus_in (GtkWidget *widget,
+ GdkEventFocus *event)
+{
+ if (EV_VIEW (widget)->pixbuf_cache)
+ ev_pixbuf_cache_style_changed (EV_VIEW (widget)->pixbuf_cache);
+ gtk_widget_queue_draw (widget);
+
+ return FALSE;
+}
+
+static gint
+ev_view_focus_out (GtkWidget *widget,
+ GdkEventFocus *event)
+{
+ if (EV_VIEW (widget)->pixbuf_cache)
+ ev_pixbuf_cache_style_changed (EV_VIEW (widget)->pixbuf_cache);
+ gtk_widget_queue_draw (widget);
+
+ return FALSE;
+}
+
+static gboolean
+ev_view_leave_notify_event (GtkWidget *widget, GdkEventCrossing *event)
+{
+ EvView *view = EV_VIEW (widget);
+
+ 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 FALSE;
+}
+
+static void
+ev_view_style_set (GtkWidget *widget,
+ GtkStyle *old_style)
+{
+ if (EV_VIEW (widget)->pixbuf_cache)
+ ev_pixbuf_cache_style_changed (EV_VIEW (widget)->pixbuf_cache);
+
+ GTK_WIDGET_CLASS (ev_view_parent_class)->style_set (widget, old_style);
+}
+
+
+/*** Drawing ***/
+
+static guint32
+ev_gdk_color_to_rgb (const GdkColor *color)
+{
+ guint32 result;
+ result = (0xff0000 | (color->red & 0xff00));
+ result <<= 8;
+ result |= ((color->green & 0xff00) | (color->blue >> 8));
+ return result;
+}
+
+static void