atkobject.c 54.2 KB
Newer Older
Bill Haneman's avatar
Bill Haneman committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/* ATK -  Accessibility Toolkit
 * Copyright 2001 Sun Microsystems Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
15 16 17
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
Bill Haneman's avatar
Bill Haneman committed
18 19
 */

20 21
#include "config.h"

22
#include <string.h>
23
#include <locale.h>
24

Bill Haneman's avatar
Bill Haneman committed
25
#include <glib-object.h>
26
#include <glib/gi18n-lib.h>
Bill Haneman's avatar
Bill Haneman committed
27 28

#include "atk.h"
29
#include "atkmarshal.h"
30
#include "atkprivate.h"
31

32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
/**
 * SECTION:atkobject
 * @Short_description: The base object class for the Accessibility Toolkit API.
 * @Title:AtkObject
 *
 * This class is the primary class for accessibility support via the
 * Accessibility ToolKit (ATK).  Objects which are instances of
 * #AtkObject (or instances of AtkObject-derived types) are queried
 * for properties which relate basic (and generic) properties of a UI
 * component such as name and description.  Instances of #AtkObject
 * may also be queried as to whether they implement other ATK
 * interfaces (e.g. #AtkAction, #AtkComponent, etc.), as appropriate
 * to the role which a given UI component plays in a user interface.
 *
 * All UI components in an application which provide useful
 * information or services to the user must provide corresponding
 * #AtkObject instances on request (in GTK+, for instance, usually on
 * a call to #gtk_widget_get_accessible ()), either via ATK support
 * built into the toolkit for the widget class or ancestor class, or
 * in the case of custom widgets, if the inherited #AtkObject
 * implementation is insufficient, via instances of a new #AtkObject
 * subclass.
 *
 * See also: #AtkObjectFactory, #AtkRegistry.  (GTK+ users see also
 * #GtkAccessible).
 *
 */

60
static GPtrArray *role_names = NULL;
61

Bill Haneman's avatar
Bill Haneman committed
62 63 64 65 66 67 68
enum
{
  PROP_0,  /* gobject convention */

  PROP_NAME,
  PROP_DESCRIPTION,
  PROP_PARENT,      /* ancestry has changed */
69
  PROP_VALUE,
70
  PROP_ROLE,
71 72
  PROP_LAYER,
  PROP_MDI_ZORDER,
73 74 75 76 77 78
  PROP_TABLE_CAPTION,
  PROP_TABLE_COLUMN_DESCRIPTION,
  PROP_TABLE_COLUMN_HEADER,
  PROP_TABLE_ROW_DESCRIPTION,
  PROP_TABLE_ROW_HEADER,
  PROP_TABLE_SUMMARY,
79
  PROP_TABLE_CAPTION_OBJECT,
80
  PROP_HYPERTEXT_NUM_LINKS,
Bill Haneman's avatar
Bill Haneman committed
81 82 83 84 85
  PROP_LAST         /* gobject convention */
};

enum {
  CHILDREN_CHANGED,
86
  FOCUS_EVENT,
87
  PROPERTY_CHANGE,
88
  STATE_CHANGE,
89
  VISIBLE_DATA_CHANGED,
90
  ACTIVE_DESCENDANT_CHANGED,
91
  
Bill Haneman's avatar
Bill Haneman committed
92 93 94
  LAST_SIGNAL
};

95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
/* These are listed here for extraction by intltool */
#if 0
  N_("invalid")
  N_("accelerator label")
  N_("alert")
  N_("animation")
  N_("arrow")
  N_("calendar")
  N_("canvas")
  N_("check box")
  N_("check menu item")
  N_("color chooser")
  N_("column header")
  N_("combo box")
  N_("dateeditor")
  N_("desktop icon")
  N_("desktop frame")
  N_("dial")
  N_("dialog")
  N_("directory pane")
  N_("drawing area")
  N_("file chooser")
  N_("filler")
118
  /* I know it looks wrong but that is what Java returns */
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
  N_("fontchooser")
  N_("frame")
  N_("glass pane")
  N_("html container")
  N_("icon")
  N_("image")
  N_("internal frame")
  N_("label")
  N_("layered pane")
  N_("list")
  N_("list item")
  N_("menu")
  N_("menu bar")
  N_("menu item")
  N_("option pane")
  N_("page tab")
  N_("page tab list")
  N_("panel")
  N_("password text")
  N_("popup menu")
  N_("progress bar")
  N_("push button")
  N_("radio button")
  N_("radio menu item")
  N_("root pane")
  N_("row header")
  N_("scroll bar")
  N_("scroll pane")
  N_("separator")
  N_("slider")
  N_("split pane")
  N_("spin button")
  N_("statusbar")
  N_("table")
  N_("table cell")
  N_("table column header")
  N_("table row header")
  N_("tear off menu item")
  N_("terminal")
  N_("text")
  N_("toggle button")
  N_("tool bar")
  N_("tool tip")
  N_("tree")
  N_("tree table")
  N_("unknown")
  N_("viewport")
  N_("window")
  N_("header")
  N_("footer")
  N_("paragraph")
  N_("ruler")
  N_("application")
  N_("autocomplete")
  N_("edit bar")
  N_("embedded component")
  N_("entry")
  N_("chart")
  N_("caption")
  N_("document frame")
  N_("heading")
  N_("page")
  N_("section")
  N_("redundant object")
  N_("form")
  N_("link")
  N_("input method window")
186 187 188 189 190 191 192 193 194 195 196 197 198
  N_("table row")
  N_("tree item")
  N_("document spreadsheet")
  N_("document presentation")
  N_("document text")
  N_("document web")
  N_("document email")
  N_("comment")
  N_("list box")
  N_("grouping")
  N_("image map")
  N_("notification")
  N_("info bar")
199 200
  N_("level bar")
  N_("title bar")
201
  N_("block quote")
202 203
  N_("audio")
  N_("video")
204 205 206 207 208 209 210 211 212 213 214
  N_("definition")
  N_("article")
  N_("landmark")
  N_("log")
  N_("marquee")
  N_("math")
  N_("rating")
  N_("timer")
  N_("description list")
  N_("description term")
  N_("description value")
215 216
#endif /* 0 */

217 218 219 220 221
static void            atk_object_class_init        (AtkObjectClass  *klass);
static void            atk_object_init              (AtkObject       *accessible,
                                                     AtkObjectClass  *klass);
static AtkRelationSet* atk_object_real_ref_relation_set 
                                                    (AtkObject       *accessible);
222 223
static void            atk_object_real_initialize   (AtkObject       *accessible,
                                                     gpointer        data);
224 225 226 227 228 229 230 231 232
static void            atk_object_real_set_property (GObject         *object,
                                                     guint            prop_id,
                                                     const GValue    *value,
                                                     GParamSpec      *pspec);
static void            atk_object_real_get_property (GObject         *object,
                                                     guint            prop_id,
                                                     GValue          *value,
                                                     GParamSpec      *pspec);
static void            atk_object_finalize          (GObject         *object);
233 234
static const gchar*    atk_object_real_get_name     (AtkObject       *object);
static const gchar*    atk_object_real_get_description
235 236 237
                                                   (AtkObject       *object);
static AtkObject*      atk_object_real_get_parent  (AtkObject       *object);
static AtkRole         atk_object_real_get_role    (AtkObject       *object);
238
static AtkLayer        atk_object_real_get_layer   (AtkObject       *object);
239 240
static AtkStateSet*    atk_object_real_ref_state_set
                                                   (AtkObject       *object);
241 242 243 244 245 246 247
static void            atk_object_real_set_name    (AtkObject       *object,
                                                    const gchar     *name);
static void            atk_object_real_set_description
                                                   (AtkObject       *object,
                                                    const gchar     *description);
static void            atk_object_real_set_parent  (AtkObject       *object,
                                                    AtkObject       *parent);
248 249
static void            atk_object_real_set_role    (AtkObject       *object,
                                                    AtkRole         role);
250 251
static void            atk_object_notify           (GObject         *obj,
                                                    GParamSpec      *pspec);
252 253
static const gchar*    atk_object_real_get_object_locale
                                                   (AtkObject       *object);
Bill Haneman's avatar
Bill Haneman committed
254 255 256 257 258

static guint atk_object_signals[LAST_SIGNAL] = { 0, };

static gpointer parent_class = NULL;

259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
static const gchar* const atk_object_name_property_name = "accessible-name";
static const gchar* const atk_object_name_property_description = "accessible-description";
static const gchar* const atk_object_name_property_parent = "accessible-parent";
static const gchar* const atk_object_name_property_value = "accessible-value";
static const gchar* const atk_object_name_property_role = "accessible-role";
static const gchar* const atk_object_name_property_component_layer = "accessible-component-layer";
static const gchar* const atk_object_name_property_component_mdi_zorder = "accessible-component-mdi-zorder";
static const gchar* const atk_object_name_property_table_caption = "accessible-table-caption";
static const gchar* const atk_object_name_property_table_column_description = "accessible-table-column-description";
static const gchar* const atk_object_name_property_table_column_header = "accessible-table-column-header";
static const gchar* const atk_object_name_property_table_row_description = "accessible-table-row-description";
static const gchar* const atk_object_name_property_table_row_header = "accessible-table-row-header";
static const gchar* const atk_object_name_property_table_summary = "accessible-table-summary";
static const gchar* const atk_object_name_property_table_caption_object = "accessible-table-caption-object";
static const gchar* const atk_object_name_property_hypertext_num_links = "accessible-hypertext-nlinks";
Bill Haneman's avatar
Bill Haneman committed
274

275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
static void
initialize_role_names ()
{
  GTypeClass *enum_class;
  GEnumValue *enum_value;
  int i;
  gchar *role_name = NULL;

  if (role_names)
    return;

  role_names = g_ptr_array_new ();
  enum_class = g_type_class_ref (ATK_TYPE_ROLE);
  if (!G_IS_ENUM_CLASS(enum_class))
    return;

  for (i = 0; i < ATK_ROLE_LAST_DEFINED; i++)
    {
      enum_value = g_enum_get_value (G_ENUM_CLASS (enum_class), i);
      role_name = g_strdup (enum_value->value_nick);
      // We want the role names to be in the format "check button" and not "check-button"
296
      _compact_name (role_name);
297 298 299 300 301 302 303
      g_ptr_array_add (role_names, role_name);
    }

  g_type_class_unref (enum_class);

}

Bill Haneman's avatar
Bill Haneman committed
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
GType
atk_object_get_type (void)
{
  static GType type = 0;

  if (!type)
    {
      static const GTypeInfo typeInfo =
      {
        sizeof (AtkObjectClass),
        (GBaseInitFunc) NULL,
        (GBaseFinalizeFunc) NULL,
        (GClassInitFunc) atk_object_class_init,
        (GClassFinalizeFunc) NULL,
        NULL,
        sizeof (AtkObject),
        0,
        (GInstanceInitFunc) atk_object_init,
      } ;
      type = g_type_register_static (G_TYPE_OBJECT, "AtkObject", &typeInfo, 0) ;
    }
  return type;
}

static void
atk_object_class_init (AtkObjectClass *klass)
{
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);

333
  parent_class = g_type_class_peek_parent (klass);
Bill Haneman's avatar
Bill Haneman committed
334 335 336 337

  gobject_class->set_property = atk_object_real_set_property;
  gobject_class->get_property = atk_object_real_get_property;
  gobject_class->finalize = atk_object_finalize;
338 339 340 341 342 343 344 345
  gobject_class->notify = atk_object_notify;

  klass->get_name = atk_object_real_get_name;
  klass->get_description = atk_object_real_get_description;
  klass->get_parent = atk_object_real_get_parent;
  klass->get_n_children = NULL;
  klass->ref_child = NULL;
  klass->get_index_in_parent = NULL;
346
  klass->ref_relation_set = atk_object_real_ref_relation_set;
347
  klass->get_role = atk_object_real_get_role;
348 349
  klass->get_layer = atk_object_real_get_layer;
  klass->get_mdi_zorder = NULL;
350
  klass->initialize = atk_object_real_initialize;
351
  klass->ref_state_set = atk_object_real_ref_state_set;
352 353 354
  klass->set_name = atk_object_real_set_name;
  klass->set_description = atk_object_real_set_description;
  klass->set_parent = atk_object_real_set_parent;
355
  klass->set_role = atk_object_real_set_role;
356
  klass->get_object_locale = atk_object_real_get_object_locale;
Bill Haneman's avatar
Bill Haneman committed
357

358 359 360
  /*
   * We do not define default signal handlers here
   */
Bill Haneman's avatar
Bill Haneman committed
361
  klass->children_changed = NULL;
362 363
  klass->focus_event = NULL;
  klass->property_change = NULL;
364
  klass->visible_data_changed = NULL;
365
  klass->active_descendant_changed = NULL;
Bill Haneman's avatar
Bill Haneman committed
366

367
  _gettext_initialization ();
368

Bill Haneman's avatar
Bill Haneman committed
369 370 371
  g_object_class_install_property (gobject_class,
                                   PROP_NAME,
                                   g_param_spec_string (atk_object_name_property_name,
372
                                                        _("Accessible Name"),
373
                                                        _("Object instance’s name formatted for assistive technology access"),
Bill Haneman's avatar
Bill Haneman committed
374 375 376 377 378
                                                        NULL,
                                                        G_PARAM_READWRITE));
  g_object_class_install_property (gobject_class,
                                   PROP_DESCRIPTION,
                                   g_param_spec_string (atk_object_name_property_description,
379 380
                                                        _("Accessible Description"),
                                                        _("Description of an object, formatted for assistive technology access"),
Bill Haneman's avatar
Bill Haneman committed
381 382
                                                        NULL,
                                                        G_PARAM_READWRITE));
383 384
  g_object_class_install_property (gobject_class,
                                   PROP_PARENT,
385
                                   g_param_spec_object (atk_object_name_property_parent,
386
                                                        _("Accessible Parent"),
387
                                                        _("Parent of the current accessible as returned by atk_object_get_parent()"),
388 389
                                                        ATK_TYPE_OBJECT,
                                                        G_PARAM_READWRITE));
390 391 392 393 394 395 396 397 398 399

  /**
   * AtkObject:accessible-value:
   *
   * Numeric value of this object, in case being and AtkValue.
   *
   * Deprecated: Since 2.12. Use atk_value_get_value_and_text() to get
   * the value, and value-changed signal to be notified on their value
   * changes.
   */
400 401
  g_object_class_install_property (gobject_class,
                                   PROP_VALUE,
402
                                   g_param_spec_double (atk_object_name_property_value,
403 404
                                                        _("Accessible Value"),
                                                        _("Is used to notify that the value has changed"),
405 406 407
                                                        0.0,
                                                        G_MAXDOUBLE,
                                                        0.0,
408
                                                        G_PARAM_READWRITE));
409 410
  g_object_class_install_property (gobject_class,
                                   PROP_ROLE,
411
                                   g_param_spec_enum   (atk_object_name_property_role,
412 413
                                                        _("Accessible Role"),
                                                        _("The accessible role of this object"),
414
                                                        ATK_TYPE_ROLE,
415
                                                        ATK_ROLE_UNKNOWN,
416
                                                        G_PARAM_READWRITE));
417 418 419
  g_object_class_install_property (gobject_class,
                                   PROP_LAYER,
                                   g_param_spec_int    (atk_object_name_property_component_layer,
420 421
                                                        _("Accessible Layer"),
                                                        _("The accessible layer of this object"),
422 423 424 425 426 427 428
                                                        0,
                                                        G_MAXINT,
                                                        0,
                                                        G_PARAM_READABLE));
  g_object_class_install_property (gobject_class,
                                   PROP_MDI_ZORDER,
                                   g_param_spec_int    (atk_object_name_property_component_mdi_zorder,
429 430
                                                        _("Accessible MDI Value"),
                                                        _("The accessible MDI value of this object"),
431 432 433 434
                                                        G_MININT,
                                                        G_MAXINT,
                                                        G_MININT,
                                                        G_PARAM_READABLE));
435 436 437 438 439 440 441 442

  /**
   * AtkObject:accessible-table-caption:
   *
   * Table caption.
   *
   * Deprecated: Since 1.3. Use table-caption-object instead.
   */
443 444
  g_object_class_install_property (gobject_class,
                                   PROP_TABLE_CAPTION,
445
                                   g_param_spec_string (atk_object_name_property_table_caption,
446 447
                                                        _("Accessible Table Caption"),
                                                        _("Is used to notify that the table caption has changed; this property should not be used. accessible-table-caption-object should be used instead"),
448
                                                        NULL,
449
                                                        G_PARAM_READWRITE));
450 451 452 453 454 455 456 457
  /**
   * AtkObject:accessible-table-column-header:
   *
   * Accessible table column header.
   *
   * Deprecated: Since 2.12. Use atk_table_get_column_header() and
   * atk_table_set_column_header() instead.
   */
458 459 460
  g_object_class_install_property (gobject_class,
                                   PROP_TABLE_COLUMN_HEADER,
                                   g_param_spec_object (atk_object_name_property_table_column_header,
461 462
                                                        _("Accessible Table Column Header"),
                                                        _("Is used to notify that the table column header has changed"),
463 464
                                                        ATK_TYPE_OBJECT,
                                                        G_PARAM_READWRITE));
465 466 467 468 469 470 471 472 473

  /**
   * AtkObject:accessible-table-column-description:
   *
   * Accessible table column description.
   *
   * Deprecated: Since 2.12. Use atk_table_get_column_description()
   * and atk_table_set_column_description() instead.
   */
474 475
  g_object_class_install_property (gobject_class,
                                   PROP_TABLE_COLUMN_DESCRIPTION,
476
                                   g_param_spec_string (atk_object_name_property_table_column_description,
477 478
                                                        _("Accessible Table Column Description"),
                                                        _("Is used to notify that the table column description has changed"),
479
                                                        NULL,
480
                                                        G_PARAM_READWRITE));
481 482 483 484 485 486 487 488 489

  /**
   * AtkObject:accessible-table-row-header:
   *
   * Accessible table row header.
   *
   * Deprecated: Since 2.12. Use atk_table_get_row_header() and
   * atk_table_set_row_header() instead.
   */
490 491 492
  g_object_class_install_property (gobject_class,
                                   PROP_TABLE_ROW_HEADER,
                                   g_param_spec_object (atk_object_name_property_table_row_header,
493 494
                                                        _("Accessible Table Row Header"),
                                                        _("Is used to notify that the table row header has changed"),
495 496
                                                        ATK_TYPE_OBJECT,
                                                        G_PARAM_READWRITE));
497 498 499 500 501 502 503 504
  /**
   * AtkObject:accessible-table-row-description:
   *
   * Accessible table row description.
   *
   * Deprecated: Since 2.12. Use atk_table_get_row_description() and
   * atk_table_set_row_description() instead.
   */
505 506
  g_object_class_install_property (gobject_class,
                                   PROP_TABLE_ROW_DESCRIPTION,
507
                                   g_param_spec_string (atk_object_name_property_table_row_description,
508 509
                                                        _("Accessible Table Row Description"),
                                                        _("Is used to notify that the table row description has changed"),
510
                                                        NULL,
511 512 513 514
                                                        G_PARAM_READWRITE));
  g_object_class_install_property (gobject_class,
                                   PROP_TABLE_SUMMARY,
                                   g_param_spec_object (atk_object_name_property_table_summary,
515 516
                                                        _("Accessible Table Summary"),
                                                        _("Is used to notify that the table summary has changed"),
517 518
                                                        ATK_TYPE_OBJECT,
                                                        G_PARAM_READWRITE));
519 520 521
  g_object_class_install_property (gobject_class,
                                   PROP_TABLE_CAPTION_OBJECT,
                                   g_param_spec_object (atk_object_name_property_table_caption_object,
522 523
                                                        _("Accessible Table Caption Object"),
                                                        _("Is used to notify that the table caption has changed"),
524 525
                                                        ATK_TYPE_OBJECT,
                                                        G_PARAM_READWRITE));
526 527 528
  g_object_class_install_property (gobject_class,
                                   PROP_HYPERTEXT_NUM_LINKS,
                                   g_param_spec_int    (atk_object_name_property_hypertext_num_links,
529
                                                        _("Number of Accessible Hypertext Links"),
530 531 532 533 534
                                                        _("The number of links which the current AtkHypertext has"),
                                                        0,
                                                        G_MAXINT,
                                                        0,
                                                        G_PARAM_READABLE));
535 536 537 538

  /**
   * AtkObject::children-changed:
   * @atkobject: the object which received the signal.
539 540
   * @arg1: The index of the added or removed child. The value can be
   * -1. This is used if the value is not known by the implementor
541
   * when the child is added/removed or irrelevant.
542
   * @arg2: (type AtkObject): A gpointer to the child AtkObject which was added or
543 544 545
   * removed. If the child was removed, it is possible that it is not
   * available for the implementor. In that case this pointer can be
   * NULL.
546 547 548 549 550
   *
   * The signal "children-changed" is emitted when a child is added or
   * removed form an object. It supports two details: "add" and
   * "remove"
   */
551
  atk_object_signals[CHILDREN_CHANGED] =
552 553 554 555 556 557 558
    g_signal_new ("children_changed",
		  G_TYPE_FROM_CLASS (klass),
		  G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
		  G_STRUCT_OFFSET (AtkObjectClass, children_changed),
		  NULL, NULL,
		  g_cclosure_marshal_VOID__UINT_POINTER,
		  G_TYPE_NONE,
559
		  2, G_TYPE_UINT, G_TYPE_POINTER);
560 561 562 563 564 565 566 567 568 569

  /**
   * AtkObject::focus-event:
   * @atkobject: the object which received the signal
   * @arg1: a boolean value which indicates whether the object gained
   * or lost focus.
   *
   * The signal "focus-event" is emitted when an object gained or lost
   * focus.
   *
570
   * Deprecated: 2.9.4: Use the #AtkObject::state-change signal instead.
571
   */
572
  atk_object_signals[FOCUS_EVENT] =
573 574 575 576 577 578 579 580
    g_signal_new ("focus_event",
		  G_TYPE_FROM_CLASS (klass),
		  G_SIGNAL_RUN_LAST,
		  G_STRUCT_OFFSET (AtkObjectClass, focus_event), 
		  NULL, NULL,
		  g_cclosure_marshal_VOID__BOOLEAN,
		  G_TYPE_NONE,
		  1, G_TYPE_BOOLEAN);
581 582 583
  /**
   * AtkObject::property-change:
   * @atkobject: the object which received the signal.
584 585
   * @arg1: (type AtkPropertyValues): an #AtkPropertyValues containing the new
   * value of the property which changed.
586 587
   *
   * The signal "property-change" is emitted when an object's property
588 589 590 591 592 593 594 595 596 597 598 599
   * value changes. @arg1 contains an #AtkPropertyValues with the name
   * and the new value of the property whose value has changed. Note
   * that, as with GObject notify, getting this signal does not
   * guarantee that the value of the property has actually changed; it
   * may also be emitted when the setter of the property is called to
   * reinstate the previous value.
   *
   * Toolkit implementor note: ATK implementors should use
   * g_object_notify() to emit property-changed
   * notifications. #AtkObject::property-changed is needed by the
   * implementation of atk_add_global_event_listener() because GObject
   * notify doesn't support emission hooks.
600
   */
601 602 603
  atk_object_signals[PROPERTY_CHANGE] =
    g_signal_new ("property_change",
                  G_TYPE_FROM_CLASS (klass),
604
                  G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
605 606 607 608 609
                  G_STRUCT_OFFSET (AtkObjectClass, property_change),
                  (GSignalAccumulator) NULL, NULL,
                  g_cclosure_marshal_VOID__POINTER,
                  G_TYPE_NONE, 1,
                  G_TYPE_POINTER);
610 611 612 613 614 615 616 617 618 619 620

  /**
   * AtkObject::state-change:
   * @atkobject: the object which received the signal.
   * @arg1: The name of the state which has changed
   * @arg2: A boolean which indicates whether the state has been set or unset.
   *
   * The "state-change" signal is emitted when an object's state
   * changes.  The detail value identifies the state type which has
   * changed.
   */
621
  atk_object_signals[STATE_CHANGE] =
622 623 624 625 626
    g_signal_new ("state_change",
                  G_TYPE_FROM_CLASS (klass),
                  G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
                  G_STRUCT_OFFSET (AtkObjectClass, state_change),
                  (GSignalAccumulator) NULL, NULL,
627 628 629
                  atk_marshal_VOID__STRING_BOOLEAN,
                  G_TYPE_NONE, 2,
                  G_TYPE_STRING,
630
                  G_TYPE_BOOLEAN);
631 632 633 634 635 636 637 638

  /**
   * AtkObject::visible-data-changed:
   * @atkobject: the object which received the signal.
   *
   * The "visible-data-changed" signal is emitted when the visual
   * appearance of the object changed.
   */
639 640 641 642 643 644 645 646
  atk_object_signals[VISIBLE_DATA_CHANGED] =
    g_signal_new ("visible_data_changed",
                  G_TYPE_FROM_CLASS (klass),
                  G_SIGNAL_RUN_LAST,
                  G_STRUCT_OFFSET (AtkObjectClass, visible_data_changed),
                  (GSignalAccumulator) NULL, NULL,
                  g_cclosure_marshal_VOID__VOID,
                  G_TYPE_NONE, 0);
647 648 649 650

  /**
   * AtkObject::active-descendant-changed:
   * @atkobject: the object which received the signal.
651
   * @arg1: (type AtkObject): the newly focused object.
652 653 654 655 656 657
   *
   * The "active-descendant-changed" signal is emitted by an object
   * which has the state ATK_STATE_MANAGES_DESCENDANTS when the focus
   * object in the object changes. For instance, a table will emit the
   * signal when the cell in the table which has focus changes.
   */
658 659 660 661 662 663 664 665 666
  atk_object_signals[ACTIVE_DESCENDANT_CHANGED] =
    g_signal_new ("active_descendant_changed",
		  G_TYPE_FROM_CLASS (klass),
		  G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
		  G_STRUCT_OFFSET (AtkObjectClass, active_descendant_changed),
		  NULL, NULL,
		  g_cclosure_marshal_VOID__POINTER,
		  G_TYPE_NONE,
		  1, G_TYPE_POINTER);
Bill Haneman's avatar
Bill Haneman committed
667 668 669 670 671 672
}

static void
atk_object_init  (AtkObject        *accessible,
                  AtkObjectClass   *klass)
{
673 674 675
  accessible->name = NULL;
  accessible->description = NULL;
  accessible->accessible_parent = NULL;
676
  accessible->relation_set = atk_relation_set_new();
677
  accessible->role = ATK_ROLE_UNKNOWN;
Bill Haneman's avatar
Bill Haneman committed
678 679
}

680 681
GType
atk_implementor_get_type (void)
Bill Haneman's avatar
Bill Haneman committed
682
{
683 684 685 686 687 688 689 690 691 692 693 694 695 696 697
  static GType type = 0;

  if (!type)
    {
      static const GTypeInfo typeInfo =
      {
        sizeof (AtkImplementorIface),
        (GBaseInitFunc) NULL,
        (GBaseFinalizeFunc) NULL,
      } ;

      type = g_type_register_static (G_TYPE_INTERFACE, "AtkImplementorIface", &typeInfo, 0) ;
    }

  return type;
Bill Haneman's avatar
Bill Haneman committed
698 699
}

700
/**
701
 * atk_object_get_name:
702
 * @accessible: an #AtkObject
703
 *
Brian Cameron's avatar
Brian Cameron committed
704
 * Gets the accessible name of the accessible.
705 706
 *
 * Returns: a character string representing the accessible name of the object.
707
 **/
708
const gchar*
Bill Haneman's avatar
Bill Haneman committed
709 710 711 712 713 714 715 716 717 718 719 720 721
atk_object_get_name (AtkObject *accessible)
{
  AtkObjectClass *klass;

  g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);

  klass = ATK_OBJECT_GET_CLASS (accessible);
  if (klass->get_name)
    return (klass->get_name) (accessible);
  else
    return NULL;
}

722
/**
723
 * atk_object_get_description:
724
 * @accessible: an #AtkObject
725
 *
Brian Cameron's avatar
Brian Cameron committed
726
 * Gets the accessible description of the accessible.
727
 *
728 729
 * Returns: a character string representing the accessible description
 * of the accessible.
730
 *
731
 **/
732
const gchar*
Bill Haneman's avatar
Bill Haneman committed
733 734 735 736 737 738 739 740 741 742 743 744 745
atk_object_get_description (AtkObject *accessible)
{
  AtkObjectClass *klass;

  g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);

  klass = ATK_OBJECT_GET_CLASS (accessible);
  if (klass->get_description)
    return (klass->get_description) (accessible);
  else
    return NULL;
}

746
/**
747
 * atk_object_get_parent:
748
 * @accessible: an #AtkObject
749
 *
750 751 752 753 754
 * Gets the accessible parent of the accessible. By default this is
 * the one assigned with atk_object_set_parent(), but it is assumed
 * that ATK implementors have ways to get the parent of the object
 * without the need of assigning it manually with
 * atk_object_set_parent(), and will return it with this method.
755
 *
756 757 758 759 760
 * If you are only interested on the parent assigned with
 * atk_object_set_parent(), use atk_object_peek_parent().
 *
 * Returns: (transfer none): an #AtkObject representing the accessible
 * parent of the accessible
761
 **/
Bill Haneman's avatar
Bill Haneman committed
762 763 764 765 766 767 768 769 770 771 772 773 774 775
AtkObject*
atk_object_get_parent (AtkObject *accessible)
{
  AtkObjectClass *klass;

  g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);

  klass = ATK_OBJECT_GET_CLASS (accessible);
  if (klass->get_parent)
    return (klass->get_parent) (accessible);
  else
    return NULL;
}

776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796
/**
 * atk_object_peek_parent:
 * @accessible: an #AtkObject
 *
 * Gets the accessible parent of the accessible, if it has been
 * manually assigned with atk_object_set_parent. Otherwise, this
 * function returns %NULL.
 *
 * This method is intended as an utility for ATK implementors, and not
 * to be exposed to accessible tools. See atk_object_get_parent() for
 * further reference.
 *
 * Returns: (transfer none): an #AtkObject representing the accessible
 * parent of the accessible if assigned
 **/
AtkObject*
atk_object_peek_parent (AtkObject *accessible)
{
  return accessible->accessible_parent;
}

797
/**
798
 * atk_object_get_n_accessible_children:
799
 * @accessible: an #AtkObject
800
 *
Brian Cameron's avatar
Brian Cameron committed
801
 * Gets the number of accessible children of the accessible.
802
 *
803 804
 * Returns: an integer representing the number of accessible children
 * of the accessible.
805
 **/
Bill Haneman's avatar
Bill Haneman committed
806 807 808 809 810 811 812 813 814 815 816 817 818 819
gint
atk_object_get_n_accessible_children (AtkObject *accessible)
{
  AtkObjectClass *klass;

  g_return_val_if_fail (ATK_IS_OBJECT (accessible), 0);

  klass = ATK_OBJECT_GET_CLASS (accessible);
  if (klass->get_n_children)
    return (klass->get_n_children) (accessible);
  else
    return 0;
}

820
/**
821
 * atk_object_ref_accessible_child:
822
 * @accessible: an #AtkObject
823 824
 * @i: a gint representing the position of the child, starting from 0
 *
825
 * Gets a reference to the specified accessible child of the object.
826 827
 * The accessible children are 0-based so the first accessible child is
 * at index 0, the second at index 1 and so on.
828
 *
829 830
 * Returns: (transfer full): an #AtkObject representing the specified
 * accessible child of the accessible.
831
 **/
Bill Haneman's avatar
Bill Haneman committed
832 833 834 835 836 837 838 839 840 841 842 843 844 845 846
AtkObject*
atk_object_ref_accessible_child (AtkObject   *accessible,
                                 gint        i)
{
  AtkObjectClass *klass;

  g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);

  klass = ATK_OBJECT_GET_CLASS (accessible);
  if (klass->ref_child)
    return (klass->ref_child) (accessible, i);
  else
    return NULL;
}

847
/**
848
 * atk_object_ref_relation_set:
849
 * @accessible: an #AtkObject
850
 *
Brian Cameron's avatar
Brian Cameron committed
851
 * Gets the #AtkRelationSet associated with the object.
852
 *
853 854
 * Returns: (transfer full): an #AtkRelationSet representing the relation set
 * of the object.
855
 **/
Bill Haneman's avatar
Bill Haneman committed
856
AtkRelationSet*
857
atk_object_ref_relation_set (AtkObject *accessible)
Bill Haneman's avatar
Bill Haneman committed
858 859 860 861 862 863
{
  AtkObjectClass *klass;

  g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);

  klass = ATK_OBJECT_GET_CLASS (accessible);
864 865
  if (klass->ref_relation_set)
    return (klass->ref_relation_set) (accessible);
Bill Haneman's avatar
Bill Haneman committed
866 867 868 869
  else
    return NULL;
}

870
/**
871
 * atk_role_register:
872 873
 * @name: a character string describing the new role.
 *
874 875
 * Registers the role specified by @name. @name must be a meaningful
 * name. So it should not be empty, or consisting on whitespaces.
Brian Cameron's avatar
Brian Cameron committed
876
 *
877 878 879 880
 * Deprecated: Since 2.12. If your application/toolkit doesn't find a
 * suitable role for a specific object defined at #AtkRole, please
 * submit a bug in order to add a new role to the specification.
 *
881 882
 * Returns: an #AtkRole for the new role if added
 * properly. ATK_ROLE_INVALID in case of error.
883
 **/
Bill Haneman's avatar
Bill Haneman committed
884
AtkRole
885
atk_role_register (const gchar *name)
Bill Haneman's avatar
Bill Haneman committed
886
{
887 888 889 890 891 892 893 894 895 896 897 898 899 900
  gboolean valid = FALSE;
  gint i = 0;
  glong length = g_utf8_strlen (name, -1);

  for (i=0; i < length; i++) {
    if (name[i]!=' ') {
      valid = TRUE;
      break;
    }
  }

  if (!valid)
    return ATK_ROLE_INVALID;

901 902
  if (!role_names)
    initialize_role_names ();
903

904 905
  g_ptr_array_add (role_names, g_strdup (name));
  return role_names->len - 1;
Bill Haneman's avatar
Bill Haneman committed
906 907
}

908
/**
909
 * atk_object_get_role:
910
 * @accessible: an #AtkObject
911
 *
Brian Cameron's avatar
Brian Cameron committed
912
 * Gets the role of the accessible.
913
 *
914
 * Returns: an #AtkRole which is the role of the accessible
915
 **/
Bill Haneman's avatar
Bill Haneman committed
916
AtkRole
917 918
atk_object_get_role (AtkObject *accessible) 
{
Bill Haneman's avatar
Bill Haneman committed
919 920 921 922 923 924 925 926 927 928 929
  AtkObjectClass *klass;

  g_return_val_if_fail (ATK_IS_OBJECT (accessible), ATK_ROLE_UNKNOWN);

  klass = ATK_OBJECT_GET_CLASS (accessible);
  if (klass->get_role)
    return (klass->get_role) (accessible);
  else
    return ATK_ROLE_UNKNOWN;
}

930 931 932 933 934 935
/**
 * atk_object_get_layer:
 * @accessible: an #AtkObject
 *
 * Gets the layer of the accessible.
 *
936
 * Deprecated: Use atk_component_get_layer instead.
937 938
 *
 * Returns: an #AtkLayer which is the layer of the accessible
939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960
 **/
AtkLayer
atk_object_get_layer (AtkObject *accessible) 
{
  AtkObjectClass *klass;

  g_return_val_if_fail (ATK_IS_OBJECT (accessible), ATK_LAYER_INVALID);

  klass = ATK_OBJECT_GET_CLASS (accessible);
  if (klass->get_layer)
    return (klass->get_layer) (accessible);
  else
    return ATK_LAYER_INVALID;
}

/**
 * atk_object_get_mdi_zorder:
 * @accessible: an #AtkObject
 *
 * Gets the zorder of the accessible. The value G_MININT will be returned 
 * if the layer of the accessible is not ATK_LAYER_MDI.
 *
961
 * Deprecated: Use atk_component_get_mdi_zorder instead.
962
 *
963 964 965
 * Returns: a gint which is the zorder of the accessible, i.e. the depth at 
 * which the component is shown in relation to other components in the same 
 * container.
966
 *
967 968 969 970 971 972 973 974 975 976 977 978 979 980 981
 **/
gint
atk_object_get_mdi_zorder (AtkObject *accessible) 
{
  AtkObjectClass *klass;

  g_return_val_if_fail (ATK_IS_OBJECT (accessible), G_MININT);

  klass = ATK_OBJECT_GET_CLASS (accessible);
  if (klass->get_mdi_zorder)
    return (klass->get_mdi_zorder) (accessible);
  else
    return G_MININT;
}

982
/**
983
 * atk_object_ref_state_set:
984
 * @accessible: an #AtkObject
985
 *
986 987
 * Gets a reference to the state set of the accessible; the caller must
 * unreference it when it is no longer needed.
988
 *
989
 * Returns: (transfer full): a reference to an #AtkStateSet which is the state
990
 * set of the accessible
991
 **/
992
AtkStateSet*
993 994
atk_object_ref_state_set (AtkObject *accessible) 
{
Bill Haneman's avatar
Bill Haneman committed
995 996
  AtkObjectClass *klass;

997
  g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
Bill Haneman's avatar
Bill Haneman committed
998 999

  klass = ATK_OBJECT_GET_CLASS (accessible);
1000 1001
  if (klass->ref_state_set)
    return (klass->ref_state_set) (accessible);
Bill Haneman's avatar
Bill Haneman committed
1002
  else
1003
    return NULL;
Bill Haneman's avatar
Bill Haneman committed
1004 1005
}

1006
/**
1007
 * atk_object_get_index_in_parent:
1008
 * @accessible: an #AtkObject
1009 1010 1011
 *
 * Gets the 0-based index of this accessible in its parent; returns -1 if the
 * accessible does not have an accessible parent.
1012
 *
1013
 * Returns: an integer which is the index of the accessible in its parent
1014
 **/
Bill Haneman's avatar
Bill Haneman committed
1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028
gint
atk_object_get_index_in_parent (AtkObject *accessible)
{
  AtkObjectClass *klass;

  g_return_val_if_fail (ATK_OBJECT (accessible), -1);

  klass = ATK_OBJECT_GET_CLASS (accessible);
  if (klass->get_index_in_parent)
    return (klass->get_index_in_parent) (accessible);
  else
    return -1;
}

1029
/**
1030
 * atk_object_set_name:
1031
 * @accessible: an #AtkObject
1032
 * @name: a character string to be set as the accessible name
1033
 *
1034 1035 1036 1037
 * Sets the accessible name of the accessible. You can't set the name
 * to NULL. This is reserved for the initial value. In this aspect
 * NULL is similar to ATK_ROLE_UNKNOWN. If you want to set the name to
 * a empty value you can use "".
1038
 **/
Bill Haneman's avatar
Bill Haneman committed
1039 1040 1041 1042 1043
void
atk_object_set_name (AtkObject    *accessible,
                     const gchar  *name)
{
  AtkObjectClass *klass;
1044
  gboolean notify = FALSE;
Bill Haneman's avatar
Bill Haneman committed
1045 1046

  g_return_if_fail (ATK_IS_OBJECT (accessible));
1047
  g_return_if_fail (name != NULL);
Bill Haneman's avatar
Bill Haneman committed
1048 1049 1050

  klass = ATK_OBJECT_GET_CLASS (accessible);
  if (klass->set_name)
1051
    {
1052
      /* Do not notify for initial name setting. See bug 665870 */
1053
      notify = (accessible->name != NULL);
1054

1055
      (klass->set_name) (accessible, name);
1056 1057
      if (notify)
        g_object_notify (G_OBJECT (accessible), atk_object_name_property_name);
1058
    }
Bill Haneman's avatar
Bill Haneman committed
1059 1060
}

1061
/**
1062
 * atk_object_set_description:
1063
 * @accessible: an #AtkObject
1064
 * @description: a character string to be set as the accessible description
1065
 *
1066 1067 1068 1069
 * Sets the accessible description of the accessible. You can't set
 * the description to NULL. This is reserved for the initial value. In
 * this aspect NULL is similar to ATK_ROLE_UNKNOWN. If you want to set
 * the name to a empty value you can use "".
1070
 **/
Bill Haneman's avatar
Bill Haneman committed
1071 1072 1073 1074 1075
void
atk_object_set_description (AtkObject   *accessible,
                            const gchar *description)
{
  AtkObjectClass *klass;
1076
  gboolean notify = FALSE;
Bill Haneman's avatar
Bill Haneman committed
1077 1078

  g_return_if_fail (ATK_IS_OBJECT (accessible));
1079
  g_return_if_fail (description != NULL);
Bill Haneman's avatar
Bill Haneman committed
1080 1081 1082

  klass = ATK_OBJECT_GET_CLASS (accessible);
  if (klass->set_description)
1083
    {
1084 1085 1086
      /* Do not notify for initial name setting. See bug 665870 */
      notify = (accessible->description != NULL);

1087
      (klass->set_description) (accessible, description);
1088 1089 1090
      if (notify)
        g_object_notify (G_OBJECT (accessible),
                         atk_object_name_property_description);
1091
    }
Bill Haneman's avatar
Bill Haneman committed
1092 1093
}

1094
/**
1095
 * atk_object_set_parent:
1096
 * @accessible: an #AtkObject
1097
 * @parent: an #AtkObject to be set as the accessible parent
1098
 *
1099
 * Sets the accessible parent of the accessible. @parent can be NULL.
1100
 **/
Bill Haneman's avatar
Bill Haneman committed
1101 1102 1103 1104 1105 1106 1107 1108 1109 1110
void
atk_object_set_parent (AtkObject *accessible,
                       AtkObject *parent)
{
  AtkObjectClass *klass;

  g_return_if_fail (ATK_IS_OBJECT (accessible));

  klass = ATK_OBJECT_GET_CLASS (accessible);
  if (klass->set_parent)
1111 1112 1113 1114
    {
      (klass->set_parent) (accessible, parent);
      g_object_notify (G_OBJECT (accessible), atk_object_name_property_parent);
    }
Bill Haneman's avatar
Bill Haneman committed
1115 1116
}

1117
/**
1118
 * atk_object_set_role:
1119
 * @accessible: an #AtkObject
1120
 * @role: an #AtkRole to be set as the role
1121
 *
Brian Cameron's avatar
Brian Cameron committed
1122
 * Sets the role of the accessible.
1123
 **/
Bill Haneman's avatar
Bill Haneman committed
1124 1125 1126 1127 1128
void
atk_object_set_role (AtkObject *accessible, 
                     AtkRole   role)
{
  AtkObjectClass *klass;
1129
  AtkRole old_role;
Bill Haneman's avatar
Bill Haneman committed
1130 1131 1132 1133 1134

  g_return_if_fail (ATK_IS_OBJECT (accessible));

  klass = ATK_OBJECT_GET_CLASS (accessible);
  if (klass->set_role)
1135
    {
1136 1137 1138 1139 1140 1141 1142 1143
      old_role = atk_object_get_role (accessible);
      if (old_role != role)
        {
          (klass->set_role) (accessible, role);
          if (old_role != ATK_ROLE_UNKNOWN)
          /* Do not notify for initial role setting */
            g_object_notify (G_OBJECT (accessible), atk_object_name_property_role);
        }
1144
    }
Bill Haneman's avatar
Bill Haneman committed
1145 1146
}

1147
/**
1148
 * atk_object_connect_property_change_handler: (skip)
1149
 * @accessible: an #AtkObject
1150
 * @handler: a function to be called when a property changes its value
1151
 *
1152 1153
 * Deprecated: Since 2.12. Connect directly to property-change or
 * notify signals.
1154
 *
1155 1156
 * Returns: a #guint which is the handler id used in 
 * atk_object_remove_property_change_handler()
1157
 **/
Bill Haneman's avatar
Bill Haneman committed
1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173
guint
atk_object_connect_property_change_handler (AtkObject *accessible,
                                            AtkPropertyChangeHandler *handler)
{
  AtkObjectClass *klass;

  g_return_val_if_fail (ATK_IS_OBJECT (accessible), 0);
  g_return_val_if_fail ((handler != NULL), 0);

  klass = ATK_OBJECT_GET_CLASS (accessible);
  if (klass->connect_property_change_handler)
    return (klass->connect_property_change_handler) (accessible, handler);
  else
    return 0;
}

1174
/**
1175
 * atk_object_remove_property_change_handler:
1176
 * @accessible: an #AtkObject
1177
 * @handler_id: a guint which identifies the handler to be removed.
1178 1179 1180
 *
 * Deprecated: Since 2.12.
 *
1181 1182
 * Removes a property change handler.
 **/
Bill Haneman's avatar
Bill Haneman committed
1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195
void
atk_object_remove_property_change_handler  (AtkObject *accessible,
                                            guint      handler_id)
{
  AtkObjectClass *klass;

  g_return_if_fail (ATK_IS_OBJECT (accessible));

  klass = ATK_OBJECT_GET_CLASS (accessible);
  if (klass->remove_property_change_handler)
    (klass->remove_property_change_handler) (accessible, handler_id);
}

1196 1197 1198 1199
/**
 * atk_object_notify_state_change:
 * @accessible: an #AtkObject
 * @state: an #AtkState whose state is changed
1200
 * @value: a gboolean which indicates whether the state is being set on or off
1201
 * 
1202 1203 1204 1205
 * Emits a state-change signal for the specified state.
 *
 * Note that as a general rule when the state of an existing object changes,
 * emitting a notification is expected.
1206 1207 1208 1209 1210 1211
 **/
void
atk_object_notify_state_change (AtkObject *accessible,
                                AtkState  state,
                                gboolean  value)
{
1212
  const gchar* name;
1213

Li Yuan's avatar
Li Yuan committed
1214 1215
  g_return_if_fail (ATK_IS_OBJECT (accessible));

1216
  name = atk_state_type_get_name (state);
1217
  g_signal_emit (accessible, atk_object_signals[STATE_CHANGE],
1218 1219
                 g_quark_from_string (name),
                 name, value, NULL);
1220 1221
}

Bill Haneman's avatar
Bill Haneman committed
1222
/**
1223
 * atk_implementor_ref_accessible:
1224
 * @implementor: The #GObject instance which should implement #AtkImplementorIface
Bill Haneman's avatar
Bill Haneman committed
1225
 * if a non-null return value is required.
1226
 * 
1227
 * Gets a reference to an object's #AtkObject implementation, if
1228 1229
 * the object implements #AtkObjectIface
 *
1230 1231
 * Returns: (transfer full): a reference to an object's #AtkObject
 * implementation
Bill Haneman's avatar
Bill Haneman committed
1232 1233
 */
AtkObject *
1234
atk_implementor_ref_accessible (AtkImplementor *implementor)
Bill Haneman's avatar
Bill Haneman committed
1235
{
1236 1237 1238
  AtkImplementorIface *iface;
  AtkObject           *accessible = NULL;

1239
  g_return_val_if_fail (ATK_IS_IMPLEMENTOR (implementor), NULL);
Bill Haneman's avatar
Bill Haneman committed
1240

1241
  iface = ATK_IMPLEMENTOR_GET_IFACE (implementor);
Bill Haneman's avatar
Bill Haneman committed
1242

1243
  if (iface != NULL) 
1244
    accessible =  iface->ref_accessible (implementor);
Bill Haneman's avatar
Bill Haneman committed
1245 1246 1247

  g_return_val_if_fail ((accessible != NULL), NULL);

1248
  return accessible;
Bill Haneman's avatar
Bill Haneman committed
1249 1250
}

1251 1252
    	
/**
1253 1254
 * atk_object_get_attributes:
 * @accessible: An #AtkObject.
1255
 *
1256 1257 1258 1259
 * Get a list of properties applied to this object as a whole, as an #AtkAttributeSet consisting of 
 * name-value pairs. As such these attributes may be considered weakly-typed properties or annotations, 
 * as distinct from strongly-typed object data available via other get/set methods.
 * Not all objects have explicit "name-value pair" #AtkAttributeSet properties.
1260
 *
1261
 * Since: 1.12
1262
 *
1263 1264 1265 1266 1267
 * Returns: (transfer full): an #AtkAttributeSet consisting of all
 * explicit properties/annotations applied to the object, or an empty
 * set if the object has no name-value pair attributes assigned to
 * it. This #atkattributeset should be freed by a call to
 * atk_attribute_set_free().
1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283
 */
AtkAttributeSet *
atk_object_get_attributes (AtkObject                  *accessible)
{
  AtkObjectClass *klass;

  g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);

  klass = ATK_OBJECT_GET_CLASS (accessible);
  if (klass->get_attributes)
    return (klass->get_attributes) (accessible); 
  else 
    return NULL;
	
}

1284 1285
static AtkRelationSet*
atk_object_real_ref_relation_set (AtkObject *accessible)
Bill Haneman's avatar
Bill Haneman committed
1286
{
1287 1288
  g_return_val_if_fail (accessible->relation_set, NULL);
  g_object_ref (accessible->relation_set); 
1289 1290

  return accessible->relation_set;
Bill Haneman's avatar
Bill Haneman committed
1291 1292 1293 1294
}

static void
atk_object_real_set_property (GObject      *object,
1295 1296 1297
                              guint         prop_id,
                              const GValue *value,
                              GParamSpec   *pspec)
Bill Haneman's avatar
Bill Haneman committed
1298 1299 1300 1301 1302 1303
{
  AtkObject *accessible;

  accessible = ATK_OBJECT (object);

  switch (prop_id)
1304
    {
Bill Haneman's avatar
Bill Haneman committed
1305 1306 1307 1308 1309 1310
    case PROP_NAME:
      atk_object_set_name (accessible, g_value_get_string (value));
      break;
    case PROP_DESCRIPTION:
      atk_object_set_description (accessible, g_value_get_string (value));
      break;
1311
    case PROP_ROLE:
1312
      atk_object_set_role (accessible, g_value_get_enum (value));
1313 1314 1315
      break;
    case PROP_PARENT:
      atk_object_set_parent (accessible, g_value_get_object (value));
Bill Haneman's avatar
Bill Haneman committed
1316
      break;
1317 1318 1319 1320
    case PROP_VALUE:
      if (ATK_IS_VALUE (accessible))
        atk_value_set_current_value (ATK_VALUE (accessible), value);
      break;
1321 1322 1323 1324 1325 1326 1327 1328
    case PROP_TABLE_SUMMARY:
      if (ATK_IS_TABLE (accessible))
        atk_table_set_summary (ATK_TABLE (accessible), g_value_get_object (value));
      break;
    case PROP_TABLE_CAPTION_OBJECT:
      if (ATK_IS_TABLE (accessible))
        atk_table_set_caption (ATK_TABLE (accessible), g_value_get_object (value));
      break;
Bill Haneman's avatar
Bill Haneman committed
1329 1330
    default:
      break;
1331
    }
Bill Haneman's avatar
Bill Haneman committed
1332 1333 1334 1335
}

static void
atk_object_real_get_property (GObject      *object,
1336 1337 1338
                              guint         prop_id,
                              GValue       *value,
                              GParamSpec   *pspec)
Bill Haneman's avatar
Bill Haneman committed
1339 1340 1341 1342 1343 1344
{
  AtkObject *accessible;

  accessible = ATK_OBJECT (object);

  switch (prop_id)
1345
    {
Bill Haneman's avatar
Bill Haneman committed
1346 1347 1348 1349 1350
    case PROP_NAME:
      g_value_set_string (value, atk_object_get_name (accessible));
      break;
    case PROP_DESCRIPTION:
      g_value_set_string (value, atk_object_get_description (accessible));
Michael Meeks's avatar
Michael Meeks committed
1351
      break;
1352
    case PROP_ROLE:
1353
      g_value_set_enum (value, atk_object_get_role (accessible));
1354
      break;
1355
    case PROP_LAYER:
1356 1357
      if (ATK_IS_COMPONENT (accessible))
        g_value_set_int (value, atk_component_get_layer (ATK_COMPONENT (accessible)));
1358 1359
      break;
    case PROP_MDI_ZORDER:
1360 1361
      if (ATK_IS_COMPONENT (accessible))
        g_value_set_int (value, atk_component_get_mdi_zorder (ATK_COMPONENT (accessible)));
1362
      break;
1363 1364
    case PROP_PARENT:
      g_value_set_object (value, atk_object_get_parent (accessible));
Bill Haneman's avatar
Bill Haneman committed
1365
      break;
1366 1367 1368 1369
    case PROP_VALUE:
      if (ATK_IS_VALUE (accessible))
        atk_value_get_current_value (ATK_VALUE (accessible), value);
      break;
1370 1371 1372 1373 1374 1375 1376 1377
    case PROP_TABLE_SUMMARY:
      if (ATK_IS_TABLE (accessible))
        g_value_set_object (value, atk_table_get_summary (ATK_TABLE (accessible)));
      break;
    case PROP_TABLE_CAPTION_OBJECT:
      if (ATK_IS_TABLE (accessible))
        g_value_set_object (value, atk_table_get_caption (ATK_TABLE (accessible)));
      break;
1378 1379
    case PROP_HYPERTEXT_NUM_LINKS:
      if (ATK_IS_HYPERTEXT (accessible))
1380
        g_value_set_int (value, atk_hypertext_get_n_links (ATK_HYPERTEXT (accessible)));
1381
      break;
Bill Haneman's avatar
Bill Haneman committed
1382
    default:
1383
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
Bill Haneman's avatar
Bill Haneman committed
1384
      break;
1385
    }
Bill Haneman's avatar
Bill Haneman committed
1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400
}

static void
atk_object_finalize (GObject *object)
{
  AtkObject        *accessible;

  g_return_if_fail (ATK_IS_OBJECT (object));

  accessible = ATK_OBJECT (object);

  g_free (accessible->name);
  g_free (accessible->description);

  /*
1401
   * Free memory allocated for relation set if it have been allocated.
Bill Haneman's avatar
Bill Haneman committed
1402
   */
1403 1404
  if (accessible->relation_set)
    g_object_unref (accessible->relation_set);
1405 1406 1407

  if (accessible->accessible_parent)
    g_object_unref (accessible->accessible_parent);
Bill Haneman's avatar
Bill Haneman committed
1408 1409 1410

  G_OBJECT_CLASS (parent_class)->finalize (object);
}
1411

1412
static const gchar*
1413 1414 1415 1416 1417
atk_object_real_get_name (AtkObject *object)
{
  return object->name;
}

1418
static const gchar*
1419 1420 1421 1422 1423 1424 1425 1426
atk_object_real_get_description (AtkObject *object)
{
  return object->description;
}

static AtkObject*
atk_object_real_get_parent (AtkObject       *object)
{
1427
  return atk_object_peek_parent (object);
1428 1429 1430 1431 1432 1433 1434 1435
}

static AtkRole
atk_object_real_get_role (AtkObject       *object)
{
  return object->role;
}

1436 1437 1438 1439 1440 1441
static AtkLayer
atk_object_real_get_layer (AtkObject       *object)
{
  return object->layer;
}

1442 1443 1444 1445
static AtkStateSet*
atk_object_real_ref_state_set (AtkObject *accessible) 
{
  AtkStateSet *state_set;
1446
  AtkObject *focus_object;
1447 1448 1449

  state_set = atk_state_set_new ();

1450 1451 1452
  focus_object = atk_get_focus_object ();
  if (focus_object == accessible)
    atk_state_set_add_state (state_set, ATK_STATE_FOCUSED);
1453

1454 1455 1456
  return state_set; 
}

1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476
static void
atk_object_real_set_name (AtkObject       *object,
                          const gchar     *name)
{
  g_free (object->name);
  object->name = g_strdup (name);
}

static void
atk_object_real_set_description (AtkObject       *object,
                                 const gchar     *description)
{
  g_free (object->description);
  object->description = g_strdup (description);
}

static void
atk_object_real_set_parent (AtkObject       *object,
                            AtkObject       *parent)
{
1477 1478
  if (object->accessible_parent)
    g_object_unref (object->accessible_parent);
1479

1480 1481 1482
  object->accessible_parent = parent;
  if (object->accessible_parent)
    g_object_ref (object->accessible_parent);
1483 1484
}

1485 1486 1487 1488 1489 1490
static void
atk_object_real_set_role (AtkObject *object,
                          AtkRole   role)
{
  object->role = role;
}
1491

1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514
/**
 * atk_object_initialize:
 * @accessible: a #AtkObject
 * @data: a #gpointer which identifies the object for which the AtkObject was created.
 *
 * This function is called when implementing subclasses of #AtkObject.
 * It does initialization required for the new object. It is intended
 * that this function should called only in the ..._new() functions used
 * to create an instance of a subclass of #AtkObject
 **/
void
atk_object_initialize (AtkObject  *accessible,
                       gpointer   data)
{
  AtkObjectClass *klass;

  g_return_if_fail (ATK_IS_OBJECT (accessible));

  klass = ATK_OBJECT_GET_CLASS (accessible);
  if (klass->initialize)
    klass->initialize (accessible, data);
}

1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526
/*
 * This function is a signal handler for notify signal which gets emitted
 * when a property changes value.
 *
 * It constructs an AtkPropertyValues structure and emits a "property_changed"
 * signal which causes the user specified AtkPropertyChangeHandler
 * to be called.
 */
static void
atk_object_notify (GObject     *obj,
                   GParamSpec  *pspec)
{
1527
  AtkPropertyValues values = { NULL, };
1528