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.
21 #include <glib/gi18n.h>
23 #include "ev-view-accessible.h"
24 #include "ev-view-private.h"
26 #define EV_TYPE_VIEW_ACCESSIBLE (ev_view_accessible_get_type ())
27 #define EV_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EV_TYPE_VIEW_ACCESSIBLE, EvViewAccessible))
28 #define EV_IS_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EV_TYPE_VIEW_ACCESSIBLE))
30 static gulong accessible_private_data_quark;
32 static GType ev_view_accessible_get_type (void);
40 static const gchar *const ev_view_accessible_action_names[] =
47 static const gchar *const ev_view_accessible_action_descriptions[] =
50 N_("Scroll View Down"),
56 gchar *action_descriptions[LAST_ACTION];
57 guint action_idle_handler;
58 EvScrollType idle_scroll;
59 } EvViewAccessiblePriv;
61 static EvViewAccessiblePriv *
62 ev_view_accessible_get_priv (AtkObject *accessible)
64 return g_object_get_qdata (G_OBJECT (accessible),
65 accessible_private_data_quark);
69 ev_view_accessible_free_priv (EvViewAccessiblePriv *priv)
73 if (priv->action_idle_handler)
74 g_source_remove (priv->action_idle_handler);
75 for (i = 0; i < LAST_ACTION; i++)
76 if (priv->action_descriptions [i] != NULL)
77 g_free (priv->action_descriptions [i]);
80 static void ev_view_accessible_class_init (GtkAccessibleClass * klass)
82 accessible_private_data_quark = g_quark_from_static_string ("ev-view-accessible-private-data");
87 ev_view_accessible_get_text (AtkText *text,
93 widget = GTK_ACCESSIBLE (text)->widget;
95 /* State is defunct */
102 ev_view_accessible_get_character_at_offset (AtkText *text,
107 widget = GTK_ACCESSIBLE (text)->widget;
109 /* State is defunct */
116 ev_view_accessible_get_text_before_offset (AtkText *text,
118 AtkTextBoundary boundary_type,
124 widget = GTK_ACCESSIBLE (text)->widget;
126 /* State is defunct */
133 ev_view_accessible_get_text_at_offset (AtkText *text,
135 AtkTextBoundary boundary_type,
141 widget = GTK_ACCESSIBLE (text)->widget;
143 /* State is defunct */
150 ev_view_accessible_get_text_after_offset (AtkText *text,
152 AtkTextBoundary boundary_type,
158 widget = GTK_ACCESSIBLE (text)->widget;
160 /* State is defunct */
167 ev_view_accessible_get_character_count (AtkText *text)
171 widget = GTK_ACCESSIBLE (text)->widget;
173 /* State is defunct */
180 ev_view_accessible_get_caret_offset (AtkText *text)
184 widget = GTK_ACCESSIBLE (text)->widget;
186 /* State is defunct */
193 ev_view_accessible_set_caret_offset (AtkText *text, gint offset)
197 widget = GTK_ACCESSIBLE (text)->widget;
199 /* State is defunct */
205 static AtkAttributeSet*
206 ev_view_accessible_get_run_attributes (AtkText *text,
213 widget = GTK_ACCESSIBLE (text)->widget;
215 /* State is defunct */
221 static AtkAttributeSet*
222 ev_view_accessible_get_default_attributes (AtkText *text)
226 widget = GTK_ACCESSIBLE (text)->widget;
228 /* State is defunct */
235 ev_view_accessible_get_character_extents (AtkText *text,
245 widget = GTK_ACCESSIBLE (text)->widget;
247 /* State is defunct */
254 ev_view_accessible_get_offset_at_point (AtkText *text,
261 widget = GTK_ACCESSIBLE (text)->widget;
263 /* State is defunct */
270 ev_view_accessible_get_n_selections (AtkText *text)
274 widget = GTK_ACCESSIBLE (text)->widget;
276 /* State is defunct */
283 ev_view_accessible_get_selection (AtkText *text,
290 widget = GTK_ACCESSIBLE (text)->widget;
292 /* State is defunct */
299 ev_view_accessible_add_selection (AtkText *text,
305 widget = GTK_ACCESSIBLE (text)->widget;
307 /* State is defunct */
314 ev_view_accessible_remove_selection (AtkText *text,
319 widget = GTK_ACCESSIBLE (text)->widget;
321 /* State is defunct */
328 ev_view_accessible_set_selection (AtkText *text,
335 widget = GTK_ACCESSIBLE (text)->widget;
337 /* State is defunct */
344 static void ev_view_accessible_text_iface_init (AtkTextIface * iface)
346 g_return_if_fail (iface != NULL);
348 iface->get_text = ev_view_accessible_get_text;
349 iface->get_character_at_offset = ev_view_accessible_get_character_at_offset;
350 iface->get_text_before_offset = ev_view_accessible_get_text_before_offset;
351 iface->get_text_at_offset = ev_view_accessible_get_text_at_offset;
352 iface->get_text_after_offset = ev_view_accessible_get_text_after_offset;
353 iface->get_caret_offset = ev_view_accessible_get_caret_offset;
354 iface->set_caret_offset = ev_view_accessible_set_caret_offset;
355 iface->get_character_count = ev_view_accessible_get_character_count;
356 iface->get_n_selections = ev_view_accessible_get_n_selections;
357 iface->get_selection = ev_view_accessible_get_selection;
358 iface->add_selection = ev_view_accessible_add_selection;
359 iface->remove_selection = ev_view_accessible_remove_selection;
360 iface->set_selection = ev_view_accessible_set_selection;
361 iface->get_run_attributes = ev_view_accessible_get_run_attributes;
362 iface->get_default_attributes = ev_view_accessible_get_default_attributes;
363 iface->get_character_extents = ev_view_accessible_get_character_extents;
364 iface->get_offset_at_point = ev_view_accessible_get_offset_at_point;
369 ev_view_accessible_idle_do_action (gpointer data)
371 EvViewAccessiblePriv* priv = ev_view_accessible_get_priv (ATK_OBJECT (data));
373 ev_view_scroll (EV_VIEW (GTK_ACCESSIBLE (data)->widget),
376 priv->action_idle_handler = 0;
381 ev_view_accessible_action_do_action (AtkAction *action,
384 EvViewAccessiblePriv* priv = ev_view_accessible_get_priv (ATK_OBJECT (action));
386 if (GTK_ACCESSIBLE (action)->widget == NULL)
389 if (priv->action_idle_handler)
393 case ACTION_SCROLL_UP:
394 priv->idle_scroll = EV_SCROLL_PAGE_BACKWARD;
396 case ACTION_SCROLL_DOWN:
397 priv->idle_scroll = EV_SCROLL_PAGE_FORWARD;
402 priv->action_idle_handler = g_idle_add (ev_view_accessible_idle_do_action,
408 ev_view_accessible_action_get_n_actions (AtkAction *action)
414 ev_view_accessible_action_get_description (AtkAction *action,
417 EvViewAccessiblePriv* priv = ev_view_accessible_get_priv (ATK_OBJECT (action));
419 if (i < 0 || i >= LAST_ACTION)
422 if (priv->action_descriptions[i])
423 return priv->action_descriptions[i];
425 return ev_view_accessible_action_descriptions[i];
429 ev_view_accessible_action_get_name (AtkAction *action,
432 if (i < 0 || i >= LAST_ACTION)
435 return ev_view_accessible_action_names[i];
439 ev_view_accessible_action_set_description (AtkAction *action,
441 const gchar *description)
443 EvViewAccessiblePriv* priv = ev_view_accessible_get_priv (ATK_OBJECT (action));
445 if (i < 0 || i >= LAST_ACTION)
448 if (priv->action_descriptions[i])
449 g_free (priv->action_descriptions[i]);
451 priv->action_descriptions[i] = g_strdup (description);
456 static void ev_view_accessible_action_iface_init (AtkActionIface * iface)
458 iface->do_action = ev_view_accessible_action_do_action;
459 iface->get_n_actions = ev_view_accessible_action_get_n_actions;
460 iface->get_description = ev_view_accessible_action_get_description;
461 iface->get_name = ev_view_accessible_action_get_name;
462 iface->set_description = ev_view_accessible_action_set_description;
466 GType ev_view_accessible_get_type (void)
468 static GType type = 0;
471 static GTypeInfo tinfo = {
473 (GBaseInitFunc) NULL, /* base init */
474 (GBaseFinalizeFunc) NULL, /* base finalize */
475 (GClassInitFunc) ev_view_accessible_class_init, /* class init */
476 (GClassFinalizeFunc) NULL, /* class finalize */
477 NULL, /* class data */
478 0, /* instance size */
479 0, /* nb preallocs */
480 (GInstanceInitFunc) NULL, /* instance init */
481 NULL /* value table */
484 static const GInterfaceInfo atk_text_info = {
486 ev_view_accessible_text_iface_init,
487 (GInterfaceFinalizeFunc) NULL,
491 static const GInterfaceInfo atk_action_info = {
493 ev_view_accessible_action_iface_init,
494 (GInterfaceFinalizeFunc) NULL,
498 * Figure out the size of the class and instance
499 * we are deriving from
501 AtkObjectFactory *factory;
504 GType derived_atk_type;
506 derived_type = g_type_parent (EV_TYPE_VIEW);
507 factory = atk_registry_get_factory (atk_get_default_registry (),
509 derived_atk_type = atk_object_factory_get_accessible_type (factory);
511 g_type_query (derived_atk_type, &query);
512 tinfo.class_size = query.class_size;
513 tinfo.instance_size = query.instance_size;
515 type = g_type_register_static (derived_atk_type, "EvViewAccessible",
517 g_type_add_interface_static (type, ATK_TYPE_TEXT,
519 g_type_add_interface_static (type, ATK_TYPE_ACTION,
526 static AtkObject *ev_view_accessible_new(GObject * obj)
528 AtkObject *accessible;
529 EvViewAccessiblePriv *priv;
531 g_return_val_if_fail(EV_IS_VIEW (obj), NULL);
533 accessible = g_object_new (ev_view_accessible_get_type (), NULL);
534 atk_object_initialize (accessible, obj);
536 atk_object_set_name (ATK_OBJECT (accessible), _("Document View"));
537 atk_object_set_role (ATK_OBJECT (accessible), ATK_ROLE_UNKNOWN);
539 priv = g_new0 (EvViewAccessiblePriv, 1);
540 g_object_set_qdata_full (G_OBJECT (accessible),
541 accessible_private_data_quark,
543 (GDestroyNotify) ev_view_accessible_free_priv);
548 GType ev_view_accessible_factory_get_accessible_type(void)
550 return ev_view_accessible_get_type();
553 static AtkObject *ev_view_accessible_factory_create_accessible (GObject * obj)
555 return ev_view_accessible_new(obj);
558 static void ev_view_accessible_factory_class_init (AtkObjectFactoryClass * klass)
560 klass->create_accessible = ev_view_accessible_factory_create_accessible;
561 klass->get_accessible_type =
562 ev_view_accessible_factory_get_accessible_type;
565 GType ev_view_accessible_factory_get_type (void)
567 static GType type = 0;
570 static const GTypeInfo tinfo = {
571 sizeof(AtkObjectFactoryClass),
572 NULL, /* base_init */
573 NULL, /* base_finalize */
574 (GClassInitFunc) ev_view_accessible_factory_class_init,
575 NULL, /* class_finalize */
576 NULL, /* class_data */
577 sizeof(AtkObjectFactory),
582 type = g_type_register_static (ATK_TYPE_OBJECT_FACTORY,
583 "EvViewAccessibleFactory", &tinfo,