1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
2 /* this file is part of evince, a gnome document viewer
4 * Copyright (C) 2004 Red Hat, Inc
6 * Evince is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * Evince is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22 #include <glib/gi18n.h>
24 #include "ev-view-accessible.h"
25 #include "ev-view-private.h"
27 #define EV_TYPE_VIEW_ACCESSIBLE (ev_view_accessible_get_type ())
28 #define EV_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EV_TYPE_VIEW_ACCESSIBLE, EvViewAccessible))
29 #define EV_IS_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EV_TYPE_VIEW_ACCESSIBLE))
31 static GType ev_view_accessible_get_type (void);
39 static const gchar *const ev_view_accessible_action_names[] =
46 static const gchar *const ev_view_accessible_action_descriptions[] =
49 N_("Scroll View Down"),
55 gchar *action_descriptions[LAST_ACTION];
56 guint action_idle_handler;
57 EvScrollType idle_scroll;
58 } EvViewAccessiblePriv;
60 typedef GtkAccessibleClass EvViewAccessibleClass;
62 #define EV_VIEW_ACCESSIBLE_GET_PRIVATE(inst) (G_TYPE_INSTANCE_GET_PRIVATE ((inst), EV_TYPE_VIEW_ACCESSIBLE, EvViewAccessiblePriv))
65 ev_view_accessible_finalize (GObject *object)
67 EvViewAccessiblePriv *priv = EV_VIEW_ACCESSIBLE_GET_PRIVATE (object);
70 if (priv->action_idle_handler)
71 g_source_remove (priv->action_idle_handler);
72 for (i = 0; i < LAST_ACTION; i++)
73 g_free (priv->action_descriptions [i]);
76 static void ev_view_accessible_class_init (EvViewAccessibleClass *klass)
78 GObjectClass *object_class = G_OBJECT_CLASS (klass);
80 object_class->finalize = ev_view_accessible_finalize;
82 g_type_class_add_private (klass, sizeof (EvViewAccessiblePriv));
86 ev_view_accessible_get_text (AtkText *text,
92 widget = GTK_ACCESSIBLE (text)->widget;
94 /* State is defunct */
101 ev_view_accessible_get_character_at_offset (AtkText *text,
106 widget = GTK_ACCESSIBLE (text)->widget;
108 /* State is defunct */
115 ev_view_accessible_get_text_before_offset (AtkText *text,
117 AtkTextBoundary boundary_type,
123 widget = GTK_ACCESSIBLE (text)->widget;
125 /* State is defunct */
132 ev_view_accessible_get_text_at_offset (AtkText *text,
134 AtkTextBoundary boundary_type,
140 widget = GTK_ACCESSIBLE (text)->widget;
142 /* State is defunct */
149 ev_view_accessible_get_text_after_offset (AtkText *text,
151 AtkTextBoundary boundary_type,
157 widget = GTK_ACCESSIBLE (text)->widget;
159 /* State is defunct */
166 ev_view_accessible_get_character_count (AtkText *text)
170 widget = GTK_ACCESSIBLE (text)->widget;
172 /* State is defunct */
179 ev_view_accessible_get_caret_offset (AtkText *text)
183 widget = GTK_ACCESSIBLE (text)->widget;
185 /* State is defunct */
192 ev_view_accessible_set_caret_offset (AtkText *text, gint offset)
196 widget = GTK_ACCESSIBLE (text)->widget;
198 /* State is defunct */
204 static AtkAttributeSet*
205 ev_view_accessible_get_run_attributes (AtkText *text,
212 widget = GTK_ACCESSIBLE (text)->widget;
214 /* State is defunct */
220 static AtkAttributeSet*
221 ev_view_accessible_get_default_attributes (AtkText *text)
225 widget = GTK_ACCESSIBLE (text)->widget;
227 /* State is defunct */
234 ev_view_accessible_get_character_extents (AtkText *text,
244 widget = GTK_ACCESSIBLE (text)->widget;
246 /* State is defunct */
253 ev_view_accessible_get_offset_at_point (AtkText *text,
260 widget = GTK_ACCESSIBLE (text)->widget;
262 /* State is defunct */
269 ev_view_accessible_get_n_selections (AtkText *text)
273 widget = GTK_ACCESSIBLE (text)->widget;
275 /* State is defunct */
282 ev_view_accessible_get_selection (AtkText *text,
289 widget = GTK_ACCESSIBLE (text)->widget;
291 /* State is defunct */
298 ev_view_accessible_add_selection (AtkText *text,
304 widget = GTK_ACCESSIBLE (text)->widget;
306 /* State is defunct */
313 ev_view_accessible_remove_selection (AtkText *text,
318 widget = GTK_ACCESSIBLE (text)->widget;
320 /* State is defunct */
327 ev_view_accessible_set_selection (AtkText *text,
334 widget = GTK_ACCESSIBLE (text)->widget;
336 /* State is defunct */
343 static void ev_view_accessible_text_iface_init (AtkTextIface * iface)
345 g_return_if_fail (iface != NULL);
347 iface->get_text = ev_view_accessible_get_text;
348 iface->get_character_at_offset = ev_view_accessible_get_character_at_offset;
349 iface->get_text_before_offset = ev_view_accessible_get_text_before_offset;
350 iface->get_text_at_offset = ev_view_accessible_get_text_at_offset;
351 iface->get_text_after_offset = ev_view_accessible_get_text_after_offset;
352 iface->get_caret_offset = ev_view_accessible_get_caret_offset;
353 iface->set_caret_offset = ev_view_accessible_set_caret_offset;
354 iface->get_character_count = ev_view_accessible_get_character_count;
355 iface->get_n_selections = ev_view_accessible_get_n_selections;
356 iface->get_selection = ev_view_accessible_get_selection;
357 iface->add_selection = ev_view_accessible_add_selection;
358 iface->remove_selection = ev_view_accessible_remove_selection;
359 iface->set_selection = ev_view_accessible_set_selection;
360 iface->get_run_attributes = ev_view_accessible_get_run_attributes;
361 iface->get_default_attributes = ev_view_accessible_get_default_attributes;
362 iface->get_character_extents = ev_view_accessible_get_character_extents;
363 iface->get_offset_at_point = ev_view_accessible_get_offset_at_point;
368 ev_view_accessible_idle_do_action (gpointer data)
370 EvViewAccessiblePriv* priv = EV_VIEW_ACCESSIBLE_GET_PRIVATE (data);
372 ev_view_scroll (EV_VIEW (GTK_ACCESSIBLE (data)->widget),
375 priv->action_idle_handler = 0;
380 ev_view_accessible_action_do_action (AtkAction *action,
383 EvViewAccessiblePriv* priv = EV_VIEW_ACCESSIBLE_GET_PRIVATE (action);
385 if (GTK_ACCESSIBLE (action)->widget == NULL)
388 if (priv->action_idle_handler)
392 case ACTION_SCROLL_UP:
393 priv->idle_scroll = EV_SCROLL_PAGE_BACKWARD;
395 case ACTION_SCROLL_DOWN:
396 priv->idle_scroll = EV_SCROLL_PAGE_FORWARD;
401 priv->action_idle_handler = g_idle_add (ev_view_accessible_idle_do_action,
407 ev_view_accessible_action_get_n_actions (AtkAction *action)
413 ev_view_accessible_action_get_description (AtkAction *action,
416 EvViewAccessiblePriv* priv = EV_VIEW_ACCESSIBLE_GET_PRIVATE (action);
418 if (i < 0 || i >= LAST_ACTION)
421 if (priv->action_descriptions[i])
422 return priv->action_descriptions[i];
424 return ev_view_accessible_action_descriptions[i];
428 ev_view_accessible_action_get_name (AtkAction *action,
431 if (i < 0 || i >= LAST_ACTION)
434 return ev_view_accessible_action_names[i];
438 ev_view_accessible_action_set_description (AtkAction *action,
440 const gchar *description)
442 EvViewAccessiblePriv* priv = EV_VIEW_ACCESSIBLE_GET_PRIVATE (action);
443 gchar *old_description;
445 if (i < 0 || i >= LAST_ACTION)
448 old_description = priv->action_descriptions[i];
449 priv->action_descriptions[i] = g_strdup (description);
450 g_free (old_description);
455 static void ev_view_accessible_action_iface_init (AtkActionIface * iface)
457 iface->do_action = ev_view_accessible_action_do_action;
458 iface->get_n_actions = ev_view_accessible_action_get_n_actions;
459 iface->get_description = ev_view_accessible_action_get_description;
460 iface->get_name = ev_view_accessible_action_get_name;
461 iface->set_description = ev_view_accessible_action_set_description;
464 GType ev_view_accessible_get_type (void)
466 static GType type = 0;
468 if (G_UNLIKELY (type == 0)) {
471 (GBaseInitFunc) NULL, /* base init */
472 (GBaseFinalizeFunc) NULL, /* base finalize */
473 (GClassInitFunc) ev_view_accessible_class_init, /* class init */
474 (GClassFinalizeFunc) NULL, /* class finalize */
475 NULL, /* class data */
476 0, /* instance size */
477 0, /* nb preallocs */
478 (GInstanceInitFunc) NULL, /* instance init */
479 NULL /* value table */
482 const GInterfaceInfo atk_text_info = {
484 ev_view_accessible_text_iface_init,
485 (GInterfaceFinalizeFunc) NULL,
489 const GInterfaceInfo atk_action_info = {
491 ev_view_accessible_action_iface_init,
492 (GInterfaceFinalizeFunc) NULL,
496 * Figure out the size of the class and instance
497 * we are deriving from
499 AtkObjectFactory *factory;
502 GType derived_atk_type;
504 derived_type = g_type_parent (EV_TYPE_VIEW);
505 factory = atk_registry_get_factory (atk_get_default_registry (),
507 derived_atk_type = atk_object_factory_get_accessible_type (factory);
509 g_type_query (derived_atk_type, &query);
510 tinfo.class_size = query.class_size;
511 tinfo.instance_size = query.instance_size;
513 type = g_type_register_static (derived_atk_type, "EvViewAccessible",
515 g_type_add_interface_static (type, ATK_TYPE_TEXT,
517 g_type_add_interface_static (type, ATK_TYPE_ACTION,
524 static AtkObject *ev_view_accessible_new(GObject * obj)
526 AtkObject *accessible;
528 g_return_val_if_fail(EV_IS_VIEW (obj), NULL);
530 accessible = g_object_new (ev_view_accessible_get_type (), NULL);
531 atk_object_initialize (accessible, obj);
533 atk_object_set_name (ATK_OBJECT (accessible), _("Document View"));
534 atk_object_set_role (ATK_OBJECT (accessible), ATK_ROLE_UNKNOWN);
539 typedef AtkObjectFactory EvViewAccessibleFactory;
540 typedef AtkObjectFactoryClass EvViewAccessibleFactoryClass;
542 static void ev_view_accessible_factory_init (EvViewAccessibleFactory *factory)
546 static GType ev_view_accessible_factory_get_accessible_type(void)
548 return ev_view_accessible_get_type();
551 static AtkObject *ev_view_accessible_factory_create_accessible (GObject * obj)
553 return ev_view_accessible_new(obj);
556 static void ev_view_accessible_factory_class_init (AtkObjectFactoryClass * klass)
558 klass->create_accessible = ev_view_accessible_factory_create_accessible;
559 klass->get_accessible_type =
560 ev_view_accessible_factory_get_accessible_type;
563 G_DEFINE_TYPE (EvViewAccessibleFactory, ev_view_accessible_factory, ATK_TYPE_OBJECT_FACTORY)