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_naviframe_page.c
22 * @brief EailNaviframePage implementation
25 #include "eail_naviframe_page.h"
26 #include "eail_naviframe.h"
27 #include "eail_factory.h"
28 #include "eail_widget.h"
29 #include "eail_priv.h"
31 static void atk_component_interface_init(AtkComponentIface *iface);
34 * Defines EailNaviframePage type
36 G_DEFINE_TYPE_WITH_CODE(EailNaviframePage,
39 G_IMPLEMENT_INTERFACE(ATK_TYPE_COMPONENT,
40 atk_component_interface_init));
43 * @brief Creates a new instance of an accessible naviframe page
45 * @param naviframe AtkObject instance
46 * @param navi_tab_item Elm_Object_Item instance
47 * @returns AtkObject representing the accessible naviframe page
50 eail_naviframe_page_new(AtkObject *naviframe, Elm_Object_Item *navi_tab_item)
52 AtkObject *atk_object;
53 EailNaviframePage *page;
54 Evas_Object *o, *widget;
56 g_return_val_if_fail(EAIL_IS_NAVIFRAME(naviframe), NULL);
58 widget = eail_widget_get_widget(EAIL_WIDGET(naviframe));
60 g_return_val_if_fail(widget != NULL, NULL);
62 atk_object = g_object_new(EAIL_TYPE_NAVIFRAME_PAGE, NULL);
63 page = EAIL_NAVIFRAME_PAGE(atk_object);
65 page->naviframe = widget;
67 page->page = navi_tab_item;
69 page->child_count = 0;
71 o = elm_object_item_part_content_get(page->page, "prev_btn");
72 if (o && elm_object_widget_check(o))
73 page->content[page->child_count++] = o;
75 o = elm_object_item_part_content_get(page->page, "icon");
76 if (o && elm_object_widget_check(o))
77 page->content[page->child_count++] = o;
79 o = elm_object_item_part_content_get(page->page, "next_btn");
80 if (o && elm_object_widget_check(o))
81 page->content[page->child_count++] = o;
83 o = elm_object_item_part_content_get(page->page, "default");
84 if (o && elm_object_widget_check(o))
85 page->content[page->child_count++] = o;
87 page->parent_naviframe = naviframe;
89 atk_object->layer = ATK_LAYER_WIDGET;
95 * @brief Returns the accessible name if assigned, title or subtitle otherwise
97 * Implementation of atk_object_get_name from AtkObject.
99 * @param obj AtkObject instance
100 * @returns string representing the accessible name if assigned, title or subtitle otherwise
103 eail_naviframe_page_name_get(AtkObject *obj)
105 g_return_val_if_fail(EAIL_IS_NAVIFRAME_PAGE(obj), NULL);
107 EailNaviframePage *page = EAIL_NAVIFRAME_PAGE(obj);
108 if (page->name != NULL) return page->name;
110 const char *title = elm_object_item_part_text_get(page->page, "default");
111 const char *subtitle = elm_object_item_part_text_get(page->page, "subtitle");
113 if (subtitle != NULL)
114 page->name = eina_stringshare_printf("%s\n%s", title, subtitle);
116 page->name = eina_stringshare_add(title);
122 * @brief Initiates EailNaviframePage
124 * @param naviframe_page EailNaviframePage instance
127 eail_naviframe_page_init(EailNaviframePage *naviframe_page)
132 * @brief Initializes EailNaviframPage
134 * @param obj AtkObject instance
135 * @param data user data
138 eail_naviframe_page_initialize(AtkObject *obj, gpointer data)
140 ATK_OBJECT_CLASS(eail_naviframe_page_parent_class)->initialize(obj, data);
142 obj->role = ATK_ROLE_PAGE_TAB;
143 obj->layer = ATK_LAYER_WIDGET;
147 * @brief Finalizes object
149 * @param obj AtkObject instance
152 eail_naviframe_page_finalize(GObject *obj)
154 EailNaviframePage *page = EAIL_NAVIFRAME_PAGE(obj);
156 eina_stringshare_del(page->name);
159 eail_factory_unregister_item_from_cache(page->page);
161 G_OBJECT_CLASS(eail_naviframe_page_parent_class)->finalize(obj);
165 * @brief Gets the number of accessible children of obj
167 * @param obj AtkObject instance
169 * @returns integer representing the number of children
172 eail_naviframe_page_n_children_get(AtkObject *obj)
174 EailNaviframePage *page;
176 g_return_val_if_fail(EAIL_IS_NAVIFRAME_PAGE(obj), 0);
177 page = EAIL_NAVIFRAME_PAGE(obj);
179 return page->child_count;
183 * @brief Gets obj's parent
185 * @param obj AtkObject instance
187 * @returns AtkObject representing the parent of obj
190 eail_naviframe_page_parent_get(AtkObject *obj)
192 EailNaviframePage *page;
194 g_return_val_if_fail(EAIL_IS_NAVIFRAME_PAGE(obj), NULL);
196 page = EAIL_NAVIFRAME_PAGE(obj);
198 return ATK_OBJECT(page->parent_naviframe);
202 * @brief Gets a reference to the specified child of obj
204 * @param obj AtkObject instance
205 * @param i child index
207 * @returns AtkObject representing the specified child
210 eail_naviframe_page_ref_child(AtkObject *obj, gint i)
212 EailNaviframePage *page;
213 AtkObject *atk_obj_child = NULL;
215 g_return_val_if_fail(EAIL_IS_NAVIFRAME_PAGE(obj), NULL);
217 page = EAIL_NAVIFRAME_PAGE(obj);
218 if (i >= page->child_count) return NULL;
220 atk_obj_child = eail_factory_get_accessible(page->content[i]);
222 g_object_ref(atk_obj_child);
223 return atk_obj_child;
227 * @brief Gets the index of obj in parent object
229 * @param obj AtkObject instance
231 * @returns integer representing the index of object
234 eail_naviframe_page_index_in_parent_get(AtkObject *obj)
236 EailNaviframePage *page = NULL;
237 Eina_List *list = NULL;
238 gint pos = -1, i = 0;
240 if (!EAIL_IS_NAVIFRAME_PAGE(obj))
242 ERR("Not a naviframe page");
246 page = EAIL_NAVIFRAME_PAGE(obj);
247 if (!page->naviframe) return pos;
249 list = elm_naviframe_items_get(page->naviframe);
250 for (i = 0; i < eina_list_count(list); ++i)
252 if (page->page == eina_list_nth(list, i))
259 eina_list_free(list);
264 * @brief Gets the state set of the accessible object
266 * @param obj AtkObject instance
268 * @returns AtkStateSet representing the state set of the accessible object
271 eail_naviframe_page_ref_state_set(AtkObject *obj)
273 EailNaviframePage *page;
274 AtkStateSet *state_set;
277 g_return_val_if_fail(EAIL_IS_NAVIFRAME_PAGE(obj), NULL);
279 page = EAIL_NAVIFRAME_PAGE(obj);
280 if (!page->naviframe) return NULL;
282 widget = elm_object_part_content_get(page->naviframe, "default");
284 state_set = atk_state_set_new();
286 /* only item-page on top is visible*/
287 if (elm_naviframe_top_item_get(page->naviframe) == page->page)
289 atk_state_set_add_state(state_set, ATK_STATE_SHOWING);
290 atk_state_set_add_state(state_set, ATK_STATE_VISIBLE);
293 if (!elm_object_disabled_get(widget))
294 atk_state_set_add_state(state_set, ATK_STATE_ENABLED);
300 * @brief EailNaviframePage class initializer
302 * @param klass EailNaviframePageClass instance
305 eail_naviframe_page_class_init(EailNaviframePageClass *klass)
307 GObjectClass *g_object_class = G_OBJECT_CLASS(klass);
308 AtkObjectClass *atk_class = ATK_OBJECT_CLASS(klass);
310 atk_class->initialize = eail_naviframe_page_initialize;
311 atk_class->get_name = eail_naviframe_page_name_get;
312 atk_class->get_parent = eail_naviframe_page_parent_get;
313 atk_class->get_n_children = eail_naviframe_page_n_children_get;
314 atk_class->ref_child = eail_naviframe_page_ref_child;
315 atk_class->ref_state_set = eail_naviframe_page_ref_state_set;
316 atk_class->get_index_in_parent = eail_naviframe_page_index_in_parent_get;
318 g_object_class->finalize = eail_naviframe_page_finalize;
322 * @brief Gets the rectangle which gives the extent of the component
324 * Implementation of get_extents from AtkComponent interface.
326 * @param component AtkComponent instance
327 * @param [out] x x coordinate
328 * @param [out] y y coordinate
329 * @param [out] width width of the rectangle
330 * @param [out] height height of the rectangle
331 * @param coord_type specifies whether the coordinates are relative to the screen or to the component's top level window
334 eail_naviframe_page_get_extents(AtkComponent *component,
339 AtkCoordType coord_type)
341 EailNaviframePage *page;
343 g_return_if_fail(EAIL_IS_NAVIFRAME_PAGE(component));
345 page = EAIL_NAVIFRAME_PAGE(component);
346 *x = *y = *width = *height = G_MININT;
347 if (!page->naviframe) return;
349 widget = page->naviframe;
351 evas_object_geometry_get(widget, x, y, width, height);
352 if (coord_type == ATK_XY_SCREEN)
356 Ecore_Evas *ee = ecore_evas_ecore_evas_get(
357 evas_object_evas_get(widget));
358 ecore_evas_geometry_get(ee, &ee_x, &ee_y, NULL, NULL);
365 * @brief AtkComponent interface initialization
367 * @param iface AtkComponentIface instance
369 static void atk_component_interface_init(AtkComponentIface *iface)
371 g_return_if_fail(iface != NULL);
373 iface->get_extents = eail_naviframe_page_get_extents;