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.
18 typedef struct _Widget_Data Widget_Data;
20 struct _Elm_Slideshow_Item
24 Eina_List *l, *l_built;
26 const Elm_Slideshow_Item_Class *itc;
31 Evas_Object *slideshow;
33 // list of Elm_Slideshow_Item*
35 Eina_List *items_built;
37 Elm_Slideshow_Item *current;
38 Elm_Slideshow_Item *previous;
40 Eina_List *transitions;
41 const char *transition;
49 Eina_List *list; //list of const char *
53 static const char *widtype = NULL;
54 static void _del_hook(Evas_Object *obj);
55 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
56 static void _theme_hook(Evas_Object *obj);
57 static void _sizing_eval(Evas_Object *obj);
58 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
59 static Eina_Bool _timer_cb(void *data);
60 static void _on_focus_hook(void *data, Evas_Object *obj);
61 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src,
62 Evas_Callback_Type type, void *event_info);
65 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
67 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
68 Evas_Event_Key_Down *ev = event_info;
69 Widget_Data *wd = elm_widget_data_get(obj);
70 if (!wd) return EINA_FALSE;
71 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
72 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
73 if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")))
75 elm_slideshow_previous(obj);
76 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
79 if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")))
81 elm_slideshow_next(obj);
82 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
85 if ((!strcmp(ev->keyname, "Return")) ||
86 (!strcmp(ev->keyname, "KP_Enter")) ||
87 (!strcmp(ev->keyname, "space")))
93 ecore_timer_del(wd->timer);
97 elm_slideshow_timeout_set(obj, wd->timeout);
99 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
106 _del_hook(Evas_Object *obj)
109 Widget_Data *wd = elm_widget_data_get(obj);
111 elm_slideshow_clear(obj);
112 elm_widget_stringlist_free(wd->transitions);
113 if (wd->timer) ecore_timer_del(wd->timer);
114 EINA_LIST_FREE(wd->layout.list, layout)
115 eina_stringshare_del(layout);
120 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
122 Widget_Data *wd = elm_widget_data_get(obj);
124 if (elm_widget_focus_get(obj))
126 edje_object_signal_emit(wd->slideshow, "elm,action,focus", "elm");
127 evas_object_focus_set(wd->slideshow, EINA_TRUE);
131 edje_object_signal_emit(wd->slideshow, "elm,action,unfocus", "elm");
132 evas_object_focus_set(wd->slideshow, EINA_FALSE);
137 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
139 Widget_Data *wd = elm_widget_data_get(obj);
141 edje_object_mirrored_set(wd->slideshow, rtl);
145 _theme_hook(Evas_Object *obj)
147 Widget_Data *wd = elm_widget_data_get(obj);
149 _elm_widget_mirrored_reload(obj);
150 _mirrored_set(obj, elm_widget_mirrored_get(obj));
151 _elm_theme_object_set(obj, wd->slideshow, "slideshow", "base", elm_widget_style_get(obj));
152 edje_object_scale_set(wd->slideshow, elm_widget_scale_get(obj) *
158 _sizing_eval(Evas_Object *obj)
160 Widget_Data *wd = elm_widget_data_get(obj);
161 Evas_Coord minw = -1, minh = -1;
163 edje_object_size_min_calc(wd->slideshow, &minw, &minh);
164 evas_object_size_hint_min_set(obj, minw, minh);
165 evas_object_size_hint_max_set(obj, minw, minh);
169 static Elm_Slideshow_Item* _item_prev_get(Elm_Slideshow_Item* item)
171 Widget_Data *wd = elm_widget_data_get(item->base.widget);
172 Elm_Slideshow_Item* prev = eina_list_data_get(eina_list_prev(item->l));
173 if((!prev) && (wd->loop))
174 prev = eina_list_data_get(eina_list_last(item->l));
178 static Elm_Slideshow_Item* _item_next_get(Elm_Slideshow_Item* item)
180 Widget_Data *wd = elm_widget_data_get(item->base.widget);
181 Elm_Slideshow_Item* next = eina_list_data_get(eina_list_next(item->l));
182 if((!next) && (wd->loop))
183 next = eina_list_data_get(wd->items);
189 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
195 _sub_del(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
201 _item_realize(Elm_Slideshow_Item *item)
203 Elm_Slideshow_Item *_item;
204 Evas_Object *obj = item->base.widget;
205 Widget_Data *wd = elm_widget_data_get(obj);
208 if ((!item->base.view) && (item->itc->func.get))
210 item->base.view = item->itc->func.get((void*)item->base.data, obj);
211 evas_object_smart_member_add(item->base.view, obj);
212 item->l_built = eina_list_append(NULL, item);
213 wd->items_built = eina_list_merge(wd->items_built, item->l_built);
214 evas_object_hide(item->base.view);
216 else if (item->l_built)
217 wd->items_built = eina_list_demote_list(wd->items_built, item->l_built);
219 //pre-create previous and next item
220 _item = _item_next_get(item);
221 if ((_item) && (!_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) && (_item->l_built))
230 wd->items_built = eina_list_demote_list(wd->items_built, _item->l_built);
232 _item = _item_prev_get(item);
233 if ((_item) && (!_item->base.view) && (_item->itc->func.get))
235 _item->base.view = _item->itc->func.get((void*)_item->base.data, obj);
236 evas_object_smart_member_add(_item->base.view, obj);
237 _item->l_built = eina_list_append(NULL, _item);
238 wd->items_built = eina_list_merge(wd->items_built, _item->l_built);
239 evas_object_hide(_item->base.view);
241 else if ((_item) && (_item->l_built))
242 wd->items_built = eina_list_demote_list(wd->items_built, _item->l_built);
244 //delete unused items
245 while (eina_list_count(wd->items_built) > 3)
247 _item = eina_list_data_get(wd->items_built);
248 wd->items_built = eina_list_remove_list(wd->items_built, wd->items_built);
249 if(item->itc->func.del)
250 item->itc->func.del((void*)item->base.data, _item->base.view);
251 evas_object_del(_item->base.view);
252 _item->base.view = NULL;
257 _end(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
259 Elm_Slideshow_Item *item;
260 Widget_Data *wd = elm_widget_data_get(data);
266 edje_object_part_unswallow(NULL, item->base.view);
267 evas_object_hide(item->base.view);
273 if ((!item) || (!item->base.view)) return;
276 edje_object_part_unswallow(NULL, item->base.view);
277 evas_object_show(item->base.view);
279 edje_object_signal_emit(wd->slideshow, "anim,end", "slideshow");
280 edje_object_part_swallow(wd->slideshow, "elm.swallow.1", item->base.view);
285 _timer_cb(void *data)
287 Evas_Object *obj = data;
288 Widget_Data *wd = elm_widget_data_get(obj);
289 if (!wd) return ECORE_CALLBACK_CANCEL;
291 elm_slideshow_next(obj);
292 return ECORE_CALLBACK_CANCEL;
298 * Add a new slideshow to the parent
300 * @param parent The parent object
301 * @return The new object or NULL if it cannot be created
306 elm_slideshow_add(Evas_Object *parent)
312 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
314 wd = ELM_NEW(Widget_Data);
315 e = evas_object_evas_get(parent);
317 obj = elm_widget_add(e);
318 ELM_SET_WIDTYPE(widtype, "slideshow");
319 elm_widget_type_set(obj, "slideshow");
320 elm_widget_sub_object_add(parent, obj);
321 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
322 elm_widget_data_set(obj, wd);
323 elm_widget_del_hook_set(obj, _del_hook);
324 elm_widget_theme_hook_set(obj, _theme_hook);
325 elm_widget_can_focus_set(obj, EINA_TRUE);
326 elm_widget_event_hook_set(obj, _event_hook);
331 wd->slideshow = edje_object_add(e);
332 _elm_theme_object_set(obj, wd->slideshow, "slideshow", "base", "default");
333 evas_object_smart_member_add(wd->slideshow, obj);
334 elm_widget_resize_object_set(obj, wd->slideshow);
335 evas_object_show(wd->slideshow);
337 wd->transitions = elm_widget_stringlist_get(edje_object_data_get(wd->slideshow, "transitions"));
338 if (eina_list_count(wd->transitions) > 0)
339 wd->transition = eina_stringshare_add(eina_list_data_get(wd->transitions));
341 wd->layout.list = elm_widget_stringlist_get(edje_object_data_get(wd->slideshow, "layouts"));
342 if (eina_list_count(wd->layout.list) > 0)
343 wd->layout.current = eina_list_data_get(wd->layout.list);
345 edje_object_signal_callback_add(wd->slideshow, "end", "slideshow", _end, obj);
347 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
348 evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
350 _mirrored_set(obj, elm_widget_mirrored_get(obj));
356 * Add a object in the list. The object can be a evas object image or a elm photo for example.
358 * @param obj The slideshow object
359 * @aram itc Callbacks used to create the object and delete the data associated when the item is deleted.
360 * @param data Data used by the user to identified the item
361 * @return Returns The slideshow item
365 EAPI Elm_Slideshow_Item*
366 elm_slideshow_item_add(Evas_Object *obj, const Elm_Slideshow_Item_Class *itc, const void *data)
368 Elm_Slideshow_Item *item;
369 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
370 Widget_Data *wd = elm_widget_data_get(obj);
372 if (!wd) return NULL;
373 item = elm_widget_item_new(obj, Elm_Slideshow_Item);
374 item->base.data = data;
376 item->l = eina_list_append(item->l, item);
378 wd->items = eina_list_merge(wd->items, item->l);
380 if (!wd->current) elm_slideshow_show(item);
388 * @param obj The slideshow object
389 * @param item The item
394 elm_slideshow_show(Elm_Slideshow_Item *item)
397 Elm_Slideshow_Item *next = NULL;
399 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
400 wd = elm_widget_data_get(item->base.widget);
403 if (item == wd->current)
407 _end(item->base.widget, item->base.widget, NULL, NULL);
409 if (wd->timer) ecore_timer_del(wd->timer);
410 if (wd->timeout > 0.0)
411 wd->timer = ecore_timer_add(wd->timeout, _timer_cb, item->base.widget);
413 edje_object_part_swallow(wd->slideshow, "elm.swallow.2", next->base.view);
414 evas_object_show(next->base.view);
415 snprintf(buf, sizeof(buf), "%s,next", wd->transition);
416 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
417 wd->previous = wd->current;
419 evas_object_smart_callback_call(item->base.widget, "changed", wd->current);
423 * Go to the next item
425 * @param obj The slideshow object
430 elm_slideshow_next(Evas_Object *obj)
433 Elm_Slideshow_Item *next = NULL;
434 ELM_CHECK_WIDTYPE(obj, widtype);
435 Widget_Data *wd = elm_widget_data_get(obj);
440 next = _item_next_get(wd->current);
442 if ((!next) || (next == wd->current)) return;
444 _end(obj, obj, NULL, NULL);
446 if (wd->timer) ecore_timer_del(wd->timer);
447 if (wd->timeout > 0.0)
448 wd->timer = ecore_timer_add(wd->timeout, _timer_cb, obj);
452 edje_object_part_swallow(wd->slideshow, "elm.swallow.2", next->base.view);
453 evas_object_show(next->base.view);
455 snprintf(buf, sizeof(buf), "%s,next", wd->transition);
456 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
458 wd->previous = wd->current;
460 evas_object_smart_callback_call(obj, "changed", wd->current);
464 * Go to the previous item
466 * @param obj The slideshow object
471 elm_slideshow_previous(Evas_Object *obj)
474 Elm_Slideshow_Item *prev = NULL;
475 ELM_CHECK_WIDTYPE(obj, widtype);
476 Widget_Data *wd = elm_widget_data_get(obj);
481 prev = _item_prev_get(wd->current);
483 if ((!prev) || (prev == wd->current)) return;
485 _end(obj, obj, NULL, NULL);
487 if (wd->timer) ecore_timer_del(wd->timer);
488 if (wd->timeout > 0.0)
489 wd->timer = ecore_timer_add(wd->timeout, _timer_cb, obj);
493 edje_object_part_swallow(wd->slideshow, "elm.swallow.2", prev->base.view);
494 evas_object_show(prev->base.view);
496 snprintf(buf, 1024, "%s,previous", wd->transition);
497 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
499 wd->previous = wd->current;
501 evas_object_smart_callback_call(obj, "changed", wd->current);
505 * Returns the list of transitions available.
507 * @param obj The slideshow object
508 * @return Returns the list of transitions (list of const char*)
512 EAPI const Eina_List *
513 elm_slideshow_transitions_get(const Evas_Object *obj)
515 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
516 Widget_Data *wd = elm_widget_data_get(obj);
517 if (!wd) return NULL;
518 return wd->transitions;
522 * Returns the list of layouts available.
524 * @param obj The slideshow object
525 * @return Returns the list of layout (list of const char*)
529 EAPI const Eina_List *
530 elm_slideshow_layouts_get(const Evas_Object *obj)
532 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
533 Widget_Data *wd = elm_widget_data_get(obj);
534 if (!wd) return NULL;
535 return wd->layout.list;
539 * Set the transition to use
541 * @param obj The slideshow object
542 * @param transition the new transition
547 elm_slideshow_transition_set(Evas_Object *obj, const char *transition)
549 ELM_CHECK_WIDTYPE(obj, widtype);
550 Widget_Data *wd = elm_widget_data_get(obj);
552 eina_stringshare_replace(&wd->transition, transition);
556 * Returns the transition to use
558 * @param obj The slideshow object
559 * @return the transition set
564 elm_slideshow_transition_get(const Evas_Object *obj)
566 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
567 Widget_Data *wd = elm_widget_data_get(obj);
568 if (!wd) return NULL;
569 return wd->transition;
573 * The slideshow can go to the next item automatically after a few seconds.
574 * This method set the timeout to use. A timeout <=0 disable the timer.
576 * @param obj The slideshow object
577 * @param timeout The new timeout
582 elm_slideshow_timeout_set(Evas_Object *obj, double timeout)
584 ELM_CHECK_WIDTYPE(obj, widtype);
585 Widget_Data *wd = elm_widget_data_get(obj);
587 wd->timeout = timeout;
588 if (wd->timer) ecore_timer_del(wd->timer);
591 wd->timer = ecore_timer_add(timeout, _timer_cb, obj);
595 * Returns the timeout value
597 * @param obj The slideshow object
598 * @return Returns the timeout
603 elm_slideshow_timeout_get(const Evas_Object *obj)
605 ELM_CHECK_WIDTYPE(obj, widtype) -1.0;
606 Widget_Data *wd = elm_widget_data_get(obj);
607 if (!wd) return -1.0;
612 * Set if the first item should follow the last and vice versa
614 * @param obj The slideshow object
615 * @param loop if EINA_TRUE, the first item will follow the last and vice versa
620 elm_slideshow_loop_set(Evas_Object *obj, Eina_Bool loop)
622 ELM_CHECK_WIDTYPE(obj, widtype);
623 Widget_Data *wd = elm_widget_data_get(obj);
629 * Returns the current layout name
631 * @param obj The slideshow object
632 * @returns Returns the layout name
637 elm_slideshow_layout_get(const Evas_Object *obj)
639 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
640 Widget_Data *wd = elm_widget_data_get(obj);
641 if (!wd) return EINA_FALSE;
642 return wd->layout.current;
648 * @param obj The slideshow object
649 * @param layout the new layout
654 elm_slideshow_layout_set(Evas_Object *obj, const char *layout)
657 ELM_CHECK_WIDTYPE(obj, widtype);
658 Widget_Data *wd = elm_widget_data_get(obj);
661 wd->layout.current = layout;
662 snprintf(buf, sizeof(buf), "layout,%s", layout);
663 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
667 * Return if the first item should follow the last and vice versa
669 * @param obj The slideshow object
670 * @returns Returns the loop flag
675 elm_slideshow_loop_get(const Evas_Object *obj)
677 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
678 Widget_Data *wd = elm_widget_data_get(obj);
679 if (!wd) return EINA_FALSE;
684 * Delete all the items
686 * @param obj The slideshow object
691 elm_slideshow_clear(Evas_Object *obj)
693 Elm_Slideshow_Item *item;
694 ELM_CHECK_WIDTYPE(obj, widtype);
695 Widget_Data *wd = elm_widget_data_get(obj);
699 EINA_LIST_FREE(wd->items_built, item)
701 if (item->itc->func.del)
702 item->itc->func.del((void*)item->base.data, item->base.view);
703 evas_object_del(item->base.view);
704 item->base.view = NULL;
707 EINA_LIST_FREE(wd->items, item)
709 elm_widget_item_del(item);
717 * @param item The slideshow item
722 elm_slideshow_item_del(Elm_Slideshow_Item *item)
724 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
725 Widget_Data *wd = elm_widget_data_get(item->base.widget);
727 if (wd->previous == item) wd->previous = NULL;
728 if (wd->current == item)
730 Eina_List *l = eina_list_data_find_list(wd->items, item);
731 Eina_List *l2 = eina_list_next(l);
734 l2 = eina_list_nth_list(wd->items, eina_list_count(wd->items) - 1);
736 elm_slideshow_show(eina_list_data_get(l2));
739 wd->items = eina_list_remove_list(wd->items, item->l);
740 wd->items_built = eina_list_remove_list(wd->items_built, item->l_built);
742 if ((item->base.view) && (item->itc->func.del))
743 item->itc->func.del((void*)item->base.data, item->base.view);
745 evas_object_del(item->base.view);
750 * Returns the list of items
751 * @param obj The slideshow object
752 * @return Returns the list of items (list of Elm_Slideshow_Item).
756 EAPI const Eina_List *
757 elm_slideshow_items_get(const Evas_Object *obj)
759 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
760 Widget_Data *wd = elm_widget_data_get(obj);
761 if (!wd) return NULL;
767 * Returns the current item displayed
769 * @param obj The slideshow object
770 * @return Returns the current item displayed
774 EAPI Elm_Slideshow_Item *
775 elm_slideshow_item_current_get(const Evas_Object *obj)
777 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
778 Widget_Data *wd = elm_widget_data_get(obj);
779 if (!wd) return NULL;
784 * Returns the evas object associated to an item
786 * @param item The slideshow item
787 * @return Returns the evas object associated to this item
792 elm_slideshow_item_object_get(const Elm_Slideshow_Item * item)
794 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
795 return item->base.view;
799 * Returns the data associated to an item
801 * @param item The slideshow item
802 * @return Returns the data associated to this item
807 elm_slideshow_item_data_get(const Elm_Slideshow_Item * item)
809 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
810 return elm_widget_item_data_get(item);