X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=test%2Fsimple-at.c;h=63bec0afbafaf94832a51022ca21f69126e3f947;hb=4653a37c7f84b40047393325fe59ba4e97b9a9a9;hp=94fa106cee73194493d6fc90e364acdcd32ccdc4;hpb=6cf5aca394787ce29eb620a3c2e665a1c74b3a4c;p=platform%2Fcore%2Fuifw%2Fat-spi2-atk.git diff --git a/test/simple-at.c b/test/simple-at.c index 94fa106..63bec0a 100644 --- a/test/simple-at.c +++ b/test/simple-at.c @@ -21,125 +21,275 @@ */ #include +#include +#include #include +#include #include -#include "spi.h" - -static void report_focus_event (void *fp); -static void report_button_press (void *fp); -static boolean report_key_event (void *fp); -static void check_property_change (void *fp); +#include "../util/mag_client.h" +#include "../cspi/spi-private.h" /* A hack for now */ + +#undef 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); +static SPIBoolean report_command_key_event (const AccessibleKeystroke *stroke, void *user_data); +static SPIBoolean report_ordinary_key_event (const AccessibleKeystroke *stroke, void *user_data); static void get_environment_vars (void); static int _festival_init (); -static void _festival_say (const char *text, const char *voice, boolean shutup); +static void _festival_say (const char *text, const char *voice, SPIBoolean shutup); static void _festival_write (const char *buff, int fd); -static boolean use_magnifier = FALSE; -static boolean use_festival = FALSE; -static boolean festival_chatty = FALSE; +#ifdef PRINT_TREE +static void print_accessible_tree (Accessible *accessible, char *prefix); +#endif + +static SPIBoolean use_magnifier = FALSE; +static SPIBoolean use_festival = FALSE; +static SPIBoolean festival_chatty = FALSE; +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 AccessibleKeystrokeListener *key_listener; +static AccessibleEventListener *text_listener; +static AccessibleKeystrokeListener *command_key_listener; +static AccessibleKeystrokeListener *ordinary_key_listener; +static AccessibleKeySet *command_keyset; int -main(int argc, char **argv) +main (int argc, char **argv) { int i, j; int n_desktops; int n_apps; + char *s; Accessible *desktop; Accessible *application; + const char *modules; - if ((argc > 1) && (!strncmp(argv[1],"-h",2))) - { - printf ("Usage: simple-at\n"); - printf ("\tEnvironment variables used:\n\t\tFESTIVAL\n\t\tMAGNIFIER\n\t\tFESTIVAL_CHATTY\n"); - exit(0); - } - - SPI_init(); + if ((argc > 1) && (!strncmp (argv[1], "-h", 2))) + { + printf ("Usage: simple-at\n"); + printf ("\tEnvironment variables used:\n\t\tFESTIVAL\n\t\tMAGNIFIER\n\t\tFESTIVAL_CHATTY\n"); + exit (0); + } - focus_listener = createAccessibleEventListener (report_focus_event); - property_listener = createAccessibleEventListener (check_property_change); - button_listener = createAccessibleEventListener (report_button_press); - registerGlobalEventListener (focus_listener, "focus:"); - registerGlobalEventListener (property_listener, "object:property-change:accessible-selection"); - registerGlobalEventListener (button_listener, "Gtk:GtkWidget:button-press-event"); - n_desktops = getDesktopCount (); + modules = g_getenv ("GTK_MODULES"); + if (!modules || modules [0] == '\0') + { + putenv ("GTK_MODULES="); + } + modules = NULL; + + SPI_init (); + + 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:"); + SPI_registerGlobalEventListener (property_listener, "object:property-change"); +/* :accessible-selection"); */ + SPI_registerGlobalEventListener (property_listener, "object:property-change:accessible-name"); + SPI_registerGlobalEventListener (generic_listener, "object:selection-changed"); + SPI_registerGlobalEventListener (generic_listener, "object:children-changed"); + 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 (button_listener, "Gtk:GtkWidget:button-press-event"); + SPI_registerGlobalEventListener (window_listener, "Gtk:GtkWidget:window-state-event"); + n_desktops = SPI_getDesktopCount (); for (i=0; i 0) + { + AccessibleText_getCharacterExtents (text, 0, &x0, &y0, &w0, &h0, + SPI_COORD_TYPE_SCREEN); + AccessibleText_getCharacterExtents (text, nchars-1, &xN, &yN, &wN, &hN, + SPI_COORD_TYPE_SCREEN); + x = MIN (x0, xN); + width = MAX (x0 + w0, xN + wN) - x; + fprintf (stderr, "Text bounding box: (%ld, %ld) ; (%ld, %ld)\n", + x, y, x+width, y+height); + } + } if (use_magnifier) { - magnifier_set_roi ((short) 0, x, y, width, height); + magnifier_set_roi ((short) 0, x, y, width, height); } } + + if (Accessible_isValue (obj)) + { + AccessibleValue *value = Accessible_getValue (obj); + fprintf (stderr, "Current value = %f, min = %f; max = %f\n", + AccessibleValue_getCurrentValue (value), + AccessibleValue_getMinimumValue (value), + AccessibleValue_getMaximumValue (value)); + } /* if this is a text object, speak the first sentence. */ if (Accessible_isText(obj)) @@ -149,70 +299,155 @@ report_focussed_accessible (Accessible *obj, boolean shutup_previous_speech) long start_offset, end_offset; char *first_sentence = "empty"; text_interface = Accessible_getText (obj); - fprintf (stderr, "isText...%p %p\n", text_interface, (void *)*text_interface); first_sentence = AccessibleText_getTextAtOffset ( text_interface, (long) 0, SPI_TEXT_BOUNDARY_SENTENCE_START, &start_offset, &end_offset); - if (first_sentence) _festival_say(first_sentence, "voice_don_diphone", FALSE); - fprintf (stderr, "done reporting on focussed object\n"); + if (first_sentence && use_festival) + { + _festival_say(first_sentence, "voice_don_diphone", FALSE); + SPI_freeString (first_sentence); + } + len = AccessibleText_getCharacterCount (text_interface); + s = AccessibleText_getText (text_interface, 0, len); + fprintf (stderr, "done reporting on focussed object, text=%s\n", s); } } void -report_focus_event (void *p) +report_focus_event (const AccessibleEvent *event, void *user_data) +{ + char *s; + + g_return_if_fail (event->source != NULL); + s = Accessible_getName (event->source); + if (s) + { + fprintf (stderr, "%s event from %s\n", event->type, s); + SPI_freeString (s); + report_focussed_accessible (event->source, TRUE); + } + Accessible_getParent (event->source); + name_changed = FALSE; +} + +void +report_generic_event (const AccessibleEvent *event, void *user_data) { - AccessibleEvent *ev = (AccessibleEvent *) p; - fprintf (stderr, "%s event from %s\n", ev->type, - Accessible_getName (&ev->source)); - report_focussed_accessible (&ev->source, TRUE); + fprintf (stderr, "%s event received\n", event->type); } void -report_button_press (void *p) +report_window_event (const AccessibleEvent *event, void *user_data) { - AccessibleEvent *ev = (AccessibleEvent *) p; - fprintf (stderr, "%s event from %s\n", ev->type, - Accessible_getName (&ev->source)); - fprintf (stderr, "Object description %s\n", - Accessible_getDescription (&ev->source)); + fprintf (stderr, "%s event received\n", event->type); } +void +report_text_event (const AccessibleEvent *event, void *user_data) +{ + AccessibleText *text = Accessible_getText (event->source); + fprintf (stderr, "%s event received\n", event->type); + if (use_magnifier && strcmp (event->type, "object:text-changed")) + { + long offset = AccessibleText_getCaretOffset (text); + long x, y, w, h; + fprintf (stderr, "offset %d\n", (int) offset); + AccessibleText_getCharacterExtents (text, offset, &x, &y, &w, &h, + SPI_COORD_TYPE_SCREEN); + 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); + } + 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); + _festival_say (new_text, "voice_kal_diphone", FALSE); + SPI_freeString (new_text); + } +} + +void +report_button_press (const AccessibleEvent *event, void *user_data) +{ + char *s; + + g_return_if_fail (event->source != NULL); + + s = Accessible_getName (event->source); + + fprintf (stderr, "%s event from %s\n", event->type, s); + SPI_freeString (s); + s = Accessible_getDescription (event->source); + fprintf (stderr, "Object description %s\n", s); + SPI_freeString (s); +} void -check_property_change (void *p) +check_property_change (const AccessibleEvent *event, void *user_data) { - AccessibleEvent *ev = (AccessibleEvent *) p; - AccessibleSelection *selection = Accessible_getSelection (&ev->source); + AccessibleSelection *selection = Accessible_getSelection (event->source); int n_selections; int i; + char *s; + fprintf (stderr, "property change event!\n"); if (selection) { n_selections = (int) AccessibleSelection_getNSelectedChildren (selection); - fprintf (stderr, "(Property) %s event from %s, %d selected children\n", ev->type, - Accessible_getName (&ev->source), n_selections); + s = Accessible_getName (event->source); + fprintf (stderr, "(Property) %s event from %s, %d selected children\n", + event->type, s, n_selections); + SPI_freeString (s); /* for now, speak entire selection set */ for (i=0; itype, "object:property-change:accessible-name")) + { + name_changed = TRUE; + report_focussed_accessible (event->source, TRUE); + } + else + { + fprintf (stderr, "Property change %s received\n", event->type); + } } static void -simple_at_exit() +simple_at_exit () { - deregisterGlobalEventListenerAll (focus_listener); - deregisterGlobalEventListenerAll (property_listener); - deregisterGlobalEventListenerAll (button_listener); - deregisterAccessibleKeystrokeListener (key_listener, SPI_KEYMASK_ALT ); - - SPI_exit (); + SPI_deregisterGlobalEventListenerAll (focus_listener); + AccessibleEventListener_unref (focus_listener); + + SPI_deregisterGlobalEventListenerAll (property_listener); + AccessibleEventListener_unref (property_listener); + + SPI_deregisterGlobalEventListenerAll (generic_listener); + AccessibleEventListener_unref (generic_listener); + + SPI_deregisterGlobalEventListenerAll (text_listener); + AccessibleEventListener_unref (text_listener); + + SPI_deregisterGlobalEventListenerAll (button_listener); + AccessibleEventListener_unref (button_listener); + + SPI_deregisterAccessibleKeystrokeListener (command_key_listener, SPI_KEYMASK_ALT | SPI_KEYMASK_CONTROL); + AccessibleKeystrokeListener_unref (command_key_listener); + SPI_freeAccessibleKeySet (command_keyset); + + SPI_deregisterAccessibleKeystrokeListener (ordinary_key_listener, SPI_KEYMASK_SHIFTLOCK); + AccessibleKeystrokeListener_unref (ordinary_key_listener); + + SPI_event_quit (); } -static boolean -is_command_key (AccessibleKeyStroke *key) +static SPIBoolean +is_command_key (const AccessibleKeystroke *key) { switch (key->keyID) { @@ -223,29 +458,46 @@ is_command_key (AccessibleKeyStroke *key) case 'M': case 'm': use_magnifier = ! use_magnifier; + fprintf (stderr, "%ssing magnifier\n", use_magnifier ? "U" : "Not u"); return TRUE; case 'F': case 'f': use_festival = ! use_festival; + fprintf (stderr, "%speech output\n", use_festival ? "S" : "No s"); return TRUE; default: return FALSE; } } -static boolean -report_key_event (void *p) +static SPIBoolean +report_command_key_event (const AccessibleKeystroke *key, void *user_data) { - AccessibleKeyStroke *key = (AccessibleKeyStroke *) p; - fprintf(stderr, "KeyEvent %s%c (keycode %d)\n", + fprintf (stderr, "Command KeyEvent %s%c (keycode %d); string=%s; time=%lx\n", (key->modifiers & SPI_KEYMASK_ALT)?"Alt-":"", ((key->modifiers & SPI_KEYMASK_SHIFT)^(key->modifiers & SPI_KEYMASK_SHIFTLOCK))? (char) toupper((int) key->keyID) : (char) tolower((int) key->keyID), - (int) key->keycode); + (int) key->keycode, + key->keystring, + (long int) key->timestamp); return is_command_key (key); } -static int _festival_init () + +static SPIBoolean +report_ordinary_key_event (const AccessibleKeystroke *key, void *user_data) +{ + fprintf (stderr, "Received key event:\tsym %ld\n\tmods %x\n\tcode %d\n\tstring=\'%s\'\n\ttime %lx\n", + (long) key->keyID, + (unsigned int) key->modifiers, + (int) key->keycode, + key->keystring, + (long int) key->timestamp); + return FALSE; +} + +static int +_festival_init () { int fd; struct sockaddr_in name; @@ -269,7 +521,8 @@ static int _festival_init () return fd; } -static void _festival_say (const char *text, const char *voice, boolean shutup) +static void +_festival_say (const char *text, const char *voice, SPIBoolean shutup) { static int fd = 0; gchar *quoted; @@ -314,7 +567,8 @@ static void _festival_say (const char *text, const char *voice, boolean shutup) g_free(quoted); } -static void _festival_write (const gchar *command_string, int fd) +static void +_festival_write (const gchar *command_string, int fd) { fprintf(stderr, command_string); if (fd < 0) {