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_gengrid.c
22 * @brief EailGengrid implementation
25 #include <Elementary.h>
27 #include "eail_gengrid.h"
28 #include "eail_item_parent.h"
29 #include "eail_factory.h"
30 #include "eail_utils.h"
31 #include "eail_priv.h"
33 static void eail_item_parent_interface_init(EailItemParentIface *iface);
34 static void atk_table_interface_init(AtkTableIface *iface);
35 static void atk_selection_interface_init(AtkSelectionIface *iface);
37 /** @brief GObject definition for EailGengrid implementation*/
38 G_DEFINE_TYPE_WITH_CODE(EailGengrid,
41 G_IMPLEMENT_INTERFACE(EAIL_TYPE_ITEM_PARENT,
42 eail_item_parent_interface_init)
43 G_IMPLEMENT_INTERFACE(ATK_TYPE_TABLE,
44 atk_table_interface_init)
45 G_IMPLEMENT_INTERFACE(ATK_TYPE_SELECTION,
46 atk_selection_interface_init));
49 * Implementation of the *AtkObject* interface
53 * @brief Handler for realized event, used to notify about gengrid content
56 * @param data passed to callback
57 * @param obj object that raised event
58 * @param event_info additional event info (item is passed here)
61 eail_gengrid_item_handle_realized_event(void *data,
65 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
66 AtkObject *atk_item = NULL, *atk_parent = NULL;
68 atk_parent = ATK_OBJECT(data);
69 if (!atk_parent) return;
71 atk_item = eail_factory_get_item_atk_obj
72 (item, ATK_ROLE_LIST_ITEM, atk_parent);
74 if (!atk_item) return;
76 eail_emit_children_changed_obj(TRUE, atk_parent, atk_item);
80 * @brief Handler for unrealized event, used to notify about gengrid content
83 * @param data passed to callback
84 * @param obj object that raised event
85 * @param event_info additional event info (item is passed here)
88 eail_gengrid_item_handle_unrealized_event(void *data,
92 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
93 AtkObject *atk_item = NULL, *atk_parent = NULL;
95 atk_parent = ATK_OBJECT(data);
96 if (!atk_parent) return;
98 atk_item = eail_factory_get_item_atk_obj
99 (item, ATK_ROLE_LIST_ITEM, atk_parent);
101 if (!atk_item) return;
103 eail_emit_children_changed_obj(FALSE, atk_parent, atk_item);
104 atk_object_notify_state_change(atk_item, ATK_STATE_DEFUNCT, TRUE);
106 DBG("Unregistering item from cache...");
107 eail_factory_unregister_item_from_cache(item);
111 * @brief Initializes EailGengrid object
113 * @param obj EailGengrid instance
114 * @param data user data passed for initialization
117 eail_gengrid_initialize(AtkObject *obj, gpointer data)
119 Evas_Object *nested_widget = NULL;
120 ATK_OBJECT_CLASS(eail_gengrid_parent_class)->initialize(obj, data);
121 obj->role = ATK_ROLE_TABLE;
123 nested_widget = eail_widget_get_widget(EAIL_WIDGET(obj));
126 ERR("No evas object inside EailWidget was found");
130 evas_object_smart_callback_add(nested_widget, "selected",
131 eail_list_item_handle_selected_event, obj);
132 evas_object_smart_callback_add(nested_widget, "unselected",
133 eail_list_item_handle_unselected_event, obj);
134 evas_object_smart_callback_add(nested_widget, "realized",
135 eail_gengrid_item_handle_realized_event, obj);
136 evas_object_smart_callback_add(nested_widget, "unrealized",
137 eail_gengrid_item_handle_unrealized_event, obj);
141 * @brief Gets the list of created widgets
143 * @param gengrid EailGengrid instance
145 * @returns Eina_List representing the list of widgets elm_gengrid holds
148 eail_gengrid_items_get(EailGengrid *gengrid)
150 g_return_val_if_fail(EAIL_IS_WIDGET(gengrid), NULL);
152 Evas_Object *widget = eail_widget_get_widget(EAIL_WIDGET(gengrid));
154 return elm_gengrid_realized_items_get(widget);
158 * @brief Gets the number of created widgets
160 * @param obj AtkObject instance
162 * @returns integer representing the number of created widgets
165 eail_gengrid_n_items_get(AtkObject *obj)
168 Eina_List *items = eail_gengrid_items_get(EAIL_GENGRID(obj));
169 n_items = eina_list_count(items);
170 eina_list_free(items);
176 * @brief Gets the reference to the specified elm_gengrid's child
178 * @param obj AtkObject instance
179 * @param i child index
181 * @returns AtkObject representing the elm_gengrid's child
184 eail_gengrid_ref_child(AtkObject *obj, gint i)
186 g_return_val_if_fail(EAIL_IS_GENGRID(obj), NULL);
188 AtkObject *child = NULL;
190 Eina_List *list = eail_gengrid_items_get(EAIL_GENGRID(obj));
191 if (eina_list_count(list) > i)
193 child = eail_factory_get_item_atk_obj
194 (eina_list_nth(list, i), ATK_ROLE_LIST_ITEM, obj);
203 * @brief Gets a reference to the state set of the accessible
205 * The caller must unreference it when it is no longer needed.
207 * Implementation of ref_state_set from AtkObject.
209 * @param obj AtkObject instance
211 * @returns AtkStateSet representing the state set of the accessible
214 eail_gengrid_ref_state_set(AtkObject *obj)
216 Evas_Object *widget = eail_widget_get_widget(EAIL_WIDGET(obj));
217 AtkStateSet *state_set =
218 ATK_OBJECT_CLASS(eail_gengrid_parent_class)->ref_state_set(obj);
220 if (!widget) return state_set;
222 if (elm_gengrid_multi_select_get(widget))
223 atk_state_set_add_state(state_set, ATK_STATE_MULTISELECTABLE);
229 * @brief Initializes EailGengrid object
231 * @param gengrid EailGengrid instance
234 eail_gengrid_init(EailGengrid *gengrid)
239 * @brief Initializes EailGengrid class
241 * @param klass EailGengridClass instance
244 eail_gengrid_class_init(EailGengridClass *klass)
246 AtkObjectClass *atk_class = ATK_OBJECT_CLASS(klass);
248 atk_class->initialize = eail_gengrid_initialize;
249 atk_class->get_n_children = eail_gengrid_n_items_get;
250 atk_class->ref_child = eail_gengrid_ref_child;
251 atk_class->ref_state_set = eail_gengrid_ref_state_set;
255 * @brief Gets the name of elm_gengrid child
257 * @param parent EailItemParent instance
258 * @param item EailItem child instance
260 * @returns string representing the item's name
263 eail_gengrid_item_name_get(EailItemParent *parent, EailItem *item)
265 Elm_Object_Item *it = eail_item_get_item(item);
266 /*that will work only for default theme*/
267 if (!it) return NULL;
269 return elm_object_item_part_text_get(it, "elm.text");
273 * @brief Gets the item's index in parent object
275 * @param parent EailItemParent instance
276 * @param item EailItem child instance
278 * @returns integer representing the child's index in parent
281 eail_gengrid_item_index_in_parent_get(EailItemParent *parent, EailItem *item)
283 Elm_Object_Item *it = eail_item_get_item(item);
287 return elm_gengrid_item_index_get(it)-1;
291 * @brief Gets the state set of EailGengrid item
293 * @param parent EailItemParent instance
294 * @param item EailItem child instance
295 * @param state_set AtkStateSet to fill
297 * @returns AtkStateSet representing the state set of the child
300 eail_gengrid_ref_item_state_set(EailItemParent *parent,
302 AtkStateSet *state_set)
304 Evas_Object *widget = eail_widget_get_widget(EAIL_WIDGET(parent));
305 Elm_Object_Item *it = eail_item_get_item(item);
307 if (!widget || !it) return state_set;
309 Evas_Object *cell = elm_object_item_widget_get(it);
311 if ((elm_gengrid_select_mode_get(widget) != ELM_OBJECT_SELECT_MODE_NONE) &&
312 (elm_gengrid_item_select_mode_get(it) != ELM_OBJECT_SELECT_MODE_NONE))
314 atk_state_set_add_state(state_set, ATK_STATE_SELECTABLE);
315 if (elm_gengrid_selected_item_get(cell))
316 atk_state_set_add_state(state_set, ATK_STATE_SELECTED);
319 if (evas_object_visible_get(cell))
320 atk_state_set_add_state(state_set, ATK_STATE_VISIBLE);
322 atk_state_set_add_state(state_set, ATK_STATE_SHOWING);
328 * @brief Grabs focus of EailGengrid item
330 * @param parent EailGengrid instance
331 * @param item EailGengrid child instance
333 * @returns TRUE on success, FALSE otherwise
336 eail_gengrid_grab_item_focus(EailItemParent *parent,
339 Elm_Object_Item *it = eail_item_get_item(item);
340 if (!it) return FALSE;
342 Evas_Object *obj = elm_object_item_widget_get(it);
343 if (!elm_object_focus_allow_get(obj)) return FALSE;
345 elm_object_focus_set(obj, EINA_TRUE);
351 * @brief Gets the rectangle which gives the extent of the component
353 * Implementation of get_extents from AtkComponent for EailGengrid child.
355 * @param parent EailGengrid instance
356 * @param item EailGengrid child instance
357 * @param [out] x x coordinate
358 * @param [out] y coordinate
359 * @param [out] width width of the rectangle
360 * @param [out] height height of the rectangle
361 * @param coord_type specifies whether the coordinates are relative to the screen or to the components top level window
364 eail_gengrid_item_extents_get(EailItemParent *parent,
370 AtkCoordType coord_type)
372 Evas_Object *widget = eail_widget_get_widget(EAIL_WIDGET(parent));
373 Elm_Object_Item *it = eail_item_get_item(item);
375 if ((!widget) || (!it)) return;
377 Evas_Object *it_widget = elm_object_item_widget_get(it);
378 evas_object_geometry_get(it_widget, x, y, width, height);
380 if (coord_type == ATK_XY_SCREEN) {
383 ecore_evas_ecore_evas_get(evas_object_evas_get(it_widget));
385 ecore_evas_geometry_get(ee, &ee_x, &ee_y, NULL, NULL);
392 * @brief Gets supported actions
394 * Implementation of EailItemParent->get_actions_supported callback.
396 * @param parent EailItemParent instance
397 * @param item EailItem instance
398 * @returns implementation representing supported actions
401 eail_gengrid_get_actions_supported(EailItemParent *parent,
404 return EAIL_ACTION_SUPPORTED_CLICK | EAIL_ACTION_SUPPORTED_PRESS |
405 EAIL_ACTION_SUPPORTED_RELEASE;
409 * @brief Gets index in parent
411 * @param parent EailItemParent instance
412 * @param item EailItem child instance
414 * @returns int representing the index in parent
417 eail_gengrid_get_item_index_in_parent(EailItemParent *parent, EailItem *item)
419 Elm_Object_Item *it = eail_item_get_item(item);
423 return elm_gengrid_item_index_get(it)-1;
427 * @brief EailItemParent interface initialization
429 * @param iface EailItemParentIface instance
432 eail_item_parent_interface_init(EailItemParentIface *iface)
436 iface->get_item_name = eail_gengrid_item_name_get;
437 iface->get_item_index_in_parent = eail_gengrid_item_index_in_parent_get;
438 iface->ref_item_state_set = eail_gengrid_ref_item_state_set;
439 iface->grab_item_focus = eail_gengrid_grab_item_focus;
440 iface->get_item_extents = eail_gengrid_item_extents_get;
441 iface->get_actions_supported = eail_gengrid_get_actions_supported;
442 iface->get_item_index_in_parent = eail_gengrid_get_item_index_in_parent;
446 * @brief Helper function for getting rows and columns count
448 * @param object elm_gengrid instance
449 * @param [out] rows rows count
450 * @param [out] columns columns count
453 _get_n_rows_columns(const Evas_Object *object,
454 int *rows, int *columns)
457 Eina_List *l, *list = elm_gengrid_realized_items_get(object);
468 EINA_LIST_FOREACH(list, l, it)
470 unsigned int item_row, item_col;
471 elm_gengrid_item_pos_get(it, &item_col, &item_row);
472 if (item_row > row) row++;
473 if (item_col > column) column++;
476 eina_list_free(list);
478 *columns = column + 1;
483 * @brief Gets the number of rows in the table
485 * Implementation of get_n_rows from AtkTable.
487 * @param table AtkTable instance
489 * @returns integer representing the number of rows
492 eail_gengrid_n_rows_get(AtkTable *table)
497 g_return_val_if_fail(EAIL_IS_GENGRID(table), -1);
499 widget = eail_widget_get_widget(EAIL_WIDGET(table));
500 if (!widget) return -1;
502 _get_n_rows_columns(widget, &rows, &columns);
507 * @brief Gets the number of columns in the table
509 * Implementation of get_n_columns from AtkTable.
511 * @param table AtkTable instance
513 * @returns integer representing the number of columns
516 eail_gengrid_n_columns_get(AtkTable *table)
521 g_return_val_if_fail(EAIL_IS_GENGRID(table), -1);
523 widget = eail_widget_get_widget(EAIL_WIDGET(table));
525 _get_n_rows_columns(widget, &rows, &columns);
531 * @brief Gets a gint representing the index at the specified row and column
533 * Implementation of get_index_at from AtkTable.
535 * @param table AtkTable instance
536 * @param row number of row in table
537 * @param column number of column in table
539 * @returns integer representing the index of the specified position
542 eail_gengrid_index_at_get(AtkTable *table, gint row, gint column)
545 gint n_rows, n_columns;
548 g_return_val_if_fail(EAIL_IS_GENGRID(table), -1);
549 widget = eail_widget_get_widget(EAIL_WIDGET(table));
550 if (!widget) return -1;
552 _get_n_rows_columns(widget, &n_rows, &n_columns);
554 if ((row >= n_rows) || (column >= n_columns)) return -1;
556 if (elm_gengrid_horizontal_get(widget))
557 ret_val = ((n_columns) * column) + row;
559 ret_val = ((n_columns) * row) + column;
561 /* testing if result is within bounds */
562 if (ret_val >= eail_gengrid_n_items_get(ATK_OBJECT(table)))
569 * @brief Get a reference to the table cell at row, column
571 * Implementation of ref_at from AtkTable.
573 * @param table AtkTable instance
574 * @param row number of row in table
575 * @param column number of column in table
577 * @returns AtkObject representing the child object
580 eail_gengrid_ref_at(AtkTable *table, gint row, gint column)
584 g_return_val_if_fail(EAIL_IS_GENGRID(table), NULL);
586 index = eail_gengrid_index_at_get(table, row, column);
587 if (index == -1) return NULL;
589 return eail_gengrid_ref_child(ATK_OBJECT(table), index);
593 * @brief Helper function for getting object's position in table at given index
595 * @param widget Evas_Object instance
596 * @param [out] row row number
597 * @param [out] column column number
598 * @param index index of child item
601 _get_item_pos(const Evas_Object *widget, gint *row, gint *column, gint index)
613 list = elm_gengrid_realized_items_get(widget);
614 it = eina_list_nth(list, index);
615 elm_gengrid_item_pos_get(it, (unsigned int *)column, (unsigned int *)row);
617 eina_list_free(list);
621 * @brief Gets an integer representing the column at the specified index
623 * Implementation of get_column_at_index from AtkTable.
625 * @param table AtkTable instance
626 * @param index child index
628 * @returns integer representing the column number in table
631 eail_gengrid_column_at_index_get(AtkTable *table, gint index)
636 g_return_val_if_fail(EAIL_IS_GENGRID(table), -1);
637 if (index >= eail_gengrid_n_items_get(ATK_OBJECT(table)))
640 widget = eail_widget_get_widget(EAIL_WIDGET(table));
641 _get_item_pos(widget, &row, &column, index);
647 * @brief Gets a gint representing the row at the specified index
649 * Implementation of get_row_at_index from AtkTable.
651 * @param table AtkTable instance
652 * @param index child index
654 * @returns integer representing the row number in table
657 eail_gengrid_row_at_index_get(AtkTable *table, gint index)
662 g_return_val_if_fail(EAIL_IS_GENGRID(table), -1);
663 if (index >= eail_gengrid_n_items_get(ATK_OBJECT(table)))
666 widget = eail_widget_get_widget(EAIL_WIDGET(table));
667 _get_item_pos(widget, &row, &column, index);
673 * @brief Gets a boolean value indicating whether the accessible object
674 * at the specified row and column is selected
676 * Implementation of is_selected from AtkTable.
678 * @param table AtkTable instance
679 * @param row row's number
680 * @param column column's number
682 * @returns TRUE if selected, FALSE otherwise
685 eail_gengrid_is_selected(AtkTable *table, gint row, gint column)
693 g_return_val_if_fail(EAIL_IS_GENGRID(table), FALSE);
694 widget = eail_widget_get_widget(EAIL_WIDGET(table));
695 index = eail_gengrid_index_at_get(table, row, column);
696 if (index == -1) return FALSE;
698 list = elm_gengrid_realized_items_get(widget);
699 it = eina_list_nth(list, index);
700 result = elm_gengrid_item_selected_get(it);
702 eina_list_free(list);
707 * @brief Gets a boolean value indicating whether the specified row is selected
709 * Implementation of is_row_selected from AtkTable interface.
711 * @param table AtkTable instance
712 * @param row number of row in table
714 * @returns TRUE if selected, FALSE otherwise
717 eail_gengrid_is_row_selected(AtkTable *table, gint row)
721 const Eina_List *selected;
723 int list_count, n_rows;
725 g_return_val_if_fail(EAIL_IS_GENGRID(table), FALSE);
726 widget = eail_widget_get_widget(EAIL_WIDGET(table));
727 /*it is possible to select row only in multiselct mode*/
728 if (!elm_gengrid_multi_select_get(widget))
731 selected = elm_gengrid_selected_items_get(widget);
732 if (!selected) return FALSE;
734 n_rows = eail_gengrid_n_rows_get(table);
735 if (row > n_rows) return FALSE;
737 list = elm_gengrid_realized_items_get(widget);
738 list_count = eina_list_count(list);
741 for (int i = 0; i < list_count; i++)
743 Elm_Object_Item *it = eina_list_nth(list, i);
745 elm_gengrid_item_pos_get(it, &x, &y);
746 if((row == x) && (!elm_gengrid_item_selected_get(it)))
748 /*row is considered selected if all items in row are selected*/
753 eina_list_free(list);
758 * @brief Gets the selected rows of the table by initializing selected
759 * with the selected row numbers
761 * This array should be freed by the caller.
763 * Implementation of get_selected_rows from AtkTable interface.
765 * @param table AtkTable instance
766 * @param [out] selected selected rows number
768 * @returns integer representing the selected rows count
771 eail_gengrid_selected_rows_get(AtkTable *table, gint **selected)
776 int n_rows, n_selected, i;
778 g_return_val_if_fail(EAIL_IS_GENGRID(table), 0);
779 widget = eail_widget_get_widget(EAIL_WIDGET(table));
783 if (!elm_gengrid_multi_select_get(widget) && eail_gengrid_n_columns_get(table) > 1)
786 n_rows = eail_gengrid_n_rows_get(table);
788 array = g_array_new(FALSE, FALSE, sizeof(gint));
789 for (i = 0; i < n_rows; i++)
791 if (eail_gengrid_is_row_selected(table, i))
792 g_array_append_val(array, i);
795 n_selected = array->len;
799 *selected = (gint *) g_malloc (n_selected * sizeof(gint));
801 for (i=0; i<n_selected;i++)
803 row = g_array_index(array,gint,i);
804 (*selected)[i] = row;
807 g_array_free(array, FALSE);
815 * @brief Helper function for setting row selection
817 * @param table AtkTable instance
818 * @param row row number
819 * @param selection EINA_TRUE for selection, EINA_FALSE for removing selection
822 _set_row_selection(AtkTable *table, int row, Eina_Bool selection)
824 Evas_Object *widget = eail_widget_get_widget(EAIL_WIDGET(table));
825 Eina_List *list = elm_gengrid_realized_items_get(widget);
826 int list_count = eina_list_count(list);
828 for (int i = 0; i < list_count; i++)
831 Elm_Object_Item *it = eina_list_nth(list, i);
832 elm_gengrid_item_pos_get(it, &x, &y);
835 elm_gengrid_item_selected_set(it, selection);
839 eina_list_free(list);
843 * @brief Adds the specified row to the selection
845 * Implementation of add_row_selection from AtkTable.
847 * @param table AtkTable instance
848 * @param row row number in table
850 * @returns TRUE on success, FALSE otherwise
853 eail_gengrid_add_row_selection(AtkTable *table, gint row)
858 g_return_val_if_fail(EAIL_IS_GENGRID(table), FALSE);
859 widget = eail_widget_get_widget(EAIL_WIDGET(table));
861 if (!widget) return FALSE;
862 if (!elm_gengrid_multi_select_get(widget)) return FALSE;
863 n_rows = eail_gengrid_n_rows_get(table);
864 if (row > n_rows) return FALSE;
866 _set_row_selection(table, row, EINA_TRUE);
871 * @brief Removes the specified row from the selection
873 * Implementation of remove_row_selection from AtkTable interface.
875 * @param table AtkTable instance
876 * @param row number of row in table
878 * @returns TRUE on success, FALSE otherwise
881 eail_gengrid_remove_row_selection(AtkTable *table, gint row)
886 g_return_val_if_fail(EAIL_IS_GENGRID(table), FALSE);
888 widget = eail_widget_get_widget(EAIL_WIDGET(table));
889 if (!widget) return FALSE;
890 if (!elm_gengrid_multi_select_get(widget)) return FALSE;
891 n_rows = eail_gengrid_n_rows_get(table);
892 if (row > n_rows) return FALSE;
894 _set_row_selection(table, row, EINA_FALSE);
900 * @brief Gets a boolean value indicating whether the specified column is selected
902 * Implementation of is_column_selected from AtkTable interface.
904 * @param table AtkTable implementation
905 * @param column number of column in table
907 * @returns TRUE on selection, FALSE otherwise
910 eail_gengrid_is_column_selected(AtkTable *table, gint column)
914 const Eina_List *selected;
915 int n_columns, list_count;
918 g_return_val_if_fail(EAIL_IS_GENGRID(table), FALSE);
919 widget = eail_widget_get_widget(EAIL_WIDGET(table));
920 if (!elm_gengrid_multi_select_get(widget)) return FALSE;
921 n_columns = eail_gengrid_n_columns_get(table);
922 if (column > n_columns) return FALSE;
923 selected = elm_gengrid_selected_items_get(widget);
924 if (!selected) return FALSE;
926 list = elm_gengrid_realized_items_get(widget);
927 list_count = eina_list_count(list);
929 for (int i = 0; i < list_count; i++)
931 Elm_Object_Item *it = eina_list_nth(list, i);
933 elm_gengrid_item_pos_get(it, &x, &y);
934 if ((y == column) && (!elm_gengrid_item_selected_get(it)))
941 eina_list_free(list);
946 * @brief Helper function for setting column selection in elm_gengrid
948 * @param table AtkTable instance
949 * @param column number of column in table
950 * @param selection EINA_TRUE for selection, EINA_FALSE otherwise
953 _set_column_selection(AtkTable *table, int column, Eina_Bool selection)
955 Evas_Object *widget = eail_widget_get_widget(EAIL_WIDGET(table));
956 Eina_List *list = elm_gengrid_realized_items_get(widget);
957 int list_count = eina_list_count(list);
959 for (int i = 0; i < list_count; i++)
962 Elm_Object_Item *it = eina_list_nth(list, i);
963 elm_gengrid_item_pos_get(it, &x, &y);
966 elm_gengrid_item_selected_set(it, selection);
970 eina_list_free(list);
974 * @brief Gets the selected columns of the table by initializing selected
975 * with the selected columns numbers
977 * This array should be freed by the caller.
979 * Implementation of get_selected_columns from AtkTable interface.
981 * @param table AtkTable instance
982 * @param [out] selected selected columns number
984 * @returns integer representing the selected columns count
987 eail_gengrid_selected_columns_get(AtkTable *table, gint **selected)
992 int n_cols, n_selected, i;
994 g_return_val_if_fail(EAIL_IS_GENGRID(table), 0);
995 widget = eail_widget_get_widget(EAIL_WIDGET(table));
999 if (!elm_gengrid_multi_select_get(widget) && eail_gengrid_n_rows_get(table) > 1)
1002 n_cols = eail_gengrid_n_columns_get(table);
1004 array = g_array_new(FALSE, FALSE, sizeof(gint));
1005 for (i = 0; i < n_cols; i++)
1007 if (eail_gengrid_is_column_selected(table, i))
1008 g_array_append_val(array, i);
1011 n_selected = array->len;
1015 *selected = (gint *) g_malloc (n_selected * sizeof(gint));
1017 for (i=0; i<n_selected;i++)
1019 col = g_array_index(array,gint,i);
1020 (*selected)[i] = col;
1023 g_array_free(array, FALSE);
1031 * @brief Adds the specified column to the selection
1033 * Implementation of add_column_selection from AtkTable interface.
1035 * @param table AtkTable instance
1036 * @param column number of column in table
1038 * @returns TRUE on success, FALSE otherwise
1041 eail_gengrid_add_column_selection(AtkTable *table, gint column)
1043 Evas_Object *widget;
1046 g_return_val_if_fail(EAIL_IS_GENGRID(table), FALSE);
1047 widget = eail_widget_get_widget(EAIL_WIDGET(table));
1048 if (!widget) return FALSE;
1049 if (!elm_gengrid_multi_select_get(widget)) return FALSE;
1050 n_columns = eail_gengrid_n_columns_get(table);
1051 if (column > n_columns) return FALSE;
1053 _set_column_selection(table, column, EINA_TRUE);
1058 * @brief Removes the specified column from the selection
1060 * Implementation of remove_column_selection from AtkTable.
1062 * @param table AtkTable instance
1063 * @param column column number in table
1065 * @returns TRUE on success, FALSE otherwise
1068 eail_gengrid_remove_column_selection(AtkTable *table, gint column)
1070 Evas_Object *widget;
1073 g_return_val_if_fail(EAIL_IS_GENGRID(table), FALSE);
1074 widget = eail_widget_get_widget(EAIL_WIDGET(table));
1075 if (!widget) return FALSE;
1076 if (!elm_gengrid_multi_select_get(widget)) return FALSE;
1077 n_columns = eail_gengrid_n_columns_get(table);
1078 if (column > n_columns) return FALSE;
1080 _set_column_selection(table, column, EINA_FALSE);
1086 * @brief AtkTable interface initialization
1088 * @param iface AtkTableIface instance
1091 atk_table_interface_init(AtkTableIface *iface)
1095 iface->ref_at = eail_gengrid_ref_at;
1096 iface->get_n_rows = eail_gengrid_n_rows_get;
1097 iface->get_n_columns = eail_gengrid_n_columns_get;
1098 iface->get_index_at = eail_gengrid_index_at_get;
1099 iface->get_column_at_index = eail_gengrid_column_at_index_get;
1100 iface->get_row_at_index = eail_gengrid_row_at_index_get;
1101 iface->is_row_selected = eail_gengrid_is_row_selected;
1102 iface->is_selected = eail_gengrid_is_selected;
1103 iface->get_selected_rows = eail_gengrid_selected_rows_get;
1104 iface->add_row_selection = eail_gengrid_add_row_selection;
1105 iface->remove_row_selection = eail_gengrid_remove_row_selection;
1106 iface->is_column_selected = eail_gengrid_is_column_selected;
1107 iface->get_selected_columns = eail_gengrid_selected_columns_get;
1108 iface->add_column_selection = eail_gengrid_add_column_selection;
1109 iface->remove_column_selection = eail_gengrid_remove_column_selection;
1112 iface->get_column_extent_at = NULL;
1113 iface->get_row_extent_at = NULL;
1114 iface->get_column_header = NULL;
1115 iface->get_column_description = NULL;
1119 * @brief Adds the specified accessible child of the object to the object's selection
1121 * Implementation of add_selection from AtkSelection interface.
1123 * @param selection AtkSelection instance
1124 * @param i index of child to select
1126 * @returns TRUE on success, FALSE otherwise
1129 eail_gengrid_selection_add(AtkSelection *selection, gint i)
1131 Evas_Object *widget;
1132 Elm_Object_Item *it;
1136 g_return_val_if_fail(EAIL_IS_GENGRID(selection), FALSE);
1137 widget = eail_widget_get_widget(EAIL_WIDGET(selection));
1138 list = elm_gengrid_realized_items_get(widget);
1140 if (i > eina_list_count(list)) return FALSE;
1141 it = eina_list_nth(list, i);
1143 if (elm_gengrid_item_selected_get(it))
1147 elm_gengrid_item_selected_set(it, EINA_TRUE);
1151 eina_list_free(list);
1156 * @brief Clears the selection in the object so that no children in the object are selected
1158 * Implementation of clear_selection from AtkSelection.
1160 * @param selection AtkSelection instance
1162 * @returns TRUE on success, FALSE otherwise
1165 eail_gengrid_selection_clear(AtkSelection *selection)
1167 const Eina_List *l, *list;
1168 Evas_Object *widget;
1169 Elm_Object_Item *it;
1171 g_return_val_if_fail(EAIL_IS_GENGRID(selection), FALSE);
1172 widget = eail_widget_get_widget(EAIL_WIDGET(selection));
1174 if (elm_gengrid_multi_select_get(widget))
1176 list = elm_gengrid_selected_items_get(widget);
1177 EINA_LIST_FOREACH(list, l, it)
1179 elm_gengrid_item_selected_set(it, EINA_FALSE);
1184 it = elm_gengrid_selected_item_get(widget);
1185 elm_gengrid_item_selected_set(it, EINA_FALSE);
1193 * @brief Gets a reference to the accessible object representing the specified
1194 * selected child of the object
1196 * Note: callers should not rely on NULL
1197 * or on a zero value for indication of whether AtkSelectionIface is
1198 * implemented, they should use type checking/interface checking macros
1199 * or the atk_get_accessible_value() convenience method.
1201 * Implementation of ref_selection from AtkSelection interface.
1203 * @param selection AtkSelection instance
1204 * @param i index of selected child
1206 * @returns AtkObject representing the selected object
1209 eail_gengrid_selection_ref(AtkSelection *selection, gint i)
1211 Evas_Object *widget;
1212 Elm_Object_Item *it;
1213 const Eina_List *list;
1214 Eina_Bool multiselect;
1217 g_return_val_if_fail(EAIL_IS_GENGRID(selection), NULL);
1218 widget = eail_widget_get_widget(EAIL_WIDGET(selection));
1219 multiselect = elm_gengrid_multi_select_get(widget);
1221 if ((!multiselect) && (i != 0)) return FALSE;
1225 list = elm_gengrid_selected_items_get(widget);
1226 if (i > eina_list_count(list)) return NULL;
1227 it = eina_list_nth(list, i);
1231 it = elm_gengrid_selected_item_get(widget);
1234 if (!it) return NULL;
1236 child = eail_factory_get_item_atk_obj
1237 (it, ATK_ROLE_LIST_ITEM, ATK_OBJECT(selection));
1239 g_object_ref(child);
1245 * @brief Gets the number of accessible children currently selected.
1247 * Note: callers should not rely on NULL or on a zero value
1248 * for indication of whether AtkSelectionIface is implemented,
1249 * they should use type checking/interface checking macros or
1250 * the atk_get_accessible_value() convenience method.
1252 * Implementation of get_selection_count from AtkSelection interface.
1254 * @param selection AtkSelection instance
1256 * @returns integer representing the number of selected items
1259 eail_gengrid_selection_count_get(AtkSelection *selection)
1261 Evas_Object *widget;
1262 Elm_Object_Item *it;
1263 const Eina_List *list;
1266 g_return_val_if_fail(EAIL_IS_GENGRID(selection), -1);
1267 widget = eail_widget_get_widget(EAIL_WIDGET(selection));
1268 if (!elm_gengrid_multi_select_get(widget))
1270 it = elm_gengrid_selected_item_get(widget);
1271 n_selections = (it ? 1 : 0);
1275 list = elm_gengrid_selected_items_get(widget);
1276 n_selections = eina_list_count(list);
1279 return n_selections;
1283 * @brief Determines if the current child of this object is selected.
1285 * Note: callers should not rely on NULL or on a zero value for
1286 * indication of whether AtkSelectionIface is implemented, they
1287 * should use type checking/interface checking macros or
1288 * the atk_get_accessible_value() convenience method.
1290 * Implementation of is_child_selected from AtkSelection interface.
1292 * @param selection AtkSelection instance
1293 * @param i index of child
1295 * @returns TRUE on selection, FALSE otherwise
1298 eail_gengrid_selection_is_child_selected(AtkSelection *selection, int i)
1300 Evas_Object *widget;
1301 Elm_Object_Item *it;
1305 g_return_val_if_fail(EAIL_IS_GENGRID(selection), FALSE);
1306 widget = eail_widget_get_widget(EAIL_WIDGET(selection));
1307 list = elm_gengrid_realized_items_get(widget);
1309 if (i > eina_list_count(list))
1311 eina_list_free(list);
1315 it = eina_list_nth(list, i);
1316 selected = (elm_gengrid_item_selected_get(it) ? TRUE : FALSE);
1317 eina_list_free(list);
1323 * @brief Removes the specified child of the object from the object's selection
1325 * Implementation of remove_selection from AtkSelection.
1327 * @param selection AtkSelection instance
1328 * @param i index of selected child
1330 * @returns TRUE on success, FALSE otherwise
1333 eail_gengrid_selection_remove(AtkSelection *selection, gint i)
1335 Evas_Object *widget;
1336 Elm_Object_Item *it;
1337 const Eina_List *list;
1338 Eina_Bool multiselect;
1340 g_return_val_if_fail(EAIL_IS_GENGRID(selection), FALSE);
1341 widget = eail_widget_get_widget(EAIL_WIDGET(selection));
1342 multiselect = elm_gengrid_multi_select_get(widget);
1343 if ((!multiselect) && (i != 0)) return FALSE;
1347 it = elm_gengrid_selected_item_get(widget);
1348 elm_gengrid_item_selected_set(it, FALSE);
1352 list = elm_gengrid_selected_items_get(widget);
1353 if (i > eina_list_count(list)) return FALSE;
1355 it = eina_list_nth(list, i);
1356 elm_gengrid_item_selected_set(it, EINA_FALSE);
1363 * @brief Causes every child of the object to be selected if the object supports multiple selections
1365 * Implementation of select_all from AtkSelection interface.
1367 * @param selection AtkSelection instance
1369 * @return TRUE on success, FALSE otherwise
1372 eail_gengrid_selection_select_all(AtkSelection *selection)
1374 Evas_Object *widget;
1375 Elm_Object_Item *it;
1376 Eina_List *l, *list;
1378 g_return_val_if_fail(EAIL_IS_GENGRID(selection), FALSE);
1379 widget = eail_widget_get_widget(EAIL_WIDGET(selection));
1380 if (!elm_gengrid_multi_select_get(widget)) return FALSE;
1382 list = elm_gengrid_realized_items_get(widget);
1383 EINA_LIST_FOREACH(list, l, it)
1385 elm_gengrid_item_selected_set(it, EINA_TRUE);
1391 * @brief AtkSelection interface initialization
1393 * @param iface AtkSelectionIface instance
1396 atk_selection_interface_init(AtkSelectionIface *iface)
1398 g_return_if_fail(iface != NULL);
1400 iface->add_selection = eail_gengrid_selection_add;
1401 iface->clear_selection = eail_gengrid_selection_clear;
1402 iface->ref_selection = eail_gengrid_selection_ref;
1403 iface->get_selection_count = eail_gengrid_selection_count_get;
1404 iface->is_child_selected = eail_gengrid_selection_is_child_selected;
1405 iface->remove_selection = eail_gengrid_selection_remove;
1406 iface->select_all_selection = eail_gengrid_selection_select_all;