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;
53 Eina_List *list; //list of const char *
57 static const char *widtype = NULL;
58 static void _del_hook(Evas_Object *obj);
59 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
60 static void _theme_hook(Evas_Object *obj);
61 static void _sizing_eval(Evas_Object *obj);
62 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
63 static Eina_Bool _timer_cb(void *data);
64 static void _on_focus_hook(void *data, Evas_Object *obj);
65 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src,
66 Evas_Callback_Type type, void *event_info);
68 static const char SIG_CHANGED[] = "changed";
70 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);
202 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
208 _sub_del(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
214 _item_realize(Elm_Slideshow_Item *item)
216 Elm_Slideshow_Item *_item;
217 Evas_Object *obj = item->base.widget;
218 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 _item = _item_next_get(item);
234 if ((_item) && (!_item->base.view) && (_item->itc->func.get))
236 _item->base.view = _item->itc->func.get((void*)_item->base.data, obj);
237 evas_object_smart_member_add(_item->base.view, obj);
238 _item->l_built = eina_list_append(NULL, _item);
239 wd->items_built = eina_list_merge(wd->items_built, _item->l_built);
240 evas_object_hide(_item->base.view);
242 else if ((_item) && (_item->l_built))
243 wd->items_built = eina_list_demote_list(wd->items_built, _item->l_built);
245 _item = _item_prev_get(item);
246 if ((_item) && (!_item->base.view) && (_item->itc->func.get))
248 _item->base.view = _item->itc->func.get((void*)_item->base.data, obj);
249 evas_object_smart_member_add(_item->base.view, obj);
250 _item->l_built = eina_list_append(NULL, _item);
251 wd->items_built = eina_list_merge(wd->items_built, _item->l_built);
252 evas_object_hide(_item->base.view);
254 else if ((_item) && (_item->l_built))
255 wd->items_built = eina_list_demote_list(wd->items_built, _item->l_built);
257 //delete unused items
258 while (eina_list_count(wd->items_built) > 3)
260 _item = eina_list_data_get(wd->items_built);
261 wd->items_built = eina_list_remove_list(wd->items_built, wd->items_built);
262 if(item->itc->func.del)
263 item->itc->func.del((void*)item->base.data, _item->base.view);
264 evas_object_del(_item->base.view);
265 _item->base.view = NULL;
270 _end(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
272 Elm_Slideshow_Item *item;
273 Widget_Data *wd = elm_widget_data_get(data);
279 edje_object_part_unswallow(NULL, item->base.view);
280 evas_object_hide(item->base.view);
286 if ((!item) || (!item->base.view)) return;
289 edje_object_part_unswallow(NULL, item->base.view);
290 evas_object_show(item->base.view);
292 edje_object_signal_emit(wd->slideshow, "anim,end", "slideshow");
293 edje_object_part_swallow(wd->slideshow, "elm.swallow.1", item->base.view);
298 _timer_cb(void *data)
300 Evas_Object *obj = data;
301 Widget_Data *wd = elm_widget_data_get(obj);
302 if (!wd) return ECORE_CALLBACK_CANCEL;
304 elm_slideshow_next(obj);
305 return ECORE_CALLBACK_CANCEL;
311 * Add a new slideshow to the parent
313 * @param parent The parent object
314 * @return The new object or NULL if it cannot be created
319 elm_slideshow_add(Evas_Object *parent)
325 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
327 ELM_SET_WIDTYPE(widtype, "slideshow");
328 elm_widget_type_set(obj, "slideshow");
329 elm_widget_sub_object_add(parent, obj);
330 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
331 elm_widget_data_set(obj, wd);
332 elm_widget_del_hook_set(obj, _del_hook);
333 elm_widget_theme_hook_set(obj, _theme_hook);
334 elm_widget_can_focus_set(obj, EINA_TRUE);
335 elm_widget_event_hook_set(obj, _event_hook);
340 wd->slideshow = edje_object_add(e);
341 _elm_theme_object_set(obj, wd->slideshow, "slideshow", "base", "default");
342 evas_object_smart_member_add(wd->slideshow, obj);
343 elm_widget_resize_object_set(obj, wd->slideshow);
344 evas_object_show(wd->slideshow);
346 wd->transitions = elm_widget_stringlist_get(edje_object_data_get(wd->slideshow, "transitions"));
347 if (eina_list_count(wd->transitions) > 0)
348 wd->transition = eina_stringshare_add(eina_list_data_get(wd->transitions));
350 wd->layout.list = elm_widget_stringlist_get(edje_object_data_get(wd->slideshow, "layouts"));
351 if (eina_list_count(wd->layout.list) > 0)
352 wd->layout.current = eina_list_data_get(wd->layout.list);
354 edje_object_signal_callback_add(wd->slideshow, "end", "slideshow", _end, obj);
356 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
357 evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
359 evas_object_smart_callbacks_descriptions_set(obj, _signals);
361 _mirrored_set(obj, elm_widget_mirrored_get(obj));
367 * Add a object in the list. The object can be a evas object image or a elm photo for example.
369 * @param obj The slideshow object
370 * @aram itc Callbacks used to create the object and delete the data associated when the item is deleted.
371 * @param data Data used by the user to identified the item
372 * @return Returns The slideshow item
376 EAPI Elm_Slideshow_Item*
377 elm_slideshow_item_add(Evas_Object *obj, const Elm_Slideshow_Item_Class *itc, const void *data)
379 Elm_Slideshow_Item *item;
380 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
381 Widget_Data *wd = elm_widget_data_get(obj);
383 if (!wd) return NULL;
384 item = elm_widget_item_new(obj, Elm_Slideshow_Item);
385 item->base.data = data;
387 item->l = eina_list_append(item->l, item);
389 wd->items = eina_list_merge(wd->items, item->l);
391 if (!wd->current) elm_slideshow_show(item);
399 * @param obj The slideshow object
400 * @param item The item
405 elm_slideshow_show(Elm_Slideshow_Item *item)
408 Elm_Slideshow_Item *next = NULL;
410 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
411 wd = elm_widget_data_get(item->base.widget);
414 if (item == wd->current)
418 _end(item->base.widget, item->base.widget, NULL, NULL);
420 if (wd->timer) ecore_timer_del(wd->timer);
421 if (wd->timeout > 0.0)
422 wd->timer = ecore_timer_add(wd->timeout, _timer_cb, item->base.widget);
424 edje_object_part_swallow(wd->slideshow, "elm.swallow.2", next->base.view);
425 evas_object_show(next->base.view);
426 snprintf(buf, sizeof(buf), "%s,next", wd->transition);
427 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
428 wd->previous = wd->current;
430 evas_object_smart_callback_call(item->base.widget, SIG_CHANGED, wd->current);
434 * Go to the next item
436 * @param obj The slideshow object
441 elm_slideshow_next(Evas_Object *obj)
444 Elm_Slideshow_Item *next = NULL;
445 ELM_CHECK_WIDTYPE(obj, widtype);
446 Widget_Data *wd = elm_widget_data_get(obj);
451 next = _item_next_get(wd->current);
453 if ((!next) || (next == wd->current)) return;
455 _end(obj, obj, 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, obj);
463 edje_object_part_swallow(wd->slideshow, "elm.swallow.2", next->base.view);
464 evas_object_show(next->base.view);
466 snprintf(buf, sizeof(buf), "%s,next", wd->transition);
467 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
469 wd->previous = wd->current;
471 evas_object_smart_callback_call(obj, SIG_CHANGED, wd->current);
475 * Go to the previous item
477 * @param obj The slideshow object
482 elm_slideshow_previous(Evas_Object *obj)
485 Elm_Slideshow_Item *prev = NULL;
486 ELM_CHECK_WIDTYPE(obj, widtype);
487 Widget_Data *wd = elm_widget_data_get(obj);
492 prev = _item_prev_get(wd->current);
494 if ((!prev) || (prev == wd->current)) return;
496 _end(obj, obj, NULL, NULL);
498 if (wd->timer) ecore_timer_del(wd->timer);
499 if (wd->timeout > 0.0)
500 wd->timer = ecore_timer_add(wd->timeout, _timer_cb, obj);
504 edje_object_part_swallow(wd->slideshow, "elm.swallow.2", prev->base.view);
505 evas_object_show(prev->base.view);
507 snprintf(buf, 1024, "%s,previous", wd->transition);
508 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
510 wd->previous = wd->current;
512 evas_object_smart_callback_call(obj, SIG_CHANGED, wd->current);
516 * Returns the list of transitions available.
518 * @param obj The slideshow object
519 * @return Returns the list of transitions (list of const char*)
523 EAPI const Eina_List *
524 elm_slideshow_transitions_get(const Evas_Object *obj)
526 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
527 Widget_Data *wd = elm_widget_data_get(obj);
528 if (!wd) return NULL;
529 return wd->transitions;
533 * Returns the list of layouts available.
535 * @param obj The slideshow object
536 * @return Returns the list of layout (list of const char*)
540 EAPI const Eina_List *
541 elm_slideshow_layouts_get(const Evas_Object *obj)
543 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
544 Widget_Data *wd = elm_widget_data_get(obj);
545 if (!wd) return NULL;
546 return wd->layout.list;
550 * Set the transition to use
552 * @param obj The slideshow object
553 * @param transition the new transition
558 elm_slideshow_transition_set(Evas_Object *obj, const char *transition)
560 ELM_CHECK_WIDTYPE(obj, widtype);
561 Widget_Data *wd = elm_widget_data_get(obj);
563 eina_stringshare_replace(&wd->transition, transition);
567 * Returns the transition to use
569 * @param obj The slideshow object
570 * @return the transition set
575 elm_slideshow_transition_get(const Evas_Object *obj)
577 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
578 Widget_Data *wd = elm_widget_data_get(obj);
579 if (!wd) return NULL;
580 return wd->transition;
584 * The slideshow can go to the next item automatically after a few seconds.
585 * This method set the timeout to use. A timeout <=0 disable the timer.
587 * @param obj The slideshow object
588 * @param timeout The new timeout
593 elm_slideshow_timeout_set(Evas_Object *obj, double timeout)
595 ELM_CHECK_WIDTYPE(obj, widtype);
596 Widget_Data *wd = elm_widget_data_get(obj);
598 wd->timeout = timeout;
599 if (wd->timer) ecore_timer_del(wd->timer);
602 wd->timer = ecore_timer_add(timeout, _timer_cb, obj);
606 * Returns the timeout value
608 * @param obj The slideshow object
609 * @return Returns the timeout
614 elm_slideshow_timeout_get(const Evas_Object *obj)
616 ELM_CHECK_WIDTYPE(obj, widtype) -1.0;
617 Widget_Data *wd = elm_widget_data_get(obj);
618 if (!wd) return -1.0;
623 * Set if the first item should follow the last and vice versa
625 * @param obj The slideshow object
626 * @param loop if EINA_TRUE, the first item will follow the last and vice versa
631 elm_slideshow_loop_set(Evas_Object *obj, Eina_Bool loop)
633 ELM_CHECK_WIDTYPE(obj, widtype);
634 Widget_Data *wd = elm_widget_data_get(obj);
640 * Returns the current layout name
642 * @param obj The slideshow object
643 * @returns Returns the layout name
648 elm_slideshow_layout_get(const Evas_Object *obj)
650 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
651 Widget_Data *wd = elm_widget_data_get(obj);
652 if (!wd) return EINA_FALSE;
653 return wd->layout.current;
659 * @param obj The slideshow object
660 * @param layout the new layout
665 elm_slideshow_layout_set(Evas_Object *obj, const char *layout)
668 ELM_CHECK_WIDTYPE(obj, widtype);
669 Widget_Data *wd = elm_widget_data_get(obj);
672 wd->layout.current = layout;
673 snprintf(buf, sizeof(buf), "layout,%s", layout);
674 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
678 * Return if the first item should follow the last and vice versa
680 * @param obj The slideshow object
681 * @returns Returns the loop flag
686 elm_slideshow_loop_get(const Evas_Object *obj)
688 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
689 Widget_Data *wd = elm_widget_data_get(obj);
690 if (!wd) return EINA_FALSE;
695 * Delete all the items
697 * @param obj The slideshow object
702 elm_slideshow_clear(Evas_Object *obj)
704 Elm_Slideshow_Item *item;
705 ELM_CHECK_WIDTYPE(obj, widtype);
706 Widget_Data *wd = elm_widget_data_get(obj);
710 EINA_LIST_FREE(wd->items_built, item)
712 if (item->itc->func.del)
713 item->itc->func.del((void*)item->base.data, item->base.view);
714 evas_object_del(item->base.view);
715 item->base.view = NULL;
718 EINA_LIST_FREE(wd->items, item)
720 elm_widget_item_del(item);
728 * @param item The slideshow item
733 elm_slideshow_item_del(Elm_Slideshow_Item *item)
735 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
736 Widget_Data *wd = elm_widget_data_get(item->base.widget);
738 if (wd->previous == item) wd->previous = NULL;
739 if (wd->current == item)
741 Eina_List *l = eina_list_data_find_list(wd->items, item);
742 Eina_List *l2 = eina_list_next(l);
745 l2 = eina_list_nth_list(wd->items, eina_list_count(wd->items) - 1);
747 elm_slideshow_show(eina_list_data_get(l2));
750 wd->items = eina_list_remove_list(wd->items, item->l);
751 wd->items_built = eina_list_remove_list(wd->items_built, item->l_built);
753 if ((item->base.view) && (item->itc->func.del))
754 item->itc->func.del((void*)item->base.data, item->base.view);
756 evas_object_del(item->base.view);
761 * Returns the list of items
762 * @param obj The slideshow object
763 * @return Returns the list of items (list of Elm_Slideshow_Item).
767 EAPI const Eina_List *
768 elm_slideshow_items_get(const Evas_Object *obj)
770 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
771 Widget_Data *wd = elm_widget_data_get(obj);
772 if (!wd) return NULL;
778 * Returns the current item displayed
780 * @param obj The slideshow object
781 * @return Returns the current item displayed
785 EAPI Elm_Slideshow_Item *
786 elm_slideshow_item_current_get(const Evas_Object *obj)
788 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
789 Widget_Data *wd = elm_widget_data_get(obj);
790 if (!wd) return NULL;
795 * Returns the evas object associated to an item
797 * @param item The slideshow item
798 * @return Returns the evas object associated to this item
803 elm_slideshow_item_object_get(const Elm_Slideshow_Item * item)
805 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
806 return item->base.view;
810 * Returns the data associated to an item
812 * @param item The slideshow item
813 * @return Returns the data associated to this item
818 elm_slideshow_item_data_get(const Elm_Slideshow_Item * item)
820 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
821 return elm_widget_item_data_get(item);