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")) ||
74 ((!strcmp(ev->keyname, "KP_Left")) && (!ev->string)))
76 elm_slideshow_previous(obj);
77 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
80 if ((!strcmp(ev->keyname, "Right")) ||
81 ((!strcmp(ev->keyname, "KP_Right")) && (!ev->string)))
83 elm_slideshow_next(obj);
84 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
87 if ((!strcmp(ev->keyname, "Return")) ||
88 (!strcmp(ev->keyname, "KP_Enter")) ||
89 (!strcmp(ev->keyname, "space")))
95 ecore_timer_del(wd->timer);
99 elm_slideshow_timeout_set(obj, wd->timeout);
101 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
108 _del_pre_hook(Evas_Object *obj)
110 Widget_Data *wd = elm_widget_data_get(obj);
112 evas_object_event_callback_del_full(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
113 _changed_size_hints, obj);
117 _del_hook(Evas_Object *obj)
120 Widget_Data *wd = elm_widget_data_get(obj);
122 elm_slideshow_clear(obj);
123 elm_widget_stringlist_free(wd->transitions);
124 if (wd->timer) ecore_timer_del(wd->timer);
125 EINA_LIST_FREE(wd->layout.list, layout)
126 eina_stringshare_del(layout);
131 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
133 Widget_Data *wd = elm_widget_data_get(obj);
135 if (elm_widget_focus_get(obj))
137 edje_object_signal_emit(wd->slideshow, "elm,action,focus", "elm");
138 evas_object_focus_set(wd->slideshow, EINA_TRUE);
142 edje_object_signal_emit(wd->slideshow, "elm,action,unfocus", "elm");
143 evas_object_focus_set(wd->slideshow, EINA_FALSE);
148 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
150 Widget_Data *wd = elm_widget_data_get(obj);
152 edje_object_mirrored_set(wd->slideshow, rtl);
156 _theme_hook(Evas_Object *obj)
158 Widget_Data *wd = elm_widget_data_get(obj);
160 _elm_widget_mirrored_reload(obj);
161 _mirrored_set(obj, elm_widget_mirrored_get(obj));
162 _elm_theme_object_set(obj, wd->slideshow, "slideshow", "base", elm_widget_style_get(obj));
163 edje_object_scale_set(wd->slideshow, elm_widget_scale_get(obj) *
169 _sizing_eval(Evas_Object *obj)
171 Widget_Data *wd = elm_widget_data_get(obj);
172 Evas_Coord minw = -1, minh = -1;
174 edje_object_size_min_calc(wd->slideshow, &minw, &minh);
175 evas_object_size_hint_min_set(obj, minw, minh);
176 evas_object_size_hint_max_set(obj, minw, minh);
180 static Elm_Slideshow_Item* _item_prev_get(Elm_Slideshow_Item* item)
182 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
183 Elm_Slideshow_Item* prev = eina_list_data_get(eina_list_prev(item->l));
184 if ((!prev) && (wd->loop))
185 prev = eina_list_data_get(eina_list_last(item->l));
189 static Elm_Slideshow_Item* _item_next_get(Elm_Slideshow_Item* item)
191 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
192 Elm_Slideshow_Item* next = eina_list_data_get(eina_list_next(item->l));
193 if ((!next) && (wd->loop))
194 next = eina_list_data_get(wd->items);
199 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
205 _sub_del(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
211 _item_realize(Elm_Slideshow_Item *item)
213 Elm_Slideshow_Item *_item_prev, *_item_next;
214 Evas_Object *obj = WIDGET(item);
215 Widget_Data *wd = elm_widget_data_get(obj);
216 int ac, bc, lc, ic = 0;
219 if ((!VIEW(item)) && (item->itc->func.get))
221 VIEW(item) = item->itc->func.get(elm_widget_item_data_get(item),
223 evas_object_smart_member_add(VIEW(item), obj);
224 item->l_built = eina_list_append(NULL, item);
225 wd->items_built = eina_list_merge(wd->items_built, item->l_built);
226 //FIXME: item could be showed by obj
227 evas_object_hide(VIEW(item));
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 ac = wd->count_item_pre_after;
235 bc = wd->count_item_pre_before;
237 lc = eina_list_count(wd->items) - 1;
238 while (lc > 0 && ((ac > 0) || (bc > 0)))
240 if (lc > 0 && ac > 0)
246 _item_next = _item_next_get(_item_next);
248 && (!VIEW(_item_next))
249 && (_item_next->itc->func.get))
253 _item_next->itc->func.get(
254 elm_widget_item_data_get(_item_next), obj);
255 evas_object_smart_member_add(VIEW(_item_next), 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 //FIXME: _item_next could be showed by obj later
260 evas_object_hide(VIEW(_item_next));
262 else if (_item_next && _item_next->l_built)
266 eina_list_demote_list(wd->items_built,
267 _item_next->l_built);
272 if (lc > 0 && bc > 0)
278 _item_prev = _item_prev_get(_item_prev);
280 && (!VIEW(_item_prev))
281 && (_item_prev->itc->func.get))
285 _item_prev->itc->func.get(
286 elm_widget_item_data_get(_item_prev), obj);
287 evas_object_smart_member_add(VIEW(_item_prev), obj);
288 _item_prev->l_built = eina_list_append(NULL, _item_prev);
289 wd->items_built = eina_list_merge(wd->items_built,
290 _item_prev->l_built);
291 //FIXME: _item_prev could be showed by obj later
292 evas_object_hide(VIEW(_item_prev));
294 else if (_item_prev && _item_prev->l_built)
298 eina_list_demote_list(wd->items_built,
299 _item_prev->l_built);
305 //delete unused items
307 while ((int)eina_list_count(wd->items_built) > lc)
309 item = eina_list_data_get(wd->items_built);
310 wd->items_built = eina_list_remove_list(wd->items_built,
312 if (item->itc->func.del)
313 item->itc->func.del(elm_widget_item_data_get(item), VIEW(item));
314 evas_object_del(VIEW(item));
320 _end(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
322 Elm_Slideshow_Item *item;
323 Widget_Data *wd = elm_widget_data_get(data);
329 edje_object_part_unswallow(wd->slideshow, VIEW(item));
330 evas_object_hide(VIEW(item));
335 if ((!item) || (!VIEW(item))) return;
338 edje_object_part_unswallow(wd->slideshow, VIEW(item));
340 edje_object_part_swallow(wd->slideshow, "elm.swallow.1", VIEW(item));
341 edje_object_signal_emit(wd->slideshow, "anim,end", "slideshow");
342 if (emission != NULL)
343 evas_object_smart_callback_call(data, SIG_TRANSITION_END, wd->current);
347 _timer_cb(void *data)
349 Evas_Object *obj = data;
350 Widget_Data *wd = elm_widget_data_get(obj);
351 if (!wd) return ECORE_CALLBACK_CANCEL;
353 elm_slideshow_next(obj);
354 return ECORE_CALLBACK_CANCEL;
358 _item_del_pre_hook(Elm_Object_Item *it)
360 Elm_Slideshow_Item *item = (Elm_Slideshow_Item *)it;
361 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
362 if (!wd) return EINA_FALSE;
364 if (wd->previous == item) wd->previous = NULL;
365 if (wd->current == item)
367 Eina_List *l = eina_list_data_find_list(wd->items, item);
368 Eina_List *l2 = eina_list_next(l);
372 l2 = eina_list_prev(l);
374 elm_slideshow_item_show(eina_list_data_get(l2));
378 elm_slideshow_item_show(eina_list_data_get(l2));
381 wd->items = eina_list_remove_list(wd->items, item->l);
382 wd->items_built = eina_list_remove_list(wd->items_built, item->l_built);
384 if ((VIEW(item)) && (item->itc->func.del))
385 item->itc->func.del(elm_widget_item_data_get(item), VIEW(item));
391 elm_slideshow_add(Evas_Object *parent)
397 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
399 ELM_SET_WIDTYPE(widtype, "slideshow");
400 elm_widget_type_set(obj, "slideshow");
401 elm_widget_sub_object_add(parent, obj);
402 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
403 elm_widget_data_set(obj, wd);
404 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
405 elm_widget_del_hook_set(obj, _del_hook);
406 elm_widget_theme_hook_set(obj, _theme_hook);
407 elm_widget_can_focus_set(obj, EINA_TRUE);
408 elm_widget_event_hook_set(obj, _event_hook);
413 wd->slideshow = edje_object_add(e);
414 _elm_theme_object_set(obj, wd->slideshow, "slideshow", "base", "default");
415 wd->count_item_pre_before = 2;
416 wd->count_item_pre_after = 2;
417 elm_widget_resize_object_set(obj, wd->slideshow);
419 wd->transitions = elm_widget_stringlist_get(edje_object_data_get(wd->slideshow, "transitions"));
420 if (eina_list_count(wd->transitions) > 0)
421 wd->transition = eina_stringshare_add(eina_list_data_get(wd->transitions));
423 wd->layout.list = elm_widget_stringlist_get(edje_object_data_get(wd->slideshow, "layouts"));
424 if (eina_list_count(wd->layout.list) > 0)
425 wd->layout.current = eina_list_data_get(wd->layout.list);
427 edje_object_signal_callback_add(wd->slideshow, "end", "slideshow", _end, obj);
429 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
430 evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
432 evas_object_smart_callbacks_descriptions_set(obj, _signals);
434 _mirrored_set(obj, elm_widget_mirrored_get(obj));
439 EAPI Elm_Object_Item*
440 elm_slideshow_item_add(Evas_Object *obj, const Elm_Slideshow_Item_Class *itc, const void *data)
442 Elm_Slideshow_Item *item;
443 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
444 Widget_Data *wd = elm_widget_data_get(obj);
446 if (!wd) return NULL;
447 item = elm_widget_item_new(obj, Elm_Slideshow_Item);
448 if (!item) return NULL;
449 elm_widget_item_del_pre_hook_set(item, _item_del_pre_hook);
451 item->l = eina_list_append(item->l, item);
452 elm_widget_item_data_set(item, data);
454 wd->items = eina_list_merge(wd->items, item->l);
456 if (!wd->current) elm_slideshow_item_show((Elm_Object_Item *)item);
458 return (Elm_Object_Item *)item;
461 EAPI Elm_Object_Item*
462 elm_slideshow_item_sorted_insert(Evas_Object *obj, const Elm_Slideshow_Item_Class *itc, const void *data, Eina_Compare_Cb func)
464 Elm_Slideshow_Item *item;
465 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
466 Widget_Data *wd = elm_widget_data_get(obj);
467 if (!wd) return NULL;
469 item = elm_widget_item_new(obj, Elm_Slideshow_Item);
470 if (!item) return NULL;
471 elm_widget_item_del_pre_hook_set(item, _item_del_pre_hook);
473 item->l = eina_list_append(item->l, item);
474 elm_widget_item_data_set(item, data);
476 wd->items = eina_list_sorted_merge(wd->items, item->l, func);
478 if (!wd->current) elm_slideshow_item_show((Elm_Object_Item *)item);
480 return (Elm_Object_Item *)item;
484 elm_slideshow_item_show(Elm_Object_Item *it)
486 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
489 Elm_Slideshow_Item *item, *next = NULL;
491 item = (Elm_Slideshow_Item *)it;
492 wd = elm_widget_data_get(WIDGET(item));
494 if (item == wd->current) return;
497 _end(WIDGET(item), WIDGET(item), NULL, NULL);
499 if (wd->timer) ecore_timer_del(wd->timer);
501 if (wd->timeout > 0.0)
502 wd->timer = ecore_timer_add(wd->timeout, _timer_cb, WIDGET(item));
504 edje_object_part_swallow(wd->slideshow, "elm.swallow.2", VIEW(next));
505 snprintf(buf, sizeof(buf), "%s,next", wd->transition);
506 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
507 wd->previous = wd->current;
509 evas_object_smart_callback_call(WIDGET(item), SIG_CHANGED, wd->current);
513 elm_slideshow_next(Evas_Object *obj)
516 Elm_Slideshow_Item *next = NULL;
517 ELM_CHECK_WIDTYPE(obj, widtype);
518 Widget_Data *wd = elm_widget_data_get(obj);
523 next = _item_next_get(wd->current);
525 if ((!next) || (next == wd->current)) return;
527 _end(obj, obj, NULL, NULL);
529 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);
565 if (wd->timeout > 0.0)
566 wd->timer = ecore_timer_add(wd->timeout, _timer_cb, obj);
570 edje_object_part_swallow(wd->slideshow, "elm.swallow.2", VIEW(prev));
572 snprintf(buf, 1024, "%s,previous", wd->transition);
573 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
575 wd->previous = wd->current;
577 evas_object_smart_callback_call(obj, SIG_CHANGED, wd->current);
580 EAPI const Eina_List *
581 elm_slideshow_transitions_get(const Evas_Object *obj)
583 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
584 Widget_Data *wd = elm_widget_data_get(obj);
585 if (!wd) return NULL;
586 return wd->transitions;
589 EAPI const Eina_List *
590 elm_slideshow_layouts_get(const Evas_Object *obj)
592 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
593 Widget_Data *wd = elm_widget_data_get(obj);
594 if (!wd) return NULL;
595 return wd->layout.list;
599 elm_slideshow_transition_set(Evas_Object *obj, const char *transition)
601 ELM_CHECK_WIDTYPE(obj, widtype);
602 Widget_Data *wd = elm_widget_data_get(obj);
604 eina_stringshare_replace(&wd->transition, transition);
608 elm_slideshow_transition_get(const Evas_Object *obj)
610 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
611 Widget_Data *wd = elm_widget_data_get(obj);
612 if (!wd) return NULL;
613 return wd->transition;
617 elm_slideshow_timeout_set(Evas_Object *obj, double timeout)
619 ELM_CHECK_WIDTYPE(obj, widtype);
620 Widget_Data *wd = elm_widget_data_get(obj);
622 wd->timeout = timeout;
623 if (wd->timer) ecore_timer_del(wd->timer);
626 wd->timer = ecore_timer_add(timeout, _timer_cb, obj);
630 elm_slideshow_timeout_get(const Evas_Object *obj)
632 ELM_CHECK_WIDTYPE(obj, widtype) -1.0;
633 Widget_Data *wd = elm_widget_data_get(obj);
634 if (!wd) return -1.0;
639 elm_slideshow_loop_set(Evas_Object *obj, Eina_Bool loop)
641 ELM_CHECK_WIDTYPE(obj, widtype);
642 Widget_Data *wd = elm_widget_data_get(obj);
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;
657 elm_slideshow_layout_set(Evas_Object *obj, const char *layout)
660 ELM_CHECK_WIDTYPE(obj, widtype);
661 Widget_Data *wd = elm_widget_data_get(obj);
664 wd->layout.current = layout;
665 snprintf(buf, sizeof(buf), "layout,%s", layout);
666 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
670 elm_slideshow_loop_get(const Evas_Object *obj)
672 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
673 Widget_Data *wd = elm_widget_data_get(obj);
674 if (!wd) return EINA_FALSE;
679 elm_slideshow_clear(Evas_Object *obj)
681 Elm_Slideshow_Item *item;
682 ELM_CHECK_WIDTYPE(obj, widtype);
683 Widget_Data *wd = elm_widget_data_get(obj);
687 EINA_LIST_FREE(wd->items_built, item)
689 if (item->itc->func.del)
690 item->itc->func.del(elm_widget_item_data_get(item), VIEW(item));
693 EINA_LIST_FREE(wd->items, item)
694 elm_widget_item_free(item);
697 EAPI const Eina_List *
698 elm_slideshow_items_get(const Evas_Object *obj)
700 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
701 Widget_Data *wd = elm_widget_data_get(obj);
702 if (!wd) return NULL;
706 EAPI Elm_Object_Item *
707 elm_slideshow_item_current_get(const Evas_Object *obj)
709 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
710 Widget_Data *wd = elm_widget_data_get(obj);
711 if (!wd) return NULL;
712 return (Elm_Object_Item *) wd->current;
716 elm_slideshow_item_object_get(const Elm_Object_Item * it)
718 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
723 elm_slideshow_cache_before_get(const Evas_Object *obj)
725 ELM_CHECK_WIDTYPE(obj, widtype) -1;
726 Widget_Data *wd = elm_widget_data_get(obj);
728 return wd->count_item_pre_before;
732 elm_slideshow_cache_before_set(Evas_Object *obj, int count)
734 ELM_CHECK_WIDTYPE(obj, widtype);
735 Widget_Data *wd = elm_widget_data_get(obj);
737 if (count < 0) count = 0;
738 wd->count_item_pre_before = count;
742 elm_slideshow_cache_after_get(const Evas_Object *obj)
744 ELM_CHECK_WIDTYPE(obj, widtype) -1;
745 Widget_Data *wd = elm_widget_data_get(obj);
747 return wd->count_item_pre_after;
751 elm_slideshow_cache_after_set(Evas_Object *obj, int count)
753 ELM_CHECK_WIDTYPE(obj, widtype);
754 Widget_Data *wd = elm_widget_data_get(obj);
756 if (count < 0) count = 0;
757 wd->count_item_pre_after = count;
760 EAPI Elm_Object_Item *
761 elm_slideshow_item_nth_get(const Evas_Object *obj, unsigned int nth)
763 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
764 Widget_Data *wd = elm_widget_data_get(obj);
765 if (!wd) return NULL;
766 return eina_list_nth(wd->items, nth);
770 elm_slideshow_count_get(const Evas_Object *obj)
772 ELM_CHECK_WIDTYPE(obj, widtype) 0;
773 Widget_Data *wd = elm_widget_data_get(obj);
775 return eina_list_count(wd->items);