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_pre_hook(Evas_Object *obj);
43 static void _del_hook(Evas_Object *obj);
44 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
45 static void _theme_hook(Evas_Object *obj);
46 static void _sizing_eval(Evas_Object *obj);
47 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
48 static Eina_Bool _timer_cb(void *data);
49 static void _on_focus_hook(void *data, Evas_Object *obj);
50 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src,
51 Evas_Callback_Type type, void *event_info);
53 static const char SIG_CHANGED[] = "changed";
55 static const Evas_Smart_Cb_Description _signals[] = {
61 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
63 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
64 Evas_Event_Key_Down *ev = event_info;
65 Widget_Data *wd = elm_widget_data_get(obj);
66 if (!wd) return EINA_FALSE;
67 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
68 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
69 if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")))
71 elm_slideshow_previous(obj);
72 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
75 if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")))
77 elm_slideshow_next(obj);
78 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
81 if ((!strcmp(ev->keyname, "Return")) ||
82 (!strcmp(ev->keyname, "KP_Enter")) ||
83 (!strcmp(ev->keyname, "space")))
89 ecore_timer_del(wd->timer);
93 elm_slideshow_timeout_set(obj, wd->timeout);
95 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
102 _del_pre_hook(Evas_Object *obj)
104 Widget_Data *wd = elm_widget_data_get(obj);
106 evas_object_event_callback_del_full(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
107 _changed_size_hints, obj);
111 _del_hook(Evas_Object *obj)
114 Widget_Data *wd = elm_widget_data_get(obj);
116 elm_slideshow_clear(obj);
117 elm_widget_stringlist_free(wd->transitions);
118 if (wd->timer) ecore_timer_del(wd->timer);
119 EINA_LIST_FREE(wd->layout.list, layout)
120 eina_stringshare_del(layout);
125 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
127 Widget_Data *wd = elm_widget_data_get(obj);
129 if (elm_widget_focus_get(obj))
131 edje_object_signal_emit(wd->slideshow, "elm,action,focus", "elm");
132 evas_object_focus_set(wd->slideshow, EINA_TRUE);
136 edje_object_signal_emit(wd->slideshow, "elm,action,unfocus", "elm");
137 evas_object_focus_set(wd->slideshow, EINA_FALSE);
142 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
144 Widget_Data *wd = elm_widget_data_get(obj);
146 edje_object_mirrored_set(wd->slideshow, rtl);
150 _theme_hook(Evas_Object *obj)
152 Widget_Data *wd = elm_widget_data_get(obj);
154 _elm_widget_mirrored_reload(obj);
155 _mirrored_set(obj, elm_widget_mirrored_get(obj));
156 _elm_theme_object_set(obj, wd->slideshow, "slideshow", "base", elm_widget_style_get(obj));
157 edje_object_scale_set(wd->slideshow, elm_widget_scale_get(obj) *
163 _sizing_eval(Evas_Object *obj)
165 Widget_Data *wd = elm_widget_data_get(obj);
166 Evas_Coord minw = -1, minh = -1;
168 edje_object_size_min_calc(wd->slideshow, &minw, &minh);
169 evas_object_size_hint_min_set(obj, minw, minh);
170 evas_object_size_hint_max_set(obj, minw, minh);
174 static Elm_Slideshow_Item* _item_prev_get(Elm_Slideshow_Item* item)
176 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
177 Elm_Slideshow_Item* prev = eina_list_data_get(eina_list_prev(item->l));
178 if ((!prev) && (wd->loop))
179 prev = eina_list_data_get(eina_list_last(item->l));
183 static Elm_Slideshow_Item* _item_next_get(Elm_Slideshow_Item* item)
185 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
186 Elm_Slideshow_Item* next = eina_list_data_get(eina_list_next(item->l));
187 if ((!next) && (wd->loop))
188 next = eina_list_data_get(wd->items);
193 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
199 _sub_del(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
205 _item_realize(Elm_Slideshow_Item *item)
207 Elm_Slideshow_Item *_item_prev, *_item_next;
208 Evas_Object *obj = WIDGET(item);
209 Widget_Data *wd = elm_widget_data_get(obj);
213 if ((!VIEW(item)) && (item->itc->func.get))
215 VIEW(item) = item->itc->func.get((void*)item->base.data, obj);
216 evas_object_smart_member_add(VIEW(item), obj);
217 item->l_built = eina_list_append(NULL, item);
218 wd->items_built = eina_list_merge(wd->items_built, item->l_built);
219 evas_object_hide(VIEW(item));
221 else if (item->l_built)
222 wd->items_built = eina_list_demote_list(wd->items_built, item->l_built);
224 //pre-create previous and next item
225 ac = wd->count_item_pre_after;
227 bc = wd->count_item_pre_before;
229 lc = eina_list_count(wd->items) - 1;
230 while (lc > 0 && ((ac > 0) || (bc > 0)))
232 if (lc > 0 && ac > 0)
238 _item_next = _item_next_get(_item_next);
240 && (!VIEW(_item_next))
241 && (_item_next->itc->func.get))
244 _item_next->itc->func.get(
245 (void*)_item_next->base.data, obj);
246 evas_object_smart_member_add(VIEW(_item_next), obj);
247 _item_next->l_built = eina_list_append(NULL, _item_next);
248 wd->items_built = eina_list_merge(wd->items_built,
249 _item_next->l_built);
250 evas_object_hide(VIEW(_item_next));
252 else if (_item_next && _item_next->l_built)
254 eina_list_demote_list(wd->items_built,
255 _item_next->l_built);
259 if (lc > 0 && bc > 0)
265 _item_prev = _item_prev_get(_item_prev);
267 && (!VIEW(_item_prev))
268 && (_item_prev->itc->func.get))
271 _item_prev->itc->func.get(
272 (void*)_item_prev->base.data, obj);
273 evas_object_smart_member_add(VIEW(_item_prev), obj);
274 _item_prev->l_built = eina_list_append(NULL, _item_prev);
275 wd->items_built = eina_list_merge(wd->items_built,
276 _item_prev->l_built);
277 evas_object_hide(VIEW(_item_prev));
279 else if (_item_prev && _item_prev->l_built)
281 eina_list_demote_list(wd->items_built,
282 _item_prev->l_built);
287 //delete unused items
288 lc = wd->count_item_pre_before + wd->count_item_pre_after + 1;
289 while ((int)eina_list_count(wd->items_built) > lc)
291 item = eina_list_data_get(wd->items_built);
292 wd->items_built = eina_list_remove_list(wd->items_built,
294 if (item->itc->func.del)
295 item->itc->func.del((void*)item->base.data, VIEW(item));
296 evas_object_del(VIEW(item));
302 _end(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
304 Elm_Slideshow_Item *item;
305 Widget_Data *wd = elm_widget_data_get(data);
311 edje_object_part_unswallow(NULL, VIEW(item));
312 evas_object_hide(VIEW(item));
318 if ((!item) || (!VIEW(item))) return;
321 edje_object_part_unswallow(NULL, VIEW(item));
322 evas_object_show(VIEW(item));
324 edje_object_signal_emit(wd->slideshow, "anim,end", "slideshow");
325 edje_object_part_swallow(wd->slideshow, "elm.swallow.1", item->base.view);
329 _timer_cb(void *data)
331 Evas_Object *obj = data;
332 Widget_Data *wd = elm_widget_data_get(obj);
333 if (!wd) return ECORE_CALLBACK_CANCEL;
335 elm_slideshow_next(obj);
336 return ECORE_CALLBACK_CANCEL;
340 elm_slideshow_add(Evas_Object *parent)
346 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
348 ELM_SET_WIDTYPE(widtype, "slideshow");
349 elm_widget_type_set(obj, "slideshow");
350 elm_widget_sub_object_add(parent, obj);
351 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
352 elm_widget_data_set(obj, wd);
353 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
354 elm_widget_del_hook_set(obj, _del_hook);
355 elm_widget_theme_hook_set(obj, _theme_hook);
356 elm_widget_can_focus_set(obj, EINA_TRUE);
357 elm_widget_event_hook_set(obj, _event_hook);
362 wd->slideshow = edje_object_add(e);
363 _elm_theme_object_set(obj, wd->slideshow, "slideshow", "base", "default");
364 evas_object_smart_member_add(wd->slideshow, obj);
365 wd->count_item_pre_before = 2;
366 wd->count_item_pre_after = 2;
367 elm_widget_resize_object_set(obj, wd->slideshow);
368 evas_object_show(wd->slideshow);
370 wd->transitions = elm_widget_stringlist_get(edje_object_data_get(wd->slideshow, "transitions"));
371 if (eina_list_count(wd->transitions) > 0)
372 wd->transition = eina_stringshare_add(eina_list_data_get(wd->transitions));
374 wd->layout.list = elm_widget_stringlist_get(edje_object_data_get(wd->slideshow, "layouts"));
375 if (eina_list_count(wd->layout.list) > 0)
376 wd->layout.current = eina_list_data_get(wd->layout.list);
378 edje_object_signal_callback_add(wd->slideshow, "end", "slideshow", _end, obj);
380 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
381 evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
383 evas_object_smart_callbacks_descriptions_set(obj, _signals);
385 _mirrored_set(obj, elm_widget_mirrored_get(obj));
390 EAPI Elm_Slideshow_Item*
391 elm_slideshow_item_add(Evas_Object *obj, const Elm_Slideshow_Item_Class *itc, const void *data)
393 Elm_Slideshow_Item *item;
394 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
395 Widget_Data *wd = elm_widget_data_get(obj);
397 if (!wd) return NULL;
398 item = elm_widget_item_new(obj, Elm_Slideshow_Item);
399 item->base.data = data;
401 item->l = eina_list_append(item->l, item);
403 wd->items = eina_list_merge(wd->items, item->l);
405 if (!wd->current) elm_slideshow_show(item);
410 EAPI Elm_Slideshow_Item*
411 elm_slideshow_item_sorted_insert(Evas_Object *obj, const Elm_Slideshow_Item_Class *itc, const void *data, Eina_Compare_Cb func)
413 Elm_Slideshow_Item *item;
414 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
415 Widget_Data *wd = elm_widget_data_get(obj);
417 if (!wd) return NULL;
418 item = elm_widget_item_new(obj, Elm_Slideshow_Item);
419 item->base.data = data;
421 item->l = eina_list_append(item->l, item);
423 wd->items = eina_list_sorted_merge(wd->items, item->l, func);
425 if (!wd->current) elm_slideshow_show(item);
431 elm_slideshow_show(Elm_Slideshow_Item *item)
434 Elm_Slideshow_Item *next = NULL;
436 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
437 wd = elm_widget_data_get(WIDGET(item));
440 if (item == wd->current)
444 _end(WIDGET(item), WIDGET(item), NULL, NULL);
446 if (wd->timer) ecore_timer_del(wd->timer);
447 if (wd->timeout > 0.0)
448 wd->timer = ecore_timer_add(wd->timeout, _timer_cb, WIDGET(item));
450 edje_object_part_swallow(wd->slideshow, "elm.swallow.2", VIEW(next));
451 evas_object_show(VIEW(next));
452 snprintf(buf, sizeof(buf), "%s,next", wd->transition);
453 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
454 wd->previous = wd->current;
456 evas_object_smart_callback_call(WIDGET(item), SIG_CHANGED, wd->current);
460 elm_slideshow_next(Evas_Object *obj)
463 Elm_Slideshow_Item *next = NULL;
464 ELM_CHECK_WIDTYPE(obj, widtype);
465 Widget_Data *wd = elm_widget_data_get(obj);
470 next = _item_next_get(wd->current);
472 if ((!next) || (next == wd->current)) return;
474 _end(obj, obj, NULL, NULL);
476 if (wd->timer) ecore_timer_del(wd->timer);
477 if (wd->timeout > 0.0)
478 wd->timer = ecore_timer_add(wd->timeout, _timer_cb, obj);
482 edje_object_part_swallow(wd->slideshow, "elm.swallow.2", VIEW(next));
483 evas_object_show(VIEW(next));
485 snprintf(buf, sizeof(buf), "%s,next", wd->transition);
486 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
488 wd->previous = wd->current;
490 evas_object_smart_callback_call(obj, SIG_CHANGED, wd->current);
494 elm_slideshow_previous(Evas_Object *obj)
497 Elm_Slideshow_Item *prev = NULL;
498 ELM_CHECK_WIDTYPE(obj, widtype);
499 Widget_Data *wd = elm_widget_data_get(obj);
504 prev = _item_prev_get(wd->current);
506 if ((!prev) || (prev == wd->current)) return;
508 _end(obj, obj, NULL, NULL);
510 if (wd->timer) ecore_timer_del(wd->timer);
511 if (wd->timeout > 0.0)
512 wd->timer = ecore_timer_add(wd->timeout, _timer_cb, obj);
516 edje_object_part_swallow(wd->slideshow, "elm.swallow.2", VIEW(prev));
517 evas_object_show(VIEW(prev));
519 snprintf(buf, 1024, "%s,previous", wd->transition);
520 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
522 wd->previous = wd->current;
524 evas_object_smart_callback_call(obj, SIG_CHANGED, wd->current);
527 EAPI const Eina_List *
528 elm_slideshow_transitions_get(const Evas_Object *obj)
530 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
531 Widget_Data *wd = elm_widget_data_get(obj);
532 if (!wd) return NULL;
533 return wd->transitions;
536 EAPI const Eina_List *
537 elm_slideshow_layouts_get(const Evas_Object *obj)
539 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
540 Widget_Data *wd = elm_widget_data_get(obj);
541 if (!wd) return NULL;
542 return wd->layout.list;
546 elm_slideshow_transition_set(Evas_Object *obj, const char *transition)
548 ELM_CHECK_WIDTYPE(obj, widtype);
549 Widget_Data *wd = elm_widget_data_get(obj);
551 eina_stringshare_replace(&wd->transition, transition);
555 elm_slideshow_transition_get(const Evas_Object *obj)
557 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
558 Widget_Data *wd = elm_widget_data_get(obj);
559 if (!wd) return NULL;
560 return wd->transition;
564 elm_slideshow_timeout_set(Evas_Object *obj, double timeout)
566 ELM_CHECK_WIDTYPE(obj, widtype);
567 Widget_Data *wd = elm_widget_data_get(obj);
569 wd->timeout = timeout;
570 if (wd->timer) ecore_timer_del(wd->timer);
573 wd->timer = ecore_timer_add(timeout, _timer_cb, obj);
577 elm_slideshow_timeout_get(const Evas_Object *obj)
579 ELM_CHECK_WIDTYPE(obj, widtype) -1.0;
580 Widget_Data *wd = elm_widget_data_get(obj);
581 if (!wd) return -1.0;
586 elm_slideshow_loop_set(Evas_Object *obj, Eina_Bool loop)
588 ELM_CHECK_WIDTYPE(obj, widtype);
589 Widget_Data *wd = elm_widget_data_get(obj);
595 elm_slideshow_layout_get(const Evas_Object *obj)
597 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
598 Widget_Data *wd = elm_widget_data_get(obj);
599 if (!wd) return EINA_FALSE;
600 return wd->layout.current;
604 elm_slideshow_layout_set(Evas_Object *obj, const char *layout)
607 ELM_CHECK_WIDTYPE(obj, widtype);
608 Widget_Data *wd = elm_widget_data_get(obj);
611 wd->layout.current = layout;
612 snprintf(buf, sizeof(buf), "layout,%s", layout);
613 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
617 elm_slideshow_loop_get(const Evas_Object *obj)
619 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
620 Widget_Data *wd = elm_widget_data_get(obj);
621 if (!wd) return EINA_FALSE;
626 elm_slideshow_clear(Evas_Object *obj)
628 Elm_Slideshow_Item *item;
629 ELM_CHECK_WIDTYPE(obj, widtype);
630 Widget_Data *wd = elm_widget_data_get(obj);
634 EINA_LIST_FREE(wd->items_built, item)
636 if (item->itc->func.del)
637 item->itc->func.del((void*)item->base.data, VIEW(item));
638 evas_object_del(VIEW(item));
642 EINA_LIST_FREE(wd->items, item)
644 elm_widget_item_del(item);
649 elm_slideshow_item_del(Elm_Slideshow_Item *item)
651 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
652 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
654 if (wd->previous == item) wd->previous = NULL;
655 if (wd->current == item)
657 Eina_List *l = eina_list_data_find_list(wd->items, item);
658 Eina_List *l2 = eina_list_next(l);
661 l2 = eina_list_nth_list(wd->items, eina_list_count(wd->items) - 1);
663 elm_slideshow_show(eina_list_data_get(l2));
666 wd->items = eina_list_remove_list(wd->items, item->l);
667 wd->items_built = eina_list_remove_list(wd->items_built, item->l_built);
669 if ((VIEW(item)) && (item->itc->func.del))
670 item->itc->func.del((void*)item->base.data, VIEW(item));
672 evas_object_del(VIEW(item));
676 EAPI const Eina_List *
677 elm_slideshow_items_get(const Evas_Object *obj)
679 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
680 Widget_Data *wd = elm_widget_data_get(obj);
681 if (!wd) return NULL;
685 EAPI Elm_Slideshow_Item *
686 elm_slideshow_item_current_get(const Evas_Object *obj)
688 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
689 Widget_Data *wd = elm_widget_data_get(obj);
690 if (!wd) return NULL;
695 elm_slideshow_item_object_get(const Elm_Slideshow_Item * item)
697 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
702 elm_slideshow_item_data_get(const Elm_Slideshow_Item * item)
704 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
705 return elm_widget_item_data_get(item);
709 elm_slideshow_cache_before_get(const Evas_Object *obj)
711 ELM_CHECK_WIDTYPE(obj, widtype) -1;
712 Widget_Data *wd = elm_widget_data_get(obj);
714 return wd->count_item_pre_before;
718 elm_slideshow_cache_before_set(Evas_Object *obj, int count)
720 ELM_CHECK_WIDTYPE(obj, widtype);
721 Widget_Data *wd = elm_widget_data_get(obj);
723 if (count < 0) count = 0;
724 wd->count_item_pre_before = count;
728 elm_slideshow_cache_after_get(const Evas_Object *obj)
730 ELM_CHECK_WIDTYPE(obj, widtype) -1;
731 Widget_Data *wd = elm_widget_data_get(obj);
733 return wd->count_item_pre_after;
737 elm_slideshow_cache_after_set(Evas_Object *obj, int count)
739 ELM_CHECK_WIDTYPE(obj, widtype);
740 Widget_Data *wd = elm_widget_data_get(obj);
742 if (count < 0) count = 0;
743 wd->count_item_pre_after = count;
746 EAPI Elm_Slideshow_Item *
747 elm_slideshow_item_nth_get(const Evas_Object *obj, unsigned int nth)
749 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
750 Widget_Data *wd = elm_widget_data_get(obj);
751 if (!wd) return NULL;
752 return eina_list_nth(wd->items, nth);
756 elm_slideshow_count_get(const Evas_Object *obj)
758 ELM_CHECK_WIDTYPE(obj, widtype) 0;
759 Widget_Data *wd = elm_widget_data_get(obj);
761 return eina_list_count(wd->items);