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 _mirrored_set(obj, elm_widget_mirrored_get(obj));
150 _elm_theme_object_set(obj, wd->slideshow, "slideshow", "base", elm_widget_style_get(obj));
151 edje_object_scale_set(wd->slideshow, elm_widget_scale_get(obj) *
157 _sizing_eval(Evas_Object *obj)
159 Widget_Data *wd = elm_widget_data_get(obj);
160 Evas_Coord minw = -1, minh = -1;
162 edje_object_size_min_calc(wd->slideshow, &minw, &minh);
163 evas_object_size_hint_min_set(obj, minw, minh);
164 evas_object_size_hint_max_set(obj, minw, minh);
168 static Elm_Slideshow_Item* _item_prev_get(Elm_Slideshow_Item* item)
170 Widget_Data *wd = elm_widget_data_get(item->base.widget);
171 Elm_Slideshow_Item* prev = eina_list_data_get(eina_list_prev(item->l));
172 if((!prev) && (wd->loop))
173 prev = eina_list_data_get(eina_list_last(item->l));
176 static Elm_Slideshow_Item* _item_next_get(Elm_Slideshow_Item* item)
178 Widget_Data *wd = elm_widget_data_get(item->base.widget);
179 Elm_Slideshow_Item* next = eina_list_data_get(eina_list_next(item->l));
180 if((!next) && (wd->loop))
181 next = eina_list_data_get(wd->items);
187 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
193 _sub_del(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
199 _item_realize(Elm_Slideshow_Item *item)
201 Elm_Slideshow_Item *_item;
202 Evas_Object *obj = item->base.widget;
203 Widget_Data *wd = elm_widget_data_get(obj);
206 if ((!item->base.view) && (item->itc->func.get))
208 item->base.view = item->itc->func.get((void*)item->base.data, obj);
209 evas_object_smart_member_add(item->base.view, obj);
210 item->l_built = eina_list_append(NULL, item);
211 wd->items_built = eina_list_merge(wd->items_built, item->l_built);
212 evas_object_hide(item->base.view);
214 else if (item->l_built)
215 wd->items_built = eina_list_demote_list(wd->items_built, item->l_built);
217 //pre-create previous and next item
218 _item = _item_next_get(item);
219 if ((_item) && (!_item->base.view) && (_item->itc->func.get))
221 _item->base.view = _item->itc->func.get((void*)_item->base.data, obj);
222 evas_object_smart_member_add(_item->base.view, obj);
223 _item->l_built = eina_list_append(NULL, _item);
224 wd->items_built = eina_list_merge(wd->items_built, _item->l_built);
225 evas_object_hide(_item->base.view);
227 else if ((_item) && (_item->l_built))
228 wd->items_built = eina_list_demote_list(wd->items_built, _item->l_built);
230 _item = _item_prev_get(item);
231 if ((_item) && (!_item->base.view) && (_item->itc->func.get))
233 _item->base.view = _item->itc->func.get((void*)_item->base.data, obj);
234 evas_object_smart_member_add(_item->base.view, obj);
235 _item->l_built = eina_list_append(NULL, _item);
236 wd->items_built = eina_list_merge(wd->items_built, _item->l_built);
237 evas_object_hide(_item->base.view);
239 else if ((_item) && (_item->l_built))
240 wd->items_built = eina_list_demote_list(wd->items_built, _item->l_built);
242 //delete unused items
243 while (eina_list_count(wd->items_built) > 3)
245 _item = eina_list_data_get(wd->items_built);
246 wd->items_built = eina_list_remove_list(wd->items_built, wd->items_built);
247 if(item->itc->func.del)
248 item->itc->func.del((void*)item->base.data, _item->base.view);
249 evas_object_del(_item->base.view);
250 _item->base.view = NULL;
255 _end(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
257 Elm_Slideshow_Item *item;
258 Widget_Data *wd = elm_widget_data_get(data);
264 edje_object_part_unswallow(NULL, item->base.view);
265 evas_object_hide(item->base.view);
271 if ((!item) || (!item->base.view)) return;
274 edje_object_part_unswallow(NULL, item->base.view);
275 evas_object_show(item->base.view);
277 edje_object_signal_emit(wd->slideshow, "anim,end", "slideshow");
278 edje_object_part_swallow(wd->slideshow, "elm.swallow.1", item->base.view);
283 _timer_cb(void *data)
285 Evas_Object *obj = data;
286 Widget_Data *wd = elm_widget_data_get(obj);
287 if (!wd) return ECORE_CALLBACK_CANCEL;
289 elm_slideshow_next(obj);
290 return ECORE_CALLBACK_CANCEL;
296 * Add a new slideshow to the parent
298 * @param parent The parent object
299 * @return The new object or NULL if it cannot be created
304 elm_slideshow_add(Evas_Object *parent)
310 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
312 wd = ELM_NEW(Widget_Data);
313 e = evas_object_evas_get(parent);
315 obj = elm_widget_add(e);
316 ELM_SET_WIDTYPE(widtype, "slideshow");
317 elm_widget_type_set(obj, "slideshow");
318 elm_widget_sub_object_add(parent, obj);
319 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
320 elm_widget_data_set(obj, wd);
321 elm_widget_del_hook_set(obj, _del_hook);
322 elm_widget_theme_hook_set(obj, _theme_hook);
323 elm_widget_can_focus_set(obj, EINA_TRUE);
324 elm_widget_event_hook_set(obj, _event_hook);
329 wd->slideshow = edje_object_add(e);
330 _elm_theme_object_set(obj, wd->slideshow, "slideshow", "base", "default");
331 evas_object_smart_member_add(wd->slideshow, obj);
332 elm_widget_resize_object_set(obj, wd->slideshow);
333 evas_object_show(wd->slideshow);
335 wd->transitions = elm_widget_stringlist_get(edje_object_data_get(wd->slideshow, "transitions"));
336 if (eina_list_count(wd->transitions) > 0)
337 wd->transition = eina_stringshare_add(eina_list_data_get(wd->transitions));
339 wd->layout.list = elm_widget_stringlist_get(edje_object_data_get(wd->slideshow, "layouts"));
340 if (eina_list_count(wd->layout.list) > 0)
341 wd->layout.current = eina_list_data_get(wd->layout.list);
343 edje_object_signal_callback_add(wd->slideshow, "end", "slideshow", _end, obj);
345 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
346 evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
348 _mirrored_set(obj, elm_widget_mirrored_get(obj));
354 * Add a object in the list. The object can be a evas object image or a elm photo for example.
356 * @param obj The slideshow object
357 * @aram itc Callbacks used to create the object and delete the data associated when the item is deleted.
358 * @param data Data used by the user to identified the item
359 * @return Returns The slideshow item
363 EAPI Elm_Slideshow_Item*
364 elm_slideshow_item_add(Evas_Object *obj, const Elm_Slideshow_Item_Class *itc, const void *data)
366 Elm_Slideshow_Item *item;
367 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
368 Widget_Data *wd = elm_widget_data_get(obj);
370 if (!wd) return NULL;
371 item = elm_widget_item_new(obj, Elm_Slideshow_Item);
372 item->base.data = data;
374 item->l = eina_list_append(item->l, item);
376 wd->items = eina_list_merge(wd->items, item->l);
378 if (!wd->current) elm_slideshow_show(item);
386 * @param obj The slideshow object
387 * @param item The item
392 elm_slideshow_show(Elm_Slideshow_Item *item)
395 Elm_Slideshow_Item *next = NULL;
397 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
398 wd = elm_widget_data_get(item->base.widget);
401 if (item == wd->current)
405 evas_object_smart_callback_call(item->base.widget, "changed", next);
406 _end(item->base.widget, item->base.widget, NULL, NULL);
408 if (wd->timer) ecore_timer_del(wd->timer);
409 if (wd->timeout > 0.0)
410 wd->timer = ecore_timer_add(wd->timeout, _timer_cb, item->base.widget);
412 edje_object_part_swallow(wd->slideshow, "elm.swallow.2", next->base.view);
413 evas_object_show(next->base.view);
414 snprintf(buf, sizeof(buf), "%s,next", wd->transition);
415 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
416 wd->previous = wd->current;
421 * Go to the next item
423 * @param obj The slideshow object
428 elm_slideshow_next(Evas_Object *obj)
431 Elm_Slideshow_Item *next = NULL;
432 ELM_CHECK_WIDTYPE(obj, widtype);
433 Widget_Data *wd = elm_widget_data_get(obj);
438 next = _item_next_get(wd->current);
440 if ((!next) || (next == wd->current)) return;
441 evas_object_smart_callback_call(obj, "changed", next);
443 _end(obj, obj, NULL, NULL);
445 if (wd->timer) ecore_timer_del(wd->timer);
446 if (wd->timeout > 0.0)
447 wd->timer = ecore_timer_add(wd->timeout, _timer_cb, obj);
451 edje_object_part_swallow(wd->slideshow, "elm.swallow.2", next->base.view);
452 evas_object_show(next->base.view);
454 snprintf(buf, sizeof(buf), "%s,next", wd->transition);
455 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
457 wd->previous = wd->current;
462 * Go to the previous item
464 * @param obj The slideshow object
469 elm_slideshow_previous(Evas_Object *obj)
472 Elm_Slideshow_Item *prev = NULL;
473 ELM_CHECK_WIDTYPE(obj, widtype);
474 Widget_Data *wd = elm_widget_data_get(obj);
479 prev = _item_prev_get(wd->current);
481 if ((!prev) || (prev == wd->current)) return;
482 evas_object_smart_callback_call(obj, "changed", prev);
484 _end(obj, obj, NULL, NULL);
486 if (wd->timer) ecore_timer_del(wd->timer);
487 if (wd->timeout > 0.0)
488 wd->timer = ecore_timer_add(wd->timeout, _timer_cb, obj);
492 edje_object_part_swallow(wd->slideshow, "elm.swallow.2", prev->base.view);
493 evas_object_show(prev->base.view);
495 snprintf(buf, 1024, "%s,previous", wd->transition);
496 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
498 wd->previous = wd->current;
503 * Returns the list of transitions available.
505 * @param obj The slideshow object
506 * @return Returns the list of transitions (list of const char*)
510 EAPI const Eina_List *
511 elm_slideshow_transitions_get(const Evas_Object *obj)
513 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
514 Widget_Data *wd = elm_widget_data_get(obj);
515 if (!wd) return NULL;
516 return wd->transitions;
520 * Returns the list of layouts available.
522 * @param obj The slideshow object
523 * @return Returns the list of layout (list of const char*)
527 EAPI const Eina_List *
528 elm_slideshow_layouts_get(const Evas_Object *obj)
530 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
531 Widget_Data *wd = elm_widget_data_get(obj);
532 if (!wd) return NULL;
533 return wd->layout.list;
537 * Set the transition to use
539 * @param obj The slideshow object
540 * @param transition the new transition
545 elm_slideshow_transition_set(Evas_Object *obj, const char *transition)
547 ELM_CHECK_WIDTYPE(obj, widtype);
548 Widget_Data *wd = elm_widget_data_get(obj);
550 eina_stringshare_replace(&wd->transition, transition);
554 * Returns the transition to use
556 * @param obj The slideshow object
557 * @return the transition set
562 elm_slideshow_transition_get(const Evas_Object *obj)
564 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
565 Widget_Data *wd = elm_widget_data_get(obj);
566 if (!wd) return NULL;
567 return wd->transition;
571 * The slideshow can go to the next item automatically after a few seconds.
572 * This method set the timeout to use. A timeout <=0 disable the timer.
574 * @param obj The slideshow object
575 * @param timeout The new timeout
580 elm_slideshow_timeout_set(Evas_Object *obj, double timeout)
582 ELM_CHECK_WIDTYPE(obj, widtype);
583 Widget_Data *wd = elm_widget_data_get(obj);
585 wd->timeout = timeout;
586 if (wd->timer) ecore_timer_del(wd->timer);
589 wd->timer = ecore_timer_add(timeout, _timer_cb, obj);
593 * Returns the timeout value
595 * @param obj The slideshow object
596 * @return Returns the timeout
601 elm_slideshow_timeout_get(const Evas_Object *obj)
603 ELM_CHECK_WIDTYPE(obj, widtype) -1.0;
604 Widget_Data *wd = elm_widget_data_get(obj);
605 if (!wd) return -1.0;
610 * Set if the first item should follow the last and vice versa
612 * @param obj The slideshow object
613 * @param loop if EINA_TRUE, the first item will follow the last and vice versa
618 elm_slideshow_loop_set(Evas_Object *obj, Eina_Bool loop)
620 ELM_CHECK_WIDTYPE(obj, widtype);
621 Widget_Data *wd = elm_widget_data_get(obj);
627 * Returns the current layout name
629 * @param obj The slideshow object
630 * @returns Returns the layout name
635 elm_slideshow_layout_get(const Evas_Object *obj)
637 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
638 Widget_Data *wd = elm_widget_data_get(obj);
639 if (!wd) return EINA_FALSE;
640 return wd->layout.current;
646 * @param obj The slideshow object
647 * @param layout the new layout
652 elm_slideshow_layout_set(Evas_Object *obj, const char *layout)
655 ELM_CHECK_WIDTYPE(obj, widtype);
656 Widget_Data *wd = elm_widget_data_get(obj);
659 wd->layout.current = layout;
660 snprintf(buf, sizeof(buf), "layout,%s", layout);
661 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
665 * Return if the first item should follow the last and vice versa
667 * @param obj The slideshow object
668 * @returns Returns the loop flag
673 elm_slideshow_loop_get(const Evas_Object *obj)
675 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
676 Widget_Data *wd = elm_widget_data_get(obj);
677 if (!wd) return EINA_FALSE;
682 * Delete all the items
684 * @param obj The slideshow object
689 elm_slideshow_clear(Evas_Object *obj)
691 Elm_Slideshow_Item *item;
692 ELM_CHECK_WIDTYPE(obj, widtype);
693 Widget_Data *wd = elm_widget_data_get(obj);
697 EINA_LIST_FREE(wd->items_built, item)
699 if (item->itc->func.del)
700 item->itc->func.del((void*)item->base.data, item->base.view);
701 evas_object_del(item->base.view);
702 item->base.view = NULL;
705 EINA_LIST_FREE(wd->items, item)
707 elm_widget_item_del(item);
715 * @param item The slideshow item
720 elm_slideshow_item_del(Elm_Slideshow_Item *item)
722 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
723 Widget_Data *wd = elm_widget_data_get(item->base.widget);
725 if (wd->previous == item) wd->previous = NULL;
726 if (wd->current == item)
728 Eina_List *l = eina_list_data_find_list(wd->items, item);
729 Eina_List *l2 = eina_list_next(l);
732 l2 = eina_list_nth_list(wd->items, eina_list_count(wd->items) - 1);
734 elm_slideshow_show(eina_list_data_get(l2));
737 wd->items = eina_list_remove_list(wd->items, item->l);
738 wd->items_built = eina_list_remove_list(wd->items_built, item->l_built);
740 if ((item->base.view) && (item->itc->func.del))
741 item->itc->func.del((void*)item->base.data, item->base.view);
743 evas_object_del(item->base.view);
748 * Returns the list of items
749 * @param obj The slideshow object
750 * @return Returns the list of items (list of Elm_Slideshow_Item).
754 EAPI const Eina_List *
755 elm_slideshow_items_get(const Evas_Object *obj)
757 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
758 Widget_Data *wd = elm_widget_data_get(obj);
759 if (!wd) return NULL;
765 * Returns the current item displayed
767 * @param obj The slideshow object
768 * @return Returns the current item displayed
772 EAPI Elm_Slideshow_Item *
773 elm_slideshow_item_current_get(const Evas_Object *obj)
775 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
776 Widget_Data *wd = elm_widget_data_get(obj);
777 if (!wd) return NULL;
782 * Returns the evas object associated to an item
784 * @param item The slideshow item
785 * @return Returns the evas object associated to this item
790 elm_slideshow_item_object_get(const Elm_Slideshow_Item * item)
792 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
793 return item->base.view;
797 * Returns the data associated to an item
799 * @param item The slideshow item
800 * @return Returns the data associated to this item
805 elm_slideshow_item_data_get(const Elm_Slideshow_Item * item)
807 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
808 return elm_widget_item_data_get(item);