1 #include <Elementary.h>
4 typedef struct _Widget_Data Widget_Data;
6 typedef struct _Elm_Slideshow_Item Elm_Slideshow_Item;
8 struct _Elm_Slideshow_Item
12 Eina_List *l, *l_built;
14 const Elm_Slideshow_Item_Class *itc;
19 Evas_Object *slideshow;
21 // list of Elm_Slideshow_Item*
23 Eina_List *items_built;
25 Elm_Slideshow_Item *current;
26 Elm_Slideshow_Item *previous;
28 Eina_List *transitions;
29 const char *transition;
31 int count_item_pre_before;
32 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_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
357 Elm_Slideshow_Item *item = (Elm_Slideshow_Item *) it;
358 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
359 if (!wd) return EINA_FALSE;
361 if (wd->previous == item) wd->previous = NULL;
362 if (wd->current == item)
364 Eina_List *l = eina_list_data_find_list(wd->items, item);
365 Eina_List *l2 = eina_list_next(l);
369 l2 = eina_list_prev(l);
371 elm_slideshow_show(eina_list_data_get(l2));
375 elm_slideshow_show(eina_list_data_get(l2));
378 wd->items = eina_list_remove_list(wd->items, item->l);
379 wd->items_built = eina_list_remove_list(wd->items_built, item->l_built);
381 if ((VIEW(item)) && (item->itc->func.del))
382 item->itc->func.del(elm_widget_item_data_get(item), VIEW(item));
388 elm_slideshow_add(Evas_Object *parent)
394 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
396 ELM_SET_WIDTYPE(widtype, "slideshow");
397 elm_widget_type_set(obj, "slideshow");
398 elm_widget_sub_object_add(parent, obj);
399 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
400 elm_widget_data_set(obj, wd);
401 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
402 elm_widget_del_hook_set(obj, _del_hook);
403 elm_widget_theme_hook_set(obj, _theme_hook);
404 elm_widget_can_focus_set(obj, EINA_TRUE);
405 elm_widget_event_hook_set(obj, _event_hook);
410 wd->slideshow = edje_object_add(e);
411 _elm_theme_object_set(obj, wd->slideshow, "slideshow", "base", "default");
412 evas_object_smart_member_add(wd->slideshow, obj);
413 wd->count_item_pre_before = 2;
414 wd->count_item_pre_after = 2;
415 elm_widget_resize_object_set(obj, wd->slideshow);
416 evas_object_show(wd->slideshow);
418 wd->transitions = elm_widget_stringlist_get(edje_object_data_get(wd->slideshow, "transitions"));
419 if (eina_list_count(wd->transitions) > 0)
420 wd->transition = eina_stringshare_add(eina_list_data_get(wd->transitions));
422 wd->layout.list = elm_widget_stringlist_get(edje_object_data_get(wd->slideshow, "layouts"));
423 if (eina_list_count(wd->layout.list) > 0)
424 wd->layout.current = eina_list_data_get(wd->layout.list);
426 edje_object_signal_callback_add(wd->slideshow, "end", "slideshow", _end, obj);
428 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
429 evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
431 evas_object_smart_callbacks_descriptions_set(obj, _signals);
433 _mirrored_set(obj, elm_widget_mirrored_get(obj));
438 EAPI Elm_Object_Item*
439 elm_slideshow_item_add(Evas_Object *obj, const Elm_Slideshow_Item_Class *itc, const void *data)
441 Elm_Slideshow_Item *item;
442 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
443 Widget_Data *wd = elm_widget_data_get(obj);
445 if (!wd) return NULL;
446 item = elm_widget_item_new(obj, Elm_Slideshow_Item);
447 if (!item) return NULL;
448 elm_widget_item_del_pre_hook_set(item, _item_del_pre_hook);
450 item->l = eina_list_append(item->l, item);
451 elm_widget_item_data_set(item, data);
453 wd->items = eina_list_merge(wd->items, item->l);
455 if (!wd->current) elm_slideshow_show((Elm_Object_Item *) item);
457 return (Elm_Object_Item *) item;
460 EAPI Elm_Object_Item*
461 elm_slideshow_item_sorted_insert(Evas_Object *obj, const Elm_Slideshow_Item_Class *itc, const void *data, Eina_Compare_Cb func)
463 Elm_Slideshow_Item *item;
464 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
465 Widget_Data *wd = elm_widget_data_get(obj);
466 if (!wd) return NULL;
468 item = elm_widget_item_new(obj, Elm_Slideshow_Item);
469 if (!item) return NULL;
470 elm_widget_item_del_pre_hook_set(item, _item_del_pre_hook);
472 item->l = eina_list_append(item->l, item);
473 elm_widget_item_data_set(item, data);
475 wd->items = eina_list_sorted_merge(wd->items, item->l, func);
477 if (!wd->current) elm_slideshow_show((Elm_Object_Item *) item);
479 return (Elm_Object_Item *) item;
483 elm_slideshow_show(Elm_Object_Item *it)
485 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
488 Elm_Slideshow_Item *item, *next = NULL;
490 item = (Elm_Slideshow_Item *) it;
491 wd = elm_widget_data_get(WIDGET(item));
493 if (item == wd->current) return;
496 _end(WIDGET(item), WIDGET(item), 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, WIDGET(item));
502 edje_object_part_swallow(wd->slideshow, "elm.swallow.2", VIEW(next));
503 snprintf(buf, sizeof(buf), "%s,next", wd->transition);
504 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
505 wd->previous = wd->current;
507 evas_object_smart_callback_call(WIDGET(item), SIG_CHANGED, wd->current);
511 elm_slideshow_next(Evas_Object *obj)
514 Elm_Slideshow_Item *next = NULL;
515 ELM_CHECK_WIDTYPE(obj, widtype);
516 Widget_Data *wd = elm_widget_data_get(obj);
521 next = _item_next_get(wd->current);
523 if ((!next) || (next == wd->current)) return;
525 _end(obj, obj, NULL, NULL);
527 if (wd->timer) ecore_timer_del(wd->timer);
528 if (wd->timeout > 0.0)
529 wd->timer = ecore_timer_add(wd->timeout, _timer_cb, obj);
533 edje_object_part_swallow(wd->slideshow, "elm.swallow.2", VIEW(next));
535 snprintf(buf, sizeof(buf), "%s,next", wd->transition);
536 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
538 wd->previous = wd->current;
540 evas_object_smart_callback_call(obj, SIG_CHANGED, wd->current);
544 elm_slideshow_previous(Evas_Object *obj)
547 Elm_Slideshow_Item *prev = NULL;
548 ELM_CHECK_WIDTYPE(obj, widtype);
549 Widget_Data *wd = elm_widget_data_get(obj);
554 prev = _item_prev_get(wd->current);
556 if ((!prev) || (prev == wd->current)) return;
558 _end(obj, obj, NULL, NULL);
560 if (wd->timer) ecore_timer_del(wd->timer);
561 if (wd->timeout > 0.0)
562 wd->timer = ecore_timer_add(wd->timeout, _timer_cb, obj);
566 edje_object_part_swallow(wd->slideshow, "elm.swallow.2", VIEW(prev));
568 snprintf(buf, 1024, "%s,previous", wd->transition);
569 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
571 wd->previous = wd->current;
573 evas_object_smart_callback_call(obj, SIG_CHANGED, wd->current);
576 EAPI const Eina_List *
577 elm_slideshow_transitions_get(const Evas_Object *obj)
579 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
580 Widget_Data *wd = elm_widget_data_get(obj);
581 if (!wd) return NULL;
582 return wd->transitions;
585 EAPI const Eina_List *
586 elm_slideshow_layouts_get(const Evas_Object *obj)
588 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
589 Widget_Data *wd = elm_widget_data_get(obj);
590 if (!wd) return NULL;
591 return wd->layout.list;
595 elm_slideshow_transition_set(Evas_Object *obj, const char *transition)
597 ELM_CHECK_WIDTYPE(obj, widtype);
598 Widget_Data *wd = elm_widget_data_get(obj);
600 eina_stringshare_replace(&wd->transition, transition);
604 elm_slideshow_transition_get(const Evas_Object *obj)
606 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
607 Widget_Data *wd = elm_widget_data_get(obj);
608 if (!wd) return NULL;
609 return wd->transition;
613 elm_slideshow_timeout_set(Evas_Object *obj, double timeout)
615 ELM_CHECK_WIDTYPE(obj, widtype);
616 Widget_Data *wd = elm_widget_data_get(obj);
618 wd->timeout = timeout;
619 if (wd->timer) ecore_timer_del(wd->timer);
622 wd->timer = ecore_timer_add(timeout, _timer_cb, obj);
626 elm_slideshow_timeout_get(const Evas_Object *obj)
628 ELM_CHECK_WIDTYPE(obj, widtype) -1.0;
629 Widget_Data *wd = elm_widget_data_get(obj);
630 if (!wd) return -1.0;
635 elm_slideshow_loop_set(Evas_Object *obj, Eina_Bool loop)
637 ELM_CHECK_WIDTYPE(obj, widtype);
638 Widget_Data *wd = elm_widget_data_get(obj);
644 elm_slideshow_layout_get(const Evas_Object *obj)
646 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
647 Widget_Data *wd = elm_widget_data_get(obj);
648 if (!wd) return EINA_FALSE;
649 return wd->layout.current;
653 elm_slideshow_layout_set(Evas_Object *obj, const char *layout)
656 ELM_CHECK_WIDTYPE(obj, widtype);
657 Widget_Data *wd = elm_widget_data_get(obj);
660 wd->layout.current = layout;
661 snprintf(buf, sizeof(buf), "layout,%s", layout);
662 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
666 elm_slideshow_loop_get(const Evas_Object *obj)
668 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
669 Widget_Data *wd = elm_widget_data_get(obj);
670 if (!wd) return EINA_FALSE;
675 elm_slideshow_clear(Evas_Object *obj)
677 Elm_Slideshow_Item *item;
678 ELM_CHECK_WIDTYPE(obj, widtype);
679 Widget_Data *wd = elm_widget_data_get(obj);
683 EINA_LIST_FREE(wd->items_built, item)
685 if (item->itc->func.del)
686 item->itc->func.del(elm_widget_item_data_get(item), VIEW(item));
689 EINA_LIST_FREE(wd->items, item)
690 elm_widget_item_free(item);
694 elm_slideshow_item_del(Elm_Object_Item *it)
696 elm_object_item_del(it);
699 EAPI const Eina_List *
700 elm_slideshow_items_get(const Evas_Object *obj)
702 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
703 Widget_Data *wd = elm_widget_data_get(obj);
704 if (!wd) return NULL;
708 EAPI Elm_Object_Item *
709 elm_slideshow_item_current_get(const Evas_Object *obj)
711 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
712 Widget_Data *wd = elm_widget_data_get(obj);
713 if (!wd) return NULL;
714 return (Elm_Object_Item *) wd->current;
718 elm_slideshow_item_object_get(const Elm_Object_Item * it)
720 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
725 elm_slideshow_item_data_get(const Elm_Object_Item * it)
727 return elm_object_item_data_get(it);
731 elm_slideshow_cache_before_get(const Evas_Object *obj)
733 ELM_CHECK_WIDTYPE(obj, widtype) -1;
734 Widget_Data *wd = elm_widget_data_get(obj);
736 return wd->count_item_pre_before;
740 elm_slideshow_cache_before_set(Evas_Object *obj, int count)
742 ELM_CHECK_WIDTYPE(obj, widtype);
743 Widget_Data *wd = elm_widget_data_get(obj);
745 if (count < 0) count = 0;
746 wd->count_item_pre_before = count;
750 elm_slideshow_cache_after_get(const Evas_Object *obj)
752 ELM_CHECK_WIDTYPE(obj, widtype) -1;
753 Widget_Data *wd = elm_widget_data_get(obj);
755 return wd->count_item_pre_after;
759 elm_slideshow_cache_after_set(Evas_Object *obj, int count)
761 ELM_CHECK_WIDTYPE(obj, widtype);
762 Widget_Data *wd = elm_widget_data_get(obj);
764 if (count < 0) count = 0;
765 wd->count_item_pre_after = count;
768 EAPI Elm_Object_Item *
769 elm_slideshow_item_nth_get(const Evas_Object *obj, unsigned int nth)
771 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
772 Widget_Data *wd = elm_widget_data_get(obj);
773 if (!wd) return NULL;
774 return eina_list_nth(wd->items, nth);
778 elm_slideshow_count_get(const Evas_Object *obj)
780 ELM_CHECK_WIDTYPE(obj, widtype) 0;
781 Widget_Data *wd = elm_widget_data_get(obj);
783 return eina_list_count(wd->items);