X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=shell%2Fev-view.c;h=f0a371cd605c027d32a0aa376c08881c2d776bca;hb=0badb78f245130a87888ccbfa624c251707ddf27;hp=15bd41244edcf10215eae5d720374955b0372632;hpb=85c366bda9f25b1249ba8333604eb3e757bc6edf;p=evince.git diff --git a/shell/ev-view.c b/shell/ev-view.c index 15bd4124..f0a371cd 100644 --- a/shell/ev-view.c +++ b/shell/ev-view.c @@ -19,6 +19,7 @@ */ #include +#include #include #include #include @@ -29,6 +30,7 @@ #include "ev-marshal.h" #include "ev-view.h" +#include "ev-view-private.h" #include "ev-utils.h" #include "ev-selection.h" #include "ev-document-find.h" @@ -55,12 +57,14 @@ enum { PROP_SIZING_MODE, PROP_ZOOM, PROP_ROTATION, + PROP_HAS_SELECTION, }; enum { SIGNAL_BINDING_ACTIVATED, SIGNAL_ZOOM_INVALID, SIGNAL_EXTERNAL_LINK, + SIGNAL_POPUP_MENU, N_SIGNALS, }; @@ -81,15 +85,6 @@ static const GtkTargetEntry targets[] = { static guint signals[N_SIGNALS]; -typedef enum { - EV_VIEW_CURSOR_NORMAL, - EV_VIEW_CURSOR_IBEAM, - EV_VIEW_CURSOR_LINK, - EV_VIEW_CURSOR_WAIT, - EV_VIEW_CURSOR_HIDDEN, - EV_VIEW_CURSOR_DRAG -} EvViewCursor; - typedef enum { EV_VIEW_FIND_NEXT, EV_VIEW_FIND_PREV @@ -101,97 +96,7 @@ typedef enum { #define MIN_SCALE 0.05409 #define MAX_SCALE 4.0 -/* Information for middle clicking and moving around the doc */ -typedef struct { - gboolean in_drag; - GdkPoint start; - gdouble hadj; - gdouble vadj; -} DragInfo; - -/* Information for handling selection */ -typedef struct { - gboolean in_selection; - GdkPoint start; - GList *selections; -} SelectionInfo; - -typedef enum { - SCROLL_TO_KEEP_POSITION, - SCROLL_TO_CURRENT_PAGE, - SCROLL_TO_CENTER -} PendingScroll; - -struct _EvView { - GtkWidget parent_instance; - - EvDocument *document; - - char *status; - char *find_status; - - /* Scrolling */ - GtkAdjustment *hadjustment; - GtkAdjustment *vadjustment; - - gint scroll_x; - gint scroll_y; - - /* Information for middle clicking and dragging around. */ - DragInfo drag_info; - - /* Selection */ - gint motion_x; - gint motion_y; - guint selection_update_id; - - EvViewSelectionMode selection_mode; - SelectionInfo selection_info; - - int pressed_button; - EvViewCursor cursor; - GtkWidget *link_tooltip; - EvLink *hovered_link; - - EvPageCache *page_cache; - EvPixbufCache *pixbuf_cache; - - gint start_page; - gint end_page; - gint current_page; - - EvJobRender *current_job; - - int find_page; - int find_result; - int spacing; - - int rotation; - double scale; - - gboolean continuous; - gboolean dual_page; - gboolean fullscreen; - gboolean presentation; - EvSizingMode sizing_mode; - - PendingScroll pending_scroll; - gboolean pending_resize; -}; - -struct _EvViewClass { - GtkWidgetClass parent_class; - - void (*set_scroll_adjustments) (EvView *view, - GtkAdjustment *hadjustment, - GtkAdjustment *vadjustment); - void (*binding_activated) (EvView *view, - GtkScrollType scroll, - gboolean horizontal); - void (*zoom_invalid) (EvView *view); - void (*external_link) (EvView *view, - EvLink *link); -}; +#define SCROLL_TIME 150 /*** Scrolling ***/ static void scroll_to_current_page (EvView *view, @@ -243,11 +148,14 @@ static void find_page_at_location (EvView gint *page, gint *x_offset, gint *y_offset); - +static gboolean doc_point_to_view_point (EvView *view, + int page, + EvPoint *doc_point, + GdkPoint *view_point); /*** Hyperrefs ***/ -static EvLink* get_link_at_location (EvView *view, - gdouble x, - gdouble y); +static EvLink * ev_view_get_link_at_location (EvView *view, + gdouble x, + gdouble y); static char* tip_from_link (EvView *view, EvLink *link); static void handle_link_over_xy (EvView *view, @@ -271,6 +179,7 @@ static gboolean ev_view_scroll_event (GtkWidget GdkEventScroll *event); static gboolean ev_view_expose_event (GtkWidget *widget, GdkEventExpose *event); +static gboolean ev_view_popup_menu (GtkWidget *widget); static gboolean ev_view_button_press_event (GtkWidget *widget, GdkEventButton *event); static gboolean ev_view_motion_notify_event (GtkWidget *widget, @@ -284,6 +193,8 @@ static gboolean ev_view_leave_notify_event (GtkWidget static void ev_view_style_set (GtkWidget *widget, GtkStyle *old_style); +static AtkObject *ev_view_get_accessible (GtkWidget *widget); + /*** Drawing ***/ static guint32 ev_gdk_color_to_rgb (const GdkColor *color); static void draw_rubberband (GtkWidget *widget, @@ -401,32 +312,37 @@ G_DEFINE_TYPE (EvView, ev_view, GTK_TYPE_WIDGET) static void scroll_to_current_page (EvView *view, GtkOrientation orientation) { - GdkRectangle page_area; - GtkBorder border; + GdkPoint view_point; if (view->document == NULL) { return; } - get_page_extents (view, view->current_page, &page_area, &border); + doc_point_to_view_point (view, view->current_page, &view->pending_point, &view_point); + + if (orientation == GTK_ORIENTATION_VERTICAL) { + view->pending_point.y = 0; + } else { + view->pending_point.x = 0; + } if (orientation == GTK_ORIENTATION_VERTICAL) { if (view->continuous) { gtk_adjustment_clamp_page (view->vadjustment, - page_area.y - view->spacing, - page_area.y + view->vadjustment->page_size); + view_point.y - view->spacing / 2, + view_point.y + view->vadjustment->page_size); } else { gtk_adjustment_set_value (view->vadjustment, - view->vadjustment->lower); + view_point.y); } } else { if (view->dual_page) { gtk_adjustment_clamp_page (view->hadjustment, - page_area.x, - page_area.x + view->hadjustment->page_size); + view_point.x, + view_point.x + view->hadjustment->page_size); } else { gtk_adjustment_set_value (view->hadjustment, - CLAMP (view->hadjustment->value, + CLAMP (view_point.x, view->hadjustment->lower, view->hadjustment->upper - view->hadjustment->page_size)); @@ -464,7 +380,7 @@ view_set_adjustment_values (EvView *view, case SCROLL_TO_KEEP_POSITION: factor = (adjustment->value) / adjustment->upper; break; - case SCROLL_TO_CURRENT_PAGE: + case SCROLL_TO_PAGE_POSITION: break; case SCROLL_TO_CENTER: factor = (adjustment->value + adjustment->page_size * 0.5) / adjustment->upper; @@ -485,7 +401,7 @@ view_set_adjustment_values (EvView *view, new_value = CLAMP (adjustment->upper * factor + 0.5, 0, adjustment->upper - adjustment->page_size); gtk_adjustment_set_value (adjustment, (int)new_value); break; - case SCROLL_TO_CURRENT_PAGE: + case SCROLL_TO_PAGE_POSITION: scroll_to_current_page (view, orientation); break; case SCROLL_TO_CENTER: @@ -934,7 +850,7 @@ view_rect_to_doc_rect (EvView *view, doc_rect->y2 = doc_rect->y1 + (double) view_rect->height / view->scale; } -static void +static gboolean doc_point_to_view_point (EvView *view, int page, EvPoint *doc_point, @@ -942,7 +858,7 @@ doc_point_to_view_point (EvView *view, { GdkRectangle page_area; GtkBorder border; - double x, y; + double x, y, view_x, view_y; int width, height; ev_page_cache_get_size (view->page_cache, page, @@ -968,8 +884,13 @@ doc_point_to_view_point (EvView *view, 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; + view_x = x * view->scale; + view_y = y * view->scale; + view_point->x = view_x + page_area.x; + view_point->y = view_y + page_area.y; + + return (view_x > 0 && view_x <= page_area.width && + view_y > 0 && view_y <= page_area.height); } static void @@ -1092,15 +1013,44 @@ ev_view_get_height (EvView *view) return GTK_WIDGET (view)->allocation.height; } +static gboolean +location_in_selected_text (EvView *view, + gdouble x, + gdouble y) +{ + gint page = -1; + gint x_offset = 0, y_offset = 0; + EvViewSelection *selection; + GList *l = NULL; + + for (l = view->selection_info.selections; l != NULL; l = l->next) { + selection = (EvViewSelection *)l->data; + + find_page_at_location (view, x, y, &page, &x_offset, &y_offset); + + if (page != selection->page) + continue; + + if (selection->covered_region && + gdk_region_point_in (selection->covered_region, x_offset, y_offset)) + return TRUE; + } + + return FALSE; +} + /*** Hyperref ***/ static EvLink * -get_link_at_location (EvView *view, - gdouble x, - gdouble y) +ev_view_get_link_at_location (EvView *view, + gdouble x, + gdouble y) { gint page = -1; gint x_offset = 0, y_offset = 0; GList *link_mapping; + + x += view->scroll_x; + y += view->scroll_y; find_page_at_location (view, x, y, &page, &x_offset, &y_offset); @@ -1118,18 +1068,10 @@ get_link_at_location (EvView *view, static void goto_fitr_link (EvView *view, EvLink *link) { - GdkPoint view_point; EvPoint doc_point; - int doc_width, doc_height, page; + int page; double zoom; - page = ev_link_get_page (link); - ev_page_cache_get_size (view->page_cache, page, 0, 1.0, &doc_width, &doc_height); - - doc_point.x = ev_link_get_left (link); - doc_point.y = ev_link_get_top (link); - doc_point_to_view_point (view, page, &doc_point, &view_point); - zoom = zoom_for_size_best_fit (ev_link_get_right (link) - ev_link_get_left (link), ev_link_get_top (link) - ev_link_get_bottom (link), ev_view_get_width (view), @@ -1137,14 +1079,21 @@ goto_fitr_link (EvView *view, EvLink *link) ev_view_set_sizing_mode (view, EV_SIZING_FREE); ev_view_set_zoom (view, zoom, FALSE); - ev_page_cache_set_current_page (view->page_cache, page); - gtk_adjustment_set_value (view->hadjustment, view_point.x); + + page = ev_link_get_page (link); + doc_point.x = ev_link_get_left (link); + doc_point.y = ev_link_get_top (link); + + view->current_page = page; + view->pending_point = doc_point; + view->pending_scroll = SCROLL_TO_PAGE_POSITION; + + gtk_widget_queue_resize (GTK_WIDGET (view)); } static void goto_fitv_link (EvView *view, EvLink *link) { - GdkPoint view_point; EvPoint doc_point; int doc_width, doc_height, page; double zoom; @@ -1154,7 +1103,6 @@ goto_fitv_link (EvView *view, EvLink *link) doc_point.x = ev_link_get_left (link); doc_point.y = 0; - doc_point_to_view_point (view, page, &doc_point, &view_point); zoom = zoom_for_size_fit_height (doc_width - doc_point.x , doc_height, ev_view_get_width (view), @@ -1162,14 +1110,17 @@ goto_fitv_link (EvView *view, EvLink *link) ev_view_set_sizing_mode (view, EV_SIZING_FREE); ev_view_set_zoom (view, zoom, FALSE); - ev_page_cache_set_current_page (view->page_cache, page); - gtk_adjustment_set_value (view->hadjustment, view_point.x); + + view->current_page = page; + view->pending_point = doc_point; + view->pending_scroll = SCROLL_TO_PAGE_POSITION; + + gtk_widget_queue_resize (GTK_WIDGET (view)); } static void goto_fith_link (EvView *view, EvLink *link) { - GdkPoint view_point; EvPoint doc_point; int doc_width, doc_height, page; double zoom; @@ -1179,7 +1130,6 @@ goto_fith_link (EvView *view, EvLink *link) doc_point.x = 0; doc_point.y = doc_height - ev_link_get_top (link); - doc_point_to_view_point (view, page, &doc_point, &view_point); zoom = zoom_for_size_fit_width (doc_width, ev_link_get_top (link), ev_view_get_width (view), @@ -1187,7 +1137,12 @@ goto_fith_link (EvView *view, EvLink *link) ev_view_set_sizing_mode (view, EV_SIZING_FREE); ev_view_set_zoom (view, zoom, FALSE); - gtk_adjustment_set_value (view->vadjustment, view_point.y); + + view->current_page = page; + view->pending_point = doc_point; + view->pending_scroll = SCROLL_TO_PAGE_POSITION; + + gtk_widget_queue_resize (GTK_WIDGET (view)); } static void @@ -1205,13 +1160,16 @@ goto_fit_link (EvView *view, EvLink *link) ev_view_set_sizing_mode (view, EV_SIZING_FREE); ev_view_set_zoom (view, zoom, FALSE); - ev_page_cache_set_current_page (view->page_cache, page); + + view->current_page = page; + view->pending_scroll = SCROLL_TO_PAGE_POSITION; + + gtk_widget_queue_resize (GTK_WIDGET (view)); } static void goto_xyz_link (EvView *view, EvLink *link) { - GdkPoint view_point; EvPoint doc_point; int height, page; double zoom; @@ -1220,17 +1178,19 @@ goto_xyz_link (EvView *view, EvLink *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_sizing_mode (view, EV_SIZING_FREE); 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); + view->current_page = page; + view->pending_point = doc_point; + view->pending_scroll = SCROLL_TO_PAGE_POSITION; + + gtk_widget_queue_resize (GTK_WIDGET (view)); } void @@ -1305,7 +1265,7 @@ 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); + link = ev_view_get_link_at_location (view, x, y); if (view->link_tooltip == NULL) { view->link_tooltip = ev_tooltip_new (GTK_WIDGET (view)); @@ -1319,9 +1279,13 @@ handle_link_over_xy (EvView *view, gint x, gint y) 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)); + if (msg && g_utf8_validate (msg, -1, NULL)) { + EvTooltip *tooltip = EV_TOOLTIP (view->link_tooltip); + + ev_tooltip_set_position (tooltip, x, y); + ev_tooltip_set_text (tooltip, msg); + ev_tooltip_activate (tooltip); + } g_free (msg); ev_view_set_cursor (view, EV_VIEW_CURSOR_LINK); @@ -1536,6 +1500,7 @@ ev_view_realize (GtkWidget *widget) GDK_SCROLL_MASK | GDK_KEY_PRESS_MASK | GDK_POINTER_MOTION_MASK | + GDK_POINTER_MOTION_HINT_MASK | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK; @@ -1658,27 +1623,50 @@ ev_view_expose_event (GtkWidget *widget, return FALSE; } +static gboolean +ev_view_popup_menu (GtkWidget *widget) +{ + gint x, y; + EvLink *link; + EvView *view = EV_VIEW (widget); + + gtk_widget_get_pointer (widget, &x, &y); + link = ev_view_get_link_at_location (view, x, y); + g_signal_emit (view, signals[SIGNAL_POPUP_MENU], 0, link); + return TRUE; +} + static gboolean ev_view_button_press_event (GtkWidget *widget, GdkEventButton *event) { EvView *view = EV_VIEW (widget); - + EvLink *link; + if (!GTK_WIDGET_HAS_FOCUS (widget)) { gtk_widget_grab_focus (widget); } - + view->pressed_button = event->button; - + view->selection_info.in_drag = FALSE; + switch (event->button) { - case 1: + case 1: if (view->selection_info.selections) { - clear_selection (view); + if (location_in_selected_text (view, + event->x + view->scroll_x, + event->y + view->scroll_y)) { + view->selection_info.in_drag = TRUE; + } else { + 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 @@ -1690,49 +1678,143 @@ ev_view_button_press_event (GtkWidget *widget, ev_view_set_cursor (view, EV_VIEW_CURSOR_DRAG); + return TRUE; + case 3: + link = ev_view_get_link_at_location (view, event->x, event->y); + g_signal_emit (view, signals[SIGNAL_POPUP_MENU], 0, link); return TRUE; } - + return FALSE; } +static void +ev_view_drag_data_get (GtkWidget *widget, + GdkDragContext *context, + GtkSelectionData *selection_data, + guint info, + guint time) +{ + EvView *view = EV_VIEW (widget); + + if (view->selection_info.selections && + ev_document_can_get_text (view->document)) { + gchar *text; + + text = get_selected_text (view); + + gtk_selection_data_set_text (selection_data, text, strlen (text)); + + g_free (text); + } +} 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); - + compute_selections (view, &view->selection_info.start, &view->motion); view->selection_update_id = 0; return FALSE; } +static gboolean +selection_scroll_timeout_cb (EvView *view) +{ + gint x, y, shift = 0; + GtkWidget *widget = GTK_WIDGET (view); + + gtk_widget_get_pointer (widget, &x, &y); + + if (y > widget->allocation.height) { + shift = (y - widget->allocation.height) / 2; + } else if (y < 0) { + shift = y / 2; + } + + if (shift) + gtk_adjustment_set_value (view->vadjustment, + CLAMP (view->vadjustment->value + shift, + view->vadjustment->lower, + view->vadjustment->upper - + view->vadjustment->page_size)); + + if (x > widget->allocation.width) { + shift = (x - widget->allocation.width) / 2; + } else if (x < 0) { + shift = x / 2; + } + + if (shift) + gtk_adjustment_set_value (view->hadjustment, + CLAMP (view->hadjustment->value + shift, + view->hadjustment->lower, + view->hadjustment->upper - + view->hadjustment->page_size)); + + return TRUE; +} + static gboolean ev_view_motion_notify_event (GtkWidget *widget, GdkEventMotion *event) { EvView *view = EV_VIEW (widget); + gint x, y; if (!view->document) return FALSE; + + if (event->is_hint || event->window != widget->window) { + gtk_widget_get_pointer (widget, &x, &y); + } else { + x = event->x; + y = event->y; + } + + if (view->selection_info.in_drag) { + if (gtk_drag_check_threshold (widget, + view->selection_info.start.x, + view->selection_info.start.y, + x, y)) { + GdkDragContext *context; + GtkTargetList *target_list = gtk_target_list_new (NULL, 0); + + gtk_target_list_add_text_targets (target_list, 0); + + context = gtk_drag_begin (widget, target_list, + GDK_ACTION_COPY, + 1, (GdkEvent *)event); + + view->selection_info.in_drag = FALSE; + + gtk_target_list_unref (target_list); + return TRUE; + } + } + /* For the Evince 0.4.x release, we limit selection to un-rotated * documents only. */ - if (view->pressed_button == 1 && - view->rotation == 0) { + if (view->pressed_button == 1 && view->rotation == 0) { + + /* Schedule timeout to scroll during selection and additionally + * scroll once to allow arbitrary speed. */ + if (!view->selection_scroll_id) + view->selection_scroll_id = g_timeout_add (SCROLL_TIME, (GSourceFunc)selection_scroll_timeout_cb, view); + else + selection_scroll_timeout_cb (view); + view->selection_info.in_selection = TRUE; - view->motion_x = event->x + view->scroll_x; - view->motion_y = event->y + view->scroll_y; + view->motion.x = x + view->scroll_x; + view->motion.y = 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 + /* 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) + if (!view->selection_update_id) view->selection_update_id = g_idle_add ((GSourceFunc)selection_update_idle_cb, view); return TRUE; @@ -1777,7 +1859,7 @@ ev_view_motion_notify_event (GtkWidget *widget, */ } else if (view->pressed_button <= 0 && view->rotation == 0) { - handle_link_over_xy (view, event->x, event->y); + handle_link_over_xy (view, x, y); return TRUE; } @@ -1796,8 +1878,7 @@ ev_view_button_release_event (GtkWidget *widget, } if (view->document) { - link = get_link_at_location (view, event->x + view->scroll_x, - event->y + view->scroll_y); + link = ev_view_get_link_at_location (view, event->x, event->y); } else { link = NULL; } @@ -1805,8 +1886,24 @@ ev_view_button_release_event (GtkWidget *widget, view->pressed_button = -1; view->drag_info.in_drag = FALSE; + if (view->selection_scroll_id) { + g_source_remove (view->selection_scroll_id); + view->selection_scroll_id = 0; + } + if (view->selection_update_id) { + g_source_remove (view->selection_update_id); + view->selection_update_id = 0; + } + if (view->selection_info.selections) { ev_view_update_primary_selection (view); + + if (view->selection_info.in_drag) { + clear_selection (view); + gtk_widget_queue_draw (widget); + } + + view->selection_info.in_drag = FALSE; } else if (link) { ev_view_goto_link (view, link); } else if (view->presentation) { @@ -1884,7 +1981,6 @@ ev_view_style_set (GtkWidget *widget, GTK_WIDGET_CLASS (ev_view_parent_class)->style_set (widget, old_style); } - /*** Drawing ***/ static guint32 @@ -2149,6 +2245,16 @@ ev_view_destroy (GtkObject *object) gtk_widget_destroy (view->link_tooltip); } + if (view->selection_scroll_id) { + g_source_remove (view->selection_scroll_id); + view->selection_scroll_id = 0; + } + + if (view->selection_update_id) { + g_source_remove (view->selection_update_id); + view->selection_update_id = 0; + } + ev_view_set_scroll_adjustments (view, NULL, NULL); GTK_OBJECT_CLASS (ev_view_parent_class)->destroy (object); @@ -2190,6 +2296,37 @@ ev_view_set_property (GObject *object, } } +static AtkObject * +ev_view_get_accessible (GtkWidget *widget) +{ + static gboolean first_time = TRUE; + + if (first_time) { + AtkObjectFactory *factory; + AtkRegistry *registry; + GType derived_type; + GType derived_atk_type; + + /* + * Figure out whether accessibility is enabled by looking at the + * type of the accessible object which would be created for + * the parent type of EvView. + */ + derived_type = g_type_parent (EV_TYPE_VIEW); + + registry = atk_get_default_registry (); + factory = atk_registry_get_factory (registry, + derived_type); + derived_atk_type = atk_object_factory_get_accessible_type (factory); + if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE)) + atk_registry_set_factory_type (registry, + EV_TYPE_VIEW, + ev_view_accessible_factory_get_type ()); + first_time = FALSE; + } + return GTK_WIDGET_CLASS (ev_view_parent_class)->get_accessible (widget); +} + static void ev_view_get_property (GObject *object, guint prop_id, @@ -2227,6 +2364,10 @@ ev_view_get_property (GObject *object, case PROP_ROTATION: g_value_set_int (value, view->rotation); break; + case PROP_HAS_SELECTION: + g_value_set_boolean (value, + view->selection_info.selections != NULL); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } @@ -2250,6 +2391,7 @@ ev_view_class_init (EvViewClass *class) widget_class->button_release_event = ev_view_button_release_event; widget_class->focus_in_event = ev_view_focus_in; widget_class->focus_out_event = ev_view_focus_out; + widget_class->get_accessible = ev_view_get_accessible; widget_class->size_request = ev_view_size_request; widget_class->size_allocate = ev_view_size_allocate; widget_class->realize = ev_view_realize; @@ -2257,6 +2399,8 @@ ev_view_class_init (EvViewClass *class) 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; + widget_class->drag_data_get = ev_view_drag_data_get; + widget_class->popup_menu = ev_view_popup_menu; gtk_object_class->destroy = ev_view_destroy; class->set_scroll_adjustments = ev_view_set_scroll_adjustments; @@ -2298,6 +2442,14 @@ ev_view_class_init (EvViewClass *class) g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, G_TYPE_OBJECT); + signals[SIGNAL_POPUP_MENU] = g_signal_new ("popup", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (EvViewClass, popup_menu), + NULL, NULL, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, 1, + G_TYPE_OBJECT); g_object_class_install_property (object_class, PROP_STATUS, @@ -2372,6 +2524,13 @@ ev_view_class_init (EvViewClass *class) 360, 0, G_PARAM_READWRITE)); + g_object_class_install_property (object_class, + PROP_HAS_SELECTION, + g_param_spec_boolean ("has-selection", + "Has selection", + "The view has selections", + FALSE, + G_PARAM_READABLE)); binding_set = gtk_binding_set_by_class (class); @@ -2392,7 +2551,9 @@ ev_view_init (EvView *view) view->pressed_button = -1; view->cursor = EV_VIEW_CURSOR_NORMAL; view->drag_info.in_drag = FALSE; + view->selection_info.selections = NULL; view->selection_info.in_selection = FALSE; + view->selection_info.in_drag = FALSE; view->selection_mode = EV_VIEW_SELECTION_TEXT; view->continuous = TRUE; view->dual_page = FALSE; @@ -2430,7 +2591,7 @@ page_changed_cb (EvPageCache *page_cache, if (view->current_page != new_page) { view->current_page = new_page; - view->pending_scroll = SCROLL_TO_CURRENT_PAGE; + view->pending_scroll = SCROLL_TO_PAGE_POSITION; gtk_widget_queue_resize (GTK_WIDGET (view)); if (EV_IS_DOCUMENT_FIND (view->document)) { @@ -2596,7 +2757,7 @@ ev_view_set_continuous (EvView *view, if (view->continuous != continuous) { view->continuous = continuous; - view->pending_scroll = SCROLL_TO_CURRENT_PAGE; + view->pending_scroll = SCROLL_TO_PAGE_POSITION; gtk_widget_queue_resize (GTK_WIDGET (view)); } @@ -2622,7 +2783,7 @@ ev_view_set_dual_page (EvView *view, if (view->dual_page == dual_page) return; - view->pending_scroll = SCROLL_TO_CURRENT_PAGE; + view->pending_scroll = SCROLL_TO_PAGE_POSITION; view->dual_page = dual_page; /* FIXME: if we're keeping the pixbuf cache around, we should extend the * preload_cache_size to be 2 if dual_page is set. @@ -2669,7 +2830,7 @@ ev_view_set_presentation (EvView *view, return; view->presentation = presentation; - view->pending_scroll = SCROLL_TO_CURRENT_PAGE; + view->pending_scroll = SCROLL_TO_PAGE_POSITION; gtk_widget_queue_resize (GTK_WIDGET (view)); if (GTK_WIDGET_REALIZED (view)) { @@ -3424,6 +3585,7 @@ merge_selection_region (EvView *view, g_list_foreach (view->selection_info.selections, (GFunc)selection_free, NULL); view->selection_info.selections = new_list; ev_pixbuf_cache_set_selection_list (view->pixbuf_cache, new_list); + g_object_notify (G_OBJECT (view), "has-selection"); new_list_ptr = new_list; old_list_ptr = old_list; @@ -3554,6 +3716,7 @@ clear_selection (EvView *view) g_list_foreach (view->selection_info.selections, (GFunc)selection_free, NULL); view->selection_info.selections = NULL; view->selection_info.in_selection = FALSE; + g_object_notify (G_OBJECT (view), "has-selection"); } @@ -3588,9 +3751,16 @@ ev_view_select_all (EvView *view) } ev_pixbuf_cache_set_selection_list (view->pixbuf_cache, view->selection_info.selections); + g_object_notify (G_OBJECT (view), "has-selection"); gtk_widget_queue_draw (GTK_WIDGET (view)); } +gboolean +ev_view_get_has_selection (EvView *view) +{ + return view->selection_info.selections != NULL; +} + static char * get_selected_text (EvView *ev_view) {