2 * Copyright (c) 2013 Samsung Electronics Co., Ltd.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
21 * @file eail_ctxpopup.c
22 * @brief EailCtxpopup implementation
25 #include <Elementary.h>
27 #include "eail_ctxpopup.h"
28 #include "eail_factory.h"
29 #include "eail_priv.h"
31 static void atk_action_interface_init(AtkActionIface *iface);
34 * @brief Define EailCtxpopup GObject type
36 G_DEFINE_TYPE_WITH_CODE(EailCtxpopup,
39 G_IMPLEMENT_INTERFACE(ATK_TYPE_ACTION,
40 atk_action_interface_init));
43 * @brief Initializer for AtkObject
45 * @param obj AtkObject instance
46 * @param data initialization data
49 eail_ctxpopup_initialize(AtkObject *obj, gpointer data)
51 ATK_OBJECT_CLASS(eail_ctxpopup_parent_class)->initialize(obj, data);
53 obj->role = ATK_ROLE_POPUP_MENU;
57 * @brief Destructor for EailCtxpopup class
59 * @param object GObject instance to be finalized
62 eail_ctxpopup_finalize(GObject *object)
64 EailCtxpopup *ctxpopup = EAIL_CTXPOPUP(object);
66 if (ctxpopup->dismiss_description) free(ctxpopup->dismiss_description);
68 G_OBJECT_CLASS(eail_ctxpopup_parent_class)->finalize(object);
72 * @brief EailCtxpopup GObject instance initializer
74 * @param ctxpopup EailCtxpopup instance
77 eail_ctxpopup_init(EailCtxpopup *ctxpopup)
79 ctxpopup->dismiss_description = NULL;
83 * @brief Helper function for getting nested content of elm_popup widget
85 * @param obj AtkObject instance
87 * @returns Evas_Object representing the nested widget content
88 * from elm_popup widget
91 _eail_get_nested_widget(AtkObject *obj)
93 Evas_Object *ctxpopup_widget = NULL, *nested_widget = NULL;
94 /* getting widget of ctxpopup class */
95 ctxpopup_widget = eail_widget_get_widget(EAIL_WIDGET(obj));
98 ERR("No widget found for EailCtxpopup object!");
101 nested_widget = elm_object_part_content_get(ctxpopup_widget, "default");
103 return nested_widget;
107 * @brief Gets the number of accessible children of the accessible
109 * Implementation AtkObject->get_n_children callback.
111 * @param obj AtkObject instance
113 * @returns integer representing the number of accessible children of
117 eail_ctxpopup_get_n_children(AtkObject *obj)
119 Evas_Object *nested_widget = NULL;
121 nested_widget = _eail_get_nested_widget(obj);
129 * @brief Gets a reference to the specified accessible child of the object
131 * The accessible children are 0-based so the first accessible child
132 * is at index 0, the second at index 1 and so on.
134 * Implementation of AtkObject->ref_child callback.
136 * @param obj AtkObject instance
137 * @param i index of the child
139 * @returns AtkObject representing the specified accessible child of the
143 eail_ctxpopup_ref_child(AtkObject *obj, gint i)
145 Evas_Object *nested_widget = NULL;
148 nested_widget = _eail_get_nested_widget(obj);
149 atk_obj = eail_factory_get_accessible(nested_widget);
152 g_object_ref(atk_obj);
158 * @brief Initializer for EailPopup GObject class
160 * Defines callbacks for base AtkObject.
162 * @param klass EailCtxpopupClass instance
165 eail_ctxpopup_class_init(EailCtxpopupClass *klass)
167 AtkObjectClass *atk_class = ATK_OBJECT_CLASS(klass);
168 GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
170 atk_class->initialize = eail_ctxpopup_initialize;
171 atk_class->get_n_children = eail_ctxpopup_get_n_children;
172 atk_class->ref_child = eail_ctxpopup_ref_child;
173 gobject_class->finalize = eail_ctxpopup_finalize;
177 * Implementation of the *AtkAction* interface
181 * @brief Gets the number of accessible actions available on the object
183 * If there are more than one, the first one is considered
184 * the "default" action of the object.
186 * Implementation of get_n_actions from AtkAction interface.
188 * @param action AtkAction instance
190 * @return integer representing the number of available actions
193 eail_ctxpopup_n_actions_get(AtkAction *action)
199 * @brief Gets the description string of the specified action of the object
201 * Implementation of get_description from AtkAction interface.
203 * @param action AtkAction instance
204 * @param i action index
206 * @return string representing the specified action's description
209 eail_ctxpopup_description_get(AtkAction *action,
212 EailCtxpopup *ctxpopup;
213 const char *action_description;
215 ctxpopup = EAIL_CTXPOPUP(action);
216 if (!ctxpopup) return NULL;
221 action_description = ctxpopup->dismiss_description;
224 action_description = NULL;
228 return action_description;
232 * @brief Sets a description of the specified action of the object
234 * Implementation of set_description from AtkAction interface.
236 * @param action AtkAction instance
237 * @param i action index
238 * @param description action description
240 * @return TRUE on success, FALSE otherwise
243 eail_ctxpopup_description_set(AtkAction *action,
245 const char *description)
247 EailCtxpopup *ctxpopup;
250 ctxpopup = EAIL_CTXPOPUP(action);
251 if (!ctxpopup) return FALSE;
256 value = &ctxpopup->dismiss_description;
266 *value = g_strdup(description);
274 * @brief Gets the name string of the specified action of the object
276 * Implementation of get_name from AtkAction interface.
278 * @param action AtkAction instance
279 * @param i action index
281 * @return string representing the specified action's name
284 eail_ctxpopup_action_name_get(AtkAction *action,
287 const char* action_name;
292 action_name = "dismiss";
303 * @brief Performs the specified action on the object
305 * Implementation of do_action from AtkAction interface.
307 * @param action AtkAction instance
308 * @param i action index
310 * @return TRUE on success, FALSE otherwise
313 eail_ctxpopup_do_action(AtkAction *action,
318 widget = eail_widget_get_widget(EAIL_WIDGET(action));
319 if (!widget) return FALSE;
321 if ((elm_object_disabled_get(widget)) || (!evas_object_visible_get(widget)))
324 const char *action_name = atk_action_get_name(action, i);
325 if (!action_name) return FALSE;
327 if (!g_strcmp0(action_name, "dismiss"))
328 elm_ctxpopup_dismiss(widget);
336 * @brief AtkAction interface initializer
338 * Function called upon instance creation. It initializes AtkAction interface
339 * implementation i.e hooks method pointers in the interface structure
340 * to the implementing class's implementation.
342 * @param iface AtkActionIface instance
345 atk_action_interface_init(AtkActionIface *iface)
347 g_return_if_fail(iface != NULL);
349 iface->get_n_actions = eail_ctxpopup_n_actions_get;
350 iface->get_description = eail_ctxpopup_description_get;
351 iface->set_description = eail_ctxpopup_description_set;
352 iface->get_name = eail_ctxpopup_action_name_get;
353 iface->do_action = eail_ctxpopup_do_action;