2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; https://wiki.gnome.org/Accessibility)
5 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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.1 of the License, or (at your option) any later version.
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.
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., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
27 #include "my-atk-object.h"
28 #include "my-atk-action.h"
30 typedef struct _MyAtkActionInfo MyAtkActionInfo;
32 struct _MyAtkActionInfo {
37 MyAtkActionFunc do_action_func;
40 static void atk_action_interface_init (AtkActionIface *iface);
42 G_DEFINE_TYPE_WITH_CODE (MyAtkAction,
45 G_IMPLEMENT_INTERFACE(ATK_TYPE_ACTION,
46 atk_action_interface_init));
48 #define MY_ATK_ACTION_GET_PRIVATE(obj) \
49 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), MY_TYPE_ATK_ACTION, MyAtkActionPrivate))
51 struct _MyAtkActionPrivate {
53 guint action_idle_handler;
59 my_atk_action_initialize (AtkObject *obj, gpointer data)
64 my_atk_action_init (MyAtkAction *action_obj)
66 MyAtkActionPrivate *priv = MY_ATK_ACTION_GET_PRIVATE (action_obj);
67 action_obj->priv = priv;
68 priv->action_queue = NULL;
69 priv->action_idle_handler = 0;
70 priv->action_list = NULL;
71 priv->children = NULL;
75 my_atk_action_finalize (GObject *object)
80 my_atk_action_class_init (MyAtkActionClass *my_class)
82 AtkObjectClass *atk_class = ATK_OBJECT_CLASS (my_class);
83 GObjectClass *gobject_class = G_OBJECT_CLASS (my_class);
85 gobject_class->finalize = my_atk_action_finalize;
87 atk_class->initialize = my_atk_action_initialize;
89 g_type_class_add_private (gobject_class, sizeof (MyAtkActionPrivate));
92 static MyAtkActionInfo *
93 _my_atk_action_get_action_info (MyAtkAction *action, gint i)
95 MyAtkActionPrivate *priv = NULL;
96 MyAtkActionInfo *node_data = NULL;
98 g_return_val_if_fail (MY_IS_ATK_ACTION (action), NULL);
102 if (priv->action_list == NULL)
105 node_data = g_list_nth_data (priv->action_list, i);
107 g_return_val_if_fail (node_data, NULL);
113 my_atk_action_description_get (AtkAction *action, gint i)
115 MyAtkAction *my_action = NULL;
116 MyAtkActionInfo *info = NULL;
118 g_return_val_if_fail (MY_IS_ATK_ACTION (action), NULL);
119 my_action = MY_ATK_ACTION (action);
121 info = _my_atk_action_get_action_info (my_action, i);
126 return strdup (info->description);
130 my_atk_action_description_set (AtkAction *action, gint i, const char *des)
132 MyAtkAction *my_action = NULL;
133 MyAtkActionInfo *info = NULL;
135 g_return_val_if_fail (MY_IS_ATK_ACTION (action), FALSE);
136 my_action = MY_ATK_ACTION (action);
138 info = _my_atk_action_get_action_info (my_action, i);
143 g_free (info->description);
144 info->description = g_strdup (des);
150 my_atk_action_name_get (AtkAction *action, gint i)
152 MyAtkAction *my_action = NULL;
153 MyAtkActionInfo *info = NULL;
155 g_return_val_if_fail (MY_IS_ATK_ACTION (action), NULL);
156 my_action = MY_ATK_ACTION (action);
158 info = _my_atk_action_get_action_info (my_action, i);
163 return strdup (info->name);
167 my_atk_action_localized_name_get (AtkAction *action, gint i)
169 MyAtkAction *my_action = NULL;
170 MyAtkActionInfo *info = NULL;
172 g_return_val_if_fail (MY_IS_ATK_ACTION (action), NULL);
173 my_action = MY_ATK_ACTION (action);
175 info = _my_atk_action_get_action_info (my_action, i);
180 return strdup (info->name);
184 my_atk_action_get_n_actions (AtkAction *action)
186 MyAtkAction *action_obj = NULL;
187 MyAtkActionPrivate *priv = NULL;
189 action_obj = MY_ATK_ACTION (action);
190 priv = action_obj->priv;
192 return g_list_length (priv->action_list);
196 my_atk_action_get_keybinding (AtkAction *action, gint i)
198 MyAtkAction *my_action = NULL;
199 MyAtkActionInfo *info = NULL;
201 g_return_val_if_fail (MY_IS_ATK_ACTION (action), NULL);
202 my_action = MY_ATK_ACTION (action);
204 info = _my_atk_action_get_action_info (my_action, i);
209 return strdup (info->keybinding);
212 void perform_action (AtkObject *obj)
214 AtkStateSet *state_set1 = atk_object_ref_state_set (obj);
215 atk_state_set_add_state (state_set1, ATK_STATE_ACTIVE);
219 my_atk_action_do_action (AtkAction *action, gint i)
221 g_return_val_if_fail (MY_IS_ATK_ACTION (action), FALSE);
223 perform_action (ATK_OBJECT (action));
228 guint my_atk_action_add_action (MyAtkAction *action,
229 const gchar *action_name,
230 const gchar *action_description,
231 const gchar *action_keybinding)
233 MyAtkActionInfo *info = NULL;
234 MyAtkActionPrivate *priv = NULL;
236 g_return_val_if_fail (MY_IS_ATK_ACTION (action), -1);
240 info = g_slice_new (MyAtkActionInfo);
241 info->name = g_strdup (action_name);
242 info->description = g_strdup (action_description);
243 info->keybinding = g_strdup (action_keybinding);
245 priv->action_list = g_list_append (priv->action_list, info);
247 return g_list_length (priv->action_list);
251 atk_action_interface_init (AtkActionIface *iface)
253 g_return_if_fail (iface);
255 iface->do_action = my_atk_action_do_action;
257 iface->get_n_actions = my_atk_action_get_n_actions;
258 iface->get_description = my_atk_action_description_get;
259 iface->get_keybinding = my_atk_action_get_keybinding;
260 iface->get_name = my_atk_action_name_get;
261 iface->set_description = my_atk_action_description_set;
262 iface->get_localized_name = my_atk_action_localized_name_get;