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);
200 int ac, bc, lc, ic = 0;
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))
234 _item_next->base.view =
235 _item_next->itc->func.get(
236 (void*)_item_next->base.data, obj);
237 evas_object_smart_member_add(_item_next->base.view, obj);
238 _item_next->l_built = eina_list_append(NULL, _item_next);
239 wd->items_built = eina_list_merge(wd->items_built,
240 _item_next->l_built);
241 evas_object_hide(_item_next->base.view);
243 else if (_item_next && _item_next->l_built)
247 eina_list_demote_list(wd->items_built,
248 _item_next->l_built);
253 if (lc > 0 && bc > 0)
259 _item_prev = _item_prev_get(_item_prev);
261 && (!_item_prev->base.view)
262 && (_item_prev->itc->func.get))
265 _item_prev->base.view =
266 _item_prev->itc->func.get(
267 (void*)_item_prev->base.data, obj);
268 evas_object_smart_member_add(_item_prev->base.view, obj);
269 _item_prev->l_built = eina_list_append(NULL, _item_prev);
270 wd->items_built = eina_list_merge(wd->items_built,
271 _item_prev->l_built);
272 evas_object_hide(_item_prev->base.view);
274 else if (_item_prev && _item_prev->l_built)
278 eina_list_demote_list(wd->items_built,
279 _item_prev->l_built);
285 //delete unused items
287 while ((int)eina_list_count(wd->items_built) > lc)
289 item = eina_list_data_get(wd->items_built);
290 wd->items_built = eina_list_remove_list(wd->items_built,
292 if (item->itc->func.del)
293 item->itc->func.del((void*)item->base.data, item->base.view);
294 evas_object_del(item->base.view);
295 item->base.view = NULL;
300 _end(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
302 Elm_Slideshow_Item *item;
303 Widget_Data *wd = elm_widget_data_get(data);
309 edje_object_part_unswallow(NULL, item->base.view);
310 evas_object_hide(item->base.view);
316 if ((!item) || (!item->base.view)) return;
319 edje_object_part_unswallow(NULL, item->base.view);
320 evas_object_show(item->base.view);
322 edje_object_signal_emit(wd->slideshow, "anim,end", "slideshow");
323 edje_object_part_swallow(wd->slideshow, "elm.swallow.1", item->base.view);
327 _timer_cb(void *data)
329 Evas_Object *obj = data;
330 Widget_Data *wd = elm_widget_data_get(obj);
331 if (!wd) return ECORE_CALLBACK_CANCEL;
333 elm_slideshow_next(obj);
334 return ECORE_CALLBACK_CANCEL;
338 elm_slideshow_add(Evas_Object *parent)
344 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
346 ELM_SET_WIDTYPE(widtype, "slideshow");
347 elm_widget_type_set(obj, "slideshow");
348 elm_widget_sub_object_add(parent, obj);
349 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
350 elm_widget_data_set(obj, wd);
351 elm_widget_del_hook_set(obj, _del_hook);
352 elm_widget_theme_hook_set(obj, _theme_hook);
353 elm_widget_can_focus_set(obj, EINA_TRUE);
354 elm_widget_event_hook_set(obj, _event_hook);
359 wd->slideshow = edje_object_add(e);
360 _elm_theme_object_set(obj, wd->slideshow, "slideshow", "base", "default");
361 evas_object_smart_member_add(wd->slideshow, obj);
362 wd->count_item_pre_before = 2;
363 wd->count_item_pre_after = 2;
364 elm_widget_resize_object_set(obj, wd->slideshow);
365 evas_object_show(wd->slideshow);
367 wd->transitions = elm_widget_stringlist_get(edje_object_data_get(wd->slideshow, "transitions"));
368 if (eina_list_count(wd->transitions) > 0)
369 wd->transition = eina_stringshare_add(eina_list_data_get(wd->transitions));
371 wd->layout.list = elm_widget_stringlist_get(edje_object_data_get(wd->slideshow, "layouts"));
372 if (eina_list_count(wd->layout.list) > 0)
373 wd->layout.current = eina_list_data_get(wd->layout.list);
375 edje_object_signal_callback_add(wd->slideshow, "end", "slideshow", _end, obj);
377 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
378 evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
380 evas_object_smart_callbacks_descriptions_set(obj, _signals);
382 _mirrored_set(obj, elm_widget_mirrored_get(obj));
387 EAPI Elm_Slideshow_Item*
388 elm_slideshow_item_add(Evas_Object *obj, const Elm_Slideshow_Item_Class *itc, const void *data)
390 Elm_Slideshow_Item *item;
391 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
392 Widget_Data *wd = elm_widget_data_get(obj);
394 if (!wd) return NULL;
395 item = elm_widget_item_new(obj, Elm_Slideshow_Item);
396 item->base.data = data;
398 item->l = eina_list_append(item->l, item);
400 wd->items = eina_list_merge(wd->items, item->l);
402 if (!wd->current) elm_slideshow_show(item);
407 EAPI Elm_Slideshow_Item*
408 elm_slideshow_item_sorted_insert(Evas_Object *obj, const Elm_Slideshow_Item_Class *itc, const void *data, Eina_Compare_Cb func)
410 Elm_Slideshow_Item *item;
411 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
412 Widget_Data *wd = elm_widget_data_get(obj);
414 if (!wd) return NULL;
415 item = elm_widget_item_new(obj, Elm_Slideshow_Item);
416 item->base.data = data;
418 item->l = eina_list_append(item->l, item);
420 wd->items = eina_list_sorted_merge(wd->items, item->l, func);
422 if (!wd->current) elm_slideshow_show(item);
428 elm_slideshow_show(Elm_Slideshow_Item *item)
431 Elm_Slideshow_Item *next = NULL;
433 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
434 wd = elm_widget_data_get(item->base.widget);
437 if (item == wd->current)
441 _end(item->base.widget, item->base.widget, NULL, NULL);
443 if (wd->timer) ecore_timer_del(wd->timer);
444 if (wd->timeout > 0.0)
445 wd->timer = ecore_timer_add(wd->timeout, _timer_cb, item->base.widget);
447 edje_object_part_swallow(wd->slideshow, "elm.swallow.2", next->base.view);
448 evas_object_show(next->base.view);
449 snprintf(buf, sizeof(buf), "%s,next", wd->transition);
450 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
451 wd->previous = wd->current;
453 evas_object_smart_callback_call(item->base.widget, SIG_CHANGED, wd->current);
457 elm_slideshow_next(Evas_Object *obj)
460 Elm_Slideshow_Item *next = NULL;
461 ELM_CHECK_WIDTYPE(obj, widtype);
462 Widget_Data *wd = elm_widget_data_get(obj);
467 next = _item_next_get(wd->current);
469 if ((!next) || (next == wd->current)) return;
471 _end(obj, obj, NULL, NULL);
473 if (wd->timer) ecore_timer_del(wd->timer);
474 if (wd->timeout > 0.0)
475 wd->timer = ecore_timer_add(wd->timeout, _timer_cb, obj);
479 edje_object_part_swallow(wd->slideshow, "elm.swallow.2", next->base.view);
480 evas_object_show(next->base.view);
482 snprintf(buf, sizeof(buf), "%s,next", wd->transition);
483 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
485 wd->previous = wd->current;
487 evas_object_smart_callback_call(obj, SIG_CHANGED, wd->current);
491 elm_slideshow_previous(Evas_Object *obj)
494 Elm_Slideshow_Item *prev = NULL;
495 ELM_CHECK_WIDTYPE(obj, widtype);
496 Widget_Data *wd = elm_widget_data_get(obj);
501 prev = _item_prev_get(wd->current);
503 if ((!prev) || (prev == wd->current)) return;
505 _end(obj, obj, NULL, NULL);
507 if (wd->timer) ecore_timer_del(wd->timer);
508 if (wd->timeout > 0.0)
509 wd->timer = ecore_timer_add(wd->timeout, _timer_cb, obj);
513 edje_object_part_swallow(wd->slideshow, "elm.swallow.2", prev->base.view);
514 evas_object_show(prev->base.view);
516 snprintf(buf, 1024, "%s,previous", wd->transition);
517 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
519 wd->previous = wd->current;
521 evas_object_smart_callback_call(obj, SIG_CHANGED, wd->current);
524 EAPI const Eina_List *
525 elm_slideshow_transitions_get(const Evas_Object *obj)
527 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
528 Widget_Data *wd = elm_widget_data_get(obj);
529 if (!wd) return NULL;
530 return wd->transitions;
533 EAPI const Eina_List *
534 elm_slideshow_layouts_get(const Evas_Object *obj)
536 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
537 Widget_Data *wd = elm_widget_data_get(obj);
538 if (!wd) return NULL;
539 return wd->layout.list;
543 elm_slideshow_transition_set(Evas_Object *obj, const char *transition)
545 ELM_CHECK_WIDTYPE(obj, widtype);
546 Widget_Data *wd = elm_widget_data_get(obj);
548 eina_stringshare_replace(&wd->transition, transition);
552 elm_slideshow_transition_get(const Evas_Object *obj)
554 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
555 Widget_Data *wd = elm_widget_data_get(obj);
556 if (!wd) return NULL;
557 return wd->transition;
561 elm_slideshow_timeout_set(Evas_Object *obj, double timeout)
563 ELM_CHECK_WIDTYPE(obj, widtype);
564 Widget_Data *wd = elm_widget_data_get(obj);
566 wd->timeout = timeout;
567 if (wd->timer) ecore_timer_del(wd->timer);
570 wd->timer = ecore_timer_add(timeout, _timer_cb, obj);
574 elm_slideshow_timeout_get(const Evas_Object *obj)
576 ELM_CHECK_WIDTYPE(obj, widtype) -1.0;
577 Widget_Data *wd = elm_widget_data_get(obj);
578 if (!wd) return -1.0;
583 elm_slideshow_loop_set(Evas_Object *obj, Eina_Bool loop)
585 ELM_CHECK_WIDTYPE(obj, widtype);
586 Widget_Data *wd = elm_widget_data_get(obj);
592 elm_slideshow_layout_get(const Evas_Object *obj)
594 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
595 Widget_Data *wd = elm_widget_data_get(obj);
596 if (!wd) return EINA_FALSE;
597 return wd->layout.current;
601 elm_slideshow_layout_set(Evas_Object *obj, const char *layout)
604 ELM_CHECK_WIDTYPE(obj, widtype);
605 Widget_Data *wd = elm_widget_data_get(obj);
608 wd->layout.current = layout;
609 snprintf(buf, sizeof(buf), "layout,%s", layout);
610 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
614 elm_slideshow_loop_get(const Evas_Object *obj)
616 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
617 Widget_Data *wd = elm_widget_data_get(obj);
618 if (!wd) return EINA_FALSE;
623 elm_slideshow_clear(Evas_Object *obj)
625 Elm_Slideshow_Item *item;
626 ELM_CHECK_WIDTYPE(obj, widtype);
627 Widget_Data *wd = elm_widget_data_get(obj);
631 EINA_LIST_FREE(wd->items_built, item)
633 if (item->itc->func.del)
634 item->itc->func.del((void*)item->base.data, item->base.view);
635 evas_object_del(item->base.view);
636 item->base.view = NULL;
639 EINA_LIST_FREE(wd->items, item)
641 elm_widget_item_del(item);
646 elm_slideshow_item_del(Elm_Slideshow_Item *item)
648 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
649 Widget_Data *wd = elm_widget_data_get(item->base.widget);
651 if (wd->previous == item) wd->previous = NULL;
652 if (wd->current == item)
654 Eina_List *l = eina_list_data_find_list(wd->items, item);
655 Eina_List *l2 = eina_list_next(l);
659 l2 = eina_list_prev(l);
661 elm_slideshow_show(eina_list_data_get(l2));
665 elm_slideshow_show(eina_list_data_get(l2));
668 wd->items = eina_list_remove_list(wd->items, item->l);
669 wd->items_built = eina_list_remove_list(wd->items_built, item->l_built);
671 if ((item->base.view) && (item->itc->func.del))
672 item->itc->func.del((void*)item->base.data, item->base.view);
674 evas_object_del(item->base.view);
678 EAPI const Eina_List *
679 elm_slideshow_items_get(const Evas_Object *obj)
681 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
682 Widget_Data *wd = elm_widget_data_get(obj);
683 if (!wd) return NULL;
687 EAPI Elm_Slideshow_Item *
688 elm_slideshow_item_current_get(const Evas_Object *obj)
690 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
691 Widget_Data *wd = elm_widget_data_get(obj);
692 if (!wd) return NULL;
697 elm_slideshow_item_object_get(const Elm_Slideshow_Item * item)
699 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
700 return item->base.view;
704 elm_slideshow_item_data_get(const Elm_Slideshow_Item * item)
706 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
707 return elm_widget_item_data_get(item);
711 elm_slideshow_cache_before_get(const Evas_Object *obj)
713 ELM_CHECK_WIDTYPE(obj, widtype) -1;
714 Widget_Data *wd = elm_widget_data_get(obj);
716 return wd->count_item_pre_before;
720 elm_slideshow_cache_before_set(Evas_Object *obj, int count)
722 ELM_CHECK_WIDTYPE(obj, widtype);
723 Widget_Data *wd = elm_widget_data_get(obj);
725 if (count < 0) count = 0;
726 wd->count_item_pre_before = count;
730 elm_slideshow_cache_after_get(const Evas_Object *obj)
732 ELM_CHECK_WIDTYPE(obj, widtype) -1;
733 Widget_Data *wd = elm_widget_data_get(obj);
735 return wd->count_item_pre_after;
739 elm_slideshow_cache_after_set(Evas_Object *obj, int count)
741 ELM_CHECK_WIDTYPE(obj, widtype);
742 Widget_Data *wd = elm_widget_data_get(obj);
744 if (count < 0) count = 0;
745 wd->count_item_pre_after = count;
748 EAPI Elm_Slideshow_Item *
749 elm_slideshow_item_nth_get(const Evas_Object *obj, unsigned int nth)
751 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
752 Widget_Data *wd = elm_widget_data_get(obj);
753 if (!wd) return NULL;
754 return eina_list_nth(wd->items, nth);
758 elm_slideshow_count_get(const Evas_Object *obj)
760 ELM_CHECK_WIDTYPE(obj, widtype) 0;
761 Widget_Data *wd = elm_widget_data_get(obj);
763 return eina_list_count(wd->items);