| 1 |
/* CALLY - The Clutter Accessibility Implementation Library |
| 2 |
* |
| 3 |
* Copyright (C) 2009 Igalia, S.L. |
| 4 |
* |
| 5 |
* Author: Alejandro Piñeiro Iglesias <[email protected]> |
| 6 |
* |
| 7 |
* This library is free software; you can redistribute it and/or |
| 8 |
* modify it under the terms of the GNU Lesser General Public |
| 9 |
* License as published by the Free Software Foundation; either |
| 10 |
* version 2 of the License, or (at your option) any later version. |
| 11 |
* |
| 12 |
* This library is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 |
* Lesser General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU Lesser General Public |
| 18 |
* License along with this library; if not, write to the |
| 19 |
* Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 20 |
* Boston, MA 02111-1307, USA. |
| 21 |
*/ |
| 22 |
|
| 23 |
#include <atk/atk.h> |
| 24 |
#include <clutter/clutter.h> |
| 25 |
|
| 26 |
#include "cally-examples-util.h" |
| 27 |
|
| 28 |
#define WIDTH 800 |
| 29 |
#define HEIGHT 600 |
| 30 |
|
| 31 |
static ClutterActor *text_actor = NULL; |
| 32 |
static ClutterActor *text_editable_actor = NULL; |
| 33 |
|
| 34 |
/* |
| 35 |
* Test AtkText interface |
| 36 |
*/ |
| 37 |
static void |
| 38 |
test_atk_text (ClutterActor *actor) |
| 39 |
{ |
| 40 |
gchar *text = NULL; |
| 41 |
AtkObject *object = NULL; |
| 42 |
AtkText *cally_text = NULL; |
| 43 |
gboolean bool = FALSE; |
| 44 |
gunichar unichar; |
| 45 |
gint count = -1; |
| 46 |
gint start = -1; |
| 47 |
gint end = -1; |
| 48 |
gint pos = -1; |
| 49 |
AtkAttributeSet *at_set = NULL; |
| 50 |
GSList *attrs; |
| 51 |
gchar *buf; |
| 52 |
gint x, y, width, height; |
| 53 |
|
| 54 |
object = atk_gobject_accessible_for_object (G_OBJECT (actor)); |
| 55 |
cally_text = ATK_TEXT (object); |
| 56 |
|
| 57 |
if (!cally_text) |
| 58 |
return; |
| 59 |
|
| 60 |
text = atk_text_get_text (cally_text, 0, -1); |
| 61 |
g_print ("atk_text_get_text output: %s\n", text); |
| 62 |
|
| 63 |
unichar = atk_text_get_character_at_offset (cally_text, 5); |
| 64 |
buf = g_ucs4_to_utf8 (&unichar, 1, NULL, NULL, NULL); |
| 65 |
g_print ("atk_text_get_character_at_offset(5): '%s' vs '%c'\n", buf, text[5]); |
| 66 |
g_free (text); text = NULL; |
| 67 |
g_free (buf); buf = NULL; |
| 68 |
|
| 69 |
text = atk_text_get_text_before_offset (cally_text, |
| 70 |
5, ATK_TEXT_BOUNDARY_WORD_END, |
| 71 |
&start, &end); |
| 72 |
g_print ("atk_text_get_text_before_offset: %s, %i, %i\n", |
| 73 |
text, start, end); |
| 74 |
g_free (text); text = NULL; |
| 75 |
|
| 76 |
text = atk_text_get_text_at_offset (cally_text, |
| 77 |
5, ATK_TEXT_BOUNDARY_WORD_END, |
| 78 |
&start, &end); |
| 79 |
g_print ("atk_text_get_text_at_offset: %s, %i, %i\n", |
| 80 |
text, start, end); |
| 81 |
g_free (text); text = NULL; |
| 82 |
|
| 83 |
text = atk_text_get_text_after_offset (cally_text, |
| 84 |
5, ATK_TEXT_BOUNDARY_WORD_END, |
| 85 |
&start, &end); |
| 86 |
g_print ("atk_text_get_text_after_offset: %s, %i, %i\n", |
| 87 |
text, start, end); |
| 88 |
g_free (text); text = NULL; |
| 89 |
|
| 90 |
pos = atk_text_get_caret_offset (cally_text); |
| 91 |
g_print ("atk_text_get_caret_offset: %i\n", pos); |
| 92 |
|
| 93 |
atk_text_set_caret_offset (cally_text, 5); |
| 94 |
|
| 95 |
count = atk_text_get_character_count (cally_text); |
| 96 |
g_print ("atk_text_get_character_count: %i\n", count); |
| 97 |
|
| 98 |
count = atk_text_get_n_selections (cally_text); |
| 99 |
g_print ("atk_text_get_n_selections: %i\n", count); |
| 100 |
|
| 101 |
text = atk_text_get_selection (cally_text, 0, &start, &end); |
| 102 |
g_print ("atk_text_get_selection: %s, %i, %i\n", text, start, end); |
| 103 |
g_free(text); text = NULL; |
| 104 |
|
| 105 |
bool = atk_text_remove_selection (cally_text, 0); |
| 106 |
g_print ("atk_text_remove_selection (0): %i\n", bool); |
| 107 |
|
| 108 |
bool = atk_text_remove_selection (cally_text, 1); |
| 109 |
g_print ("atk_text_remove_selection (1): %i\n", bool); |
| 110 |
|
| 111 |
bool = atk_text_add_selection (cally_text, 5, 10); |
| 112 |
g_print ("atk_text_add_selection: %i\n", bool); |
| 113 |
|
| 114 |
bool = atk_text_set_selection (cally_text, 0, 6, 10); |
| 115 |
g_print ("atk_text_set_selection: %i\n", bool); |
| 116 |
|
| 117 |
at_set = atk_text_get_run_attributes (cally_text, 0, |
| 118 |
&start, &end); |
| 119 |
g_print ("atk_text_get_run_attributes: %i, %i\n", start, end); |
| 120 |
attrs = (GSList*) at_set; |
| 121 |
while (attrs) |
| 122 |
{ |
| 123 |
AtkAttribute *at = (AtkAttribute *) attrs->data; |
| 124 |
g_print ("text run %s = %s\n", at->name, at->value); |
| 125 |
attrs = g_slist_next (attrs); |
| 126 |
} |
| 127 |
|
| 128 |
atk_text_get_character_extents (cally_text, 0, &x, &y, &width, &height, |
| 129 |
ATK_XY_WINDOW); |
| 130 |
g_print ("atk_text_get_character_extents (0, window): x=%i y=%i width=%i height=%i\n", |
| 131 |
x, y, width, height); |
| 132 |
|
| 133 |
atk_text_get_character_extents (cally_text, 0, &x, &y, &width, &height, |
| 134 |
ATK_XY_SCREEN); |
| 135 |
g_print ("atk_text_get_character_extents (0, screen): x=%i y=%i width=%i height=%i\n", |
| 136 |
x, y, width, height); |
| 137 |
|
| 138 |
pos = atk_text_get_offset_at_point (cally_text, 200, 10, ATK_XY_WINDOW); |
| 139 |
g_print ("atk_text_get_offset_at_point (200, 10, window): %i\n", pos); |
| 140 |
|
| 141 |
pos = atk_text_get_offset_at_point (cally_text, 200, 100, ATK_XY_SCREEN); |
| 142 |
g_print ("atk_text_get_offset_at_point (200, 100, screen): %i\n", pos); |
| 143 |
|
| 144 |
} |
| 145 |
|
| 146 |
static void |
| 147 |
dump_actor_default_atk_attributes (ClutterActor *actor) |
| 148 |
{ |
| 149 |
AtkObject *object = NULL; |
| 150 |
AtkText *cally_text = NULL; |
| 151 |
AtkAttributeSet *at_set = NULL; |
| 152 |
GSList *attrs; |
| 153 |
const gchar *text_value = NULL; |
| 154 |
|
| 155 |
object = atk_gobject_accessible_for_object (G_OBJECT (actor)); |
| 156 |
cally_text = ATK_TEXT (object); |
| 157 |
|
| 158 |
if (!cally_text) |
| 159 |
return; |
| 160 |
|
| 161 |
text_value = clutter_text_get_text (CLUTTER_TEXT (actor)); |
| 162 |
g_print ("text value = %s\n", text_value); |
| 163 |
|
| 164 |
at_set = atk_text_get_default_attributes (cally_text); |
| 165 |
attrs = (GSList*) at_set; |
| 166 |
while (attrs) { |
| 167 |
AtkAttribute *at = (AtkAttribute *) attrs->data; |
| 168 |
g_print ("text default %s = %s\n", at->name, at->value); |
| 169 |
attrs = g_slist_next (attrs); |
| 170 |
} |
| 171 |
} |
| 172 |
|
| 173 |
static gboolean |
| 174 |
button_press_cb (ClutterActor *actor, |
| 175 |
ClutterButtonEvent *event, |
| 176 |
gpointer data) |
| 177 |
{ |
| 178 |
test_atk_text (text_actor); |
| 179 |
test_atk_text (text_editable_actor); |
| 180 |
|
| 181 |
return TRUE; |
| 182 |
} |
| 183 |
|
| 184 |
static void |
| 185 |
make_ui (ClutterActor *stage) |
| 186 |
{ |
| 187 |
ClutterColor color_stage = { 0x00, 0x00, 0x00, 0xff }; |
| 188 |
ClutterColor color_text = { 0xff, 0x00, 0x00, 0xff }; |
| 189 |
ClutterColor color_sel = { 0x00, 0xff, 0x00, 0x55 }; |
| 190 |
ClutterColor color_rect = { 0x00, 0xff, 0xff, 0xff }; |
| 191 |
ClutterColor color_label = { 0x00, 0x00, 0x00, 0xff }; |
| 192 |
ClutterActor *button = NULL; |
| 193 |
ClutterActor *rectangle = NULL; |
| 194 |
ClutterActor *label = NULL; |
| 195 |
|
| 196 |
clutter_stage_set_color (CLUTTER_STAGE (stage), &color_stage); |
| 197 |
clutter_actor_set_size (stage, WIDTH, HEIGHT); |
| 198 |
|
| 199 |
/* text */ |
| 200 |
text_actor = clutter_text_new_full ("Sans Bold 32px", |
| 201 |
"", |
| 202 |
&color_text); |
| 203 |
clutter_text_set_markup (CLUTTER_TEXT(text_actor), |
| 204 |
"<span fgcolor=\"#FFFF00\" bgcolor=\"#00FF00\"><s>Lorem ipsum dolor sit amet</s></span>"); |
| 205 |
clutter_container_add_actor (CLUTTER_CONTAINER (stage), text_actor); |
| 206 |
dump_actor_default_atk_attributes (text_actor); |
| 207 |
|
| 208 |
/* text_editable */ |
| 209 |
text_editable_actor = clutter_text_new_full ("Sans Bold 32px", |
| 210 |
"consectetur adipisicing elit", |
| 211 |
&color_text); |
| 212 |
clutter_actor_set_position (text_editable_actor, 20, 100); |
| 213 |
clutter_text_set_editable (CLUTTER_TEXT (text_editable_actor), TRUE); |
| 214 |
clutter_text_set_selectable (CLUTTER_TEXT (text_editable_actor), TRUE); |
| 215 |
clutter_text_set_selection_color (CLUTTER_TEXT (text_editable_actor), |
| 216 |
&color_sel); |
| 217 |
clutter_text_set_line_wrap (CLUTTER_TEXT (text_editable_actor), TRUE); |
| 218 |
clutter_actor_grab_key_focus (text_editable_actor); |
| 219 |
clutter_actor_set_reactive (text_editable_actor, TRUE); |
| 220 |
dump_actor_default_atk_attributes (text_editable_actor); |
| 221 |
|
| 222 |
clutter_container_add_actor (CLUTTER_CONTAINER (stage), text_editable_actor); |
| 223 |
|
| 224 |
/* test button */ |
| 225 |
button = clutter_group_new (); |
| 226 |
rectangle = clutter_rectangle_new_with_color (&color_rect); |
| 227 |
clutter_actor_set_size (rectangle, 75, 35); |
| 228 |
|
| 229 |
label = clutter_text_new_full ("Sans Bold 32px", |
| 230 |
"Test", &color_label); |
| 231 |
clutter_actor_set_position (button, 100, 200); |
| 232 |
clutter_container_add_actor (CLUTTER_CONTAINER (button), rectangle); |
| 233 |
clutter_container_add_actor (CLUTTER_CONTAINER (button), label); |
| 234 |
clutter_actor_set_reactive (button, TRUE); |
| 235 |
|
| 236 |
g_signal_connect_after (button, "button-press-event", |
| 237 |
G_CALLBACK (button_press_cb), NULL); |
| 238 |
|
| 239 |
clutter_container_add_actor (CLUTTER_CONTAINER (stage), button); |
| 240 |
} |
| 241 |
|
| 242 |
int |
| 243 |
main (int argc, char *argv[]) |
| 244 |
{ |
| 245 |
ClutterActor *stage; |
| 246 |
|
| 247 |
g_set_application_name ("AtkText"); |
| 248 |
|
| 249 |
if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) |
| 250 |
return 1; |
| 251 |
|
| 252 |
cally_util_a11y_init (&argc, &argv); |
| 253 |
|
| 254 |
stage = clutter_stage_new (); |
| 255 |
clutter_stage_set_title (CLUTTER_STAGE (stage), "Cally - AtkText Test"); |
| 256 |
g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); |
| 257 |
|
| 258 |
make_ui (stage); |
| 259 |
|
| 260 |
clutter_actor_show_all (stage); |
| 261 |
|
| 262 |
test_atk_text (text_actor); |
| 263 |
test_atk_text (text_editable_actor); |
| 264 |
|
| 265 |
clutter_main (); |
| 266 |
|
| 267 |
return 0; |
| 268 |
} |