Started fixing IDL docs.
[platform/core/uifw/at-spi2-atk.git] / libspi / application.c
index 9d9d93c..e7d1a66 100644 (file)
  * Boston, MA 02111-1307, USA.
  */
 
-/*
- * application.c: implements Application.idl
- *
- */
+/* application.c: implements SpiApplication.idl */
+
 #include <string.h>
 #include <config.h>
-#include <bonobo/Bonobo.h>
 #include <atk/atkutil.h>
-
-/*
- * This pulls the CORBA definitions for the "Accessibility::Accessible" server
- */
-#include <libspi/Accessibility.h>
-
-/*
- * This pulls the definition for the BonoboObject (GObject Type)
- */
-#include "application.h"
+#include <libspi/application.h>
 
 /*
  * Our parent Gtk object type
  */
-#define PARENT_TYPE ACCESSIBLE_TYPE
+#define PARENT_TYPE SPI_ACCESSIBLE_TYPE
 
 /*
  * A pointer to our parent object class
  */
-static AccessibleClass *application_parent_class;
+static SpiAccessibleClass *spi_application_parent_class;
 
-static Application *the_app;
+static SpiApplication *the_app;
 
 /* static methods */
 
@@ -57,48 +45,55 @@ static void notify_listeners (GList *listeners,
                              Accessibility_Event *e,
                              CORBA_Environment *ev);
 
-static char* lookup_toolkit_event_for_name (char *generic_name);
+static char *reverse_lookup_name_for_toolkit_event (char *toolkit_name);
 
-static char* reverse_lookup_name_for_toolkit_event (char *toolkit_name);
+static const char *
+lookup_toolkit_event_for_name (const char *generic_name)
+{
+    char *toolkit_specific_name;
+    SpiApplicationClass *klass = g_type_class_peek (SPI_APPLICATION_TYPE);
+#ifdef SPI_DEBUG
+    fprintf (stderr, "looking for %s in hash table.\n", generic_name);
+#endif
+    toolkit_specific_name =
+           (char *) g_hash_table_lookup (klass->toolkit_event_names, generic_name);
+#ifdef SPI_DEBUG
+    fprintf (stderr, "generic event %s converted to %s\n", generic_name, toolkit_specific_name);
+#endif
+    return toolkit_specific_name;
+}
 
 /*
  * Implemented GObject::finalize
  */
 static void
-accessible_application_finalize (GObject *object)
+spi_accessible_application_finalize (GObject *object)
 {
   /* TODO: any necessary cleanup */
-  (G_OBJECT_CLASS (application_parent_class))->finalize (object);
+  (G_OBJECT_CLASS (spi_application_parent_class))->finalize (object);
 }
 
 static CORBA_string
 impl_accessibility_application_get_toolkit_name (PortableServer_Servant servant,
                                                  CORBA_Environment *ev)
 {
-  CORBA_char *retval;
-  Application *application = APPLICATION (bonobo_object_from_servant (servant));
-  retval = CORBA_string_dup (atk_get_toolkit_name ());
-  return retval;
+       return CORBA_string_dup (atk_get_toolkit_name ());
 }
 
 static CORBA_string
 impl_accessibility_application_get_version (PortableServer_Servant servant,
                                             CORBA_Environment *ev)
 {
-  CORBA_char *retval;
-  Application *application = APPLICATION (bonobo_object_from_servant (servant));
-  retval = CORBA_string_dup (atk_get_toolkit_version ());
-  return retval;
+       return CORBA_string_dup (atk_get_toolkit_version ());
 }
 
 static CORBA_long
 impl_accessibility_application_get_id (PortableServer_Servant servant,
                                        CORBA_Environment *ev)
 {
-  CORBA_long retval;
-  Application *application = APPLICATION (bonobo_object_from_servant (servant));
-  retval = (CORBA_long) application->id;
-  return retval;
+       SpiApplication *application = SPI_APPLICATION (
+               bonobo_object_from_servant (servant));
+       return application->id;
 }
 
 static void
@@ -106,14 +101,15 @@ impl_accessibility_application_set_id (PortableServer_Servant servant,
                                        const CORBA_long id,
                                        CORBA_Environment *ev)
 {
-  Application *application = APPLICATION (bonobo_object_from_servant (servant));
-  application->id = id;
+       SpiApplication *application = SPI_APPLICATION (
+               bonobo_object_from_servant (servant));
+       application->id = id;
 }
 
 #define APP_STATIC_BUFF_SZ 64
 
 static gboolean
-application_object_event_listener (GSignalInvocationHint *signal_hint,
+spi_application_object_event_listener (GSignalInvocationHint *signal_hint,
                                   guint n_param_values,
                                   const GValue *param_values,
                                   gpointer data)
@@ -121,10 +117,10 @@ application_object_event_listener (GSignalInvocationHint *signal_hint,
   Accessibility_Event *e = Accessibility_Event__alloc();
   AtkObject *aobject;
   GObject *gobject;
-  Accessible *source;
+  SpiAccessible *source;
   CORBA_Environment ev;
   GSignalQuery signal_query;
-  gchar *name;
+  const gchar *name;
   char sbuf[APP_STATIC_BUFF_SZ];
   char *generic_name;
   
@@ -151,13 +147,14 @@ application_object_event_listener (GSignalInvocationHint *signal_hint,
   }
   else
   {
+    aobject = NULL;
     g_error("received event from non-AtkImplementor");
   }
 
   g_return_val_if_fail (generic_name, FALSE);
   if (generic_name)
     {
-        source = accessible_new (aobject);
+        source = spi_accessible_new (aobject);
        e->type = CORBA_string_dup (generic_name);
        e->source = BONOBO_OBJREF (source);
         /*
@@ -171,7 +168,7 @@ application_object_event_listener (GSignalInvocationHint *signal_hint,
         bonobo_object_release_unref (e->source, &ev); 
     }
   /* and, decrement the refcount on atkobject, incremented moments ago:
-   *  the call to accessible_new() above should have added an extra ref */
+   *  the call to spi_accessible_new() above should have added an extra ref */
   g_object_unref (G_OBJECT (aobject));
 
   return TRUE;
@@ -179,7 +176,7 @@ application_object_event_listener (GSignalInvocationHint *signal_hint,
 
 
 static gboolean
-application_toolkit_event_listener (GSignalInvocationHint *signal_hint,
+spi_application_toolkit_event_listener (GSignalInvocationHint *signal_hint,
                                    guint n_param_values,
                                    const GValue *param_values,
                                    gpointer data)
@@ -187,10 +184,10 @@ application_toolkit_event_listener (GSignalInvocationHint *signal_hint,
   Accessibility_Event *e = Accessibility_Event__alloc();
   AtkObject *aobject;
   GObject *gobject;
-  Accessible *source;
+  SpiAccessible *source;
   CORBA_Environment ev;
   GSignalQuery signal_query;
-  gchar *name;
+  const char *name;
   char sbuf[APP_STATIC_BUFF_SZ];
 
   g_signal_query (signal_hint->signal_id, &signal_query);
@@ -205,13 +202,13 @@ application_toolkit_event_listener (GSignalInvocationHint *signal_hint,
   if (ATK_IS_IMPLEMENTOR (gobject))
     {
       aobject = atk_implementor_ref_accessible (ATK_IMPLEMENTOR (gobject));
-      source = accessible_new (aobject);
+      source = spi_accessible_new (aobject);
       e->type = CORBA_string_dup (sbuf);
       e->source = BONOBO_OBJREF (source);
       e->detail1 = 0;
       e->detail2 = 0;
       if (the_app) notify_listeners (the_app->toolkit_listeners, e, &ev);
-      bonobo_object_unref (source);
+      bonobo_object_unref (BONOBO_OBJECT (source));
       g_object_unref (G_OBJECT (aobject));
     }
   return TRUE;
@@ -223,14 +220,14 @@ impl_accessibility_application_register_toolkit_event_listener (PortableServer_S
                                                                 const CORBA_char *event_name,
                                                                 CORBA_Environment *ev)
 {
-  guint listener_id;
-  listener_id =
-     atk_add_global_event_listener (application_toolkit_event_listener, event_name);
+  guint spi_listener_id;
+  spi_listener_id =
+     atk_add_global_event_listener (spi_application_toolkit_event_listener, (char *) event_name);
   the_app->toolkit_listeners = g_list_append (the_app->toolkit_listeners,
                                              CORBA_Object_duplicate (listener, ev));
 #ifdef SPI_DEBUG
   fprintf (stderr, "registered %d for toolkit events named: %s\n",
-           listener_id,
+           spi_listener_id,
            event_name);
 #endif
 }
@@ -241,19 +238,20 @@ impl_accessibility_application_register_object_event_listener (PortableServer_Se
                                                               const CORBA_char *event_name,
                                                               CORBA_Environment *ev)
 {
-  guint listener_id;
-  char *toolkit_specific_event_name = lookup_toolkit_event_for_name (event_name);
+  guint spi_listener_id = 0;
+  const char *toolkit_specific_event_name =
+         lookup_toolkit_event_for_name (event_name);
   if (toolkit_specific_event_name)
   {
-    listener_id =
-       atk_add_global_event_listener (application_object_event_listener,
+    spi_listener_id =
+       atk_add_global_event_listener (spi_application_object_event_listener,
                                      CORBA_string_dup (toolkit_specific_event_name));
     the_app->toolkit_listeners = g_list_append (the_app->toolkit_listeners,
                                              CORBA_Object_duplicate (listener, ev));
   }
 #ifdef SPI_DEBUG
   fprintf (stderr, "registered %d for object events named: %s\n",
-           listener_id,
+           spi_listener_id,
            event_name);
 #endif
 }
@@ -278,26 +276,10 @@ notify_listeners (GList *listeners, Accessibility_Event *e, CORBA_Environment *e
 }
 
 static char *
-lookup_toolkit_event_for_name (char *generic_name)
-{
-    char *toolkit_specific_name;
-    ApplicationClass *klass = g_type_class_peek (APPLICATION_TYPE);
-#ifdef SPI_DEBUG
-    fprintf (stderr, "looking for %s in hash table.\n", generic_name);
-#endif
-    toolkit_specific_name =
-           (char *) g_hash_table_lookup (klass->toolkit_event_names, generic_name);
-#ifdef SPI_DEBUG
-    fprintf (stderr, "generic event %s converted to %s\n", generic_name, toolkit_specific_name);
-#endif
-    return toolkit_specific_name;
-}
-
-static char *
 reverse_lookup_name_for_toolkit_event (char *toolkit_specific_name)
 {
     char *generic_name;
-    ApplicationClass *klass = g_type_class_peek (APPLICATION_TYPE);
+    SpiApplicationClass *klass = g_type_class_peek (SPI_APPLICATION_TYPE);
 #ifdef SPI_DEBUG
     fprintf (stderr, "(reverse lookup) looking for %s in hash table.\n", toolkit_specific_name);
 #endif
@@ -321,19 +303,19 @@ init_toolkit_names (GHashTable **generic_event_names, GHashTable **toolkit_event
                             "Gtk:AtkObject:property-change",
                             "object:property-change");
 #ifdef SPI_DEBUG
-       fprintf (stderr, "inserted selection_changed hash\n");
+       fprintf (stderr, "inserted spi_selection_changed hash\n");
 #endif
 }
 
 static void
-application_class_init (ApplicationClass *klass)
+spi_application_class_init (SpiApplicationClass *klass)
 {
   GObjectClass * object_class = (GObjectClass *) klass;
   POA_Accessibility_Application__epv *epv = &klass->epv;
 
-  application_parent_class = g_type_class_ref (ACCESSIBLE_TYPE);
+  spi_application_parent_class = g_type_class_ref (SPI_ACCESSIBLE_TYPE);
 
-  object_class->finalize = accessible_application_finalize;
+  object_class->finalize = spi_accessible_application_finalize;
 
   epv->_get_toolkitName = impl_accessibility_application_get_toolkit_name;
   epv->_get_version = impl_accessibility_application_get_version;
@@ -344,54 +326,22 @@ application_class_init (ApplicationClass *klass)
 }
 
 static void
-application_init (Application  *application)
+spi_application_init (SpiApplication  *application)
 {
-  ACCESSIBLE (application)->atko = g_object_new (atk_object_get_type(), NULL);
-  application->toolkit_listeners = (GList *) NULL;
+  application->parent.atko = g_object_new (ATK_TYPE_OBJECT, NULL);
+  application->toolkit_listeners = NULL;
   the_app = application;
 }
 
-GType
-application_get_type (void)
-{
-        static GType type = 0;
-
-        if (!type) {
-                static const GTypeInfo tinfo = {
-                        sizeof (ApplicationClass),
-                        (GBaseInitFunc) NULL,
-                        (GBaseFinalizeFunc) NULL,
-                        (GClassInitFunc) application_class_init,
-                        (GClassFinalizeFunc) NULL,
-                        NULL, /* class data */
-                        sizeof (Application),
-                        0, /* n preallocs */
-                        (GInstanceInitFunc) application_init,
-                        NULL /* value table */
-                };
-                /*
-                 * Bonobo_type_unique auto-generates a load of
-                 * CORBA structures for us. All derived types must
-                 * use bonobo_type_unique.
-                 */
-                type = bonobo_type_unique (
-                        PARENT_TYPE,
-                        POA_Accessibility_Application__init,
-                        NULL,
-                        G_STRUCT_OFFSET (ApplicationClass, epv),
-                        &tinfo,
-                        "Application");
-        }
-
-        return type;
-}
+BONOBO_TYPE_FUNC_FULL (SpiApplication,
+                      Accessibility_Application,
+                      PARENT_TYPE, spi_application);
 
-Application *
-application_new (AtkObject *app_root)
+SpiApplication *
+spi_application_new (AtkObject *app_root)
 {
-    Application *retval =
-               APPLICATION (g_object_new (application_get_type (), NULL));
-    ACCESSIBLE (retval)->atko = app_root;
+    SpiApplication *retval = g_object_new (SPI_APPLICATION_TYPE, NULL);
+    retval->parent.atko = app_root;
     g_object_ref (G_OBJECT (app_root));
     return retval;
 }