| 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 |
AtkObject *object = NULL; |
| 41 |
AtkEditableText *cally_editable_text = NULL; |
| 42 |
gint pos = 0; |
| 43 |
|
| 44 |
object = atk_gobject_accessible_for_object (G_OBJECT (actor)); |
| 45 |
cally_editable_text = ATK_EDITABLE_TEXT (object); |
| 46 |
|
| 47 |
if (cally_editable_text != NULL) { |
| 48 |
atk_editable_text_set_text_contents (cally_editable_text, "New text"); |
| 49 |
atk_editable_text_delete_text (cally_editable_text, 0, 3); |
| 50 |
pos = 3; |
| 51 |
atk_editable_text_insert_text (cally_editable_text, "New", 0, &pos); |
| 52 |
|
| 53 |
/* Not implemented in cally, just checking that we can call this |
| 54 |
functions */ |
| 55 |
atk_editable_text_copy_text (cally_editable_text, 0, -1); |
| 56 |
atk_editable_text_paste_text (cally_editable_text, 5); |
| 57 |
atk_editable_text_cut_text (cally_editable_text, 0, -1); |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
static gboolean |
| 62 |
insert_text_press_cb (ClutterActor *actor, |
| 63 |
ClutterButtonEvent *event, |
| 64 |
gpointer data) |
| 65 |
{ |
| 66 |
AtkObject *object = NULL; |
| 67 |
AtkEditableText *cally_editable_text = NULL; |
| 68 |
gint pos = 0; |
| 69 |
|
| 70 |
object = atk_gobject_accessible_for_object (G_OBJECT (text_editable_actor)); |
| 71 |
cally_editable_text = ATK_EDITABLE_TEXT (object); |
| 72 |
|
| 73 |
pos = 3; |
| 74 |
atk_editable_text_insert_text (cally_editable_text, "New", 0, &pos); |
| 75 |
|
| 76 |
return TRUE; |
| 77 |
} |
| 78 |
|
| 79 |
static gboolean |
| 80 |
delete_text_press_cb (ClutterActor *actor, |
| 81 |
ClutterButtonEvent *event, |
| 82 |
gpointer data) |
| 83 |
{ |
| 84 |
AtkObject *object = NULL; |
| 85 |
AtkEditableText *cally_editable_text = NULL; |
| 86 |
|
| 87 |
object = atk_gobject_accessible_for_object (G_OBJECT (text_editable_actor)); |
| 88 |
cally_editable_text = ATK_EDITABLE_TEXT (object); |
| 89 |
|
| 90 |
atk_editable_text_delete_text (cally_editable_text, 0, 3); |
| 91 |
|
| 92 |
return TRUE; |
| 93 |
} |
| 94 |
|
| 95 |
static gboolean |
| 96 |
set_text_press_cb (ClutterActor *actor, |
| 97 |
ClutterButtonEvent *event, |
| 98 |
gpointer data) |
| 99 |
{ |
| 100 |
AtkObject *object = NULL; |
| 101 |
AtkEditableText *cally_editable_text = NULL; |
| 102 |
|
| 103 |
object = atk_gobject_accessible_for_object (G_OBJECT (text_editable_actor)); |
| 104 |
cally_editable_text = ATK_EDITABLE_TEXT (object); |
| 105 |
|
| 106 |
atk_editable_text_set_text_contents (cally_editable_text, "New text"); |
| 107 |
|
| 108 |
return TRUE; |
| 109 |
} |
| 110 |
|
| 111 |
static gboolean |
| 112 |
activate_deactivate_press_cb (ClutterActor *actor, |
| 113 |
ClutterButtonEvent *event, |
| 114 |
gpointer data) |
| 115 |
{ |
| 116 |
gboolean active = FALSE; |
| 117 |
|
| 118 |
active = clutter_text_get_activatable (CLUTTER_TEXT (text_editable_actor)); |
| 119 |
clutter_text_set_activatable (CLUTTER_TEXT (text_editable_actor), !active); |
| 120 |
|
| 121 |
return TRUE; |
| 122 |
} |
| 123 |
|
| 124 |
static gboolean |
| 125 |
print_cursor_position_press_cb (ClutterActor *actor, |
| 126 |
ClutterButtonEvent *event, |
| 127 |
gpointer data) |
| 128 |
{ |
| 129 |
gint pos = 0; |
| 130 |
|
| 131 |
pos = clutter_text_get_cursor_position (CLUTTER_TEXT (text_editable_actor)); |
| 132 |
|
| 133 |
g_print ("current cursor position %i\n", pos); |
| 134 |
|
| 135 |
return TRUE; |
| 136 |
} |
| 137 |
|
| 138 |
static void |
| 139 |
activate_cb (ClutterActor *actor, |
| 140 |
gpointer data) |
| 141 |
{ |
| 142 |
g_print ("Actor activated\n"); |
| 143 |
} |
| 144 |
|
| 145 |
static ClutterActor* |
| 146 |
_create_button (const gchar *text) |
| 147 |
{ |
| 148 |
ClutterActor *button = NULL; |
| 149 |
ClutterActor *rectangle = NULL; |
| 150 |
ClutterActor *label = NULL; |
| 151 |
|
| 152 |
button = clutter_group_new (); |
| 153 |
rectangle = clutter_rectangle_new_with_color (CLUTTER_COLOR_Magenta); |
| 154 |
clutter_actor_set_size (rectangle, 375, 35); |
| 155 |
|
| 156 |
label = clutter_text_new_full ("Sans Bold 32px", |
| 157 |
text, |
| 158 |
CLUTTER_COLOR_Black); |
| 159 |
clutter_container_add_actor (CLUTTER_CONTAINER (button), rectangle); |
| 160 |
clutter_container_add_actor (CLUTTER_CONTAINER (button), label); |
| 161 |
clutter_actor_set_reactive (button, TRUE); |
| 162 |
|
| 163 |
return button; |
| 164 |
} |
| 165 |
|
| 166 |
static void |
| 167 |
make_ui (ClutterActor *stage) |
| 168 |
{ |
| 169 |
ClutterActor *button = NULL; |
| 170 |
|
| 171 |
clutter_stage_set_title (CLUTTER_STAGE (stage), "Cally - AtkEditable Test"); |
| 172 |
clutter_stage_set_color (CLUTTER_STAGE (stage), CLUTTER_COLOR_White); |
| 173 |
clutter_actor_set_size (stage, WIDTH, HEIGHT); |
| 174 |
|
| 175 |
/* text */ |
| 176 |
text_actor = clutter_text_new_full ("Sans Bold 32px", |
| 177 |
"Lorem ipsum dolor sit amet", |
| 178 |
CLUTTER_COLOR_Red); |
| 179 |
clutter_container_add_actor (CLUTTER_CONTAINER (stage), text_actor); |
| 180 |
|
| 181 |
/* text_editable */ |
| 182 |
text_editable_actor = clutter_text_new_full ("Sans Bold 32px", |
| 183 |
"consectetur adipisicing elit", |
| 184 |
CLUTTER_COLOR_Red); |
| 185 |
clutter_actor_set_position (text_editable_actor, 0, 100); |
| 186 |
clutter_text_set_editable (CLUTTER_TEXT (text_editable_actor), TRUE); |
| 187 |
clutter_text_set_selectable (CLUTTER_TEXT (text_editable_actor), TRUE); |
| 188 |
clutter_text_set_selection_color (CLUTTER_TEXT (text_editable_actor), |
| 189 |
CLUTTER_COLOR_Green); |
| 190 |
clutter_text_set_activatable (CLUTTER_TEXT (text_editable_actor), |
| 191 |
TRUE); |
| 192 |
clutter_text_set_line_wrap (CLUTTER_TEXT (text_editable_actor), TRUE); |
| 193 |
clutter_actor_grab_key_focus (text_editable_actor); |
| 194 |
clutter_actor_set_reactive (text_editable_actor, TRUE); |
| 195 |
|
| 196 |
clutter_container_add_actor (CLUTTER_CONTAINER (stage), text_editable_actor); |
| 197 |
g_signal_connect (text_editable_actor, "activate", |
| 198 |
G_CALLBACK (activate_cb), NULL); |
| 199 |
|
| 200 |
/* test buttons */ |
| 201 |
button = _create_button ("Set"); |
| 202 |
clutter_actor_set_position (button, 100, 200); |
| 203 |
|
| 204 |
g_signal_connect_after (button, "button-press-event", |
| 205 |
G_CALLBACK (set_text_press_cb), NULL); |
| 206 |
|
| 207 |
clutter_container_add_actor (CLUTTER_CONTAINER (stage), button); |
| 208 |
|
| 209 |
button = _create_button ("Delete"); |
| 210 |
clutter_actor_set_position (button, 100, 250); |
| 211 |
|
| 212 |
g_signal_connect_after (button, "button-press-event", |
| 213 |
G_CALLBACK (delete_text_press_cb), NULL); |
| 214 |
|
| 215 |
clutter_container_add_actor (CLUTTER_CONTAINER (stage), button); |
| 216 |
|
| 217 |
button = _create_button ("Insert"); |
| 218 |
clutter_actor_set_position (button, 100, 300); |
| 219 |
|
| 220 |
g_signal_connect_after (button, "button-press-event", |
| 221 |
G_CALLBACK (insert_text_press_cb), NULL); |
| 222 |
|
| 223 |
clutter_container_add_actor (CLUTTER_CONTAINER (stage), button); |
| 224 |
|
| 225 |
button = _create_button ("Activate/Deactivate"); |
| 226 |
clutter_actor_set_position (button, 100, 350); |
| 227 |
|
| 228 |
g_signal_connect_after (button, "button-press-event", |
| 229 |
G_CALLBACK (activate_deactivate_press_cb), NULL); |
| 230 |
|
| 231 |
clutter_container_add_actor (CLUTTER_CONTAINER (stage), button); |
| 232 |
|
| 233 |
button = _create_button ("Cursor position"); |
| 234 |
clutter_actor_set_position (button, 100, 450); |
| 235 |
|
| 236 |
g_signal_connect_after (button, "button-press-event", |
| 237 |
G_CALLBACK (print_cursor_position_press_cb), NULL); |
| 238 |
|
| 239 |
clutter_container_add_actor (CLUTTER_CONTAINER (stage), button); |
| 240 |
|
| 241 |
} |
| 242 |
|
| 243 |
int |
| 244 |
main (int argc, char *argv[]) |
| 245 |
{ |
| 246 |
ClutterActor *stage = NULL; |
| 247 |
|
| 248 |
g_set_application_name ("AtkEditableText"); |
| 249 |
|
| 250 |
if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) |
| 251 |
return 1; |
| 252 |
|
| 253 |
cally_util_a11y_init (&argc, &argv); |
| 254 |
|
| 255 |
stage = clutter_stage_new (); |
| 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 |
} |