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.
22 * @brief EailIndex implementation
25 /* enabling beta API support for Eo parts*/
26 #define EFL_BETA_API_SUPPORT
28 #include <Elementary.h>
30 #include "eail_index.h"
31 #include "eail_factory.h"
32 #include "eail_item_parent.h"
33 #include "eail_utils.h"
34 /* internal elm_widget api for listening internal index parts */
35 #define ELM_INTERNAL_API_ARGESFSDFEFC
36 #include <elm_widget.h>
37 #include <elm_widget_index.h>
39 #ifndef ELM_OBJ_INDEX_CLASS
40 #ifndef ELM_INDEX_CLASS
41 #include <elm_index_eo.h>
45 #include "eail_priv.h"
47 static void eail_item_parent_interface_init(EailItemParentIface *iface);
48 static void atk_selection_interface_init(AtkSelectionIface *iface);
51 * @brief EailIndex GObject definition
53 * It extends EAIL_TYPE_WIDGET class and implements EAIL_TYPE_ITEM_PARENT and
54 * ATK_TYPE_SELECTION interfaces
56 G_DEFINE_TYPE_WITH_CODE(EailIndex,
59 G_IMPLEMENT_INTERFACE(EAIL_TYPE_ITEM_PARENT,
60 eail_item_parent_interface_init)
61 G_IMPLEMENT_INTERFACE(ATK_TYPE_SELECTION,
62 atk_selection_interface_init));
65 * Implementation of the *AtkObject* interface
69 * @brief Initializer for AtkObject
71 * @param obj AtkObject instance
72 * @param data initialization data
75 eail_index_initialize(AtkObject *obj, gpointer data)
77 ATK_OBJECT_CLASS(eail_index_parent_class) ->initialize(obj, data);
78 obj->role = ATK_ROLE_LIST;
82 * @brief EailIndex GObject instance initializer
84 * @param button EailIndex instance
87 eail_index_init(EailIndex *button)
92 * @brief Gets the list of Elm_Object_Item* that are contained in an index widget
94 * @param obj AtkObject instance
96 * @returns const Eina_List with Elm_Object_Item* for every index
98 static const Eina_List *
99 eail_index_get_index_items(AtkObject *obj) {
100 Evas_Object *index_widget = NULL;
102 index_widget = eail_widget_get_widget(EAIL_WIDGET(obj));
103 g_return_val_if_fail(index_widget, NULL);
105 ELM_INDEX_DATA_GET(index_widget, index_sd);
106 g_return_val_if_fail(index_sd, NULL);
108 return index_sd->items;
111 * @brief Gets the number of accessible children of the accessible.
113 * Implementation of AtkObject->get_n_children callback.
115 * @param obj AtkObject instance
117 * @returns integer representing the number of accessible children of
121 eail_index_get_n_children(AtkObject *obj)
123 return eina_list_count(eail_index_get_index_items(obj));
127 * @brief Gets a reference to the specified accessible child of the object.
129 * The accessible children are 0-based so the first accessible child is at index 0,
130 * the second at index 1 and so on.
132 * Implementation of AtkObject->ref_child callback.
134 * @param obj AtkObject instance
135 * @param i index of a child
137 * @returns AtkObject representing the specified accessible child of the
141 eail_index_ref_child(AtkObject *obj, gint i)
143 const Eina_List *items;
144 AtkObject *child = NULL;
146 items = eail_index_get_index_items(obj);
147 if (eina_list_count(items) > i)
149 child = eail_factory_get_item_atk_obj
150 (eina_list_nth(items, i), ATK_ROLE_LIST_ITEM, obj);
159 * @brief Gets the accessible name of the accessible.
161 * Implementation of AtkObject->get_name callback.
163 * @param obj AtkObject instance
165 * @returns string containing the accessible description of
169 eail_index_get_name(AtkObject *obj)
172 const char *atk_name;
174 g_return_val_if_fail(EAIL_IS_INDEX(obj), NULL);
176 atk_name = ATK_OBJECT_CLASS(eail_index_parent_class)->get_name(obj);
180 widget = eail_widget_get_widget(EAIL_WIDGET(obj));
181 if (!widget) return NULL;
183 return elm_object_text_get(widget);
187 * @brief Destructor of EailIndex object
188 * @param object GObject object to be finalized
191 eail_index_finalize(GObject *object)
193 G_OBJECT_CLASS(eail_index_parent_class)->finalize(object);
197 * @brief Initializer for EailIndex GObject class
199 * Defines callbacks for base AtkObject.
201 * @param klass EailIndex instance
204 eail_index_class_init(EailIndexClass *klass)
206 AtkObjectClass *atk_class = ATK_OBJECT_CLASS(klass);
207 GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
208 atk_class->initialize = eail_index_initialize;
209 atk_class->get_n_children = eail_index_get_n_children;
210 atk_class->ref_child = eail_index_ref_child;
211 atk_class->get_name = eail_index_get_name;
212 gobject_class->finalize = eail_index_finalize;
216 * @brief Checks if content get is supported
218 * Implementation of EailItemParent->is_content_get_supported callback.
220 * @param parent EailItemParent instance
221 * @param item EailItem instance
222 * @returns always FALSE
225 eail_index_content_get_support(EailItemParent *parent,
232 * @brief Gets item's name
234 * @param parent EailItemParent instance
235 * @param item EailItem instance
236 * @return string containing item's name
239 eail_index_get_item_name(EailItemParent *parent,
242 Elm_Object_Item *it = eail_item_get_item(item);
244 return elm_index_item_letter_get(it);
248 * @brief Gets index in parent
250 * @param parent EailItemParent instance
251 * @param item EailItem child instance
253 * @returns int representing the index in parent
256 eail_index_get_item_index_in_parent(EailItemParent *parent, EailItem *item)
258 Elm_Object_Item *it = eail_item_get_item(item);
259 const Eina_List *items;
264 items = eail_index_get_index_items(ATK_OBJECT(parent));
265 for (i=0; i<eina_list_count(items); ++i)
267 if (eina_list_nth(items, i) == it)
277 * @brief Initialization of EailItemParentIface callbacks
279 * @param iface EailItemParentIface instance
282 eail_item_parent_interface_init(EailItemParentIface *iface)
284 iface->get_item_name = eail_index_get_item_name;
285 iface->is_content_get_supported = eail_index_content_get_support;
286 iface->get_item_index_in_parent = eail_index_get_item_index_in_parent;
290 * @brief Adds the specified accessible child of the object to the object's selection.
292 * Implementation of AtkSelection->add_selection callback.
294 * @param selection AtkSelection instance
295 * @param i index of object
297 * @returns TRUE if operation was successful, FALSE otherwise
300 eail_index_add_selection(AtkSelection *selection,
303 const Eina_List *items = eail_index_get_index_items(ATK_OBJECT(selection));
304 if (!items) return FALSE;
305 Elm_Object_Item *item = eina_list_nth(items, i);
307 if (!item) return FALSE;
309 elm_index_item_selected_set(item, EINA_TRUE);
314 * @brief Gets a reference to the accessible object representing the specified selected
315 * child of the object.
317 * Note: callers should not rely on NULL or on a zero value
318 * for indication of whether AtkSelectionIface is implemented, they should use
319 * type checking/interface checking macros or the atk_get_accessible_value()
320 * convenience method.
322 * Implementation of AtkSelection->ref_selection callback.
324 * @param selection AtkSelection instance
325 * @param i index of object
327 * @returns AtkObject representing the selected accessible or NULL if
328 * selection does not implement this interface
331 eail_index_ref_selection(AtkSelection *selection,
334 g_return_val_if_fail(EAIL_IS_WIDGET(selection), NULL);
336 return eail_index_ref_child(ATK_OBJECT(selection), i);
340 * @brief Clears the selection in the object so that no children in the object are
343 * Implementation of AtkSelection->clear_selection callback.
345 * @param selection aAtkSelection instance
347 * @returns TRUE if success, FALSE otherwise.
350 eail_index_clear_selection(AtkSelection *selection)
352 g_return_val_if_fail(EAIL_IS_WIDGET(selection), FALSE);
353 Evas_Object *object = eail_widget_get_widget(EAIL_WIDGET(selection));
354 g_return_val_if_fail(object, FALSE);
356 Elm_Object_Item *selected_item = elm_index_selected_item_get(object, 0);
358 /* no selected item found so selection is already clear, doing nothing and
359 * returning TRUE to mark success*/
360 if (!selected_item) return TRUE;
362 elm_index_item_selected_set(selected_item, EINA_FALSE);
368 * @brief Gets the number of accessible children currently selected.
370 * Note: callers should not rely on NULL or on a zero value for indication of whether
371 * AtkSelectionIface is implemented, they should use type checking/interface
372 * checking macros or the atk_get_accessible_value() convenience method.
374 * Implementation of AtkSelection->get_selection_count callback.
376 * @param selection AtkSelection instance
378 * @returns integer representing the number of selected elements
381 eail_index_get_selection_count(AtkSelection *selection)
383 g_return_val_if_fail(EAIL_IS_WIDGET(selection), FALSE);
384 Evas_Object *object = eail_widget_get_widget(EAIL_WIDGET(selection));
386 if (elm_index_selected_item_get(object, 0))
393 * @brief Determines if the current child of this object is selected.
395 * Note: callers should not rely on NULL or on a zero value for indication of whether
396 * AtkSelectionIface is implemented, they should use type checking/interface
397 * checking macros or the atk_get_accessible_value() convenience method.
399 * Implementation of AtkSelection->is_child_selected callback.
401 * @param selection AtkSelection instance
402 * @param i index of object
404 * @returns TRUE if the specified child is selected or
405 * FALSE if selection does not implement this interface
408 eail_index_is_child_selected(AtkSelection *selection,
411 g_return_val_if_fail(EAIL_IS_WIDGET(selection), FALSE);
412 Evas_Object *object = eail_widget_get_widget(EAIL_WIDGET(selection));
413 Elm_Object_Item *selected_item = elm_index_selected_item_get(object, 0);
414 const Eina_List *items = eail_index_get_index_items(ATK_OBJECT(selection));
415 Elm_Object_Item *item_witn_n_index = NULL;
417 /* if no item is selected, then we are sure that none of the child is
419 if (!selected_item) return FALSE;
421 /* no items on list so no child is selected*/
422 if (!items) return FALSE;
424 item_witn_n_index = eina_list_nth(items, i);
426 if (item_witn_n_index == selected_item)
433 * @brief Initializer of AtkSelectionIface interface
435 * @param iface AtkSelectionIface
437 static void atk_selection_interface_init(AtkSelectionIface *iface)
439 iface->add_selection = eail_index_add_selection;
440 iface->clear_selection = eail_index_clear_selection;
441 iface->ref_selection = eail_index_ref_selection;
442 iface->get_selection_count = eail_index_get_selection_count;
443 iface->is_child_selected = eail_index_is_child_selected;