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 EailMenu implementation
25 #include <Elementary.h>
27 #include "eail_menu.h"
28 #include "eail_item_parent.h"
29 #include "eail_factory.h"
30 #include "eail_priv.h"
32 static void eail_item_parent_interface_init(EailItemParentIface *iface);
35 * @brief Definition of EailMenu as GObject
37 * EailList is extended Widget with EAIL_TYPE_ITEM_PARENT implemented
39 G_DEFINE_TYPE_WITH_CODE(EailMenu,
42 G_IMPLEMENT_INTERFACE(EAIL_TYPE_ITEM_PARENT,
43 eail_item_parent_interface_init));
46 * Implementation of the *AtkObject* interface
50 * @brief Initializer for AtkObjectClass
53 eail_menu_initialize(AtkObject *obj, gpointer data)
55 ATK_OBJECT_CLASS(eail_menu_parent_class)->initialize(obj, data);
57 obj->role = ATK_ROLE_MENU;
61 * @brief Prepares Eina_List filled with Elm_Object_Item* objects
62 * representing items in menu
64 * Call eina_list_free on the returned list when results processing has been finished.
66 * @param list EailMenu instance
68 * @return Eina_List representing the list of list's items
71 eail_menu_get_items(EailMenu *list)
73 Eina_List *items = NULL;
74 Elm_Object_Item *item;
75 Evas_Object *widget = eail_widget_get_widget(EAIL_WIDGET(list));
77 item = elm_menu_first_item_get(widget);
80 items = eina_list_append(items, item);
81 item = elm_menu_item_next_get(item);
88 * @brief Gets the number of accessible children of the accessible
90 * Implementation of AtkObject->get_n_children callback.
92 * @param obj AtkObject instance
94 * @returns integer representing the number of accessible children of
98 eail_menu_get_n_children(AtkObject *obj)
103 items = eail_menu_get_items(EAIL_MENU(obj));
104 n_items = eina_list_count(items);
106 eina_list_free(items);
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_menu_ref_child(AtkObject *obj, gint i)
129 AtkObject *child = NULL;
131 items = eail_menu_get_items(EAIL_MENU(obj));
132 if (eina_list_count(items) > i)
134 child = eail_factory_get_item_atk_obj
135 (eina_list_nth(items, i), ATK_ROLE_MENU_ITEM, obj);
140 eina_list_free(items);
147 * @brief Gets the accessible name of the accessible
149 * Implementation of AtkObject->get_name callback.
151 * @param obj AtkObject instance
153 * @returns character string representing the accessible name of
157 eail_menu_get_name(AtkObject *obj)
159 AtkObject *parent = NULL;
160 const gchar *atk_name = NULL;
162 /* returning name from ATK default implementation if available */
163 atk_name = ATK_OBJECT_CLASS(eail_menu_parent_class)->get_name(obj);
167 parent = atk_object_get_parent(obj);
168 if (!parent) return NULL;
174 * @brief Initializer for GObject EailMenu instance
176 * @param menu EailMenu instance
179 eail_menu_init(EailMenu *menu)
184 * @brief Initializer for GObject class
186 * Defines callbacks for base AtkObject.
188 * @param klass EailMenuClass instance
191 eail_menu_class_init(EailMenuClass *klass)
193 AtkObjectClass *atk_class = ATK_OBJECT_CLASS(klass);
195 atk_class->initialize = eail_menu_initialize;
196 atk_class->get_n_children = eail_menu_get_n_children;
197 atk_class->ref_child = eail_menu_ref_child;
198 atk_class->get_name = eail_menu_get_name;
201 /* Child MenuItem handling - implementation of EailItemParent interface*/
204 * @brief Gets the name of a list's child
206 * @param parent EailItemParent instance
207 * @param item EailItem child instance
209 * @returns string representing the name of the child
212 eail_menu_item_name_get(EailItemParent *parent, EailItem *item)
214 Elm_Object_Item *it = eail_item_get_item(item);
215 if (!it) return NULL;
217 return elm_object_item_part_text_get(it, NULL);
221 * @brief Gets nested Evas_Object of given EailItem
223 * Implementation of EailItemParent->get_evas_obj callback.
225 * @param parent EailItemParent instance
226 * @param item EailItem instance
227 * @returns Evas_Object representing the menu item
230 eail_menu_item_get_evas_obj(EailItemParent *parent,
233 Elm_Object_Item *it = eail_item_get_item(item);
237 ERR("Error. Could not get Elm_Object_item from EailItem");
241 return elm_menu_item_object_get(it);
245 * @brief Gets supported actions
247 * Implementation of EailItemParent->get_actions_supported callback.
249 * @param parent EailItemParent instance
250 * @param item EailItem instance
251 * @returns integer representing supported actions
254 eail_menu_get_actions_supported(EailItemParent *parent,
257 return EAIL_ACTION_SUPPORTED_CLICK;
261 * @brief Prepares Eina_List filled with Elm_Object_Item* objects
262 * representing items in the list
264 * Call eina_list_free on the returned list when results processing has been finished.
266 * @param menu_item_obj child of menu widget
268 * @return Eina_List representing the list of menu items
270 static const Eina_List *
271 eail_menu_item_get_items(EailItem *menu_item_obj)
273 const Eina_List *items = NULL;
274 EailItem *eail_item = EAIL_ITEM(menu_item_obj);
275 Elm_Object_Item *it = eail_item_get_item(eail_item);
277 items = elm_menu_item_subitems_get(it);
283 * @brief Gets the number of accessible children of the accessible
285 * Implementation of AtkObject->get_n_children callback.
287 * @param parent EAIL representation of menu widget
288 * @param eail_item child of menu widget
290 * @returns integer representing the number of accessible children of
294 eail_menu_item_get_n_children(EailItemParent *parent, EailItem *eail_item)
297 const Eina_List *items;
298 Evas_Object *inside_widget = NULL;
300 items = eail_menu_item_get_items(eail_item);
301 n_items = eina_list_count(items);
303 /* increasing child items count for widgets that are stored inside
304 * menu item (eg. icon or button). They will be appended at the end
305 * of the children list in eail_menu_item_ref_child func*/
306 inside_widget = elm_object_item_content_get(eail_item_get_item(eail_item));
314 * @brief Creates content widgets from given menu_item AtkObject
316 * @param menu_item_obj AtkObject menu item
317 * @returns AtkObject representing the nested content of menu item
320 _eail_menu_item_create_content_atk_obj(AtkObject *menu_item_obj)
322 EailItem *eail_item = EAIL_ITEM(menu_item_obj);
323 Evas_Object *content_widget = NULL;
324 AtkObject *content_atk_obj = NULL;
326 content_widget = elm_object_item_content_get(eail_item_get_item(eail_item));
330 ERR("Content widget could not be found in menu_item.");
334 content_atk_obj = eail_factory_get_accessible(content_widget);
336 return content_atk_obj;
340 * @brief Gets a reference to the specified accessible child of the object.
342 * The accessible children are 0-based so the first accessible child is at index 0,
343 * the second at index 1 and so on.
345 * Implementation of AtkObject->ref_child callback.
347 * @param parent EailItemParent instance
348 * @param item EailItem instance
349 * @param i child index
351 * @returns AtkObject representing the specified accessible child of the
355 eail_menu_item_ref_child(EailItemParent *parent,
359 const Eina_List *items;
360 AtkObject *child = NULL;
361 Elm_Object_Item *elm_obj_item = NULL;
363 items = eail_menu_item_get_items(item);
364 if (eina_list_count(items) > i)
366 elm_obj_item = eina_list_nth(items, i);
368 /* creating new menu item from Elm_Object_Item */
369 child = eail_factory_get_item_atk_obj
370 (elm_obj_item, ATK_ROLE_MENU_ITEM, ATK_OBJECT(parent));
372 else if (eina_list_count(items) == i)
374 /* ref to widget inside menu item has to be referenced */
375 child = _eail_menu_item_create_content_atk_obj(ATK_OBJECT(item));
381 ERR("Could not ref menu item child for index %d", i);
387 * @brief Checks if content get is supported
389 * Implementation of EailItemParent->is_content_get_supported callback.
391 * @param parent EailItemParent instance
392 * @param item EailItem instance
393 * @returns always FALSE
396 eail_menu_item_content_get_support(EailItemParent *parent,
403 * @brief Gets index in parent
405 * @param parent EailItemParent instance
406 * @param item EailItem child instance
408 * @returns int representing the index in parent
411 eail_menu_get_item_index_in_parent(EailItemParent *parent, EailItem *item)
413 Elm_Object_Item *it = eail_item_get_item(item);
416 return elm_menu_item_index_get(it);
420 * @brief Initializes EailItemParentIface callbacks
422 * @param iface EailItemParentIface instance
425 eail_item_parent_interface_init(EailItemParentIface *iface)
427 iface->get_evas_obj = eail_menu_item_get_evas_obj;
428 iface->get_item_name = eail_menu_item_name_get;
429 iface->get_n_children = eail_menu_item_get_n_children;
430 iface->ref_n_child = eail_menu_item_ref_child;
431 iface->get_actions_supported = eail_menu_get_actions_supported;
432 iface->is_content_get_supported = eail_menu_item_content_get_support;
433 iface->get_item_index_in_parent = eail_menu_get_item_index_in_parent;