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[] = {
80 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
82 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
83 Evas_Event_Key_Down *ev = event_info;
84 Widget_Data *wd = elm_widget_data_get(obj);
85 if (!wd) return EINA_FALSE;
86 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
87 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
88 if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")))
90 elm_slideshow_previous(obj);
91 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
94 if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")))
96 elm_slideshow_next(obj);
97 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
100 if ((!strcmp(ev->keyname, "Return")) ||
101 (!strcmp(ev->keyname, "KP_Enter")) ||
102 (!strcmp(ev->keyname, "space")))
108 ecore_timer_del(wd->timer);
112 elm_slideshow_timeout_set(obj, wd->timeout);
114 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
121 _del_hook(Evas_Object *obj)
124 Widget_Data *wd = elm_widget_data_get(obj);
126 elm_slideshow_clear(obj);
127 elm_widget_stringlist_free(wd->transitions);
128 if (wd->timer) ecore_timer_del(wd->timer);
129 EINA_LIST_FREE(wd->layout.list, layout)
130 eina_stringshare_del(layout);
135 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
137 Widget_Data *wd = elm_widget_data_get(obj);
139 if (elm_widget_focus_get(obj))
141 edje_object_signal_emit(wd->slideshow, "elm,action,focus", "elm");
142 evas_object_focus_set(wd->slideshow, EINA_TRUE);
146 edje_object_signal_emit(wd->slideshow, "elm,action,unfocus", "elm");
147 evas_object_focus_set(wd->slideshow, EINA_FALSE);
152 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
154 Widget_Data *wd = elm_widget_data_get(obj);
156 edje_object_mirrored_set(wd->slideshow, rtl);
160 _theme_hook(Evas_Object *obj)
162 Widget_Data *wd = elm_widget_data_get(obj);
164 _elm_widget_mirrored_reload(obj);
165 _mirrored_set(obj, elm_widget_mirrored_get(obj));
166 _elm_theme_object_set(obj, wd->slideshow, "slideshow", "base", elm_widget_style_get(obj));
167 edje_object_scale_set(wd->slideshow, elm_widget_scale_get(obj) *
173 _sizing_eval(Evas_Object *obj)
175 Widget_Data *wd = elm_widget_data_get(obj);
176 Evas_Coord minw = -1, minh = -1;
178 edje_object_size_min_calc(wd->slideshow, &minw, &minh);
179 evas_object_size_hint_min_set(obj, minw, minh);
180 evas_object_size_hint_max_set(obj, minw, minh);
184 static Elm_Slideshow_Item* _item_prev_get(Elm_Slideshow_Item* item)
186 Widget_Data *wd = elm_widget_data_get(item->base.widget);
187 Elm_Slideshow_Item* prev = eina_list_data_get(eina_list_prev(item->l));
188 if((!prev) && (wd->loop))
189 prev = eina_list_data_get(eina_list_last(item->l));
193 static Elm_Slideshow_Item* _item_next_get(Elm_Slideshow_Item* item)
195 Widget_Data *wd = elm_widget_data_get(item->base.widget);
196 Elm_Slideshow_Item* next = eina_list_data_get(eina_list_next(item->l));
197 if((!next) && (wd->loop))
198 next = eina_list_data_get(wd->items);
204 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
210 _sub_del(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
216 _item_realize(Elm_Slideshow_Item *item)
218 Elm_Slideshow_Item *_item_prev, *_item_next;
219 Evas_Object *obj = item->base.widget;
220 Widget_Data *wd = elm_widget_data_get(obj);
224 if ((!item->base.view) && (item->itc->func.get))
226 item->base.view = item->itc->func.get((void*)item->base.data, obj);
227 evas_object_smart_member_add(item->base.view, obj);
228 item->l_built = eina_list_append(NULL, item);
229 wd->items_built = eina_list_merge(wd->items_built, item->l_built);
230 evas_object_hide(item->base.view);
232 else if (item->l_built)
233 wd->items_built = eina_list_demote_list(wd->items_built, item->l_built);
235 //pre-create previous and next item
236 ac = wd->count_item_pre_after;
238 bc = wd->count_item_pre_before;
240 lc = eina_list_count(wd->items) - 1;
241 while (lc > 0 && ((ac > 0) || (bc > 0)))
243 if (lc > 0 && ac > 0)
247 _item_next = _item_next_get(_item_next);
249 && (!_item_next->base.view)
250 && (_item_next->itc->func.get))
252 _item_next->base.view =
253 _item_next->itc->func.get((void*)_item_next->base.data,
255 evas_object_smart_member_add(_item_next->base.view, obj);
256 _item_next->l_built = eina_list_append(NULL, _item_next);
257 wd->items_built = eina_list_merge(wd->items_built,
258 _item_next->l_built);
259 evas_object_hide(_item_next->base.view);
261 else if (_item_next && _item_next->l_built)
262 wd->items_built = eina_list_demote_list(wd->items_built,
263 _item_next->l_built);
266 if (lc > 0 && bc > 0)
270 _item_prev = _item_prev_get(_item_prev);
272 && (!_item_prev->base.view)
273 && (_item_prev->itc->func.get))
275 _item_prev->base.view =
276 _item_prev->itc->func.get((void*)_item_prev->base.data,
278 evas_object_smart_member_add(_item_prev->base.view, obj);
279 _item_prev->l_built = eina_list_append(NULL, _item_prev);
280 wd->items_built = eina_list_merge(wd->items_built,
281 _item_prev->l_built);
282 evas_object_hide(_item_prev->base.view);
284 else if (_item_prev && _item_prev->l_built)
285 wd->items_built = eina_list_demote_list(wd->items_built,
286 _item_prev->l_built);
290 //delete unused items
291 lc = wd->count_item_pre_before + wd->count_item_pre_after + 1;
292 while (eina_list_count(wd->items_built) > lc)
294 item = eina_list_data_get(wd->items_built);
295 wd->items_built = eina_list_remove_list(wd->items_built,
297 if(item->itc->func.del)
298 item->itc->func.del((void*)item->base.data, item->base.view);
299 evas_object_del(item->base.view);
300 item->base.view = NULL;
305 _end(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
307 Elm_Slideshow_Item *item;
308 Widget_Data *wd = elm_widget_data_get(data);
314 edje_object_part_unswallow(NULL, item->base.view);
315 evas_object_hide(item->base.view);
321 if ((!item) || (!item->base.view)) return;
324 edje_object_part_unswallow(NULL, item->base.view);
325 evas_object_show(item->base.view);
327 edje_object_signal_emit(wd->slideshow, "anim,end", "slideshow");
328 edje_object_part_swallow(wd->slideshow, "elm.swallow.1", item->base.view);
333 _timer_cb(void *data)
335 Evas_Object *obj = data;
336 Widget_Data *wd = elm_widget_data_get(obj);
337 if (!wd) return ECORE_CALLBACK_CANCEL;
339 elm_slideshow_next(obj);
340 return ECORE_CALLBACK_CANCEL;
346 * Add a new slideshow to the parent
348 * @param parent The parent object
349 * @return The new object or NULL if it cannot be created
354 elm_slideshow_add(Evas_Object *parent)
360 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
362 ELM_SET_WIDTYPE(widtype, "slideshow");
363 elm_widget_type_set(obj, "slideshow");
364 elm_widget_sub_object_add(parent, obj);
365 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
366 elm_widget_data_set(obj, wd);
367 elm_widget_del_hook_set(obj, _del_hook);
368 elm_widget_theme_hook_set(obj, _theme_hook);
369 elm_widget_can_focus_set(obj, EINA_TRUE);
370 elm_widget_event_hook_set(obj, _event_hook);
375 wd->slideshow = edje_object_add(e);
376 _elm_theme_object_set(obj, wd->slideshow, "slideshow", "base", "default");
377 evas_object_smart_member_add(wd->slideshow, obj);
378 wd->count_item_pre_before = 2;
379 wd->count_item_pre_after = 2;
380 elm_widget_resize_object_set(obj, wd->slideshow);
381 evas_object_show(wd->slideshow);
383 wd->transitions = elm_widget_stringlist_get(edje_object_data_get(wd->slideshow, "transitions"));
384 if (eina_list_count(wd->transitions) > 0)
385 wd->transition = eina_stringshare_add(eina_list_data_get(wd->transitions));
387 wd->layout.list = elm_widget_stringlist_get(edje_object_data_get(wd->slideshow, "layouts"));
388 if (eina_list_count(wd->layout.list) > 0)
389 wd->layout.current = eina_list_data_get(wd->layout.list);
391 edje_object_signal_callback_add(wd->slideshow, "end", "slideshow", _end, obj);
393 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
394 evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
396 evas_object_smart_callbacks_descriptions_set(obj, _signals);
398 _mirrored_set(obj, elm_widget_mirrored_get(obj));
404 * Add a object in the list. The object can be a evas object image or a elm photo for example.
406 * @param obj The slideshow object
407 * @aram itc Callbacks used to create the object and delete the data associated when the item is deleted.
408 * @param data Data used by the user to identified the item
409 * @return Returns The slideshow item
413 EAPI Elm_Slideshow_Item*
414 elm_slideshow_item_add(Evas_Object *obj, const Elm_Slideshow_Item_Class *itc, const void *data)
416 Elm_Slideshow_Item *item;
417 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
418 Widget_Data *wd = elm_widget_data_get(obj);
420 if (!wd) return NULL;
421 item = elm_widget_item_new(obj, Elm_Slideshow_Item);
422 item->base.data = data;
424 item->l = eina_list_append(item->l, item);
426 wd->items = eina_list_merge(wd->items, item->l);
428 if (!wd->current) elm_slideshow_show(item);
436 * @param obj The slideshow object
437 * @param item The item
442 elm_slideshow_show(Elm_Slideshow_Item *item)
445 Elm_Slideshow_Item *next = NULL;
447 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
448 wd = elm_widget_data_get(item->base.widget);
451 if (item == wd->current)
455 _end(item->base.widget, item->base.widget, NULL, NULL);
457 if (wd->timer) ecore_timer_del(wd->timer);
458 if (wd->timeout > 0.0)
459 wd->timer = ecore_timer_add(wd->timeout, _timer_cb, item->base.widget);
461 edje_object_part_swallow(wd->slideshow, "elm.swallow.2", next->base.view);
462 evas_object_show(next->base.view);
463 snprintf(buf, sizeof(buf), "%s,next", wd->transition);
464 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
465 wd->previous = wd->current;
467 evas_object_smart_callback_call(item->base.widget, SIG_CHANGED, wd->current);
471 * Go to the next item
473 * @param obj The slideshow object
478 elm_slideshow_next(Evas_Object *obj)
481 Elm_Slideshow_Item *next = NULL;
482 ELM_CHECK_WIDTYPE(obj, widtype);
483 Widget_Data *wd = elm_widget_data_get(obj);
488 next = _item_next_get(wd->current);
490 if ((!next) || (next == wd->current)) return;
492 _end(obj, obj, NULL, NULL);
494 if (wd->timer) ecore_timer_del(wd->timer);
495 if (wd->timeout > 0.0)
496 wd->timer = ecore_timer_add(wd->timeout, _timer_cb, obj);
500 edje_object_part_swallow(wd->slideshow, "elm.swallow.2", next->base.view);
501 evas_object_show(next->base.view);
503 snprintf(buf, sizeof(buf), "%s,next", wd->transition);
504 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
506 wd->previous = wd->current;
508 evas_object_smart_callback_call(obj, SIG_CHANGED, wd->current);
512 * Go to the previous item
514 * @param obj The slideshow object
519 elm_slideshow_previous(Evas_Object *obj)
522 Elm_Slideshow_Item *prev = NULL;
523 ELM_CHECK_WIDTYPE(obj, widtype);
524 Widget_Data *wd = elm_widget_data_get(obj);
529 prev = _item_prev_get(wd->current);
531 if ((!prev) || (prev == wd->current)) return;
533 _end(obj, obj, NULL, NULL);
535 if (wd->timer) ecore_timer_del(wd->timer);
536 if (wd->timeout > 0.0)
537 wd->timer = ecore_timer_add(wd->timeout, _timer_cb, obj);
541 edje_object_part_swallow(wd->slideshow, "elm.swallow.2", prev->base.view);
542 evas_object_show(prev->base.view);
544 snprintf(buf, 1024, "%s,previous", wd->transition);
545 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
547 wd->previous = wd->current;
549 evas_object_smart_callback_call(obj, SIG_CHANGED, wd->current);
553 * Returns the list of transitions available.
555 * @param obj The slideshow object
556 * @return Returns the list of transitions (list of const char*)
560 EAPI const Eina_List *
561 elm_slideshow_transitions_get(const Evas_Object *obj)
563 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
564 Widget_Data *wd = elm_widget_data_get(obj);
565 if (!wd) return NULL;
566 return wd->transitions;
570 * Returns the list of layouts available.
572 * @param obj The slideshow object
573 * @return Returns the list of layout (list of const char*)
577 EAPI const Eina_List *
578 elm_slideshow_layouts_get(const Evas_Object *obj)
580 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
581 Widget_Data *wd = elm_widget_data_get(obj);
582 if (!wd) return NULL;
583 return wd->layout.list;
587 * Set the transition to use
589 * @param obj The slideshow object
590 * @param transition the new transition
595 elm_slideshow_transition_set(Evas_Object *obj, const char *transition)
597 ELM_CHECK_WIDTYPE(obj, widtype);
598 Widget_Data *wd = elm_widget_data_get(obj);
600 eina_stringshare_replace(&wd->transition, transition);
604 * Returns the transition to use
606 * @param obj The slideshow object
607 * @return the transition set
612 elm_slideshow_transition_get(const Evas_Object *obj)
614 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
615 Widget_Data *wd = elm_widget_data_get(obj);
616 if (!wd) return NULL;
617 return wd->transition;
621 * The slideshow can go to the next item automatically after a few seconds.
622 * This method set the timeout to use. A timeout <=0 disable the timer.
624 * @param obj The slideshow object
625 * @param timeout The new timeout
630 elm_slideshow_timeout_set(Evas_Object *obj, double timeout)
632 ELM_CHECK_WIDTYPE(obj, widtype);
633 Widget_Data *wd = elm_widget_data_get(obj);
635 wd->timeout = timeout;
636 if (wd->timer) ecore_timer_del(wd->timer);
639 wd->timer = ecore_timer_add(timeout, _timer_cb, obj);
643 * Returns the timeout value
645 * @param obj The slideshow object
646 * @return Returns the timeout
651 elm_slideshow_timeout_get(const Evas_Object *obj)
653 ELM_CHECK_WIDTYPE(obj, widtype) -1.0;
654 Widget_Data *wd = elm_widget_data_get(obj);
655 if (!wd) return -1.0;
660 * Set if the first item should follow the last and vice versa
662 * @param obj The slideshow object
663 * @param loop if EINA_TRUE, the first item will follow the last and vice versa
668 elm_slideshow_loop_set(Evas_Object *obj, Eina_Bool loop)
670 ELM_CHECK_WIDTYPE(obj, widtype);
671 Widget_Data *wd = elm_widget_data_get(obj);
677 * Returns the current layout name
679 * @param obj The slideshow object
680 * @returns Returns the layout name
685 elm_slideshow_layout_get(const Evas_Object *obj)
687 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
688 Widget_Data *wd = elm_widget_data_get(obj);
689 if (!wd) return EINA_FALSE;
690 return wd->layout.current;
696 * @param obj The slideshow object
697 * @param layout the new layout
702 elm_slideshow_layout_set(Evas_Object *obj, const char *layout)
705 ELM_CHECK_WIDTYPE(obj, widtype);
706 Widget_Data *wd = elm_widget_data_get(obj);
709 wd->layout.current = layout;
710 snprintf(buf, sizeof(buf), "layout,%s", layout);
711 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
715 * Return if the first item should follow the last and vice versa
717 * @param obj The slideshow object
718 * @returns Returns the loop flag
723 elm_slideshow_loop_get(const Evas_Object *obj)
725 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
726 Widget_Data *wd = elm_widget_data_get(obj);
727 if (!wd) return EINA_FALSE;
732 * Delete all the items
734 * @param obj The slideshow object
739 elm_slideshow_clear(Evas_Object *obj)
741 Elm_Slideshow_Item *item;
742 ELM_CHECK_WIDTYPE(obj, widtype);
743 Widget_Data *wd = elm_widget_data_get(obj);
747 EINA_LIST_FREE(wd->items_built, item)
749 if (item->itc->func.del)
750 item->itc->func.del((void*)item->base.data, item->base.view);
751 evas_object_del(item->base.view);
752 item->base.view = NULL;
755 EINA_LIST_FREE(wd->items, item)
757 elm_widget_item_del(item);
765 * @param item The slideshow item
770 elm_slideshow_item_del(Elm_Slideshow_Item *item)
772 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
773 Widget_Data *wd = elm_widget_data_get(item->base.widget);
775 if (wd->previous == item) wd->previous = NULL;
776 if (wd->current == item)
778 Eina_List *l = eina_list_data_find_list(wd->items, item);
779 Eina_List *l2 = eina_list_next(l);
782 l2 = eina_list_nth_list(wd->items, eina_list_count(wd->items) - 1);
784 elm_slideshow_show(eina_list_data_get(l2));
787 wd->items = eina_list_remove_list(wd->items, item->l);
788 wd->items_built = eina_list_remove_list(wd->items_built, item->l_built);
790 if ((item->base.view) && (item->itc->func.del))
791 item->itc->func.del((void*)item->base.data, item->base.view);
793 evas_object_del(item->base.view);
798 * Returns the list of items
799 * @param obj The slideshow object
800 * @return Returns the list of items (list of Elm_Slideshow_Item).
804 EAPI const Eina_List *
805 elm_slideshow_items_get(const Evas_Object *obj)
807 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
808 Widget_Data *wd = elm_widget_data_get(obj);
809 if (!wd) return NULL;
815 * Returns the current item displayed
817 * @param obj The slideshow object
818 * @return Returns the current item displayed
822 EAPI Elm_Slideshow_Item *
823 elm_slideshow_item_current_get(const Evas_Object *obj)
825 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
826 Widget_Data *wd = elm_widget_data_get(obj);
827 if (!wd) return NULL;
832 * Returns the evas object associated to an item
834 * @param item The slideshow item
835 * @return Returns the evas object associated to this item
840 elm_slideshow_item_object_get(const Elm_Slideshow_Item * item)
842 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
843 return item->base.view;
847 * Returns the data associated to an item
849 * @param item The slideshow item
850 * @return Returns the data associated to this item
855 elm_slideshow_item_data_get(const Elm_Slideshow_Item * item)
857 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
858 return elm_widget_item_data_get(item);
862 * Returns max amount of cached items before current
864 * @param obj The slideshow object
865 * @return Returns max amount of cached items
870 elm_slideshow_cache_before_get(const Evas_Object *obj)
872 ELM_CHECK_WIDTYPE(obj, widtype) -1;
873 Widget_Data *wd = elm_widget_data_get(obj);
875 return wd->count_item_pre_before;
881 * Set max amount of cached items before current
883 * @param obj The slideshow object
884 * @param count Max amount of cached items
889 elm_slideshow_cache_before_set(Evas_Object *obj, int count)
891 ELM_CHECK_WIDTYPE(obj, widtype);
892 Widget_Data *wd = elm_widget_data_get(obj);
894 if (count < 0) count = 0;
895 wd->count_item_pre_before = count;
899 * Returns max amount of cached items after current
901 * @param obj The slideshow object
902 * @return Returns max amount of cached items
907 elm_slideshow_cache_after_get(const Evas_Object *obj)
909 ELM_CHECK_WIDTYPE(obj, widtype) -1;
910 Widget_Data *wd = elm_widget_data_get(obj);
912 return wd->count_item_pre_after;
918 * Set max amount of cached items after current
920 * @param obj The slideshow object
921 * @param count max amount of cached items
926 elm_slideshow_cache_after_set(Evas_Object *obj, int count)
928 ELM_CHECK_WIDTYPE(obj, widtype);
929 Widget_Data *wd = elm_widget_data_get(obj);
931 if (count < 0) count = 0;
932 wd->count_item_pre_after = count;