Merge branch 'master' into svn_merge
[framework/uifw/elementary.git] / src / lib / elm_slideshow.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3
4 /**
5  * @defgroup Slideshow Slideshow
6  * @ingroup Elementary
7  *
8  * This object display a list of object (generally a list of images) and some actions like
9  * next/previous are used to navigate. The animations are defined in the theme,
10  * consequently new animations can be added without having to update the
11  * applications.
12  *
13  * The slideshow use 2 callbacks to create and delete the objects displayed. When an item
14  * is displayed the function itc->func.get() is called. This function should create the object,
15  * for example the object can be an evas_object_image or a photocam. When an object is no more
16  * displayed the function itc->func.del() is called, the user can delete the dana associated to the item.
17  *
18  * Signals that you can add callbacks for are:
19  *
20  * "changed" - when the slideshow switch to another item
21  */
22
23 typedef struct _Widget_Data Widget_Data;
24
25 struct _Elm_Slideshow_Item
26 {
27    Elm_Widget_Item base;
28
29    Eina_List *l, *l_built;
30
31    const Elm_Slideshow_Item_Class *itc;
32 };
33
34 struct _Widget_Data
35 {
36    Evas_Object *slideshow;
37
38    // list of Elm_Slideshow_Item*
39    Eina_List *items;
40    Eina_List *items_built;
41
42    Elm_Slideshow_Item *current;
43    Elm_Slideshow_Item *previous;
44
45    Eina_List *transitions;
46    const char *transition;
47
48    int count_item_pre_before;
49    int count_item_pre_after;
50    Ecore_Timer *timer;
51    double timeout;
52    Eina_Bool loop:1;
53
54    struct {
55         const char *current;
56         Eina_List *list; //list of const char *
57    } layout;
58 };
59
60 static const char *widtype = NULL;
61 static void _del_hook(Evas_Object *obj);
62 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
63 static void _theme_hook(Evas_Object *obj);
64 static void _sizing_eval(Evas_Object *obj);
65 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
66 static Eina_Bool _timer_cb(void *data);
67 static void _on_focus_hook(void *data, Evas_Object *obj);
68 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src,
69                              Evas_Callback_Type type, void *event_info);
70
71 static const char SIG_CHANGED[] = "changed";
72
73 static const Evas_Smart_Cb_Description _signals[] = {
74    {SIG_CHANGED, ""},
75    {NULL, NULL}
76 };
77
78 static Eina_Bool
79 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
80 {
81    if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
82    Evas_Event_Key_Down *ev = event_info;
83    Widget_Data *wd = elm_widget_data_get(obj);
84    if (!wd) return EINA_FALSE;
85    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
86    if (elm_widget_disabled_get(obj)) return EINA_FALSE;
87    if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")))
88      {
89         elm_slideshow_previous(obj);
90         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
91         return EINA_TRUE;
92      }
93    if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")))
94      {
95         elm_slideshow_next(obj);
96         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
97         return EINA_TRUE;
98      }
99    if ((!strcmp(ev->keyname, "Return")) ||
100        (!strcmp(ev->keyname, "KP_Enter")) ||
101        (!strcmp(ev->keyname, "space")))
102      {
103         if (wd->timeout)
104           {
105              if (wd->timer)
106                {
107                   ecore_timer_del(wd->timer);
108                   wd->timer = NULL;
109                }
110              else
111                elm_slideshow_timeout_set(obj, wd->timeout);
112           }
113         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
114         return EINA_TRUE;
115      }
116    return EINA_FALSE;
117 }
118
119 static void
120 _del_hook(Evas_Object *obj)
121 {
122    const char *layout;
123    Widget_Data *wd = elm_widget_data_get(obj);
124    if (!wd) return;
125    elm_slideshow_clear(obj);
126    elm_widget_stringlist_free(wd->transitions);
127    if (wd->timer) ecore_timer_del(wd->timer);
128    EINA_LIST_FREE(wd->layout.list, layout)
129       eina_stringshare_del(layout);
130    free(wd);
131 }
132
133 static void
134 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
135 {
136    Widget_Data *wd = elm_widget_data_get(obj);
137    if (!wd) return;
138    if (elm_widget_focus_get(obj))
139      {
140         edje_object_signal_emit(wd->slideshow, "elm,action,focus", "elm");
141         evas_object_focus_set(wd->slideshow, EINA_TRUE);
142      }
143    else
144      {
145         edje_object_signal_emit(wd->slideshow, "elm,action,unfocus", "elm");
146         evas_object_focus_set(wd->slideshow, EINA_FALSE);
147      }
148 }
149
150 static void
151 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
152 {
153    Widget_Data *wd = elm_widget_data_get(obj);
154    if (!wd) return;
155    edje_object_mirrored_set(wd->slideshow, rtl);
156 }
157
158 static void
159 _theme_hook(Evas_Object *obj)
160 {
161    Widget_Data *wd = elm_widget_data_get(obj);
162    if (!wd) return;
163    _elm_widget_mirrored_reload(obj);
164    _mirrored_set(obj, elm_widget_mirrored_get(obj));
165    _elm_theme_object_set(obj, wd->slideshow, "slideshow", "base", elm_widget_style_get(obj));
166    edje_object_scale_set(wd->slideshow, elm_widget_scale_get(obj) *
167                          _elm_config->scale);
168    _sizing_eval(obj);
169 }
170
171 static void
172 _sizing_eval(Evas_Object *obj)
173 {
174    Widget_Data *wd = elm_widget_data_get(obj);
175    Evas_Coord minw = -1, minh = -1;
176    if (!wd) return;
177    edje_object_size_min_calc(wd->slideshow, &minw, &minh);
178    evas_object_size_hint_min_set(obj, minw, minh);
179    evas_object_size_hint_max_set(obj, minw, minh);
180 }
181
182
183 static Elm_Slideshow_Item* _item_prev_get(Elm_Slideshow_Item* item)
184 {
185    Widget_Data *wd = elm_widget_data_get(item->base.widget);
186    Elm_Slideshow_Item* prev = eina_list_data_get(eina_list_prev(item->l));
187    if ((!prev) && (wd->loop))
188      prev = eina_list_data_get(eina_list_last(item->l));
189    return prev;
190 }
191
192 static Elm_Slideshow_Item* _item_next_get(Elm_Slideshow_Item* item)
193 {
194    Widget_Data *wd = elm_widget_data_get(item->base.widget);
195    Elm_Slideshow_Item* next = eina_list_data_get(eina_list_next(item->l));
196    if ((!next) && (wd->loop))
197      next = eina_list_data_get(wd->items);
198    return next;
199 }
200
201 static void
202 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
203 {
204    _sizing_eval(data);
205 }
206
207 static void
208 _sub_del(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
209 {
210    ;
211 }
212
213 static void
214 _item_realize(Elm_Slideshow_Item *item)
215 {
216    Elm_Slideshow_Item *_item_prev, *_item_next;
217    Evas_Object *obj = item->base.widget;
218    Widget_Data *wd = elm_widget_data_get(obj);
219    int ac, bc, lc;
220
221    if (!wd) return;
222    if ((!item->base.view) && (item->itc->func.get))
223      {
224         item->base.view = item->itc->func.get((void*)item->base.data, obj);
225         evas_object_smart_member_add(item->base.view, obj);
226         item->l_built = eina_list_append(NULL, item);
227         wd->items_built = eina_list_merge(wd->items_built, item->l_built);
228         evas_object_hide(item->base.view);
229      }
230    else if (item->l_built)
231      wd->items_built = eina_list_demote_list(wd->items_built, item->l_built);
232
233    //pre-create previous and next item
234    ac = wd->count_item_pre_after;
235    _item_next = item;
236    bc = wd->count_item_pre_before;
237    _item_prev = item;
238    lc = eina_list_count(wd->items) - 1;
239    while (lc > 0 && ((ac > 0) || (bc > 0)))
240      {
241         if (lc > 0 && ac > 0)
242           {
243              --ac;
244              --lc;
245              if (_item_next)
246                {
247                   _item_next = _item_next_get(_item_next);
248                   if ((_item_next)
249                       && (!_item_next->base.view)
250                       && (_item_next->itc->func.get))
251                     {
252                        _item_next->base.view =
253                           _item_next->itc->func.get(
254                              (void*)_item_next->base.data, obj);
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);
260                     }
261                   else if (_item_next && _item_next->l_built)
262                     wd->items_built =
263                        eina_list_demote_list(wd->items_built,
264                                              _item_next->l_built);
265                }
266           }
267
268         if (lc > 0 && bc > 0)
269           {
270              --bc;
271              --lc;
272              if (_item_prev)
273                {
274                   _item_prev = _item_prev_get(_item_prev);
275                   if ((_item_prev)
276                       && (!_item_prev->base.view)
277                       && (_item_prev->itc->func.get))
278                     {
279                        _item_prev->base.view =
280                           _item_prev->itc->func.get(
281                              (void*)_item_prev->base.data, obj);
282                        evas_object_smart_member_add(_item_prev->base.view, obj);
283                        _item_prev->l_built = eina_list_append(NULL, _item_prev);
284                        wd->items_built = eina_list_merge(wd->items_built,
285                                                          _item_prev->l_built);
286                        evas_object_hide(_item_prev->base.view);
287                     }
288                   else if (_item_prev && _item_prev->l_built)
289                     wd->items_built =
290                        eina_list_demote_list(wd->items_built,
291                                              _item_prev->l_built);
292                }
293           }
294      }
295
296    //delete unused items
297    lc = wd->count_item_pre_before + wd->count_item_pre_after + 1;
298    while ((int)eina_list_count(wd->items_built) > lc)
299      {
300         item = eina_list_data_get(wd->items_built);
301         wd->items_built = eina_list_remove_list(wd->items_built,
302                                                 wd->items_built);
303         if (item->itc->func.del)
304           item->itc->func.del((void*)item->base.data, item->base.view);
305         evas_object_del(item->base.view);
306         item->base.view = NULL;
307      }
308 }
309
310 static void
311 _end(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
312 {
313    Elm_Slideshow_Item *item;
314    Widget_Data *wd = elm_widget_data_get(data);
315    if (!wd) return;
316
317    item = wd->previous;
318    if (item)
319      {
320         edje_object_part_unswallow(NULL, item->base.view);
321         evas_object_hide(item->base.view);
322         wd->previous = NULL;
323      }
324
325
326    item = wd->current;
327    if ((!item) || (!item->base.view)) return;
328
329    _item_realize(item);
330    edje_object_part_unswallow(NULL, item->base.view);
331    evas_object_show(item->base.view);
332
333    edje_object_signal_emit(wd->slideshow, "anim,end", "slideshow");
334    edje_object_part_swallow(wd->slideshow, "elm.swallow.1", item->base.view);
335 }
336
337 static Eina_Bool
338 _timer_cb(void *data)
339 {
340    Evas_Object *obj = data;
341    Widget_Data *wd = elm_widget_data_get(obj);
342    if (!wd) return ECORE_CALLBACK_CANCEL;
343    wd->timer = NULL;
344    elm_slideshow_next(obj);
345    return ECORE_CALLBACK_CANCEL;
346 }
347
348 /**
349  * Add a new slideshow to the parent
350  *
351  * @param parent The parent object
352  * @return The new object or NULL if it cannot be created
353  *
354  * @ingroup Slideshow
355  */
356 EAPI Evas_Object *
357 elm_slideshow_add(Evas_Object *parent)
358 {
359    Evas_Object *obj;
360    Evas *e;
361    Widget_Data *wd;
362
363    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
364
365    ELM_SET_WIDTYPE(widtype, "slideshow");
366    elm_widget_type_set(obj, "slideshow");
367    elm_widget_sub_object_add(parent, obj);
368    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
369    elm_widget_data_set(obj, wd);
370    elm_widget_del_hook_set(obj, _del_hook);
371    elm_widget_theme_hook_set(obj, _theme_hook);
372    elm_widget_can_focus_set(obj, EINA_TRUE);
373    elm_widget_event_hook_set(obj, _event_hook);
374
375    wd->current = NULL;
376    wd->previous = NULL;
377
378    wd->slideshow = edje_object_add(e);
379    _elm_theme_object_set(obj, wd->slideshow, "slideshow", "base", "default");
380    evas_object_smart_member_add(wd->slideshow, obj);
381    wd->count_item_pre_before = 2;
382    wd->count_item_pre_after = 2;
383    elm_widget_resize_object_set(obj, wd->slideshow);
384    evas_object_show(wd->slideshow);
385
386    wd->transitions = elm_widget_stringlist_get(edje_object_data_get(wd->slideshow, "transitions"));
387    if (eina_list_count(wd->transitions) > 0)
388      wd->transition = eina_stringshare_add(eina_list_data_get(wd->transitions));
389
390    wd->layout.list = elm_widget_stringlist_get(edje_object_data_get(wd->slideshow, "layouts"));
391    if (eina_list_count(wd->layout.list) > 0)
392      wd->layout.current = eina_list_data_get(wd->layout.list);
393
394    edje_object_signal_callback_add(wd->slideshow, "end", "slideshow", _end, obj);
395
396    evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
397    evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
398
399    evas_object_smart_callbacks_descriptions_set(obj, _signals);
400
401    _mirrored_set(obj, elm_widget_mirrored_get(obj));
402    _sizing_eval(obj);
403    return obj;
404 }
405
406 /**
407  * Add an object in the list. The object can be a evas object image or a elm photo for example.
408  *
409  * @param obj The slideshow object
410  * @aram itc Callbacks used to create the object and delete the data associated when the item is deleted.
411  * @param data Data used by the user to identified the item
412  * @return Returns The slideshow item
413  *
414  * @ingroup Slideshow
415  */
416 EAPI Elm_Slideshow_Item*
417 elm_slideshow_item_add(Evas_Object *obj, const Elm_Slideshow_Item_Class *itc, const void *data)
418 {
419    Elm_Slideshow_Item *item;
420    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
421    Widget_Data *wd = elm_widget_data_get(obj);
422
423    if (!wd) return NULL;
424    item = elm_widget_item_new(obj, Elm_Slideshow_Item);
425    item->base.data = data;
426    item->itc = itc;
427    item->l = eina_list_append(item->l, item);
428
429    wd->items = eina_list_merge(wd->items, item->l);
430
431    if (!wd->current) elm_slideshow_show(item);
432
433    return item;
434 }
435
436 /**
437  * Insert an object in the list. The object can be a evas object image or a elm photo for example.
438  *
439  * @param obj The slideshow object
440  * @aram itc Callbacks used to create the object and delete the data associated when the item is deleted.
441  * @param data Data used by the user to identified the item
442  * @param func The function to compare data
443  * @return Returns The slideshow item
444  *
445  * @ingroup Slideshow
446  */
447 EAPI Elm_Slideshow_Item*
448 elm_slideshow_item_sorted_insert(Evas_Object *obj, const Elm_Slideshow_Item_Class *itc, const void *data, Eina_Compare_Cb func)
449 {
450    Elm_Slideshow_Item *item;
451    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
452    Widget_Data *wd = elm_widget_data_get(obj);
453
454    if (!wd) return NULL;
455    item = elm_widget_item_new(obj, Elm_Slideshow_Item);
456    item->base.data = data;
457    item->itc = itc;
458    item->l = eina_list_append(item->l, item);
459
460    wd->items = eina_list_sorted_merge(wd->items, item->l, func);
461
462    if (!wd->current) elm_slideshow_show(item);
463
464    return item;
465 }
466
467 /**
468  * Go to the item
469  *
470  * @param obj The slideshow object
471  * @param item The item
472  *
473  * @ingroup Slideshow
474  */
475 EAPI void
476 elm_slideshow_show(Elm_Slideshow_Item *item)
477 {
478    char buf[1024];
479    Elm_Slideshow_Item *next = NULL;
480    Widget_Data *wd;
481    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
482    wd = elm_widget_data_get(item->base.widget);
483    if (!wd)
484      return;
485    if (item == wd->current)
486      return;
487
488    next = item;
489    _end(item->base.widget, item->base.widget, NULL, NULL);
490
491    if (wd->timer) ecore_timer_del(wd->timer);
492    if (wd->timeout > 0.0)
493      wd->timer = ecore_timer_add(wd->timeout, _timer_cb, item->base.widget);
494    _item_realize(next);
495    edje_object_part_swallow(wd->slideshow, "elm.swallow.2", next->base.view);
496    evas_object_show(next->base.view);
497    snprintf(buf, sizeof(buf), "%s,next", wd->transition);
498    edje_object_signal_emit(wd->slideshow, buf, "slideshow");
499    wd->previous = wd->current;
500    wd->current = next;
501    evas_object_smart_callback_call(item->base.widget, SIG_CHANGED, wd->current);
502 }
503
504 /**
505  * Go to the next item
506  *
507  * @param obj The slideshow object
508  *
509  * @ingroup Slideshow
510  */
511 EAPI void
512 elm_slideshow_next(Evas_Object *obj)
513 {
514    char buf[1024];
515    Elm_Slideshow_Item *next = NULL;
516    ELM_CHECK_WIDTYPE(obj, widtype);
517    Widget_Data *wd = elm_widget_data_get(obj);
518
519    if (!wd) return;
520
521    if (wd->current)
522      next = _item_next_get(wd->current);
523
524    if ((!next) || (next == wd->current)) return;
525
526    _end(obj, obj, NULL, NULL);
527
528    if (wd->timer) ecore_timer_del(wd->timer);
529    if (wd->timeout > 0.0)
530      wd->timer = ecore_timer_add(wd->timeout, _timer_cb, obj);
531
532    _item_realize(next);
533
534    edje_object_part_swallow(wd->slideshow, "elm.swallow.2", next->base.view);
535    evas_object_show(next->base.view);
536
537    snprintf(buf, sizeof(buf), "%s,next", wd->transition);
538    edje_object_signal_emit(wd->slideshow, buf, "slideshow");
539
540    wd->previous = wd->current;
541    wd->current = next;
542    evas_object_smart_callback_call(obj, SIG_CHANGED, wd->current);
543 }
544
545 /**
546  * Go to the previous item
547  *
548  * @param obj The slideshow object
549  *
550  * @ingroup Slideshow
551  */
552 EAPI void
553 elm_slideshow_previous(Evas_Object *obj)
554 {
555    char buf[1024];
556    Elm_Slideshow_Item *prev = NULL;
557    ELM_CHECK_WIDTYPE(obj, widtype);
558    Widget_Data *wd = elm_widget_data_get(obj);
559
560    if (!wd) return;
561
562    if (wd->current)
563      prev = _item_prev_get(wd->current);
564
565    if ((!prev) ||  (prev == wd->current)) return;
566
567    _end(obj, obj, NULL, NULL);
568
569    if (wd->timer) ecore_timer_del(wd->timer);
570    if (wd->timeout > 0.0)
571      wd->timer = ecore_timer_add(wd->timeout, _timer_cb, obj);
572
573    _item_realize(prev);
574
575    edje_object_part_swallow(wd->slideshow, "elm.swallow.2", prev->base.view);
576    evas_object_show(prev->base.view);
577
578    snprintf(buf, 1024, "%s,previous", wd->transition);
579    edje_object_signal_emit(wd->slideshow, buf, "slideshow");
580
581    wd->previous = wd->current;
582    wd->current = prev;
583    evas_object_smart_callback_call(obj, SIG_CHANGED, wd->current);
584 }
585
586 /**
587  * Returns the list of transitions available.
588  *
589  * @param obj The slideshow object
590  * @return Returns the list of transitions (list of const char*)
591  *
592  * @ingroup Slideshow
593  */
594 EAPI const Eina_List *
595 elm_slideshow_transitions_get(const Evas_Object *obj)
596 {
597    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
598    Widget_Data *wd = elm_widget_data_get(obj);
599    if (!wd) return NULL;
600    return wd->transitions;
601 }
602
603 /**
604  * Returns the list of layouts available.
605  *
606  * @param obj The slideshow object
607  * @return Returns the list of layout (list of const char*)
608  *
609  * @ingroup Slideshow
610  */
611 EAPI const Eina_List *
612 elm_slideshow_layouts_get(const Evas_Object *obj)
613 {
614    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
615    Widget_Data *wd = elm_widget_data_get(obj);
616    if (!wd) return NULL;
617    return wd->layout.list;
618 }
619
620 /**
621  * Set the transition to use
622  *
623  * @param obj The slideshow object
624  * @param transition the new transition
625  *
626  * @ingroup Slideshow
627  */
628 EAPI void
629 elm_slideshow_transition_set(Evas_Object *obj, const char *transition)
630 {
631    ELM_CHECK_WIDTYPE(obj, widtype);
632    Widget_Data *wd = elm_widget_data_get(obj);
633    if (!wd) return;
634    eina_stringshare_replace(&wd->transition, transition);
635 }
636
637 /**
638  * Returns the transition to use
639  *
640  * @param obj The slideshow object
641  * @return the transition set
642  *
643  * @ingroup Slideshow
644  */
645 EAPI const char *
646 elm_slideshow_transition_get(const Evas_Object *obj)
647 {
648    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
649    Widget_Data *wd = elm_widget_data_get(obj);
650    if (!wd) return NULL;
651    return wd->transition;
652 }
653
654 /**
655  * The slideshow can go to the next item automatically after a few seconds.
656  * This method set the timeout to use. A timeout <=0 disable the timer.
657  *
658  * @param obj The slideshow object
659  * @param timeout The new timeout
660  *
661  * @ingroup Slideshow
662  */
663 EAPI void
664 elm_slideshow_timeout_set(Evas_Object *obj, double timeout)
665 {
666    ELM_CHECK_WIDTYPE(obj, widtype);
667    Widget_Data *wd = elm_widget_data_get(obj);
668    if (!wd) return;
669    wd->timeout = timeout;
670    if (wd->timer) ecore_timer_del(wd->timer);
671    wd->timer = NULL;
672    if (timeout > 0.0)
673      wd->timer = ecore_timer_add(timeout, _timer_cb, obj);
674 }
675
676 /**
677  * Returns the timeout value
678  *
679  * @param obj The slideshow object
680  * @return Returns the timeout
681  *
682  * @ingroup Slideshow
683  */
684 EAPI double
685 elm_slideshow_timeout_get(const Evas_Object *obj)
686 {
687    ELM_CHECK_WIDTYPE(obj, widtype) -1.0;
688    Widget_Data *wd = elm_widget_data_get(obj);
689    if (!wd) return -1.0;
690    return wd->timeout;
691 }
692
693 /**
694  * Set if the first item should follow the last and vice versa
695  *
696  * @param obj The slideshow object
697  * @param loop if EINA_TRUE, the first item will follow the last and vice versa
698  *
699  * @ingroup Slideshow
700  */
701 EAPI void
702 elm_slideshow_loop_set(Evas_Object *obj, Eina_Bool loop)
703 {
704    ELM_CHECK_WIDTYPE(obj, widtype);
705    Widget_Data *wd = elm_widget_data_get(obj);
706    if (!wd) return;
707    wd->loop = loop;
708 }
709
710 /**
711  * Returns the current layout name
712  *
713  * @param obj The slideshow object
714  * @returns Returns the layout name
715  *
716  * @ingroup Slideshow
717  */
718 EAPI const char *
719 elm_slideshow_layout_get(const Evas_Object *obj)
720 {
721    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
722    Widget_Data *wd = elm_widget_data_get(obj);
723    if (!wd) return EINA_FALSE;
724    return wd->layout.current;
725 }
726
727 /**
728  * Set the layout
729  *
730  * @param obj The slideshow object
731  * @param layout the new layout
732  *
733  * @ingroup Slideshow
734  */
735 EAPI void
736 elm_slideshow_layout_set(Evas_Object *obj, const char *layout)
737 {
738    char buf[PATH_MAX];
739    ELM_CHECK_WIDTYPE(obj, widtype);
740    Widget_Data *wd = elm_widget_data_get(obj);
741    if (!wd) return;
742
743    wd->layout.current = layout;
744    snprintf(buf, sizeof(buf), "layout,%s", layout);
745    edje_object_signal_emit(wd->slideshow, buf, "slideshow");
746 }
747
748 /**
749  * Return if the first item should follow the last and vice versa
750  *
751  * @param obj The slideshow object
752  * @returns Returns the loop flag
753  *
754  * @ingroup Slideshow
755  */
756 EAPI Eina_Bool
757 elm_slideshow_loop_get(const Evas_Object *obj)
758 {
759    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
760    Widget_Data *wd = elm_widget_data_get(obj);
761    if (!wd) return EINA_FALSE;
762    return wd->loop;
763 }
764
765 /**
766  * Delete all the items
767  *
768  * @param obj The slideshow object
769  *
770  * @ingroup Slideshow
771  */
772 EAPI void
773 elm_slideshow_clear(Evas_Object *obj)
774 {
775    Elm_Slideshow_Item *item;
776    ELM_CHECK_WIDTYPE(obj, widtype);
777    Widget_Data *wd = elm_widget_data_get(obj);
778    if (!wd) return;
779    wd->previous = NULL;
780    wd->current = NULL;
781    EINA_LIST_FREE(wd->items_built, item)
782      {
783         if (item->itc->func.del)
784           item->itc->func.del((void*)item->base.data, item->base.view);
785         evas_object_del(item->base.view);
786         item->base.view = NULL;
787      }
788
789    EINA_LIST_FREE(wd->items, item)
790      {
791         elm_widget_item_del(item);
792      }
793 }
794
795 /**
796  * Delete the item
797  *
798  * @param item The slideshow item
799  *
800  * @ingroup Slideshow
801  */
802 EAPI void
803 elm_slideshow_item_del(Elm_Slideshow_Item *item)
804 {
805    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
806    Widget_Data *wd = elm_widget_data_get(item->base.widget);
807    if (!wd) return;
808    if (wd->previous == item) wd->previous = NULL;
809    if (wd->current == item)
810      {
811         Eina_List *l = eina_list_data_find_list(wd->items, item);
812         Eina_List *l2 = eina_list_next(l);
813         wd->current = NULL;
814         if (!l2)
815           l2 = eina_list_nth_list(wd->items, eina_list_count(wd->items) - 1);
816         if (l2)
817           elm_slideshow_show(eina_list_data_get(l2));
818      }
819
820    wd->items = eina_list_remove_list(wd->items, item->l);
821    wd->items_built = eina_list_remove_list(wd->items_built, item->l_built);
822
823    if ((item->base.view) && (item->itc->func.del))
824      item->itc->func.del((void*)item->base.data, item->base.view);
825    if (item->base.view)
826      evas_object_del(item->base.view);
827    free(item);
828 }
829
830 /**
831  * Returns the list of items
832  * @param obj The slideshow object
833  * @return Returns the list of items (list of Elm_Slideshow_Item).
834  *
835  * @ingroup Slideshow
836  */
837 EAPI const Eina_List *
838 elm_slideshow_items_get(const Evas_Object *obj)
839 {
840    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
841    Widget_Data *wd = elm_widget_data_get(obj);
842    if (!wd) return NULL;
843    return wd->items;
844 }
845
846 /**
847  * Returns the current item displayed
848  *
849  * @param obj The slideshow object
850  * @return Returns the current item displayed
851  *
852  * @ingroup Slideshow
853  */
854 EAPI Elm_Slideshow_Item *
855 elm_slideshow_item_current_get(const Evas_Object *obj)
856 {
857    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
858    Widget_Data *wd = elm_widget_data_get(obj);
859    if (!wd) return NULL;
860    return wd->current;
861 }
862
863 /**
864  * Returns the evas object associated to an item
865  *
866  * @param item The slideshow item
867  * @return Returns the evas object associated to this item
868  *
869  * @ingroup Slideshow
870  */
871 EAPI Evas_Object *
872 elm_slideshow_item_object_get(const Elm_Slideshow_Item * item)
873 {
874    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
875    return item->base.view;
876 }
877
878 /**
879  * Returns the data associated to an item
880  *
881  * @param item The slideshow item
882  * @return Returns the data associated to this item
883  *
884  * @ingroup Slideshow
885  */
886 EAPI void *
887 elm_slideshow_item_data_get(const Elm_Slideshow_Item * item)
888 {
889    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
890    return elm_widget_item_data_get(item);
891 }
892
893 /**
894  * Returns max amount of cached items before current
895  *
896  * @param obj The slideshow object
897  * @return Returns max amount of cached items
898  *
899  * @ingroup Slideshow
900  */
901 EAPI int
902 elm_slideshow_cache_before_get(const Evas_Object *obj)
903 {
904    ELM_CHECK_WIDTYPE(obj, widtype) -1;
905    Widget_Data *wd = elm_widget_data_get(obj);
906    if (!wd) return -1;
907    return wd->count_item_pre_before;
908 }
909
910 /**
911  * Set max amount of cached items before current
912  *
913  * @param obj The slideshow object
914  * @param count Max amount of cached items
915  *
916  * @ingroup Slideshow
917  */
918 EAPI void
919 elm_slideshow_cache_before_set(Evas_Object *obj, int count)
920 {
921    ELM_CHECK_WIDTYPE(obj, widtype);
922    Widget_Data *wd = elm_widget_data_get(obj);
923    if (!wd) return;
924    if (count < 0) count = 0;
925    wd->count_item_pre_before = count;
926 }
927
928 /**
929  * Returns max amount of cached items after current
930  *
931  * @param obj The slideshow object
932  * @return Returns max amount of cached items
933  *
934  * @ingroup Slideshow
935  */
936 EAPI int
937 elm_slideshow_cache_after_get(const Evas_Object *obj)
938 {
939    ELM_CHECK_WIDTYPE(obj, widtype) -1;
940    Widget_Data *wd = elm_widget_data_get(obj);
941    if (!wd) return -1;
942    return wd->count_item_pre_after;
943 }
944
945 /**
946  * Set max amount of cached items after current
947  *
948  * @param obj The slideshow object
949  * @param count max amount of cached items
950  *
951  * @ingroup Slideshow
952  */
953 EAPI void
954 elm_slideshow_cache_after_set(Evas_Object *obj, int count)
955 {
956    ELM_CHECK_WIDTYPE(obj, widtype);
957    Widget_Data *wd = elm_widget_data_get(obj);
958    if (!wd) return;
959    if (count < 0) count = 0;
960    wd->count_item_pre_after = count;
961 }
962
963 /**
964  * Get the nth item of the slideshow
965  *
966  * @param obj The slideshow object
967  * @param nth The number of the element (0 being first)
968  * @return The item stored in slideshow at position required
969  *
970  * @ingroup Slideshow
971  */
972 EAPI Elm_Slideshow_Item *
973 elm_slideshow_item_nth_get(const Evas_Object *obj, unsigned int nth)
974 {
975    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
976    Widget_Data *wd = elm_widget_data_get(obj);
977    if (!wd) return NULL;
978    return eina_list_nth(wd->items, nth);
979 }
980
981 /**
982  * Get count of items stored in slideshow
983  *
984  * @param obj The slideshow object
985  * @return The count of items
986  *
987  * @ingroup Slideshow
988  */
989 EAPI unsigned int
990 elm_slideshow_count_get(const Evas_Object *obj)
991 {
992    ELM_CHECK_WIDTYPE(obj, widtype) 0;
993    Widget_Data *wd = elm_widget_data_get(obj);
994    if (!wd) return 0;
995    return eina_list_count(wd->items);
996 }