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 const gchar *atk_name = NULL;
107 g_return_val_if_fail(EAIL_IS_NAVIFRAME_PAGE(obj), NULL);
109 /* returning name from ATK default implementation if available */
110 atk_name = ATK_OBJECT_CLASS(eail_naviframe_page_parent_class)->get_name(obj);
111 if (atk_name) return atk_name;
113 EailNaviframePage *page = EAIL_NAVIFRAME_PAGE(obj);
114 if (page->name != NULL) return page->name;
116 const char *title = elm_object_item_part_text_get(page->page, "default");
117 const char *subtitle = elm_object_item_part_text_get(page->page, "subtitle");
119 if (subtitle != NULL)
120 page->name = eina_stringshare_printf("%s, %s", title, subtitle);
122 page->name = eina_stringshare_add(title);
128 * @brief Initiates EailNaviframePage
130 * @param naviframe_page EailNaviframePage instance
133 eail_naviframe_page_init(EailNaviframePage *naviframe_page)
138 * @brief Initializes EailNaviframPage
140 * @param obj AtkObject instance
141 * @param data user data
144 eail_naviframe_page_initialize(AtkObject *obj, gpointer data)
146 ATK_OBJECT_CLASS(eail_naviframe_page_parent_class)->initialize(obj, data);
148 obj->role = ATK_ROLE_PAGE_TAB;
149 obj->layer = ATK_LAYER_WIDGET;
153 * @brief Finalizes object
155 * @param obj AtkObject instance
158 eail_naviframe_page_finalize(GObject *obj)
160 EailNaviframePage *page = EAIL_NAVIFRAME_PAGE(obj);
162 eina_stringshare_del(page->name);
165 eail_factory_unregister_item_from_cache(page->page);
167 G_OBJECT_CLASS(eail_naviframe_page_parent_class)->finalize(obj);
171 * @brief Gets the number of accessible children of obj
173 * @param obj AtkObject instance
175 * @returns integer representing the number of children
178 eail_naviframe_page_n_children_get(AtkObject *obj)
180 EailNaviframePage *page;
182 g_return_val_if_fail(EAIL_IS_NAVIFRAME_PAGE(obj), 0);
183 page = EAIL_NAVIFRAME_PAGE(obj);
185 return page->child_count;
189 * @brief Gets obj's parent
191 * @param obj AtkObject instance
193 * @returns AtkObject representing the parent of obj
196 eail_naviframe_page_parent_get(AtkObject *obj)
198 EailNaviframePage *page;
200 g_return_val_if_fail(EAIL_IS_NAVIFRAME_PAGE(obj), NULL);
202 page = EAIL_NAVIFRAME_PAGE(obj);
204 return ATK_OBJECT(page->parent_naviframe);
208 * @brief Gets a reference to the specified child of obj
210 * @param obj AtkObject instance
211 * @param i child index
213 * @returns AtkObject representing the specified child
216 eail_naviframe_page_ref_child(AtkObject *obj, gint i)
218 EailNaviframePage *page;
219 AtkObject *atk_obj_child = NULL;
221 g_return_val_if_fail(EAIL_IS_NAVIFRAME_PAGE(obj), NULL);
223 page = EAIL_NAVIFRAME_PAGE(obj);
224 if (i >= page->child_count) return NULL;
226 atk_obj_child = eail_factory_get_accessible(page->content[i]);
228 g_object_ref(atk_obj_child);
229 return atk_obj_child;
233 * @brief Gets the index of obj in parent object
235 * @param obj AtkObject instance
237 * @returns integer representing the index of object
240 eail_naviframe_page_index_in_parent_get(AtkObject *obj)
242 EailNaviframePage *page = NULL;
243 Eina_List *list = NULL;
244 gint pos = -1, i = 0;
246 if (!EAIL_IS_NAVIFRAME_PAGE(obj))
248 ERR("Not a naviframe page");
252 page = EAIL_NAVIFRAME_PAGE(obj);
253 if (!page->naviframe) return pos;
255 list = elm_naviframe_items_get(page->naviframe);
256 for (i = 0; i < eina_list_count(list); ++i)
258 if (page->page == eina_list_nth(list, i))
265 eina_list_free(list);
270 * @brief Gets the state set of the accessible object
272 * @param obj AtkObject instance
274 * @returns AtkStateSet representing the state set of the accessible object
277 eail_naviframe_page_ref_state_set(AtkObject *obj)
279 EailNaviframePage *page;
280 AtkStateSet *state_set;
283 g_return_val_if_fail(EAIL_IS_NAVIFRAME_PAGE(obj), NULL);
285 page = EAIL_NAVIFRAME_PAGE(obj);
286 if (!page->naviframe) return NULL;
288 widget = elm_object_part_content_get(page->naviframe, "default");
290 state_set = atk_state_set_new();
292 /* only item-page on top is visible*/
293 if (elm_naviframe_top_item_get(page->naviframe) == page->page)
295 atk_state_set_add_state(state_set, ATK_STATE_SHOWING);
296 atk_state_set_add_state(state_set, ATK_STATE_VISIBLE);
299 if (!elm_object_disabled_get(widget))
300 atk_state_set_add_state(state_set, ATK_STATE_ENABLED);
306 * @brief EailNaviframePage class initializer
308 * @param klass EailNaviframePageClass instance
311 eail_naviframe_page_class_init(EailNaviframePageClass *klass)
313 GObjectClass *g_object_class = G_OBJECT_CLASS(klass);
314 AtkObjectClass *atk_class = ATK_OBJECT_CLASS(klass);
316 atk_class->initialize = eail_naviframe_page_initialize;
317 atk_class->get_name = eail_naviframe_page_name_get;
318 atk_class->get_parent = eail_naviframe_page_parent_get;
319 atk_class->get_n_children = eail_naviframe_page_n_children_get;
320 atk_class->ref_child = eail_naviframe_page_ref_child;
321 atk_class->ref_state_set = eail_naviframe_page_ref_state_set;
322 atk_class->get_index_in_parent = eail_naviframe_page_index_in_parent_get;
324 g_object_class->finalize = eail_naviframe_page_finalize;
328 * @brief Gets the rectangle which gives the extent of the component
330 * Implementation of get_extents from AtkComponent interface.
332 * @param component AtkComponent instance
333 * @param [out] x x coordinate
334 * @param [out] y y coordinate
335 * @param [out] width width of the rectangle
336 * @param [out] height height of the rectangle
337 * @param coord_type specifies whether the coordinates are relative to the screen or to the component's top level window
340 eail_naviframe_page_get_extents(AtkComponent *component,
345 AtkCoordType coord_type)
347 EailNaviframePage *page;
349 g_return_if_fail(EAIL_IS_NAVIFRAME_PAGE(component));
351 page = EAIL_NAVIFRAME_PAGE(component);
352 *x = *y = *width = *height = G_MININT;
353 if (!page->naviframe) return;
355 widget = page->naviframe;
357 evas_object_geometry_get(widget, x, y, width, height);
358 if (coord_type == ATK_XY_SCREEN)
362 Ecore_Evas *ee = ecore_evas_ecore_evas_get(
363 evas_object_evas_get(widget));
364 ecore_evas_geometry_get(ee, &ee_x, &ee_y, NULL, NULL);
371 * @brief AtkComponent interface initialization
373 * @param iface AtkComponentIface instance
375 static void atk_component_interface_init(AtkComponentIface *iface)
377 g_return_if_fail(iface != NULL);
379 iface->get_extents = eail_naviframe_page_get_extents;