+ 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;
+
+ if (view->pressed_button == 1) {
+ 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 is probably going
+ * to be slower than new motion events reach us. This means that */
+
+ 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;
+ }
+ } 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);
+ }
+ 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
+draw_rubberband (GtkWidget *widget, GdkWindow *window,
+ const GdkRectangle *rect, guchar alpha)
+{
+ GdkGC *gc;
+ GdkPixbuf *pixbuf;
+ GdkColor *fill_color_gdk;
+ guint fill_color;
+
+ fill_color_gdk = gdk_color_copy (>K_WIDGET (widget)->style->base[GTK_STATE_SELECTED]);
+ fill_color = ev_gdk_color_to_rgb (fill_color_gdk) << 8 | alpha;
+
+ pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8,
+ rect->width, rect->height);
+ gdk_pixbuf_fill (pixbuf, fill_color);
+
+ gdk_draw_pixbuf (window, NULL, pixbuf,
+ 0, 0,
+ rect->x - EV_VIEW (widget)->scroll_x, rect->y - EV_VIEW (widget)->scroll_y,
+ rect->width, rect->height,
+ GDK_RGB_DITHER_NONE,
+ 0, 0);
+
+ g_object_unref (pixbuf);
+
+ gc = gdk_gc_new (window);
+ gdk_gc_set_rgb_fg_color (gc, fill_color_gdk);
+ gdk_draw_rectangle (window, gc, FALSE,
+ rect->x - EV_VIEW (widget)->scroll_x, rect->y - EV_VIEW (widget)->scroll_y,
+ rect->width - 1,
+ rect->height - 1);