X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;ds=inline;f=shell%2Fev-view.c;h=a9418dac2337e6a2d9ed3e99238731e1869295b4;hb=c914510ee5b56a29c562f2054d8c4e627714483e;hp=fe84912335a05511b5593967275f7f84c97a6695;hpb=19033026f00585b3710644250f851ca02246c9fc;p=evince.git diff --git a/shell/ev-view.c b/shell/ev-view.c index fe849123..a9418dac 100644 --- a/shell/ev-view.c +++ b/shell/ev-view.c @@ -30,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" @@ -56,6 +57,7 @@ enum { PROP_SIZING_MODE, PROP_ZOOM, PROP_ROTATION, + PROP_HAS_SELECTION, }; enum { @@ -82,15 +84,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 @@ -102,99 +95,6 @@ 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; - gboolean in_drag; - 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); -}; - /*** Scrolling ***/ static void scroll_to_current_page (EvView *view, GtkOrientation orientation); @@ -286,6 +186,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, @@ -1117,7 +1019,8 @@ location_in_selected_text (EvView *view, if (page != selection->page) continue; - if (gdk_region_point_in (selection->covered_region, x_offset, y_offset)) + if (selection->covered_region && + gdk_region_point_in (selection->covered_region, x_offset, y_offset)) return TRUE; } @@ -1989,7 +1892,6 @@ ev_view_style_set (GtkWidget *widget, GTK_WIDGET_CLASS (ev_view_parent_class)->style_set (widget, old_style); } - /*** Drawing ***/ static guint32 @@ -2295,6 +2197,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, @@ -2332,6 +2265,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); } @@ -2355,6 +2292,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; @@ -2478,6 +2416,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); @@ -2498,6 +2443,7 @@ 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; @@ -3531,6 +3477,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; @@ -3661,6 +3608,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"); } @@ -3695,9 +3643,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) {