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 Implementation of ref_child from AtkObject interface
51 * @param obj EailSlideshow instance
52 * @param i index of a child object
54 * @returns child object
57 eail_slideshow_ref_child(AtkObject *obj, gint i)
59 Evas_Object *widget, *child_widget;
62 g_return_val_if_fail(EAIL_IS_SLIDESHOW(obj), NULL);
64 widget = eail_widget_get_widget(EAIL_WIDGET(obj));
65 if (!widget) return NULL;
67 it = elm_slideshow_item_nth_get(widget, i);
70 child_widget = elm_slideshow_item_object_get(it);
73 WRN("Given index %d is beyond realized (cached) views. Returning NULL",
78 return eail_factory_get_accessible(child_widget);
82 * @brief Implementation of get_n_children from AtkObject interface
84 * @param obj EailSlideshow instance
85 * @returns number of widget childs
88 eail_slideshow_n_children_get(AtkObject *obj)
93 g_return_val_if_fail(EAIL_IS_SLIDESHOW(obj), 0);
95 widget = eail_widget_get_widget(EAIL_WIDGET(obj));
96 if (!widget) return 0;
97 /*the real number of items stored in slideshow widget is returned by
98 elm_slideshow_count_get. However we will not be able to return all items
99 widget since only those stored in cache are created.*/
100 items_count = elm_slideshow_count_get(widget);
105 * @brief Initialize EailSlideshow as a AtkObject
107 * @param obj EailSlideshow instance
108 * @param data user data passed to initialization
111 eail_slideshow_initialize(AtkObject *obj, gpointer data)
113 ATK_OBJECT_CLASS(eail_slideshow_parent_class)->initialize(obj, data);
114 obj->role = ATK_ROLE_DOCUMENT_PRESENTATION;
118 * @brief EailSlideshow object initialization
120 * @param slideshow EailSlideshow instance
123 eail_slideshow_init(EailSlideshow *slideshow)
125 slideshow->next_description = NULL;
126 slideshow->previous_description = NULL;
127 slideshow->stop_description = NULL;
128 slideshow->start_description = NULL;
132 * @brief Destructor of EailSlideshow object
134 * @param object EailSlideshow instance
137 eail_slideshow_finalize(GObject *object)
139 EailSlideshow *slideshow = EAIL_SLIDESHOW(object);
140 if (slideshow->next_description) free(slideshow->next_description);
141 if (slideshow->previous_description) free(slideshow->previous_description);
142 if (slideshow->stop_description) free(slideshow->stop_description);
143 if (slideshow->start_description) free(slideshow->start_description);
145 G_OBJECT_CLASS(eail_slideshow_parent_class)->finalize(object);
150 * @brief EailSlideshow class initialization
152 * @param klass EailSlideshowClass object
155 eail_slideshow_class_init(EailSlideshowClass *klass)
157 AtkObjectClass *atk_class = ATK_OBJECT_CLASS(klass);
158 GObjectClass *g_object_class = G_OBJECT_CLASS(klass);
160 atk_class->initialize = eail_slideshow_initialize;
161 atk_class->get_n_children = eail_slideshow_n_children_get;
162 atk_class->ref_child = eail_slideshow_ref_child;
164 g_object_class->finalize = eail_slideshow_finalize;
168 * @brief Implementation of selection_count from AtkSelection interface
170 * @param selection EailSlideshow instance
172 * @returns number of actions
175 eail_slideshow_selection_count(AtkSelection *selection)
177 g_return_val_if_fail(EAIL_IS_SLIDESHOW(selection), 0);
183 * @brief Implementation of add_selection from AtkSelection interface
185 * @param selection EailSlideshow instance
186 * @param i index of object to select
188 * @returns TRUE on success FALSE otherwise
191 eail_slideshow_add_selection(AtkSelection *selection, gint i)
196 g_return_val_if_fail(EAIL_IS_SLIDESHOW(selection), FALSE);
198 widget = eail_widget_get_widget(EAIL_WIDGET(selection));
199 if (!widget) return FALSE;
201 it = elm_slideshow_item_nth_get(widget, i);
202 if (!it) return FALSE;
204 elm_slideshow_item_show(it);
210 * @brief Implementation ref_selecton from AtkSelection
212 * @param selection EailSlideshow instance
213 * @param i index of selection
215 * @returns selected AtkObject
218 eail_slideshow_ref_selection(AtkSelection *selection, gint i)
220 Evas_Object *widget, *it_widget;
223 g_return_val_if_fail(EAIL_IS_SLIDESHOW(selection), NULL);
224 g_return_val_if_fail(i == 0, NULL);
226 widget = eail_widget_get_widget(EAIL_WIDGET(selection));
227 it = elm_slideshow_item_current_get(widget);
229 it_widget = elm_slideshow_item_object_get(it);
231 return eail_factory_get_accessible(it_widget);
235 * @brief Implementation of is_child_selected from AtkSelection
237 * @param selection EailSlideshow instace
238 * @param i index of selection
240 * @return TRUE if object is selected FALSE otherwise
243 eail_slideshow_is_child_selected(AtkSelection *selection, gint i)
246 Elm_Object_Item *it, *current;
248 g_return_val_if_fail(EAIL_IS_SLIDESHOW(selection), FALSE);
250 widget = eail_widget_get_widget(EAIL_WIDGET(selection));
251 if (!widget) return FALSE;
253 current = elm_slideshow_item_current_get(widget);
254 it = elm_slideshow_item_nth_get(widget, i);
256 return (it == current);
260 * @brief Initialization of AtkSelection interface
262 * Function called upon instance creation. It initializes AtkValue interface
263 * implementation i.e hooks method pointers in the interface structure
264 * to the implementing class's implementation.
266 * @param iface an AtkObject than implements AtkSelectionInterface
268 static void atk_selection_interface_init(AtkSelectionIface *iface)
270 g_return_if_fail(iface != NULL);
272 iface->add_selection = eail_slideshow_add_selection;
273 iface->ref_selection = eail_slideshow_ref_selection;
274 iface->get_selection_count = eail_slideshow_selection_count;
275 iface->is_child_selected = eail_slideshow_is_child_selected;
279 * @brief Implementation of get_n_action from AtkAction interface
281 * @param action EailSlideshow instance
282 * @returns number of implemented actions
285 eail_slideshow_n_actions_get(AtkAction *action)
287 g_return_val_if_fail(EAIL_IS_SLIDESHOW(action), 0);
293 * @brief Implementation of get_action_name from AtkAction interface
295 * @param action EailSlideshow instance
296 * @param i action index
298 * @returns acton name
301 eail_slideshow_action_name_get(AtkAction *action, int i)
303 const gchar *action_name;
304 g_return_val_if_fail(EAIL_IS_SLIDESHOW(action), NULL);
308 /*advance to next image*/
309 action_name = "next";
312 /*advance to previous image*/
313 action_name = "previous";
316 /*stop the slideshow*/
317 action_name = "stop";
320 /*start the slideshow*/
321 action_name = "start";
332 * @brief Compares two doubles
333 * @param A first number
334 * @param B second number
335 * @param max_ulps number of doubles between A and B
336 * @returns TRUE if A == B, FALSE otherwise
339 _double_cmp(double A, double B, gint max_ulps)
350 g_assert(max_ulps > 0 && max_ulps < 4*1024*1024);
352 if (f1.i < 0) f1.i = 0x80000000 - f1.i;
353 if (f2.i < 0) f1.i = 0x80000000 - f2.i;
355 diff = abs(f1.i - f2.i);
356 if (diff <= max_ulps)
363 * @brief Implementation of do action from AtkAction interface
365 * @param action EailSlideshow instance
366 * @param i action index
368 * @returns TRUE on success, FALSE otherwise
371 eail_slideshow_do_action(AtkAction *action, gint i)
375 double slideshow_timeout;
377 g_return_val_if_fail(EAIL_IS_SLIDESHOW(action), FALSE);
379 widget = eail_widget_get_widget(EAIL_WIDGET(action));
380 if (!widget) return FALSE;
382 if ((elm_object_disabled_get(widget)) || (!evas_object_visible_get(widget)))
388 elm_slideshow_next(widget);
392 elm_slideshow_previous(widget);
396 elm_slideshow_timeout_set(widget, 0.0);
400 slideshow_timeout = elm_slideshow_timeout_get(widget);
401 if (_double_cmp(slideshow_timeout, 0.0, 1))
404 elm_slideshow_timeout_set(widget, SLIDESHOW_DEFAULT_TIMEOUT);
418 * @brief Implementation of get_description from AtkAction interface
420 * @param action EailSlideshow instance
421 * @param i action index
423 * @returns action description
426 eail_slidshow_description_get(AtkAction *action, gint i)
428 const gchar *action_description;
429 EailSlideshow *slideshow;
431 g_return_val_if_fail(EAIL_IS_SLIDESHOW(action), NULL);
433 slideshow = EAIL_SLIDESHOW(action);
437 action_description = slideshow->next_description;
440 action_description = slideshow->previous_description;
443 action_description = slideshow->stop_description;
446 action_description = slideshow->start_description;
449 action_description = NULL;
452 return action_description;
456 * @brief Implementation of set_description from AtkAction interface
458 * @param action EailSlideshow instance
459 * @param i action index
460 * @param description action description to set
462 * @returns TRUE on success, FALSE otherwise
465 eail_slideshow_description_set(AtkAction *action, gint i,
466 const char *description)
468 EailSlideshow *slideshow;
471 g_return_val_if_fail(EAIL_IS_SLIDESHOW(action), FALSE);
473 slideshow = EAIL_SLIDESHOW(action);
477 value = &slideshow->next_description;
480 value = &slideshow->previous_description;
483 value = &slideshow->stop_description;
486 value = &slideshow->start_description;
495 *value = g_strdup(description);
502 * @brief AtkAction interface initialization
504 * @param iface EailSlideshow object
507 atk_action_interface_init(AtkActionIface *iface)
509 g_return_if_fail(iface != NULL);
510 iface->do_action = eail_slideshow_do_action;
511 iface->get_n_actions = eail_slideshow_n_actions_get;
512 iface->get_description = eail_slidshow_description_get;
513 iface->set_description = eail_slideshow_description_set;
514 iface->get_name = eail_slideshow_action_name_get;
516 /*iface->get_localized_name;*/
517 /*iface->get_keybinding;*/