Proposed changes to ATK



I request permission to make the attached changes to ATK. The purpose of these 
changes is to allow adding accessibility support for widgets (and objects 
derived from GObject) without requiring libgail as a dependency.

Padraig

? atk.diff
? atkgobject.c
? atkgobject.h
? atkobject.c.NEW
? atkobject.h.NEW
? atkregistry.c.NEW
Index: Makefile.am
===================================================================
RCS file: /cvs/gnome/atk/atk/Makefile.am,v
retrieving revision 1.18
diff -u -p -r1.18 Makefile.am
--- Makefile.am	2001/12/07 14:42:21	1.18
+++ Makefile.am	2001/12/14 17:38:34
@@ -36,6 +36,7 @@ libatk_la_SOURCES = 		\
 	atkcomponent.c		\
 	atkdocument.c		\
 	atkeditabletext.c	\
+	atkgobject.c		\
 	atkhyperlink.c		\
 	atkhypertext.c		\
 	atkimage.c		\
@@ -81,6 +82,7 @@ atk_headers = \
         atkcomponent.h		\
         atkdocument.h		\
         atkeditabletext.h	\
+        atkgobject.h		\
         atkhyperlink.h		\
         atkhypertext.h		\
         atknoopobject.h		\
Index: atk.h
===================================================================
RCS file: /cvs/gnome/atk/atk/atk.h,v
retrieving revision 1.6
diff -u -p -r1.6 atk.h
--- atk.h	2001/06/29 14:06:35	1.6
+++ atk.h	2001/12/14 17:38:34
@@ -22,6 +22,7 @@
 #include <atk/atkcomponent.h>
 #include <atk/atkdocument.h>
 #include <atk/atkeditabletext.h>
+#include <atk/atkgobject.h>
 #include <atk/atkhyperlink.h>
 #include <atk/atkhypertext.h>
 #include <atk/atkimage.h>
Index: atkobject.c
===================================================================
RCS file: /cvs/gnome/atk/atk/atkobject.c,v
retrieving revision 1.46
diff -u -p -r1.46 atkobject.c
--- atkobject.c	2001/12/04 17:12:46	1.46
+++ atkobject.c	2001/12/14 17:38:34
@@ -1051,6 +1051,29 @@ atk_object_real_remove_property_change_h
   g_signal_handler_disconnect (obj, handler_id);
 }
 
+/**
+ * atk_object_inititialize:
+ * @atk_obj: 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  *atk_obj,
+                       gpointer   data)
+{
+  AtkObjectClass *klass;
+
+  g_return_if_fail (ATK_IS_OBJECT (atk_obj));
+
+  klass = ATK_OBJECT_GET_CLASS (atk_obj);
+  if (klass->initialize)
+    klass->initialize (atk_obj, data);
+}
+
 /*
  * This function is a signal handler for notify signal which gets emitted
  * when a property changes value.
Index: atkobject.h
===================================================================
RCS file: /cvs/gnome/atk/atk/atkobject.h,v
retrieving revision 1.27
diff -u -p -r1.27 atkobject.h
--- atkobject.h	2001/11/28 09:14:36	1.27
+++ atkobject.h	2001/12/14 17:38:34
@@ -350,6 +350,8 @@ void                      (* remove_prop
                 *accessible,
                                                                   guint
                 handler_id);
+void                      (* initialize)                         (AtkObject                     *accessible,
+                                                                  gpointer                      data);
   /*
    * The signal handler which is executed when there is a change in the
    * children of the object
@@ -442,6 +444,8 @@ void                 atk_object_remove_p
 void                 atk_object_notify_state_change              (AtkObject                      *accessible,
                                                                   AtkState                       state,
                                                                   gboolean                       value);
+void                 atk_object_initialize                       (AtkObject                     *accessible,
+                                                                  gpointer                      data);
                                     
 G_CONST_RETURN gchar* atk_role_get_name      (AtkRole         role);
 AtkRole               atk_role_for_name      (const gchar     *name);
Index: atkobjectfactory.c
===================================================================
RCS file: /cvs/gnome/atk/atk/atkobjectfactory.c,v
retrieving revision 1.5
diff -u -p -r1.5 atkobjectfactory.c
--- atkobjectfactory.c	2001/07/27 08:33:35	1.5
+++ atkobjectfactory.c	2001/12/14 17:38:34
@@ -108,3 +108,32 @@ atk_object_factory_invalidate (AtkObject
   if (klass->invalidate)
      (klass->invalidate) (factory);
 }
+
+/**
+ * atk_object_factory_get_accessible_type:
+ * @factory: an #AtkObjectFactory 
+ *
+ * Gets the GType of the accessible which is created by the factory. 
+ * The value G_TYPE_INVALID is returned if no type if found.
+ * Returns: the type of the accessible which is created by the @factory.
+ **/
+GType
+atk_object_factory_get_accessible_type (AtkObjectFactory *factory)
+{
+  AtkObjectFactoryClass *klass;
+
+  g_return_val_if_fail (ATK_OBJECT_FACTORY (factory), G_TYPE_INVALID);
+
+  g_print ("%s\n", g_type_name (G_OBJECT_TYPE (factory)));
+  klass = ATK_OBJECT_FACTORY_GET_CLASS (factory);
+  if (klass->get_accessible_type)
+{
+  g_print ("At %d in %s\n", __LINE__, __FILE__);
+     return (klass->get_accessible_type) ();
+}
+  else
+{
+  g_print ("At %d in %s\n", __LINE__, __FILE__);
+     return G_TYPE_INVALID;
+}
+}
Index: atkobjectfactory.h
===================================================================
RCS file: /cvs/gnome/atk/atk/atkobjectfactory.h,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 atkobjectfactory.h
--- atkobjectfactory.h	2001/04/26 14:23:41	1.1.1.1
+++ atkobjectfactory.h	2001/12/14 17:38:34
@@ -48,12 +48,14 @@ struct _AtkObjectFactoryClass
 
   AtkObject* (* create_accessible) (GObject          *obj);
   void       (* invalidate)        (AtkObjectFactory *factory);
+  GType      (* get_accessible_type)    (void);
 };
 
 GType atk_object_factory_get_type();
 
-AtkObject* atk_object_factory_create_accessible(AtkObjectFactory *factory, GObject *obj);
-void       atk_object_factory_invalidate       (AtkObjectFactory *factory);      
+AtkObject* atk_object_factory_create_accessible (AtkObjectFactory *factory, GObject *obj);
+void       atk_object_factory_invalidate (AtkObjectFactory *factory);
+GType      atk_object_factory_get_accessible_type (AtkObjectFactory *factory);
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
/* 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 Library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#ifndef __ATK_GOBJECT_H__
#define __ATK_GOBJECT_H__

#include <atk/atk.h>


#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

/*
 * The AtkGObject class is provided as a basis for implementing
 * accessibility support for objects which are not GTK+ widgets
 */
#define ATK_TYPE_GOBJECT                     (atk_gobject_get_type ())
#define ATK_GOBJECT(obj)                     (G_TYPE_CHECK_INSTANCE_CAST ((obj), ATK_TYPE_GOBJECT, AtkGObject))
#define ATK_GOBJECT_CLASS(klass)             (G_TYPE_CHECK_CLASS_CAST ((klass), ATK_TYPE_GOBJECT, AtkGObjectClass))
#define ATK_IS_GOBJECT(obj)                  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ATK_TYPE_GOBJECT))
#define ATK_IS_GOBJECT_CLASS(klass)          (G_TYPE_CHECK_CLASS_TYPE ((klass), ATK__TYPE_GOBJECT))
#define ATK_GOBJECT_GET_CLASS(obj)           (G_TYPE_INSTANCE_GET_CLASS ((obj), ATK_TYPE_GOBJECT, AtkGObjectClass))

typedef struct _AtkGObject                AtkGObject;
typedef struct _AtkGObjectClass           AtkGObjectClass;

struct _AtkGObject
{
  AtkObject parent;
};

GType atk_gobject_get_type (void);

struct _AtkGObjectClass
{
  AtkObjectClass parent_class;
};

AtkObject *atk_gobject_get_accessible  (GObject           *obj);
GObject   *atk_gobject_get_object      (AtkGObject        *obj);

#ifdef __cplusplus
}
#endif /* __cplusplus */


#endif /* __ATK_GOBJECT_H__ */
/* 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
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include <atk/atkgobject.h>

static void       atk_gobject_class_init               (AtkGObjectClass   *klass);
static void       atk_real_gobject_initialize          (AtkObject         *atk_obj,
                                                        gpointer          data);
static void       atk_gobject_dispose                  (gpointer          data);

static GQuark quark_accessible_object = 0;
static GQuark quark_object = 0;
static AtkObjectClass *parent_class = NULL;

GType
atk_gobject_get_type (void)
{
  static GType type = 0;

  if (!type)
    {
      static const GTypeInfo tinfo =
      {
        sizeof (AtkGObjectClass),
        (GBaseInitFunc) NULL, /* base init */
        (GBaseFinalizeFunc) NULL, /* base finalize */
        (GClassInitFunc) atk_gobject_class_init, /* class init */
        (GClassFinalizeFunc) NULL, /* class finalize */
        NULL, /* class data */
        sizeof (AtkGObject), /* instance size */
        0, /* nb preallocs */
        (GInstanceInitFunc) NULL, /* instance init */
        NULL /* value table */
      };

      type = g_type_register_static (ATK_TYPE_OBJECT,
                                     "AtkGObject", &tinfo, 0);
    }

  return type;
}

AtkObject*
atk_gobject_get_accessible (GObject *obj)
{
  AtkObject* accessible;

  g_return_val_if_fail (G_IS_OBJECT (obj), NULL);
  /* See if we have a cached accessible for this object */

  accessible = g_object_get_qdata (obj,
				   quark_accessible_object);

  if (!accessible)
    {
      AtkObjectFactory *factory;
      AtkRegistry *default_registry;

      default_registry = atk_get_default_registry ();
      factory = atk_registry_get_factory (default_registry, 
                                          G_OBJECT_TYPE (obj));
      accessible = atk_object_factory_create_accessible (factory,
                                                         obj);
      g_object_set_qdata (obj, quark_accessible_object, accessible);
    }
  return accessible;
}

GObject *
atk_gobject_get_object (AtkGObject *obj)
{
  g_return_val_if_fail (ATK_IS_GOBJECT (obj), NULL);

  return g_object_get_qdata (G_OBJECT (obj), quark_object);
}
 
static void
atk_real_gobject_initialize (AtkObject  *atk_obj,
                             gpointer   data)
{
  AtkGObject *atk_gobj;

  atk_gobj = ATK_GOBJECT (atk_obj);

  g_object_set_qdata (G_OBJECT (atk_gobj), quark_object, data);
  atk_obj->layer = ATK_LAYER_WIDGET;

  g_object_weak_ref (data,
                     (GWeakNotify) atk_gobject_dispose,
                     atk_gobj);
}

static void
atk_gobject_dispose (gpointer  data)
{
  g_return_if_fail (ATK_IS_GOBJECT (data));

  g_object_set_qdata (G_OBJECT (data), quark_accessible_object, NULL);
  atk_object_notify_state_change (ATK_OBJECT (data), ATK_STATE_DEFUNCT,
                                  TRUE); 
  g_object_unref (data);
}

static void
atk_gobject_class_init (AtkGObjectClass *klass)
{ 
  AtkObjectClass *class;

  class = ATK_OBJECT_CLASS (klass);

  parent_class = g_type_class_ref (ATK_TYPE_OBJECT);

  class->initialize = atk_real_gobject_initialize;

  quark_accessible_object = g_quark_from_static_string ("accessible-object");
  quark_object = g_quark_from_static_string ("object-for-accessible");
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]