1 #include <Elementary.h>
4 typedef struct _Widget_Data Widget_Data;
6 struct _Elm_Slideshow_Item
10 Eina_List *l, *l_built;
12 const Elm_Slideshow_Item_Class *itc;
17 Evas_Object *slideshow;
19 // list of Elm_Slideshow_Item*
21 Eina_List *items_built;
23 Elm_Slideshow_Item *current;
24 Elm_Slideshow_Item *previous;
26 Eina_List *transitions;
27 const char *transition;
29 int count_item_pre_before;
30 int count_item_pre_after;
37 Eina_List *list; //list of const char *
41 static const char *widtype = NULL;
42 static void _del_hook(Evas_Object *obj);
43 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
44 static void _theme_hook(Evas_Object *obj);
45 static void _sizing_eval(Evas_Object *obj);
46 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
47 static Eina_Bool _timer_cb(void *data);
48 static void _on_focus_hook(void *data, Evas_Object *obj);
49 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src,
50 Evas_Callback_Type type, void *event_info);
52 static const char SIG_CHANGED[] = "changed";
54 static const Evas_Smart_Cb_Description _signals[] = {
60 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
62 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
63 Evas_Event_Key_Down *ev = event_info;
64 Widget_Data *wd = elm_widget_data_get(obj);
65 if (!wd) return EINA_FALSE;
66 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
67 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
68 if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")))
70 elm_slideshow_previous(obj);
71 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
74 if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")))
76 elm_slideshow_next(obj);
77 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
80 if ((!strcmp(ev->keyname, "Return")) ||
81 (!strcmp(ev->keyname, "KP_Enter")) ||
82 (!strcmp(ev->keyname, "space")))
88 ecore_timer_del(wd->timer);
92 elm_slideshow_timeout_set(obj, wd->timeout);
94 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
101 _del_hook(Evas_Object *obj)
104 Widget_Data *wd = elm_widget_data_get(obj);
106 elm_slideshow_clear(obj);
107 elm_widget_stringlist_free(wd->transitions);
108 if (wd->timer) ecore_timer_del(wd->timer);
109 EINA_LIST_FREE(wd->layout.list, layout)
110 eina_stringshare_del(layout);
115 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
117 Widget_Data *wd = elm_widget_data_get(obj);
119 if (elm_widget_focus_get(obj))
121 edje_object_signal_emit(wd->slideshow, "elm,action,focus", "elm");
122 evas_object_focus_set(wd->slideshow, EINA_TRUE);
126 edje_object_signal_emit(wd->slideshow, "elm,action,unfocus", "elm");
127 evas_object_focus_set(wd->slideshow, EINA_FALSE);
132 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
134 Widget_Data *wd = elm_widget_data_get(obj);
136 edje_object_mirrored_set(wd->slideshow, rtl);
140 _theme_hook(Evas_Object *obj)
142 Widget_Data *wd = elm_widget_data_get(obj);
144 _elm_widget_mirrored_reload(obj);
145 _mirrored_set(obj, elm_widget_mirrored_get(obj));
146 _elm_theme_object_set(obj, wd->slideshow, "slideshow", "base", elm_widget_style_get(obj));
147 edje_object_scale_set(wd->slideshow, elm_widget_scale_get(obj) *
153 _sizing_eval(Evas_Object *obj)
155 Widget_Data *wd = elm_widget_data_get(obj);
156 Evas_Coord minw = -1, minh = -1;
158 edje_object_size_min_calc(wd->slideshow, &minw, &minh);
159 evas_object_size_hint_min_set(obj, minw, minh);
160 evas_object_size_hint_max_set(obj, minw, minh);
164 static Elm_Slideshow_Item* _item_prev_get(Elm_Slideshow_Item* item)
166 Widget_Data *wd = elm_widget_data_get(item->base.widget);
167 Elm_Slideshow_Item* prev = eina_list_data_get(eina_list_prev(item->l));
168 if ((!prev) && (wd->loop))
169 prev = eina_list_data_get(eina_list_last(item->l));
173 static Elm_Slideshow_Item* _item_next_get(Elm_Slideshow_Item* item)
175 Widget_Data *wd = elm_widget_data_get(item->base.widget);
176 Elm_Slideshow_Item* next = eina_list_data_get(eina_list_next(item->l));
177 if ((!next) && (wd->loop))
178 next = eina_list_data_get(wd->items);
183 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
189 _sub_del(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
195 _item_realize(Elm_Slideshow_Item *item)
197 Elm_Slideshow_Item *_item_prev, *_item_next;
198 Evas_Object *obj = item->base.widget;
199 Widget_Data *wd = elm_widget_data_get(obj);
203 if ((!item->base.view) && (item->itc->func.get))
205 item->base.view = item->itc->func.get((void*)item->base.data, obj);
206 evas_object_smart_member_add(item->base.view, obj);
207 item->l_built = eina_list_append(NULL, item);
208 wd->items_built = eina_list_merge(wd->items_built, item->l_built);
209 evas_object_hide(item->base.view);
211 else if (item->l_built)
212 wd->items_built = eina_list_demote_list(wd->items_built, item->l_built);
214 //pre-create previous and next item
215 ac = wd->count_item_pre_after;
217 bc = wd->count_item_pre_before;
219 lc = eina_list_count(wd->items) - 1;
220 while (lc > 0 && ((ac > 0) || (bc > 0)))
222 if (lc > 0 && ac > 0)
228 _item_next = _item_next_get(_item_next);
230 && (!_item_next->base.view)
231 && (_item_next->itc->func.get))
233 _item_next->base.view =
234 _item_next->itc->func.get(
235 (void*)_item_next->base.data, obj);
236 evas_object_smart_member_add(_item_next->base.view, obj);
237 _item_next->l_built = eina_list_append(NULL, _item_next);
238 wd->items_built = eina_list_merge(wd->items_built,
239 _item_next->l_built);
240 evas_object_hide(_item_next->base.view);
242 else if (_item_next && _item_next->l_built)
244 eina_list_demote_list(wd->items_built,
245 _item_next->l_built);
249 if (lc > 0 && bc > 0)
255 _item_prev = _item_prev_get(_item_prev);
257 && (!_item_prev->base.view)
258 && (_item_prev->itc->func.get))
260 _item_prev->base.view =
261 _item_prev->itc->func.get(
262 (void*)_item_prev->base.data, obj);
263 evas_object_smart_member_add(_item_prev->base.view, obj);
264 _item_prev->l_built = eina_list_append(NULL, _item_prev);
265 wd->items_built = eina_list_merge(wd->items_built,
266 _item_prev->l_built);
267 evas_object_hide(_item_prev->base.view);
269 else if (_item_prev && _item_prev->l_built)
271 eina_list_demote_list(wd->items_built,
272 _item_prev->l_built);
277 //delete unused items
278 lc = wd->count_item_pre_before + wd->count_item_pre_after + 1;
279 while ((int)eina_list_count(wd->items_built) > lc)
281 item = eina_list_data_get(wd->items_built);
282 wd->items_built = eina_list_remove_list(wd->items_built,
284 if (item->itc->func.del)
285 item->itc->func.del((void*)item->base.data, item->base.view);
286 evas_object_del(item->base.view);
287 item->base.view = NULL;
292 _end(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
294 Elm_Slideshow_Item *item;
295 Widget_Data *wd = elm_widget_data_get(data);
301 edje_object_part_unswallow(NULL, item->base.view);
302 evas_object_hide(item->base.view);
308 if ((!item) || (!item->base.view)) return;
311 edje_object_part_unswallow(NULL, item->base.view);
312 evas_object_show(item->base.view);
314 edje_object_signal_emit(wd->slideshow, "anim,end", "slideshow");
315 edje_object_part_swallow(wd->slideshow, "elm.swallow.1", item->base.view);
319 _timer_cb(void *data)
321 Evas_Object *obj = data;
322 Widget_Data *wd = elm_widget_data_get(obj);
323 if (!wd) return ECORE_CALLBACK_CANCEL;
325 elm_slideshow_next(obj);
326 return ECORE_CALLBACK_CANCEL;
330 elm_slideshow_add(Evas_Object *parent)
336 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
338 ELM_SET_WIDTYPE(widtype, "slideshow");
339 elm_widget_type_set(obj, "slideshow");
340 elm_widget_sub_object_add(parent, obj);
341 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
342 elm_widget_data_set(obj, wd);
343 elm_widget_del_hook_set(obj, _del_hook);
344 elm_widget_theme_hook_set(obj, _theme_hook);
345 elm_widget_can_focus_set(obj, EINA_TRUE);
346 elm_widget_event_hook_set(obj, _event_hook);
351 wd->slideshow = edje_object_add(e);
352 _elm_theme_object_set(obj, wd->slideshow, "slideshow", "base", "default");
353 evas_object_smart_member_add(wd->slideshow, obj);
354 wd->count_item_pre_before = 2;
355 wd->count_item_pre_after = 2;
356 elm_widget_resize_object_set(obj, wd->slideshow);
357 evas_object_show(wd->slideshow);
359 wd->transitions = elm_widget_stringlist_get(edje_object_data_get(wd->slideshow, "transitions"));
360 if (eina_list_count(wd->transitions) > 0)
361 wd->transition = eina_stringshare_add(eina_list_data_get(wd->transitions));
363 wd->layout.list = elm_widget_stringlist_get(edje_object_data_get(wd->slideshow, "layouts"));
364 if (eina_list_count(wd->layout.list) > 0)
365 wd->layout.current = eina_list_data_get(wd->layout.list);
367 edje_object_signal_callback_add(wd->slideshow, "end", "slideshow", _end, obj);
369 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
370 evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
372 evas_object_smart_callbacks_descriptions_set(obj, _signals);
374 _mirrored_set(obj, elm_widget_mirrored_get(obj));
379 EAPI Elm_Slideshow_Item*
380 elm_slideshow_item_add(Evas_Object *obj, const Elm_Slideshow_Item_Class *itc, const void *data)
382 Elm_Slideshow_Item *item;
383 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
384 Widget_Data *wd = elm_widget_data_get(obj);
386 if (!wd) return NULL;
387 item = elm_widget_item_new(obj, Elm_Slideshow_Item);
388 item->base.data = data;
390 item->l = eina_list_append(item->l, item);
392 wd->items = eina_list_merge(wd->items, item->l);
394 if (!wd->current) elm_slideshow_show(item);
399 EAPI Elm_Slideshow_Item*
400 elm_slideshow_item_sorted_insert(Evas_Object *obj, const Elm_Slideshow_Item_Class *itc, const void *data, Eina_Compare_Cb func)
402 Elm_Slideshow_Item *item;
403 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
404 Widget_Data *wd = elm_widget_data_get(obj);
406 if (!wd) return NULL;
407 item = elm_widget_item_new(obj, Elm_Slideshow_Item);
408 item->base.data = data;
410 item->l = eina_list_append(item->l, item);
412 wd->items = eina_list_sorted_merge(wd->items, item->l, func);
414 if (!wd->current) elm_slideshow_show(item);
420 elm_slideshow_show(Elm_Slideshow_Item *item)
423 Elm_Slideshow_Item *next = NULL;
425 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
426 wd = elm_widget_data_get(item->base.widget);
429 if (item == wd->current)
433 _end(item->base.widget, item->base.widget, NULL, NULL);
435 if (wd->timer) ecore_timer_del(wd->timer);
436 if (wd->timeout > 0.0)
437 wd->timer = ecore_timer_add(wd->timeout, _timer_cb, item->base.widget);
439 edje_object_part_swallow(wd->slideshow, "elm.swallow.2", next->base.view);
440 evas_object_show(next->base.view);
441 snprintf(buf, sizeof(buf), "%s,next", wd->transition);
442 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
443 wd->previous = wd->current;
445 evas_object_smart_callback_call(item->base.widget, SIG_CHANGED, wd->current);
449 elm_slideshow_next(Evas_Object *obj)
452 Elm_Slideshow_Item *next = NULL;
453 ELM_CHECK_WIDTYPE(obj, widtype);
454 Widget_Data *wd = elm_widget_data_get(obj);
459 next = _item_next_get(wd->current);
461 if ((!next) || (next == wd->current)) return;
463 _end(obj, obj, NULL, NULL);
465 if (wd->timer) ecore_timer_del(wd->timer);
466 if (wd->timeout > 0.0)
467 wd->timer = ecore_timer_add(wd->timeout, _timer_cb, obj);
471 edje_object_part_swallow(wd->slideshow, "elm.swallow.2", next->base.view);
472 evas_object_show(next->base.view);
474 snprintf(buf, sizeof(buf), "%s,next", wd->transition);
475 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
477 wd->previous = wd->current;
479 evas_object_smart_callback_call(obj, SIG_CHANGED, wd->current);
483 elm_slideshow_previous(Evas_Object *obj)
486 Elm_Slideshow_Item *prev = NULL;
487 ELM_CHECK_WIDTYPE(obj, widtype);
488 Widget_Data *wd = elm_widget_data_get(obj);
493 prev = _item_prev_get(wd->current);
495 if ((!prev) || (prev == wd->current)) return;
497 _end(obj, obj, NULL, NULL);
499 if (wd->timer) ecore_timer_del(wd->timer);
500 if (wd->timeout > 0.0)
501 wd->timer = ecore_timer_add(wd->timeout, _timer_cb, obj);
505 edje_object_part_swallow(wd->slideshow, "elm.swallow.2", prev->base.view);
506 evas_object_show(prev->base.view);
508 snprintf(buf, 1024, "%s,previous", wd->transition);
509 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
511 wd->previous = wd->current;
513 evas_object_smart_callback_call(obj, SIG_CHANGED, wd->current);
516 EAPI const Eina_List *
517 elm_slideshow_transitions_get(const Evas_Object *obj)
519 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
520 Widget_Data *wd = elm_widget_data_get(obj);
521 if (!wd) return NULL;
522 return wd->transitions;
525 EAPI const Eina_List *
526 elm_slideshow_layouts_get(const Evas_Object *obj)
528 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
529 Widget_Data *wd = elm_widget_data_get(obj);
530 if (!wd) return NULL;
531 return wd->layout.list;
535 elm_slideshow_transition_set(Evas_Object *obj, const char *transition)
537 ELM_CHECK_WIDTYPE(obj, widtype);
538 Widget_Data *wd = elm_widget_data_get(obj);
540 eina_stringshare_replace(&wd->transition, transition);
544 elm_slideshow_transition_get(const Evas_Object *obj)
546 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
547 Widget_Data *wd = elm_widget_data_get(obj);
548 if (!wd) return NULL;
549 return wd->transition;
553 elm_slideshow_timeout_set(Evas_Object *obj, double timeout)
555 ELM_CHECK_WIDTYPE(obj, widtype);
556 Widget_Data *wd = elm_widget_data_get(obj);
558 wd->timeout = timeout;
559 if (wd->timer) ecore_timer_del(wd->timer);
562 wd->timer = ecore_timer_add(timeout, _timer_cb, obj);
566 elm_slideshow_timeout_get(const Evas_Object *obj)
568 ELM_CHECK_WIDTYPE(obj, widtype) -1.0;
569 Widget_Data *wd = elm_widget_data_get(obj);
570 if (!wd) return -1.0;
575 elm_slideshow_loop_set(Evas_Object *obj, Eina_Bool loop)
577 ELM_CHECK_WIDTYPE(obj, widtype);
578 Widget_Data *wd = elm_widget_data_get(obj);
584 elm_slideshow_layout_get(const Evas_Object *obj)
586 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
587 Widget_Data *wd = elm_widget_data_get(obj);
588 if (!wd) return EINA_FALSE;
589 return wd->layout.current;
593 elm_slideshow_layout_set(Evas_Object *obj, const char *layout)
596 ELM_CHECK_WIDTYPE(obj, widtype);
597 Widget_Data *wd = elm_widget_data_get(obj);
600 wd->layout.current = layout;
601 snprintf(buf, sizeof(buf), "layout,%s", layout);
602 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
606 elm_slideshow_loop_get(const Evas_Object *obj)
608 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
609 Widget_Data *wd = elm_widget_data_get(obj);
610 if (!wd) return EINA_FALSE;
615 elm_slideshow_clear(Evas_Object *obj)
617 Elm_Slideshow_Item *item;
618 ELM_CHECK_WIDTYPE(obj, widtype);
619 Widget_Data *wd = elm_widget_data_get(obj);
623 EINA_LIST_FREE(wd->items_built, item)
625 if (item->itc->func.del)
626 item->itc->func.del((void*)item->base.data, item->base.view);
627 evas_object_del(item->base.view);
628 item->base.view = NULL;
631 EINA_LIST_FREE(wd->items, item)
633 elm_widget_item_del(item);
638 elm_slideshow_item_del(Elm_Slideshow_Item *item)
640 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
641 Widget_Data *wd = elm_widget_data_get(item->base.widget);
643 if (wd->previous == item) wd->previous = NULL;
644 if (wd->current == item)
646 Eina_List *l = eina_list_data_find_list(wd->items, item);
647 Eina_List *l2 = eina_list_next(l);
650 l2 = eina_list_nth_list(wd->items, eina_list_count(wd->items) - 1);
652 elm_slideshow_show(eina_list_data_get(l2));
655 wd->items = eina_list_remove_list(wd->items, item->l);
656 wd->items_built = eina_list_remove_list(wd->items_built, item->l_built);
658 if ((item->base.view) && (item->itc->func.del))
659 item->itc->func.del((void*)item->base.data, item->base.view);
661 evas_object_del(item->base.view);
665 EAPI const Eina_List *
666 elm_slideshow_items_get(const Evas_Object *obj)
668 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
669 Widget_Data *wd = elm_widget_data_get(obj);
670 if (!wd) return NULL;
674 EAPI Elm_Slideshow_Item *
675 elm_slideshow_item_current_get(const Evas_Object *obj)
677 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
678 Widget_Data *wd = elm_widget_data_get(obj);
679 if (!wd) return NULL;
684 elm_slideshow_item_object_get(const Elm_Slideshow_Item * item)
686 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
687 return item->base.view;
691 elm_slideshow_item_data_get(const Elm_Slideshow_Item * item)
693 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
694 return elm_widget_item_data_get(item);
698 elm_slideshow_cache_before_get(const Evas_Object *obj)
700 ELM_CHECK_WIDTYPE(obj, widtype) -1;
701 Widget_Data *wd = elm_widget_data_get(obj);
703 return wd->count_item_pre_before;
707 elm_slideshow_cache_before_set(Evas_Object *obj, int count)
709 ELM_CHECK_WIDTYPE(obj, widtype);
710 Widget_Data *wd = elm_widget_data_get(obj);
712 if (count < 0) count = 0;
713 wd->count_item_pre_before = count;
717 elm_slideshow_cache_after_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_after;
726 elm_slideshow_cache_after_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_after = count;
735 EAPI Elm_Slideshow_Item *
736 elm_slideshow_item_nth_get(const Evas_Object *obj, unsigned int nth)
738 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
739 Widget_Data *wd = elm_widget_data_get(obj);
740 if (!wd) return NULL;
741 return eina_list_nth(wd->items, nth);
745 elm_slideshow_count_get(const Evas_Object *obj)
747 ELM_CHECK_WIDTYPE(obj, widtype) 0;
748 Widget_Data *wd = elm_widget_data_get(obj);
750 return eina_list_count(wd->items);