Revert "Revert "Merge remote-tracking branch 'origin/sandbox/mniesluchow/upstream_2_1...
[platform/upstream/atk.git] / atk / atkregistry.c
index d85673e..364d8ba 100644 (file)
  * Boston, MA 02111-1307, USA.
  */
 
+#include "config.h"
+
 #include "atkregistry.h"
 #include "atknoopobjectfactory.h"
 
-static AtkRegistry *default_registry = NULL;;
+/**
+ * SECTION:atkregistry
+ * @Short_description: An object used to store the GType of the
+ * factories used to create an accessible object for an object of a
+ * particular GType.
+ * @Title:AtkRegistry
+ *
+ * The AtkRegistry is normally used to create appropriate ATK "peers"
+ * for user interface components.  Application developers usually need
+ * only interact with the AtkRegistry by associating appropriate ATK
+ * implementation classes with GObject classes via the
+ * atk_registry_set_factory_type call, passing the appropriate GType
+ * for application custom widget classes.
+ */
+
+static AtkRegistry *default_registry = NULL;
 
 static void              atk_registry_init           (AtkRegistry      *instance,
                                                       AtkRegistryClass *klass);
 static void              atk_registry_finalize       (GObject          *instance);
 static void              atk_registry_class_init     (AtkRegistryClass *klass);
+static AtkRegistry*      atk_registry_new            (void);
 
-static AtkRegistry*      atk_registry_new            ();
-static GType           atk_registry_get_factory_type (AtkRegistry      *registry,
-                                                      GType            type);
+static gpointer parent_class = NULL;
 
 GType
 atk_registry_get_type (void)
@@ -61,14 +77,11 @@ atk_registry_get_type (void)
 static void
 atk_registry_class_init (AtkRegistryClass *klass)
 {
-  GObjectClass *object_class;
+  GObjectClass *object_class = (GObjectClass *) klass;
 
-  /* is paranoia appropriate in a class initializer ? */
-  g_return_if_fail (G_IS_OBJECT_CLASS (klass));
+  parent_class = g_type_class_peek_parent (klass);
 
-  object_class = G_OBJECT_CLASS (klass);
   object_class->finalize = atk_registry_finalize;
-  default_registry = atk_registry_new ();
 }
 
 #if 0
@@ -81,51 +94,53 @@ atk_registry_class_finalize (GObjectClass *klass)
 {
   g_return_if_fail (ATK_IS_REGISTRY_CLASS (klass));
 
-  g_free (default_registry);
+  g_object_unref (G_OBJECT (default_registry));
 }
 #endif
 
 static void
 atk_registry_init (AtkRegistry *instance, AtkRegistryClass *klass)
 {
-  instance->factory_type_registry = g_hash_table_new (NULL, NULL);
-  instance->factory_singleton_cache = g_hash_table_new (NULL, NULL);
+  instance->factory_type_registry = g_hash_table_new ((GHashFunc) NULL, 
+                                                      (GEqualFunc) NULL);
+  instance->factory_singleton_cache = g_hash_table_new ((GHashFunc) NULL, 
+                                                        (GEqualFunc) NULL);
 }
 
-static AtkRegistry*
-atk_registry_new ()
+static AtkRegistry *
+atk_registry_new (void)
 {
   GObject *object;
 
   object = g_object_new (ATK_TYPE_REGISTRY, NULL);
 
-  g_return_val_if_fail ((object != NULL), NULL);
   g_return_val_if_fail (ATK_IS_REGISTRY (object), NULL);
 
   return (AtkRegistry *) object;
 }
 
 static void
-atk_registry_finalize (GObject *instance)
+atk_registry_finalize (GObject *object)
 {
-  AtkRegistry *registry;
+  AtkRegistry *registry = ATK_REGISTRY (object);
 
-  g_return_if_fail (ATK_IS_REGISTRY (instance));
-  registry = ATK_REGISTRY (instance);
-  g_free (registry->factory_type_registry);
-  g_free (registry->factory_singleton_cache);
+  g_hash_table_destroy (registry->factory_type_registry);
+  g_hash_table_destroy (registry->factory_singleton_cache);
+
+  G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
 /**
  * atk_registry_set_factory_type:
  * @registry: the #AtkRegistry in which to register the type association
  * @type: an #AtkObject type 
- * @factory_type: an #AtkObjectFactory type to associate with @type
+ * @factory_type: an #AtkObjectFactory type to associate with @type.  Must
+ * implement AtkObject appropriate for @type.
  *
  * Associate an #AtkObjectFactory subclass with a #GType. Note:
  * The associated @factory_type will thereafter be responsible for
  * the creation of new #AtkObject implementations for instances
- * of type @type.
+ * appropriate for @type.
  **/
 void
 atk_registry_set_factory_type (AtkRegistry *registry,
@@ -139,18 +154,18 @@ atk_registry_set_factory_type (AtkRegistry *registry,
   g_return_if_fail (ATK_IS_REGISTRY (registry));
 
   value = g_hash_table_lookup (registry->factory_type_registry, 
-                                  GUINT_TO_POINTER (type));
-  old_type = GPOINTER_TO_UINT (value);
+                                  (gpointer) type);
+  old_type = (GType) value;
   if (old_type && old_type != factory_type)
     {
       g_hash_table_remove (registry->factory_type_registry, 
-                           GUINT_TO_POINTER (type));
+                           (gpointer) type);
       /*
        * If the old factory was created, notify it that it has
        * been replaced, then free it.
        */
       old_factory = g_hash_table_lookup (registry->factory_singleton_cache, 
-                                         GUINT_TO_POINTER (old_type));
+                                         (gpointer) old_type);
       if (old_factory)
         {
           atk_object_factory_invalidate (old_factory);
@@ -158,8 +173,8 @@ atk_registry_set_factory_type (AtkRegistry *registry,
         }
     }
   g_hash_table_insert (registry->factory_type_registry, 
-                       GUINT_TO_POINTER (type)
-                       GUINT_TO_POINTER (factory_type));
+                       (gpointer) type
+                       (gpointer) factory_type);
 }
 
 /**
@@ -169,7 +184,7 @@ atk_registry_set_factory_type (AtkRegistry *registry,
  * subclass
  *
  * Provides a #GType indicating the #AtkObjectFactory subclass
- * associated with type @type
+ * associated with @type.
  *
  * Returns: a #GType associated with type @type
  **/
@@ -188,7 +203,7 @@ atk_registry_get_factory_type (AtkRegistry *registry,
   do {
     value =
         g_hash_table_lookup (registry->factory_type_registry, 
-                             GUINT_TO_POINTER (type));
+                             (gpointer) type);
     type = g_type_parent (type);
     if (type == G_TYPE_INVALID)
       {
@@ -196,7 +211,7 @@ atk_registry_get_factory_type (AtkRegistry *registry,
       }
   } while (value == NULL);
 
-  factory_type = GPOINTER_TO_UINT (value);
+  factory_type = (GType) value;
   return factory_type;
 }
 
@@ -206,10 +221,10 @@ atk_registry_get_factory_type (AtkRegistry *registry,
  * @type: a #GType with which to look up the associated #AtkObjectFactory
  *
  * Gets an #AtkObjectFactory appropriate for creating #AtkObjects
- * of type @type.
+ * appropriate for @type.
  *
- * Returns: an #AtkObjectFactory appropriate for creating #AtkObjects
- * of type @type.
+ * Returns: (transfer none): an #AtkObjectFactory appropriate for creating
+ * #AtkObjects appropriate for @type.
  **/
 AtkObjectFactory*
 atk_registry_get_factory (AtkRegistry *registry,
@@ -234,14 +249,14 @@ atk_registry_get_factory (AtkRegistry *registry,
   /* ask second hashtable for instance of factory type */
   factory_pointer =
         g_hash_table_lookup (registry->factory_singleton_cache, 
-        GUINT_TO_POINTER (factory_type));
+        (gpointer) factory_type);
 
   /* if there isn't one already, create one and save it */
   if (factory_pointer == NULL)
     {
       factory_pointer = g_type_create_instance (factory_type);
       g_hash_table_insert (registry->factory_singleton_cache,
-                           GUINT_TO_POINTER (factory_type),
+                           (gpointer) factory_type,
                            factory_pointer);
     }
 
@@ -249,7 +264,7 @@ atk_registry_get_factory (AtkRegistry *registry,
 }
 
 /**
- *atk_get_default_registry:
+ * atk_get_default_registry:
  *
  * Gets a default implementation of the #AtkObjectFactory/type
  * registry.
@@ -257,17 +272,17 @@ atk_registry_get_factory (AtkRegistry *registry,
  * registry for registering new #AtkObject factories. Following
  * a call to this function, maintainers may call atk_registry_set_factory_type()
  * to associate an #AtkObjectFactory subclass with the GType of objects
- * for whom accessability information will be provided.
+ * for whom accessibility information will be provided.
  *
- * Returns: a default implementation of the #AtkObjectFactory/type
- * registry
+ * Returns: (transfer full): a default implementation of the
+ * #AtkObjectFactory/type registry
  **/
 AtkRegistry*
-atk_get_default_registry ()
+atk_get_default_registry (void)
 {
   if (!default_registry)
-  {
-    default_registry = atk_registry_new();
-  }
+    {
+      default_registry = atk_registry_new ();
+    }
   return default_registry;
 }