Debian Codegraph @

tests/accessibility/cally-atkevents-example.c

raw
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 /*
24 * The purpose of this example is test key event and global event
25 * implementation, specifically:
26 *
27 * atk_add_global_event_listener
28 * atk_remove_global_event_listener
29 * atk_add_key_event_listener
30 * atk_remove_key_event_listener
31 */
32 #include <atk/atk.h>
33 #include <clutter/clutter.h>
34 #include <cally/cally.h>
35
36 #include "cally-examples-util.h"
37
38 #define WIDTH 800
39 #define HEIGHT 600
40 #define HEIGHT_STEP 100
41 #define NUM_ENTRIES 3
42
43 struct _Data{
44 gint value;
45 };
46 typedef struct _Data Data;
47
48 static gboolean
49 atk_key_listener (AtkKeyEventStruct *event, gpointer data)
50 {
51 Data *my_data = (Data*) data;
52
53 g_print ("atk_listener: 0x%x ", event->keyval);
54
55 if (my_data != NULL) {
56 g_print ("\t Data value: %i\n", my_data->value);
57 } else {
58 g_print ("\tNo data!!\n");
59 }
60
61 return FALSE;
62 }
63
64 static gboolean
65 window_event_listener (GSignalInvocationHint * signal_hint,
66 guint n_param_values,
67 const GValue * param_values, gpointer data)
68 {
69 AtkObject *accessible;
70 GSignalQuery signal_query;
71 const gchar *name, *s;
72
73 g_signal_query (signal_hint->signal_id, &signal_query);
74 name = signal_query.signal_name;
75
76 accessible = ATK_OBJECT (g_value_get_object (&param_values[0]));
77 s = atk_object_get_name (accessible);
78
79 g_print ("Detected window event \"%s\" from object \"%p\" named \"%s\"\n",
80 name, accessible, s);
81
82 return TRUE;
83 }
84 static void
85 make_ui (ClutterActor *stage)
86 {
87 gint i = 0;
88 ClutterActor *editable = NULL;
89 ClutterActor *rectangle = NULL;
90 ClutterActor *label = NULL;
91 ClutterColor color_sel = { 0x00, 0xff, 0x00, 0x55 };
92 ClutterColor color_label = { 0x00, 0xff, 0x55, 0xff };
93 ClutterColor color_rect = { 0x00, 0xff, 0xff, 0x55 };
94 float label_geom_y, editable_geom_y;
95
96 clutter_stage_set_color (CLUTTER_STAGE (stage), CLUTTER_COLOR_White);
97 clutter_actor_set_size (stage, WIDTH, HEIGHT);
98
99 label_geom_y = 50;
100 editable_geom_y = 50;
101
102 for (i = 0; i < NUM_ENTRIES; i++)
103 {
104 /* label */
105 label = clutter_text_new_full ("Sans Bold 32px",
106 "Entry",
107 &color_label);
108 clutter_actor_set_position (label, 0, label_geom_y);
109
110 /* editable */
111 editable = clutter_text_new_full ("Sans Bold 32px",
112 "ddd",
113 CLUTTER_COLOR_Red);
114 clutter_actor_set_position (editable, 150, editable_geom_y);
115 clutter_actor_set_size (editable, 500, 75);
116 clutter_text_set_editable (CLUTTER_TEXT (editable), TRUE);
117 clutter_text_set_selectable (CLUTTER_TEXT (editable), TRUE);
118 clutter_text_set_selection_color (CLUTTER_TEXT (editable),
119 &color_sel);
120 clutter_actor_grab_key_focus (editable);
121 clutter_actor_set_reactive (editable, TRUE);
122
123 /* rectangle: to create a entry "feeling" */
124 rectangle = clutter_rectangle_new_with_color (&color_rect);
125 clutter_actor_set_position (rectangle, 150, editable_geom_y);
126 clutter_actor_set_size (rectangle, 500, 75);
127
128 clutter_container_add_actor (CLUTTER_CONTAINER (stage), label);
129 clutter_container_add_actor (CLUTTER_CONTAINER (stage), editable);
130 clutter_container_add_actor (CLUTTER_CONTAINER (stage), rectangle);
131
132 label_geom_y += HEIGHT_STEP;
133 editable_geom_y += HEIGHT_STEP;
134 }
135 }
136
137 int
138 main (int argc, char *argv[])
139 {
140 ClutterActor *stage, *stage_main;
141 Data data1, data2, data3;
142 guint id_1 = 0, id_2 = 0, id_3 = 0;
143
144 g_set_application_name ("AtkText");
145
146 if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
147 return 1;
148
149 if (cally_util_a11y_init (&argc, &argv) == FALSE)
150 {
151 g_error ("This example requires the accessibility support, "
152 "especifically AtkUtil implementation loaded, "
153 "as it tries to register and remove event listeners");
154 }
155
156 data1.value = 10;
157 data2.value = 20;
158 data3.value = 30;
159
160 /* key event listeners */
161 id_1 = atk_add_key_event_listener ((AtkKeySnoopFunc)atk_key_listener, &data1);
162 atk_remove_key_event_listener (id_1);
163 id_2 = atk_add_key_event_listener ((AtkKeySnoopFunc)atk_key_listener, &data2);
164 id_3 = atk_add_key_event_listener ((AtkKeySnoopFunc)atk_key_listener, &data3);
165
166 atk_remove_key_event_listener (id_2);
167
168 g_print ("key event listener ids registered: (%i, %i, %i)\n", id_1, id_2, id_3);
169
170 /* event listeners */
171 atk_add_global_event_listener (window_event_listener, "Atk:AtkWindow:create");
172 atk_add_global_event_listener (window_event_listener, "Atk:AtkWindow:destroy");
173 atk_add_global_event_listener (window_event_listener, "Atk:AtkWindow:activate");
174 atk_add_global_event_listener (window_event_listener, "Atk:AtkWindow:deactivate");
175
176 stage_main = clutter_stage_new ();
177 clutter_stage_set_title (CLUTTER_STAGE (stage_main), "Cally - AtkEvents/1");
178 g_signal_connect (stage_main, "destroy", G_CALLBACK (clutter_main_quit), NULL);
179 make_ui (stage_main);
180
181 clutter_actor_show_all (stage_main);
182
183 if (clutter_feature_available (CLUTTER_FEATURE_STAGE_MULTIPLE))
184 {
185 stage = clutter_stage_new ();
186 clutter_stage_set_title (CLUTTER_STAGE (stage), "Cally - AtkEvents/2");
187 g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
188
189 make_ui (stage);
190 clutter_actor_show_all (stage);
191 }
192
193 clutter_main ();
194
195 return 0;
196 }