1 #include <Elementary.h>
5 * @defgroup Slideshow slideshow
8 * This object display a list of object (generally a list of images) and some actions like
9 * next/previous are used to navigate. The animations are defined in the theme,
10 * consequently new animations can be added without having to update the
13 * The slideshow use 2 callbacks to create and delete the objects displayed. When an item
14 * is displayed the function itc->func.get() is called. This function should create the object,
15 * for example the object can be an evas_object_image or a photocam. When a object is no more
16 * displayed the function itc->func.del() is called, the user can delete the dana associated to the item.
19 typedef struct _Widget_Data Widget_Data;
21 struct _Elm_Slideshow_Item
25 Eina_List *l, *l_built;
28 const Elm_Slideshow_Item_Class *itc;
35 Evas_Object *slideshow;
37 // list of Elm_Slideshow_Item*
39 Eina_List *items_built;
41 Elm_Slideshow_Item *current;
42 Elm_Slideshow_Item *previous;
44 Eina_List *transitions;
45 const char *transition;
53 Eina_List *list; //list of const char *
57 static const char *widtype = NULL;
58 static void _del_hook(Evas_Object *obj);
59 static void _theme_hook(Evas_Object *obj);
60 static void _sizing_eval(Evas_Object *obj);
61 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
62 static Eina_Bool _timer_cb(void *data);
65 _del_hook(Evas_Object *obj)
68 Widget_Data *wd = elm_widget_data_get(obj);
70 elm_slideshow_clear(obj);
71 elm_widget_stringlist_free(wd->transitions);
72 if (wd->timer) ecore_timer_del(wd->timer);
73 EINA_LIST_FREE(wd->layout.list, layout)
74 eina_stringshare_del(layout);
79 _theme_hook(Evas_Object *obj)
81 Widget_Data *wd = elm_widget_data_get(obj);
83 _elm_theme_object_set(obj, wd->slideshow, "slideshow", "base", elm_widget_style_get(obj));
84 edje_object_scale_set(wd->slideshow, elm_widget_scale_get(obj) *
90 _sizing_eval(Evas_Object *obj)
92 Widget_Data *wd = elm_widget_data_get(obj);
93 Evas_Coord minw = -1, minh = -1;
95 edje_object_size_min_calc(wd->slideshow, &minw, &minh);
96 evas_object_size_hint_min_set(obj, minw, minh);
97 evas_object_size_hint_max_set(obj, minw, minh);
101 static Elm_Slideshow_Item* _item_prev_get(Elm_Slideshow_Item* item)
103 Widget_Data *wd = elm_widget_data_get(item->obj);
104 Elm_Slideshow_Item* prev = eina_list_data_get(eina_list_prev(item->l));
105 if(!prev && wd->loop)
106 prev = eina_list_data_get(eina_list_last(item->l));
109 static Elm_Slideshow_Item* _item_next_get(Elm_Slideshow_Item* item)
111 Widget_Data *wd = elm_widget_data_get(item->obj);
112 Elm_Slideshow_Item* next = eina_list_data_get(eina_list_next(item->l));
113 if(!next && wd->loop)
114 next = eina_list_data_get(wd->items);
120 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
126 _sub_del(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
132 _item_realize(Elm_Slideshow_Item *item)
134 Elm_Slideshow_Item *_item;
135 Evas_Object *obj = item->obj;
136 Widget_Data *wd = elm_widget_data_get(obj);
139 if ((!item->o) && (item->itc->func.get))
141 item->o = item->itc->func.get((void*)item->data, obj);
142 evas_object_smart_member_add(item->o, obj);
143 item->l_built = eina_list_append(NULL, item);
144 wd->items_built = eina_list_merge(wd->items_built, item->l_built);
145 evas_object_hide(item->o);
147 else if (item->l_built)
148 wd->items_built = eina_list_demote_list(wd->items_built, item->l_built);
150 //pre-create previous and next item
151 _item = _item_next_get(item);
152 if ((_item) && (!_item->o) && (_item->itc->func.get))
154 _item->o = _item->itc->func.get((void*)_item->data, obj);
155 evas_object_smart_member_add(_item->o, obj);
156 _item->l_built = eina_list_append(NULL, _item);
157 wd->items_built = eina_list_merge(wd->items_built, _item->l_built);
158 evas_object_hide(_item->o);
160 else if ((_item) && (_item->l_built))
161 wd->items_built = eina_list_demote_list(wd->items_built, _item->l_built);
163 _item = _item_prev_get(item);
164 if ((_item) && (!_item->o) && (_item->itc->func.get))
166 _item->o = _item->itc->func.get((void*)_item->data, obj);
167 evas_object_smart_member_add(_item->o, obj);
168 _item->l_built = eina_list_append(NULL, _item);
169 wd->items_built = eina_list_merge(wd->items_built, _item->l_built);
170 evas_object_hide(_item->o);
172 else if ((_item) && (_item->l_built))
173 wd->items_built = eina_list_demote_list(wd->items_built, _item->l_built);
175 //delete unused items
176 while (eina_list_count(wd->items_built) > 3)
178 _item = eina_list_data_get(wd->items_built);
179 wd->items_built = eina_list_remove_list(wd->items_built, wd->items_built);
180 if(item->itc->func.del)
181 item->itc->func.del((void*)item->data, _item->o);
182 evas_object_del(_item->o);
188 _end(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
190 Elm_Slideshow_Item *item;
191 Widget_Data *wd = elm_widget_data_get(data);
197 edje_object_part_unswallow(NULL, item->o);
198 evas_object_hide(item->o);
204 if (!item || !item->o) return;
207 edje_object_part_unswallow(NULL, item->o);
208 evas_object_show(item->o);
210 edje_object_signal_emit(wd->slideshow, "anim,end", "slideshow");
211 edje_object_part_swallow(wd->slideshow, "elm.swallow.1", item->o);
216 _timer_cb(void *data)
218 Evas_Object *obj = data;
219 Widget_Data *wd = elm_widget_data_get(obj);
220 if (!wd) return ECORE_CALLBACK_CANCEL;
222 elm_slideshow_next(obj);
223 return ECORE_CALLBACK_CANCEL;
229 * Add a new slideshow to the parent
231 * @param parent The parent object
232 * @return The new object or NULL if it cannot be created
237 elm_slideshow_add(Evas_Object *parent)
243 wd = ELM_NEW(Widget_Data);
244 e = evas_object_evas_get(parent);
245 obj = elm_widget_add(e);
246 ELM_SET_WIDTYPE(widtype, "slideshow");
247 elm_widget_type_set(obj, "slideshow");
248 elm_widget_sub_object_add(parent, obj);
249 elm_widget_data_set(obj, wd);
250 elm_widget_del_hook_set(obj, _del_hook);
251 elm_widget_theme_hook_set(obj, _theme_hook);
256 wd->slideshow = edje_object_add(e);
257 _elm_theme_object_set(obj, wd->slideshow, "slideshow", "base", "default");
258 evas_object_smart_member_add(wd->slideshow, obj);
259 elm_widget_resize_object_set(obj, wd->slideshow);
260 evas_object_show(wd->slideshow);
262 wd->transitions = elm_widget_stringlist_get(edje_object_data_get(wd->slideshow, "transitions"));
263 if (eina_list_count(wd->transitions) > 0)
264 wd->transition = eina_stringshare_add(eina_list_data_get(wd->transitions));
266 wd->layout.list = elm_widget_stringlist_get(edje_object_data_get(wd->slideshow, "layouts"));
267 if (eina_list_count(wd->layout.list) > 0)
268 wd->layout.current = eina_list_data_get(wd->layout.list);
270 edje_object_signal_callback_add(wd->slideshow, "end", "slideshow", _end, obj);
272 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
273 evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
280 * Add a object in the list. The object can be a evas object image or a elm photo for example.
282 * @param obj The slideshow object
283 * @aram itc Callbacks used to create the object and delete the data associated when the item is deleted.
284 * @param data Data used by the user to identified the item
285 * @return Returns The slideshow item
289 EAPI Elm_Slideshow_Item*
290 elm_slideshow_item_add(Evas_Object *obj, const Elm_Slideshow_Item_Class *itc, const void *data)
292 Elm_Slideshow_Item *item;
293 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
294 Widget_Data *wd = elm_widget_data_get(obj);
296 if (!wd) return NULL;
297 item = calloc(1, sizeof(Elm_Slideshow_Item));
301 item->l = eina_list_append(item->l, item);
303 wd->items = eina_list_merge(wd->items, item->l);
305 if (!wd->current) elm_slideshow_show(item);
313 * @param obj The slideshow object
314 * @param item The item
319 elm_slideshow_show(Elm_Slideshow_Item *item)
322 Elm_Slideshow_Item *next = NULL;
326 ELM_CHECK_WIDTYPE(item->obj, widtype);
327 wd = elm_widget_data_get(item->obj);
330 if (item == wd->current)
334 _end(item->obj, item->obj, NULL, NULL);
336 if (wd->timer) ecore_timer_del(wd->timer);
338 wd->timer = ecore_timer_add(wd->timeout, _timer_cb, item->obj);
340 edje_object_part_swallow(wd->slideshow, "elm.swallow.2", next->o);
341 evas_object_show(next->o);
342 snprintf(buf, sizeof(buf), "%s,next", wd->transition);
343 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
344 wd->previous = wd->current;
350 * Go to the next item
352 * @param obj The slideshow object
357 elm_slideshow_next(Evas_Object *obj)
360 Elm_Slideshow_Item *next = NULL;
361 ELM_CHECK_WIDTYPE(obj, widtype);
362 Widget_Data *wd = elm_widget_data_get(obj);
367 next = _item_next_get(wd->current);
369 if (!next || next == wd->current) return;
372 _end(obj, obj, NULL, NULL);
374 if (wd->timer) ecore_timer_del(wd->timer);
376 wd->timer = ecore_timer_add(wd->timeout, _timer_cb, obj);
380 edje_object_part_swallow(wd->slideshow, "elm.swallow.2", next->o);
381 evas_object_show(next->o);
383 snprintf(buf, sizeof(buf), "%s,next", wd->transition);
384 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
386 wd->previous = wd->current;
391 * Go to the previous item
393 * @param obj The slideshow object
398 elm_slideshow_previous(Evas_Object *obj)
401 Elm_Slideshow_Item *prev = NULL;
402 ELM_CHECK_WIDTYPE(obj, widtype);
403 Widget_Data *wd = elm_widget_data_get(obj);
408 prev = _item_prev_get(wd->current);
410 if (!prev || prev == wd->current) return;
412 _end(obj, obj, NULL, NULL);
414 if (wd->timer) ecore_timer_del(wd->timer);
416 wd->timer = ecore_timer_add(wd->timeout, _timer_cb, obj);
420 edje_object_part_swallow(wd->slideshow, "elm.swallow.2", prev->o);
421 evas_object_show(prev->o);
423 snprintf(buf, 1024, "%s,previous", wd->transition);
424 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
426 wd->previous = wd->current;
431 * Returns the list of transitions available.
433 * @param obj The slideshow object
434 * @return Returns the list of transitions (list of const char*)
439 elm_slideshow_transitions_get(const Evas_Object *obj)
441 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
442 Widget_Data *wd = elm_widget_data_get(obj);
443 if (!wd) return NULL;
444 return wd->transitions;
448 * Returns the list of layouts available.
450 * @param obj The slideshow object
451 * @return Returns the list of layout (list of const char*)
456 elm_slideshow_layouts_get(const Evas_Object *obj)
458 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
459 Widget_Data *wd = elm_widget_data_get(obj);
460 if (!wd) return NULL;
461 return wd->layout.list;
465 * Set the transition to use
467 * @param obj The slideshow object
468 * @param transition the new transition
473 elm_slideshow_transition_set(Evas_Object *obj, const char *transition)
475 ELM_CHECK_WIDTYPE(obj, widtype);
476 Widget_Data *wd = elm_widget_data_get(obj);
478 eina_stringshare_replace(&wd->transition, transition);
482 * Returns the transition to use
484 * @param obj The slideshow object
485 * @return the transition set
490 elm_slideshow_transition_get(const Evas_Object *obj)
492 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
493 Widget_Data *wd = elm_widget_data_get(obj);
494 if (!wd) return NULL;
495 return wd->transition;
499 * The slideshow can go to the next item automatically after a few seconds.
500 * This method set the timeout to use. A timeout <=0 disable the timer.
502 * @param obj The slideshow object
503 * @param timeout The new timeout
508 elm_slideshow_timeout_set(Evas_Object *obj ,int timeout)
510 ELM_CHECK_WIDTYPE(obj, widtype);
511 Widget_Data *wd = elm_widget_data_get(obj);
513 wd->timeout = timeout;
514 if (wd->timer) ecore_timer_del(wd->timer);
517 wd->timer = ecore_timer_add(timeout, _timer_cb, obj);
521 * Returns the timeout value
523 * @param obj The slideshow object
524 * @return Returns the timeout
529 elm_slideshow_timeout_get(const Evas_Object *obj)
531 ELM_CHECK_WIDTYPE(obj, widtype) -1;
532 Widget_Data *wd = elm_widget_data_get(obj);
538 * Set if the first item should follow the last and vice versa
540 * @param obj The slideshow object
541 * @param loop if EINA_TRUE, the first item will follow the last and vice versa
546 elm_slideshow_loop_set(Evas_Object *obj, Eina_Bool loop)
548 ELM_CHECK_WIDTYPE(obj, widtype);
549 Widget_Data *wd = elm_widget_data_get(obj);
555 * Returns the current layout name
557 * @param obj The slideshow object
558 * @returns Returns the layout name
563 elm_slideshow_layout_get(const Evas_Object *obj)
565 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
566 Widget_Data *wd = elm_widget_data_get(obj);
567 if (!wd) return EINA_FALSE;
568 return wd->layout.current;
574 * @param obj The slideshow object
575 * @param layout the new layout
580 elm_slideshow_layout_set(Evas_Object *obj, const char *layout)
583 ELM_CHECK_WIDTYPE(obj, widtype);
584 Widget_Data *wd = elm_widget_data_get(obj);
587 wd->layout.current = layout;
588 snprintf(buf, sizeof(buf), "layout,%s", layout);
589 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
593 * Return if the first item should follow the last and vice versa
595 * @param obj The slideshow object
596 * @returns Returns the loop flag
601 elm_slideshow_loop_get(const Evas_Object *obj)
603 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
604 Widget_Data *wd = elm_widget_data_get(obj);
605 if (!wd) return EINA_FALSE;
610 * Delete all the items
612 * @param obj The slideshow object
617 elm_slideshow_clear(Evas_Object *obj)
619 Elm_Slideshow_Item *item;
620 ELM_CHECK_WIDTYPE(obj, widtype);
621 Widget_Data *wd = elm_widget_data_get(obj);
625 EINA_LIST_FREE(wd->items_built, item)
627 if (item->itc->func.del)
628 item->itc->func.del((void*)item->data, item->o);
629 evas_object_del(item->o);
632 EINA_LIST_FREE(wd->items, item)
642 * @param item The slideshow item
647 elm_slideshow_item_del(Elm_Slideshow_Item *item)
650 Widget_Data *wd = elm_widget_data_get(item->obj);
652 if (wd->previous == item) wd->previous = NULL;
653 if (wd->current == item)
655 Eina_List *l = eina_list_data_find_list(wd->items, item);
656 Eina_List *l2 = eina_list_next(l);
659 l2 = eina_list_nth_list(wd->items, eina_list_count(wd->items) - 1);
661 elm_slideshow_show(eina_list_data_get(l2));
664 wd->items = eina_list_remove_list(wd->items, item->l);
665 wd->items_built = eina_list_remove_list(wd->items_built, item->l_built);
667 if (item->o && item->itc->func.del)
668 item->itc->func.del((void*)item->data, wd->previous->o);
670 evas_object_del(item->o);
675 * Returns the list of items
676 * @param obj The slideshow object
677 * @return Returns the list of items (list of Elm_Slideshow_Item).
681 EAPI const Eina_List *
682 elm_slideshow_items_get(const Evas_Object *obj)
684 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
685 Widget_Data *wd = elm_widget_data_get(obj);
686 if (!wd) return NULL;
692 * Returns the current item displayed
694 * @param obj The slideshow object
695 * @return Returns the current item displayed
699 EAPI Elm_Slideshow_Item *
700 elm_slideshow_item_current_get(const Evas_Object *obj)
702 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
703 Widget_Data *wd = elm_widget_data_get(obj);
704 if (!wd) return NULL;
709 * Returns the evas object associated to an item
711 * @param item The slideshow item
712 * @return Returns the evas object associated to this item
717 elm_slideshow_item_object_get(Elm_Slideshow_Item * item)
719 if (!item) return NULL;
724 * Returns the data associated to an item
726 * @param item The slideshow item
727 * @return Returns the data associated to this item
732 elm_slideshow_item_data_get(Elm_Slideshow_Item * item)
734 if (!item) return NULL;
735 return (void *)item->data;