Add some missing files
[platform/core/uifw/at-spi2-atk.git] / test / simple-at.c
index d35ade7..7da2bb5 100644 (file)
@@ -2,7 +2,8 @@
  * AT-SPI - Assistive Technology Service Provider Interface
  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
  *
- * Copyright 2001 Sun Microsystems Inc.
+ * Copyright 2001, 2002 Sun Microsystems Inc.,
+ * Copyright 2001, 2002 Ximian, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  * Boston, MA 02111-1307, USA.
  */
-
+#include <stdio.h>
+#include <strings.h>
 #include <stdlib.h>
 #include <ctype.h>
 #include <unistd.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <sys/un.h>
-#include "../util/mag_client.h"
+#undef MAGNIFIER_ENABLED
 #include "../cspi/spi-private.h" /* A hack for now */
 
-#undef PRINT_TREE
+#define PRINT_TREE
 
 static void report_focus_event    (const AccessibleEvent *event, void *user_data);
 static void report_generic_event  (const AccessibleEvent *event, void *user_data);
+static void report_window_event  (const AccessibleEvent *event, void *user_data);
 static void report_text_event     (const AccessibleEvent *event, void *user_data);
 static void report_button_press   (const AccessibleEvent *event, void *user_data);
 static void check_property_change (const AccessibleEvent *event, void *user_data);
@@ -40,7 +43,7 @@ static SPIBoolean report_command_key_event  (const AccessibleKeystroke *stroke,
 static SPIBoolean report_ordinary_key_event (const AccessibleKeystroke *stroke, void *user_data);
 static void get_environment_vars (void);
 
-static int _festival_init ();
+static int _festival_init (void);
 static void _festival_say (const char *text, const char *voice, SPIBoolean shutup);
 static void _festival_write (const char *buff, int fd);
 
@@ -48,7 +51,10 @@ static void _festival_write (const char *buff, int fd);
 static void print_accessible_tree (Accessible *accessible, char *prefix);
 #endif
 
+#ifdef MAGNIFIER_ENABLED
 static SPIBoolean use_magnifier = FALSE;
+#endif
+
 static SPIBoolean use_festival = FALSE;
 static SPIBoolean festival_chatty = FALSE;
 static SPIBoolean name_changed = FALSE;
@@ -56,6 +62,7 @@ static SPIBoolean name_changed = FALSE;
 static AccessibleEventListener *focus_listener;
 static AccessibleEventListener *property_listener;
 static AccessibleEventListener *generic_listener;
+static AccessibleEventListener *window_listener;
 static AccessibleEventListener *button_listener;
 static AccessibleEventListener *text_listener;
 static AccessibleKeystrokeListener *command_key_listener;
@@ -92,6 +99,7 @@ main (int argc, char **argv)
   focus_listener = SPI_createAccessibleEventListener (report_focus_event, NULL);
   property_listener = SPI_createAccessibleEventListener (check_property_change, NULL); 
   generic_listener = SPI_createAccessibleEventListener (report_generic_event, NULL); 
+  window_listener = SPI_createAccessibleEventListener (report_window_event, NULL); 
   text_listener = SPI_createAccessibleEventListener (report_text_event, NULL); 
   button_listener = SPI_createAccessibleEventListener (report_button_press, NULL);
   SPI_registerGlobalEventListener (focus_listener, "focus:");
@@ -103,8 +111,10 @@ main (int argc, char **argv)
   SPI_registerGlobalEventListener (generic_listener, "object:visible-data-changed"); 
   SPI_registerGlobalEventListener (generic_listener, "object:text-selection-changed"); 
   SPI_registerGlobalEventListener (text_listener, "object:text-caret-moved"); 
-  SPI_registerGlobalEventListener (generic_listener, "object:text-changed"); 
+  SPI_registerGlobalEventListener (text_listener, "object:text-changed"); 
   SPI_registerGlobalEventListener (button_listener, "Gtk:GtkWidget:button-press-event");
+  SPI_registerGlobalEventListener (window_listener, "window:minimize");
+  SPI_registerGlobalEventListener (window_listener, "window:activate");
   n_desktops = SPI_getDesktopCount ();
 
   for (i=0; i<n_desktops; ++i)
@@ -118,7 +128,7 @@ main (int argc, char **argv)
         {
           application = Accessible_getChildAtIndex (desktop, j);
          s = Accessible_getName (application);
-          fprintf (stderr, "app %d name: %s\n", j, s);
+          fprintf (stderr, "app %d name: %s\n", j, s ? s : "(nil)");
 #ifdef PRINT_TREE
          print_accessible_tree (application, "*");
 #endif
@@ -169,6 +179,7 @@ get_environment_vars (void)
           festival_chatty = TRUE;
        }
     }
+#ifdef MAGNIFIER_ENABLED
   if (g_getenv ("MAGNIFIER"))
     {
       fprintf (stderr, "Using magnifier\n");
@@ -178,6 +189,7 @@ get_environment_vars (void)
     {
       fprintf (stderr, "Not using magnifier\n");
     }
+#endif
 
   if (!use_festival)
     {
@@ -193,8 +205,8 @@ print_accessible_tree (Accessible *accessible, char *prefix)
        int i;
        char *name;
        char *role_name;
-       char *parent_name;
-       char *parent_role;
+       char *parent_name = NULL;
+       char *parent_role = NULL;
        char child_prefix[100];
        Accessible *child;
        Accessible *parent;
@@ -206,15 +218,18 @@ print_accessible_tree (Accessible *accessible, char *prefix)
          {
                parent_name = Accessible_getName (parent);
                parent_role = Accessible_getRoleName (parent);
+               Accessible_unref (parent);
          }
-       Accessible_unref (parent);
        name = Accessible_getName (accessible);
        role_name = Accessible_getRoleName (accessible);
-       fprintf (stdout, "%sAccessible [%s] \"%s\"; parent [%s] %s\n",
-                prefix, role_name, name, parent_role, parent_name);
+       fprintf (stdout, "%sAccessible [%s] \"%s\"; parent [%s] %s.\n",
+                prefix, role_name, name ? name : "(nil)",
+                parent_role ? parent_role : "(nil)",
+                parent_name ? parent_name : "(nil)");
        SPI_freeString (name);
        SPI_freeString (role_name);
        SPI_freeString (parent_name);
+       SPI_freeString (parent_role);
        n_children = Accessible_getChildCount (accessible);
        for (i = 0; i < n_children; ++i)
                {
@@ -273,11 +288,14 @@ report_focussed_accessible (Accessible *obj, SPIBoolean shutup_previous_speech)
                       x, y, x+width, y+height);
            }
        }
+#ifdef MAGNIFIER_ENABLED
       if (use_magnifier) {
        magnifier_set_roi ((short) 0, x, y, width, height);
       }
+#endif
     }
 
+
   if (Accessible_isValue (obj))
     {
       AccessibleValue *value = Accessible_getValue (obj);
@@ -332,10 +350,21 @@ report_generic_event (const AccessibleEvent *event, void *user_data)
 }
 
 void
+report_window_event (const AccessibleEvent *event, void *user_data)
+{
+  fprintf (stderr, "%s event received\n", event->type);
+  if (!strcmp (event->type, "window:activate"))
+  {
+      print_accessible_tree (event->source, "window");
+  }
+}
+
+void
 report_text_event (const AccessibleEvent *event, void *user_data)
 {
   AccessibleText *text = Accessible_getText (event->source);
   fprintf (stderr, "%s event received\n", event->type);
+#ifdef MAGNIFIER_ENABLED
   if (use_magnifier && strcmp (event->type, "object:text-changed"))
     {
       long offset = AccessibleText_getCaretOffset (text);
@@ -346,13 +375,27 @@ report_text_event (const AccessibleEvent *event, void *user_data)
       fprintf (stderr, "new roi %d %d %d %d\n", (int) x, (int) y, (int) w, (int) h);
       magnifier_set_roi ((short) 0, x, y, w, h);
     }
+#endif
   if (!strcmp (event->type, "object:text-changed"))
     {
       long start, end;
-      char *new_text = AccessibleText_getTextAtOffset (text, (long) 0, SPI_TEXT_BOUNDARY_SENTENCE_START, &start, &end);
+      char *new_text = AccessibleText_getTextAtOffset (text, (long) event->detail1, SPI_TEXT_BOUNDARY_WORD_START, &start, &end);
       _festival_say (new_text, "voice_kal_diphone", FALSE);
+      fprintf (stderr, "text changed: %s", new_text ? new_text : "");
       SPI_freeString (new_text);
     }
+  else
+    {
+      long start, end;
+      char *word_text = AccessibleText_getTextAtOffset (text, (long) event->detail1, SPI_TEXT_BOUNDARY_WORD_START, &start, &end);
+      char *sentence_text = AccessibleText_getTextAtOffset (text, (long) event->detail1, SPI_TEXT_BOUNDARY_SENTENCE_START, &start, &end);
+      fprintf (stderr, "text changed: word %s; sentence %s at %ld",
+              (word_text ? word_text : ""),
+              (sentence_text ? sentence_text : ""),
+              event->detail1);
+      if (word_text) SPI_freeString (word_text);
+      if (sentence_text) SPI_freeString (sentence_text);
+    }
 }
 
 void
@@ -409,7 +452,7 @@ check_property_change (const AccessibleEvent *event, void *user_data)
 }
 
 static void
-simple_at_exit ()
+simple_at_exit (void)
 {
   SPI_deregisterGlobalEventListenerAll (focus_listener);
   AccessibleEventListener_unref        (focus_listener);
@@ -445,11 +488,13 @@ is_command_key (const AccessibleKeystroke *key)
     case 'q':
            simple_at_exit(); 
            return TRUE; /* not reached */
+#ifdef MAGNIFIER_ENABLED
     case 'M':
     case 'm':
            use_magnifier = ! use_magnifier;
             fprintf (stderr, "%ssing magnifier\n", use_magnifier ? "U" : "Not u");
            return TRUE;
+#endif
     case 'F':
     case 'f':
            use_festival = ! use_festival;
@@ -487,7 +532,7 @@ report_ordinary_key_event (const AccessibleKeystroke *key, void *user_data)
 }
 
 static int
-_festival_init ()
+_festival_init (void)
 {
   int fd;
   struct sockaddr_in name;