Add accessibility tests

http://bugzilla.clutter-project.org/show_bug.cgi?id=2099

Signed-off-by: Emmanuele Bassi <ebassi@linux.intel.com>
This commit is contained in:
Alejandro Piñeiro 2010-04-26 20:07:22 +02:00 committed by Emmanuele Bassi
parent 8f8e88b692
commit 790d2165f3
11 changed files with 1182 additions and 1 deletions

View File

@ -1030,6 +1030,7 @@ AC_CONFIG_FILES([
clutter/cogl/pango/Makefile
clutter/json/Makefile
tests/Makefile
tests/accessibility/Makefile
tests/conform/Makefile
tests/data/Makefile
tests/interactive/Makefile

View File

@ -1,4 +1,4 @@
SUBDIRS = data interactive micro-bench tools
SUBDIRS = accessibility data interactive micro-bench tools
if BUILD_TESTS
SUBDIRS += conform

View File

@ -20,6 +20,9 @@ covers most of the original Clutter tests. Ideally some of these tests will be
migrated into the conformance/ directory so they can be used in automated
nightly tests.
The accessibility/ tests are tests created to test the accessibility support of
clutter, testing some of the atk interfaces.
The data/ directory contains optional data (like images and ClutterScript
definitions) that can be referenced by a test.

View File

@ -0,0 +1,61 @@
include $(top_srcdir)/build/autotools/Makefile.am.silent
EXAMPLES = cally-atkcomponent-example \
cally-atkeditabletext-example \
cally-atkevents-example \
cally-atktext-example \
cally-clone-example
common_ldadd = $(top_builddir)/clutter/libclutter-@CLUTTER_WINSYS@-@CLUTTER_API_VERSION@.la
CALLY_UTIL_SOURCES = cally-examples-util.c
INCLUDES = \
-I$(top_srcdir) \
-I$(top_srcdir)/clutter \
-I$(top_srcdir)/clutter/cogl \
-I$(top_builddir)/clutter \
-I$(top_builddir)/clutter/cogl \
-I$(top_srcdir)/tests/accessibility
noinst_PROGRAMS = $(EXAMPLES)
# atk component example
cally_atkcomponent_example_LDADD = $(CLUTTER_LIBS) $(common_ldadd)
cally_atkcomponent_example_CFLAGS = $(CLUTTER_CFLAGS) $(MAINTAINER_CFLAGS) \
-DPREFIXDIR=\"$(libdir)\" \
$(INCLUDES)
cally_atkcomponent_example_SOURCES = cally-atkcomponent-example.c \
$(CALLY_UTIL_SOURCES)
# atk text example
cally_atktext_example_LDADD = $(CLUTTER_LIBS) $(common_ldadd)
cally_atktext_example_CFLAGS = $(CLUTTER_CFLAGS) $(MAINTAINER_CFLAGS)\
-DPREFIXDIR=\"$(libdir)\" \
$(INCLUDES)
cally_atktext_example_SOURCES = cally-atktext-example.c \
$(CALLY_UTIL_SOURCES)
# atk text example2
cally_atkevents_example_LDADD = $(CLUTTER_LIBS) $(common_ldadd)
cally_atkevents_example_CFLAGS = $(CLUTTER_CFLAGS) $(MAINTAINER_CFLAGS)\
-DPREFIXDIR=\"$(libdir)\" \
$(INCLUDES)
cally_atkevents_example_SOURCES = cally-atkevents-example.c \
$(CALLY_UTIL_SOURCES)
# atk editable text example
cally_atkeditabletext_example_LDADD = $(CLUTTER_LIBS) $(common_ldadd)
cally_atkeditabletext_example_CFLAGS = $(CLUTTER_CFLAGS) $(MAINTAINER_CFLAGS) \
-DPREFIXDIR=\"$(libdir)\" \
$(INCLUDES)
cally_atkeditabletext_example_SOURCES = cally-atkeditabletext-example.c \
$(CALLY_UTIL_SOURCES)
# cally clone example
cally_clone_example_LDADD = $(CLUTTER_LIBS) $(common_ldadd)
cally_clone_example_CFLAGS = $(CLUTTER_CFLAGS) $(MAINTAINER_CFLAGS) \
-DPREFIXDIR=\"$(libdir)\" \
$(INCLUDES)
cally_clone_example_SOURCES = cally-clone-example.c \
$(CALLY_UTIL_SOURCES)

View File

@ -0,0 +1,102 @@
/* CALLY - The Clutter Accessibility Implementation Library
*
* Copyright (C) 2009 Igalia, S.L.
*
* Author: Alejandro Piñeiro Iglesias <apinheiro@igalia.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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 <clutter/clutter.h>
#include "cally-examples-util.h"
#define WIDTH 300
#define HEIGHT 300
#define SIZE 50
#define DEPTH -100
static const ClutterColor color1 = { 0xff, 0xff, 0x00, 0xff };
static const ClutterColor color2 = { 0x00, 0xff, 0x00, 0xff };
static const ClutterColor color3 = { 0x00, 0x00, 0xff, 0xff };
static const ClutterColor color4 = { 0xff, 0x00, 0xff, 0xff };
int
main (int argc, char *argv[])
{
ClutterActor *stage = NULL;
ClutterColor color = { 0x00, 0x00, 0x00, 0xff };
ClutterActor *button1 = NULL;
ClutterActor *button2 = NULL;
ClutterActor *button3 = NULL;
ClutterActor *button4 = NULL;
ClutterActor *group[4];
ClutterGeometry geom = {0, 0, SIZE, SIZE};
gint i = 0;
clutter_init (&argc, &argv);
cally_util_a11y_init (&argc, &argv);
stage = clutter_stage_get_default ();
clutter_stage_set_color (CLUTTER_STAGE (stage), &color);
clutter_actor_set_size (stage, WIDTH, HEIGHT);
button1 = clutter_rectangle_new_with_color (&color1);
clutter_actor_set_geometry (button1, &geom);
button2 = clutter_rectangle_new_with_color (&color2);
geom.x = 2*SIZE;
geom.y = 0;
clutter_actor_set_geometry (button2, &geom);
geom.x = 0;
geom.y = 2*SIZE;
button3 = clutter_rectangle_new_with_color (&color3);
clutter_actor_set_geometry (button3, &geom);
clutter_actor_set_depth( button3, DEPTH);
/* a nested hierarchy, to check that the relative positions are
computed properly */
geom.x = SIZE/2;
geom.y = SIZE/2;
button4 = clutter_rectangle_new_with_color (&color4);
clutter_actor_set_geometry (button4, &geom);
clutter_actor_show (button4);
for (i = 0; i < 4; i++) {
group[i] = clutter_group_new ();
clutter_actor_set_geometry (group[i], &geom);
if (i > 0)
clutter_group_add (CLUTTER_GROUP (group[i]), group [i - 1]);
clutter_actor_show_all (group[i]);
}
clutter_group_add (CLUTTER_GROUP (stage), button1);
clutter_group_add (CLUTTER_GROUP (stage), button2);
clutter_group_add (CLUTTER_GROUP (stage), button3);
clutter_group_add (CLUTTER_GROUP (stage), group[3]);
clutter_group_add (CLUTTER_GROUP (group[0]), button4);
clutter_actor_show_all (stage);
clutter_main ();
return 0;
}

View File

@ -0,0 +1,270 @@
/* CALLY - The Clutter Accessibility Implementation Library
*
* Copyright (C) 2009 Igalia, S.L.
*
* Author: Alejandro Piñeiro Iglesias <apinheiro@igalia.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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 <atk/atk.h>
#include <clutter/clutter.h>
#include "cally-examples-util.h"
#define WIDTH 800
#define HEIGHT 600
static ClutterActor *text_actor = NULL;
static ClutterActor *text_editable_actor = NULL;
/*
* Test AtkText interface
*/
static void
test_atk_text (ClutterActor *actor)
{
AtkObject *object = NULL;
AtkEditableText *cally_editable_text = NULL;
gint pos = 0;
object = atk_gobject_accessible_for_object (G_OBJECT (actor));
cally_editable_text = ATK_EDITABLE_TEXT (object);
if (cally_editable_text != NULL) {
atk_editable_text_set_text_contents (cally_editable_text, "New text");
atk_editable_text_delete_text (cally_editable_text, 0, 3);
pos = 3;
atk_editable_text_insert_text (cally_editable_text, "New", 0, &pos);
/* Not implemented in cally, just checking that we can call this
functions */
atk_editable_text_copy_text (cally_editable_text, 0, -1);
atk_editable_text_paste_text (cally_editable_text, 5);
atk_editable_text_cut_text (cally_editable_text, 0, -1);
}
}
static gboolean
insert_text_press_cb (ClutterActor *actor,
ClutterButtonEvent *event,
gpointer data)
{
AtkObject *object = NULL;
AtkEditableText *cally_editable_text = NULL;
gint pos = 0;
object = atk_gobject_accessible_for_object (G_OBJECT (text_editable_actor));
cally_editable_text = ATK_EDITABLE_TEXT (object);
pos = 3;
atk_editable_text_insert_text (cally_editable_text, "New", 0, &pos);
return TRUE;
}
static gboolean
delete_text_press_cb (ClutterActor *actor,
ClutterButtonEvent *event,
gpointer data)
{
AtkObject *object = NULL;
AtkEditableText *cally_editable_text = NULL;
object = atk_gobject_accessible_for_object (G_OBJECT (text_editable_actor));
cally_editable_text = ATK_EDITABLE_TEXT (object);
atk_editable_text_delete_text (cally_editable_text, 0, 3);
return TRUE;
}
static gboolean
set_text_press_cb (ClutterActor *actor,
ClutterButtonEvent *event,
gpointer data)
{
AtkObject *object = NULL;
AtkEditableText *cally_editable_text = NULL;
object = atk_gobject_accessible_for_object (G_OBJECT (text_editable_actor));
cally_editable_text = ATK_EDITABLE_TEXT (object);
atk_editable_text_set_text_contents (cally_editable_text, "New text");
return TRUE;
}
static gboolean
activate_deactivate_press_cb (ClutterActor *actor,
ClutterButtonEvent *event,
gpointer data)
{
gboolean active = FALSE;
active = clutter_text_get_activatable (CLUTTER_TEXT (text_editable_actor));
clutter_text_set_activatable (CLUTTER_TEXT (text_editable_actor), !active);
return TRUE;
}
static gboolean
print_cursor_position_press_cb (ClutterActor *actor,
ClutterButtonEvent *event,
gpointer data)
{
gint pos = 0;
pos = clutter_text_get_cursor_position (CLUTTER_TEXT (text_editable_actor));
g_print ("current cursor position %i\n", pos);
return TRUE;
}
static void
activate_cb (ClutterActor *actor,
gpointer data)
{
g_print ("Actor activated\n");
}
static ClutterActor*
_create_button (const gchar *text)
{
ClutterActor *button = NULL;
ClutterActor *rectangle = NULL;
ClutterActor *label = NULL;
ClutterColor color_rect = { 0x00, 0xff, 0xff, 0xff };
ClutterColor color_label = { 0x00, 0x00, 0x00, 0xff };
button = clutter_group_new ();
rectangle = clutter_rectangle_new_with_color (&color_rect);
clutter_actor_set_size (rectangle, 375, 35);
label = clutter_text_new_full ("Sans Bold 32px",
text, &color_label);
clutter_group_add (CLUTTER_GROUP (button), rectangle);
clutter_group_add (CLUTTER_GROUP (button), label);
clutter_actor_set_reactive (button, TRUE);
return button;
}
static void
make_ui (ClutterActor *stage)
{
ClutterColor color_stage = { 0x00, 0x00, 0x00, 0xff };
ClutterColor color_text = { 0xff, 0x00, 0x00, 0xff };
ClutterColor color_sel = { 0x00, 0xff, 0x00, 0x55 };
ClutterActor *button = NULL;
clutter_stage_set_color (CLUTTER_STAGE (stage), &color_stage);
clutter_actor_set_size (stage, WIDTH, HEIGHT);
/* text */
text_actor = clutter_text_new_full ("Sans Bold 32px",
"Lorem ipsum dolor sit amet",
&color_text);
clutter_group_add (CLUTTER_GROUP (stage), text_actor);
/* text_editable */
text_editable_actor = clutter_text_new_full ("Sans Bold 32px",
"consectetur adipisicing elit",
&color_text);
clutter_actor_set_position (text_editable_actor, 0, 100);
clutter_text_set_editable (CLUTTER_TEXT (text_editable_actor), TRUE);
clutter_text_set_selectable (CLUTTER_TEXT (text_editable_actor), TRUE);
clutter_text_set_selection_color (CLUTTER_TEXT (text_editable_actor),
&color_sel);
clutter_text_set_activatable (CLUTTER_TEXT (text_editable_actor),
TRUE);
clutter_text_set_line_wrap (CLUTTER_TEXT (text_editable_actor), TRUE);
clutter_actor_grab_key_focus (text_editable_actor);
clutter_actor_set_reactive (text_editable_actor, TRUE);
clutter_group_add (CLUTTER_GROUP (stage), text_editable_actor);
g_signal_connect (text_editable_actor, "activate",
G_CALLBACK (activate_cb), NULL);
/* test buttons */
button = _create_button ("Set");
clutter_actor_set_position (button, 100, 200);
g_signal_connect_after (button, "button-press-event",
G_CALLBACK (set_text_press_cb), NULL);
clutter_group_add (CLUTTER_GROUP (stage), button);
button = _create_button ("Delete");
clutter_actor_set_position (button, 100, 250);
g_signal_connect_after (button, "button-press-event",
G_CALLBACK (delete_text_press_cb), NULL);
clutter_group_add (CLUTTER_GROUP (stage), button);
button = _create_button ("Insert");
clutter_actor_set_position (button, 100, 300);
g_signal_connect_after (button, "button-press-event",
G_CALLBACK (insert_text_press_cb), NULL);
clutter_group_add (CLUTTER_GROUP (stage), button);
button = _create_button ("Activate/Deactivate");
clutter_actor_set_position (button, 100, 350);
g_signal_connect_after (button, "button-press-event",
G_CALLBACK (activate_deactivate_press_cb), NULL);
clutter_group_add (CLUTTER_GROUP (stage), button);
button = _create_button ("Cursor position");
clutter_actor_set_position (button, 100, 450);
g_signal_connect_after (button, "button-press-event",
G_CALLBACK (print_cursor_position_press_cb), NULL);
clutter_group_add (CLUTTER_GROUP (stage), button);
}
int
main (int argc, char *argv[])
{
ClutterActor *stage = NULL;
g_set_application_name ("AtkEditableText");
clutter_init (&argc, &argv);
cally_util_a11y_init (&argc, &argv);
stage = clutter_stage_get_default ();
make_ui (stage);
clutter_actor_show_all (stage);
test_atk_text (text_actor);
test_atk_text (text_editable_actor);
clutter_main ();
return 0;
}

View File

@ -0,0 +1,180 @@
/* CALLY - The Clutter Accessibility Implementation Library
*
* Copyright (C) 2009 Igalia, S.L.
*
* Author: Alejandro Piñeiro Iglesias <apinheiro@igalia.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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.
*/
/*
* The purpose of this example is test key event and global event
* implementation, specifically:
*
* atk_add_global_event_listener
* atk_remove_global_event_listener
* atk_add_key_event_listener
* atk_remove_key_event_listener
*/
#include <atk/atk.h>
#include <clutter/clutter.h>
#include "cally-examples-util.h"
#define WIDTH 800
#define HEIGHT 600
#define HEIGHT_STEP 100
#define NUM_ENTRIES 3
struct _Data{
gint value;
};
typedef struct _Data Data;
static gboolean
atk_key_listener (AtkKeyEventStruct *event, gpointer data)
{
Data *my_data = (Data*) data;
g_print ("atk_listener: 0x%x ", event->keyval);
if (my_data != NULL) {
g_print ("\t Data value: %i\n", my_data->value);
} else {
g_print ("\tNo data!!\n");
}
return FALSE;
}
static gboolean
window_event_listener (GSignalInvocationHint * signal_hint,
guint n_param_values,
const GValue * param_values, gpointer data)
{
AtkObject *accessible;
GSignalQuery signal_query;
const gchar *name, *s;
g_signal_query (signal_hint->signal_id, &signal_query);
name = signal_query.signal_name;
accessible = ATK_OBJECT (g_value_get_object (&param_values[0]));
s = atk_object_get_name (accessible);
g_print ("Detected window event \"%s\" from object \"%p\" named \"%s\"\n",
name, accessible, s);
return TRUE;
}
static void
make_ui (ClutterActor *stage)
{
gint i = 0;
ClutterActor *editable = NULL;
ClutterActor *rectangle = NULL;
ClutterActor *label = NULL;
ClutterColor color_stage = { 0x00, 0x00, 0x00, 0xff };
ClutterColor color_text = { 0xff, 0x00, 0x00, 0xff };
ClutterColor color_sel = { 0x00, 0xff, 0x00, 0x55 };
ClutterColor color_label = { 0x00, 0xff, 0x55, 0xff };
ClutterColor color_rect = { 0x00, 0xff, 0xff, 0x55 };
ClutterGeometry label_geom = {0, 50, -1, -1};
ClutterGeometry editable_geom = {150, 50, 500, 75};
clutter_stage_set_color (CLUTTER_STAGE (stage), &color_stage);
clutter_actor_set_size (stage, WIDTH, HEIGHT);
for (i = 0; i < NUM_ENTRIES; i++)
{
/* label */
label = clutter_text_new_full ("Sans Bold 32px",
"Entry",
&color_label);
clutter_actor_set_geometry (label, &label_geom);
/* editable */
editable = clutter_text_new_full ("Sans Bold 32px",
"ddd",
&color_text);
clutter_actor_set_geometry (editable, &editable_geom);
clutter_text_set_editable (CLUTTER_TEXT (editable), TRUE);
clutter_text_set_selectable (CLUTTER_TEXT (editable), TRUE);
clutter_text_set_selection_color (CLUTTER_TEXT (editable),
&color_sel);
clutter_actor_grab_key_focus (editable);
clutter_actor_set_reactive (editable, TRUE);
/* rectangle: to create a entry "feeling" */
rectangle = clutter_rectangle_new_with_color (&color_rect);
clutter_actor_set_geometry (rectangle, &editable_geom);
clutter_group_add (CLUTTER_GROUP (stage), label);
clutter_group_add (CLUTTER_GROUP (stage), editable);
clutter_group_add (CLUTTER_GROUP (stage), rectangle);
label_geom.y += HEIGHT_STEP;
editable_geom.y += HEIGHT_STEP;
}
}
int
main (int argc, char *argv[])
{
ClutterActor *stage = NULL;
Data data1, data2,data3;
guint id_2 = 0;
g_set_application_name ("AtkText");
clutter_init (&argc, &argv);
cally_util_a11y_init (&argc, &argv);
data1.value = 10;
data2.value = 20;
data3.value = 30;
/* key event listeners */
atk_add_key_event_listener ((AtkKeySnoopFunc)atk_key_listener, &data1);
id_2 = atk_add_key_event_listener ((AtkKeySnoopFunc)atk_key_listener, &data2);
atk_add_key_event_listener ((AtkKeySnoopFunc)atk_key_listener, &data3);
atk_remove_key_event_listener (id_2);
/* event listeners */
atk_add_global_event_listener (window_event_listener, "window:create");
atk_add_global_event_listener (window_event_listener, "window:destroy");
atk_add_global_event_listener (window_event_listener, "window:activate");
atk_add_global_event_listener (window_event_listener, "window:deactivate");
stage = clutter_stage_get_default ();
make_ui (stage);
clutter_actor_show_all (stage);
if (clutter_feature_available (CLUTTER_FEATURE_STAGE_MULTIPLE))
{
stage = clutter_stage_new ();
make_ui (stage);
clutter_actor_show_all (stage);
}
clutter_main ();
return 0;
}

View File

@ -0,0 +1,212 @@
/* CALLY - The Clutter Accessibility Implementation Library
*
* Copyright (C) 2009 Igalia, S.L.
*
* Author: Alejandro Piñeiro Iglesias <apinheiro@igalia.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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 <atk/atk.h>
#include <clutter/clutter.h>
#include "cally-examples-util.h"
#define WIDTH 800
#define HEIGHT 600
static ClutterActor *text_actor = NULL;
static ClutterActor *text_editable_actor = NULL;
/*
* Test AtkText interface
*/
static void
test_atk_text (ClutterActor *actor)
{
gchar *text = NULL;
AtkObject *object = NULL;
AtkText *cally_text = NULL;
gboolean bool = FALSE;
gunichar unichar;
gchar buf[7];
gint count = -1;
gint start = -1;
gint end = -1;
gint pos = -1;
AtkAttributeSet *at_set = NULL;
object = atk_gobject_accessible_for_object (G_OBJECT (actor));
cally_text = ATK_TEXT (object);
if (cally_text != NULL) {
text = atk_text_get_text (cally_text, 0, -1);
g_print ("atk_text_get_text output: %s\n", text);
g_free (text); text = NULL;
unichar = atk_text_get_character_at_offset (cally_text, 5);
g_unichar_to_utf8 (unichar, buf);
g_print ("atk_text_get_character_at_offset: %s\n", buf);
text = atk_text_get_text_before_offset (cally_text,
5, ATK_TEXT_BOUNDARY_WORD_END,
&start, &end);
g_print ("atk_text_get_text_before_offset: %s, %i, %i\n",
text, start, end);
g_free (text); text = NULL;
text = atk_text_get_text_at_offset (cally_text,
5, ATK_TEXT_BOUNDARY_WORD_END,
&start, &end);
g_print ("atk_text_get_text_at_offset: %s, %i, %i\n",
text, start, end);
g_free (text); text = NULL;
text = atk_text_get_text_after_offset (cally_text,
5, ATK_TEXT_BOUNDARY_WORD_END,
&start, &end);
g_print ("atk_text_get_text_after_offset: %s, %i, %i\n",
text, start, end);
g_free (text); text = NULL;
pos = atk_text_get_caret_offset (cally_text);
g_print ("atk_text_get_caret_offset: %i\n", pos);
atk_text_set_caret_offset (cally_text, 5);
count = atk_text_get_character_count (cally_text);
g_print ("atk_text_get_character_count: %i\n", count);
count = atk_text_get_n_selections (cally_text);
g_print ("atk_text_get_n_selections: %i\n", count);
text = atk_text_get_selection (cally_text, 0, &start, &end);
g_print ("atk_text_get_selection: %s, %i, %i\n", text, start, end);
g_free(text); text = NULL;
bool = atk_text_remove_selection (cally_text, 0);
g_print ("atk_text_remove_selection (0): %i\n", bool);
bool = atk_text_remove_selection (cally_text, 1);
g_print ("atk_text_remove_selection (1): %i\n", bool);
bool = atk_text_add_selection (cally_text, 5, 10);
g_print ("atk_text_add_selection: %i\n", bool);
bool = atk_text_set_selection (cally_text, 0, 6, 10);
g_print ("atk_text_set_selection: %i\n", bool);
at_set = atk_text_get_run_attributes (cally_text, 10,
&start, &end);
g_print ("atk_text_get_run_attributes: %i, %i\n", start, end);
at_set = atk_text_get_default_attributes (cally_text);
g_print ("atk_text_get_default_attributes: (at_set==NULL) == %i \n",
at_set == NULL);
}
}
static gboolean
button_press_cb (ClutterActor *actor,
ClutterButtonEvent *event,
gpointer data)
{
test_atk_text (text_actor);
test_atk_text (text_editable_actor);
return TRUE;
}
static void
make_ui (ClutterActor *stage)
{
ClutterColor color_stage = { 0x00, 0x00, 0x00, 0xff };
ClutterColor color_text = { 0xff, 0x00, 0x00, 0xff };
ClutterColor color_sel = { 0x00, 0xff, 0x00, 0x55 };
ClutterColor color_rect = { 0x00, 0xff, 0xff, 0xff };
ClutterColor color_label = { 0x00, 0x00, 0x00, 0xff };
ClutterActor *button = NULL;
ClutterActor *rectangle = NULL;
ClutterActor *label = NULL;
clutter_stage_set_color (CLUTTER_STAGE (stage), &color_stage);
clutter_actor_set_size (stage, WIDTH, HEIGHT);
/* text */
text_actor = clutter_text_new_full ("Sans Bold 32px",
"Lorem ipsum dolor sit amet",
&color_text);
clutter_group_add (CLUTTER_GROUP (stage), text_actor);
/* text_editable */
text_editable_actor = clutter_text_new_full ("Sans Bold 32px",
"consectetur adipisicing elit",
&color_text);
clutter_actor_set_position (text_editable_actor, 0, 100);
clutter_text_set_editable (CLUTTER_TEXT (text_editable_actor), TRUE);
clutter_text_set_selectable (CLUTTER_TEXT (text_editable_actor), TRUE);
clutter_text_set_selection_color (CLUTTER_TEXT (text_editable_actor),
&color_sel);
clutter_text_set_line_wrap (CLUTTER_TEXT (text_editable_actor), TRUE);
clutter_actor_grab_key_focus (text_editable_actor);
clutter_actor_set_reactive (text_editable_actor, TRUE);
clutter_group_add (CLUTTER_GROUP (stage), text_editable_actor);
/* test button */
button = clutter_group_new ();
rectangle = clutter_rectangle_new_with_color (&color_rect);
clutter_actor_set_size (rectangle, 75, 35);
label = clutter_text_new_full ("Sans Bold 32px",
"Test", &color_label);
clutter_actor_set_position (button, 100, 200);
clutter_group_add (CLUTTER_GROUP (button), rectangle);
clutter_group_add (CLUTTER_GROUP (button), label);
clutter_actor_set_reactive (button, TRUE);
g_signal_connect_after (button, "button-press-event",
G_CALLBACK (button_press_cb), NULL);
clutter_group_add (CLUTTER_GROUP (stage), button);
}
int
main (int argc, char *argv[])
{
ClutterActor *stage = NULL;
g_set_application_name ("AtkText");
clutter_init (&argc, &argv);
cally_util_a11y_init (&argc, &argv);
stage = clutter_stage_get_default ();
make_ui (stage);
clutter_actor_show_all (stage);
test_atk_text (text_actor);
test_atk_text (text_editable_actor);
clutter_main ();
return 0;
}

View File

@ -0,0 +1,112 @@
/* CALLY - The Clutter Accessibility Implementation Library
*
* Copyright (C) 2009 Igalia, S.L.
*
* Author: Alejandro Piñeiro Iglesias <apinheiro@igalia.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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 <atk/atk.h>
#include <clutter/clutter.h>
#include "cally-examples-util.h"
#define WIDTH 800
#define HEIGHT 600
#define HEIGHT_STEP 100
#define NUM_ENTRIES 3
static void
make_ui (ClutterActor *stage)
{
ClutterActor *editable = NULL;
ClutterActor *rectangle = NULL;
ClutterActor *label = NULL;
ClutterColor color_stage = { 0x00, 0x00, 0x00, 0xff };
ClutterColor color_text = { 0xff, 0x00, 0x00, 0xff };
ClutterColor color_sel = { 0x00, 0xff, 0x00, 0x55 };
ClutterColor color_label = { 0x00, 0xff, 0x55, 0xff };
ClutterColor color_rect = { 0x00, 0xff, 0xff, 0x55 };
ClutterGeometry editable_geom = {150, 50, 100, 75};
ClutterActor *full_entry = NULL;
ClutterActor *cloned_entry = NULL;
clutter_stage_set_color (CLUTTER_STAGE (stage), &color_stage);
clutter_actor_set_size (stage, WIDTH, HEIGHT);
label = clutter_text_new_full ("Sans Bold 32px",
"Entry",
&color_label);
clutter_actor_set_position (label, 0, 50);
/* editable */
editable = clutter_text_new_full ("Sans Bold 32px",
"ddd",
&color_text);
clutter_actor_set_position (editable, 150, 50);
clutter_text_set_editable (CLUTTER_TEXT (editable), TRUE);
clutter_text_set_selectable (CLUTTER_TEXT (editable), TRUE);
clutter_text_set_selection_color (CLUTTER_TEXT (editable),
&color_sel);
clutter_actor_grab_key_focus (editable);
clutter_actor_set_reactive (editable, TRUE);
/* rectangle: to create a entry "feeling" */
rectangle = clutter_rectangle_new_with_color (&color_rect);
clutter_actor_set_geometry (rectangle, &editable_geom);
full_entry = clutter_group_new ();
clutter_actor_set_position (full_entry, 0, 50);
clutter_actor_set_size (full_entry, 100, 75);
clutter_group_add (CLUTTER_GROUP (full_entry), label);
clutter_group_add (CLUTTER_GROUP (full_entry), editable);
clutter_group_add (CLUTTER_GROUP (full_entry), rectangle);
clutter_actor_show_all (full_entry);
clutter_actor_set_scale (full_entry, 2, 1);
clutter_group_add (CLUTTER_GROUP (stage), full_entry);
/* Cloning! */
cloned_entry = clutter_clone_new (full_entry);
clutter_actor_set_position (cloned_entry, 50, 200);
clutter_actor_set_scale (cloned_entry, 1, 2);
clutter_actor_show_all (cloned_entry);
clutter_actor_set_reactive (cloned_entry, TRUE);
clutter_group_add (CLUTTER_GROUP (stage), cloned_entry);
}
int
main (int argc, char *argv[])
{
ClutterActor *stage = NULL;
g_set_application_name ("Clone Example");
clutter_init (&argc, &argv);
cally_util_a11y_init (&argc, &argv);
stage = clutter_stage_get_default ();
make_ui (stage);
clutter_actor_show_all (stage);
clutter_main ();
return 0;
}

View File

@ -0,0 +1,216 @@
/* CALLY - The Clutter Accessibility Implementation Library
*
* Copyright (C) 2009 Igalia, S.L.
*
* Author: Alejandro Piñeiro Iglesias <apinheiro@igalia.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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 <gmodule.h>
#include <stdlib.h>
#include <clutter/clutter.h>
#include "cally-examples-util.h"
/* Checking the at-spi sources, the module directory is
* $(libdir)/gtk-2.0/modules
*
* It is supposed cally would be installed on the same libdir.
*
* You could use the option atk-bridge-dir to use other directory.
*/
#define ATK_BRIDGE_DEFAULT_MODULE_DIRECTORY PREFIXDIR"/gtk-2.0/modules"
/* Convenient default directory (debug purposes) */
#define CALLY_DEFAULT_MODULE_DIRECTORY "../cally/.libs"
static gchar **
_get_clutter_module_paths (void)
{
gchar **retval;
GPtrArray *paths;
const gchar *modules_dir;
paths = g_ptr_array_new ();
/* CLUTTER_[API/ABI]_VERSION_S not provided by clutter */
/* g_ptr_array_add (paths, */
/* g_build_filename (g_get_home_dir (), */
/* ".clutter-" CLUTTER_API_VERSION_S, */
/* CLUTTER_ABI_VERSION_S, */
/* "modules", */
/* NULL)); */
/* g_ptr_array_add (paths, */
/* g_build_filename (CLUTTER_LIBDIR, */
/* "clutter-" CLUTTER_API_VERSION_S, */
/* CLUTTER_ABI_VERSION_S, */
/* "modules", */
/* NULL)); */
g_ptr_array_add (paths, g_strdup (CALLY_DEFAULT_MODULE_DIRECTORY));
modules_dir = g_getenv ("CLUTTER_MODULES_PATH");
if (modules_dir)
g_ptr_array_add (paths, g_strdup (modules_dir));
g_ptr_array_add (paths, NULL);
retval = (gchar **) paths->pdata;
g_ptr_array_free (paths, FALSE);
return retval;
}
static gchar *
_search_for_clutter_module (const gchar *module_name)
{
gchar **paths, **path;
gchar *module_path = NULL;
paths = _get_clutter_module_paths ();
for (path = paths; *path; path++)
{
gchar *tmp_name;
tmp_name = g_module_build_path (*path, module_name);
if (g_file_test (tmp_name, G_FILE_TEST_EXISTS))
{
module_path = tmp_name;
break;
}
g_free (tmp_name);
}
g_strfreev (paths);
return module_path;
}
static gchar *
_search_for_bridge_module (const gchar *module_name)
{
/* We simplify the search for the atk bridge, see see the definition
* of the macro for more information*/
return g_strdup (ATK_BRIDGE_DEFAULT_MODULE_DIRECTORY);
}
static gchar*
_a11y_check_custom_bridge (int *argc,
char ***argv)
{
GError *error = NULL;
GOptionContext *context;
static gchar *bridge_dir = NULL;
static GOptionEntry entries [] =
{
{"atk-bridge-dir", 'd', 0, G_OPTION_ARG_STRING, &bridge_dir, "atk-bridge module directory", NULL}
};
context = g_option_context_new ("- cally examples");
g_option_context_add_main_entries (context, entries, NULL);
if (!g_option_context_parse (context, argc, argv, &error))
{
g_print ("%s\n", error->message);
g_print ("Use --help for more information.\n");
exit (0);
}
return bridge_dir;
}
static gboolean
_a11y_invoke_module (const gchar *module_path,
gboolean init)
{
GModule *handle;
void (*invoke_fn) (void);
const char *method;
if (init)
method = "gnome_accessibility_module_init";
else
method = "gnome_accessibility_module_shutdown";
if (!module_path)
return FALSE;
if (!(handle = g_module_open (module_path, G_MODULE_BIND_LAZY)))
{
g_warning ("Accessibility: failed to load module '%s': '%s'",
module_path, g_module_error ());
return FALSE;
}
if (!g_module_symbol (handle, method, (gpointer *)&invoke_fn))
{
g_warning ("Accessibility: error library '%s' does not include "
"method '%s' required for accessibility support",
module_path, method);
g_module_close (handle);
return FALSE;
}
g_debug ("Module %s loaded successfully", module_path);
invoke_fn ();
return TRUE;
}
/**
* This method will initialize the accessibility support provided by cally.
*
* Basically it will load the cally module using gmodule functions.
*
*/
void
cally_util_a11y_init (int *argc, char ***argv)
{
gchar *bridge_dir = NULL;
gchar *cally_path = NULL;
gchar *bridge_path = NULL;
cally_path = _search_for_clutter_module ("cally-1.0");
if (cally_path == NULL)
{
g_warning ("Accessibility: failed to find module 'cally-1.0' "
"which is needed to make this application accessible");
return;
}
bridge_dir = _a11y_check_custom_bridge (argc, argv);
if (bridge_dir == NULL)
bridge_dir = _search_for_bridge_module ("atk-bridge");
bridge_path = g_module_build_path (bridge_dir, "libatk-bridge");
_a11y_invoke_module (cally_path, TRUE);
_a11y_invoke_module (bridge_path, TRUE);
g_free (bridge_dir);
g_free (bridge_path);
g_free (cally_path);
}

View File

@ -0,0 +1,24 @@
/* CALLY - The Clutter Accessibility Implementation Library
*
* Copyright (C) 2009 Igalia, S.L.
*
* Author: Alejandro Piñeiro Iglesias <apinheiro@igalia.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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.
*/
void
cally_util_a11y_init (int *argc, char ***argv);