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_slideshow.c
22 * @brief EailSlideshow implementation
25 #include <Elementary.h>
27 #include "eail_slideshow.h"
28 #include "eail_factory.h"
29 #include "eail_priv.h"
32 * @brief Default timeout in seconds
34 #define SLIDESHOW_DEFAULT_TIMEOUT 3.0
36 static void atk_selection_interface_init(AtkSelectionIface *iface);
37 static void atk_action_interface_init(AtkActionIface *iface);
40 * @brief Define GObject type
42 G_DEFINE_TYPE_WITH_CODE(EailSlideshow, eail_slideshow, EAIL_TYPE_WIDGET,
43 G_IMPLEMENT_INTERFACE(ATK_TYPE_SELECTION,
44 atk_selection_interface_init)
45 G_IMPLEMENT_INTERFACE(ATK_TYPE_ACTION,
46 atk_action_interface_init));
49 * @brief Gets a reference to the specified accessible child of the object.
51 * The accessible children are 0-based so the first accessible child
52 * is at index 0, the second at index 1 and so on.
54 * Implementation of ref_child from AtkObject interface.
56 * @param obj AtkObject instance
57 * @param i index of a child object
59 * @returns AtkObject representing the specified accessible child
62 eail_slideshow_ref_child(AtkObject *obj, gint i)
64 Evas_Object *widget, *child_widget;
67 g_return_val_if_fail(EAIL_IS_SLIDESHOW(obj), NULL);
69 widget = eail_widget_get_widget(EAIL_WIDGET(obj));
70 if (!widget) return NULL;
72 it = elm_slideshow_item_nth_get(widget, i);
75 child_widget = elm_slideshow_item_object_get(it);
78 WRN("Given index %d is beyond realized (cached) views. Returning NULL",
83 return eail_factory_get_accessible(child_widget);
87 * @brief Gets the number of accessible children of the accessible
89 * Implementation of get_n_children from AtkObject interface.
91 * @param obj AtkObject instance
92 * @returns integer representing the number of widget's children
95 eail_slideshow_n_children_get(AtkObject *obj)
100 g_return_val_if_fail(EAIL_IS_SLIDESHOW(obj), 0);
102 widget = eail_widget_get_widget(EAIL_WIDGET(obj));
103 if (!widget) return 0;
104 /*the real number of items stored in slideshow widget is returned by
105 elm_slideshow_count_get. However we will not be able to return all items
106 widget since only those stored in cache are created.*/
107 items_count = elm_slideshow_count_get(widget);
112 * @brief Initialize EailSlideshow as AtkObject
114 * @param obj AtkObject instance
115 * @param data user data passed to initialization
118 eail_slideshow_initialize(AtkObject *obj, gpointer data)
120 ATK_OBJECT_CLASS(eail_slideshow_parent_class)->initialize(obj, data);
121 obj->role = ATK_ROLE_DOCUMENT_PRESENTATION;
125 * @brief EailSlideshow object initialization
127 * @param slideshow EailSlideshow instance
130 eail_slideshow_init(EailSlideshow *slideshow)
132 slideshow->next_description = NULL;
133 slideshow->previous_description = NULL;
134 slideshow->stop_description = NULL;
135 slideshow->start_description = NULL;
139 * @brief Destructor of EailSlideshow object
141 * @param object GObject instance
144 eail_slideshow_finalize(GObject *object)
146 EailSlideshow *slideshow = EAIL_SLIDESHOW(object);
147 if (slideshow->next_description) free(slideshow->next_description);
148 if (slideshow->previous_description) free(slideshow->previous_description);
149 if (slideshow->stop_description) free(slideshow->stop_description);
150 if (slideshow->start_description) free(slideshow->start_description);
152 G_OBJECT_CLASS(eail_slideshow_parent_class)->finalize(object);
157 * @brief EailSlideshow class initialization
159 * @param klass EailSlideshowClass instance
162 eail_slideshow_class_init(EailSlideshowClass *klass)
164 AtkObjectClass *atk_class = ATK_OBJECT_CLASS(klass);
165 GObjectClass *g_object_class = G_OBJECT_CLASS(klass);
167 atk_class->initialize = eail_slideshow_initialize;
168 atk_class->get_n_children = eail_slideshow_n_children_get;
169 atk_class->ref_child = eail_slideshow_ref_child;
171 g_object_class->finalize = eail_slideshow_finalize;
175 * @brief Gets the number of accessible children currently selected.
177 * Implementation of get_selection_count from AtkSelection interface.
179 * @param selection AtkSelection instance
181 * @returns integer representing the number of currently selected children
184 eail_slideshow_selection_count(AtkSelection *selection)
186 g_return_val_if_fail(EAIL_IS_SLIDESHOW(selection), 0);
192 * @brief Adds the specified accessible child of the object to the object's selection
194 * Implementation of add_selection from AtkSelection interface.
196 * @param selection AtkSelection instance
197 * @param i index of object to select
199 * @returns TRUE on success, FALSE otherwise
202 eail_slideshow_add_selection(AtkSelection *selection, gint i)
207 g_return_val_if_fail(EAIL_IS_SLIDESHOW(selection), FALSE);
209 widget = eail_widget_get_widget(EAIL_WIDGET(selection));
210 if (!widget) return FALSE;
212 it = elm_slideshow_item_nth_get(widget, i);
213 if (!it) return FALSE;
215 elm_slideshow_item_show(it);
221 * @brief Gets a reference to the accessible object representing
222 * the specified selected child of the object.
224 * Implementation of ref_selecton from AtkSelection.
226 * @param selection AtkSelection instance
227 * @param i index of selection
229 * @returns AtkObject representing the specified selected child
232 eail_slideshow_ref_selection(AtkSelection *selection, gint i)
234 Evas_Object *widget, *it_widget;
237 g_return_val_if_fail(EAIL_IS_SLIDESHOW(selection), NULL);
238 g_return_val_if_fail(i == 0, NULL);
240 widget = eail_widget_get_widget(EAIL_WIDGET(selection));
241 it = elm_slideshow_item_current_get(widget);
243 it_widget = elm_slideshow_item_object_get(it);
245 return eail_factory_get_accessible(it_widget);
249 * @brief Determines if the current child of this object is selected.
251 * Implementation of is_child_selected from AtkSelection.
253 * @param selection AtkSelection instance
254 * @param i index of selection
256 * @return TRUE if object is selected, FALSE otherwise
259 eail_slideshow_is_child_selected(AtkSelection *selection, gint i)
262 Elm_Object_Item *it, *current;
264 g_return_val_if_fail(EAIL_IS_SLIDESHOW(selection), FALSE);
266 widget = eail_widget_get_widget(EAIL_WIDGET(selection));
267 if (!widget) return FALSE;
269 current = elm_slideshow_item_current_get(widget);
270 it = elm_slideshow_item_nth_get(widget, i);
272 return (it == current);
276 * @brief Initialization of AtkSelection interface
278 * Function called upon instance creation. It initializes AtkValue interface
279 * implementation i.e hooks method pointers in the interface structure
280 * to the implementing class's implementation.
282 * @param iface AtkObject instance that implements AtkSelectionInterface
284 static void atk_selection_interface_init(AtkSelectionIface *iface)
286 g_return_if_fail(iface != NULL);
288 iface->add_selection = eail_slideshow_add_selection;
289 iface->ref_selection = eail_slideshow_ref_selection;
290 iface->get_selection_count = eail_slideshow_selection_count;
291 iface->is_child_selected = eail_slideshow_is_child_selected;
295 * @brief Gets the number of accessible actions available on the object
297 * If there are more than one, the first one is considered the "default" action of the object.
299 * Implementation of get_n_actions from AtkAction interface.
301 * @param action AtkAction instance
302 * @returns integer representing the number of implemented actions
305 eail_slideshow_n_actions_get(AtkAction *action)
307 g_return_val_if_fail(EAIL_IS_SLIDESHOW(action), 0);
313 * @brief Gets the name of the specified action of the object
315 * Implementation of get_name from AtkAction interface.
317 * @param action AtkAction instance
318 * @param i action index
320 * @returns string representing the name of the specified action
323 eail_slideshow_action_name_get(AtkAction *action, int i)
325 const gchar *action_name;
326 g_return_val_if_fail(EAIL_IS_SLIDESHOW(action), NULL);
330 /*advance to next image*/
331 action_name = "next";
334 /*advance to previous image*/
335 action_name = "previous";
338 /*stop the slideshow*/
339 action_name = "stop";
342 /*start the slideshow*/
343 action_name = "start";
354 * @brief Compares two doubles
356 * @param A first number
357 * @param B second number
358 * @param max_ulps number of doubles between A and B
359 * @returns TRUE if A equals B, FALSE otherwise
362 _double_cmp(double A, double B, gint max_ulps)
373 g_assert(max_ulps > 0 && max_ulps < 4*1024*1024);
375 if (f1.i < 0) f1.i = 0x80000000 - f1.i;
376 if (f2.i < 0) f1.i = 0x80000000 - f2.i;
378 diff = abs(f1.i - f2.i);
379 if (diff <= max_ulps)
386 * @brief Performs the specified action on the object
388 * Implementation of do_action from AtkAction interface.
390 * @param action AtkAction instance
391 * @param i action index
393 * @returns TRUE on success, FALSE otherwise
396 eail_slideshow_do_action(AtkAction *action, gint i)
400 double slideshow_timeout;
402 g_return_val_if_fail(EAIL_IS_SLIDESHOW(action), FALSE);
404 widget = eail_widget_get_widget(EAIL_WIDGET(action));
405 if (!widget) return FALSE;
407 if ((elm_object_disabled_get(widget)) || (!evas_object_visible_get(widget)))
413 elm_slideshow_next(widget);
417 elm_slideshow_previous(widget);
421 elm_slideshow_timeout_set(widget, 0.0);
425 slideshow_timeout = elm_slideshow_timeout_get(widget);
426 if (_double_cmp(slideshow_timeout, 0.0, 1))
429 elm_slideshow_timeout_set(widget, SLIDESHOW_DEFAULT_TIMEOUT);
443 * @brief Gets the description of the specified action of the object
445 * Implementation of get_description from AtkAction interface.
447 * @param action AtkAction instance
448 * @param i action index
450 * @returns string representing the description of the specified action
453 eail_slidshow_description_get(AtkAction *action, gint i)
455 const gchar *action_description;
456 EailSlideshow *slideshow;
458 g_return_val_if_fail(EAIL_IS_SLIDESHOW(action), NULL);
460 slideshow = EAIL_SLIDESHOW(action);
464 action_description = slideshow->next_description;
467 action_description = slideshow->previous_description;
470 action_description = slideshow->stop_description;
473 action_description = slideshow->start_description;
476 action_description = NULL;
479 return action_description;
483 * @brief Sets a description of the specified action of the object
485 * Implementation of set_description from AtkAction interface.
487 * @param action AtkAction instance
488 * @param i action index
489 * @param description action's description to set
491 * @returns TRUE on success, FALSE otherwise
494 eail_slideshow_description_set(AtkAction *action, gint i,
495 const char *description)
497 EailSlideshow *slideshow;
500 g_return_val_if_fail(EAIL_IS_SLIDESHOW(action), FALSE);
502 slideshow = EAIL_SLIDESHOW(action);
506 value = &slideshow->next_description;
509 value = &slideshow->previous_description;
512 value = &slideshow->stop_description;
515 value = &slideshow->start_description;
524 *value = g_strdup(description);
531 * @brief AtkAction interface initialization
533 * @param iface AtkActionIface instance
536 atk_action_interface_init(AtkActionIface *iface)
538 g_return_if_fail(iface != NULL);
539 iface->do_action = eail_slideshow_do_action;
540 iface->get_n_actions = eail_slideshow_n_actions_get;
541 iface->get_description = eail_slidshow_description_get;
542 iface->set_description = eail_slideshow_description_set;
543 iface->get_name = eail_slideshow_action_name_get;
545 /*iface->get_localized_name;*/
546 /*iface->get_keybinding;*/