1 #include <Elementary.h>
5 * @defgroup Slideshow Slideshow
7 * This object display a list of object (generally a list of images) and some actions like
8 * next/previous are used to navigate. The animations are defined in the theme,
9 * consequently new animations can be added without having to update the
12 * The slideshow use 2 callbacks to create and delete the objects displayed. When an item
13 * is displayed the function itc->func.get() is called. This function should create the object,
14 * for example the object can be an evas_object_image or a photocam. When a object is no more
15 * displayed the function itc->func.del() is called, the user can delete the dana associated to the item.
17 * Signals that you can add callbacks for are:
19 * "changed" - when the slideshow switch to another item
22 typedef struct _Widget_Data Widget_Data;
24 struct _Elm_Slideshow_Item
28 Eina_List *l, *l_built;
30 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;
47 int count_item_pre_before;
48 int count_item_pre_after;
55 Eina_List *list; //list of const char *
59 static const char *widtype = NULL;
60 static void _del_hook(Evas_Object *obj);
61 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
62 static void _theme_hook(Evas_Object *obj);
63 static void _sizing_eval(Evas_Object *obj);
64 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
65 static Eina_Bool _timer_cb(void *data);
66 static void _on_focus_hook(void *data, Evas_Object *obj);
67 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src,
68 Evas_Callback_Type type, void *event_info);
70 static const char SIG_CHANGED[] = "changed";
72 static const Evas_Smart_Cb_Description _signals[] = {
78 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
80 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
81 Evas_Event_Key_Down *ev = event_info;
82 Widget_Data *wd = elm_widget_data_get(obj);
83 if (!wd) return EINA_FALSE;
84 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
85 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
86 if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")))
88 elm_slideshow_previous(obj);
89 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
92 if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")))
94 elm_slideshow_next(obj);
95 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
98 if ((!strcmp(ev->keyname, "Return")) ||
99 (!strcmp(ev->keyname, "KP_Enter")) ||
100 (!strcmp(ev->keyname, "space")))
106 ecore_timer_del(wd->timer);
110 elm_slideshow_timeout_set(obj, wd->timeout);
112 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
119 _del_hook(Evas_Object *obj)
122 Widget_Data *wd = elm_widget_data_get(obj);
124 elm_slideshow_clear(obj);
125 elm_widget_stringlist_free(wd->transitions);
126 if (wd->timer) ecore_timer_del(wd->timer);
127 EINA_LIST_FREE(wd->layout.list, layout)
128 eina_stringshare_del(layout);
133 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
135 Widget_Data *wd = elm_widget_data_get(obj);
137 if (elm_widget_focus_get(obj))
139 edje_object_signal_emit(wd->slideshow, "elm,action,focus", "elm");
140 evas_object_focus_set(wd->slideshow, EINA_TRUE);
144 edje_object_signal_emit(wd->slideshow, "elm,action,unfocus", "elm");
145 evas_object_focus_set(wd->slideshow, EINA_FALSE);
150 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
152 Widget_Data *wd = elm_widget_data_get(obj);
154 edje_object_mirrored_set(wd->slideshow, rtl);
158 _theme_hook(Evas_Object *obj)
160 Widget_Data *wd = elm_widget_data_get(obj);
162 _elm_widget_mirrored_reload(obj);
163 _mirrored_set(obj, elm_widget_mirrored_get(obj));
164 _elm_theme_object_set(obj, wd->slideshow, "slideshow", "base", elm_widget_style_get(obj));
165 edje_object_scale_set(wd->slideshow, elm_widget_scale_get(obj) *
171 _sizing_eval(Evas_Object *obj)
173 Widget_Data *wd = elm_widget_data_get(obj);
174 Evas_Coord minw = -1, minh = -1;
176 edje_object_size_min_calc(wd->slideshow, &minw, &minh);
177 evas_object_size_hint_min_set(obj, minw, minh);
178 evas_object_size_hint_max_set(obj, minw, minh);
182 static Elm_Slideshow_Item* _item_prev_get(Elm_Slideshow_Item* item)
184 Widget_Data *wd = elm_widget_data_get(item->base.widget);
185 Elm_Slideshow_Item* prev = eina_list_data_get(eina_list_prev(item->l));
186 if ((!prev) && (wd->loop))
187 prev = eina_list_data_get(eina_list_last(item->l));
191 static Elm_Slideshow_Item* _item_next_get(Elm_Slideshow_Item* item)
193 Widget_Data *wd = elm_widget_data_get(item->base.widget);
194 Elm_Slideshow_Item* next = eina_list_data_get(eina_list_next(item->l));
195 if ((!next) && (wd->loop))
196 next = eina_list_data_get(wd->items);
201 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
207 _sub_del(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
213 _item_realize(Elm_Slideshow_Item *item)
215 Elm_Slideshow_Item *_item_prev, *_item_next;
216 Evas_Object *obj = item->base.widget;
217 Widget_Data *wd = elm_widget_data_get(obj);
221 if ((!item->base.view) && (item->itc->func.get))
223 item->base.view = item->itc->func.get((void*)item->base.data, obj);
224 evas_object_smart_member_add(item->base.view, obj);
225 item->l_built = eina_list_append(NULL, item);
226 wd->items_built = eina_list_merge(wd->items_built, item->l_built);
227 evas_object_hide(item->base.view);
229 else if (item->l_built)
230 wd->items_built = eina_list_demote_list(wd->items_built, item->l_built);
232 //pre-create previous and next item
233 ac = wd->count_item_pre_after;
235 bc = wd->count_item_pre_before;
237 lc = eina_list_count(wd->items) - 1;
238 while (lc > 0 && ((ac > 0) || (bc > 0)))
240 if (lc > 0 && ac > 0)
244 _item_next = _item_next_get(_item_next);
246 && (!_item_next->base.view)
247 && (_item_next->itc->func.get))
249 _item_next->base.view =
250 _item_next->itc->func.get((void*)_item_next->base.data,
252 evas_object_smart_member_add(_item_next->base.view, obj);
253 _item_next->l_built = eina_list_append(NULL, _item_next);
254 wd->items_built = eina_list_merge(wd->items_built,
255 _item_next->l_built);
256 evas_object_hide(_item_next->base.view);
258 else if (_item_next && _item_next->l_built)
259 wd->items_built = eina_list_demote_list(wd->items_built,
260 _item_next->l_built);
263 if (lc > 0 && bc > 0)
267 _item_prev = _item_prev_get(_item_prev);
269 && (!_item_prev->base.view)
270 && (_item_prev->itc->func.get))
272 _item_prev->base.view =
273 _item_prev->itc->func.get((void*)_item_prev->base.data,
275 evas_object_smart_member_add(_item_prev->base.view, obj);
276 _item_prev->l_built = eina_list_append(NULL, _item_prev);
277 wd->items_built = eina_list_merge(wd->items_built,
278 _item_prev->l_built);
279 evas_object_hide(_item_prev->base.view);
281 else if (_item_prev && _item_prev->l_built)
282 wd->items_built = eina_list_demote_list(wd->items_built,
283 _item_prev->l_built);
287 //delete unused items
288 lc = wd->count_item_pre_before + wd->count_item_pre_after + 1;
289 while ((int)eina_list_count(wd->items_built) > lc)
291 item = eina_list_data_get(wd->items_built);
292 wd->items_built = eina_list_remove_list(wd->items_built,
294 if (item->itc->func.del)
295 item->itc->func.del((void*)item->base.data, item->base.view);
296 evas_object_del(item->base.view);
297 item->base.view = NULL;
302 _end(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
304 Elm_Slideshow_Item *item;
305 Widget_Data *wd = elm_widget_data_get(data);
311 edje_object_part_unswallow(NULL, item->base.view);
312 evas_object_hide(item->base.view);
318 if ((!item) || (!item->base.view)) return;
321 edje_object_part_unswallow(NULL, item->base.view);
322 evas_object_show(item->base.view);
324 edje_object_signal_emit(wd->slideshow, "anim,end", "slideshow");
325 edje_object_part_swallow(wd->slideshow, "elm.swallow.1", item->base.view);
329 _timer_cb(void *data)
331 Evas_Object *obj = data;
332 Widget_Data *wd = elm_widget_data_get(obj);
333 if (!wd) return ECORE_CALLBACK_CANCEL;
335 elm_slideshow_next(obj);
336 return ECORE_CALLBACK_CANCEL;
340 * Add a new slideshow to the parent
342 * @param parent The parent object
343 * @return The new object or NULL if it cannot be created
348 elm_slideshow_add(Evas_Object *parent)
354 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
356 ELM_SET_WIDTYPE(widtype, "slideshow");
357 elm_widget_type_set(obj, "slideshow");
358 elm_widget_sub_object_add(parent, obj);
359 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
360 elm_widget_data_set(obj, wd);
361 elm_widget_del_hook_set(obj, _del_hook);
362 elm_widget_theme_hook_set(obj, _theme_hook);
363 elm_widget_can_focus_set(obj, EINA_TRUE);
364 elm_widget_event_hook_set(obj, _event_hook);
369 wd->slideshow = edje_object_add(e);
370 _elm_theme_object_set(obj, wd->slideshow, "slideshow", "base", "default");
371 evas_object_smart_member_add(wd->slideshow, obj);
372 wd->count_item_pre_before = 2;
373 wd->count_item_pre_after = 2;
374 elm_widget_resize_object_set(obj, wd->slideshow);
375 evas_object_show(wd->slideshow);
377 wd->transitions = elm_widget_stringlist_get(edje_object_data_get(wd->slideshow, "transitions"));
378 if (eina_list_count(wd->transitions) > 0)
379 wd->transition = eina_stringshare_add(eina_list_data_get(wd->transitions));
381 wd->layout.list = elm_widget_stringlist_get(edje_object_data_get(wd->slideshow, "layouts"));
382 if (eina_list_count(wd->layout.list) > 0)
383 wd->layout.current = eina_list_data_get(wd->layout.list);
385 edje_object_signal_callback_add(wd->slideshow, "end", "slideshow", _end, obj);
387 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
388 evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
390 evas_object_smart_callbacks_descriptions_set(obj, _signals);
392 _mirrored_set(obj, elm_widget_mirrored_get(obj));
398 * Add a object in the list. The object can be a evas object image or a elm photo for example.
400 * @param obj The slideshow object
401 * @aram itc Callbacks used to create the object and delete the data associated when the item is deleted.
402 * @param data Data used by the user to identified the item
403 * @return Returns The slideshow item
407 EAPI Elm_Slideshow_Item*
408 elm_slideshow_item_add(Evas_Object *obj, const Elm_Slideshow_Item_Class *itc, const void *data)
410 Elm_Slideshow_Item *item;
411 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
412 Widget_Data *wd = elm_widget_data_get(obj);
414 if (!wd) return NULL;
415 item = elm_widget_item_new(obj, Elm_Slideshow_Item);
416 item->base.data = data;
418 item->l = eina_list_append(item->l, item);
420 wd->items = eina_list_merge(wd->items, item->l);
422 if (!wd->current) elm_slideshow_show(item);
430 * @param obj The slideshow object
431 * @param item The item
436 elm_slideshow_show(Elm_Slideshow_Item *item)
439 Elm_Slideshow_Item *next = NULL;
441 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
442 wd = elm_widget_data_get(item->base.widget);
445 if (item == wd->current)
449 _end(item->base.widget, item->base.widget, NULL, NULL);
451 if (wd->timer) ecore_timer_del(wd->timer);
452 if (wd->timeout > 0.0)
453 wd->timer = ecore_timer_add(wd->timeout, _timer_cb, item->base.widget);
455 edje_object_part_swallow(wd->slideshow, "elm.swallow.2", next->base.view);
456 evas_object_show(next->base.view);
457 snprintf(buf, sizeof(buf), "%s,next", wd->transition);
458 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
459 wd->previous = wd->current;
461 evas_object_smart_callback_call(item->base.widget, SIG_CHANGED, wd->current);
465 * Go to the next item
467 * @param obj The slideshow object
472 elm_slideshow_next(Evas_Object *obj)
475 Elm_Slideshow_Item *next = NULL;
476 ELM_CHECK_WIDTYPE(obj, widtype);
477 Widget_Data *wd = elm_widget_data_get(obj);
482 next = _item_next_get(wd->current);
484 if ((!next) || (next == wd->current)) return;
486 _end(obj, obj, NULL, NULL);
488 if (wd->timer) ecore_timer_del(wd->timer);
489 if (wd->timeout > 0.0)
490 wd->timer = ecore_timer_add(wd->timeout, _timer_cb, obj);
494 edje_object_part_swallow(wd->slideshow, "elm.swallow.2", next->base.view);
495 evas_object_show(next->base.view);
497 snprintf(buf, sizeof(buf), "%s,next", wd->transition);
498 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
500 wd->previous = wd->current;
502 evas_object_smart_callback_call(obj, SIG_CHANGED, wd->current);
506 * Go to the previous item
508 * @param obj The slideshow object
513 elm_slideshow_previous(Evas_Object *obj)
516 Elm_Slideshow_Item *prev = NULL;
517 ELM_CHECK_WIDTYPE(obj, widtype);
518 Widget_Data *wd = elm_widget_data_get(obj);
523 prev = _item_prev_get(wd->current);
525 if ((!prev) || (prev == wd->current)) return;
527 _end(obj, obj, NULL, NULL);
529 if (wd->timer) ecore_timer_del(wd->timer);
530 if (wd->timeout > 0.0)
531 wd->timer = ecore_timer_add(wd->timeout, _timer_cb, obj);
535 edje_object_part_swallow(wd->slideshow, "elm.swallow.2", prev->base.view);
536 evas_object_show(prev->base.view);
538 snprintf(buf, 1024, "%s,previous", wd->transition);
539 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
541 wd->previous = wd->current;
543 evas_object_smart_callback_call(obj, SIG_CHANGED, wd->current);
547 * Returns the list of transitions available.
549 * @param obj The slideshow object
550 * @return Returns the list of transitions (list of const char*)
554 EAPI const Eina_List *
555 elm_slideshow_transitions_get(const Evas_Object *obj)
557 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
558 Widget_Data *wd = elm_widget_data_get(obj);
559 if (!wd) return NULL;
560 return wd->transitions;
564 * Returns the list of layouts available.
566 * @param obj The slideshow object
567 * @return Returns the list of layout (list of const char*)
571 EAPI const Eina_List *
572 elm_slideshow_layouts_get(const Evas_Object *obj)
574 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
575 Widget_Data *wd = elm_widget_data_get(obj);
576 if (!wd) return NULL;
577 return wd->layout.list;
581 * Set the transition to use
583 * @param obj The slideshow object
584 * @param transition the new transition
589 elm_slideshow_transition_set(Evas_Object *obj, const char *transition)
591 ELM_CHECK_WIDTYPE(obj, widtype);
592 Widget_Data *wd = elm_widget_data_get(obj);
594 eina_stringshare_replace(&wd->transition, transition);
598 * Returns the transition to use
600 * @param obj The slideshow object
601 * @return the transition set
606 elm_slideshow_transition_get(const Evas_Object *obj)
608 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
609 Widget_Data *wd = elm_widget_data_get(obj);
610 if (!wd) return NULL;
611 return wd->transition;
615 * The slideshow can go to the next item automatically after a few seconds.
616 * This method set the timeout to use. A timeout <=0 disable the timer.
618 * @param obj The slideshow object
619 * @param timeout The new timeout
624 elm_slideshow_timeout_set(Evas_Object *obj, double timeout)
626 ELM_CHECK_WIDTYPE(obj, widtype);
627 Widget_Data *wd = elm_widget_data_get(obj);
629 wd->timeout = timeout;
630 if (wd->timer) ecore_timer_del(wd->timer);
633 wd->timer = ecore_timer_add(timeout, _timer_cb, obj);
637 * Returns the timeout value
639 * @param obj The slideshow object
640 * @return Returns the timeout
645 elm_slideshow_timeout_get(const Evas_Object *obj)
647 ELM_CHECK_WIDTYPE(obj, widtype) -1.0;
648 Widget_Data *wd = elm_widget_data_get(obj);
649 if (!wd) return -1.0;
654 * Set if the first item should follow the last and vice versa
656 * @param obj The slideshow object
657 * @param loop if EINA_TRUE, the first item will follow the last and vice versa
662 elm_slideshow_loop_set(Evas_Object *obj, Eina_Bool loop)
664 ELM_CHECK_WIDTYPE(obj, widtype);
665 Widget_Data *wd = elm_widget_data_get(obj);
671 * Returns the current layout name
673 * @param obj The slideshow object
674 * @returns Returns the layout name
679 elm_slideshow_layout_get(const Evas_Object *obj)
681 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
682 Widget_Data *wd = elm_widget_data_get(obj);
683 if (!wd) return EINA_FALSE;
684 return wd->layout.current;
690 * @param obj The slideshow object
691 * @param layout the new layout
696 elm_slideshow_layout_set(Evas_Object *obj, const char *layout)
699 ELM_CHECK_WIDTYPE(obj, widtype);
700 Widget_Data *wd = elm_widget_data_get(obj);
703 wd->layout.current = layout;
704 snprintf(buf, sizeof(buf), "layout,%s", layout);
705 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
709 * Return if the first item should follow the last and vice versa
711 * @param obj The slideshow object
712 * @returns Returns the loop flag
717 elm_slideshow_loop_get(const Evas_Object *obj)
719 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
720 Widget_Data *wd = elm_widget_data_get(obj);
721 if (!wd) return EINA_FALSE;
726 * Delete all the items
728 * @param obj The slideshow object
733 elm_slideshow_clear(Evas_Object *obj)
735 Elm_Slideshow_Item *item;
736 ELM_CHECK_WIDTYPE(obj, widtype);
737 Widget_Data *wd = elm_widget_data_get(obj);
741 EINA_LIST_FREE(wd->items_built, item)
743 if (item->itc->func.del)
744 item->itc->func.del((void*)item->base.data, item->base.view);
745 evas_object_del(item->base.view);
746 item->base.view = NULL;
749 EINA_LIST_FREE(wd->items, item)
751 elm_widget_item_del(item);
758 * @param item The slideshow item
763 elm_slideshow_item_del(Elm_Slideshow_Item *item)
765 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
766 Widget_Data *wd = elm_widget_data_get(item->base.widget);
768 if (wd->previous == item) wd->previous = NULL;
769 if (wd->current == item)
771 Eina_List *l = eina_list_data_find_list(wd->items, item);
772 Eina_List *l2 = eina_list_next(l);
775 l2 = eina_list_nth_list(wd->items, eina_list_count(wd->items) - 1);
777 elm_slideshow_show(eina_list_data_get(l2));
780 wd->items = eina_list_remove_list(wd->items, item->l);
781 wd->items_built = eina_list_remove_list(wd->items_built, item->l_built);
783 if ((item->base.view) && (item->itc->func.del))
784 item->itc->func.del((void*)item->base.data, item->base.view);
786 evas_object_del(item->base.view);
791 * Returns the list of items
792 * @param obj The slideshow object
793 * @return Returns the list of items (list of Elm_Slideshow_Item).
797 EAPI const Eina_List *
798 elm_slideshow_items_get(const Evas_Object *obj)
800 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
801 Widget_Data *wd = elm_widget_data_get(obj);
802 if (!wd) return NULL;
807 * Returns the current item displayed
809 * @param obj The slideshow object
810 * @return Returns the current item displayed
814 EAPI Elm_Slideshow_Item *
815 elm_slideshow_item_current_get(const Evas_Object *obj)
817 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
818 Widget_Data *wd = elm_widget_data_get(obj);
819 if (!wd) return NULL;
824 * Returns the evas object associated to an item
826 * @param item The slideshow item
827 * @return Returns the evas object associated to this item
832 elm_slideshow_item_object_get(const Elm_Slideshow_Item * item)
834 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
835 return item->base.view;
839 * Returns the data associated to an item
841 * @param item The slideshow item
842 * @return Returns the data associated to this item
847 elm_slideshow_item_data_get(const Elm_Slideshow_Item * item)
849 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
850 return elm_widget_item_data_get(item);
854 * Returns max amount of cached items before current
856 * @param obj The slideshow object
857 * @return Returns max amount of cached items
862 elm_slideshow_cache_before_get(const Evas_Object *obj)
864 ELM_CHECK_WIDTYPE(obj, widtype) -1;
865 Widget_Data *wd = elm_widget_data_get(obj);
867 return wd->count_item_pre_before;
871 * Set max amount of cached items before current
873 * @param obj The slideshow object
874 * @param count Max amount of cached items
879 elm_slideshow_cache_before_set(Evas_Object *obj, int count)
881 ELM_CHECK_WIDTYPE(obj, widtype);
882 Widget_Data *wd = elm_widget_data_get(obj);
884 if (count < 0) count = 0;
885 wd->count_item_pre_before = count;
889 * Returns max amount of cached items after current
891 * @param obj The slideshow object
892 * @return Returns max amount of cached items
897 elm_slideshow_cache_after_get(const Evas_Object *obj)
899 ELM_CHECK_WIDTYPE(obj, widtype) -1;
900 Widget_Data *wd = elm_widget_data_get(obj);
902 return wd->count_item_pre_after;
906 * Set max amount of cached items after current
908 * @param obj The slideshow object
909 * @param count max amount of cached items
914 elm_slideshow_cache_after_set(Evas_Object *obj, int count)
916 ELM_CHECK_WIDTYPE(obj, widtype);
917 Widget_Data *wd = elm_widget_data_get(obj);
919 if (count < 0) count = 0;
920 wd->count_item_pre_after = count;