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_hoversel.c
22 * @brief EailHoversel implementation.
25 #include <Elementary.h>
27 #include "eail_hoversel.h"
28 #include "eail_factory.h"
29 #include "eail_item_parent.h"
30 #include "eail_priv.h"
32 static void atk_action_interface_init(AtkActionIface *iface);
33 static void eail_item_parent_interface_init(EailItemParentIface *iface);
36 * @brief EailHoversel type definition
38 G_DEFINE_TYPE_WITH_CODE(EailHoversel,
41 G_IMPLEMENT_INTERFACE(EAIL_TYPE_ITEM_PARENT,
42 eail_item_parent_interface_init)
43 G_IMPLEMENT_INTERFACE(ATK_TYPE_ACTION,
44 atk_action_interface_init));
47 static AtkStateSet *eail_hoversel_ref_state_set(AtkObject *obj);
48 static gint eail_hoversel_get_n_children(AtkObject *obj);
49 static AtkObject *eail_hoversel_ref_child(AtkObject *obj,
51 static void eail_hoversel_initialize(AtkObject *obj,
53 static void eail_hoversel_finalize(GObject *obj);
56 static const char *eail_hoversel_description_get(AtkAction *action,
58 static gboolean eail_hoversel_description_set(AtkAction *action,
60 const char *description);
61 static const char *eail_hoversel_action_name_get(AtkAction *action,
63 static int eail_hoversel_n_actions_get(AtkAction *action);
64 static gboolean eail_hoversel_do_action(AtkAction *action,
69 /* Helper functions */
70 static const Eina_List *eail_hoversel_items_get(EailHoversel *obj);
73 * Implementation of the *AtkObject* interface
77 * @brief EailHoverser initializer
79 * @param obj AtkObject instance
80 * @param data initialization data
83 eail_hoversel_initialize(AtkObject *obj, gpointer data)
85 ATK_OBJECT_CLASS(eail_hoversel_parent_class)->initialize(obj, data);
86 obj->role = ATK_ROLE_GLASS_PANE;
90 * @brief EailHoversel finalizer.
92 * Destroys object and allocated resources.
94 * @param obj object that needs to be finalized
97 eail_hoversel_finalize(GObject *obj)
99 EailHoversel *hoversel = EAIL_HOVERSEL(obj);
101 if (hoversel->shrink_description) free(hoversel->shrink_description);
102 if (hoversel->expand_description) free(hoversel->expand_description);
104 G_OBJECT_CLASS(eail_hoversel_parent_class)->finalize(obj);
108 * @brief EailHoversel instance initializer.
110 * @param hoversel EailHoversel instance
113 eail_hoversel_init(EailHoversel *hoversel)
115 hoversel->shrink_description = NULL;
116 hoversel->expand_description = NULL;
120 * @brief Gets the state set of the accessible.
122 * The caller must unreference it when it is no longer needed.
124 * @param accessible EailHoversel instance
125 * @return AtkStateSet containing the state set of the accessible
128 eail_hoversel_ref_state_set(AtkObject *accessible)
130 AtkStateSet *state_set = NULL;
131 Evas_Object *widget = NULL;
134 ATK_OBJECT_CLASS(eail_hoversel_parent_class)->ref_state_set(accessible);
137 printf("NULL STATE SET");
140 widget = eail_widget_get_widget(EAIL_WIDGET(accessible));
143 atk_state_set_add_state(state_set, ATK_STATE_DEFUNCT);
147 if (elm_hoversel_expanded_get(widget))
149 atk_state_set_add_state(state_set, ATK_STATE_EXPANDED);
151 if (elm_hoversel_horizontal_get(widget))
152 atk_state_set_add_state(state_set, ATK_STATE_HORIZONTAL);
154 atk_state_set_add_state(state_set, ATK_STATE_VERTICAL);
158 atk_state_set_add_state(state_set, ATK_STATE_DEFAULT);
165 * @brief Gets the number of accessible children of obj
167 * @param obj AtkObject instance
168 * @return integer containing the number of obj's children
171 eail_hoversel_get_n_children(AtkObject *obj)
173 const Eina_List *list;
175 g_return_val_if_fail(EAIL_IS_HOVERSEL(obj), 0);
177 list = eail_hoversel_items_get(EAIL_HOVERSEL(obj));
179 return eina_list_count(list);
183 * @brief Gets a reference to the specified accessible child of the object.
185 * The accessible children are 0-based so the first accessible child is at index 0, the second at index 1 and so on.
187 * Implementation of ref_child from AtkObject interface.
189 * The caller must unreference it when it is no longer needed.
191 * @param obj AtkObject instance
192 * @param i child index
193 * @return AtkObject containing the reference to the specified accessible child
196 eail_hoversel_ref_child(AtkObject *obj,
199 const Eina_List *items;
200 AtkObject *child = NULL;
202 g_return_val_if_fail(EAIL_IS_HOVERSEL(obj), NULL);
204 items = eail_hoversel_items_get(EAIL_HOVERSEL(obj));
205 if (eina_list_count(items) > i)
207 child = eail_factory_get_item_atk_obj
208 (eina_list_nth(items, i), ATK_ROLE_LABEL, obj);
213 ERR("Tried to ref child with index %d out of bounds!", i);
219 * @brief EailHoversel class initializer.
221 * @param klass EailHoverselClass instance
224 eail_hoversel_class_init(EailHoverselClass *klass)
226 AtkObjectClass *atk_class = ATK_OBJECT_CLASS(klass);
227 GObjectClass *object_class = G_OBJECT_CLASS(klass);
229 atk_class->initialize = eail_hoversel_initialize;
230 atk_class->ref_state_set = eail_hoversel_ref_state_set;
231 atk_class->get_n_children = eail_hoversel_get_n_children;
232 atk_class->ref_child = eail_hoversel_ref_child;
234 object_class->finalize = eail_hoversel_finalize;
238 * Implementation of the *AtkAction* interface
242 * @brief AtkAction interface initializer.
244 * @param iface EailHoversel instance
247 atk_action_interface_init(AtkActionIface *iface)
249 g_return_if_fail(iface != NULL);
251 iface->do_action = eail_hoversel_do_action;
252 iface->get_n_actions = eail_hoversel_n_actions_get;
253 iface->get_description = eail_hoversel_description_get;
254 iface->get_name = eail_hoversel_action_name_get;
255 iface->set_description = eail_hoversel_description_set;
259 * @brief Gets the description of the specified action of the object.
261 * Implementation of get_description from AtkAction interface.
263 * @param action EailHoversel instance
264 * @param i action index
265 * @return string representing the description of the specified action
268 eail_hoversel_description_get(AtkAction *action,
271 EailHoversel *hoversel;
272 const char *action_description;
274 hoversel = EAIL_HOVERSEL(action);
275 if (!hoversel) return NULL;
280 action_description = hoversel->shrink_description;
283 action_description = hoversel->expand_description;
286 action_description = NULL;
290 return action_description;
294 * @brief Sets a description of the specified action of the object.
296 * Implementation of set_description from AtkAction interface.
298 * @param action AtkAction instance
299 * @param i index of the action to be performed
300 * @param description action desciption
301 * @return TRUE if description was set successfully, FALSE otherwise
304 eail_hoversel_description_set(AtkAction *action,
306 const char *description)
308 EailHoversel *hoversel;
311 hoversel = EAIL_HOVERSEL(action);
312 if (!hoversel) return FALSE;
317 value = &hoversel->shrink_description;
320 value = &hoversel->expand_description;
330 *value = g_strdup(description);
338 * @brief Gets the name of the specified action of the object.
340 * Implementation of get_name from AtkAction interface.
342 * @param action AtkAction instance
343 * @param i index of the action to be performed
344 * @return string representing the name of the specified action
347 eail_hoversel_action_name_get(AtkAction *action,
350 const char* action_name;
355 action_name = "shrink";
358 action_name = "expand";
369 * @brief Gets the number of accessible actions available on the object.
371 * If there are more than one, the first one is considered the "default" action of the object.
373 * Implementation of get_n_actions from AtkAction interface.
375 * @param action AtkAction instance
376 * @return integer containing the number of implemented actions
379 eail_hoversel_n_actions_get(AtkAction *action)
385 * @brief Performs the specified action on the object.
387 * Implementation of do_action from AtkAction interface.
389 * @param action AtkAction instance
390 * @param i action index
391 * @return TRUE on success, FALSE otherwise
394 eail_hoversel_do_action(AtkAction *action,
399 widget = eail_widget_get_widget(EAIL_WIDGET(action));
400 if (!widget) return FALSE;
402 if ((elm_object_disabled_get(widget)) || (!evas_object_visible_get(widget)))
405 const char *action_name = atk_action_get_name(action, i);
406 if (!action_name) return FALSE;
408 if (!g_strcmp0(action_name, "expand"))
410 if (elm_hoversel_expanded_get(widget))
413 elm_hoversel_hover_begin(widget);
414 atk_object_notify_state_change(ATK_OBJECT(action), ATK_STATE_EXPANDED, TRUE);
416 else if (!g_strcmp0(action_name, "shrink"))
418 if (!elm_hoversel_expanded_get(widget))
421 elm_hoversel_hover_end(widget);
422 atk_object_notify_state_change(ATK_OBJECT(action), ATK_STATE_EXPANDED, FALSE);
429 * Implementation of the *EailItemParent* interface
433 * @brief Gets the name of hoversel's child
435 * @param parent parent instance
436 * @param item child instance
438 * @returns string representing the name of the child
441 eail_hoversel_item_name_get(EailItemParent *parent, EailItem *item)
443 Elm_Object_Item *it = eail_item_get_item(item);
444 if (!it) return NULL;
446 return elm_object_item_part_text_get(it, NULL);
450 * @brief Checks if content get is supported
452 * Implementation of EailItemParent->is_content_get_supported callback.
454 * @param parent EailItemParent instance
455 * @param item EailItem instance
456 * @returns FALSE as there is no content support
459 eail_hoversel_content_get_support(EailItemParent *parent,
466 * @brief EailItemParent interface initializer
468 * @param iface EailItemParentIface instance
471 eail_item_parent_interface_init(EailItemParentIface *iface)
473 iface->get_item_name = eail_hoversel_item_name_get;
474 iface->is_content_get_supported = eail_hoversel_content_get_support;
482 * @brief Gets obj's items list.
484 * @param obj EailHoversel instance
485 * @return Eina_List containing obj's items
487 static const Eina_List *
488 eail_hoversel_items_get(EailHoversel *obj)
491 const Eina_List *items = NULL;
493 g_return_val_if_fail(EAIL_HOVERSEL(obj), NULL);
495 widget = eail_widget_get_widget(EAIL_WIDGET(obj));
496 if (!widget) return NULL;
498 items = elm_hoversel_items_get(widget);
499 if (!items) return NULL;