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_diskselector.c
22 * @brief EailDiskselector implementation
25 #include <Elementary.h>
27 #include "eail_diskselector.h"
28 #include "eail_factory.h"
29 #include "eail_item_parent.h"
30 #include "eail_utils.h"
31 #include "eail_priv.h"
33 #define EAIL_diskselector_ACTION_NEXT "next" /**< @brief 'next' action name*/
34 #define EAIL_diskselector_ACTION_PREV "previous" /**< @brief 'prev' action name*/
36 static void atk_selection_interface_init(AtkSelectionIface *iface);
37 static void eail_item_parent_interface_init(EailItemParentIface *iface);
38 static void eail_diskselector_actions_table_init(EailDiskselector *widget);
40 * @brief Definition of EailDiskselector as GObject
42 * EailDiskselector is extended ScrollableWidget with EAIL_TYPE_ITEM_PARENT and
43 * ATK_TYPE_SELECTION implemented
45 G_DEFINE_TYPE_WITH_CODE(EailDiskselector,
47 EAIL_TYPE_SCROLLABLE_WIDGET,
48 G_IMPLEMENT_INTERFACE(ATK_TYPE_SELECTION,
49 atk_selection_interface_init)
50 G_IMPLEMENT_INTERFACE(EAIL_TYPE_ITEM_PARENT,
51 eail_item_parent_interface_init));
54 * @brief Initializer for AtkObjectClass
56 * @param obj AtkObject instance
57 * @param data initialization data
60 eail_diskselector_initialize(AtkObject *obj, gpointer data)
62 Evas_Object *nested_widget = NULL;
63 ATK_OBJECT_CLASS(eail_diskselector_parent_class)->initialize(obj, data);
64 obj->role = ATK_ROLE_LIST;
66 EailDiskselector *widget = EAIL_DISKSELECTOR(obj);
67 eail_diskselector_actions_table_init(widget);
69 nested_widget = eail_widget_get_widget(EAIL_WIDGET(obj));
72 ERR("No evas object inside EailWidget was found");
76 evas_object_smart_callback_add(nested_widget, "selected",
77 eail_list_item_handle_selected_event, obj);
81 * @brief Initializer for GObject EailList instance
83 * @param diskselector EailDiskselector instance
86 eail_diskselector_init(EailDiskselector *diskselector)
91 * @brief Gets the number of accessible children of the accessible.
93 * Implementation of AtkObject->get_n_children callback.
95 * @param obj AtkObject instance
97 * @returns integer representing the number of accessible children of
101 eail_diskselector_get_n_children(AtkObject *obj)
105 Evas_Object *widget = eail_widget_get_widget(EAIL_WIDGET(obj));
106 n_items = eina_list_count(elm_diskselector_items_get(widget));
112 * @brief Gets a reference to the specified accessible child of the object.
114 * The accessible children are 0-based so the first accessible child is at index 0,
115 * the second at index 1 and so on.
117 * Implementation of AtkObject->ref_child callback.
119 * @param obj AtkObject instance
120 * @param i child index
122 * @returns AtkObject representing the specified accessible child of the
126 eail_diskselector_ref_child(AtkObject *obj, gint i)
128 const Eina_List *items;
129 AtkObject *child = NULL;
130 Evas_Object *widget = NULL;
132 widget = eail_widget_get_widget(EAIL_WIDGET(obj));
133 if (!widget) return NULL;
135 items = elm_diskselector_items_get(widget);
137 if (eina_list_count(items) > i)
139 child = eail_factory_get_item_atk_obj
140 (eina_list_nth(items, i), ATK_ROLE_LIST_ITEM, obj);
149 * @brief Destructor for EailDiskselector class
151 * @param object GObject object to be finalized
154 eail_diskselector_finalize(GObject *object)
156 G_OBJECT_CLASS(eail_diskselector_parent_class)->finalize(object);
160 * @brief Initializer for GObject EailDiskselectorClass class
162 * Defines callbacks for base AtkObject.
164 * @param klass EailDiskselectorClass instance
167 eail_diskselector_class_init(EailDiskselectorClass *klass)
169 AtkObjectClass *atk_class = ATK_OBJECT_CLASS(klass);
170 GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
171 atk_class->initialize = eail_diskselector_initialize;
172 atk_class->get_n_children = eail_diskselector_get_n_children;
173 atk_class->ref_child = eail_diskselector_ref_child;
174 gobject_class->finalize = eail_diskselector_finalize;
178 * Implementation of the *AtkSelection* interface
182 * @brief Adds the specified accessible child of the object to the object's selection.
184 * Implementation of AtkSelection->add_selection callback.
186 * @param selection AtkSelection instance
187 * @param i selection index
189 * @returns TRUE if operation was successful, FALSE otherwise
192 eail_selection_add_selection(AtkSelection *selection,
195 g_return_val_if_fail(EAIL_IS_WIDGET(selection), FALSE);
196 Evas_Object *object = eail_widget_get_widget(EAIL_WIDGET(selection));
197 const Eina_List *items = elm_diskselector_items_get(object);
198 Elm_Object_Item *item = eina_list_nth(items, i);
199 if (!item) return FALSE;
200 elm_diskselector_item_selected_set(item, EINA_TRUE);
205 * @brief Clears the selection in the object so that no children in the object are
208 * Implementation of AtkSelection->clear_selection callback.
210 * @param selection AtkSelection instance
212 * @returns always FALSE - this operation is not supported for Diskselector
215 eail_selection_clear_selection(AtkSelection *selection)
221 * @brief Gets a reference to the accessible object representing the specified selected
222 * child of the object.
224 * Note: callers should not rely on NULL or on a zero value
225 * for indication of whether AtkSelectionIface is implemented, they should use
226 * type checking/interface checking macros or the atk_get_accessible_value()
227 * convenience method.
229 * Implementation of AtkSelection->ref_selection callback.
231 * @param selection AtkSelection instance
232 * @param i selection index
234 * @returns AtkObject representing the selected accessible or NULL if
235 * selection does not implement this interface
238 eail_selection_ref_selection(AtkSelection *selection,
241 g_return_val_if_fail(EAIL_IS_WIDGET(selection), NULL);
243 Evas_Object *object = eail_widget_get_widget(EAIL_WIDGET(selection));
244 const Eina_List *items = elm_diskselector_items_get(object);
245 Elm_Object_Item *item = eina_list_nth(items, i);
246 if (!item) return NULL;
249 obj = g_object_new(EAIL_TYPE_DISKSELECTOR, NULL);
250 obj->role = ATK_ROLE_LIST_ITEM;
252 if (EAIL_IS_ITEM_PARENT(selection))
253 atk_object_set_parent(obj, (AtkObject *)selection);
255 atk_object_initialize(obj, item);
261 * @brief Gets the number of accessible children currently selected.
263 * Note: callers should not rely on NULL or on a zero value for indication of whether
264 * AtkSelectionIface is implemented, they should use type checking/interface
265 * checking macros or the atk_get_accessible_value() convenience method.
267 * Implementation of AtkSelection->get_selection_count callback.
269 * @param selection AtkSelection instance
271 * @returns always '1' - in Diskselector widget something is always selected
274 eail_selection_get_selection_count(AtkSelection *selection)
280 * @brief Determines if the current child of this object is selected.
282 * Note: callers should not rely on NULL or on a zero value for indication of whether
283 * AtkSelectionIface is implemented, they should use type checking/interface
284 * checking macros or the atk_get_accessible_value() convenience method.
286 * Implementation of AtkSelection->is_child_selected callback.
288 * @param selection AtkSelection instance
289 * @param i child index
291 * @returns gboolean representing the specified child is selected, or 0 if
292 * selection does not implement this interface
295 eail_selection_is_child_selected(AtkSelection *selection,
298 g_return_val_if_fail(EAIL_IS_WIDGET(selection), FALSE);
299 Evas_Object *object = eail_widget_get_widget(EAIL_WIDGET(selection));
300 Elm_Object_Item *selected_item = elm_diskselector_selected_item_get(object);
301 Elm_Object_Item *last_item = elm_diskselector_last_item_get(object);
302 Elm_Object_Item *item = elm_diskselector_first_item_get(object);
306 if (selected_item==item) break;
307 item = elm_diskselector_item_next_get(item);
309 } while (item!=last_item);
314 * @brief Removes the specified child of the object from the object's selection.
316 * Implementation of AtkSelection->remove_selection callback.
318 * @param selection AtkSelection instance
319 * @param i selection index
321 * @returns TRUE on success, FALSE otherwise
324 eail_selection_remove_selection(AtkSelection *selection,
327 g_return_val_if_fail(EAIL_IS_WIDGET(selection), FALSE);
328 Evas_Object *object = eail_widget_get_widget(EAIL_WIDGET(selection));
329 Elm_Object_Item *selected_item = elm_diskselector_first_item_get(object);
330 elm_diskselector_item_selected_set(selected_item, TRUE);
335 * @brief Causes every child of the object to be selected if the object supports
336 * multiple selections.
338 * Implementation of AtkSelection->select_all_selection callback.
340 * @param selection AtkSelection instance
342 * @returns FALSE - this operation is not supported for Diskselector widget
345 eail_selection_select_all_selection(AtkSelection *selection)
351 * @brief Initialization of AtkSelectionIface interface
353 * Function called upon instance creation. It initializes AtkSelection interface
354 * implementation i.e hooks method pointers in the interface structure
355 * to the implementing class's implementation.
357 * @param iface AtkSelectionIface instance
359 static void atk_selection_interface_init(AtkSelectionIface *iface)
361 iface->add_selection = eail_selection_add_selection;
362 iface->clear_selection = eail_selection_clear_selection;
363 iface->ref_selection = eail_selection_ref_selection;
364 iface->get_selection_count = eail_selection_get_selection_count;
365 iface->is_child_selected = eail_selection_is_child_selected;
366 iface->remove_selection = eail_selection_remove_selection;
367 iface->select_all_selection = eail_selection_select_all_selection;
371 * @brief Gets the name of a diskselector's child
373 * @param parent EailItemParent instance
374 * @param item EailItem child instance
376 * @returns string representing the name of the child
379 eail_diskselector_item_name_get(EailItemParent *parent, EailItem *item)
381 Elm_Object_Item *it = eail_item_get_item(item);
382 if (!it) return NULL;
384 return elm_object_item_part_text_get(it, NULL);
388 * @brief Initialization of EailItemParentIface callbacks
390 * @param iface EailItemParentIface instance
393 eail_item_parent_interface_init(EailItemParentIface *iface)
395 iface->get_item_name = eail_diskselector_item_name_get;
399 * @brief 'next' action callback
401 * @param action AtkAction instance
402 * @param data data passed to callback
403 * @return TRUE on success, FALSE otherwise
406 _eail_diskselector_action_next(AtkAction *action, void *data)
409 Elm_Object_Item *it_next;
412 g_return_val_if_fail(EAIL_IS_DISKSELECTOR(action), FALSE);
414 widget = eail_widget_get_widget(EAIL_WIDGET(action));
415 if (!widget) return FALSE;
417 it = elm_diskselector_selected_item_get(widget);
418 if (!it) return FALSE;
420 it_next = elm_diskselector_item_next_get(it);
421 if (it_next) elm_diskselector_item_selected_set(it_next, EINA_TRUE);
423 evas_object_smart_callback_call(widget, "selected", NULL);
429 * @brief 'prev' action callback
431 * @param action AtkAction instance
432 * @param data data passed to callback
433 * @return TRUE on success, FALSE otherwise
436 _eail_diskselector_action_prev(AtkAction *action, void *data)
440 Elm_Object_Item *it_prev;
442 g_return_val_if_fail(EAIL_IS_DISKSELECTOR(action), FALSE);
444 widget = eail_widget_get_widget(EAIL_WIDGET(action));
445 if (!widget) return FALSE;
447 it = elm_diskselector_selected_item_get(widget);
448 if (!it) return FALSE;
450 it_prev = elm_diskselector_item_prev_get(it);
451 if (it_prev) elm_diskselector_item_selected_set(it_prev, EINA_TRUE);
453 evas_object_smart_callback_call(widget, "selected", NULL);
459 * @brief Adds actions for scrolling to actions table
460 * @param widget EailDiskselector instance
463 eail_diskselector_actions_table_init(EailDiskselector *widget)
465 g_return_if_fail(EAIL_IS_DISKSELECTOR(widget));
467 eail_action_widget_action_append(EAIL_ACTION_WIDGET(widget),
468 EAIL_diskselector_ACTION_PREV,
470 _eail_diskselector_action_prev);
471 eail_action_widget_action_append(EAIL_ACTION_WIDGET(widget),
472 EAIL_diskselector_ACTION_NEXT,
474 _eail_diskselector_action_next);