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 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
314 ELM_SET_WIDTYPE(widtype, "slideshow");
315 elm_widget_type_set(obj, "slideshow");
316 elm_widget_sub_object_add(parent, obj);
317 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
318 elm_widget_data_set(obj, wd);
319 elm_widget_del_hook_set(obj, _del_hook);
320 elm_widget_theme_hook_set(obj, _theme_hook);
321 elm_widget_can_focus_set(obj, EINA_TRUE);
322 elm_widget_event_hook_set(obj, _event_hook);
327 wd->slideshow = edje_object_add(e);
328 _elm_theme_object_set(obj, wd->slideshow, "slideshow", "base", "default");
329 evas_object_smart_member_add(wd->slideshow, obj);
330 elm_widget_resize_object_set(obj, wd->slideshow);
331 evas_object_show(wd->slideshow);
333 wd->transitions = elm_widget_stringlist_get(edje_object_data_get(wd->slideshow, "transitions"));
334 if (eina_list_count(wd->transitions) > 0)
335 wd->transition = eina_stringshare_add(eina_list_data_get(wd->transitions));
337 wd->layout.list = elm_widget_stringlist_get(edje_object_data_get(wd->slideshow, "layouts"));
338 if (eina_list_count(wd->layout.list) > 0)
339 wd->layout.current = eina_list_data_get(wd->layout.list);
341 edje_object_signal_callback_add(wd->slideshow, "end", "slideshow", _end, obj);
343 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
344 evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
346 _mirrored_set(obj, elm_widget_mirrored_get(obj));
352 * Add a object in the list. The object can be a evas object image or a elm photo for example.
354 * @param obj The slideshow object
355 * @aram itc Callbacks used to create the object and delete the data associated when the item is deleted.
356 * @param data Data used by the user to identified the item
357 * @return Returns The slideshow item
361 EAPI Elm_Slideshow_Item*
362 elm_slideshow_item_add(Evas_Object *obj, const Elm_Slideshow_Item_Class *itc, const void *data)
364 Elm_Slideshow_Item *item;
365 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
366 Widget_Data *wd = elm_widget_data_get(obj);
368 if (!wd) return NULL;
369 item = elm_widget_item_new(obj, Elm_Slideshow_Item);
370 item->base.data = data;
372 item->l = eina_list_append(item->l, item);
374 wd->items = eina_list_merge(wd->items, item->l);
376 if (!wd->current) elm_slideshow_show(item);
384 * @param obj The slideshow object
385 * @param item The item
390 elm_slideshow_show(Elm_Slideshow_Item *item)
393 Elm_Slideshow_Item *next = NULL;
395 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
396 wd = elm_widget_data_get(item->base.widget);
399 if (item == wd->current)
403 _end(item->base.widget, item->base.widget, NULL, NULL);
405 if (wd->timer) ecore_timer_del(wd->timer);
406 if (wd->timeout > 0.0)
407 wd->timer = ecore_timer_add(wd->timeout, _timer_cb, item->base.widget);
409 edje_object_part_swallow(wd->slideshow, "elm.swallow.2", next->base.view);
410 evas_object_show(next->base.view);
411 snprintf(buf, sizeof(buf), "%s,next", wd->transition);
412 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
413 wd->previous = wd->current;
415 evas_object_smart_callback_call(item->base.widget, "changed", wd->current);
419 * Go to the next item
421 * @param obj The slideshow object
426 elm_slideshow_next(Evas_Object *obj)
429 Elm_Slideshow_Item *next = NULL;
430 ELM_CHECK_WIDTYPE(obj, widtype);
431 Widget_Data *wd = elm_widget_data_get(obj);
436 next = _item_next_get(wd->current);
438 if ((!next) || (next == wd->current)) return;
440 _end(obj, obj, NULL, NULL);
442 if (wd->timer) ecore_timer_del(wd->timer);
443 if (wd->timeout > 0.0)
444 wd->timer = ecore_timer_add(wd->timeout, _timer_cb, obj);
448 edje_object_part_swallow(wd->slideshow, "elm.swallow.2", next->base.view);
449 evas_object_show(next->base.view);
451 snprintf(buf, sizeof(buf), "%s,next", wd->transition);
452 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
454 wd->previous = wd->current;
456 evas_object_smart_callback_call(obj, "changed", wd->current);
460 * Go to the previous item
462 * @param obj The slideshow object
467 elm_slideshow_previous(Evas_Object *obj)
470 Elm_Slideshow_Item *prev = NULL;
471 ELM_CHECK_WIDTYPE(obj, widtype);
472 Widget_Data *wd = elm_widget_data_get(obj);
477 prev = _item_prev_get(wd->current);
479 if ((!prev) || (prev == wd->current)) return;
481 _end(obj, obj, NULL, NULL);
483 if (wd->timer) ecore_timer_del(wd->timer);
484 if (wd->timeout > 0.0)
485 wd->timer = ecore_timer_add(wd->timeout, _timer_cb, obj);
489 edje_object_part_swallow(wd->slideshow, "elm.swallow.2", prev->base.view);
490 evas_object_show(prev->base.view);
492 snprintf(buf, 1024, "%s,previous", wd->transition);
493 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
495 wd->previous = wd->current;
497 evas_object_smart_callback_call(obj, "changed", wd->current);
501 * Returns the list of transitions available.
503 * @param obj The slideshow object
504 * @return Returns the list of transitions (list of const char*)
508 EAPI const Eina_List *
509 elm_slideshow_transitions_get(const Evas_Object *obj)
511 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
512 Widget_Data *wd = elm_widget_data_get(obj);
513 if (!wd) return NULL;
514 return wd->transitions;
518 * Returns the list of layouts available.
520 * @param obj The slideshow object
521 * @return Returns the list of layout (list of const char*)
525 EAPI const Eina_List *
526 elm_slideshow_layouts_get(const Evas_Object *obj)
528 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
529 Widget_Data *wd = elm_widget_data_get(obj);
530 if (!wd) return NULL;
531 return wd->layout.list;
535 * Set the transition to use
537 * @param obj The slideshow object
538 * @param transition the new transition
543 elm_slideshow_transition_set(Evas_Object *obj, const char *transition)
545 ELM_CHECK_WIDTYPE(obj, widtype);
546 Widget_Data *wd = elm_widget_data_get(obj);
548 eina_stringshare_replace(&wd->transition, transition);
552 * Returns the transition to use
554 * @param obj The slideshow object
555 * @return the transition set
560 elm_slideshow_transition_get(const Evas_Object *obj)
562 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
563 Widget_Data *wd = elm_widget_data_get(obj);
564 if (!wd) return NULL;
565 return wd->transition;
569 * The slideshow can go to the next item automatically after a few seconds.
570 * This method set the timeout to use. A timeout <=0 disable the timer.
572 * @param obj The slideshow object
573 * @param timeout The new timeout
578 elm_slideshow_timeout_set(Evas_Object *obj, double timeout)
580 ELM_CHECK_WIDTYPE(obj, widtype);
581 Widget_Data *wd = elm_widget_data_get(obj);
583 wd->timeout = timeout;
584 if (wd->timer) ecore_timer_del(wd->timer);
587 wd->timer = ecore_timer_add(timeout, _timer_cb, obj);
591 * Returns the timeout value
593 * @param obj The slideshow object
594 * @return Returns the timeout
599 elm_slideshow_timeout_get(const Evas_Object *obj)
601 ELM_CHECK_WIDTYPE(obj, widtype) -1.0;
602 Widget_Data *wd = elm_widget_data_get(obj);
603 if (!wd) return -1.0;
608 * Set if the first item should follow the last and vice versa
610 * @param obj The slideshow object
611 * @param loop if EINA_TRUE, the first item will follow the last and vice versa
616 elm_slideshow_loop_set(Evas_Object *obj, Eina_Bool loop)
618 ELM_CHECK_WIDTYPE(obj, widtype);
619 Widget_Data *wd = elm_widget_data_get(obj);
625 * Returns the current layout name
627 * @param obj The slideshow object
628 * @returns Returns the layout name
633 elm_slideshow_layout_get(const Evas_Object *obj)
635 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
636 Widget_Data *wd = elm_widget_data_get(obj);
637 if (!wd) return EINA_FALSE;
638 return wd->layout.current;
644 * @param obj The slideshow object
645 * @param layout the new layout
650 elm_slideshow_layout_set(Evas_Object *obj, const char *layout)
653 ELM_CHECK_WIDTYPE(obj, widtype);
654 Widget_Data *wd = elm_widget_data_get(obj);
657 wd->layout.current = layout;
658 snprintf(buf, sizeof(buf), "layout,%s", layout);
659 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
663 * Return if the first item should follow the last and vice versa
665 * @param obj The slideshow object
666 * @returns Returns the loop flag
671 elm_slideshow_loop_get(const Evas_Object *obj)
673 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
674 Widget_Data *wd = elm_widget_data_get(obj);
675 if (!wd) return EINA_FALSE;
680 * Delete all the items
682 * @param obj The slideshow object
687 elm_slideshow_clear(Evas_Object *obj)
689 Elm_Slideshow_Item *item;
690 ELM_CHECK_WIDTYPE(obj, widtype);
691 Widget_Data *wd = elm_widget_data_get(obj);
695 EINA_LIST_FREE(wd->items_built, item)
697 if (item->itc->func.del)
698 item->itc->func.del((void*)item->base.data, item->base.view);
699 evas_object_del(item->base.view);
700 item->base.view = NULL;
703 EINA_LIST_FREE(wd->items, item)
705 elm_widget_item_del(item);
713 * @param item The slideshow item
718 elm_slideshow_item_del(Elm_Slideshow_Item *item)
720 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
721 Widget_Data *wd = elm_widget_data_get(item->base.widget);
723 if (wd->previous == item) wd->previous = NULL;
724 if (wd->current == item)
726 Eina_List *l = eina_list_data_find_list(wd->items, item);
727 Eina_List *l2 = eina_list_next(l);
730 l2 = eina_list_nth_list(wd->items, eina_list_count(wd->items) - 1);
732 elm_slideshow_show(eina_list_data_get(l2));
735 wd->items = eina_list_remove_list(wd->items, item->l);
736 wd->items_built = eina_list_remove_list(wd->items_built, item->l_built);
738 if ((item->base.view) && (item->itc->func.del))
739 item->itc->func.del((void*)item->base.data, item->base.view);
741 evas_object_del(item->base.view);
746 * Returns the list of items
747 * @param obj The slideshow object
748 * @return Returns the list of items (list of Elm_Slideshow_Item).
752 EAPI const Eina_List *
753 elm_slideshow_items_get(const Evas_Object *obj)
755 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
756 Widget_Data *wd = elm_widget_data_get(obj);
757 if (!wd) return NULL;
763 * Returns the current item displayed
765 * @param obj The slideshow object
766 * @return Returns the current item displayed
770 EAPI Elm_Slideshow_Item *
771 elm_slideshow_item_current_get(const Evas_Object *obj)
773 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
774 Widget_Data *wd = elm_widget_data_get(obj);
775 if (!wd) return NULL;
780 * Returns the evas object associated to an item
782 * @param item The slideshow item
783 * @return Returns the evas object associated to this item
788 elm_slideshow_item_object_get(const Elm_Slideshow_Item * item)
790 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
791 return item->base.view;
795 * Returns the data associated to an item
797 * @param item The slideshow item
798 * @return Returns the data associated to this item
803 elm_slideshow_item_data_get(const Elm_Slideshow_Item * item)
805 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
806 return elm_widget_item_data_get(item);