Debian Codegraph @

clutter/cally/cally-stage.c

raw
1 /* CALLY - The Clutter Accessibility Implementation Library
2 *
3 * Copyright (C) 2008 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 * SECTION:cally-stage
25 * @Title: CallyStage
26 * @short_description: Implementation of the ATK interfaces for a #ClutterStage
27 * @see_also: #ClutterStage
28 *
29 * #CallyStage implements the required ATK interfaces for #ClutterStage
30 *
31 * Some implementation details: at this moment #CallyStage is used as
32 * the most similar Window object in this toolkit (ie: emitting window
33 * related signals), although the real purpose of #ClutterStage is
34 * being a canvas. Anyway, this is required for applications using
35 * just clutter, or directly #ClutterStage
36 */
37 #include "config.h"
38
39 #include "cally-stage.h"
40 #include "cally-actor-private.h"
41
42 /* AtkObject.h */
43 static void cally_stage_real_initialize (AtkObject *obj,
44 gpointer data);
45 static AtkStateSet* cally_stage_ref_state_set (AtkObject *obj);
46
47 /* AtkWindow */
48 static void cally_stage_window_interface_init (AtkWindowIface *iface);
49
50 /* Auxiliar */
51 static void cally_stage_activate_cb (ClutterStage *stage,
52 gpointer data);
53 static void cally_stage_deactivate_cb (ClutterStage *stage,
54 gpointer data);
55
56 struct _CallyStagePrivate
57 {
58 /* NULL means that the stage will receive the focus */
59 ClutterActor *key_focus;
60
61 gboolean active;
62 };
63
64 G_DEFINE_TYPE_WITH_CODE (CallyStage,
65 cally_stage,
66 CALLY_TYPE_GROUP,
67 G_ADD_PRIVATE (CallyStage)
68 G_IMPLEMENT_INTERFACE (ATK_TYPE_WINDOW,
69 cally_stage_window_interface_init));
70
71 static void
72 cally_stage_class_init (CallyStageClass *klass)
73 {
74 AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
75
76 /* AtkObject */
77 class->initialize = cally_stage_real_initialize;
78 class->ref_state_set = cally_stage_ref_state_set;
79 }
80
81 static void
82 cally_stage_init (CallyStage *cally_stage)
83 {
84 CallyStagePrivate *priv = cally_stage_get_instance_private (cally_stage);
85
86 cally_stage->priv = priv;
87
88 priv->active = FALSE;
89 }
90
91 /**
92 * cally_stage_new:
93 * @actor: a #ClutterActor
94 *
95 * Creates a new #CallyStage for the given @actor. @actor should be a
96 * #ClutterStage.
97 *
98 * Return value: the newly created #AtkObject
99 *
100 * Since: 1.4
101 */
102 AtkObject*
103 cally_stage_new (ClutterActor *actor)
104 {
105 GObject *object = NULL;
106 AtkObject *accessible = NULL;
107
108 g_return_val_if_fail (CLUTTER_IS_STAGE (actor), NULL);
109
110 object = g_object_new (CALLY_TYPE_STAGE, NULL);
111
112 accessible = ATK_OBJECT (object);
113 atk_object_initialize (accessible, actor);
114
115 return accessible;
116 }
117
118 static void
119 cally_stage_notify_key_focus_cb (ClutterStage *stage,
120 GParamSpec *pspec,
121 CallyStage *self)
122 {
123 ClutterActor *key_focus = NULL;
124 AtkObject *new = NULL;
125
126 if (self->priv->active == FALSE)
127 return;
128
129 key_focus = clutter_stage_get_key_focus (stage);
130
131 if (key_focus != self->priv->key_focus)
132 {
133 AtkObject *old = NULL;
134
135 if (self->priv->key_focus != NULL)
136 {
137 g_object_remove_weak_pointer (G_OBJECT (self->priv->key_focus),
138 (gpointer *) &self->priv->key_focus);
139 old = clutter_actor_get_accessible (self->priv->key_focus);
140 }
141 else
142 old = clutter_actor_get_accessible (CLUTTER_ACTOR (stage));
143
144 atk_object_notify_state_change (old,
145 ATK_STATE_FOCUSED,
146 FALSE);
147 }
148
149 /* we keep notifying the focus gain without checking previous
150 * key-focus to avoid some missing events due timing
151 */
152 self->priv->key_focus = key_focus;
153
154 if (key_focus != NULL)
155 {
156 /* ensure that if the key focus goes away, the field inside
157 * CallyStage is reset. see bug:
158 *
159 * https://bugzilla.gnome.org/show_bug.cgi?id=692706
160 *
161 * we remove the weak pointer above.
162 */
163 g_object_add_weak_pointer (G_OBJECT (self->priv->key_focus),
164 (gpointer *) &self->priv->key_focus);
165
166 new = clutter_actor_get_accessible (key_focus);
167 }
168 else
169 new = clutter_actor_get_accessible (CLUTTER_ACTOR (stage));
170
171 atk_object_notify_state_change (new,
172 ATK_STATE_FOCUSED,
173 TRUE);
174 }
175
176 static void
177 cally_stage_real_initialize (AtkObject *obj,
178 gpointer data)
179 {
180 ClutterStage *stage = NULL;
181
182 g_return_if_fail (CALLY_IS_STAGE (obj));
183
184 ATK_OBJECT_CLASS (cally_stage_parent_class)->initialize (obj, data);
185
186 stage = CLUTTER_STAGE (CALLY_GET_CLUTTER_ACTOR (obj));
187
188 g_signal_connect (stage, "activate", G_CALLBACK (cally_stage_activate_cb), obj);
189 g_signal_connect (stage, "deactivate", G_CALLBACK (cally_stage_deactivate_cb), obj);
190 g_signal_connect (stage, "notify::key-focus",
191 G_CALLBACK (cally_stage_notify_key_focus_cb), obj);
192
193 atk_object_set_role (obj, ATK_ROLE_WINDOW);
194 }
195
196 static AtkStateSet*
197 cally_stage_ref_state_set (AtkObject *obj)
198 {
199 CallyStage *cally_stage = NULL;
200 AtkStateSet *state_set = NULL;
201 ClutterStage *stage = NULL;
202
203 g_return_val_if_fail (CALLY_IS_STAGE (obj), NULL);
204 cally_stage = CALLY_STAGE (obj);
205
206 state_set = ATK_OBJECT_CLASS (cally_stage_parent_class)->ref_state_set (obj);
207 stage = CLUTTER_STAGE (CALLY_GET_CLUTTER_ACTOR (cally_stage));
208
209 if (stage == NULL)
210 return state_set;
211
212 if (cally_stage->priv->active)
213 atk_state_set_add_state (state_set, ATK_STATE_ACTIVE);
214
215 return state_set;
216 }
217
218 /* AtkWindow */
219 static void
220 cally_stage_window_interface_init (AtkWindowIface *iface)
221 {
222 /* At this moment AtkWindow is just about signals */
223 }
224
225 /* Auxiliar */
226 static void
227 cally_stage_activate_cb (ClutterStage *stage,
228 gpointer data)
229 {
230 CallyStage *cally_stage = NULL;
231
232 g_return_if_fail (CALLY_IS_STAGE (data));
233
234 cally_stage = CALLY_STAGE (data);
235
236 cally_stage->priv->active = TRUE;
237
238 atk_object_notify_state_change (ATK_OBJECT (cally_stage),
239 ATK_STATE_ACTIVE, TRUE);
240
241 g_signal_emit_by_name (cally_stage, "activate", 0);
242 }
243
244 static void
245 cally_stage_deactivate_cb (ClutterStage *stage,
246 gpointer data)
247 {
248 CallyStage *cally_stage = NULL;
249
250 g_return_if_fail (CALLY_IS_STAGE (data));
251
252 cally_stage = CALLY_STAGE (data);
253
254 cally_stage->priv->active = FALSE;
255
256 atk_object_notify_state_change (ATK_OBJECT (cally_stage),
257 ATK_STATE_ACTIVE, FALSE);
258
259 g_signal_emit_by_name (cally_stage, "deactivate", 0);
260 }