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_toolbar.c
22 * @brief EailToolbar implementation
26 #include <Elementary.h>
28 #include "eail_toolbar.h"
29 #include "eail_factory.h"
30 #include "eail_item_parent.h"
31 #include "eail_priv.h"
33 static void eail_item_parent_interface_init(EailItemParentIface *iface);
36 * @brief Definition of EailToolbar as GObject
38 * EailToolbar is extended EAIL_TYPE_WIDGET with EAIL_TYPE_ITEM_PARENT interface
41 G_DEFINE_TYPE_WITH_CODE(EailToolbar, eail_toolbar, EAIL_TYPE_WIDGET,
42 G_IMPLEMENT_INTERFACE(EAIL_TYPE_ITEM_PARENT,
43 eail_item_parent_interface_init)
47 * @brief Implementation of the *AtkObject* interface
49 * Basic initialization for AtkObject (parent initialization, role definition
52 * @param obj AtkObject instance
53 * @param data additional data passed to initialization
56 eail_toolbar_initialize(AtkObject *obj, gpointer data)
58 ATK_OBJECT_CLASS(eail_toolbar_parent_class) ->initialize(obj, data);
59 obj->role = ATK_ROLE_TOOL_BAR;
63 * @brief EailToolbar instance initializer
65 * @param toolbar EailToolbar instance
68 eail_toolbar_init(EailToolbar *toolbar)
74 * @brief Gets toolbar items
76 * @param toolbar EailToolbar instance
77 * @return Eina_List representing the list of Elm_Object_Item objects
80 eail_toolbar_get_items(EailToolbar *toolbar)
82 Eina_List *items = NULL;
83 Elm_Object_Item *item;
84 Evas_Object *widget = eail_widget_get_widget(EAIL_WIDGET(toolbar));
86 item = elm_toolbar_first_item_get(widget);
89 items = eina_list_append(items, item);
90 item = elm_toolbar_item_next_get(item);
97 * @brief Gets the number of accessible children of the accessible
99 * Implementation of AtkObject->get_n_children callback.
101 * @param obj AtkObject instance
103 * @returns integer representing the number of accessible children of
107 eail_toolbar_get_n_children(AtkObject *obj)
112 items = eail_toolbar_get_items(EAIL_TOOLBAR(obj));
113 n_items = eina_list_count(items);
115 eina_list_free(items);
121 * @brief Gets a reference to the specified accessible child of the object.
123 * The accessible children are 0-based so the first accessible child is at index 0,
124 * the second at index 1 and so on.
126 * Implementation of AtkObject->ref_child callback.
128 * @param obj AtkObject instance
129 * @param i index of a child
131 * @returns AtkObject representing the specified accessible child of the
135 eail_toolbar_ref_child(AtkObject *obj, gint i)
138 AtkObject *child = NULL;
140 items = eail_toolbar_get_items(EAIL_TOOLBAR(obj) );
141 if (eina_list_count(items) > i)
143 child = eail_factory_get_item_atk_obj
144 (eina_list_nth(items, i), ATK_ROLE_MENU_ITEM, obj);
149 ERR("Tried to ref child with index %d out of bounds!", i);
151 eina_list_free(items);
157 * @brief Destructor for EailToolbar object
159 * @param object GObject corresponding to EailToolbar
162 eail_toolbar_finalize(GObject *object)
164 G_OBJECT_CLASS(eail_toolbar_parent_class)->finalize(object);
168 * @brief Initializer for EailToolbar GObject class
170 * Defines callbacks for base AtkObject.
172 * @param klass EailToolbarClass instance
175 eail_toolbar_class_init(EailToolbarClass *klass)
177 AtkObjectClass *class = ATK_OBJECT_CLASS(klass);
178 GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
179 class->initialize = eail_toolbar_initialize;
180 class->get_n_children = eail_toolbar_get_n_children;
181 class->ref_child = eail_toolbar_ref_child;
182 gobject_class->finalize = eail_toolbar_finalize;
186 * @brief Gets the object of item
188 * @param parent EailItemParent instance
189 * @param item EailItem instance
190 * @returns Evas_Object representing the item
193 eail_toolbar_get_evas_obj(EailItemParent *parent,
196 Elm_Object_Item *it = eail_item_get_item(item);
200 ERR("Error. Could not get Elm_Object_item from EailItem");
204 return elm_toolbar_item_object_get(it);
208 * @brief Gets supported actions
210 * Implementation of EailItemParent->get_actions_supported callback.
212 * @param parent EailItemParent instance
213 * @param item EailItem instance
214 * @returns integer representing supported actions
217 eail_toolbar_get_actions_supported(EailItemParent *parent,
220 return EAIL_ACTION_SUPPORTED_CLICK;
224 * @brief Gets the accessible name of the item
226 * @param parent EailItemParent instance
227 * @param item EailItem instance
229 * @returns string representing the accessible name of the item
232 eail_toolbar_item_name_get(EailItemParent *parent, EailItem *item)
234 Elm_Object_Item *it = eail_item_get_item(item);
235 if (!it) return NULL;
237 return elm_object_item_part_text_get(it, NULL);
241 * @brief Gets index in parent
243 * @param parent EailItemParent instance
244 * @param item EailItem child instance
246 * @returns int representing the index in parent
249 eail_toolbar_get_item_index_in_parent(EailItemParent *parent, EailItem *item)
251 Elm_Object_Item *it = eail_item_get_item(item);
258 items = eail_toolbar_get_items(EAIL_TOOLBAR(ATK_OBJECT(parent)));
259 for (i=0; i<eina_list_count(items); ++i)
261 if (eina_list_nth(items, i) == it)
268 eina_list_free(items);
273 * @brief Initialization of EailItemParentIface interface callbacks
275 * Function called upon instance creation. It initializes EailItemParent
276 * interface implementation i.e hooks method pointers in the interface structure
277 * to the implementing class's implementation.
279 * @param iface EailItemParent interface
282 eail_item_parent_interface_init(EailItemParentIface *iface)
284 iface->get_item_name = eail_toolbar_item_name_get;
285 iface->get_evas_obj = eail_toolbar_get_evas_obj;
286 iface->get_actions_supported = eail_toolbar_get_actions_supported;
287 iface->get_item_index_in_parent = eail_toolbar_get_item_index_in_parent;