diff options
author | Mark Doffman <mdoff@silver-wind.(none)> | 2008-05-16 16:11:40 +0100 |
---|---|---|
committer | Mark Doffman <mdoff@silver-wind.(none)> | 2008-05-16 16:16:19 +0100 |
commit | ff143bfb6c3ca9e1a7362bd7f9c7c5eba31eb135 (patch) | |
tree | 3661a3149da6031c5a0e74463fdd428738e2bf1b /test | |
parent | 5d01be6ec7d2cb2e662c695bd4c28c50ac3f2dab (diff) | |
download | at-spi2-core-ff143bfb6c3ca9e1a7362bd7f9c7c5eba31eb135.tar.gz |
2008-05-16 Mark Doffman <mark.doffman@codethink.co.uk>
Re-organize the directories. The main purpose of
this change is to remove CORBA code and references
that are no longer used.
* atk-adaptor/
Code here used to live in libspi and atk-bridge.
* droute/
The droute module has been moved from libspi to
its own directory.
* spi-common
Code and definitions common to registryd and
the atk-adaptor. Mostly moved from libspi/dbus.c
and accessible.h.
* cspi/
Removed for the moment. Will have to be
mostly rewritten for D-Bus.
Diffstat (limited to 'test')
-rw-r--r-- | test/Makefile.am | 47 | ||||
-rw-r--r-- | test/accessx-gui.c | 764 | ||||
-rw-r--r-- | test/app.c | 99 | ||||
-rw-r--r-- | test/at.c | 131 | ||||
-rwxr-xr-x | test/demo.csh | 47 | ||||
-rw-r--r-- | test/event-listener-test.c | 646 | ||||
-rw-r--r-- | test/key-listener-test.c | 201 | ||||
-rw-r--r-- | test/keypad-test.c | 186 | ||||
-rw-r--r-- | test/keysynth-demo.c | 511 | ||||
-rw-r--r-- | test/keysynth-test.c | 67 | ||||
-rw-r--r-- | test/login-helper-client-test.c | 216 | ||||
-rw-r--r-- | test/login-helper-server-test.c | 162 | ||||
-rw-r--r-- | test/screen-review-test.c | 1121 | ||||
-rw-r--r-- | test/simple-at.c | 615 | ||||
-rw-r--r-- | test/stress-test.c | 100 | ||||
-rw-r--r-- | test/test-simple.c | 815 | ||||
-rwxr-xr-x | test/visual-bell.c | 145 | ||||
-rw-r--r-- | test/window-listener-test.c | 86 |
18 files changed, 0 insertions, 5959 deletions
diff --git a/test/Makefile.am b/test/Makefile.am deleted file mode 100644 index fad3d4cd..00000000 --- a/test/Makefile.am +++ /dev/null @@ -1,47 +0,0 @@ -NULL= - -noinst_PROGRAMS = test-simple at app simple-at stress-test keysynth-demo key-listener-test event-listener-test window-listener-test screen-review-test keypad-test keysynth-test login-helper-client-test login-helper-server-test - -login_helper_client_test_SOURCES = login-helper-client-test.c - -login_helper_server_test_SOURCES = login-helper-server-test.c - -keysynth_test_SOURCES = keysynth-test.c - -stress_test_SOURCES = stress-test.c - -window_listener_test_SOURCES = window-listener-test.c - -keypad_test_SOURCES = keypad-test.c - -key_listener_test_SOURCES = key-listener-test.c - -event_listener_test_SOURCES = event-listener-test.c - -screen_review_test_SOURCES = screen-review-test.c - -at_SOURCES = at.c - -app_SOURCES = app.c - -simple_at_SOURCES = simple-at.c - -keysynth_demo_SOURCES = keysynth-demo.c - -test_simple_SOURCES = test-simple.c - -DEBUG_CFLAGS=-DSPI_DEBUG - -INCLUDES = -I$(top_srcdir) \ - -I$(top_builddir) \ - $(TESTS_CFLAGS) \ - $(DEBUG_CFLAGS) - -LDADD = ../libspi/libspi.la ../cspi/libcspi.la ../login-helper/libloginhelper.la $(TESTS_LIBS) $(X_LIBS) $(XINPUT_LIBS) - -TESTS = test-simple - -TESTS_ENVIRONMENT = \ - LD_LIBRARY_PATH=$(top_builddir)/libspi/.libs/:$(top_builddir)/cspi/.libs/ \ - PATH=$(top_builddir)/registryd/.libs/:$(PATH) - diff --git a/test/accessx-gui.c b/test/accessx-gui.c deleted file mode 100644 index 1ce91f0b..00000000 --- a/test/accessx-gui.c +++ /dev/null @@ -1,764 +0,0 @@ -/* - * AT-SPI - Assistive Technology Service Provider Interface - * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap) - * - * 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 - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <gtk/gtk.h> -#include <gdk/gdkx.h> -#include <X11/XKBlib.h> /* AccessX control defs */ -#include "spi.h" - -#define N_CONTROLS 8 - -static XkbDescPtr xkb; - -typedef struct { - unsigned long mask; - short int *val; - char *label; - char *val_label; -} AccessXControlStruct; - -static void -gui_exit(GtkButton *notused, void *alsonotused) -{ - gtk_exit(0); -} - -static void -toggle_xkb_control (GtkButton *toggle_button, AccessXControlStruct *control_struct) -{ - gboolean is_active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (toggle_button)); - XkbChangeEnabledControls (GDK_DISPLAY(), XkbUseCoreKbd, control_struct->mask, - is_active ? control_struct->mask : 0); -} - -static void -toggle_xkb_notify_control (GtkButton *toggle_button, AccessXControlStruct *control_struct) -{ - gboolean is_active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (toggle_button)); - unsigned short mask, always_off_mask; - XkbChangeEnabledControls (GDK_DISPLAY(), XkbUseCoreKbd, XkbAccessXFeedbackMask | XkbAudibleBellMask, - XkbAccessXFeedbackMask | XkbAudibleBellMask); - - mask = XkbAX_TwoKeysMask | XkbAX_LatchToLockMask | XkbAX_DumbBellFBMask; - always_off_mask = XkbAX_SKPressFBMask | XkbAX_SKReleaseFBMask; - - if (is_active) - xkb->ctrls->ax_options |= (control_struct->mask | mask); - else - xkb->ctrls->ax_options &= (~control_struct->mask); - - xkb->ctrls->ax_options &= ~always_off_mask; - - XkbSetControls (GDK_DISPLAY(), XkbAccessXFeedbackMask, xkb); -} - -static void -toggle_accessx (GtkButton *toggle_button, void *unused) -{ - gboolean is_active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (toggle_button)); - XkbChangeEnabledControls (GDK_DISPLAY(), XkbUseCoreKbd, XkbAllBooleanCtrlsMask, - (is_active) ? xkb->ctrls->enabled_ctrls : 0); -/*if (is_active/) XkbSetControls (GDK_DISPLAY(), XkbAllBooleanCtrlsMask, xkb);*/ -} - -static void -set_accessx_control_value (GtkRange *range_control, AccessXControlStruct *control_struct) -{ - *(control_struct->val) = (short int) gtk_range_get_value (range_control); - XkbSetControls (GDK_DISPLAY(), control_struct->mask, xkb); -} - -static gboolean -init_xkb () -{ - int opcode, xkb_event_code, error, result, major, minor; - Status status; - result = XkbQueryExtension (GDK_DISPLAY(), &opcode, &xkb_event_code, &error, &major, &minor); - if (result != True) return False; - - xkb = XkbGetMap(GDK_DISPLAY(), 0, XkbUseCoreKbd); - if ((int)xkb == BadAlloc || xkb == NULL) - { - return False; - } - else - { - status = XkbGetControls(GDK_DISPLAY(), XkbAllControlsMask, xkb); - if (status != Success) - { - XkbFreeKeyboard(xkb, XkbAllControlsMask, True); - return False; - } - else - { - if (!xkb->ctrls) - { - XkbFreeKeyboard(xkb, XkbAllControlsMask, True); - return False; - } - } - } - - return True; -} - -static AccessXControlStruct * -control_struct_new (unsigned int mask, - short int *val_ptr, - char *label, - char *val_label) -{ - AccessXControlStruct *control = g_new0 (AccessXControlStruct, 1); - control->mask = mask; - control->val = val_ptr; - control->label = label; - control->val_label = val_label; - return control; -} - -static GtkWidget* -basic_toggles_box () -{ - GtkWidget *hbox, *outer_vbox, *vbox, *label, *button, *range, *frame; - GtkAdjustment *adjustment; - AccessXControlStruct *control; - - outer_vbox = gtk_widget_new (GTK_TYPE_VBOX, - "GtkWidget::visible", TRUE, - NULL); - - hbox = gtk_widget_new (GTK_TYPE_HBOX, - "GtkWidget::parent", outer_vbox, - "GtkWidget::visible", TRUE, - NULL); - - button = g_object_connect (gtk_widget_new (GTK_TYPE_CHECK_BUTTON, - "GtkButton::label", "Enable AccessX", - "GtkWidget::parent", hbox, - "GtkWidget::visible", TRUE, - NULL), - "signal::clicked", - toggle_accessx, NULL, - NULL); - -/* FeatureFBMask seems not to work :-( - - control = control_struct_new (XkbAX_FeatureFBMask, &xkb->ctrls->ax_options, NULL, NULL); - - button = g_object_connect (gtk_widget_new (GTK_TYPE_CHECK_BUTTON, - "GtkButton::label", "Notify Changes", - "GtkWidget::parent", hbox, - "GtkWidget::visible", TRUE, - NULL), - "signal::clicked", - toggle_xkb_notify_control, control, - NULL); -*/ - - gtk_widget_new (GTK_TYPE_HSEPARATOR, - "GtkWidget::parent", outer_vbox, - "GtkWidget::visible", TRUE, - NULL); - - hbox = gtk_widget_new (GTK_TYPE_HBOX, - "GtkWidget::parent", outer_vbox, - "GtkWidget::visible", TRUE, - NULL); - - control = control_struct_new (XkbStickyKeysMask, &xkb->ctrls->enabled_ctrls, NULL, NULL); - - button = g_object_connect (gtk_widget_new (GTK_TYPE_CHECK_BUTTON, - "GtkButton::label", "Sticky Keys", - "GtkWidget::parent", hbox, - "GtkWidget::visible", TRUE, - NULL), - "signal::clicked", - toggle_xkb_control, control, - NULL); - - control = control_struct_new (XkbAX_StickyKeysFBMask, &xkb->ctrls->ax_options, NULL, NULL); - - button = g_object_connect (gtk_widget_new (GTK_TYPE_CHECK_BUTTON, - "GtkButton::label", "Beep when Latched", - "GtkWidget::parent", hbox, - "GtkWidget::visible", TRUE, - NULL), - "signal::clicked", - toggle_xkb_notify_control, control, - NULL); - - frame = gtk_widget_new (gtk_frame_get_type(), - "GtkFrame::label", "Slow Keys", - "GtkWidget::parent", outer_vbox, - "GtkWidget::visible", TRUE, - NULL); - - vbox = gtk_widget_new (GTK_TYPE_VBOX, - "GtkWidget::parent", frame, - "GtkWidget::visible", TRUE, - NULL); - - hbox = gtk_widget_new (GTK_TYPE_HBOX, - "GtkWidget::parent", vbox, - "GtkWidget::visible", TRUE, - NULL); - - control = control_struct_new (XkbSlowKeysMask, &xkb->ctrls->slow_keys_delay, NULL, NULL); - - button = g_object_connect (gtk_widget_new (GTK_TYPE_CHECK_BUTTON, - "GtkButton::label", "Enable Slow Keys", - "GtkWidget::parent", hbox, - "GtkWidget::visible", TRUE, - NULL), - "signal::clicked", - toggle_xkb_control, control, - NULL); - - adjustment = GTK_ADJUSTMENT (gtk_adjustment_new (1.0, 1.0, 2000.0, 1.0, 10.0, 1.0 )); - - range = g_object_connect (gtk_widget_new (GTK_TYPE_HSCALE, - "GtkWidget::parent", hbox, - "GtkWidget::visible", TRUE, - "GtkRange::update_policy", GTK_UPDATE_DELAYED, - "GtkScale::digits", 0, - "GtkScale::adjustment", adjustment, - NULL), - "signal::value_changed", - set_accessx_control_value, control, - NULL); - - gtk_widget_set_usize (GTK_WIDGET (range), 150, -1); - - label = gtk_widget_new (GTK_TYPE_LABEL, - "GtkLabel::label", "Delay (mS)", - "GtkWidget::parent", hbox, - "GtkWidget::visible", TRUE, - NULL); - - hbox = gtk_widget_new (GTK_TYPE_HBOX, - "GtkWidget::parent", vbox, - "GtkWidget::visible", TRUE, - NULL); - - control = control_struct_new (XkbAX_SKAcceptFBMask, &xkb->ctrls->ax_options, NULL, NULL); - - button = g_object_connect (gtk_widget_new (GTK_TYPE_CHECK_BUTTON, - "GtkButton::label", "Beep on Accept", - "GtkWidget::parent", hbox, - "GtkWidget::visible", TRUE, - NULL), - "signal::clicked", - toggle_xkb_notify_control, control, - NULL); - - control = control_struct_new (XkbAX_SKRejectFBMask, &xkb->ctrls->ax_options, NULL, NULL); - - button = g_object_connect (gtk_widget_new (GTK_TYPE_CHECK_BUTTON, - "GtkButton::label", "Beep on Reject", - "GtkWidget::parent", hbox, - "GtkWidget::visible", TRUE, - NULL), - "signal::clicked", - toggle_xkb_notify_control, control, - NULL); - - frame = gtk_widget_new (gtk_frame_get_type(), - "GtkFrame::label", "Bounce Keys", - "GtkWidget::parent", outer_vbox, - "GtkWidget::visible", TRUE, - NULL); - - vbox = gtk_widget_new (GTK_TYPE_VBOX, - "GtkWidget::parent", frame, - "GtkWidget::visible", TRUE, - NULL); - - hbox = gtk_widget_new (GTK_TYPE_HBOX, - "GtkWidget::parent", vbox, - "GtkWidget::visible", TRUE, - NULL); - - control = control_struct_new (XkbBounceKeysMask, &xkb->ctrls->debounce_delay, NULL, NULL); - - button = g_object_connect (gtk_widget_new (GTK_TYPE_CHECK_BUTTON, - "GtkButton::label", "Enable Key Debounce", - "GtkWidget::parent", hbox, - "GtkWidget::visible", TRUE, - NULL), - "signal::clicked", - toggle_xkb_control, control, - NULL); - - adjustment = GTK_ADJUSTMENT (gtk_adjustment_new (1.0, 1.0, 2000.0, 1.0, 10.0, 1.0 )); - - range = g_object_connect (gtk_widget_new (GTK_TYPE_HSCALE, - "GtkWidget::parent", hbox, - "GtkWidget::visible", TRUE, - "GtkRange::update_policy", GTK_UPDATE_DELAYED, - "GtkScale::digits", 0, - "GtkScale::adjustment", adjustment, - NULL), - "signal::value_changed", - set_accessx_control_value, control, - NULL); - - gtk_widget_set_usize (GTK_WIDGET (range), 150, -1); - - label = gtk_widget_new (GTK_TYPE_LABEL, - "GtkLabel::label", "Delay (mS)", - "GtkWidget::parent", hbox, - "GtkWidget::visible", TRUE, - NULL); - - hbox = gtk_widget_new (GTK_TYPE_HBOX, - "GtkWidget::parent", vbox, - "GtkWidget::visible", TRUE, - NULL); - - control = control_struct_new (XkbAX_BKRejectFBMask, &xkb->ctrls->ax_options, NULL, NULL); - - button = g_object_connect (gtk_widget_new (GTK_TYPE_CHECK_BUTTON, - "GtkButton::label", "Beep on Reject", - "GtkWidget::parent", hbox, - "GtkWidget::visible", TRUE, - NULL), - "signal::clicked", - toggle_xkb_notify_control, control, - NULL); - - return outer_vbox; -} - -static GtkWidget* -repeat_keys_box () -{ - GtkWidget *outer_hbox, *vbox, *label, *button, *range, *frame; - GtkAdjustment *adjustment; - AccessXControlStruct *control = - control_struct_new (XkbRepeatKeysMask, &xkb->ctrls->repeat_delay, NULL, NULL); - - frame = gtk_widget_new (gtk_frame_get_type(), - "GtkFrame::label","Repeat Keys", - "GtkWidget::visible", TRUE, - NULL); - - outer_hbox = gtk_widget_new (GTK_TYPE_HBOX, - "GtkWidget::visible", TRUE, - "GtkWidget::parent", frame, - NULL); - - button = g_object_connect (gtk_widget_new (GTK_TYPE_CHECK_BUTTON, - "GtkButton::label", "Enable RepeatKeys", - "GtkWidget::parent", outer_hbox, - "GtkWidget::visible", TRUE, - NULL), - "signal::clicked", - toggle_xkb_control, control, - NULL); - - gtk_box_set_child_packing (GTK_BOX (outer_hbox), button, FALSE, FALSE, 0, GTK_PACK_START); - - - vbox = gtk_widget_new (GTK_TYPE_VBOX, - "GtkWidget::visible", TRUE, - "GtkWidget::parent", outer_hbox, - NULL); - - adjustment = GTK_ADJUSTMENT (gtk_adjustment_new (200.0, 200.0, 4000.0, 10.0, 100.0, 10.0 )); - - range = g_object_connect (gtk_widget_new (GTK_TYPE_HSCALE, - "GtkWidget::parent", vbox, - "GtkWidget::visible", TRUE, - "GtkRange::update_policy", GTK_UPDATE_DELAYED, - "GtkScale::digits", 0, - "GtkScale::adjustment", adjustment, - NULL), - "signal::value_changed", - set_accessx_control_value, control, - NULL); - - gtk_widget_set_usize (GTK_WIDGET (range), 150, -1); - - adjustment = GTK_ADJUSTMENT (gtk_adjustment_new (200.0, 40.0, 4000.0, 1.0, 10.0, 1.0 )); - - control = control_struct_new (XkbRepeatKeysMask, &xkb->ctrls->repeat_interval, NULL, NULL); - - range = g_object_connect (gtk_widget_new (GTK_TYPE_HSCALE, - "GtkWidget::parent", vbox, - "GtkWidget::visible", TRUE, - "GtkRange::update_policy", GTK_UPDATE_DELAYED, - "GtkScale::digits", 0, - "GtkScale::adjustment", adjustment, - NULL), - "signal::value_changed", - set_accessx_control_value, control, - NULL); - - gtk_widget_set_usize (GTK_WIDGET (range), 150, -1); - - vbox = gtk_widget_new (GTK_TYPE_VBOX, - "GtkWidget::visible", TRUE, - "GtkWidget::parent", outer_hbox, - NULL); - - label = gtk_widget_new (GTK_TYPE_LABEL, - "GtkLabel::label", "Delay (mS)", - "GtkWidget::parent", vbox, - "GtkWidget::visible", TRUE, - NULL); - - label = gtk_widget_new (GTK_TYPE_LABEL, - "GtkLabel::label", "Interval (mS)", - "GtkWidget::parent", vbox, - "GtkWidget::visible", TRUE, - NULL); - - return frame; -} - -static GtkWidget* -mouse_keys_box () -{ - GtkWidget *outer_hbox, *vbox, *label, *button, *range, *frame; - GtkAdjustment *adjustment; - AccessXControlStruct *control = - control_struct_new (XkbMouseKeysMask, &xkb->ctrls->mk_delay, NULL, NULL); - - frame = gtk_widget_new (gtk_frame_get_type(), - "GtkFrame::label","Mouse Keys", - "GtkWidget::visible", TRUE, - NULL); - - outer_hbox = gtk_widget_new (GTK_TYPE_HBOX, - "GtkWidget::visible", TRUE, - "GtkWidget::parent", frame, - NULL); - - button = g_object_connect (gtk_widget_new (GTK_TYPE_CHECK_BUTTON, - "GtkButton::label", "Enable MouseKeys", - "GtkWidget::parent", outer_hbox, - "GtkWidget::visible", TRUE, - NULL), - "signal::clicked", - toggle_xkb_control, control, - NULL); - - gtk_box_set_child_packing (GTK_BOX (outer_hbox), button, FALSE, FALSE, 0, GTK_PACK_START); - - vbox = gtk_widget_new (GTK_TYPE_VBOX, - "GtkWidget::visible", TRUE, - "GtkWidget::parent", outer_hbox, - NULL); - - adjustment = GTK_ADJUSTMENT (gtk_adjustment_new (200.0, 20.0, 4000.0, 10.0, 100.0, 10.0 )); - - control = control_struct_new (XkbRepeatKeysMask, &xkb->ctrls->mk_interval, NULL, NULL); - - range = g_object_connect (gtk_widget_new (GTK_TYPE_HSCALE, - "GtkWidget::parent", vbox, - "GtkWidget::visible", TRUE, - "GtkRange::update_policy", GTK_UPDATE_DELAYED, - "GtkScale::digits", 0, - "GtkScale::adjustment", adjustment, - NULL), - "signal::value_changed", - set_accessx_control_value, control, - NULL); - - gtk_widget_set_usize (GTK_WIDGET (range), 150, -1); - - adjustment = GTK_ADJUSTMENT (gtk_adjustment_new (800.0, 200.0, 4000.0, 1.0, 10.0, 1.0 )); - - control = control_struct_new (XkbRepeatKeysMask, &xkb->ctrls->mk_time_to_max, NULL, NULL); - - range = g_object_connect (gtk_widget_new (GTK_TYPE_HSCALE, - "GtkWidget::parent", vbox, - "GtkWidget::visible", TRUE, - "GtkRange::update_policy", GTK_UPDATE_DELAYED, - "GtkScale::digits", 0, - "GtkScale::adjustment", adjustment, - NULL), - "signal::value_changed", - set_accessx_control_value, control, - NULL); - - gtk_widget_set_usize (GTK_WIDGET (range), 150, -1); - - adjustment = GTK_ADJUSTMENT (gtk_adjustment_new (800.0, 200.0, 4000.0, 1.0, 10.0, 1.0 )); - - control = control_struct_new (XkbMouseKeysMask, &xkb->ctrls->mk_max_speed, NULL, NULL); - - range = g_object_connect (gtk_widget_new (GTK_TYPE_HSCALE, - "GtkWidget::parent", vbox, - "GtkWidget::visible", TRUE, - "GtkRange::update_policy", GTK_UPDATE_DELAYED, - "GtkScale::digits", 0, - "GtkScale::adjustment", adjustment, - NULL), - "signal::value_changed", - set_accessx_control_value, control, - NULL); - - gtk_widget_set_usize (GTK_WIDGET (range), 150, -1); - - adjustment = GTK_ADJUSTMENT (gtk_adjustment_new (800.0, 200.0, 4000.0, 1.0, 10.0, 1.0 )); - - control = control_struct_new (XkbMouseKeysMask, &xkb->ctrls->mk_curve, NULL, NULL); - - range = g_object_connect (gtk_widget_new (GTK_TYPE_HSCALE, - "GtkWidget::parent", vbox, - "GtkWidget::visible", TRUE, - "GtkRange::update_policy", GTK_UPDATE_DELAYED, - "GtkScale::digits", 0, - "GtkScale::adjustment", adjustment, - NULL), - "signal::value_changed", - set_accessx_control_value, control, - NULL); - - vbox = gtk_widget_new (gtk_vbox_get_type(), - "GtkWidget::name", "MouseKeys", - "GtkWidget::parent", outer_hbox, - "GtkWidget::visible", TRUE, - "GtkContainer::border_width", 5, - NULL); - label = gtk_widget_new (GTK_TYPE_LABEL, - "GtkLabel::label", "Delay (mS)", - "GtkWidget::parent", vbox, - "GtkWidget::visible", TRUE, - NULL); - - label = gtk_widget_new (GTK_TYPE_LABEL, - "GtkLabel::label", "Accel. time (mS)", - "GtkWidget::parent", vbox, - "GtkWidget::visible", TRUE, - NULL); - - label = gtk_widget_new (GTK_TYPE_LABEL, - "GtkLabel::label", "Interval (mS)", - "GtkWidget::parent", vbox, - "GtkWidget::visible", TRUE, - NULL); - - label = gtk_widget_new (GTK_TYPE_LABEL, - "GtkLabel::label", "Max. Speed", - "GtkWidget::parent", vbox, - "GtkWidget::visible", TRUE, - NULL); - - label = gtk_widget_new (GTK_TYPE_LABEL, - "GtkLabel::label", "Curve", - "GtkWidget::parent", vbox, - "GtkWidget::visible", TRUE, - NULL); - return frame; -} - -static GtkWidget* -timeout_box () -{ - GtkWidget *hbox, *label, *button, *range; - GtkAdjustment *adjustment; - AccessXControlStruct *control = - control_struct_new (XkbAccessXTimeoutMask, &xkb->ctrls->ax_timeout, NULL, NULL); - - hbox = gtk_widget_new (gtk_hbox_get_type(), - "GtkWidget::visible", TRUE, - NULL); - - button = g_object_connect (gtk_widget_new (GTK_TYPE_CHECK_BUTTON, - "GtkButton::label", "AccessX Timeout", - "GtkWidget::parent", hbox, - "GtkWidget::visible", TRUE, - NULL), - "signal::clicked", - toggle_xkb_control, control, - NULL); - - adjustment = GTK_ADJUSTMENT (gtk_adjustment_new (1.0, 1.0, 200.0, 1.0, 10.0, 1.0 )); - - range = g_object_connect (gtk_widget_new (GTK_TYPE_HSCALE, - "GtkWidget::parent", hbox, - "GtkWidget::visible", TRUE, - "GtkRange::update_policy", GTK_UPDATE_DELAYED, - "GtkScale::digits", 0, - "GtkScale::adjustment", adjustment, - NULL), - "signal::value_changed", - set_accessx_control_value, control, - NULL); - - gtk_widget_set_usize (GTK_WIDGET (range), 150, -1); - - label = gtk_widget_new (GTK_TYPE_LABEL, - "GtkLabel::label", "AccessX Timeout (Min.)", - "GtkWidget::parent", hbox, - "GtkWidget::visible", TRUE, - NULL); - - return hbox; -} - -static void -create_gui (void) -{ - GtkWidget *window, *button, *container, *hbox; - - window = g_object_connect (gtk_widget_new (gtk_window_get_type (), - "user_data", NULL, - "can_focus", FALSE, - "type", GTK_WINDOW_TOPLEVEL, - "window-position", GTK_WIN_POS_CENTER, - "title", "AccessX", - "allow_grow", TRUE, - "allow_shrink", TRUE, - "border_width", 10, - NULL), - "signal::destroy", gui_exit, NULL, - NULL); - - container = gtk_widget_new (GTK_TYPE_VBOX, - "GtkWidget::parent", window, - "GtkWidget::visible", TRUE, - NULL); - - /* create and add containers for: AccessX on/off, - basic toggles, - MouseKeys support, and timeout */ - - gtk_container_add (GTK_CONTAINER (container), basic_toggles_box ()); - gtk_container_add (GTK_CONTAINER (container), repeat_keys_box ()); -/* gtk_container_add (GTK_CONTAINER (container), mouse_keys_box ()); - gtk_container_add (GTK_CONTAINER (container), timeout_box ());*/ - - hbox = gtk_widget_new (gtk_hbox_get_type(), - "GtkWidget::parent", container, - "GtkWidget::visible", TRUE, - "GtkContainer::border_width", 5, - NULL); - - button = g_object_connect (gtk_widget_new (gtk_button_get_type (), - "GtkButton::label", "Quit", - "GtkWidget::parent", hbox, - "GtkWidget::visible", TRUE, - NULL), - "signal::clicked", - gui_exit, NULL, - NULL); - - gtk_widget_show (window); -} - -static void -create_gui_x (void) -{ - GtkWidget *window, *button, *container, *hbox, *range; - GtkAdjustment *adjustment; - int i; - static AccessXControlStruct* controls[N_CONTROLS]; - controls[0] = control_struct_new (XkbSlowKeysMask, &xkb->ctrls->slow_keys_delay, "Slow Keys", "Delay, mS"); - controls[1] = control_struct_new (XkbStickyKeysMask, &xkb->ctrls->ax_options, "Sticky Keys", NULL); - controls[2] = control_struct_new (XkbBounceKeysMask, &xkb->ctrls->debounce_delay, "Key Debounce", "Delay, mS"); - controls[3] = control_struct_new (XkbRepeatKeysMask, &xkb->ctrls->repeat_delay, "Repeat Keys", "Delay, mS"); - controls[4] = control_struct_new (XkbRepeatKeysMask, &xkb->ctrls->repeat_interval, NULL, "Interval, mS"); - controls[5] = control_struct_new (XkbMouseKeysMask, &xkb->ctrls->mk_delay, "MouseKeys", "Delay, mS"); - controls[6] = control_struct_new (XkbMouseKeysAccelMask, &xkb->ctrls->mk_time_to_max, NULL, "Accel"); - controls[7] = control_struct_new (XkbAccessXTimeoutMask, &xkb->ctrls->ax_timeout, "AccessX timeout", "Sec"); - - hbox = gtk_widget_new (gtk_hbox_get_type(), - "GtkWidget::parent", container, - "GtkWidget::visible", TRUE, - NULL); - - i = 0; /* FIXME: this looks bogus */ - button = g_object_connect (gtk_widget_new (gtk_check_button_get_type (), - "GtkButton::label", "Access X Timeout", - "GtkWidget::parent", hbox, - "GtkWidget::visible", TRUE, - NULL), - "signal::clicked", - toggle_xkb_control, controls[i], - NULL); - - adjustment = GTK_ADJUSTMENT (gtk_adjustment_new (1.0, 1.0, 200.0, 1.0, 10.0, 1.0 )); - - range = g_object_connect (gtk_widget_new (gtk_hscale_get_type (), - "GtkWidget::parent", hbox, - "GtkWidget::visible", TRUE, - "GtkScale::adjustment", adjustment, - NULL), - "signal::value_changed", - set_accessx_control_value, controls[i], - NULL); - - gtk_widget_set_usize (GTK_WIDGET (range), 150, -1); - gtk_widget_new (gtk_label_get_type(), - "GtkWidget::parent", hbox, - "GtkLabel::label", controls[i]->val_label, - "GtkWidget::visible", TRUE, - NULL); - - hbox = gtk_widget_new (gtk_hbox_get_type(), - "GtkWidget::parent", container, - "GtkWidget::visible", TRUE, - "GtkContainer::border_width", 5, - NULL); - - button = g_object_connect (gtk_widget_new (gtk_button_get_type (), - "GtkButton::label", "Quit", - "GtkWidget::parent", hbox, - "GtkWidget::visible", TRUE, - NULL), - "signal::clicked", - gui_exit, NULL, - NULL); - - gtk_widget_show (window); -} - -int -main(int argc, char **argv) -{ - - if ((argc > 1) && (!strncmp(argv[1],"-h",2))) - { - printf ("Usage: keysynth-demo\n"); - exit(0); - } - - gtk_init (&argc, &argv); /* must call, because this program uses GTK+ */ - - if (!init_xkb ()) - { - g_error ("Xkb extension not present, can't initialize accessX\n"); - } - - create_gui (); - - gtk_main (); - - return 0; -} diff --git a/test/app.c b/test/app.c deleted file mode 100644 index 3236b6a7..00000000 --- a/test/app.c +++ /dev/null @@ -1,99 +0,0 @@ -/* - * AT-SPI - Assistive Technology Service Provider Interface - * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap) - * - * 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 - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <stdio.h> -#include <stdlib.h> -#include <libbonobo.h> -#include <bonobo-activation/bonobo-activation.h> -#include <atk/atkobject.h> -#include <libspi/Accessibility.h> -#include <libspi/accessible.h> -#include <libspi/application.h> - -#define APP_STATIC_BUFF_SZ 30 - -int -main(int argc, char **argv) -{ - CORBA_Environment ev; - CORBA_Object oclient; - AtkObject *atko; - char *obj_id; - char sbuf[APP_STATIC_BUFF_SZ]; - - Accessibility_Registry registry; - Accessibility_Event e; - SpiAccessible *accessible; - SpiApplication *app; - - CORBA_exception_init(&ev); - - if (!bonobo_init (&argc, argv)) - { - g_error ("Could not initialize Bonobo"); - } - - /* Create the accesssible application server object */ - g_snprintf(sbuf, APP_STATIC_BUFF_SZ, "application-%s", argv[0]); - - atko = g_object_new (atk_object_get_type(), NULL); - atk_object_set_name (atko, sbuf); - atk_object_set_description( atko, "test application for accessibility SPI"); - app = spi_application_new(atko); - - /* Create the SpiAccessible 'source' for the event */ - accessible = spi_accessible_new (atko); - fprintf(stderr, "accessible created.\n"); - - e.source = bonobo_object_corba_objref ( bonobo_object (accessible)); - e.type = CORBA_string_dup ("focus:"); - - obj_id = "OAFIID:Accessibility_Registry:1.0"; - - oclient = bonobo_activation_activate_from_id (obj_id, 0, NULL, &ev); - if (ev._major != CORBA_NO_EXCEPTION) { - fprintf(stderr, - ("Accessibility app error: exception during registry activation from id: %s\n"), - CORBA_exception_id(&ev)); - CORBA_exception_free(&ev); - exit(-1); - } - - if (CORBA_Object_is_nil (oclient, &ev)) - { - g_error ("Could not locate registry"); - } - - registry = (Accessibility_Registry) oclient; - - Accessibility_Registry_registerApplication (registry, - bonobo_object_corba_objref (bonobo_object (app)), - &ev); - fprintf(stderr, "registerApplication has been called.\n"); - - Accessibility_Registry_notifyEvent (registry, &e, &ev); - fprintf (stderr, "notify event has been called.\n"); - - bonobo_main (); /* needed when app becomes a server ? */ - exit(0); -} diff --git a/test/at.c b/test/at.c deleted file mode 100644 index aa8e8c60..00000000 --- a/test/at.c +++ /dev/null @@ -1,131 +0,0 @@ -/* - * AT-SPI - Assistive Technology Service Provider Interface - * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap) - * - * 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 - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <stdio.h> -#include <stdlib.h> -#include <libbonobo.h> -#include <libspi/Accessibility.h> -#include <libspi/accessible.h> -#include <libspi/listener.h> - -void -check_ev (CORBA_Environment *ev, char *desc) -{ - if (ev->_major != CORBA_NO_EXCEPTION) { - fprintf(stderr, - ("Accessibility app error: exception during CORBA call %s (%s)\n"), - CORBA_exception_id(ev), desc); - CORBA_exception_free(ev); - exit(-1); - } -} - -int -main(int argc, char **argv) -{ - CORBA_Environment ev; - CORBA_Object oclient; - char *obj_id; - CORBA_long i; - CORBA_short n_desktops; - CORBA_long j; - CORBA_long n_apps; - CORBA_string s; - Accessibility_Desktop desktop; - Accessibility_Application app; - Accessibility_Registry registry; - SpiListener *listener; - - CORBA_exception_init(&ev); - - if (!bonobo_init (&argc, argv)) - { - g_error ("Could not initialize Bonobo"); - } - - obj_id = "OAFIID:Accessibility_Registry:1.0"; - - oclient = bonobo_activation_activate_from_id (obj_id, 0, NULL, &ev); - if (ev._major != CORBA_NO_EXCEPTION) { - fprintf(stderr, - ("Accessibility app error: exception during registry activation from id: %s\n"), - CORBA_exception_id(&ev)); - CORBA_exception_free(&ev); - exit(-1); - } - - if (CORBA_Object_is_nil (oclient, &ev)) - { - g_error ("Could not locate registry"); - } - - bonobo_activate (); - - listener = spi_listener_new (); - - registry = (Accessibility_Registry) oclient; - - Accessibility_Registry_registerGlobalEventListener - (registry, - (Accessibility_EventListener) - bonobo_object_corba_objref (bonobo_object (listener)), - "focus:", - &ev); - check_ev (&ev, "register:focus"); - Accessibility_Registry_registerGlobalEventListener - (registry, - (Accessibility_EventListener) - bonobo_object_corba_objref (bonobo_object (listener)), - "Gtk:GtkWidget:button-press-event", - &ev); - check_ev (&ev, "register:button_press"); - fprintf (stderr, "AT callback registered.\n"); - - n_desktops = Accessibility_Registry_getDesktopCount (registry, &ev); - - for (i=0; i<n_desktops; ++i) - { - desktop = Accessibility_Registry_getDesktop (registry, i, &ev); - s = Accessibility_Desktop__get_name (desktop, &ev); - fprintf (stderr, "desktop %d name: %s\n", i, s); - CORBA_free (s); - check_ev (&ev, "desktop:name"); - n_apps = Accessibility_Desktop__get_childCount (desktop, &ev); - check_ev (&ev, "desktop:childCount"); - fprintf (stderr, "desktop has %d apps:\n", n_apps); - for (j=0; j<n_apps; ++j) - { - app = (Accessibility_Application) Accessibility_Desktop_getChildAtIndex (desktop, j, &ev); - check_ev (&ev, "desktop:getChildAtIndex"); - s = Accessibility_Application__get_name (app, &ev); - fprintf (stderr, "app %d name: %s\n", j, s); - CORBA_free (s); - check_ev (&ev, "app:getName"); - } - } - - fprintf (stderr, "finished querying desktop(s).\n"); - bonobo_main (); - /* needed by at because it is a server ? */ - exit(0); -} diff --git a/test/demo.csh b/test/demo.csh deleted file mode 100755 index bc14b3cf..00000000 --- a/test/demo.csh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/csh -echo "This demo requires the festival synthesis system, and modules" -echo "'gail'. It also assumes (for the moment) that the gnome-2.0" -echo "libraries are in /opt/gnome-2.0/lib, gnome-2.0 executables are in" -echo "/opt/gnome-2.0/bin, and that festival is installed in" -echo "/usr/share/festival/festival." -echo "***WARNING*** this demo calls bonobo-slay and pkill, so it" -echo "may kill a number of existing processes/applications on your system." -echo "you are advised to read and edit the file before use." -setenv PATH /opt/gnome-2.0/bin:/bin:/usr/bin:$HOME/gnome/at-spi/test/.libs:/usr/share/festival/festival/bin -setenv LD_LIBRARY_PATH /opt/gnome-2.0/lib -bonobo-slay -pkill festival_server -pkill festival -pkill sleep -pkill magnifier -pkill simple-at -pkill keysynth-demo -unsetenv GTK_MODULES -setenv MAGNIFIER 1 -setenv FESTIVAL 1 -setenv GTK_RC_FILES /opt/gnome-2.0/share/themes/Default/gtk-2.0/gtkrc -# start the text-to-speech service -festival_server & - -# start the simple AT client, which uses the -# MAGNIFIER and FESTIVAL environment variables -simple-at & -sleep 2; keysynth-demo & -# now set GTK_MODULES for use by GTK+ applications -# this will cause the gail accessibility support, -# the ferret test tool, and the atk-bridge to be -# loaded - -setenv GTK_MODULES "gail:ferret:atk-bridge" - -gtk-demo - -# these might be out of place, if gtk-demo backgrounds -# itself - -pkill festival_server -pkill festival -pkill sleep -pkill magnifier -pkill simple-at - diff --git a/test/event-listener-test.c b/test/event-listener-test.c deleted file mode 100644 index 1571d400..00000000 --- a/test/event-listener-test.c +++ /dev/null @@ -1,646 +0,0 @@ -/* - * AT-SPI - Assistive Technology Service Provider Interface - * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap) - * - * Copyright 2001, 2002, 2003 Sun Microsystems Inc., - * Copyright 2001, 2002, 2003 Ximian, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include "../cspi/spi-private.h" /* A hack for now */ - -static void traverse_accessible_tree (Accessible *accessible); - -static void report_event (const AccessibleEvent *event, void *user_data); -static void report_caret_event (const AccessibleEvent *event, void *user_data); -static void report_bounds_event (const AccessibleEvent *event, void *user_data); -static void report_detail_event (const AccessibleEvent *event, void *user_data); -static void report_detail1_event (const AccessibleEvent *event, void *user_data); -static void report_text_event (const AccessibleEvent *event, void *user_data); -static void report_text_selection_event (const AccessibleEvent *event, void *user_data); -static void report_active_descendant_changed_event (const AccessibleEvent *event, void *user_data); -static void report_children_changed_event (const AccessibleEvent *event, void *user_data); -static void report_name_changed_event (const AccessibleEvent *event, void *user_data); -static void report_description_changed_event (const AccessibleEvent *event, void *user_data); -static void report_parent_changed_event (const AccessibleEvent *event, void *user_data); -static void report_window_event (const AccessibleEvent *event, void *user_data); -static void report_table_summary_event (const AccessibleEvent *event, void *user_data); -static void report_table_header_event (const AccessibleEvent *event, void *user_data); -static void report_table_caption_event (const AccessibleEvent *event, void *user_data); -static void report_table_row_description_event (const AccessibleEvent *event, void *user_data); -static void report_table_column_description_event (const AccessibleEvent *event, void *user_data); -static void timing_test_event (const AccessibleEvent *event, void *user_data); -static SPIBoolean report_mouse_event (const AccessibleDeviceEvent *event, void *user_data); - -static AccessibleEventListener *generic_listener; -static AccessibleEventListener *specific_listener; -static AccessibleEventListener *bounds_listener; -static AccessibleEventListener *detail1_listener; -static AccessibleEventListener *test_listener; -static AccessibleEventListener *text_listener; -static AccessibleEventListener *caret_listener; -static AccessibleEventListener *text_selection_listener; -static AccessibleEventListener *active_descendant_changed_listener; -static AccessibleEventListener *children_changed_listener; -static AccessibleEventListener *name_changed_listener; -static AccessibleEventListener *description_changed_listener; -static AccessibleEventListener *parent_changed_listener; -static AccessibleEventListener *window_listener; -static AccessibleEventListener *table_summary_listener; -static AccessibleEventListener *table_header_listener; -static AccessibleEventListener *table_caption_listener; -static AccessibleEventListener *table_row_description_listener; -static AccessibleEventListener *table_column_description_listener; -static AccessibleDeviceListener *mouse_device_listener; -static gint n_elements_traversed = 0; -static GTimer *timer; - -static gboolean report_mouse_events = TRUE; - -void -usage_and_exit( void ) -{ - g_print("\nUsage: event-listener-test [-h] [-m]\n"); - g_print(" -h : prints this usage message.\n"); - g_print(" -m : disable mouse event reporting.\n\n"); - - exit( 1 ); -} - -int -main (int argc, char **argv) -{ - int c; - - /* Parse Command-line */ - if ( argc > 1 ) { - while ( ( c = getopt( argc, argv, "hm")) != EOF ) { - switch( c ) { - case 'm': - report_mouse_events = FALSE; - break; - default: - usage_and_exit(); - break; - } - } - if ( optind < argc ) { - usage_and_exit(); - } - } - - fprintf (stderr, "RUNNING\n"); - - SPI_init (); - - generic_listener = SPI_createAccessibleEventListener ( - report_event, NULL); - specific_listener = SPI_createAccessibleEventListener ( - report_detail_event, NULL); - bounds_listener = SPI_createAccessibleEventListener ( - report_bounds_event, NULL); - text_listener = SPI_createAccessibleEventListener ( - report_text_event, NULL); - caret_listener = SPI_createAccessibleEventListener ( - report_caret_event, NULL); - text_selection_listener = SPI_createAccessibleEventListener ( - report_text_selection_event, NULL); - active_descendant_changed_listener = SPI_createAccessibleEventListener ( - report_active_descendant_changed_event, NULL); - children_changed_listener = SPI_createAccessibleEventListener ( - report_children_changed_event, NULL); - name_changed_listener = SPI_createAccessibleEventListener ( - report_name_changed_event, NULL); - description_changed_listener = SPI_createAccessibleEventListener ( - report_description_changed_event, NULL); - parent_changed_listener = SPI_createAccessibleEventListener ( - report_parent_changed_event, NULL); - window_listener = SPI_createAccessibleEventListener ( - report_window_event, NULL); - table_summary_listener = SPI_createAccessibleEventListener ( - report_table_summary_event, NULL); - table_header_listener = SPI_createAccessibleEventListener ( - report_table_header_event, NULL); - table_caption_listener = SPI_createAccessibleEventListener ( - report_table_caption_event, NULL); - table_row_description_listener = SPI_createAccessibleEventListener ( - report_table_row_description_event, NULL); - table_column_description_listener = SPI_createAccessibleEventListener ( - report_table_column_description_event, NULL); - test_listener = SPI_createAccessibleEventListener ( - timing_test_event, NULL); - mouse_device_listener = SPI_createAccessibleDeviceListener ( - report_mouse_event, NULL); - detail1_listener = SPI_createAccessibleEventListener ( - report_detail1_event, NULL); - - SPI_registerGlobalEventListener (generic_listener, - "focus:"); - if ( report_mouse_events ) { - SPI_registerGlobalEventListener (specific_listener, - "mouse:rel"); - SPI_registerGlobalEventListener (specific_listener, - "mouse:button"); - SPI_registerGlobalEventListener (specific_listener, - "mouse:abs"); - } - SPI_registerDeviceEventListener (mouse_device_listener, - SPI_BUTTON_PRESSED | SPI_BUTTON_RELEASED, - NULL); - SPI_registerGlobalEventListener (specific_listener, - "keyboard:modifiers"); - - SPI_registerGlobalEventListener (generic_listener, - "object:property-change"); - SPI_registerGlobalEventListener (name_changed_listener, - "object:property-change:accessible-name"); - SPI_registerGlobalEventListener (description_changed_listener, - "object:property-change:accessible-description"); - SPI_registerGlobalEventListener (parent_changed_listener, - "object:property-change:accessible-parent"); - SPI_registerGlobalEventListener (generic_listener, - "object:state-changed"); -/* SPI_registerGlobalEventListener (specific_listener, - "object:state-changed:focused"); */ - SPI_registerGlobalEventListener (generic_listener, - "object:selection-changed"); - - SPI_registerGlobalEventListener (children_changed_listener, - "object:children-changed"); - SPI_registerGlobalEventListener (active_descendant_changed_listener, - "object:active-descendant-changed"); - SPI_registerGlobalEventListener (generic_listener, - "object:visible-data-changed"); - SPI_registerGlobalEventListener (text_selection_listener, - "object:text-selection-changed"); - SPI_registerGlobalEventListener (caret_listener, - "object:text-caret-moved"); - SPI_registerGlobalEventListener (text_listener, - "object:text-changed"); - SPI_registerGlobalEventListener (generic_listener, - "object:column-inserted"); - SPI_registerGlobalEventListener (generic_listener, - "object:row-inserted"); - SPI_registerGlobalEventListener (generic_listener, - "object:column-reordered"); - SPI_registerGlobalEventListener (generic_listener, - "object:row-reordered"); - SPI_registerGlobalEventListener (generic_listener, - "object:column-deleted"); - SPI_registerGlobalEventListener (generic_listener, - "object:row-deleted"); - SPI_registerGlobalEventListener (generic_listener, - "object:model-changed"); - SPI_registerGlobalEventListener (detail1_listener, - "object:link-selected"); -#if 0 - SPI_registerGlobalEventListener (bounds_listener, - "object:bounds-changed"); -#endif - SPI_registerGlobalEventListener (window_listener, - "window:minimize"); - SPI_registerGlobalEventListener (window_listener, - "window:maximize"); - SPI_registerGlobalEventListener (window_listener, - "window:restore"); - SPI_registerGlobalEventListener (window_listener, - "window:activate"); - SPI_registerGlobalEventListener (window_listener, - "window:create"); - SPI_registerGlobalEventListener (window_listener, - "window:deactivate"); - SPI_registerGlobalEventListener (window_listener, - "window:close"); - SPI_registerGlobalEventListener (window_listener, - "window:lower"); - SPI_registerGlobalEventListener (window_listener, - "window:raise"); - SPI_registerGlobalEventListener (window_listener, - "window:resize"); - SPI_registerGlobalEventListener (window_listener, - "window:shade"); - SPI_registerGlobalEventListener (window_listener, - "window:unshade"); - SPI_registerGlobalEventListener (table_summary_listener, - "object:property-change:accessible-table-summary"); - SPI_registerGlobalEventListener (table_header_listener, - "object:property-change:accessible-table-row-header"); - SPI_registerGlobalEventListener (table_header_listener, - "object:property-change:accessible-table-column-header"); - SPI_registerGlobalEventListener (table_summary_listener, - "object:property-change:accessible-table-summary"); - SPI_registerGlobalEventListener (table_row_description_listener, - "object:property-change:accessible-table-row-description"); - SPI_registerGlobalEventListener (table_column_description_listener, - "object:property-change:accessible-table-column-description"); - SPI_registerGlobalEventListener (test_listener, - "object:test"); -#ifdef NOT_YET_IMPLEMENTED - /* event below possibly should just be property change? */ - SPI_registerGlobalEventListener (generic_listener, - "window:restyle"); - SPI_registerGlobalEventListener (generic_listener, - "window:desktop-create"); - SPI_registerGlobalEventListener (generic_listener, - "window:desktop-destroy"); -#endif - - timer = g_timer_new (); - traverse_accessible_tree (SPI_getDesktop (0)); - g_print ("Time for first traversal of %d elements: %lf\n", - n_elements_traversed, - g_timer_elapsed (timer, NULL)); - g_timer_start (timer); - traverse_accessible_tree (SPI_getDesktop (0)); - g_timer_stop (timer); - g_print ("Time for subsequent traversal %f\n", g_timer_elapsed (timer, NULL)); - g_print ("[%f elements/sec, %f SPI calls/sec]\n", - n_elements_traversed/g_timer_elapsed(timer, NULL), - (n_elements_traversed*8+1)/g_timer_elapsed(timer, NULL)); - g_timer_reset (timer); - SPI_event_main (); - - putenv ("AT_BRIDGE_SHUTDOWN=1"); - - /* - * TODO: Add a key event listener that calls test_exit, to - * deregister and cleanup appropriately. - */ - - return SPI_exit (); -} - -static void -traverse_accessible_tree (Accessible *accessible) -{ - int n_children; - int i; - char *name; - char *role_name; - Accessible *child; - - n_elements_traversed++; - name = Accessible_getName (accessible); - role_name = Accessible_getRoleName (accessible); -#ifdef VERBOSE - fprintf (stdout, "[%s] \"%s\"\n", - role_name, name); -#endif - SPI_freeString (name); - SPI_freeString (role_name); - n_children = Accessible_getChildCount (accessible); - if (!Accessible_isTable (accessible)) - { - for (i = 0; i < n_children; ++i) - { - child = Accessible_getChildAtIndex (accessible, i); - traverse_accessible_tree (child); - Accessible_unref (child); - } - } -} - -void -report_event (const AccessibleEvent *event, void *user_data) -{ - static long count = 0; - char *s = Accessible_getName (event->source); - fprintf (stderr, "%s %s\n", event->type, s); - if (s) SPI_freeString (s); - if (count == 0) { - g_timer_reset (timer); - g_timer_start (timer); - } - ++count; - if ((count % 100) == 0) { - g_print ("%ld events received, %f events/sec\n", - count, - count/g_timer_elapsed(timer, NULL)); - } - - /* check for Table interface - if present, query selections */ - if (Accessible_isTable (event->source)) - { - gint n_selected_rows = 0; - gint n_selected_cols = 0; - long int *rows, *cols; - AccessibleTable *table = Accessible_getTable (event->source); - - n_selected_rows = AccessibleTable_getSelectedRows (table, &rows); - n_selected_cols = AccessibleTable_getSelectedColumns (table, &cols); - - g_print ("TABLE interface: selectedRows=%d, selectedCols = %d\n", - n_selected_rows, n_selected_cols); - } -} - -void -report_caret_event (const AccessibleEvent *event, void *user_data) -{ - char *s = Accessible_getName (event->source); - long int start, end, offset, line_start_begin; - long int line_start_end, line_end_begin, line_end_end; - - AccessibleText *text = Accessible_getText (event->source); - offset = event->detail1; - AccessibleText_getTextAtOffset (text, offset, - SPI_TEXT_BOUNDARY_SENTENCE_START, - &start, &end); - fprintf (stderr, - "caret event from %s %s: offset %ld, SENTENCE_START offsets start=%ld, end=%ld\n", - event->type, s, offset, start, end); - AccessibleText_getTextAtOffset (text, offset, - SPI_TEXT_BOUNDARY_SENTENCE_END, - &start, &end); - AccessibleText_getTextAtOffset (text, offset, - SPI_TEXT_BOUNDARY_LINE_START, - &line_start_begin, &line_start_end); - AccessibleText_getTextAtOffset (text, offset, - SPI_TEXT_BOUNDARY_LINE_END, - &line_end_begin, &line_end_end); - fprintf (stderr, - "SENTENCE_END: %ld - %ld; LINE_START: %ld - %ld; LINE_END: %ld - %ld\n", - start, end, line_start_begin, line_start_end, - line_end_begin, line_end_end); - - AccessibleText_getTextAtOffset (text, offset, - SPI_TEXT_BOUNDARY_WORD_START, - &line_start_begin, &line_start_end); - AccessibleText_getTextAtOffset (text, offset, - SPI_TEXT_BOUNDARY_WORD_END, - &line_end_begin, &line_end_end); - fprintf (stderr, - "WORD_START: %ld - %ld; WORD_END: %ld - %ld\n", - line_start_begin, line_start_end, - line_end_begin, line_end_end); - - if (s) SPI_freeString (s); -} - -void -report_detail_event (const AccessibleEvent *event, void *user_data) -{ - char *s = Accessible_getName (event->source); - fprintf (stderr, "(detail) %s %s %ld %ld\n", event->type, s, - event->detail1, event->detail2); - if (s) SPI_freeString (s); -} - -void -report_detail1_event (const AccessibleEvent *event, void *user_data) -{ - char *s = Accessible_getName (event->source); - fprintf (stderr, "(detail) %s %s %ld\n", event->type, s, - event->detail1); - if (s) SPI_freeString (s); -} - -void -report_bounds_event (const AccessibleEvent *event, void *user_data) -{ - char *s = Accessible_getName (event->source); - SPIRect *bounds = AccessibleBoundsChangedEvent_getNewBounds (event); - if (!bounds) fprintf (stderr, "bounds-changed event with no bounds?\n"); - fprintf (stderr, "(bounds-changed) %s %s %ld,%ld - %ld,%ld\n", event->type, s, - bounds->x, bounds->y, bounds->x + bounds->width, bounds->y + bounds->height); - SPI_freeRect (bounds); - if (s) SPI_freeString (s); -} - -void -report_text_event (const AccessibleEvent *event, void *user_data) -{ - char *s = Accessible_getName (event->source); - fprintf (stderr, "(detail) %s %s %ld %ld\n", event->type, s, - event->detail1, event->detail2); - SPI_freeString (s); - s = AccessibleTextChangedEvent_getChangeString (event); - fprintf (stderr, "context string %s\n", (s) ? s : "<nil>"); - if (s) SPI_freeString (s); -} - -void -report_text_selection_event (const AccessibleEvent *event, void *user_data) -{ - char *s = Accessible_getName (event->source); - fprintf (stderr, "(detail) %s %s %ld %ld\n", event->type, s, - event->detail1, event->detail2); - SPI_freeString (s); - s = AccessibleTextSelectionChangedEvent_getSelectionString (event); - fprintf (stderr, "context string %s\n", (s) ? s : "<nil>"); - SPI_freeString (s); -} - -void -report_active_descendant_changed_event (const AccessibleEvent *event, void *user_data) -{ - char *s = Accessible_getName (event->source); - char *s1; - Accessible *ao; - - ao = AccessibleActiveDescendantChangedEvent_getActiveDescendant (event); - s1 = Accessible_getName (ao); - fprintf (stderr, "(detail) %s parent: %s child: %s %ld %ld\n", event->type, - s ? s : "<null>", s1 ? s1 : "<null>", - event->detail1, event->detail2); - SPI_freeString (s); - SPI_freeString (s1); - Accessible_unref (ao); -} -void -report_children_changed_event (const AccessibleEvent *event, void *user_data) -{ - char *s = Accessible_getName (event->source); - char *s1 = NULL, *s2, *s3 = NULL; - Accessible *ao; - - ao = AccessibleChildChangedEvent_getChildAccessible (event); - if (ao) s1 = Accessible_getName (ao); - s2 = Accessible_getRoleName (event->source); - if (ao) s3 = Accessible_getRoleName (ao); - fprintf (stderr, "(detail) %s parent: %s [%s] child: %s [%s] %ld %ld\n", - event->type, - s ? s : "<null>", - s2, - s1 ? s1 : "<null>", - s3 ? s3 : "<null>", - event->detail1, event->detail2); - SPI_freeString (s); - SPI_freeString (s1); - SPI_freeString (s2); - SPI_freeString (s3); - Accessible_unref (ao); -} - -void -report_name_changed_event (const AccessibleEvent *event, void *user_data) -{ - char *s = Accessible_getName (event->source); - fprintf (stderr, "(detail) %s %s %ld %ld\n", event->type, s, - event->detail1, event->detail2); - SPI_freeString (s); - s = AccessibleNameChangedEvent_getNameString (event); - fprintf (stderr, "context string %s\n", (s) ? s : "<nil>"); - SPI_freeString (s); -} - -void -report_description_changed_event (const AccessibleEvent *event, void *user_data) -{ - char *s = Accessible_getName (event->source); - fprintf (stderr, "(detail) %s %s %ld %ld\n", event->type, s, - event->detail1, event->detail2); - SPI_freeString (s); - s = AccessibleDescriptionChangedEvent_getDescriptionString (event); - fprintf (stderr, "context string %s\n", (s) ? s : "<nil>"); - SPI_freeString (s); -} - -void -report_parent_changed_event (const AccessibleEvent *event, void *user_data) -{ - char *s = Accessible_getName (event->source); - char *s1; - Accessible *ao; - - ao = AccessibleParentChangedEvent_getParentAccessible (event); - s1 = Accessible_getName (ao); - fprintf (stderr, "(detail) %s parent: %s child: %s %ld %ld\n", event->type, - s ? s : "<null>", s1 ? s1 : "<null>", - event->detail1, event->detail2); - SPI_freeString (s); - SPI_freeString (s1); - Accessible_unref (ao); -} - -void -report_window_event (const AccessibleEvent *event, void *user_data) -{ - char *s = Accessible_getName (event->source); - fprintf (stderr, "(detail) %s %s %ld %ld\n", event->type, s, - event->detail1, event->detail2); - SPI_freeString (s); - s = AccessibleWindowEvent_getTitleString (event); - fprintf (stderr, "context string %s\n", (s) ? s : "<nil>"); - SPI_freeString (s); -} - -void -report_table_summary_event (const AccessibleEvent *event, void *user_data) -{ - char *s = Accessible_getName (event->source); - char *s1; - Accessible *ao; - - ao = AccessibleTableSummaryChangedEvent_getSummaryAccessible (event); - s1 = Accessible_getName (ao); - fprintf (stderr, "(detail) %s parent: %s child: %s %ld %ld\n", event->type, - s ? s : "<null>", s1 ? s1 : "<null>", - event->detail1, event->detail2); - SPI_freeString (s); - SPI_freeString (s1); - Accessible_unref (ao); -} - -void -report_table_header_event (const AccessibleEvent *event, void *user_data) -{ - char *s = Accessible_getName (event->source); - char *s1; - Accessible *ao; - - ao = AccessibleTableHeaderChangedEvent_getHeaderAccessible (event); - s1 = Accessible_getName (ao); - fprintf (stderr, "(detail) %s parent: %s child: %s %ld %ld\n", event->type, - s ? s : "<null>", s1 ? s1 : "<null>", - event->detail1, event->detail2); - SPI_freeString (s); - SPI_freeString (s1); - Accessible_unref (ao); -} - -void -report_table_caption_event (const AccessibleEvent *event, void *user_data) -{ - char *s = Accessible_getName (event->source); - fprintf (stderr, "(detail) %s %s %ld %ld\n", event->type, s, - event->detail1, event->detail2); - SPI_freeString (s); - s = AccessibleTableCaptionChangedEvent_getCaptionString (event); - fprintf (stderr, "context string %s\n", (s) ? s : "<nil>"); - SPI_freeString (s); -} - -void -report_table_row_description_event (const AccessibleEvent *event, void *user_data) -{ - char *s = Accessible_getName (event->source); - fprintf (stderr, "(detail) %s %s %ld %ld\n", event->type, s, - event->detail1, event->detail2); - SPI_freeString (s); - s = AccessibleTableRowDescriptionChangedEvent_getDescriptionString (event); - fprintf (stderr, "context string %s\n", (s) ? s : "<nil>"); - SPI_freeString (s); -} - -void -report_table_column_description_event (const AccessibleEvent *event, void *user_data) -{ - char *s = Accessible_getName (event->source); - fprintf (stderr, "(detail) %s %s %ld %ld\n", event->type, s, - event->detail1, event->detail2); - SPI_freeString (s); - s = AccessibleTableColumnDescriptionChangedEvent_getDescriptionString (event); - fprintf (stderr, "context string %s\n", (s) ? s : "<nil>"); - SPI_freeString (s); -} - -SPIBoolean -report_mouse_event (const AccessibleDeviceEvent *event, void *user_data) -{ - fprintf (stderr, "mouse event %ld %d %x %x\n", - event->keyID, - (int) event->keycode, - (unsigned) event->type, - (unsigned) event->modifiers); - return FALSE; -} - -void -timing_test_event (const AccessibleEvent *event, void *user_data) -{ - static long count = 0; - if (count == 0) g_timer_start (timer); - ++count; - if ((count % 500) == 0) { - g_print ("%ld events received, %f events/sec\n", - count, - count/g_timer_elapsed(timer, NULL)); - } -} - -void -test_exit (void) -{ - SPI_deregisterGlobalEventListenerAll (generic_listener); - AccessibleEventListener_unref (generic_listener); - SPI_deregisterGlobalEventListenerAll (specific_listener); - AccessibleEventListener_unref (specific_listener); -} diff --git a/test/key-listener-test.c b/test/key-listener-test.c deleted file mode 100644 index 5c7d43df..00000000 --- a/test/key-listener-test.c +++ /dev/null @@ -1,201 +0,0 @@ -/* - * AT-SPI - Assistive Technology Service Provider Interface - * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap) - * - * 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 - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <stdlib.h> -#include <stdio.h> -#include <ctype.h> -#include <unistd.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <sys/un.h> -#include <cspi/spi.h> - -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 SPIBoolean report_synchronous_key_event (const AccessibleKeystroke *stroke, void *user_data); -static SPIBoolean report_tab_key_event (const AccessibleKeystroke *stroke, void *user_data); -static SPIBoolean report_all_key_event (const AccessibleKeystroke *stroke, void *user_data); - -static AccessibleKeystrokeListener *command_key_listener; -static AccessibleKeystrokeListener *ordinary_key_listener; -static AccessibleKeystrokeListener *synchronous_key_listener; -static AccessibleKeystrokeListener *tab_key_listener; -static AccessibleKeystrokeListener *all_key_listener; -static AccessibleKeySet *command_keyset; -static AccessibleKeySet *async_keyset; -static AccessibleKeySet *sync_keyset; -static AccessibleKeySet *tab_keyset; - -int -main (int argc, char **argv) -{ - const char *tab_strings[1] = {"Tab"}; - short keycodes[] = {65, 64, 23}; - SPIBoolean retval = FALSE; - - SPI_init (); - - /* prepare the keyboard snoopers */ - command_key_listener = SPI_createAccessibleKeystrokeListener (report_command_key_event, NULL); - ordinary_key_listener = SPI_createAccessibleKeystrokeListener (report_ordinary_key_event, NULL); - synchronous_key_listener = SPI_createAccessibleKeystrokeListener (report_synchronous_key_event, NULL); - tab_key_listener = SPI_createAccessibleKeystrokeListener (report_tab_key_event, NULL); - all_key_listener = SPI_createAccessibleKeystrokeListener (report_all_key_event, NULL); - - command_keyset = SPI_createAccessibleKeySet (1, "q", NULL, NULL); - async_keyset = SPI_createAccessibleKeySet (3, NULL, keycodes, NULL); - sync_keyset = SPI_createAccessibleKeySet (3, "def", NULL, NULL); - tab_keyset = SPI_createAccessibleKeySet (1, NULL, NULL, tab_strings); - retval = SPI_registerAccessibleKeystrokeListener(command_key_listener, - command_keyset, - SPI_KEYMASK_ALT | SPI_KEYMASK_CONTROL, - (unsigned long) ( SPI_KEY_PRESSED ), - SPI_KEYLISTENER_ALL_WINDOWS); - fprintf (stderr, "Command key registry: result %s\n", retval ? "succeeded" : - "failed"); - retval = SPI_registerAccessibleKeystrokeListener(ordinary_key_listener, - async_keyset, - SPI_KEYMASK_UNMODIFIED, - (unsigned long) ( SPI_KEY_PRESSED | SPI_KEY_RELEASED ), - SPI_KEYLISTENER_NOSYNC); - - retval = SPI_registerAccessibleKeystrokeListener(synchronous_key_listener, - sync_keyset, - SPI_KEYMASK_UNMODIFIED, - (unsigned long) ( SPI_KEY_PRESSED | SPI_KEY_RELEASED ), - SPI_KEYLISTENER_CANCONSUME); - - retval = SPI_registerAccessibleKeystrokeListener(tab_key_listener, - tab_keyset, - SPI_KEYMASK_ALT, - (unsigned long) ( SPI_KEY_PRESSED | SPI_KEY_RELEASED ), - SPI_KEYLISTENER_ALL_WINDOWS); - fprintf (stderr, "tab listener registry: %s\n", retval ? "succeeded" : "failed"); - - retval = SPI_registerAccessibleKeystrokeListener(all_key_listener, - SPI_KEYSET_ALL_KEYS, - SPI_KEYMASK_CONTROL | SPI_KEYMASK_SHIFT, - (unsigned long) ( SPI_KEY_PRESSED | SPI_KEY_RELEASED ), - SPI_KEYLISTENER_ALL_WINDOWS); - - fprintf (stderr, "all key registry: %s\n", retval ? "succeeded" : "failed" ); - - SPI_registerAccessibleKeystrokeListener(all_key_listener, - SPI_KEYSET_ALL_KEYS, - SPI_KEYMASK_SHIFT, - (unsigned long) ( SPI_KEY_PRESSED ), - SPI_KEYLISTENER_NOSYNC | SPI_KEYLISTENER_CANCONSUME); - - SPI_event_main (); - - putenv ("AT_BRIDGE_SHUTDOWN=1"); - - return SPI_exit (); -} - -static void -simple_at_exit (void) -{ - 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_ALT | SPI_KEYMASK_CONTROL); */ - AccessibleKeystrokeListener_unref (ordinary_key_listener); - SPI_freeAccessibleKeySet (async_keyset); - -/* SPI_deregisterAccessibleKeystrokeListener (synchronous_key_listener, SPI_KEYMASK_ALT | SPI_KEYMASK_CONTROL); */ - AccessibleKeystrokeListener_unref (synchronous_key_listener); - SPI_freeAccessibleKeySet (sync_keyset); - - SPI_deregisterAccessibleKeystrokeListener (tab_key_listener, SPI_KEYMASK_ALT | SPI_KEYMASK_CONTROL); - AccessibleKeystrokeListener_unref (tab_key_listener); - SPI_freeAccessibleKeySet (tab_keyset); - - SPI_event_quit (); -} - -static SPIBoolean -is_command_key (const AccessibleKeystroke *key) -{ - switch (key->keyID) - { - case 'Q': - case 'q': - simple_at_exit(); - return TRUE; /* not reached */ - default: - return FALSE; - } -} - -static void -print_key_event (const AccessibleKeystroke *key, char *prefix) -{ - fprintf (stderr, "%s KeyEvent %s%c (keycode %d); string=%s; time=%lx\n", - prefix, - (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, - key->keystring, - (long int) key->timestamp); -} - -static SPIBoolean -report_command_key_event (const AccessibleKeystroke *key, void *user_data) -{ - print_key_event (key, "command"); - return is_command_key (key); -} - -static SPIBoolean -report_ordinary_key_event (const AccessibleKeystroke *key, void *user_data) -{ - print_key_event (key, "ordinary"); - return FALSE; -} - -static SPIBoolean -report_synchronous_key_event (const AccessibleKeystroke *key, void *user_data) -{ - /* consume 'd' key, let others pass through */ - print_key_event (key, "synchronous (consumable) "); - return ( key->keyID == 'd' ) ? TRUE : FALSE; -} - -static SPIBoolean -report_tab_key_event (const AccessibleKeystroke *key, void *user_data) -{ - print_key_event (key, "[TAB]"); - return FALSE; -} - -static SPIBoolean -report_all_key_event (const AccessibleKeystroke *key, void *user_data) -{ - fprintf(stderr, "(%ld)", key->keyID); - return FALSE; -} - diff --git a/test/keypad-test.c b/test/keypad-test.c deleted file mode 100644 index 7be9c995..00000000 --- a/test/keypad-test.c +++ /dev/null @@ -1,186 +0,0 @@ -/* - * AT-SPI - Assistive Technology Service Provider Interface - * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap) - * - * 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 - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <stdlib.h> -#include <stdio.h> -#include <ctype.h> -#include <unistd.h> -#include <glib-object.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <sys/un.h> -#include <cspi/spi.h> -#define XK_MISCELLANY -#include <X11/keysymdef.h> -#include <gdk/gdk.h> -#include <gdk/gdkx.h> - -static SPIBoolean report_keypad_key_event (const AccessibleKeystroke *stroke, void *user_data); - -static short *get_keypad_keycodes (void); - -static AccessibleKeystrokeListener *keypad_key_listener; -static AccessibleKeySet *keypad_keyset; - -static Display *get_display (void); - -int -main (int argc, char **argv) -{ - SPIBoolean retval = FALSE; - - SPI_init (); - - gdk_init (&argc, &argv); /* - * needed in this test program only - * because we are calling GDK_DISPLAY() - */ - - /* prepare the keyboard snoopers */ - keypad_key_listener = SPI_createAccessibleKeystrokeListener (report_keypad_key_event, NULL); - keypad_keyset = SPI_createAccessibleKeySet (16, NULL, get_keypad_keycodes (), NULL); - - retval = SPI_registerAccessibleKeystrokeListener(keypad_key_listener, - keypad_keyset, - SPI_KEYMASK_UNMODIFIED, - (unsigned long) ( SPI_KEY_PRESSED | - SPI_KEY_RELEASED ), - SPI_KEYLISTENER_ALL_WINDOWS); - fprintf (stderr, "Keypad key registry: result %s\n", retval ? "succeeded" : - "failed"); - - retval = SPI_registerAccessibleKeystrokeListener(keypad_key_listener, - keypad_keyset, - SPI_KEYMASK_SHIFT, - (unsigned long) ( SPI_KEY_PRESSED | - SPI_KEY_RELEASED ), - SPI_KEYLISTENER_ALL_WINDOWS); - - fprintf (stderr, "Shift-Keypad key registry: result %s\n", retval ? "succeeded" : - "failed"); - - retval = SPI_registerAccessibleKeystrokeListener(keypad_key_listener, - keypad_keyset, - SPI_KEYMASK_MOD2, - (unsigned long) ( SPI_KEY_PRESSED | - SPI_KEY_RELEASED ), - SPI_KEYLISTENER_ALL_WINDOWS); - - fprintf (stderr, "Mod2-Keypad key registry: result %s\n", retval ? "succeeded" : - "failed"); - - retval = SPI_registerAccessibleKeystrokeListener(keypad_key_listener, - keypad_keyset, - SPI_KEYMASK_MOD3, - (unsigned long) ( SPI_KEY_PRESSED | - SPI_KEY_RELEASED ), - SPI_KEYLISTENER_ALL_WINDOWS); - - fprintf (stderr, "Mod3-Keypad key registry: result %s\n", retval ? "succeeded" : - "failed"); - - retval = SPI_registerAccessibleKeystrokeListener(keypad_key_listener, - keypad_keyset, - SPI_KEYMASK_MOD2 | SPI_KEYMASK_SHIFT, - (unsigned long) ( SPI_KEY_PRESSED | - SPI_KEY_RELEASED ), - SPI_KEYLISTENER_ALL_WINDOWS); - - fprintf (stderr, "Mod2-Shift-Keypad key registry: result %s\n", retval ? "succeeded" : - "failed"); - - retval = SPI_registerAccessibleKeystrokeListener(keypad_key_listener, - keypad_keyset, - SPI_KEYMASK_MOD3 | SPI_KEYMASK_SHIFT, - (unsigned long) ( SPI_KEY_PRESSED | - SPI_KEY_RELEASED ), - SPI_KEYLISTENER_ALL_WINDOWS); - - fprintf (stderr, "Mod3-Shift-Keypad key registry: result %s\n", retval ? "succeeded" : - "failed"); - - SPI_event_main (); - - putenv ("AT_BRIDGE_SHUTDOWN=1"); - - return SPI_exit (); -} - -static Display* -get_display (void) -{ - return GDK_DISPLAY (); -} - -static short* -get_keypad_keycodes (void) -{ - short *keycodes = (short *) g_new0 (short *, 16); - int i; - - keycodes [0] = XKeysymToKeycode (get_display (), XK_KP_0); - keycodes [1] = XKeysymToKeycode (get_display (), XK_KP_1); - keycodes [2] = XKeysymToKeycode (get_display (), XK_KP_2); - keycodes [3] = XKeysymToKeycode (get_display (), XK_KP_3); - keycodes [4] = XKeysymToKeycode (get_display (), XK_KP_4); - keycodes [5] = XKeysymToKeycode (get_display (), XK_KP_5); - keycodes [6] = XKeysymToKeycode (get_display (), XK_KP_6); - keycodes [7] = XKeysymToKeycode (get_display (), XK_KP_7); - keycodes [8] = XKeysymToKeycode (get_display (), XK_KP_8); - keycodes [9] = XKeysymToKeycode (get_display (), XK_KP_9); - keycodes [10] = XKeysymToKeycode (get_display (), XK_KP_Divide); - keycodes [11] = XKeysymToKeycode (get_display (), XK_KP_Multiply); - keycodes [12] = XKeysymToKeycode (get_display (), XK_KP_Add); - keycodes [13] = XKeysymToKeycode (get_display (), XK_KP_Subtract); - keycodes [14] = XKeysymToKeycode (get_display (), XK_KP_Decimal); - keycodes [15] = XKeysymToKeycode (get_display (), XK_KP_Enter); - - for (i = 0; i < 16; ++i) - { - fprintf (stderr, "keycode[%d] = %d\n", i, (int) keycodes[i]); - } - return keycodes; -} - -static void -print_key_event (const AccessibleKeystroke *key, char *prefix) -{ - fprintf (stderr, "%s KeyEvent %s%c [keysym 0x%ld] (keycode %d); string=%s; time=%lx\n", - prefix, - (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), - key->keyID, - (int) key->keycode, - key->keystring, - (long int) key->timestamp); -} - -static SPIBoolean -report_keypad_key_event (const AccessibleKeystroke *key, void *user_data) -{ - print_key_event (key, "keypad"); - return FALSE; -} - - diff --git a/test/keysynth-demo.c b/test/keysynth-demo.c deleted file mode 100644 index 5f6b6f77..00000000 --- a/test/keysynth-demo.c +++ /dev/null @@ -1,511 +0,0 @@ -/* - * AT-SPI - Assistive Technology Service Provider Interface - * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap) - * - * 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 - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <gtk/gtk.h> -#include <gdk/gdkx.h> -#include <cspi/spi.h> - -#define LABELMAXLEN 20 -#define MIN_KEYCODE 9 -#define CAPSLOCK_KEYCODE 66 -#define SHIFT_L_KEYCODE 50 -#define SHIFT_R_KEYCODE 62 - -/* these can be increased to access more keys */ -#define MAX_ROWS 6 /* The last row only holds Quit and ShiftLatch, special-purpose keys */ -#define MAX_COLUMNS 14 - -static AccessibleKeystrokeListener *key_listener; -static AccessibleKeystrokeListener *switch_listener; - -static SPIBoolean shift_latched = False; -static SPIBoolean caps_lock = False; -static GtkButton **buttons[MAX_ROWS]; - -typedef enum { - SCAN_IDLE, - SCAN_LINES, - SCAN_LINES_DONE, - SCAN_KEYS, - SCAN_KEYS_DONE -} ScanTimerState; - -typedef struct { - ScanTimerState timer_state; - gint scan_row; - gint scan_column; -} ScanState; - -GdkColor * -button_default_bg_color (GtkButton *button) -{ - static GdkColor bg_color; - static gboolean initialized = FALSE; - if (!initialized) - { - bg_color = gtk_widget_get_style (GTK_WIDGET (button))->bg[GTK_STATE_NORMAL]; - initialized = TRUE; - } - return &bg_color; -} - -GdkColor * -button_default_selected_color (GtkButton *button) -{ - static GdkColor selected_color; - static gboolean initialized = FALSE; - if (!initialized) - { - selected_color = gtk_widget_get_style (GTK_WIDGET (button))->bg[GTK_STATE_SELECTED]; - initialized = TRUE; - } - return &selected_color; -} - -void -select_key (gint lineno, gint keyno) -{ - /* - * Before we do this, we need to make sure we've saved the default normal bg. - * The button_default_bg_color() call caches this for us (as a side-effect). - * Probably we should do this a cleaner way... - */ - button_default_bg_color (buttons [lineno][keyno]); - gtk_widget_modify_bg (GTK_WIDGET (buttons [lineno][keyno]), - GTK_STATE_NORMAL, - button_default_selected_color (buttons [lineno][keyno])); -} - -void -deselect_key (gint lineno, gint keyno) -{ - gtk_widget_modify_bg (GTK_WIDGET (buttons [lineno][keyno]), - GTK_STATE_NORMAL, - button_default_bg_color (buttons [lineno][keyno])); -} - -void -deselect_line (gint lineno) -{ - int i; - int max_columns = MAX_COLUMNS; - if (lineno == MAX_ROWS-1) max_columns = 2; - for (i=0; i<max_columns; ++i) - deselect_key (lineno, i); -} - -void -select_line (gint lineno) -{ - int i; - int max_columns = MAX_COLUMNS; - if (lineno == MAX_ROWS-1) max_columns = 2; - for (i=0; i<max_columns; ++i) - select_key (lineno, i); -} - - -static ScanState* -scan_state (void) -{ - static ScanState state = {SCAN_IDLE, 0, 0}; - return &state; -} - -static gboolean -timeout_scan (gpointer data) -{ - ScanState *state = (ScanState *) data; - state->timer_state = SCAN_IDLE; - deselect_key (state->scan_row, state->scan_column); - return FALSE; -} - -static gboolean -increment_scan (gpointer data) -{ - ScanState *state = (ScanState *) data; - int max_columns; - switch (state->timer_state) - { - case SCAN_IDLE: -/* happens if switch-break occurs before the timer fires, after SCAN_KEYS_DONE*/ - return FALSE; - case SCAN_LINES: - deselect_line (state->scan_row); - state->scan_row = (++state->scan_row < MAX_ROWS) ? state->scan_row : 0; - select_line (state->scan_row); - g_print ("line %d\n", state->scan_row); - break; - case SCAN_KEYS: - deselect_key (state->scan_row, state->scan_column); - if (state->scan_row == MAX_ROWS-1) max_columns = 2; - else max_columns = MAX_COLUMNS; /* last row has only two keys */ - state->scan_column = (++state->scan_column < max_columns) ? state->scan_column : 0; - select_key (state->scan_row, state->scan_column); - g_print ("row %d\n", state->scan_column); - break; - case SCAN_LINES_DONE: - case SCAN_KEYS_DONE: - return FALSE; - } - return TRUE; -} - -static void -scan_start (unsigned int timestamp) -{ - ScanState *state = scan_state(); - switch (state->timer_state) - { - case SCAN_IDLE: - state->timer_state = SCAN_LINES; - state->scan_column = 0; - state->scan_row = 0; - g_timeout_add_full (G_PRIORITY_HIGH_IDLE, 600, increment_scan, state, NULL); - select_line (state->scan_row); - break; - case SCAN_LINES_DONE: - state->timer_state = SCAN_KEYS; - g_timeout_add_full (G_PRIORITY_HIGH_IDLE, 600, increment_scan, state, NULL); - deselect_line (state->scan_row); - select_key (state->scan_row, state->scan_column); - break; - case SCAN_KEYS_DONE: - gtk_button_clicked (buttons[state->scan_row][state->scan_column]); - deselect_key (state->scan_row, state->scan_column); - state->timer_state = SCAN_IDLE; - break; - default: - g_print("unexpected state for 'scan start'\n"); - } -} - -static void -scan_stop (unsigned int timestamp) -{ - /* find the element correspondin to this event's timestamp */ - ScanState *state = scan_state(); - switch (state->timer_state) - { - case SCAN_LINES: - state->timer_state = SCAN_LINES_DONE; - break; - case SCAN_KEYS: - state->timer_state = SCAN_KEYS_DONE; - g_timeout_add_full (G_PRIORITY_HIGH_IDLE, 1200, timeout_scan, state, NULL); - break; - case SCAN_IDLE: - break; - default: - g_print("unexpected state for 'scan stop'\n"); - } -} - -static void -label_buttons(SPIBoolean shifted) -{ - int i, j; - KeySym keysym; - KeyCode keycode = MIN_KEYCODE; - char label[LABELMAXLEN] = " "; - char *button_label; - char *keysymstring; - - for (i=0; i<MAX_ROWS-1; ++i) /* last row doesn't change */ - { - for (j=0; j<MAX_COLUMNS; ++j, ++keycode) - { - keysym = (KeySym) XKeycodeToKeysym (GDK_DISPLAY(), keycode, shifted ? 1 : 0); - /* Note: these routines are not i18n-savvy, we need to use XIM, other methods here */ - if (keysym && g_ascii_isprint((int)keysym)) - { - g_snprintf (label, 2, "%c", (int) keysym); - } - else - { - keysymstring = XKeysymToString (keysym); - if (keysymstring) - { - /* KP_ means keypad... we won't expose this difference */ - if (!strncmp (keysymstring, "KP_", 3)) - strncpy (label, (char *)(keysymstring+3), LABELMAXLEN); - else strncpy (label, keysymstring, LABELMAXLEN); - } - else *label = 0; - } - button_label = - *label==' ' ? " space " : label; - gtk_button_set_label (buttons[i][j], button_label); - } - } -} - -static void -show_shift (GtkButton *button, SPIBoolean *is_shifted) -{ - label_buttons (*is_shifted ^ caps_lock); -} - -static void -toggle_shift_latch (GtkButton *button) -{ - shift_latched = !shift_latched; - if (buttons) label_buttons (caps_lock || shift_latched); -} - -static void -keysynth_exit (void) -{ - SPI_deregisterAccessibleKeystrokeListener (key_listener, SPI_KEYMASK_ALT); - AccessibleKeystrokeListener_unref (key_listener); - - SPI_deregisterAccessibleKeystrokeListener (switch_listener, SPI_KEYMASK_UNMODIFIED); - AccessibleKeystrokeListener_unref (switch_listener); - - SPI_event_quit (); -} - -static void -keysynth_realize (GtkWidget *widget) -{ - XWMHints wm_hints; - Atom wm_window_protocols[2]; - static gboolean initialized = FALSE; - - if (!initialized) - { - wm_window_protocols[0] = gdk_x11_get_xatom_by_name ("WM_DELETE_WINDOW"); - wm_window_protocols[1] = gdk_x11_get_xatom_by_name ("_NET_WM_PING"); - } - - wm_hints.flags = InputHint; - wm_hints.input = False; - - XSetWMHints (GDK_WINDOW_XDISPLAY (widget->window), - GDK_WINDOW_XWINDOW (widget->window), &wm_hints); - - XSetWMProtocols (GDK_WINDOW_XDISPLAY (widget->window), - GDK_WINDOW_XWINDOW (widget->window), wm_window_protocols, 2); -} - -static void -button_exit (GtkButton *notused, void *alsonotused) -{ - keysynth_exit (); -} - -static SPIBoolean -is_command_key (const AccessibleKeystroke *key, void *user_data) -{ - switch (key->keyID) - { - case 'Q': - case 'q': - keysynth_exit (); - return TRUE; /* not reached */ - } - return FALSE; -} - -static SPIBoolean -switch_callback (const AccessibleKeystroke *key, void *user_data) -{ - static SPIBoolean is_down = FALSE; - - if (key->type == SPI_KEY_RELEASED) - { - g_print ("switch up\n"); - is_down = FALSE; - scan_stop (key->timestamp); - } - else - if (!is_down) - { - g_print ("switch down\n"); - is_down = TRUE; - scan_start (key->timestamp); - } - /* catch the first, ignore the rest (will repeat) until keyrelease */ - return FALSE; -} - -static void -synth_keycode (GtkButton *button, KeyCode *keycode) -{ - static KeyCode shift_keycode = 0; - if (!shift_keycode) shift_keycode = XKeysymToKeycode(GDK_DISPLAY(), (KeySym) 0xFFE1); - /* Note: in a real onscreen keyboard shift keycode should not be hard-coded! */ - - if (*keycode) - { - if (*keycode == CAPSLOCK_KEYCODE) - { - caps_lock = !caps_lock; - label_buttons (caps_lock || shift_latched); - } - if (shift_latched) - SPI_generateKeyboardEvent (shift_keycode, NULL, SPI_KEY_PRESS); - - g_print ("generating key %d\n", (int) *keycode); - SPI_generateKeyboardEvent ((long) *keycode, NULL, SPI_KEY_PRESSRELEASE); - - if (shift_latched) - { - SPI_generateKeyboardEvent (shift_keycode, NULL, SPI_KEY_RELEASE); - toggle_shift_latch (button); - } - } -} - -static void -create_vkbd(void) -{ - GtkWidget *window, *container, *hbox; - int i, j; - KeyCode *keycodeptr, keycode = MIN_KEYCODE; - static SPIBoolean true_val = True; - static SPIBoolean false_val = False; - - window = g_object_connect (gtk_widget_new (gtk_window_get_type (), - "user_data", NULL, - "can_focus", FALSE, - "type", GTK_WINDOW_TOPLEVEL, - "window-position", GTK_WIN_POS_CENTER, - "title", "test", - "allow_grow", FALSE, - "allow_shrink", FALSE, - "border_width", 10, - NULL), - "signal::realize", keysynth_realize, NULL, - "signal::destroy", keysynth_exit, NULL, - NULL); - - container = gtk_widget_new (GTK_TYPE_VBOX, - "GtkWidget::parent", window, - "GtkWidget::visible", TRUE, - NULL); - for (i=0; i<MAX_ROWS-1; ++i) - { - hbox = gtk_widget_new (gtk_hbox_get_type(), - "GtkWidget::parent", container, - "GtkWidget::visible", TRUE, - NULL); - buttons[i] = g_new0 (GtkButton*, MAX_COLUMNS); - for (j=0; j<MAX_COLUMNS; ++j) - { - keycodeptr = (KeyCode *) g_new0 (KeyCode, 1); - *keycodeptr = keycode; - buttons[i][j] = g_object_connect (gtk_widget_new (gtk_button_get_type (), - "GtkWidget::parent", hbox, - "GtkWidget::visible", TRUE, - NULL), - "signal::clicked", - synth_keycode, keycodeptr, - NULL); - if (keycode == SHIFT_L_KEYCODE || keycode == SHIFT_R_KEYCODE) - { - g_object_connect (buttons[i][j], "signal::pressed", show_shift, - &true_val, NULL); - g_object_connect (buttons[i][j], "signal::released", show_shift, - &false_val, NULL); - } - ++keycode; - } - } - hbox = gtk_widget_new (gtk_hbox_get_type(), - "GtkWidget::parent", container, - "GtkWidget::visible", TRUE, - NULL); - buttons[i] = g_new0 (GtkButton*, 2); - buttons[i][0] = g_object_connect (gtk_widget_new (gtk_button_get_type (), - "GtkButton::label", "Quit", - "GtkWidget::parent", hbox, - "GtkWidget::visible", TRUE, - NULL), - "signal::clicked", - button_exit, NULL, - NULL); - buttons[i][1] = g_object_connect (gtk_widget_new (gtk_button_get_type (), - "GtkButton::label", "ShiftLatch", - "GtkWidget::parent", hbox, - "GtkWidget::visible", TRUE, - NULL), - "signal::clicked", - toggle_shift_latch, NULL, - NULL); - label_buttons (caps_lock || shift_latched); - gtk_widget_show (window); -} - -int -main (int argc, char **argv) -{ - AccessibleKeySet switch_set; - - if ((argc > 1) && (!strncmp (argv[1], "-h", 2))) - { - printf ("Usage: keysynth-demo\n"); - exit (1); - } - - gtk_init (&argc, &argv); /* must call, because this program uses GTK+ */ - - SPI_init (); - - key_listener = SPI_createAccessibleKeystrokeListener (is_command_key, NULL); - /* will listen only to Alt-key combinations */ - SPI_registerAccessibleKeystrokeListener (key_listener, - (AccessibleKeySet *) SPI_KEYSET_ALL_KEYS, - SPI_KEYMASK_ALT | SPI_KEYMASK_CONTROL, - (unsigned long) ( KeyPress | KeyRelease), - SPI_KEYLISTENER_CANCONSUME | SPI_KEYLISTENER_ALL_WINDOWS); - create_vkbd (); - - /* - * Register a listener on an 'unused' key, to serve as a 'single switch'. - * On most Intel boxes there is at least one 'special' system key that does not - * have a non-zero keycode assigned in the Xserver, so we will intercept any keycode - * that is 'zero'. Often these the are the "windows" or the "menu" keys. - */ - switch_set.keysyms = g_new0 (unsigned long, 1); - switch_set.keycodes = g_new0 (unsigned short, 1); - switch_set.keystrings = g_new0 (char *, 1); - switch_set.len = 1; - switch_set.keysyms[0] = (unsigned long) 0; - switch_set.keycodes[0] = (unsigned short) 0; - switch_set.keystrings[0] = ""; - switch_listener = SPI_createAccessibleKeystrokeListener (switch_callback, NULL); - SPI_registerAccessibleKeystrokeListener (switch_listener, - &switch_set, - SPI_KEYMASK_UNMODIFIED, - (unsigned long) ( SPI_KEY_PRESSED | SPI_KEY_RELEASED ), - SPI_KEYLISTENER_NOSYNC); - - SPI_event_main (); - - return SPI_exit (); -} diff --git a/test/keysynth-test.c b/test/keysynth-test.c deleted file mode 100644 index 22adf463..00000000 --- a/test/keysynth-test.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - * AT-SPI - Assistive Technology Service Provider Interface - * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap) - * - * 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 - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <unistd.h> -#include <stdlib.h> -#include "../cspi/spi-private.h" /* A hack for now */ -#include <glib-object.h> -#include <gtk/gtk.h> -#include <atk/atk.h> -#include <atk/atknoopobject.h> -#include <bonobo-activation/bonobo-activation-register.h> -#include <bonobo/bonobo-main.h> -#include <libspi/libspi.h> - -typedef struct { - long int val; - char *string; - AccessibleKeySynthType type; -} TextTest; - -static TextTest text[] = { - {65, NULL, SPI_KEY_PRESSRELEASE}, - {64, NULL, SPI_KEY_SYM}, - {0, "--hello!", SPI_KEY_STRING}, - {0, "StudlyCaps!", SPI_KEY_STRING} -}; - -static void -test_key_synthesis (void) -{ - int i; - for (i = 0; i < G_N_ELEMENTS (text); ++i) { - SPI_generateKeyboardEvent (text[i].val, text[i].string, text[i].type); - } -} - -int -main (int argc, char **argv) -{ - gtk_init (&argc, &argv); - SPI_init (); - - test_key_synthesis (); - - return SPI_exit (); -} - diff --git a/test/login-helper-client-test.c b/test/login-helper-client-test.c deleted file mode 100644 index fcbbaecf..00000000 --- a/test/login-helper-client-test.c +++ /dev/null @@ -1,216 +0,0 @@ -/* - * test utility for LoginHelper client API and services. - * - * Copyright Sun Microsystems 2004 - * - */ - -#include <X11/X.h> -#include <libbonobo.h> -#include <login-helper/Accessibility_LoginHelper.h> - -gint main (int argc, char **argv) -{ - Bonobo_ServerInfoList *server_list; - Accessibility_LoginHelper *helper_list = NULL; - CORBA_boolean safe; - CORBA_Environment ev; - Accessibility_LoginHelper_WindowList *windows; - int i; - - CORBA_exception_init (&ev); - if (!bonobo_init (&argc, argv)) - { - g_error ("Can't initialize Bonobo"); - } - - /* bonobo-activation query lists existing instances */ - server_list = bonobo_activation_query ( - "(repo_ids.has('IDL:Accessibility/LoginHelper:1.0')) AND _active", - NULL, &ev); - - if (BONOBO_EX (&ev)) - { - bonobo_debug_shutdown (); - g_error ("LoginHelper query failed : %s", - bonobo_exception_get_text (&ev)); - /* not reached (below) because g_error exits */ - CORBA_exception_free (&ev); - } - - g_message ("%d LoginHelpers are running.", - server_list ? server_list->_length : 0); - - helper_list = g_new0 (Accessibility_LoginHelper, server_list->_length); - - /* for each instance... */ - for (i = 0; i < server_list->_length; i++) - { - Accessibility_LoginHelper helper; - Bonobo_Unknown server; - Bonobo_ServerInfo info = server_list->_buffer[i]; - - server = bonobo_activation_activate_from_id ( - info.iid, Bonobo_ACTIVATION_FLAG_EXISTING_ONLY, NULL, &ev); - - if (BONOBO_EX (&ev)) - { - g_warning ("Error activating server %d: %s", i, bonobo_exception_get_text (&ev)); - CORBA_exception_free (&ev); - continue; - } - else if (server == CORBA_OBJECT_NIL) - { - g_warning ("Activated server %d is NIL!", i); - continue; - } - - bonobo_activate (); - - helper = Bonobo_Unknown_queryInterface ( - server, - "IDL:Accessibility/LoginHelper:1.0", - &ev); - - if (BONOBO_EX (&ev)) - { - g_warning ("Error performing interface query: %s", bonobo_exception_get_text (&ev)); - CORBA_exception_free (&ev); - continue; - } - else if (helper == CORBA_OBJECT_NIL) - { - g_warning ("Activated an object which advertised LoginHelper but does not implement it!"); - continue; - } - helper_list[i] = helper; - bonobo_object_release_unref (server, &ev); - - if (helper && !BONOBO_EX (&ev)) - { - /* ask the helper to go into safe mode */ - safe = Accessibility_LoginHelper_setSafe (helper, TRUE, &ev); - if (BONOBO_EX (&ev)) - { - g_warning ("setSafe(TRUE) failed: %s", - bonobo_exception_get_text (&ev)); - CORBA_exception_free (&ev); - } - /* get the raise window list (if the program went into safe mode) */ - if (safe) - { - int j; - gboolean needs_windows_raised = FALSE; - Accessibility_LoginHelper_DeviceReqList *list; - - g_message ("safe"); - - /* does this helper need to have windows raised? */ - list = Accessibility_LoginHelper_getDeviceReqs (helper, &ev); - - if (BONOBO_EX (&ev)) { - g_warning ("Bonobo exception getting Device Requirements: %s", - bonobo_exception_get_text (&ev)); - CORBA_exception_free (&ev); - } - else - { - g_message ("LoginHelper device requirements: "); - if (list->_length == 0) - g_message ("\tNone."); - - for (j = 0; j < list->_length; j++) - { - switch (list->_buffer[j]) - { - case Accessibility_LoginHelper_GUI_EVENTS: - g_message ("\tNeeds access to the GUI event subsystem (e.g. Xserver)"); - break; - case Accessibility_LoginHelper_EXT_INPUT: - g_message ("\tReads XInput extended input devices"); - break; - case Accessibility_LoginHelper_POST_WINDOWS: - g_message ("\tPosts windows"); - needs_windows_raised = TRUE; - break; - case Accessibility_LoginHelper_AUDIO_OUT: - g_message ("\tWrites to audio device"); - break; - case Accessibility_LoginHelper_AUDIO_IN: - g_message ("\tReads from audio device"); - break; - case Accessibility_LoginHelper_LOCALHOST: - g_message ("\tNeeds LOCALHOST network connection"); - break; - case Accessibility_LoginHelper_SERIAL_OUT: - g_message ("\tNeeds to write to one or more serial ports"); - break; - default: - break; - } - } - CORBA_free (list); - } - if (needs_windows_raised) - { - /* don't raise in this test, but do something with each wid */ - windows = Accessibility_LoginHelper_getRaiseWindows (helper, &ev); - if (BONOBO_EX (&ev)) - { - g_warning ("getRaiseWindows failed: %s", - bonobo_exception_get_text (&ev)); - CORBA_exception_free (&ev); - } - g_message ("%d windows need raising", windows->_length); - for (j = 0; j < windows->_length; j++) - { - Window wid; - wid = windows->_buffer[j].winID; - g_message ("Window ID = %ld", (long) wid); - } - } - } - else - { - g_warning ("LoginHelper %d did not go into safe mode", i); - } - } - else - { - if (BONOBO_EX (&ev)) - { - g_warning ("Error activating %s: %s", - info.iid, bonobo_exception_get_text (&ev)); - CORBA_exception_free (&ev); - } - else - { - g_warning ("no active instance of %s found", info.iid); - } - } - } - - /* - * In an actual login/authentication setting, login/authentication - * would take place here, and code below would be executed after - * authentication was complete. - */ - - /* now tell the apps they can resume their normal activities */ - for (i = 0; i < server_list->_length; i++) - { - Accessibility_LoginHelper helper = helper_list[i]; - /* really no need to check the return value this time */ - Accessibility_LoginHelper_setSafe (helper, FALSE, &ev); - if (BONOBO_EX (&ev)) - { - g_warning ("setSafe(FALSE) failed: %s", - bonobo_exception_get_text (&ev)); - CORBA_exception_free (&ev); - } - CORBA_Object_release (helper, &ev); - } - CORBA_free (server_list); - - return bonobo_debug_shutdown (); /* see if we leaked stuff */ -} diff --git a/test/login-helper-server-test.c b/test/login-helper-server-test.c deleted file mode 100644 index bfa8c205..00000000 --- a/test/login-helper-server-test.c +++ /dev/null @@ -1,162 +0,0 @@ -#include <libbonobo.h> -#include <login-helper/login-helper.h> -#include <gtk/gtkmain.h> -#include <gtk/gtkwindow.h> -#include <gdk/gdkx.h> -#include <X11/Xatom.h> - -static void test_init_login_helper_vpointers (LoginHelper *helper, - gpointer test_set_safe, - gpointer test_get_device_reqs, - gpointer test_get_raise_windows); - -static gboolean test_set_safe (LoginHelper *helper, gboolean safe); - -static LoginHelperDeviceReqFlags test_get_device_reqs (LoginHelper *helper); - -static Window* test_get_raise_windows (LoginHelper *helper); - -static void test_post_window (void); - -static void test_set_wm_dock (void); - -static GtkWidget *mainwin = NULL; - -int -main (int argc, char **argv) -{ - int ret; - char *obj_id; - BonoboObject *helper; - - if (!bonobo_init (&argc, argv)) - { - g_error ("Could not initialize oaf / Bonobo"); - } - - obj_id = "OAFIID:GNOME_TEST:1.0"; /* just for testing, install manually */ - - helper = BONOBO_OBJECT (g_object_new (LOGIN_HELPER_TYPE, NULL)); - - ret = bonobo_activation_register_active_server ( - obj_id, - bonobo_object_corba_objref (bonobo_object (helper)), - NULL); - - if (ret != Bonobo_ACTIVATION_REG_SUCCESS) - { - switch (ret) - { - case Bonobo_ACTIVATION_REG_NOT_LISTED: - fprintf (stderr, "OAFIID not listed\n"); - break; - default: - fprintf (stderr, "Registration Error: %d\n", ret); - break; - } - } - else - { - CORBA_Environment ev; - Bonobo_Unknown ret; - CORBA_exception_init (&ev); - - ret = Bonobo_Unknown_queryInterface ( - BONOBO_OBJREF (helper), - "IDL:Accessibility/LoginHelper:1.0", - &ev); - - if (BONOBO_EX (&ev)) - { - fprintf (stderr, "queryInterface error: %s\n", - bonobo_exception_get_text (&ev)); - } - else - { - fprintf (stderr, "query returned %p: objref self = %p\n", - ret, BONOBO_OBJREF (helper)); - } - } - - /* this is a testing hack - we are changing the LoginHelperClass's vpointers here */ - - test_init_login_helper_vpointers ((LoginHelper*)helper, test_set_safe, test_get_device_reqs, test_get_raise_windows); - - gtk_init (&argc, &argv); - - test_post_window (); - - bonobo_main (); - - return 0; -} - -static void -test_init_login_helper_vpointers (LoginHelper *helper, - gpointer set_safe_func, - gpointer get_device_reqs_func, - gpointer get_raise_windows_func) -{ - LoginHelperClass *klass = LOGIN_HELPER_GET_CLASS (helper); - klass->set_safe = set_safe_func; - klass->get_device_reqs = get_device_reqs_func; - klass->get_raise_windows = get_raise_windows_func; -} - -static gboolean -test_set_safe (LoginHelper *helper, gboolean safe) -{ - return TRUE; -} - -static LoginHelperDeviceReqFlags -test_get_device_reqs (LoginHelper *helper) -{ - return LOGIN_HELPER_POST_WINDOWS; -} - -static Window* -test_get_raise_windows (LoginHelper *helper) -{ - Window *winlist = g_new0 (Window, 2); - winlist[0] = GDK_WINDOW_XWINDOW (mainwin->window); - winlist[1] = None; - return winlist; -} - - -void -test_set_wm_dock (void) -{ - Atom atom_type[1], atom_window_type; - - gtk_widget_hide (mainwin); - - gdk_error_trap_push (); - atom_window_type = gdk_x11_get_xatom_by_name ("_NET_WM_WINDOW_TYPE"); - - atom_type[0] = gdk_x11_get_xatom_by_name ("_NET_WM_WINDOW_TYPE_DOCK"); - - XChangeProperty (GDK_WINDOW_XDISPLAY (mainwin->window), - GDK_WINDOW_XWINDOW (mainwin->window), - atom_window_type, - XA_ATOM, 32, PropModeReplace, - (guchar *) &atom_type, 1); - gdk_error_trap_pop (); - - gtk_widget_show (mainwin); - -} - -static void -test_post_window (void) -{ - mainwin = gtk_window_new (GTK_WINDOW_TOPLEVEL); - - gtk_window_set_screen (GTK_WINDOW (mainwin), gdk_screen_get_default ()); - - /* gtk_window_set_keep_above (GTK_WINDOW (mainwin), true); optional */ - /* test_set_wm_dock (); optional */ - - gtk_widget_show_all (mainwin); -} diff --git a/test/screen-review-test.c b/test/screen-review-test.c deleted file mode 100644 index 1b5fa2ea..00000000 --- a/test/screen-review-test.c +++ /dev/null @@ -1,1121 +0,0 @@ -/* - * AT-SPI - Assistive Technology Service Provider Interface - * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap) - * - * 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 - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include "../cspi/spi-private.h" - -#undef CLIP_DEBUG - -/* - * Screen Review Algorithm Demonstration, Benchmark, and Test-bed. - * - * Issues: - * - * * there are bugs in the compositing code. - * - * * brute-force algorithm uses no client-side cache; performance mediocre. - * - * * we don't have good ordering information for the toplevel windows, - * and our current heuristic is not guaranteed if - * the active window is not always on top (i.e. autoraise is - * not enabled). - * - * * can't know about "inaccessible" objects that may be obscuring the - * accessible windows (inherent to API-based approach). - * - * * text column alignment is crude since it relies on a hard-coded - * (and arbitrary) ratio of horizontal pixels to character columns. - * For small proportional fonts, overruns are likely to result in - * occasional review lines that exceed the standard length. - * - * * (others). - */ - -#undef CHUNK_LIST_DEBUG /* define to get list of text chunks before clip */ - -#define BOUNDS_CONTAIN_X_BOUNDS(b, p) ( ((p).x>=(b).x) &&\ - (((p).x + (p).width) <= \ - ((b).x + (b).width)) && \ - ((b).width > 0) && ((b).height > 0)) - -#define BOUNDS_CONTAIN_Y(b, p) (((p)>=(b)->y) && ((p)<=((b)->y + (b)->height))\ - && ((b)->width > 0) && ((b)->height > 0)) - -#define CHUNK_BOUNDS_BEFORE_START(c, i) ((i) && ((c)->clip_bounds.x < \ - (i)->clip_bounds.x)) - -#define CHUNK_BOUNDS_END_BEFORE_START(c, i) ((i) && \ - (((c)->clip_bounds.x + \ - (c)->clip_bounds.width) < \ - (i)->clip_bounds.x)) - -#define CHUNK_BOUNDS_AFTER_END(c, i) ((i) && ((c)->clip_bounds.x >= \ - ((i)->clip_bounds.x + \ - (i)->clip_bounds.width))) - -#define CHUNK_BOUNDS_SPANS_END(c, i) ((i) && (((c)->clip_bounds.x + \ - (c)->clip_bounds.width) >= \ - ((i)->clip_bounds.x + \ - (i)->clip_bounds.width))) -/* - * #define CHUNK_BOUNDS_WITHIN(c, i) ((i) && ((c)->clip_bounds.x >= \ - * (i)->text_bounds.x) && \ - * (((c)->clip_bounds.x + (c)->clip_bounds.width) \ - * <= ((i)->text_bounds.x + (i)->text_bounds.width))) - */ - -#define IS_CLIPPING_CONTAINER(a) ((a) != SPI_ROLE_PAGE_TAB) - -static void report_screen_review_line (const AccessibleEvent *event, void *user_data); - -static AccessibleEventListener *mouseclick_listener; - -typedef struct _BoundaryRect { - long int x; - long int y; - long int width; - long int height; - AccessibleRole role; /* role of last clipping element */ - gboolean isClipped; - gboolean isEmpty; -} BoundaryRect; - -typedef struct _TextChunk { - char *string; - Accessible *source; - int start_offset; - int end_offset; - BoundaryRect clip_bounds; - BoundaryRect text_bounds; - BoundaryRect start_char_bounds; - BoundaryRect end_char_bounds; -} TextChunk; - -typedef struct _ScreenReviewBuffer { - GList *text_chunks; -} ScreenReviewBuffer; - -static gboolean isJava = FALSE; - -int -main (int argc, char **argv) -{ - SPI_init (); - - mouseclick_listener = SPI_createAccessibleEventListener ( - report_screen_review_line, NULL); - - SPI_registerGlobalEventListener (mouseclick_listener, - "Gtk:GtkWidget:button-press-event"); -#undef JAVA_TEST_HACK -#ifdef JAVA_TEST_HACK /* Only use this to test Java apps */ - SPI_registerGlobalEventListener (mouseclick_listener, - "object:text-caret-moved"); - isJava = TRUE; -#endif - SPI_event_main (); - - putenv ("AT_BRIDGE_SHUTDOWN=1"); - - /* - * TODO: Add a key event listener that calls test_exit, to - * deregister and cleanup appropriately. - */ - - return SPI_exit (); -} - -static inline gboolean -chunk_bounds_within (TextChunk *chunk, TextChunk *test_chunk) -{ - int x1, tx1; - gboolean gtx1, ltx2; - - x1 = chunk->clip_bounds.x; - tx1 = test_chunk->clip_bounds.x; - gtx1 = (chunk->clip_bounds.x >= test_chunk->clip_bounds.x); - ltx2 = (chunk->clip_bounds.x + chunk->clip_bounds.width - <= test_chunk->clip_bounds.x + test_chunk->clip_bounds.width); - return gtx1 && ltx2; -} - -#define CHUNK_BOUNDS_WITHIN(a, b) chunk_bounds_within(a, b) - -static BoundaryRect ** -clip_bounds_clone (BoundaryRect *bounds[]) -{ - int i; - BoundaryRect **bounds_clone; - bounds_clone = (BoundaryRect **) - g_new0 (gpointer, SPI_LAYER_LAST_DEFINED); - for (i = 1; i < SPI_LAYER_LAST_DEFINED; ++i) { - bounds_clone[i] = g_new0 (BoundaryRect, 1); - *bounds_clone[i] = *bounds[i]; - } - return bounds_clone; -} - -static void -boundary_clip (BoundaryRect *bounds, BoundaryRect *clipBounds) -{ - int x2 = bounds->x + bounds->width; - int y2 = bounds->y + bounds->height; -#ifdef CLIP_DEBUG - fprintf (stderr, "bclip %d-%d, %d-%d; ", - bounds->x, x2, - clipBounds->x, clipBounds->x+clipBounds->width); -#endif - bounds->x = MAX (bounds->x, clipBounds->x); - bounds->y = MAX (bounds->y, clipBounds->y); - x2 = MIN (x2, clipBounds->x + clipBounds->width); - y2 = MIN (y2, clipBounds->y + clipBounds->height); - bounds->width = MAX (x2 - bounds->x, 0); - bounds->height = MAX (y2 - bounds->y, 0); - if (!bounds->width || !bounds->height) - bounds->isEmpty = TRUE; - if (IS_CLIPPING_CONTAINER (bounds->role)) { - *clipBounds = *bounds; - } -#ifdef CLIP_DEBUG - fprintf (stderr, "%d-%d\n", - bounds->x, bounds->x+bounds->width); -#endif -} - -static void -boundary_xclip_head (BoundaryRect *bounds, BoundaryRect *clipBounds) -{ - int x2; - int cx2 = clipBounds->x + clipBounds->width; - if (cx2 < bounds->x) return; - x2 = bounds->x + bounds->width; - if (cx2 <= x2) bounds->x = cx2; - bounds->width = MAX (0, x2 - cx2); -} - -static void -boundary_xclip_tail (BoundaryRect *bounds, BoundaryRect *clipBounds) -{ - int x2 = bounds->x + bounds->width; - if (clipBounds->x > x2) return; - bounds->width = MAX (0, clipBounds->x - bounds->x); -} - -static TextChunk* -text_chunk_copy (TextChunk *chunk) -{ - TextChunk *copy = g_new0 (TextChunk, 1); - *copy = *chunk; - if (chunk->string) copy->string = g_strdup (chunk->string); - if (copy->source) Accessible_ref (copy->source); - return copy; -} - -static void -text_chunk_tail_clip (TextChunk *bottom, TextChunk *top) -{ -#ifdef CLIP_DEBUG - fprintf (stderr, "bottom %d-%d, top %d-%d;", - bottom->clip_bounds.x, - bottom->clip_bounds.x + bottom->clip_bounds.width, - top->clip_bounds.x, - top->clip_bounds.x + top->clip_bounds.width); -#endif - boundary_xclip_tail (&bottom->text_bounds, &top->clip_bounds); - boundary_xclip_tail (&bottom->clip_bounds, &top->clip_bounds); - bottom->text_bounds.isClipped = TRUE; - bottom->clip_bounds.isClipped = TRUE; -#ifdef CLIP_DEBUG - fprintf (stderr, "result %d-%d\n", - bottom->clip_bounds.x, - bottom->clip_bounds.x + bottom->clip_bounds.width); -#endif -} - -static void -text_chunk_head_clip (TextChunk *bottom, TextChunk *top) -{ -#ifdef CLIP_DEBUG - fprintf (stderr, "bottom %d-%d, top %d-%d;", - bottom->clip_bounds.x, - bottom->clip_bounds.x + bottom->clip_bounds.width, - top->clip_bounds.x, - top->clip_bounds.x + top->clip_bounds.width); -#endif - boundary_xclip_head (&bottom->text_bounds, &top->clip_bounds); - boundary_xclip_head (&bottom->clip_bounds, &top->clip_bounds); - bottom->text_bounds.isClipped = TRUE; - bottom->clip_bounds.isClipped = TRUE; -#ifdef CLIP_DEBUG - fprintf (stderr, "result %d-%d\n", - bottom->clip_bounds.x, - bottom->clip_bounds.x + bottom->clip_bounds.width); -#endif -} - -static GList * -text_chunk_split_insert (GList *chunk_list, GList *iter, TextChunk *chunk) -{ - TextChunk *iter_chunk = iter->data; - TextChunk *iter_copy = text_chunk_copy (iter_chunk); - /* TODO: FIXME something is wrong here */ -#ifdef CLIP_DEBUG - fprintf (stderr, "***clip insert of %s into %s\n", - chunk->string ? chunk->string : "<null>", - iter_chunk->string ? iter_chunk->string : "<null>"); -#endif - chunk_list = g_list_insert_before (chunk_list, iter, iter_copy); - text_chunk_tail_clip (iter_copy, chunk); - chunk_list = g_list_insert_before (chunk_list, iter, chunk); - text_chunk_head_clip (iter_chunk, chunk); - return chunk_list; -} - -/* #define PRINT_CHUNK_DEBUG(a, b, c, d) print_chunk_debug(a, b, c, d) */ - -#define PRINT_CHUNK_DEBUG(a, b, c, d) - -#ifdef PRINT_CHUNK_DEBUG -static void -print_chunk_debug (TextChunk *chunk, char *opname, GList *prev, GList *next) -{ - fprintf (stderr, "%sing chunk %s between %s and %s; %ld-%ld\n", - opname, - chunk->string, - (prev ? ((TextChunk *) prev->data)->string : "<null>"), - (next ? ((TextChunk *) next->data)->string : "<null>"), - chunk->clip_bounds.x, - chunk->text_bounds.x + chunk->text_bounds.width); -} -#endif - -static GList * -text_chunk_list_head_clip (GList *text_chunk_list, - TextChunk *chunk, - GList *next) -{ - GList *target, *iter = next, *prev; - prev = iter->prev; -/* if (chunk->string && strlen (chunk->string)) { */ - text_chunk_list = - g_list_insert_before (text_chunk_list, next, chunk); -/* }*/ - while (iter && CHUNK_BOUNDS_SPANS_END (chunk, (TextChunk *)iter->data)) { -#ifdef CLIP_DEBUG - fprintf (stderr, "deleting %s\n", - ((TextChunk *)iter->data)->string); -#endif - target = iter; - iter = iter->next; - text_chunk_list = - g_list_delete_link (text_chunk_list, target); - } - if (iter && !CHUNK_BOUNDS_END_BEFORE_START (chunk, - (TextChunk *)iter->data)) { - text_chunk_head_clip ((TextChunk *)iter->data, - chunk); - } - if (prev && - !CHUNK_BOUNDS_AFTER_END ( - chunk, - (TextChunk *)prev->data)) { - text_chunk_tail_clip ( - (TextChunk *)prev->data, - chunk); - } - - return text_chunk_list; -} - -static GList * -text_chunk_list_clip_and_insert (GList *text_chunk_list, - TextChunk *chunk, - GList *prev, - GList *next) -{ -#ifdef CLIP_DEBUG -/* if (chunk->string) */ - fprintf (stderr, "clip-and-insert for %s, between %s (%d) and %s (%d)\n", - chunk->string, - (prev && ((TextChunk *)prev->data)->string ? ((TextChunk *)prev->data)->string : "<null>"), - (prev ? ((TextChunk *)prev->data)->text_bounds.x : -1), - (next && ((TextChunk *)next->data)->string ? ((TextChunk *)next->data)->string : "<null>"), - (next ? ((TextChunk *)next->data)->text_bounds.x : -1)); -#endif - /* cases: */ - if (!prev && !next) { /* first element in, no clip needed */ - text_chunk_list = - g_list_append (text_chunk_list, chunk); - PRINT_CHUNK_DEBUG (chunk, "append", - prev, - NULL); - } else { /* check for clip with prev */ - /* if we split the prev */ - if (prev && - CHUNK_BOUNDS_WITHIN (chunk, (TextChunk *) prev->data)) { - text_chunk_list = - text_chunk_split_insert ( - text_chunk_list, - prev, chunk); - } else if (next) { - /* we split the 'next' element */ - if (CHUNK_BOUNDS_WITHIN (chunk, (TextChunk *)next->data)) { - text_chunk_list = - text_chunk_split_insert (text_chunk_list, - next, chunk); - } else { - /* do an insert + head clip */ - text_chunk_list = - text_chunk_list_head_clip ( - text_chunk_list, - chunk, - next); - } - } else { - if (!CHUNK_BOUNDS_AFTER_END (chunk, - (TextChunk *) prev->data)) { - text_chunk_tail_clip (prev->data, chunk); - } - text_chunk_list = - g_list_append (text_chunk_list, chunk); - } - } - return text_chunk_list; -} - -static GList * -text_chunk_list_insert_chunk (GList *text_chunk_list, TextChunk *chunk) -{ - GList *iter = g_list_first (text_chunk_list); - TextChunk *iter_chunk = NULL; - do { - if (iter) iter_chunk = (TextChunk *) iter->data; - /* if we're ahead of the current element */ - if (!iter) { - text_chunk_list = - text_chunk_list_clip_and_insert (text_chunk_list, - chunk, - iter, - NULL); - break; - } else if (CHUNK_BOUNDS_BEFORE_START (chunk, iter_chunk)) { - text_chunk_list = - text_chunk_list_clip_and_insert (text_chunk_list, - chunk, - iter->prev, - iter); - break; - } else if (!iter->next ) { - text_chunk_list = - text_chunk_list_clip_and_insert (text_chunk_list, - chunk, - iter, - NULL); - break; - } - if (iter) iter = iter->next; - } while (iter); - return text_chunk_list; -} - -static TextChunk * -review_buffer_get_text_chunk (ScreenReviewBuffer *reviewBuffer, - Accessible *accessible, BoundaryRect *bounds, - int screen_x, int screen_y) -{ - AccessibleText *text = NULL; - AccessibleRole role; - TextChunk *text_chunk; - char *s = NULL; - int offset; - long start, end; - long x2, y2; - - role = Accessible_getRole (accessible); - text_chunk = g_new0 (TextChunk, 1); - text_chunk->clip_bounds = *bounds; - text_chunk->source = accessible; - Accessible_ref (accessible); - if (Accessible_isText (accessible)) { - text = Accessible_getText (accessible); - offset = AccessibleText_getOffsetAtPoint (text, - screen_x, - screen_y, - SPI_COORD_TYPE_SCREEN); - s = AccessibleText_getTextAtOffset (text, offset, - SPI_TEXT_BOUNDARY_LINE_START, - &start, &end); - if (end > start) { - AccessibleText_getCharacterExtents ( - text, start, - &text_chunk->start_char_bounds.x, - &text_chunk->start_char_bounds.y, - &text_chunk->start_char_bounds.width, - &text_chunk->start_char_bounds.height, - SPI_COORD_TYPE_SCREEN); -#ifdef CLIP_DEBUG - fprintf (stderr, "%s: start char (%d) x, width %d %d; ", - s, - start, - text_chunk->start_char_bounds.x, - text_chunk->start_char_bounds.width); -#endif - if (s && strlen (s) && s[strlen (s) - 1] == '\n') - end--; - AccessibleText_getCharacterExtents ( - text, end - 1, - &text_chunk->end_char_bounds.x, - &text_chunk->end_char_bounds.y, - &text_chunk->end_char_bounds.width, - &text_chunk->end_char_bounds.height, - SPI_COORD_TYPE_SCREEN); -#ifdef CLIP_DEBUG - fprintf (stderr, "end char (%d) x, width %d %d\n", - end - 1, - text_chunk->end_char_bounds.x, - text_chunk->end_char_bounds.width); -#endif - } - text_chunk->text_bounds.x = MIN (text_chunk->start_char_bounds.x, - text_chunk->end_char_bounds.x); - text_chunk->text_bounds.y = MIN (text_chunk->start_char_bounds.y, - text_chunk->end_char_bounds.y); - x2 = MAX (text_chunk->start_char_bounds.x + - text_chunk->start_char_bounds.width, - text_chunk->end_char_bounds.x + - text_chunk->end_char_bounds.width); - text_chunk->text_bounds.width = x2 - text_chunk->text_bounds.x; - y2 = MAX (text_chunk->start_char_bounds.y + - text_chunk->start_char_bounds.height, - text_chunk->end_char_bounds.y + - text_chunk->end_char_bounds.height); - text_chunk->text_bounds.height = y2 - text_chunk->text_bounds.y; - text_chunk->start_offset = start; - text_chunk->end_offset = end; - AccessibleText_unref (text); - } else { - if (role == SPI_ROLE_PUSH_BUTTON || - role == SPI_ROLE_CHECK_BOX || - role == SPI_ROLE_LABEL || - role == SPI_ROLE_MENU || - role == SPI_ROLE_MENU_ITEM) { /* don't like this - special casing :-( */ - s = Accessible_getName (accessible); - /* use name instead */ - text_chunk->text_bounds = text_chunk->clip_bounds; - text_chunk->start_offset = 0; - text_chunk->end_offset = strlen (s); - } - } - if (text_chunk->text_bounds.x < text_chunk->clip_bounds.x) { - text_chunk->text_bounds.x = text_chunk->clip_bounds.x; - text_chunk->text_bounds.isClipped = TRUE; - } - if ((text_chunk->text_bounds.x + - text_chunk->text_bounds.width) - > (text_chunk->clip_bounds.x + - text_chunk->clip_bounds.width)) { - text_chunk->text_bounds.width = - MAX (0, (text_chunk->clip_bounds.x + - text_chunk->clip_bounds.width) - - text_chunk->text_bounds.x); - text_chunk->text_bounds.isClipped = TRUE; - } - if (!BOUNDS_CONTAIN_Y (&text_chunk->text_bounds, - screen_y)) { -#ifdef CLIP_DEBUG - fprintf (stderr, "%s out of bounds (%d-%d)\n", s, - text_chunk->text_bounds.y, - text_chunk->text_bounds.y + - text_chunk->text_bounds.height); -#endif - s = NULL; - text_chunk->start_offset = offset; - text_chunk->end_offset = offset; - } - if (s && strlen (s)) { - if (s[strlen(s)-1] == '\n') s[strlen(s)-1] = ' '; - /* XXX: if last char is newline, aren't its bounds wrong now? */ - text_chunk->string = s; -#ifdef CLIP_DEBUG - fprintf (stderr, "%s, bounds %d-%d; clip %d-%d\n", - s, - text_chunk->text_bounds.x, - text_chunk->text_bounds.x+text_chunk->text_bounds.width, - text_chunk->clip_bounds.x, - text_chunk->clip_bounds.x+text_chunk->clip_bounds.width); -#endif - } else { - text_chunk->string = NULL; - } - return text_chunk; -} - -#ifdef CHUNK_LIST_DEBUG -static void -debug_chunk_list (GList *iter) -{ - TextChunk *chunk; - while (iter) { - chunk = (TextChunk *)iter->data; - fprintf (stderr, "Chunk %s, clip %ld-%ld, text %ld-%ld\n", - chunk->string, - chunk->clip_bounds.x, - chunk->clip_bounds.x + chunk->clip_bounds.width, - chunk->text_bounds.x, - chunk->text_bounds.x + chunk->text_bounds.width); - iter = iter->next; - } -} -#endif - -static void -clip_into_buffers (Accessible *accessible, BoundaryRect* parentClipBounds[], - ScreenReviewBuffer *reviewBuffers[], - int screen_x, int screen_y) -{ - int n_children, child_n; - Accessible *child; - BoundaryRect bounds; - BoundaryRect** clip_bounds; - TextChunk *text_chunk; - AccessibleComponent *component; - AccessibleRole role; - int layer; - - clip_bounds = clip_bounds_clone (parentClipBounds); - if (Accessible_isComponent (accessible)) { - role = Accessible_getRole (accessible); - component = Accessible_getComponent (accessible); - layer = AccessibleComponent_getLayer (component); - bounds = *clip_bounds[layer]; - if (!bounds.isEmpty) { - AccessibleComponent_getExtents (component, - &bounds.x, - &bounds.y, - &bounds.width, - &bounds.height, - SPI_COORD_TYPE_SCREEN); - bounds.role = role; - if (clip_bounds[layer]) - boundary_clip (&bounds, clip_bounds[layer]); - if (BOUNDS_CONTAIN_Y (&bounds, screen_y)) { - text_chunk = review_buffer_get_text_chunk ( - reviewBuffers[layer], accessible, &bounds, - screen_x, screen_y); - reviewBuffers[layer]->text_chunks = - text_chunk_list_insert_chunk ( - reviewBuffers[layer]->text_chunks, - text_chunk); - } else { - bounds.isEmpty = - IS_CLIPPING_CONTAINER (bounds.role); - } - } - Accessible_unref (component); - } - /* - * we always descend into children in case they are in a higher layer - * this can of course be optimized for the topmost layer... - * but nobody uses that one! (SPI_LAYER_OVERLAY) - */ - n_children = Accessible_getChildCount (accessible); - for (child_n = 0; child_n < n_children; ++child_n) { - child = Accessible_getChildAtIndex (accessible, child_n); - clip_into_buffers (child, clip_bounds, reviewBuffers, screen_x, screen_y); - Accessible_unref (child); - } - /* TODO: free the parent clip bounds */ -} - -#undef CHARACTER_CLIP_DEBUG - -static char* -text_chunk_get_clipped_substring_by_char (TextChunk *chunk, int start, int end) -{ - BoundaryRect char_bounds; - int i; - char *s; - GString *string = g_string_new (""); - gunichar c; - AccessibleText *text = Accessible_getText (chunk->source); - for (i = start; i < end; ++i) { - AccessibleText_getCharacterExtents (text, - i, - &char_bounds.x, - &char_bounds.y, - &char_bounds.width, - &char_bounds.height, - SPI_COORD_TYPE_SCREEN); -#ifdef CHARACTER_CLIP_DEBUG - fprintf (stderr, "testing %d-%d against %d-%d\n", - char_bounds.x, char_bounds.x+char_bounds.width, - chunk->text_bounds.x, - chunk->text_bounds.x + chunk->text_bounds.width); -#endif - if (BOUNDS_CONTAIN_X_BOUNDS (chunk->text_bounds, - char_bounds)) { - c = AccessibleText_getCharacterAtOffset ( - text, i); -#ifdef CLIP_DEBUG - fprintf (stderr, "[%c]", c); -#endif - g_string_append_unichar (string, c); - } - } - AccessibleText_unref (text); - s = string->str; - g_string_free (string, FALSE); - return s; -} - - -/* - * Note: this routine shouldn't have to do as much as it currently does, - * but at the moment it works around another bug (probably one in this - * code). - */ -static char * -string_strip_newlines (char *s, long offset, long *start_offset, long *end_offset) -{ - int i; - char *word_start = s; - /* FIXME: potential memory leak here */ - for (i=0; s && s[i]; ++i) - { - if (s [i] == '\n' && i > (offset - *start_offset) ) { - s [i] = '\0'; - *end_offset = *start_offset + i; - return word_start; - } else if (s [i] == '\n') { - word_start = &s[i + 1]; - } - } - return word_start; -} - -static char * -string_guess_clip (TextChunk *chunk) -{ - BoundaryRect b; - char *s = NULL, *sp = chunk->string, *ep; - long start_offset, end_offset, len; - if (sp) { - AccessibleComponent *component = - Accessible_getComponent (chunk->source); - ep = sp + (strlen (sp)); - len = g_utf8_strlen (chunk->string, -1); - if (component) { - AccessibleComponent_getExtents (component, - &b.x, &b.y, - &b.width, &b.height, - SPI_COORD_TYPE_SCREEN); - start_offset = len * (chunk->text_bounds.x - b.x) / b.width; - end_offset = len * (chunk->text_bounds.x + - chunk->text_bounds.width - b.x) / b.width; - fprintf (stderr, "String len %ld, clipped to %ld-%ld\n", - len, start_offset, end_offset); - len = end_offset - start_offset; - sp = g_utf8_offset_to_pointer (chunk->string, start_offset); - ep = g_utf8_offset_to_pointer (chunk->string, end_offset); - } - s = g_new0 (char, ep - sp + 1); - s = g_utf8_strncpy (s, sp, len); - s [sp - ep] = '\0'; - g_assert (g_utf8_validate (s, -1, NULL)); - } - return s; -} - -static char* -text_chunk_get_clipped_string (TextChunk *chunk) -{ - char *s, *string = ""; - long start = chunk->start_offset, end = chunk->end_offset; - long word_start, word_end, range_end; - BoundaryRect start_bounds, end_bounds; - gboolean start_inside, end_inside; - if (!chunk->text_bounds.isClipped || !chunk->string) - string = chunk->string; - else if (chunk->source && Accessible_isText (chunk->source)) { - /* while words at offset lie within the bounds, add them */ - AccessibleText *text = Accessible_getText (chunk->source); -#ifdef CLIP_DEBUG - fprintf (stderr, "clipping %s\n", chunk->string); -#endif - do { - s = AccessibleText_getTextAtOffset (text, - start, - SPI_TEXT_BOUNDARY_WORD_END, - &word_start, - &word_end); - range_end = word_end; - s = string_strip_newlines (s, start, &word_start, &word_end); - AccessibleText_getCharacterExtents (text, - word_start, - &start_bounds.x, - &start_bounds.y, - &start_bounds.width, - &start_bounds.height, - SPI_COORD_TYPE_SCREEN); - AccessibleText_getCharacterExtents (text, - word_end - 1, - &end_bounds.x, - &end_bounds.y, - &end_bounds.width, - &end_bounds.height, - SPI_COORD_TYPE_SCREEN); - start_inside = BOUNDS_CONTAIN_X_BOUNDS (chunk->text_bounds, - start_bounds); - end_inside = BOUNDS_CONTAIN_X_BOUNDS (chunk->text_bounds, - end_bounds); - if (start_inside && end_inside) { - /* word is contained in bounds */ - string = g_strconcat (string, s, NULL); - } else if (start_inside || end_inside) { - /* one end of word is in */ - if (word_end > end) word_end = end; - s = text_chunk_get_clipped_substring_by_char ( - chunk, - MAX (word_start, chunk->start_offset), - MIN (word_end, chunk->end_offset)); - string = g_strconcat (string, s, NULL); - } else { - } - start = range_end; - } while (start < chunk->end_offset); - } else { /* we're clipped, but don't implement AccessibleText :-( */ - /* guess for now, maybe we can do better someday */ - string = string_guess_clip (chunk); - } - return string; -} - - -static char* -text_chunk_pad_string (TextChunk *chunk, char *string, glong offset, const char *pad_chars) -{ - char *s = ""; - char *cp; - char startbuf[6], padbuf[6], endbuf[6]; - int pixels_per_column = 6; - /* this is an arbitrary pixel-to-textcolumn mapping at present */ - glong end_padding; - gint howmany; - howmany = g_unichar_to_utf8 (g_utf8_get_char (pad_chars), startbuf); - startbuf[howmany] = '\0'; - g_assert (howmany < 7 && howmany > 0); - cp = g_utf8_find_next_char (pad_chars, NULL); - howmany = g_unichar_to_utf8 (g_utf8_get_char (cp), padbuf); - padbuf[howmany] = '\0'; - g_assert (howmany < 7 && howmany > 0); - cp = g_utf8_find_next_char (cp, NULL); - howmany = g_unichar_to_utf8 (g_utf8_get_char (cp), endbuf); - endbuf[howmany] = '\0'; - g_assert (howmany < 7 && howmany > 0); - end_padding = chunk->clip_bounds.x / pixels_per_column; - while (offset < end_padding - 1) { - s = g_strconcat (s, padbuf, NULL); /* could be more efficient */ - ++offset; - } - s = g_strconcat (s, startbuf, string, NULL); - offset += g_utf8_strlen (string, -1) + 1; - end_padding = chunk->text_bounds.x / pixels_per_column; - while (offset < end_padding) { - s = g_strconcat (s, padbuf, NULL); /* could be more efficient */ - ++offset; - } - end_padding = (chunk->clip_bounds.x + chunk->clip_bounds.width) / - pixels_per_column; - while (offset < end_padding - 1) { - s = g_strconcat (s, padbuf, NULL); /* could be more efficient */ - ++offset; - } - s = g_strconcat (s, endbuf, NULL); - return s; -} - -static char* -text_chunk_to_string (TextChunk *chunk, glong offset) -{ - char *s = NULL; - if (chunk->string) { - s = text_chunk_get_clipped_string (chunk); - if (chunk->clip_bounds.role == SPI_ROLE_PUSH_BUTTON) { - s = text_chunk_pad_string (chunk, s, offset, "[ ]"); - } else if (chunk->clip_bounds.role == SPI_ROLE_FRAME) { - s = text_chunk_pad_string (chunk, s, offset, "| |"); - } else if (chunk->clip_bounds.role == SPI_ROLE_TEXT) { - s = text_chunk_pad_string (chunk, s, offset, "\" \""); - } else { - s = text_chunk_pad_string (chunk, s, offset, " "); - } - } - return s; -} - -static char* -text_chunk_list_to_string (GList *iter) -{ - char *s = ""; - char *string; - TextChunk *chunk = NULL; - while (iter) { - chunk = (TextChunk *)iter->data; - if (chunk) { - string = text_chunk_to_string (chunk, g_utf8_strlen (s, -1)); - if (string) - s = g_strconcat (s, string, NULL); - } - iter = iter->next; - } - s = g_strconcat (s, "|", NULL); - return s; -} - -#define COMPOSITE_DEBUG - -static void -toplevel_composite (ScreenReviewBuffer *buffers[]) -{ - int i; - GList *chunk_list, *iter; - TextChunk *chunk; - - chunk_list = buffers[SPI_LAYER_CANVAS]->text_chunks; - for (i = SPI_LAYER_MDI; i < SPI_LAYER_OVERLAY; ++i) { - iter = buffers[i]->text_chunks; -#ifdef COMPOSITE_DEBUG - fprintf (stderr, "layer %d has %d chunks\n", - i, g_list_length (iter)); -#endif - while (iter) { - chunk = (TextChunk *) iter->data; - if (chunk) { -#ifdef COMPOSITE_DEBUG - fprintf (stderr, "inserting chunk <%s>\n", - chunk->string ? chunk->string : "<null>"); -#endif - chunk_list = - text_chunk_list_insert_chunk (chunk_list, - chunk); - } - iter = iter->next; - } - } -} - -static char* -review_buffer_composite (ScreenReviewBuffer *buffers[]) -{ - /* TODO: FIXME: something is wrong here, compositing fails */ - int i; - GList *chunk_list, *iter; - TextChunk *chunk; - chunk_list = buffers[SPI_LAYER_BACKGROUND]->text_chunks; - for (i = 2; i < SPI_LAYER_LAST_DEFINED; ++i) { - if (i == SPI_LAYER_WIDGET) i = SPI_LAYER_OVERLAY; - /* - * Q: why skip these layers ? - * A: since layers WIDGET, MDI, and POPUP have already been - * composited into layer CANVAS for each toplevel before this - * routine is called. - */ - iter = buffers[i]->text_chunks; -#ifdef CLIP_DEBUG - fprintf (stderr, "layer %d has %d chunks\n", - i, g_list_length (iter)); -#endif - while (iter) { - chunk = (TextChunk *) iter->data; - if (chunk) { -#ifdef CLIP_DEBUG - fprintf (stderr, "inserting chunk <%s>\n", - chunk->string ? chunk->string : "<null>"); -#endif - chunk_list = - text_chunk_list_insert_chunk (chunk_list, - chunk); - } - iter = iter->next; - } - } - - chunk_list = buffers[SPI_LAYER_WIDGET]->text_chunks; - return text_chunk_list_to_string (chunk_list); -} - -static char * -get_screen_review_line_at (int x, int y) -{ - char *string; - Accessible *desktop, *app, *toplevel; - AccessibleComponent *component; - AccessibleStateSet *states; - GList *toplevels = NULL, *actives = NULL, *iter; - ScreenReviewBuffer* reviewBuffers[SPI_LAYER_LAST_DEFINED]; - BoundaryRect* clip_bounds[SPI_LAYER_LAST_DEFINED]; - BoundaryRect toplevel_bounds; - int n_apps, n_toplevels, app_n, toplevel_n; - GTimer *timer = g_timer_new (); - int i; - - for (i = 1; i < SPI_LAYER_LAST_DEFINED; ++i) { - reviewBuffers[i] = g_new0 (ScreenReviewBuffer, 1); - clip_bounds[i] = g_new0 (BoundaryRect, 1); - clip_bounds[i]->isClipped = FALSE; - clip_bounds[i]->isEmpty = FALSE; - } - - /* how do we decide which desktop ? */ - desktop = SPI_getDesktop (0); - - /* for each app */ - n_apps = Accessible_getChildCount (desktop); - for (app_n = 0; app_n < n_apps; ++app_n) { - /* for each toplevel in app */ - app = Accessible_getChildAtIndex (desktop, app_n); - n_toplevels = Accessible_getChildCount (app); - for (toplevel_n = 0; toplevel_n < n_toplevels; ++toplevel_n) { - Accessible *toplevel = Accessible_getChildAtIndex (app, toplevel_n); - if (Accessible_isComponent (toplevel)) - toplevels = g_list_prepend (toplevels, toplevel); - else { - Accessible_unref (toplevel); - fprintf (stderr, "warning, app toplevel not a component.\n"); - } - } - } - - /* sort: at the moment we don't have a good way to sort except to put actives on top */ - for (iter = g_list_first (toplevels); iter; iter = iter->next) { - Accessible *toplevel = - (Accessible *) iter->data; - if (AccessibleStateSet_contains (Accessible_getStateSet (toplevel), - SPI_STATE_ACTIVE)) { - actives = g_list_prepend (actives, toplevel); - } - } - - for (iter = g_list_first (actives); iter; iter = actives->next) { - toplevels = g_list_remove (toplevels, iter->data); /* place at end */ - toplevels = g_list_append (toplevels, iter->data); - } - g_list_free (actives); - - /* for each toplevel, ending with the active one(s), - * clip against children, putting results into appropriate charBuffer. - */ - for (iter = g_list_first (toplevels); iter; iter = iter->next) { - toplevel = (Accessible *) iter->data; - if (Accessible_isComponent (toplevel)) { - /* make sure toplevel is visible and not iconified or shaded */ - states = Accessible_getStateSet (toplevel); - if ((AccessibleStateSet_contains (states, SPI_STATE_VISIBLE) - && (!AccessibleStateSet_contains (states, SPI_STATE_ICONIFIED))) - || isJava) { /* isJava hack! */ - component = Accessible_getComponent (toplevel); - AccessibleComponent_getExtents (component, - &toplevel_bounds.x, - &toplevel_bounds.y, - &toplevel_bounds.width, - &toplevel_bounds.height, - SPI_COORD_TYPE_SCREEN); - toplevel_bounds.isEmpty = FALSE; - for (i = 1; i < SPI_LAYER_LAST_DEFINED; ++i) { - *clip_bounds[i] = toplevel_bounds; - } - clip_into_buffers (toplevel, clip_bounds, - reviewBuffers, x, y); - - toplevel_composite (reviewBuffers); -#ifdef CHUNK_LIST_DEBUG - fprintf (stderr, "toplevel clip done\n"); - debug_chunk_list (reviewBuffers[SPI_LAYER_WIDGET]->text_chunks); -#endif - } - } - Accessible_unref (toplevel); - } - - string = review_buffer_composite (reviewBuffers); - - /* SIMPLE SINGLE-PASS ALGORITHM:*/ - /* traverse the tree: - * keep a pointer to outermost instance of each layer - * clip against outermost in same layer - * when this clip occurs, store outermost clipped string in 2d string buffer. - * string buffer may have attributes to mark component bounds, line art, - * or attributes of text being reviewed. - * composite the layers, ignoring NULL chars in the string buffers. - * - * Limitations: - * sibling clip not correct, text may overwrite if siblings intersect onscreen - * length of resulting text buffer may vary! - * - * Technical issues: - * no API for ordering toplevels yet, other than knowing which is ACTIVE. - * not much implementation for the LAYER API yet, other than menus. - */ - g_timer_stop (timer); - fprintf (stderr, "elapsed time = %f s\n", g_timer_elapsed (timer, NULL)); - - return string; -} - -void -report_screen_review_line (const AccessibleEvent *event, void *user_data) -{ - static Display *display = NULL; - int x, y, win_x, win_y; - Window root_return, child_return; - unsigned int mask_return; - - if (!display) display = XOpenDisplay (getenv ("DISPLAY")); - /* - * we would prefer to get the x,y info in the above event. - * At the moment we don't get detail params for "toolkit" events, - * so for testing purposes we use XQueryPointer. Actual apps - * probably shouldn't do this. - */ - XQueryPointer (display, - DefaultRootWindow (display), - &root_return, &child_return, - &x, &y, - &win_x, &win_y, - &mask_return); - - fprintf (stderr, "screen review event %s at %d, %d\n", event->type, - x, y); - fprintf (stderr, "[%s]\n", - get_screen_review_line_at (x, y)); -} - -void -test_exit (void) -{ - SPI_deregisterGlobalEventListenerAll (mouseclick_listener); - AccessibleEventListener_unref (mouseclick_listener); -} diff --git a/test/simple-at.c b/test/simple-at.c deleted file mode 100644 index 7da2bb52..00000000 --- a/test/simple-at.c +++ /dev/null @@ -1,615 +0,0 @@ -/* - * AT-SPI - Assistive Technology Service Provider Interface - * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap) - * - * 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 - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * 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> -#undef MAGNIFIER_ENABLED -#include "../cspi/spi-private.h" /* A hack for now */ - -#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); -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 (void); -static void _festival_say (const char *text, const char *voice, SPIBoolean shutup); -static void _festival_write (const char *buff, int fd); - -#ifdef PRINT_TREE -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; - -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; -static AccessibleKeystrokeListener *ordinary_key_listener; -static AccessibleKeySet *command_keyset; - -int -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); - } - - 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 (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) - { - desktop = SPI_getDesktop (i); - s = Accessible_getName (desktop); - fprintf (stderr, "desktop %d name: %s\n", i, s); - SPI_freeString (s); - n_apps = Accessible_getChildCount (desktop); - for (j=0; j<n_apps; ++j) - { - application = Accessible_getChildAtIndex (desktop, j); - s = Accessible_getName (application); - fprintf (stderr, "app %d name: %s\n", j, s ? s : "(nil)"); -#ifdef PRINT_TREE - print_accessible_tree (application, "*"); -#endif - SPI_freeString (s); - Accessible_unref (application); - } - Accessible_unref (desktop); - } - - /* prepare the keyboard snoopers */ - command_key_listener = SPI_createAccessibleKeystrokeListener (report_command_key_event, NULL); - ordinary_key_listener = SPI_createAccessibleKeystrokeListener (report_ordinary_key_event, NULL); - - command_keyset = SPI_createAccessibleKeySet (11, "qmf23456789", NULL, NULL); - - /* will listen only to Control-Alt-q KeyPress events */ - SPI_registerAccessibleKeystrokeListener(command_key_listener, - command_keyset, - SPI_KEYMASK_ALT | SPI_KEYMASK_CONTROL, - (unsigned long) ( SPI_KEY_PRESSED ), - SPI_KEYLISTENER_ALL_WINDOWS); - - /* will listen only to CAPSLOCK key events, both press and release */ - SPI_registerAccessibleKeystrokeListener(ordinary_key_listener, - (AccessibleKeySet *) SPI_KEYSET_ALL_KEYS, - SPI_KEYMASK_SHIFTLOCK, - (unsigned long) ( SPI_KEY_PRESSED | SPI_KEY_RELEASED ), - SPI_KEYLISTENER_NOSYNC); - - get_environment_vars (); - - SPI_event_main (); - - putenv ("AT_BRIDGE_SHUTDOWN=1"); - - return SPI_exit (); -} - -static void -get_environment_vars (void) -{ - if (g_getenv ("FESTIVAL")) - { - fprintf (stderr, "Using festival\n"); - use_festival = TRUE; - if (g_getenv ("FESTIVAL_CHATTY")) - { - festival_chatty = TRUE; - } - } -#ifdef MAGNIFIER_ENABLED - if (g_getenv ("MAGNIFIER")) - { - fprintf (stderr, "Using magnifier\n"); - use_magnifier = TRUE; - } - else - { - fprintf (stderr, "Not using magnifier\n"); - } -#endif - - if (!use_festival) - { - fprintf (stderr, "No speech output\n"); - } -} - -#ifdef PRINT_TREE -static void -print_accessible_tree (Accessible *accessible, char *prefix) -{ - int n_children; - int i; - char *name; - char *role_name; - char *parent_name = NULL; - char *parent_role = NULL; - char child_prefix[100]; - Accessible *child; - Accessible *parent; - - strncpy (child_prefix, prefix, 98); - strcat (child_prefix, "*"); - parent = Accessible_getParent (accessible); - if (parent) - { - parent_name = Accessible_getName (parent); - parent_role = Accessible_getRoleName (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 ? 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) - { - child = Accessible_getChildAtIndex (accessible, i); - print_accessible_tree (child, child_prefix); - Accessible_unref (child); - } -} -#endif - -void -report_focussed_accessible (Accessible *obj, SPIBoolean shutup_previous_speech) -{ - char *s; - int len; - long x, y, width, height; - /* hack for GUADEC demo, to make sure name changes are spoken */ - shutup_previous_speech = (shutup_previous_speech && !name_changed); - - if (use_festival) - { - if (festival_chatty) - { - s = Accessible_getRoleName (obj); - _festival_say (s, "voice_don_diphone", shutup_previous_speech); - SPI_freeString (s); - } - fprintf (stderr, "getting Name\n"); - s = Accessible_getName (obj); - _festival_say (s, "voice_kal_diphone", - shutup_previous_speech || festival_chatty); - SPI_freeString (s); - } - - if (Accessible_isComponent (obj)) - { - AccessibleComponent *component = Accessible_getComponent (obj); - AccessibleComponent_getExtents (component, &x, &y, &width, &height, - SPI_COORD_TYPE_SCREEN); - fprintf (stderr, "Bounding box: (%ld, %ld) ; (%ld, %ld)\n", - x, y, x+width, y+height); - if (Accessible_isText (obj)) - { - long x0, y0, xN, yN, w0, h0, wN, hN, nchars; - AccessibleText *text = Accessible_getText (obj); - nchars = AccessibleText_getCharacterCount (text); - if (nchars > 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); - } - } -#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); - 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)) - - { - AccessibleText *text_interface; - long start_offset, end_offset; - char *first_sentence = "empty"; - text_interface = Accessible_getText (obj); - first_sentence = AccessibleText_getTextAtOffset ( - text_interface, (long) 0, SPI_TEXT_BOUNDARY_SENTENCE_START, &start_offset, &end_offset); - 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 (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) -{ - fprintf (stderr, "%s event received\n", event->type); -} - -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); - 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); - } -#endif - if (!strcmp (event->type, "object:text-changed")) - { - long 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 -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 (const AccessibleEvent *event, void *user_data) -{ - 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); - 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; i<n_selections; ++i) - { - Accessible *obj = AccessibleSelection_getSelectedChild (selection, (long) i); - g_return_if_fail (obj); - s = Accessible_getName (obj); - fprintf (stderr, "Child %d, name=%s\n", i, s); - SPI_freeString (s); - report_focussed_accessible (obj, i==0); - } - } - else if (!strcmp (event->type, "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 (void) -{ - 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 SPIBoolean -is_command_key (const AccessibleKeystroke *key) -{ - switch (key->keyID) - { - case 'Q': - 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; - fprintf (stderr, "%speech output\n", use_festival ? "S" : "No s"); - return TRUE; - default: - return FALSE; - } -} - -static SPIBoolean -report_command_key_event (const AccessibleKeystroke *key, void *user_data) -{ - 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, - key->keystring, - (long int) key->timestamp); - return is_command_key (key); -} - - -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 (void) -{ - int fd; - struct sockaddr_in name; - int tries = 2; - - name.sin_family = AF_INET; - name.sin_port = htons (1314); - name.sin_addr.s_addr = htonl(INADDR_ANY); - fd = socket (PF_INET, SOCK_STREAM, 0); - - while (connect(fd, (struct sockaddr *) &name, sizeof (name)) < 0) { - if (!tries--) { - perror ("connect"); - return -1; - } - } - - _festival_write ("(audio_mode'async)\n", fd); - _festival_write ("(Parameter.set 'Duration_Model 'Tree_ZScore)\n", fd); - _festival_write ("(Parameter.set 'Duration_Stretch 0.75)\n", fd); - return fd; -} - -static void -_festival_say (const char *text, const char *voice, SPIBoolean shutup) -{ - static int fd = 0; - gchar *quoted; - gchar *p; - gchar prefix[50]; - static gchar voice_spec[32]; - - if (!fd) - { - fd = _festival_init (); - } - - fprintf (stderr, "saying text: %s\n", text); - - quoted = g_malloc(64+strlen(text)*2); - - sprintf (prefix, "(SayText \""); - - strncpy(quoted, prefix, 10); - p = quoted+strlen(prefix); - while (*text) { - if ( *text == '\\' || *text == '"' ) - *p = '\\'; - *p++ = *text++; - } - *p++ = '"'; - *p++ = ')'; - *p++ = '\n'; - *p = 0; - - if (shutup) _festival_write ("(audio_mode'shutup)\n", fd); - if (voice && (strncmp (voice, (char *) (voice_spec+1), strlen(voice)))) - { - snprintf (voice_spec, 32, "(%s)\n", voice); - _festival_write (voice_spec, fd); - _festival_write ("(Parameter.set 'Duration_Model 'Tree_ZScore)\n", fd); - _festival_write ("(Parameter.set 'Duration_Stretch 0.75)\n", fd); - } - - _festival_write (quoted, fd); - - g_free(quoted); -} - -static void -_festival_write (const gchar *command_string, int fd) -{ - fprintf(stderr, command_string); - if (fd < 0) { - perror("socket"); - return; - } - write(fd, command_string, strlen(command_string)); -} - diff --git a/test/stress-test.c b/test/stress-test.c deleted file mode 100644 index 3264d5f7..00000000 --- a/test/stress-test.c +++ /dev/null @@ -1,100 +0,0 @@ -/* - * AT-SPI - Assistive Technology Service Provider Interface - * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap) - * - * 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 - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <unistd.h> -#include <stdlib.h> -#include "../cspi/spi-private.h" /* A hack for now */ -#include <glib-object.h> -#include <gtk/gtk.h> -#include <atk/atk.h> -#include <atk/atknoopobject.h> -#include <bonobo-activation/bonobo-activation-register.h> -#include <bonobo/bonobo-main.h> -#include <libspi/libspi.h> - -int -main (int argc, char **argv) -{ - int i; - Accessibility_Event e; - Accessibility_Registry registry; - CORBA_Environment ev; - SpiAccessible *source; - GObject *object; - AtkObject *atko; - GTimer *timer; - - gtk_init (&argc, &argv); - SPI_init (); - object = g_object_new (GTK_TYPE_BUTTON, NULL); - atko = atk_no_op_object_new (object); - - sleep (1); - - g_print ("starting stress test...\n"); - - CORBA_exception_init (&ev); - - registry = bonobo_activation_activate_from_id ( - "OAFIID:Accessibility_Registry:1.0", 0, NULL, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) - { - g_error ("Accessibility app error: exception during " - "registry activation from id: %s\n", - CORBA_exception_id (&ev)); - CORBA_exception_free (&ev); - } - - if (registry == CORBA_OBJECT_NIL) - { - g_error ("Could not locate registry"); - } - - bonobo_activate (); - - source = spi_accessible_new (atko); - - e.type = "object:test"; - e.source = BONOBO_OBJREF (source); - e.detail1 = 0; - e.detail2 = 0; - - timer = g_timer_new (); - g_timer_start (timer); - - for (i = 0; i < 500; ++i) { - Accessibility_Accessible_ref (e.source, &ev); - Accessibility_Registry_notifyEvent (registry, &e, &ev); - } - g_timer_stop (timer); - g_print ("%d notifications sent in %f sec.\n", i, - g_timer_elapsed (timer, NULL)); - - SPI_event_main (); - - sleep (15); - - return SPI_exit (); -} - diff --git a/test/test-simple.c b/test/test-simple.c deleted file mode 100644 index 3c469ee6..00000000 --- a/test/test-simple.c +++ /dev/null @@ -1,815 +0,0 @@ -/* - * test-simple.c: A set of simple regression tests - * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap) - * - * Copyright 2001 Ximian, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -/* - * ******** Do not copy this code as an example ********* - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <locale.h> -#include <gtk/gtk.h> -#include <cspi/spi.h> -#include <libbonobo.h> - - -/* Known bugs */ -#define WHOLE_STRING -1 - -static void validate_accessible (Accessible *accessible, - gboolean has_parent, - gboolean recurse_down); - -#define WINDOW_MAGIC 0x123456a -#define TEST_STRING_A "A test string" -#define TEST_STRING_A_OBJECT "A_test_string_object" -#define TEST_STRING_B "Another test string" - -static int print_tree_depth = 0; -static gboolean print_tree = FALSE; -static gboolean do_poke = FALSE; -static gboolean key_press_received = FALSE; -static gboolean key_release_received = FALSE; - -typedef struct { - gulong magic; - GtkWidget *window; -} TestWindow; - -static gboolean -focus_me (GtkWidget *widget) -{ - AtkObject *aobject = atk_implementor_ref_accessible ( - ATK_IMPLEMENTOR (widget)); - - /* Force a focus event - even if the WM focused - * us before our at-bridge's idle handler registered - * our interest */ - if (!GTK_WIDGET_HAS_FOCUS (widget)) - gtk_widget_grab_focus (widget); -/* else: FIXME - gtk_widget_grab_focus should send a notify */ - atk_focus_tracker_notify (aobject); - - g_object_unref (G_OBJECT (aobject)); - - return FALSE; -} - -static void -test_window_add_and_show (GtkContainer *container, GtkWidget *widget) -{ - gtk_container_add (container, widget); - gtk_widget_show (widget); -} - -static GtkWidget * -create_tree (void) -{ - GtkWidget *widget; - GtkTreeIter iter; - GtkListStore *store; - GtkTreeViewColumn *column; - - store = gtk_list_store_new (1, G_TYPE_STRING); - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, 0, TEST_STRING_A, -1); - column = gtk_tree_view_column_new_with_attributes ("String", - gtk_cell_renderer_text_new (), "text", 0, NULL); - widget = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store)); - g_object_unref (G_OBJECT (store)); - gtk_tree_view_append_column (GTK_TREE_VIEW (widget), column); - - return widget; -} - -static TestWindow * -create_test_window (void) -{ - TestWindow *win = g_new0 (TestWindow, 1); - GtkWidget *widget, *vbox; - AtkObject *obj; - - win->magic = WINDOW_MAGIC; - win->window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - - gtk_widget_show (win->window); - - vbox = gtk_vbox_new (0, 0); - gtk_container_add (GTK_CONTAINER (win->window), vbox); - gtk_widget_show (vbox); - - widget = gtk_entry_new (); - gtk_entry_set_text (GTK_ENTRY (widget), TEST_STRING_A); - obj = gtk_widget_get_accessible (widget); - atk_object_set_name (obj, TEST_STRING_A_OBJECT); - - test_window_add_and_show (GTK_CONTAINER (vbox), widget); - - widget = gtk_button_new_with_label ("_Foobar"); - test_window_add_and_show (GTK_CONTAINER (vbox), widget); - - widget = gtk_hseparator_new (); - test_window_add_and_show (GTK_CONTAINER (vbox), widget); - - widget = gtk_image_new_from_stock (GTK_STOCK_DIALOG_QUESTION, - GTK_ICON_SIZE_LARGE_TOOLBAR); - test_window_add_and_show (GTK_CONTAINER (vbox), widget); - - widget = g_object_new (GTK_TYPE_HSCALE, NULL); - gtk_range_set_range (GTK_RANGE (widget), 0.0, 100.0); - test_window_add_and_show (GTK_CONTAINER (vbox), widget); - - widget = create_tree (); - test_window_add_and_show (GTK_CONTAINER (vbox), widget); - - g_idle_add ((GSourceFunc) focus_me, win->window); - - return win; -} - -static void -test_window_destroy (TestWindow *win) -{ - gtk_widget_destroy (win->window); - g_free (win); -} - -static void -test_roles (void) -{ - int i; - - fprintf (stderr, "Testing roles...\n"); - for (i = -1; i < 1000; i++) - g_assert (AccessibleRole_getName (i) != NULL); - - g_assert (!strcmp (AccessibleRole_getName (SPI_ROLE_FILE_CHOOSER), "file-chooser")); - g_assert (!strcmp (AccessibleRole_getName (SPI_ROLE_RADIO_BUTTON), "radio-button")); - g_assert (!strcmp (AccessibleRole_getName (SPI_ROLE_TABLE), "table")); - g_assert (!strcmp (AccessibleRole_getName (SPI_ROLE_WINDOW), "window")); -} - -static void -test_action (AccessibleAction *action) -{ - gint n_actions, i; - gchar *s, *sd; - g_assert ((n_actions = AccessibleAction_getNActions (action)) >= 0); - - fprintf (stderr, "Testing actions..."); - for (i = 0; i < n_actions; ++i) - { - s = AccessibleAction_getName (action, i); - g_assert (s); - sd = AccessibleAction_getDescription (action, i); - g_assert (sd); - fprintf (stderr, "%d: %s (%s); ", i, s, sd); - SPI_freeString (s); - SPI_freeString (sd); - g_assert (AccessibleAction_doAction (action, i)); - } - fprintf (stderr, "\n"); -} - -static void -test_desktop (void) -{ - Accessible *desktop; - Accessible *application; - Accessible **list; - - fprintf (stderr, "Testing desktop...\n"); - - g_assert (SPI_getDesktop (-1) == NULL); - desktop = SPI_getDesktop (0); - g_assert (desktop != NULL); - - g_assert ((SPI_getDesktopList (&list)) > 0); - g_assert (list[0] == desktop); - SPI_freeDesktopList (list); - - validate_accessible (desktop, FALSE, FALSE); - - application = Accessible_getChildAtIndex (desktop, 0); - g_assert (application != NULL); - AccessibleApplication_unref (application); - - Accessible_unref (desktop); -} - -static void -test_application (Accessible *application) -{ - char *str; - - fprintf (stderr, "Testing application ...\n"); - g_assert (Accessible_isApplication (application)); - g_assert (Accessible_getApplication (application) == - application); - AccessibleApplication_unref (application); - - str = AccessibleApplication_getToolkitName (application); - g_assert (str != NULL); - g_assert (!strcmp (str, "GAIL")); - SPI_freeString (str); - - str = AccessibleApplication_getLocale (application, LC_MESSAGES); - g_assert (!strcmp (str, setlocale (LC_MESSAGES, NULL))); - SPI_freeString (str); - - str = AccessibleApplication_getVersion (application); - g_assert (str != NULL); - SPI_freeString (str); - - AccessibleApplication_getID (application); -} - -static void -test_editable_text (AccessibleEditableText *etext) -{ - char *str; - AccessibleText *text; - - fprintf (stderr, "Testing editable text ...\n"); - - g_assert (Accessible_isText (etext)); - text = Accessible_getText (etext); - - AccessibleEditableText_setTextContents ( - etext, TEST_STRING_B); - - str = AccessibleText_getText (text, 0, WHOLE_STRING); - g_assert (!strcmp (str, TEST_STRING_B)); - - SPI_freeString (str); - - /* FIXME: lots more editing here */ - - AccessibleEditableText_setTextContents ( - etext, TEST_STRING_A); - - AccessibleText_unref (text); -} - -static void -test_table (AccessibleTable *table) -{ - Accessible *header; - gint index; - gint rows, columns; - - fprintf (stderr, "Testing table ...\n"); - - rows = AccessibleTable_getNRows (table); - g_assert (rows > 0); - - columns = AccessibleTable_getNColumns (table); - g_assert (columns > 0); - - index = AccessibleTable_getIndexAt (table, rows - 1, columns - 1); - - g_assert (AccessibleTable_getRowAtIndex (table, index) == rows - 1); - - g_assert (AccessibleTable_getColumnAtIndex (table, index) == columns - 1); - - g_assert ((header = AccessibleTable_getColumnHeader (table, 0))); - Accessible_unref (header); - - AccessibleTable_isSelected (table, 0, 0); - - /* FIXME: lots more tests */ -} - -static void -test_text (AccessibleText *text) -{ - char *str; - - fprintf (stderr, "Testing text ...\n"); - - g_assert (AccessibleText_getCharacterCount (text) == - strlen (TEST_STRING_A)); - - str = AccessibleText_getText (text, 0, WHOLE_STRING); - g_assert (!strcmp (str, TEST_STRING_A)); - SPI_freeString (str); - - str = AccessibleText_getText (text, 0, 5); - g_assert (!strncmp (str, TEST_STRING_A, 5)); - SPI_freeString (str); - - AccessibleText_setCaretOffset (text, 7); - g_assert (AccessibleText_getCaretOffset (text) == 7); - - /* FIXME: lots more tests - selections etc. etc. */ -} - -static void -test_value (AccessibleValue *value) -{ - float original_value; - - fprintf (stderr, "Testing value ...\n"); - - original_value = AccessibleValue_getCurrentValue (value); - - g_assert (AccessibleValue_getCurrentValue (value) <= - AccessibleValue_getMaximumValue (value)); - - g_assert (AccessibleValue_getCurrentValue (value) >= - AccessibleValue_getMinimumValue (value)); - - AccessibleValue_setCurrentValue (value, - AccessibleValue_getMinimumValue (value)); - - g_assert (AccessibleValue_getCurrentValue (value) == - AccessibleValue_getMinimumValue (value)); - - AccessibleValue_setCurrentValue (value, - AccessibleValue_getMaximumValue (value)); - - g_assert (AccessibleValue_getCurrentValue (value) == - AccessibleValue_getMaximumValue (value)); - - AccessibleValue_setCurrentValue (value, original_value); - - g_assert (AccessibleValue_getCurrentValue (value) == original_value); -} - -static void -test_component (AccessibleComponent *component) -{ - long x, y, width, height; - - fprintf (stderr, "Testing component...\n"); - - AccessibleComponent_getExtents ( - component, &x, &y, &width, &height, SPI_COORD_TYPE_SCREEN); - - AccessibleComponent_getPosition ( - component, &x, &y, SPI_COORD_TYPE_SCREEN); - - AccessibleComponent_getSize (component, &width, &height); - - if (width > 0 && height > 0) { -#ifdef FIXME - Accessible *accessible, *componentb; -#endif - - g_assert (AccessibleComponent_contains ( - component, x, y, SPI_COORD_TYPE_SCREEN)); - - g_assert (AccessibleComponent_contains ( - component, x + width - 1, y, SPI_COORD_TYPE_SCREEN)); - - g_assert (AccessibleComponent_contains ( - component, x + width - 1, y + height - 1, - SPI_COORD_TYPE_SCREEN)); - -#ifdef FIXME - accessible = AccessibleComponent_getAccessibleAtPoint ( - component, x, y, SPI_COORD_TYPE_SCREEN); - - g_assert (Accessible_isComponent (accessible)); - componentb = Accessible_getComponent (accessible); - g_assert (componentb == component); - - AccessibleComponent_unref (componentb); - Accessible_unref (accessible); -#endif - } - - AccessibleComponent_getLayer (component); - AccessibleComponent_getMDIZOrder (component); -/* AccessibleComponent_grabFocus (component); */ -} - -static void -test_image (AccessibleImage *image) -{ - char *desc; - long int x = -1, y = -1, width = -1, height = -1; - - desc = AccessibleImage_getImageDescription (image); - g_assert (desc != NULL); - SPI_freeString (desc); - - AccessibleImage_getImagePosition (image, &x, &y, - SPI_COORD_TYPE_SCREEN); - AccessibleImage_getImageSize (image, &width, &height); - AccessibleImage_getImageExtents (image, &x, &y, &width, &height, - SPI_COORD_TYPE_WINDOW); -} - -static void -validate_tree (Accessible *accessible, - gboolean has_parent, - gboolean recurse_down) -{ - Accessible *parent; - long len, i; - - parent = Accessible_getParent (accessible); - if (has_parent) { - long index; - Accessible *child_at_index; - - g_assert (parent != NULL); - - index = Accessible_getIndexInParent (accessible); - g_assert (index >= 0); - - child_at_index = Accessible_getChildAtIndex (parent, index); - - g_assert (child_at_index == accessible); - - Accessible_unref (child_at_index); - Accessible_unref (parent); - } - - len = Accessible_getChildCount (accessible); - print_tree_depth++; - for (i = 0; i < len; i++) { - Accessible *child; - - child = Accessible_getChildAtIndex (accessible, i); -#ifdef ROPEY - if (!child) - fprintf (stderr, "Unusual - ChildGone at %ld\n", i); - - g_assert (Accessible_getIndexInParent (child) == i); - g_assert (Accessible_getParent (child) == accessible); -#endif - - if (recurse_down && child) - validate_accessible (child, has_parent, recurse_down); - - Accessible_unref (child); - } - print_tree_depth--; -} - -static void -validate_accessible (Accessible *accessible, - gboolean has_parent, - gboolean recurse_down) -{ - Accessible *tmp; - char *name, *descr; - AccessibleRole role; - AccessibleRelation **relations; - char *role_name; - GString *item_str = g_string_new (""); - int i; - - name = Accessible_getName (accessible); - g_assert (name != NULL); - - descr = Accessible_getDescription (accessible); - g_assert (descr != NULL); - - role = Accessible_getRole (accessible); - g_assert (role != SPI_ROLE_INVALID); - role_name = Accessible_getRoleName (accessible); - g_assert (role_name != NULL); - - relations = Accessible_getRelationSet (accessible); - g_assert (relations != NULL); - - for (i = 0; relations [i]; i++) { - AccessibleRelationType type; - int targets; - - fprintf (stderr, "relation %d\n", i); - - type = AccessibleRelation_getRelationType (relations [i]); - g_assert (type != SPI_RELATION_NULL); - - targets = AccessibleRelation_getNTargets (relations [i]); - g_assert (targets != -1); - - AccessibleRelation_unref (relations [i]); - relations [i] = NULL; - } - free (relations); - - if (print_tree) { - int i; - - for (i = 0; i < print_tree_depth; i++) - fputc (' ', stderr); - fputs ("|-> [ ", stderr); - } - - if (Accessible_isAction (accessible)) { - tmp = Accessible_getAction (accessible); - g_assert (tmp != NULL); - if (print_tree) - fprintf (stderr, "At"); - else - test_action (tmp); - AccessibleAction_unref (tmp); - } - - if (Accessible_isApplication (accessible)) { - tmp = Accessible_getApplication (accessible); - if (print_tree) - fprintf (stderr, "Ap"); - else - test_application (tmp); - AccessibleApplication_unref (tmp); - } - - if (Accessible_isComponent (accessible)) { - tmp = Accessible_getComponent (accessible); - g_assert (tmp != NULL); - if (print_tree) - fprintf (stderr, "Co"); - else - test_component (tmp); - AccessibleComponent_unref (tmp); - } - - if (Accessible_isEditableText (accessible)) { - tmp = Accessible_getEditableText (accessible); - g_assert (tmp != NULL); - if (print_tree) - fprintf (stderr, "Et"); - else - test_editable_text (tmp); - AccessibleEditableText_unref (tmp); - } - - if (Accessible_isHypertext (accessible)) { - tmp = Accessible_getHypertext (accessible); - g_assert (tmp != NULL); - if (print_tree) - fprintf (stderr, "Ht"); - AccessibleHypertext_unref (tmp); - } - - if (Accessible_isImage (accessible)) { - tmp = Accessible_getImage (accessible); - g_assert (tmp != NULL); - if (print_tree) { - char *desc; - - fprintf (stderr, "Im"); - - desc = AccessibleImage_getImageDescription (tmp); - g_string_append_printf ( - item_str, " image descr: '%s'", desc); - SPI_freeString (desc); - } else - test_image (tmp); - - AccessibleImage_unref (tmp); - } - - if (Accessible_isSelection (accessible)) { - tmp = Accessible_getSelection (accessible); - g_assert (tmp != NULL); - if (print_tree) - fprintf (stderr, "Se"); - AccessibleSelection_unref (tmp); - } - - if (Accessible_isTable (accessible)) { - tmp = Accessible_getTable (accessible); - g_assert (tmp != NULL); - if (print_tree) - fprintf (stderr, "Ta"); - else - test_table (tmp); - AccessibleTable_unref (tmp); - } - - if (Accessible_isText (accessible)) { - tmp = Accessible_getText (accessible); - g_assert (tmp != NULL); - if (print_tree) - fprintf (stderr, "Te"); - else { - if (strcmp (name, TEST_STRING_A_OBJECT) == 0) - test_text (tmp); - } - AccessibleText_unref (tmp); - } - - if (Accessible_isValue (accessible)) { - tmp = Accessible_getValue (accessible); - g_assert (tmp != NULL); - if (print_tree) - fprintf (stderr, "Va"); - else - test_value (tmp); - AccessibleValue_unref (tmp); - } - - if (print_tree) - fprintf (stderr, " ] '%s' (%s) - %s: %s\n", - name, descr, role_name, item_str->str); - - SPI_freeString (name); - SPI_freeString (descr); - SPI_freeString (role_name); - g_string_free (item_str, TRUE); - - validate_tree (accessible, has_parent, recurse_down); -} - -static void -test_misc (void) -{ - fprintf (stderr, "Testing misc bits ...\n"); - - g_assert (!Accessible_isComponent (NULL)); - g_assert (Accessible_getComponent (NULL) == NULL); - SPI_freeString (NULL); -} - -static void -global_listener_cb (const AccessibleEvent *event, - void *user_data) -{ - TestWindow *win = user_data; - Accessible *desktop; - AccessibleApplication *application; - - g_assert (win->magic == WINDOW_MAGIC); - g_assert (!strcmp (event->type, "focus:")); - - fprintf (stderr, "Fielded focus event ...\n"); - - if (!do_poke) { - desktop = SPI_getDesktop (0); - application = Accessible_getChildAtIndex (desktop, 0); - g_assert (application != NULL); - Accessible_unref (desktop); - - test_application (application); - - AccessibleApplication_unref (application); - - print_tree = FALSE; - - validate_accessible (event->source, TRUE, TRUE); - - fprintf (stderr, "quitting mainloop.\n"); - gtk_main_quit (); - } - - print_tree = TRUE; - validate_accessible (event->source, TRUE, TRUE); -} - -static SPIBoolean -key_listener_cb (const AccessibleKeystroke *stroke, - void *user_data) -{ - AccessibleKeystroke *s = user_data; - - *s = *stroke; - if (stroke->keystring) s->keystring = g_strdup (stroke->keystring); - - if (s->type == SPI_KEY_PRESSED) - key_press_received = TRUE; - else if (s->type == SPI_KEY_RELEASED) - key_release_received = TRUE; - - return TRUE; -} - - -static void -test_keylisteners (void) -{ - int i; - AccessibleKeystroke stroke; - AccessibleKeystrokeListener *key_listener; - AccessibleKeySet *test_keyset; - - fprintf (stderr, "Testing keyboard listeners ...\n"); - - key_listener = SPI_createAccessibleKeystrokeListener ( - key_listener_cb, &stroke); - - test_keyset = SPI_createAccessibleKeySet (1, "=", NULL, NULL); - - g_assert (SPI_registerAccessibleKeystrokeListener ( - key_listener, - test_keyset, - 0, - SPI_KEY_PRESSED | SPI_KEY_RELEASED, - SPI_KEYLISTENER_CANCONSUME | SPI_KEYLISTENER_ALL_WINDOWS)); - - for (i = 0; i < 3; i++) { - memset (&stroke, 0, sizeof (AccessibleKeystroke)); - g_assert (SPI_generateKeyboardEvent ('=', NULL, SPI_KEY_SYM)); - while (!(key_press_received)) - g_main_context_iteration (NULL, TRUE); - fprintf (stderr, "p [%s]", stroke.keystring); - g_assert (!strcmp (stroke.keystring, "=")); - while (!(key_release_received)) - g_main_context_iteration (NULL, TRUE); - fprintf (stderr, "r [%s]", stroke.keystring); - key_press_received = FALSE; - key_release_received = FALSE; - } - g_assert (SPI_deregisterAccessibleKeystrokeListener (key_listener, 0)); - SPI_freeAccessibleKeySet (test_keyset); - - fprintf (stderr, "\n"); - - AccessibleKeystrokeListener_unref (key_listener); - - g_assert (SPI_generateMouseEvent (100, 100, "rel")); - g_assert (SPI_generateMouseEvent (-50, -50, "rel")); - g_assert (SPI_generateMouseEvent (-50, -50, "rel")); - g_assert (SPI_generateMouseEvent (-1, -1, "b1c")); -} - -int -main (int argc, char **argv) -{ - int leaked, i; - TestWindow *win; - const char *modules; - AccessibleEventListener *global_listener; - - modules = g_getenv ("GTK_MODULES"); - if (!modules || modules [0] == '\0') - putenv ("GTK_MODULES=gail:atk-bridge"); - modules = NULL; - - for (i = 1; i < argc; i++) { - if (!g_strcasecmp (argv [i], "--poke")) - do_poke = TRUE; - } - - gtk_init (&argc, &argv); - - g_assert (!SPI_init ()); - g_assert (SPI_init ()); - g_assert (SPI_getDesktopCount () == 1); - - test_roles (); - test_misc (); - test_desktop (); - test_keylisteners (); - - win = create_test_window (); - - global_listener = SPI_createAccessibleEventListener (global_listener_cb, win); - - g_assert (SPI_registerGlobalEventListener (global_listener, "focus:")); - - fprintf (stderr, "Waiting for focus event ...\n"); - gtk_main (); - - g_assert (SPI_deregisterGlobalEventListenerAll (global_listener)); - AccessibleEventListener_unref (global_listener); - - test_window_destroy (win); - - /* Wait for any pending events from the registry */ - g_usleep (500*1000); - for (i = 0; i < 100; i++) - CORBA_ORB_perform_work (NULL, NULL); - - if ((leaked = SPI_exit ())) - g_error ("Leaked %d SPI handles", leaked); - - g_assert (!SPI_exit ()); - - fprintf (stderr, "All tests passed\n"); - - if (g_getenv ("_MEMPROF_SOCKET")) { - fprintf (stderr, "Waiting for memprof\n"); - gtk_main (); - } - - putenv ("AT_BRIDGE_SHUTDOWN=1"); - - return 0; -} diff --git a/test/visual-bell.c b/test/visual-bell.c deleted file mode 100755 index d8d0f59c..00000000 --- a/test/visual-bell.c +++ /dev/null @@ -1,145 +0,0 @@ -/* - * AT-SPI - Assistive Technology Service Provider Interface - * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap) - * - * Copyright 2001, 2002 Sun Microsystems Inc., - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <X11/Xlib.h> -#include <X11/Xutil.h> -#include <X11/XKBlib.h> - -static Display *display; -static Window flash_window = None; - -static void -visual_bell_notify (XkbAnyEvent *xkb_ev) -{ - Window root; - int width, height; - root = RootWindow (display, DefaultScreen (display)); - width = DisplayWidth (display, DefaultScreen (display)); - height = DisplayHeight (display, DefaultScreen (display)); - if (flash_window == None) - { - Visual *visual = CopyFromParent; - XVisualInfo info_return; - XSetWindowAttributes xswa; - int depth = CopyFromParent; - xswa.save_under = True; - xswa.override_redirect = True; - /* TODO: use XGetVisualInfo and determine which is an - overlay, if one is present. Not sure how to tell - this yet... */ - if (XMatchVisualInfo (display, - DefaultScreen (display), - 8, - PseudoColor, - &info_return)) { - depth = 8; - visual = info_return.visual; - } - else - { - fprintf (stderr, "could not create overlay visual, using default root visual type\n"); - } - flash_window = XCreateWindow (display, root, - 0, 0, width, height, - 0, depth, - InputOutput, - visual, - CWSaveUnder | CWOverrideRedirect, - &xswa); - XSelectInput (display, flash_window, ExposureMask); - XMapWindow (display, flash_window); - } - else - { - /* just draw something in the window */ - GC gc = XCreateGC (display, flash_window, 0, NULL); - XMapWindow (display, flash_window); - XSetForeground (display, gc, - WhitePixel (display, DefaultScreen (display))); - XFillRectangle (display, flash_window, gc, - 0, 0, width, height); - XSetForeground (display, gc, - BlackPixel (display, DefaultScreen (display))); - XFillRectangle (display, flash_window, gc, - 0, 0, width, height); - } - XFlush (display); -} - -int main (int argc, char **argv) -{ - XEvent xev; - int ir, xkb_base_event_type, reason_return; - char *display_name = getenv ("DISPLAY"); - - if (!display_name) display_name = ":0.0"; - - display = XkbOpenDisplay (display_name, - &xkb_base_event_type, - &ir, NULL, NULL, &reason_return); - if (!display) - { - fprintf (stderr, "Could not connect to display! (%d)\n", - reason_return); - exit (-1); - } - - XkbSelectEvents (display, - XkbUseCoreKbd, - XkbBellNotifyMask, - XkbBellNotifyMask); - - /* comment this out to prevent bell on startup */ - XkbBell (display, None, 100, None); - - while (1) - { - XNextEvent (display, &xev); - if (xev.type == Expose) - { - XExposeEvent *exev = (XExposeEvent *) &xev; - if (exev->window == flash_window) - { - XUnmapWindow (display, flash_window); - /* discard pending bells */ - XSync (display, True); - XFlush (display); - } - } - else if (xev.type == xkb_base_event_type) - { - XkbAnyEvent *xkb_ev = (XkbAnyEvent *) &xev; - - switch (xkb_ev->xkb_type) - { - case XkbBellNotify: - /* flash something */ - visual_bell_notify (xkb_ev); - break; - } - } - } -} - diff --git a/test/window-listener-test.c b/test/window-listener-test.c deleted file mode 100644 index cbd24102..00000000 --- a/test/window-listener-test.c +++ /dev/null @@ -1,86 +0,0 @@ -/* - * AT-SPI - Assistive Technology Service Provider Interface - * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap) - * - * Copyright 2001, 2002, 2003 Sun Microsystems Inc., - * Copyright 2001, 2002, 2003 Ximian, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <stdlib.h> -#include <stdio.h> -#include <unistd.h> -#include "../cspi/spi-private.h" /* A hack for now */ - -static void report_window_event (const AccessibleEvent *event, void *user_data); -static AccessibleEventListener *window_listener; - -int -main (int argc, char **argv) -{ - SPI_init (); - - window_listener = SPI_createAccessibleEventListener ( - report_window_event, NULL); - - SPI_registerGlobalEventListener (window_listener, - "window:minimize"); - SPI_registerGlobalEventListener (window_listener, - "window:maximize"); - SPI_registerGlobalEventListener (window_listener, - "window:restore"); - SPI_registerGlobalEventListener (window_listener, - "window:activate"); - SPI_registerGlobalEventListener (window_listener, - "window:deactivate"); - SPI_registerGlobalEventListener (window_listener, - "window:create"); - SPI_registerGlobalEventListener (window_listener, - "window:destroy"); - SPI_registerGlobalEventListener (window_listener, - "window:lower"); - SPI_registerGlobalEventListener (window_listener, - "window:raise"); - SPI_registerGlobalEventListener (window_listener, - "window:resize"); - SPI_registerGlobalEventListener (window_listener, - "window:shade"); - SPI_registerGlobalEventListener (window_listener, - "window:unshade"); - SPI_event_main (); - - putenv ("AT_BRIDGE_SHUTDOWN=1"); - - /* - * TODO: Add a key event listener that calls test_exit, to - * deregister and cleanup appropriately. - */ - - return SPI_exit (); -} - -void -report_window_event (const AccessibleEvent *event, void *user_data) -{ - char *t, *s = Accessible_getName (event->source); - t = AccessibleWindowEvent_getTitleString (event); - if (t == NULL) t = ""; - fprintf (stderr, "%s %s %s\n", event->type, s, t); - SPI_freeString (s); - SPI_freeString (t); -} - |