1 #include <Elementary.h>
4 typedef struct _Widget_Data Widget_Data;
5 typedef struct _Elm_Slideshow_Item Elm_Slideshow_Item;
7 struct _Elm_Slideshow_Item
11 Eina_List *l, *l_built;
13 const Elm_Slideshow_Item_Class *itc;
18 Evas_Object *slideshow;
20 // list of Elm_Slideshow_Item*
22 Eina_List *items_built;
24 Elm_Slideshow_Item *current;
25 Elm_Slideshow_Item *previous;
27 Eina_List *transitions;
28 const char *transition;
30 int count_item_pre_before;
31 int count_item_pre_after;
38 Eina_List *list; //list of const char *
42 static const char *widtype = NULL;
43 static void _del_pre_hook(Evas_Object *obj);
44 static void _del_hook(Evas_Object *obj);
45 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
46 static void _theme_hook(Evas_Object *obj);
47 static void _sizing_eval(Evas_Object *obj);
48 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
49 static Eina_Bool _timer_cb(void *data);
50 static void _on_focus_hook(void *data, Evas_Object *obj);
51 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src,
52 Evas_Callback_Type type, void *event_info);
54 static const char SIG_CHANGED[] = "changed";
55 static const char SIG_TRANSITION_END[] = "transition,end";
57 static const Evas_Smart_Cb_Description _signals[] = {
59 {SIG_TRANSITION_END, ""},
64 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
66 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
67 Evas_Event_Key_Down *ev = event_info;
68 Widget_Data *wd = elm_widget_data_get(obj);
69 if (!wd) return EINA_FALSE;
70 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
71 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
72 if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")))
74 elm_slideshow_previous(obj);
75 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
78 if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")))
80 elm_slideshow_next(obj);
81 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
84 if ((!strcmp(ev->keyname, "Return")) ||
85 (!strcmp(ev->keyname, "KP_Enter")) ||
86 (!strcmp(ev->keyname, "space")))
92 ecore_timer_del(wd->timer);
96 elm_slideshow_timeout_set(obj, wd->timeout);
98 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
105 _del_pre_hook(Evas_Object *obj)
107 Widget_Data *wd = elm_widget_data_get(obj);
109 evas_object_event_callback_del_full(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
110 _changed_size_hints, obj);
114 _del_hook(Evas_Object *obj)
117 Widget_Data *wd = elm_widget_data_get(obj);
119 elm_slideshow_clear(obj);
120 elm_widget_stringlist_free(wd->transitions);
121 if (wd->timer) ecore_timer_del(wd->timer);
122 EINA_LIST_FREE(wd->layout.list, layout)
123 eina_stringshare_del(layout);
128 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
130 Widget_Data *wd = elm_widget_data_get(obj);
132 if (elm_widget_focus_get(obj))
134 edje_object_signal_emit(wd->slideshow, "elm,action,focus", "elm");
135 evas_object_focus_set(wd->slideshow, EINA_TRUE);
139 edje_object_signal_emit(wd->slideshow, "elm,action,unfocus", "elm");
140 evas_object_focus_set(wd->slideshow, EINA_FALSE);
145 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
147 Widget_Data *wd = elm_widget_data_get(obj);
149 edje_object_mirrored_set(wd->slideshow, rtl);
153 _theme_hook(Evas_Object *obj)
155 Widget_Data *wd = elm_widget_data_get(obj);
157 _elm_widget_mirrored_reload(obj);
158 _mirrored_set(obj, elm_widget_mirrored_get(obj));
159 _elm_theme_object_set(obj, wd->slideshow, "slideshow", "base", elm_widget_style_get(obj));
160 edje_object_scale_set(wd->slideshow, elm_widget_scale_get(obj) *
166 _sizing_eval(Evas_Object *obj)
168 Widget_Data *wd = elm_widget_data_get(obj);
169 Evas_Coord minw = -1, minh = -1;
171 edje_object_size_min_calc(wd->slideshow, &minw, &minh);
172 evas_object_size_hint_min_set(obj, minw, minh);
173 evas_object_size_hint_max_set(obj, minw, minh);
177 static Elm_Slideshow_Item* _item_prev_get(Elm_Slideshow_Item* item)
179 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
180 Elm_Slideshow_Item* prev = eina_list_data_get(eina_list_prev(item->l));
181 if ((!prev) && (wd->loop))
182 prev = eina_list_data_get(eina_list_last(item->l));
186 static Elm_Slideshow_Item* _item_next_get(Elm_Slideshow_Item* item)
188 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
189 Elm_Slideshow_Item* next = eina_list_data_get(eina_list_next(item->l));
190 if ((!next) && (wd->loop))
191 next = eina_list_data_get(wd->items);
196 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
202 _sub_del(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
208 _item_realize(Elm_Slideshow_Item *item)
210 Elm_Slideshow_Item *_item_prev, *_item_next;
211 Evas_Object *obj = WIDGET(item);
212 Widget_Data *wd = elm_widget_data_get(obj);
213 int ac, bc, lc, ic = 0;
216 if ((!VIEW(item)) && (item->itc->func.get))
218 VIEW(item) = item->itc->func.get(elm_widget_item_data_get(item),
220 evas_object_smart_member_add(VIEW(item), obj);
221 item->l_built = eina_list_append(NULL, item);
222 wd->items_built = eina_list_merge(wd->items_built, item->l_built);
223 evas_object_hide(VIEW(item));
225 else if (item->l_built)
226 wd->items_built = eina_list_demote_list(wd->items_built, item->l_built);
228 //pre-create previous and next item
229 ac = wd->count_item_pre_after;
231 bc = wd->count_item_pre_before;
233 lc = eina_list_count(wd->items) - 1;
234 while (lc > 0 && ((ac > 0) || (bc > 0)))
236 if (lc > 0 && ac > 0)
242 _item_next = _item_next_get(_item_next);
244 && (!VIEW(_item_next))
245 && (_item_next->itc->func.get))
249 _item_next->itc->func.get(
250 elm_widget_item_data_get(_item_next), obj);
251 evas_object_smart_member_add(VIEW(_item_next), obj);
252 _item_next->l_built = eina_list_append(NULL, _item_next);
253 wd->items_built = eina_list_merge(wd->items_built,
254 _item_next->l_built);
255 evas_object_hide(VIEW(_item_next));
257 else if (_item_next && _item_next->l_built)
261 eina_list_demote_list(wd->items_built,
262 _item_next->l_built);
267 if (lc > 0 && bc > 0)
273 _item_prev = _item_prev_get(_item_prev);
275 && (!VIEW(_item_prev))
276 && (_item_prev->itc->func.get))
280 _item_prev->itc->func.get(
281 elm_widget_item_data_get(_item_prev), obj);
282 evas_object_smart_member_add(VIEW(_item_prev), 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(VIEW(_item_prev));
288 else if (_item_prev && _item_prev->l_built)
292 eina_list_demote_list(wd->items_built,
293 _item_prev->l_built);
299 //delete unused items
301 while ((int)eina_list_count(wd->items_built) > lc)
303 item = eina_list_data_get(wd->items_built);
304 wd->items_built = eina_list_remove_list(wd->items_built,
306 if (item->itc->func.del)
307 item->itc->func.del(elm_widget_item_data_get(item), VIEW(item));
308 evas_object_del(VIEW(item));
314 _end(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
316 Elm_Slideshow_Item *item;
317 Widget_Data *wd = elm_widget_data_get(data);
323 edje_object_part_unswallow(wd->slideshow, VIEW(item));
324 evas_object_hide(VIEW(item));
329 if ((!item) || (!VIEW(item))) return;
332 edje_object_part_unswallow(wd->slideshow, VIEW(item));
334 edje_object_part_swallow(wd->slideshow, "elm.swallow.1", VIEW(item));
335 edje_object_signal_emit(wd->slideshow, "anim,end", "slideshow");
336 if (emission != NULL)
337 evas_object_smart_callback_call(data, SIG_TRANSITION_END, wd->current);
341 _timer_cb(void *data)
343 Evas_Object *obj = data;
344 Widget_Data *wd = elm_widget_data_get(obj);
345 if (!wd) return ECORE_CALLBACK_CANCEL;
347 elm_slideshow_next(obj);
348 return ECORE_CALLBACK_CANCEL;
352 _item_del_pre_hook(Elm_Object_Item *it)
354 Elm_Slideshow_Item *item = (Elm_Slideshow_Item *)it;
355 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
356 if (!wd) return EINA_FALSE;
358 if (wd->previous == item) wd->previous = NULL;
359 if (wd->current == item)
361 Eina_List *l = eina_list_data_find_list(wd->items, item);
362 Eina_List *l2 = eina_list_next(l);
366 l2 = eina_list_prev(l);
368 elm_slideshow_item_show(eina_list_data_get(l2));
372 elm_slideshow_item_show(eina_list_data_get(l2));
375 wd->items = eina_list_remove_list(wd->items, item->l);
376 wd->items_built = eina_list_remove_list(wd->items_built, item->l_built);
378 if ((VIEW(item)) && (item->itc->func.del))
379 item->itc->func.del(elm_widget_item_data_get(item), VIEW(item));
385 elm_slideshow_add(Evas_Object *parent)
391 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
393 ELM_SET_WIDTYPE(widtype, "slideshow");
394 elm_widget_type_set(obj, "slideshow");
395 elm_widget_sub_object_add(parent, obj);
396 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
397 elm_widget_data_set(obj, wd);
398 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
399 elm_widget_del_hook_set(obj, _del_hook);
400 elm_widget_theme_hook_set(obj, _theme_hook);
401 elm_widget_can_focus_set(obj, EINA_TRUE);
402 elm_widget_event_hook_set(obj, _event_hook);
407 wd->slideshow = edje_object_add(e);
408 _elm_theme_object_set(obj, wd->slideshow, "slideshow", "base", "default");
409 evas_object_smart_member_add(wd->slideshow, obj);
410 wd->count_item_pre_before = 2;
411 wd->count_item_pre_after = 2;
412 elm_widget_resize_object_set(obj, wd->slideshow);
413 evas_object_show(wd->slideshow);
415 wd->transitions = elm_widget_stringlist_get(edje_object_data_get(wd->slideshow, "transitions"));
416 if (eina_list_count(wd->transitions) > 0)
417 wd->transition = eina_stringshare_add(eina_list_data_get(wd->transitions));
419 wd->layout.list = elm_widget_stringlist_get(edje_object_data_get(wd->slideshow, "layouts"));
420 if (eina_list_count(wd->layout.list) > 0)
421 wd->layout.current = eina_list_data_get(wd->layout.list);
423 edje_object_signal_callback_add(wd->slideshow, "end", "slideshow", _end, obj);
425 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
426 evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
428 evas_object_smart_callbacks_descriptions_set(obj, _signals);
430 _mirrored_set(obj, elm_widget_mirrored_get(obj));
435 EAPI Elm_Object_Item*
436 elm_slideshow_item_add(Evas_Object *obj, const Elm_Slideshow_Item_Class *itc, const void *data)
438 Elm_Slideshow_Item *item;
439 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
440 Widget_Data *wd = elm_widget_data_get(obj);
442 if (!wd) return NULL;
443 item = elm_widget_item_new(obj, Elm_Slideshow_Item);
444 if (!item) return NULL;
445 elm_widget_item_del_pre_hook_set(item, _item_del_pre_hook);
447 item->l = eina_list_append(item->l, item);
448 elm_widget_item_data_set(item, data);
450 wd->items = eina_list_merge(wd->items, item->l);
452 if (!wd->current) elm_slideshow_item_show((Elm_Object_Item *)item);
454 return (Elm_Object_Item *)item;
457 EAPI Elm_Object_Item*
458 elm_slideshow_item_sorted_insert(Evas_Object *obj, const Elm_Slideshow_Item_Class *itc, const void *data, Eina_Compare_Cb func)
460 Elm_Slideshow_Item *item;
461 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
462 Widget_Data *wd = elm_widget_data_get(obj);
463 if (!wd) return NULL;
465 item = elm_widget_item_new(obj, Elm_Slideshow_Item);
466 if (!item) return NULL;
467 elm_widget_item_del_pre_hook_set(item, _item_del_pre_hook);
469 item->l = eina_list_append(item->l, item);
470 elm_widget_item_data_set(item, data);
472 wd->items = eina_list_sorted_merge(wd->items, item->l, func);
474 if (!wd->current) elm_slideshow_item_show((Elm_Object_Item *)item);
476 return (Elm_Object_Item *)item;
480 elm_slideshow_item_show(Elm_Object_Item *it)
482 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
485 Elm_Slideshow_Item *item, *next = NULL;
487 item = (Elm_Slideshow_Item *)it;
488 wd = elm_widget_data_get(WIDGET(item));
490 if (item == wd->current) return;
493 _end(WIDGET(item), WIDGET(item), NULL, NULL);
495 if (wd->timer) ecore_timer_del(wd->timer);
496 if (wd->timeout > 0.0)
497 wd->timer = ecore_timer_add(wd->timeout, _timer_cb, WIDGET(item));
499 edje_object_part_swallow(wd->slideshow, "elm.swallow.2", VIEW(next));
500 snprintf(buf, sizeof(buf), "%s,next", wd->transition);
501 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
502 wd->previous = wd->current;
504 evas_object_smart_callback_call(WIDGET(item), SIG_CHANGED, wd->current);
507 EINA_DEPRECATED EAPI void
508 elm_slideshow_show(Elm_Object_Item *it)
510 elm_slideshow_item_show(it);
514 elm_slideshow_next(Evas_Object *obj)
517 Elm_Slideshow_Item *next = NULL;
518 ELM_CHECK_WIDTYPE(obj, widtype);
519 Widget_Data *wd = elm_widget_data_get(obj);
524 next = _item_next_get(wd->current);
526 if ((!next) || (next == wd->current)) return;
528 _end(obj, obj, NULL, NULL);
530 if (wd->timer) ecore_timer_del(wd->timer);
531 if (wd->timeout > 0.0)
532 wd->timer = ecore_timer_add(wd->timeout, _timer_cb, obj);
536 edje_object_part_swallow(wd->slideshow, "elm.swallow.2", VIEW(next));
538 snprintf(buf, sizeof(buf), "%s,next", wd->transition);
539 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
541 wd->previous = wd->current;
543 evas_object_smart_callback_call(obj, SIG_CHANGED, wd->current);
547 elm_slideshow_previous(Evas_Object *obj)
550 Elm_Slideshow_Item *prev = NULL;
551 ELM_CHECK_WIDTYPE(obj, widtype);
552 Widget_Data *wd = elm_widget_data_get(obj);
557 prev = _item_prev_get(wd->current);
559 if ((!prev) || (prev == wd->current)) return;
561 _end(obj, obj, NULL, NULL);
563 if (wd->timer) ecore_timer_del(wd->timer);
564 if (wd->timeout > 0.0)
565 wd->timer = ecore_timer_add(wd->timeout, _timer_cb, obj);
569 edje_object_part_swallow(wd->slideshow, "elm.swallow.2", VIEW(prev));
571 snprintf(buf, 1024, "%s,previous", wd->transition);
572 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
574 wd->previous = wd->current;
576 evas_object_smart_callback_call(obj, SIG_CHANGED, wd->current);
579 EAPI const Eina_List *
580 elm_slideshow_transitions_get(const Evas_Object *obj)
582 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
583 Widget_Data *wd = elm_widget_data_get(obj);
584 if (!wd) return NULL;
585 return wd->transitions;
588 EAPI const Eina_List *
589 elm_slideshow_layouts_get(const Evas_Object *obj)
591 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
592 Widget_Data *wd = elm_widget_data_get(obj);
593 if (!wd) return NULL;
594 return wd->layout.list;
598 elm_slideshow_transition_set(Evas_Object *obj, const char *transition)
600 ELM_CHECK_WIDTYPE(obj, widtype);
601 Widget_Data *wd = elm_widget_data_get(obj);
603 eina_stringshare_replace(&wd->transition, transition);
607 elm_slideshow_transition_get(const Evas_Object *obj)
609 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
610 Widget_Data *wd = elm_widget_data_get(obj);
611 if (!wd) return NULL;
612 return wd->transition;
616 elm_slideshow_timeout_set(Evas_Object *obj, double timeout)
618 ELM_CHECK_WIDTYPE(obj, widtype);
619 Widget_Data *wd = elm_widget_data_get(obj);
621 wd->timeout = timeout;
622 if (wd->timer) ecore_timer_del(wd->timer);
625 wd->timer = ecore_timer_add(timeout, _timer_cb, obj);
629 elm_slideshow_timeout_get(const Evas_Object *obj)
631 ELM_CHECK_WIDTYPE(obj, widtype) -1.0;
632 Widget_Data *wd = elm_widget_data_get(obj);
633 if (!wd) return -1.0;
638 elm_slideshow_loop_set(Evas_Object *obj, Eina_Bool loop)
640 ELM_CHECK_WIDTYPE(obj, widtype);
641 Widget_Data *wd = elm_widget_data_get(obj);
647 elm_slideshow_layout_get(const Evas_Object *obj)
649 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
650 Widget_Data *wd = elm_widget_data_get(obj);
651 if (!wd) return EINA_FALSE;
652 return wd->layout.current;
656 elm_slideshow_layout_set(Evas_Object *obj, const char *layout)
659 ELM_CHECK_WIDTYPE(obj, widtype);
660 Widget_Data *wd = elm_widget_data_get(obj);
663 wd->layout.current = layout;
664 snprintf(buf, sizeof(buf), "layout,%s", layout);
665 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
669 elm_slideshow_loop_get(const Evas_Object *obj)
671 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
672 Widget_Data *wd = elm_widget_data_get(obj);
673 if (!wd) return EINA_FALSE;
678 elm_slideshow_clear(Evas_Object *obj)
680 Elm_Slideshow_Item *item;
681 ELM_CHECK_WIDTYPE(obj, widtype);
682 Widget_Data *wd = elm_widget_data_get(obj);
686 EINA_LIST_FREE(wd->items_built, item)
688 if (item->itc->func.del)
689 item->itc->func.del(elm_widget_item_data_get(item), VIEW(item));
692 EINA_LIST_FREE(wd->items, item)
693 elm_widget_item_free(item);
697 elm_slideshow_item_del(Elm_Object_Item *it)
699 elm_object_item_del(it);
702 EAPI const Eina_List *
703 elm_slideshow_items_get(const Evas_Object *obj)
705 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
706 Widget_Data *wd = elm_widget_data_get(obj);
707 if (!wd) return NULL;
711 EAPI Elm_Object_Item *
712 elm_slideshow_item_current_get(const Evas_Object *obj)
714 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
715 Widget_Data *wd = elm_widget_data_get(obj);
716 if (!wd) return NULL;
717 return (Elm_Object_Item *) wd->current;
721 elm_slideshow_item_object_get(const Elm_Object_Item * it)
723 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
728 elm_slideshow_item_data_get(const Elm_Object_Item * it)
730 return elm_object_item_data_get(it);
734 elm_slideshow_cache_before_get(const Evas_Object *obj)
736 ELM_CHECK_WIDTYPE(obj, widtype) -1;
737 Widget_Data *wd = elm_widget_data_get(obj);
739 return wd->count_item_pre_before;
743 elm_slideshow_cache_before_set(Evas_Object *obj, int count)
745 ELM_CHECK_WIDTYPE(obj, widtype);
746 Widget_Data *wd = elm_widget_data_get(obj);
748 if (count < 0) count = 0;
749 wd->count_item_pre_before = count;
753 elm_slideshow_cache_after_get(const Evas_Object *obj)
755 ELM_CHECK_WIDTYPE(obj, widtype) -1;
756 Widget_Data *wd = elm_widget_data_get(obj);
758 return wd->count_item_pre_after;
762 elm_slideshow_cache_after_set(Evas_Object *obj, int count)
764 ELM_CHECK_WIDTYPE(obj, widtype);
765 Widget_Data *wd = elm_widget_data_get(obj);
767 if (count < 0) count = 0;
768 wd->count_item_pre_after = count;
771 EAPI Elm_Object_Item *
772 elm_slideshow_item_nth_get(const Evas_Object *obj, unsigned int nth)
774 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
775 Widget_Data *wd = elm_widget_data_get(obj);
776 if (!wd) return NULL;
777 return eina_list_nth(wd->items, nth);
781 elm_slideshow_count_get(const Evas_Object *obj)
783 ELM_CHECK_WIDTYPE(obj, widtype) 0;
784 Widget_Data *wd = elm_widget_data_get(obj);
786 return eina_list_count(wd->items);