2010-04-26 18:07:22 +00:00
|
|
|
/* 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
|
2015-01-03 20:34:20 +00:00
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
2010-04-26 18:07:22 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#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;
|
|
|
|
gint count = -1;
|
|
|
|
gint start = -1;
|
|
|
|
gint end = -1;
|
|
|
|
gint pos = -1;
|
|
|
|
AtkAttributeSet *at_set = NULL;
|
2011-02-04 08:36:19 +00:00
|
|
|
GSList *attrs;
|
|
|
|
gchar *buf;
|
2011-02-02 10:29:33 +00:00
|
|
|
gint x, y, width, height;
|
2010-04-26 18:07:22 +00:00
|
|
|
|
|
|
|
object = atk_gobject_accessible_for_object (G_OBJECT (actor));
|
|
|
|
cally_text = ATK_TEXT (object);
|
|
|
|
|
2011-02-04 08:36:19 +00:00
|
|
|
if (!cally_text)
|
|
|
|
return;
|
2010-04-26 18:07:22 +00:00
|
|
|
|
2011-02-04 08:36:19 +00:00
|
|
|
text = atk_text_get_text (cally_text, 0, -1);
|
|
|
|
g_print ("atk_text_get_text output: %s\n", text);
|
2010-04-26 18:07:22 +00:00
|
|
|
|
2011-02-04 08:36:19 +00:00
|
|
|
unichar = atk_text_get_character_at_offset (cally_text, 5);
|
|
|
|
buf = g_ucs4_to_utf8 (&unichar, 1, NULL, NULL, NULL);
|
|
|
|
g_print ("atk_text_get_character_at_offset(5): '%s' vs '%c'\n", buf, text[5]);
|
|
|
|
g_free (text); text = NULL;
|
|
|
|
g_free (buf); buf = NULL;
|
2010-04-26 18:07:22 +00:00
|
|
|
|
2011-02-04 08:36:19 +00:00
|
|
|
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;
|
2010-04-26 18:07:22 +00:00
|
|
|
|
2011-02-04 08:36:19 +00:00
|
|
|
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;
|
2010-04-26 18:07:22 +00:00
|
|
|
|
2011-02-04 08:36:19 +00:00
|
|
|
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;
|
2010-04-26 18:07:22 +00:00
|
|
|
|
2011-02-04 08:36:19 +00:00
|
|
|
pos = atk_text_get_caret_offset (cally_text);
|
|
|
|
g_print ("atk_text_get_caret_offset: %i\n", pos);
|
2010-04-26 18:07:22 +00:00
|
|
|
|
2011-02-04 08:36:19 +00:00
|
|
|
atk_text_set_caret_offset (cally_text, 5);
|
2010-04-26 18:07:22 +00:00
|
|
|
|
2011-02-04 08:36:19 +00:00
|
|
|
count = atk_text_get_character_count (cally_text);
|
|
|
|
g_print ("atk_text_get_character_count: %i\n", count);
|
2010-04-26 18:07:22 +00:00
|
|
|
|
2011-02-04 08:36:19 +00:00
|
|
|
count = atk_text_get_n_selections (cally_text);
|
|
|
|
g_print ("atk_text_get_n_selections: %i\n", count);
|
2010-04-26 18:07:22 +00:00
|
|
|
|
2011-02-04 08:36:19 +00:00
|
|
|
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;
|
2010-04-26 18:07:22 +00:00
|
|
|
|
2011-02-04 08:36:19 +00:00
|
|
|
bool = atk_text_remove_selection (cally_text, 0);
|
|
|
|
g_print ("atk_text_remove_selection (0): %i\n", bool);
|
2010-04-26 18:07:22 +00:00
|
|
|
|
2011-02-04 08:36:19 +00:00
|
|
|
bool = atk_text_remove_selection (cally_text, 1);
|
|
|
|
g_print ("atk_text_remove_selection (1): %i\n", bool);
|
2010-04-26 18:07:22 +00:00
|
|
|
|
2011-02-04 08:36:19 +00:00
|
|
|
bool = atk_text_add_selection (cally_text, 5, 10);
|
|
|
|
g_print ("atk_text_add_selection: %i\n", bool);
|
2010-04-26 18:07:22 +00:00
|
|
|
|
2011-02-04 08:36:19 +00:00
|
|
|
bool = atk_text_set_selection (cally_text, 0, 6, 10);
|
|
|
|
g_print ("atk_text_set_selection: %i\n", bool);
|
2010-04-26 18:07:22 +00:00
|
|
|
|
2011-02-04 08:36:19 +00:00
|
|
|
at_set = atk_text_get_run_attributes (cally_text, 0,
|
|
|
|
&start, &end);
|
|
|
|
g_print ("atk_text_get_run_attributes: %i, %i\n", start, end);
|
|
|
|
attrs = (GSList*) at_set;
|
|
|
|
while (attrs)
|
|
|
|
{
|
|
|
|
AtkAttribute *at = (AtkAttribute *) attrs->data;
|
|
|
|
g_print ("text run %s = %s\n", at->name, at->value);
|
|
|
|
attrs = g_slist_next (attrs);
|
|
|
|
}
|
2010-04-26 18:07:22 +00:00
|
|
|
|
2011-02-02 10:29:33 +00:00
|
|
|
atk_text_get_character_extents (cally_text, 0, &x, &y, &width, &height,
|
|
|
|
ATK_XY_WINDOW);
|
|
|
|
g_print ("atk_text_get_character_extents (0, window): x=%i y=%i width=%i height=%i\n",
|
|
|
|
x, y, width, height);
|
|
|
|
|
|
|
|
atk_text_get_character_extents (cally_text, 0, &x, &y, &width, &height,
|
|
|
|
ATK_XY_SCREEN);
|
|
|
|
g_print ("atk_text_get_character_extents (0, screen): x=%i y=%i width=%i height=%i\n",
|
|
|
|
x, y, width, height);
|
|
|
|
|
2011-02-02 11:58:47 +00:00
|
|
|
pos = atk_text_get_offset_at_point (cally_text, 200, 10, ATK_XY_WINDOW);
|
|
|
|
g_print ("atk_text_get_offset_at_point (200, 10, window): %i\n", pos);
|
|
|
|
|
|
|
|
pos = atk_text_get_offset_at_point (cally_text, 200, 100, ATK_XY_SCREEN);
|
|
|
|
g_print ("atk_text_get_offset_at_point (200, 100, screen): %i\n", pos);
|
|
|
|
|
2010-04-26 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
2011-07-06 14:51:49 +00:00
|
|
|
static void
|
|
|
|
dump_actor_default_atk_attributes (ClutterActor *actor)
|
|
|
|
{
|
|
|
|
AtkObject *object = NULL;
|
|
|
|
AtkText *cally_text = NULL;
|
|
|
|
AtkAttributeSet *at_set = NULL;
|
|
|
|
GSList *attrs;
|
|
|
|
const gchar *text_value = NULL;
|
|
|
|
|
|
|
|
object = atk_gobject_accessible_for_object (G_OBJECT (actor));
|
|
|
|
cally_text = ATK_TEXT (object);
|
|
|
|
|
|
|
|
if (!cally_text)
|
|
|
|
return;
|
|
|
|
|
|
|
|
text_value = clutter_text_get_text (CLUTTER_TEXT (actor));
|
|
|
|
g_print ("text value = %s\n", text_value);
|
|
|
|
|
|
|
|
at_set = atk_text_get_default_attributes (cally_text);
|
|
|
|
attrs = (GSList*) at_set;
|
|
|
|
while (attrs) {
|
|
|
|
AtkAttribute *at = (AtkAttribute *) attrs->data;
|
|
|
|
g_print ("text default %s = %s\n", at->name, at->value);
|
|
|
|
attrs = g_slist_next (attrs);
|
|
|
|
}
|
|
|
|
}
|
2011-02-04 08:36:19 +00:00
|
|
|
|
2010-04-26 18:07:22 +00:00
|
|
|
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",
|
2011-07-06 14:51:49 +00:00
|
|
|
"",
|
2010-04-26 18:07:22 +00:00
|
|
|
&color_text);
|
2011-07-06 14:51:49 +00:00
|
|
|
clutter_text_set_markup (CLUTTER_TEXT(text_actor),
|
|
|
|
"<span fgcolor=\"#FFFF00\" bgcolor=\"#00FF00\"><s>Lorem ipsum dolor sit amet</s></span>");
|
2011-06-16 16:11:39 +00:00
|
|
|
clutter_container_add_actor (CLUTTER_CONTAINER (stage), text_actor);
|
2011-07-06 14:51:49 +00:00
|
|
|
dump_actor_default_atk_attributes (text_actor);
|
2010-04-26 18:07:22 +00:00
|
|
|
|
|
|
|
/* text_editable */
|
|
|
|
text_editable_actor = clutter_text_new_full ("Sans Bold 32px",
|
|
|
|
"consectetur adipisicing elit",
|
|
|
|
&color_text);
|
2011-02-02 10:29:33 +00:00
|
|
|
clutter_actor_set_position (text_editable_actor, 20, 100);
|
2010-04-26 18:07:22 +00:00
|
|
|
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);
|
2011-07-06 14:51:49 +00:00
|
|
|
dump_actor_default_atk_attributes (text_editable_actor);
|
2010-04-26 18:07:22 +00:00
|
|
|
|
2011-06-16 16:11:39 +00:00
|
|
|
clutter_container_add_actor (CLUTTER_CONTAINER (stage), text_editable_actor);
|
2010-04-26 18:07:22 +00:00
|
|
|
|
|
|
|
/* 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);
|
2011-06-16 16:11:39 +00:00
|
|
|
clutter_container_add_actor (CLUTTER_CONTAINER (button), rectangle);
|
|
|
|
clutter_container_add_actor (CLUTTER_CONTAINER (button), label);
|
2010-04-26 18:07:22 +00:00
|
|
|
clutter_actor_set_reactive (button, TRUE);
|
|
|
|
|
|
|
|
g_signal_connect_after (button, "button-press-event",
|
|
|
|
G_CALLBACK (button_press_cb), NULL);
|
|
|
|
|
2011-06-16 16:11:39 +00:00
|
|
|
clutter_container_add_actor (CLUTTER_CONTAINER (stage), button);
|
2010-04-26 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
2011-11-08 17:11:34 +00:00
|
|
|
ClutterActor *stage;
|
2010-04-26 18:07:22 +00:00
|
|
|
|
|
|
|
g_set_application_name ("AtkText");
|
|
|
|
|
2011-02-22 00:19:35 +00:00
|
|
|
if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
|
|
|
|
return 1;
|
2010-04-26 18:07:22 +00:00
|
|
|
|
|
|
|
cally_util_a11y_init (&argc, &argv);
|
|
|
|
|
2011-11-08 17:11:34 +00:00
|
|
|
stage = clutter_stage_new ();
|
|
|
|
clutter_stage_set_title (CLUTTER_STAGE (stage), "Cally - AtkText Test");
|
2011-11-09 10:55:49 +00:00
|
|
|
g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
|
2010-04-26 18:07:22 +00:00
|
|
|
|
|
|
|
make_ui (stage);
|
|
|
|
|
|
|
|
clutter_actor_show_all (stage);
|
|
|
|
|
|
|
|
test_atk_text (text_actor);
|
|
|
|
test_atk_text (text_editable_actor);
|
|
|
|
|
|
|
|
clutter_main ();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|