#include #include #include #include #include #include #include #include #include static gchar *events[] = { "focus:", "object:text-selection-changed", "object:text-caret-moved", }; static void report_event (const AccessibleEvent *event, void *user_data); static AccessibleEventListener *listener = NULL; int main(int argc, char **argv) { gint i; SPI_init(); listener = SPI_createAccessibleEventListener (report_event, NULL); for (i = 0; i < G_N_ELEMENTS (events); i++) SPI_registerGlobalEventListener (listener, events[i]); SPI_event_main(); SPI_exit (); return 0; } #define STR(X) X ? X : "(none)" static void text_boundary (AccessibleText *text) { struct { AccessibleTextBoundaryType type; gchar *type_text; }boundary[] = { {SPI_TEXT_BOUNDARY_CHAR, "CHAR"}, {SPI_TEXT_BOUNDARY_CURSOR_POS, "CURSOR POS"}, {SPI_TEXT_BOUNDARY_WORD_START, "WORD START"}, {SPI_TEXT_BOUNDARY_WORD_END, "WORD END"}, {SPI_TEXT_BOUNDARY_SENTENCE_START, "SENTENCE START"}, {SPI_TEXT_BOUNDARY_SENTENCE_END, "SENTENCE END"}, {SPI_TEXT_BOUNDARY_LINE_START, "LINE START"}, {SPI_TEXT_BOUNDARY_LINE_END, "LINE END"}, {SPI_TEXT_BOUNDARY_ATTRIBUTE_RANGE, "ATT RANGE"}, }; int i; long int cp, sp, ep; char *str; if (!text) return; cp = AccessibleText_getCaretOffset (text); fprintf (stderr, "\n\tBOUNDARY:"); for (i = 0; i < G_N_ELEMENTS (boundary); i++) { str = AccessibleText_getTextAtOffset (text, cp, boundary[i].type, &sp, &ep); fprintf (stderr, "\n\t\t%s: \trange %ld-%ld\ttext:%s|", boundary[i].type_text, sp, ep, str); SPI_freeString (str); } } static void report_text (Accessible *acc) { AccessibleText *text; if (!acc) return; text = Accessible_getText (acc); if (!text) return; fprintf (stderr, "\nTEXT:"); text_boundary (text); AccessibleText_unref (text); } static void report_event (const AccessibleEvent *event, void *user_data) { Accessible_ref (event->source); report_text (event->source); }