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;
39 Eina_List *list; //list of const char *
43 static const char *widtype = NULL;
44 static void _del_pre_hook(Evas_Object *obj);
45 static void _del_hook(Evas_Object *obj);
46 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
47 static void _theme_hook(Evas_Object *obj);
48 static void _sizing_eval(Evas_Object *obj);
49 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
50 static Eina_Bool _timer_cb(void *data);
51 static void _on_focus_hook(void *data, Evas_Object *obj);
52 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src,
53 Evas_Callback_Type type, void *event_info);
55 static const char SIG_CHANGED[] = "changed";
56 static const char SIG_TRANSITION_END[] = "transition,end";
58 static const Evas_Smart_Cb_Description _signals[] = {
60 {SIG_TRANSITION_END, ""},
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_pre_hook(Evas_Object *obj)
108 Widget_Data *wd = elm_widget_data_get(obj);
110 evas_object_event_callback_del_full(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
111 _changed_size_hints, obj);
115 _del_hook(Evas_Object *obj)
118 Widget_Data *wd = elm_widget_data_get(obj);
120 elm_slideshow_clear(obj);
121 elm_widget_stringlist_free(wd->transitions);
122 if (wd->timer) ecore_timer_del(wd->timer);
123 EINA_LIST_FREE(wd->layout.list, layout)
124 eina_stringshare_del(layout);
129 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
131 Widget_Data *wd = elm_widget_data_get(obj);
133 if (elm_widget_focus_get(obj))
135 edje_object_signal_emit(wd->slideshow, "elm,action,focus", "elm");
136 evas_object_focus_set(wd->slideshow, EINA_TRUE);
140 edje_object_signal_emit(wd->slideshow, "elm,action,unfocus", "elm");
141 evas_object_focus_set(wd->slideshow, EINA_FALSE);
146 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
148 Widget_Data *wd = elm_widget_data_get(obj);
150 edje_object_mirrored_set(wd->slideshow, rtl);
154 _theme_hook(Evas_Object *obj)
156 Widget_Data *wd = elm_widget_data_get(obj);
158 _elm_widget_mirrored_reload(obj);
159 _mirrored_set(obj, elm_widget_mirrored_get(obj));
160 _elm_theme_object_set(obj, wd->slideshow, "slideshow", "base", elm_widget_style_get(obj));
161 edje_object_scale_set(wd->slideshow, elm_widget_scale_get(obj) *
167 _sizing_eval(Evas_Object *obj)
169 Widget_Data *wd = elm_widget_data_get(obj);
170 Evas_Coord minw = -1, minh = -1;
172 edje_object_size_min_calc(wd->slideshow, &minw, &minh);
173 evas_object_size_hint_min_set(obj, minw, minh);
174 evas_object_size_hint_max_set(obj, minw, minh);
178 static Elm_Slideshow_Item* _item_prev_get(Elm_Slideshow_Item* item)
180 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
181 Elm_Slideshow_Item* prev = eina_list_data_get(eina_list_prev(item->l));
182 if ((!prev) && (wd->loop))
183 prev = eina_list_data_get(eina_list_last(item->l));
187 static Elm_Slideshow_Item* _item_next_get(Elm_Slideshow_Item* item)
189 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
190 Elm_Slideshow_Item* next = eina_list_data_get(eina_list_next(item->l));
191 if ((!next) && (wd->loop))
192 next = eina_list_data_get(wd->items);
197 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
203 _sub_del(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
209 _item_realize(Elm_Slideshow_Item *item)
211 Elm_Slideshow_Item *_item_prev, *_item_next;
212 Evas_Object *obj = WIDGET(item);
213 Widget_Data *wd = elm_widget_data_get(obj);
214 int ac, bc, lc, ic = 0;
217 if ((!VIEW(item)) && (item->itc->func.get))
219 VIEW(item) = item->itc->func.get(elm_widget_item_data_get(item),
221 evas_object_smart_member_add(VIEW(item), obj);
222 item->l_built = eina_list_append(NULL, item);
223 wd->items_built = eina_list_merge(wd->items_built, item->l_built);
224 evas_object_hide(VIEW(item));
226 else if (item->l_built)
227 wd->items_built = eina_list_demote_list(wd->items_built, item->l_built);
229 //pre-create previous and next item
230 ac = wd->count_item_pre_after;
232 bc = wd->count_item_pre_before;
234 lc = eina_list_count(wd->items) - 1;
235 while (lc > 0 && ((ac > 0) || (bc > 0)))
237 if (lc > 0 && ac > 0)
243 _item_next = _item_next_get(_item_next);
245 && (!VIEW(_item_next))
246 && (_item_next->itc->func.get))
250 _item_next->itc->func.get(
251 elm_widget_item_data_get(_item_next), obj);
252 evas_object_smart_member_add(VIEW(_item_next), obj);
253 _item_next->l_built = eina_list_append(NULL, _item_next);
254 wd->items_built = eina_list_merge(wd->items_built,
255 _item_next->l_built);
256 evas_object_hide(VIEW(_item_next));
258 else if (_item_next && _item_next->l_built)
262 eina_list_demote_list(wd->items_built,
263 _item_next->l_built);
268 if (lc > 0 && bc > 0)
274 _item_prev = _item_prev_get(_item_prev);
276 && (!VIEW(_item_prev))
277 && (_item_prev->itc->func.get))
281 _item_prev->itc->func.get(
282 elm_widget_item_data_get(_item_prev), obj);
283 evas_object_smart_member_add(VIEW(_item_prev), obj);
284 _item_prev->l_built = eina_list_append(NULL, _item_prev);
285 wd->items_built = eina_list_merge(wd->items_built,
286 _item_prev->l_built);
287 evas_object_hide(VIEW(_item_prev));
289 else if (_item_prev && _item_prev->l_built)
293 eina_list_demote_list(wd->items_built,
294 _item_prev->l_built);
300 //delete unused items
302 while ((int)eina_list_count(wd->items_built) > lc)
304 item = eina_list_data_get(wd->items_built);
305 wd->items_built = eina_list_remove_list(wd->items_built,
307 if (item->itc->func.del)
308 item->itc->func.del(elm_widget_item_data_get(item), VIEW(item));
309 evas_object_del(VIEW(item));
315 _end(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
317 Elm_Slideshow_Item *item;
318 Widget_Data *wd = elm_widget_data_get(data);
324 edje_object_part_unswallow(wd->slideshow, VIEW(item));
325 evas_object_hide(VIEW(item));
330 if ((!item) || (!VIEW(item))) return;
333 edje_object_part_unswallow(wd->slideshow, VIEW(item));
335 edje_object_part_swallow(wd->slideshow, "elm.swallow.1", VIEW(item));
336 edje_object_signal_emit(wd->slideshow, "anim,end", "slideshow");
337 if (emission != NULL)
338 evas_object_smart_callback_call(data, SIG_TRANSITION_END, wd->current);
342 _timer_cb(void *data)
344 Evas_Object *obj = data;
345 Widget_Data *wd = elm_widget_data_get(obj);
346 if (!wd) return ECORE_CALLBACK_CANCEL;
348 elm_slideshow_next(obj);
349 return ECORE_CALLBACK_CANCEL;
353 _item_del_pre_hook(Elm_Object_Item *it)
355 Elm_Slideshow_Item *item = (Elm_Slideshow_Item *)it;
356 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
357 if (!wd) return EINA_FALSE;
359 if (wd->previous == item) wd->previous = NULL;
360 if (wd->current == item)
362 Eina_List *l = eina_list_data_find_list(wd->items, item);
363 Eina_List *l2 = eina_list_next(l);
367 l2 = eina_list_prev(l);
369 elm_slideshow_item_show(eina_list_data_get(l2));
373 elm_slideshow_item_show(eina_list_data_get(l2));
376 wd->items = eina_list_remove_list(wd->items, item->l);
377 wd->items_built = eina_list_remove_list(wd->items_built, item->l_built);
379 if ((VIEW(item)) && (item->itc->func.del))
380 item->itc->func.del(elm_widget_item_data_get(item), VIEW(item));
386 elm_slideshow_add(Evas_Object *parent)
392 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
394 ELM_SET_WIDTYPE(widtype, "slideshow");
395 elm_widget_type_set(obj, "slideshow");
396 elm_widget_sub_object_add(parent, obj);
397 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
398 elm_widget_data_set(obj, wd);
399 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
400 elm_widget_del_hook_set(obj, _del_hook);
401 elm_widget_theme_hook_set(obj, _theme_hook);
402 elm_widget_can_focus_set(obj, EINA_TRUE);
403 elm_widget_event_hook_set(obj, _event_hook);
408 wd->slideshow = edje_object_add(e);
409 _elm_theme_object_set(obj, wd->slideshow, "slideshow", "base", "default");
410 evas_object_smart_member_add(wd->slideshow, obj);
411 wd->count_item_pre_before = 2;
412 wd->count_item_pre_after = 2;
413 elm_widget_resize_object_set(obj, wd->slideshow);
414 evas_object_show(wd->slideshow);
416 wd->transitions = elm_widget_stringlist_get(edje_object_data_get(wd->slideshow, "transitions"));
417 if (eina_list_count(wd->transitions) > 0)
418 wd->transition = eina_stringshare_add(eina_list_data_get(wd->transitions));
420 wd->layout.list = elm_widget_stringlist_get(edje_object_data_get(wd->slideshow, "layouts"));
421 if (eina_list_count(wd->layout.list) > 0)
422 wd->layout.current = eina_list_data_get(wd->layout.list);
424 edje_object_signal_callback_add(wd->slideshow, "end", "slideshow", _end, obj);
426 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
427 evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
429 evas_object_smart_callbacks_descriptions_set(obj, _signals);
431 _mirrored_set(obj, elm_widget_mirrored_get(obj));
436 EAPI Elm_Object_Item*
437 elm_slideshow_item_add(Evas_Object *obj, const Elm_Slideshow_Item_Class *itc, const void *data)
439 Elm_Slideshow_Item *item;
440 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
441 Widget_Data *wd = elm_widget_data_get(obj);
443 if (!wd) return NULL;
444 item = elm_widget_item_new(obj, Elm_Slideshow_Item);
445 if (!item) return NULL;
446 elm_widget_item_del_pre_hook_set(item, _item_del_pre_hook);
448 item->l = eina_list_append(item->l, item);
449 elm_widget_item_data_set(item, data);
451 wd->items = eina_list_merge(wd->items, item->l);
453 if (!wd->current) elm_slideshow_item_show((Elm_Object_Item *)item);
455 return (Elm_Object_Item *)item;
458 EAPI Elm_Object_Item*
459 elm_slideshow_item_sorted_insert(Evas_Object *obj, const Elm_Slideshow_Item_Class *itc, const void *data, Eina_Compare_Cb func)
461 Elm_Slideshow_Item *item;
462 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
463 Widget_Data *wd = elm_widget_data_get(obj);
464 if (!wd) return NULL;
466 item = elm_widget_item_new(obj, Elm_Slideshow_Item);
467 if (!item) return NULL;
468 elm_widget_item_del_pre_hook_set(item, _item_del_pre_hook);
470 item->l = eina_list_append(item->l, item);
471 elm_widget_item_data_set(item, data);
473 wd->items = eina_list_sorted_merge(wd->items, item->l, func);
475 if (!wd->current) elm_slideshow_item_show((Elm_Object_Item *)item);
477 return (Elm_Object_Item *)item;
481 elm_slideshow_item_show(Elm_Object_Item *it)
483 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
486 Elm_Slideshow_Item *item, *next = NULL;
488 item = (Elm_Slideshow_Item *)it;
489 wd = elm_widget_data_get(WIDGET(item));
491 if (item == wd->current) return;
494 _end(WIDGET(item), WIDGET(item), NULL, NULL);
496 if (wd->timer) ecore_timer_del(wd->timer);
497 if (wd->timeout > 0.0)
498 wd->timer = ecore_timer_add(wd->timeout, _timer_cb, WIDGET(item));
500 edje_object_part_swallow(wd->slideshow, "elm.swallow.2", VIEW(next));
501 snprintf(buf, sizeof(buf), "%s,next", wd->transition);
502 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
503 wd->previous = wd->current;
505 evas_object_smart_callback_call(WIDGET(item), SIG_CHANGED, wd->current);
509 elm_slideshow_next(Evas_Object *obj)
512 Elm_Slideshow_Item *next = NULL;
513 ELM_CHECK_WIDTYPE(obj, widtype);
514 Widget_Data *wd = elm_widget_data_get(obj);
519 next = _item_next_get(wd->current);
521 if ((!next) || (next == wd->current)) return;
523 _end(obj, obj, NULL, NULL);
525 if (wd->timer) ecore_timer_del(wd->timer);
526 if (wd->timeout > 0.0)
527 wd->timer = ecore_timer_add(wd->timeout, _timer_cb, obj);
531 edje_object_part_swallow(wd->slideshow, "elm.swallow.2", VIEW(next));
533 snprintf(buf, sizeof(buf), "%s,next", wd->transition);
534 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
536 wd->previous = wd->current;
538 evas_object_smart_callback_call(obj, SIG_CHANGED, wd->current);
542 elm_slideshow_previous(Evas_Object *obj)
545 Elm_Slideshow_Item *prev = NULL;
546 ELM_CHECK_WIDTYPE(obj, widtype);
547 Widget_Data *wd = elm_widget_data_get(obj);
552 prev = _item_prev_get(wd->current);
554 if ((!prev) || (prev == wd->current)) return;
556 _end(obj, obj, NULL, NULL);
558 if (wd->timer) ecore_timer_del(wd->timer);
559 if (wd->timeout > 0.0)
560 wd->timer = ecore_timer_add(wd->timeout, _timer_cb, obj);
564 edje_object_part_swallow(wd->slideshow, "elm.swallow.2", VIEW(prev));
566 snprintf(buf, 1024, "%s,previous", wd->transition);
567 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
569 wd->previous = wd->current;
571 evas_object_smart_callback_call(obj, SIG_CHANGED, wd->current);
574 EAPI const Eina_List *
575 elm_slideshow_transitions_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->transitions;
583 EAPI const Eina_List *
584 elm_slideshow_layouts_get(const Evas_Object *obj)
586 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
587 Widget_Data *wd = elm_widget_data_get(obj);
588 if (!wd) return NULL;
589 return wd->layout.list;
593 elm_slideshow_transition_set(Evas_Object *obj, const char *transition)
595 ELM_CHECK_WIDTYPE(obj, widtype);
596 Widget_Data *wd = elm_widget_data_get(obj);
598 eina_stringshare_replace(&wd->transition, transition);
602 elm_slideshow_transition_get(const Evas_Object *obj)
604 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
605 Widget_Data *wd = elm_widget_data_get(obj);
606 if (!wd) return NULL;
607 return wd->transition;
611 elm_slideshow_timeout_set(Evas_Object *obj, double timeout)
613 ELM_CHECK_WIDTYPE(obj, widtype);
614 Widget_Data *wd = elm_widget_data_get(obj);
616 wd->timeout = timeout;
617 if (wd->timer) ecore_timer_del(wd->timer);
620 wd->timer = ecore_timer_add(timeout, _timer_cb, obj);
624 elm_slideshow_timeout_get(const Evas_Object *obj)
626 ELM_CHECK_WIDTYPE(obj, widtype) -1.0;
627 Widget_Data *wd = elm_widget_data_get(obj);
628 if (!wd) return -1.0;
633 elm_slideshow_loop_set(Evas_Object *obj, Eina_Bool loop)
635 ELM_CHECK_WIDTYPE(obj, widtype);
636 Widget_Data *wd = elm_widget_data_get(obj);
642 elm_slideshow_layout_get(const Evas_Object *obj)
644 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
645 Widget_Data *wd = elm_widget_data_get(obj);
646 if (!wd) return EINA_FALSE;
647 return wd->layout.current;
651 elm_slideshow_layout_set(Evas_Object *obj, const char *layout)
654 ELM_CHECK_WIDTYPE(obj, widtype);
655 Widget_Data *wd = elm_widget_data_get(obj);
658 wd->layout.current = layout;
659 snprintf(buf, sizeof(buf), "layout,%s", layout);
660 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
664 elm_slideshow_loop_get(const Evas_Object *obj)
666 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
667 Widget_Data *wd = elm_widget_data_get(obj);
668 if (!wd) return EINA_FALSE;
673 elm_slideshow_clear(Evas_Object *obj)
675 Elm_Slideshow_Item *item;
676 ELM_CHECK_WIDTYPE(obj, widtype);
677 Widget_Data *wd = elm_widget_data_get(obj);
681 EINA_LIST_FREE(wd->items_built, item)
683 if (item->itc->func.del)
684 item->itc->func.del(elm_widget_item_data_get(item), VIEW(item));
687 EINA_LIST_FREE(wd->items, item)
688 elm_widget_item_free(item);
691 EAPI const Eina_List *
692 elm_slideshow_items_get(const Evas_Object *obj)
694 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
695 Widget_Data *wd = elm_widget_data_get(obj);
696 if (!wd) return NULL;
700 EAPI Elm_Object_Item *
701 elm_slideshow_item_current_get(const Evas_Object *obj)
703 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
704 Widget_Data *wd = elm_widget_data_get(obj);
705 if (!wd) return NULL;
706 return (Elm_Object_Item *) wd->current;
710 elm_slideshow_item_object_get(const Elm_Object_Item * it)
712 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
717 elm_slideshow_cache_before_get(const Evas_Object *obj)
719 ELM_CHECK_WIDTYPE(obj, widtype) -1;
720 Widget_Data *wd = elm_widget_data_get(obj);
722 return wd->count_item_pre_before;
726 elm_slideshow_cache_before_set(Evas_Object *obj, int count)
728 ELM_CHECK_WIDTYPE(obj, widtype);
729 Widget_Data *wd = elm_widget_data_get(obj);
731 if (count < 0) count = 0;
732 wd->count_item_pre_before = count;
736 elm_slideshow_cache_after_get(const Evas_Object *obj)
738 ELM_CHECK_WIDTYPE(obj, widtype) -1;
739 Widget_Data *wd = elm_widget_data_get(obj);
741 return wd->count_item_pre_after;
745 elm_slideshow_cache_after_set(Evas_Object *obj, int count)
747 ELM_CHECK_WIDTYPE(obj, widtype);
748 Widget_Data *wd = elm_widget_data_get(obj);
750 if (count < 0) count = 0;
751 wd->count_item_pre_after = count;
754 EAPI Elm_Object_Item *
755 elm_slideshow_item_nth_get(const Evas_Object *obj, unsigned int nth)
757 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
758 Widget_Data *wd = elm_widget_data_get(obj);
759 if (!wd) return NULL;
760 return eina_list_nth(wd->items, nth);
764 elm_slideshow_count_get(const Evas_Object *obj)
766 ELM_CHECK_WIDTYPE(obj, widtype) 0;
767 Widget_Data *wd = elm_widget_data_get(obj);
769 return eina_list_count(wd->items);