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_flipselector.c
22 * @brief EailFlipselector implementation.
25 #include <Elementary.h>
27 #include "eail_flipselector.h"
28 #include "eail_factory.h"
29 #include "eail_item_parent.h"
30 #include "eail_priv.h"
33 * @brief Maximum number of selections
35 #define FLIPSELECTOR_MAX_SELECTIONS 1
37 static void atk_selection_interface_init(AtkSelectionIface *iface);
38 static void atk_action_interface_init(AtkActionIface *iface);
39 static void eail_item_parent_interface_init(EailItemParentIface *iface);
42 * @brief EailFlipselector type definition
44 G_DEFINE_TYPE_WITH_CODE(EailFlipselector,
47 G_IMPLEMENT_INTERFACE(EAIL_TYPE_ITEM_PARENT,
48 eail_item_parent_interface_init)
49 G_IMPLEMENT_INTERFACE(ATK_TYPE_SELECTION,
50 atk_selection_interface_init)
51 G_IMPLEMENT_INTERFACE(ATK_TYPE_ACTION,
52 atk_action_interface_init));
55 * @brief Function executed on selected event
57 * @param data user data passed to callback
58 * @param obj source object
59 * @param event_info event info
62 _on_selected(void *data,
66 EailFlipselector *flip = EAIL_FLIPSELECTOR(data);
67 atk_object_notify_state_change(ATK_OBJECT(flip), ATK_STATE_SELECTED, TRUE);
71 * @brief EailFlipselector initializer
73 * @param obj AtkObject instance
74 * @param data initialization data
77 eail_flipselector_initialize(AtkObject *obj, gpointer data)
81 ATK_OBJECT_CLASS(eail_flipselector_parent_class)->initialize(obj, data);
82 obj->role = ATK_ROLE_LIST;
84 widget = eail_widget_get_widget(EAIL_WIDGET(obj));
86 evas_object_smart_callback_add(widget, "selected", _on_selected, obj);
87 evas_object_smart_callback_add(widget, "selected", _on_selected, obj);
91 * @brief EailFlipselector finalizer
93 * Frees memory assigned to object.
95 * @param object GObject instance
98 eail_flipselector_finalize(GObject *object)
100 EailFlipselector *flipselector = EAIL_FLIPSELECTOR(object);
102 if (flipselector->next_description) free(flipselector->next_description);
103 if (flipselector->prev_description) free(flipselector->prev_description);
105 G_OBJECT_CLASS(eail_flipselector_parent_class)->finalize(object);
109 * @brief Gets obj's items list
111 * @param obj EailFlipselector instance
112 * @return Eina_List representing the list of obj's items
114 static const Eina_List *
115 eail_flipselector_items_get(EailFlipselector *obj)
118 const Eina_List *items = NULL;
120 g_return_val_if_fail(EAIL_FLIPSELECTOR(obj), NULL);
122 widget = eail_widget_get_widget(EAIL_WIDGET(obj));
123 if (!widget) return NULL;
125 items = elm_flipselector_items_get(widget);
126 if (!items) return NULL;
132 * @brief Gets a reference to the i-th child of the accessible
134 * The caller must unreference it when it is no longer needed.
136 * @param obj AtkObject instance
137 * @param i child index
138 * @return AtkObject representing the i-th child of the accessible
141 eail_flipselector_ref_child(AtkObject *obj,
144 const Eina_List *items;
145 AtkObject *child = NULL;
147 g_return_val_if_fail(EAIL_IS_FLIPSELECTOR(obj), NULL);
149 items = eail_flipselector_items_get(EAIL_FLIPSELECTOR(obj));
150 if (eina_list_count(items) > i)
152 child = eail_factory_get_item_atk_obj
153 (eina_list_nth(items, i), ATK_ROLE_LABEL, obj);
158 ERR("Tried to ref child with index %d out of bounds!", i);
164 * @brief Gets the number of children of the accessible
166 * @param obj AtkObject instance
167 * @return integer representing the number children of the accessible
170 eail_flipselector_get_n_children(AtkObject *obj)
172 const Eina_List *list;
174 g_return_val_if_fail(EAIL_IS_FLIPSELECTOR(obj), 0);
176 list = eail_flipselector_items_get(EAIL_FLIPSELECTOR(obj));
178 return eina_list_count(list);
182 * @brief EailFlipselector interface initializer
184 * @param flipselector EailFlipselector instance
187 eail_flipselector_init(EailFlipselector *flipselector)
189 flipselector->next_description = NULL;
190 flipselector->prev_description = NULL;
196 * @brief Gets the name of a flipselector's child
198 * @param parent EailItemParent instance
199 * @param item EailItem instance
201 * @returns string representing the name of the child
204 eail_flipselector_item_name_get(EailItemParent *parent, EailItem *item)
206 Elm_Object_Item *it = eail_item_get_item(item);
207 if (!it) return NULL;
209 return elm_object_item_part_text_get(it, NULL);
213 * @brief Checks if content get is supported
215 * Implementation of EailItemParent->is_content_get_supported callback.
217 * @param parent EailItemParent instance
218 * @param item EailItem instance
219 * @returns FALSE as there is no content support
222 eail_flipselector_content_get_support(EailItemParent *parent,
229 * @brief EailItemParent interface initializer
231 * @param iface EailItemParentIface instance
234 eail_item_parent_interface_init(EailItemParentIface *iface)
236 iface->get_item_name = eail_flipselector_item_name_get;
237 iface->is_content_get_supported = eail_flipselector_content_get_support;
241 * @brief EailFlipselector class initializer
243 * @param klass EailFlipselectorClass instance
246 eail_flipselector_class_init(EailFlipselectorClass *klass)
248 AtkObjectClass *atk_class = ATK_OBJECT_CLASS(klass);
249 GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
251 atk_class->initialize = eail_flipselector_initialize;
252 atk_class->get_n_children = eail_flipselector_get_n_children;
253 atk_class->ref_child = eail_flipselector_ref_child;
254 gobject_class->finalize = eail_flipselector_finalize;
258 * @brief Selects the i-th item of the accessible
260 * @param selection AtkSelection instance
261 * @param i item index
262 * @return TRUE if item was successfully selected, FALSE otherwise
265 eail_flipselector_add_selection(AtkSelection *selection,
269 const Eina_List *list;
271 g_return_val_if_fail(EAIL_IS_FLIPSELECTOR(selection), FALSE);
273 list = eail_flipselector_items_get(EAIL_FLIPSELECTOR(selection));
275 if (eina_list_count(list) > i)
277 it = eina_list_nth(list, i);
278 if (!it) return FALSE;
280 elm_flipselector_item_selected_set(it, EINA_TRUE);
287 * @brief Clears selections
289 * @param selection AtkSelection instance
290 * @return always FALSE
293 eail_flipselector_clear_selection(AtkSelection *selection)
299 * @brief Gets the number of currently selected children
301 * @param selection AtkSelection instance
302 * @return integer representing the number of selected children
305 eail_flipselector_get_selection_count(AtkSelection *selection)
307 return FLIPSELECTOR_MAX_SELECTIONS;
311 * @brief Determines if the i-th child of the accessible is selected
313 * @param selection AtkSelection instance
314 * @param i child index
315 * @return TRUE if the i-th child is selected, FALSE otherwise
318 eail_flipselector_is_child_selected(AtkSelection *selection,
322 Elm_Object_Item *sel_it = NULL;
323 Elm_Object_Item *it = NULL;
324 const Eina_List *list;
326 g_return_val_if_fail(EAIL_IS_FLIPSELECTOR(selection), FALSE);
328 list = eail_flipselector_items_get(EAIL_FLIPSELECTOR(selection));
330 if (eina_list_count(list) > i)
332 widget = eail_widget_get_widget(EAIL_WIDGET(selection));
333 if (!widget) return FALSE;
335 sel_it = elm_flipselector_selected_item_get(widget);
336 if (!sel_it) return FALSE;
338 it = eina_list_nth(list, i);
345 * @brief Removes the i-th selection of the accessible
347 * @param selection AtkSelection instance
348 * @param i selection index
349 * @return TRUE if selection was successfully removed, FALSE otherwise
352 eail_flipselector_remove_selection(AtkSelection *selection,
356 Elm_Object_Item *sel_it;
358 const Eina_List *list;
360 g_return_val_if_fail(EAIL_IS_FLIPSELECTOR(selection), FALSE);
362 list = eail_flipselector_items_get(EAIL_FLIPSELECTOR(selection));
364 if (eina_list_count(list) > i)
366 widget = eail_widget_get_widget(EAIL_WIDGET(selection));
367 if (!widget) return FALSE;
369 sel_it = elm_flipselector_selected_item_get(widget);
370 if (!sel_it) return FALSE;
372 it = eina_list_nth(list, i);
375 elm_flipselector_item_selected_set(sel_it, EINA_FALSE);
385 * @brief Selects all children of the accessible
387 * @param selection AtkSelection instance
388 * @returns always FALSE
391 eail_flipselector_select_all_selection(AtkSelection *selection)
397 * @brief AtkSelection interface initializer
399 * @param iface AtkSelectionIface instance
401 static void atk_selection_interface_init(AtkSelectionIface *iface)
403 iface->add_selection = eail_flipselector_add_selection;
404 iface->clear_selection = eail_flipselector_clear_selection;
405 iface->get_selection_count = eail_flipselector_get_selection_count;
406 iface->is_child_selected = eail_flipselector_is_child_selected;
407 iface->remove_selection = eail_flipselector_remove_selection;
408 iface->select_all_selection = eail_flipselector_select_all_selection;
412 * Implementation of the *AtkAction* interface
416 * @brief Performs the i-th action
418 * @param action AtkAction instance
419 * @param i action index
420 * @return TRUE on success, FALSE otherwise
423 eail_flipselector_action_do_action(AtkAction *action,
427 const char *action_name;
429 widget = eail_widget_get_widget(EAIL_WIDGET(action));
430 if (!widget) return FALSE;
432 if ((elm_object_disabled_get(widget)) || (!evas_object_visible_get(widget)))
435 action_name = atk_action_get_name(action, i);
436 if (!action_name) return FALSE;
438 if (!g_strcmp0("next", action_name))
439 elm_flipselector_flip_next(widget);
440 else if (!g_strcmp0("previous", action_name))
441 elm_flipselector_flip_prev(widget);
449 * @brief Gets the number of actions available on the object
451 * @param action AtkAction instance
452 * @return integer representing the number of implemented actions
455 eail_flipselector_action_get_n_actions(AtkAction *action)
461 * @brief Gets the description string of an action with the given index
463 * @param action AtkAction instance
464 * @param i index of action
466 * @returns string representing the specified action's description
467 * or NULL if one was not found
470 eail_flipselector_action_get_description(AtkAction *action,
473 const char *action_description = NULL;
474 EailFlipselector *flipselector;
476 flipselector = EAIL_FLIPSELECTOR(action);
477 if (!flipselector) return NULL;
482 action_description = flipselector->next_description;
486 action_description = flipselector->prev_description;
490 action_description = NULL;
494 return action_description;
498 * @brief Gets the name string of an action with the given index
500 * @param action AtkAction instance
501 * @param i action index
502 * @return string representing the specified action's name
503 * or NULL if one was not found
506 eail_flipselector_action_get_name(AtkAction *action,
509 const char* action_name = NULL;
514 /* user selects next item */
515 action_name = "next";
519 /* user selects previous item */
520 action_name = "previous";
532 * @brief Sets the description of the specified action
534 * @param action AtkAction instance
535 * @param i action's number
536 * @param desc action's description
537 * @return TRUE if description was set successfully, FALSE otherwise
540 eail_flipselector_action_set_description(AtkAction *action,
544 EailFlipselector *flipselector;
547 flipselector = EAIL_FLIPSELECTOR(action);
548 if (!flipselector) return FALSE;
553 value = &flipselector->next_description;
557 value = &flipselector->prev_description;
568 *value = g_strdup(desc);
577 * @brief AtkAction interface initializer
579 * @param iface AtkActionIface instance
582 atk_action_interface_init(AtkActionIface *iface)
584 g_return_if_fail(iface != NULL);
586 iface->do_action = eail_flipselector_action_do_action;
587 iface->get_n_actions = eail_flipselector_action_get_n_actions;
588 iface->get_description = eail_flipselector_action_get_description;
589 iface->get_name = eail_flipselector_action_get_name;
590 iface->set_description = eail_flipselector_action_set_description;