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")) || (!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 //FIXME: item could be showed by obj
225 evas_object_hide(VIEW(item));
227 else if (item->l_built)
228 wd->items_built = eina_list_demote_list(wd->items_built, item->l_built);
230 //pre-create previous and next item
231 ac = wd->count_item_pre_after;
233 bc = wd->count_item_pre_before;
235 lc = eina_list_count(wd->items) - 1;
236 while (lc > 0 && ((ac > 0) || (bc > 0)))
238 if (lc > 0 && ac > 0)
244 _item_next = _item_next_get(_item_next);
246 && (!VIEW(_item_next))
247 && (_item_next->itc->func.get))
251 _item_next->itc->func.get(
252 elm_widget_item_data_get(_item_next), obj);
253 evas_object_smart_member_add(VIEW(_item_next), obj);
254 _item_next->l_built = eina_list_append(NULL, _item_next);
255 wd->items_built = eina_list_merge(wd->items_built,
256 _item_next->l_built);
257 //FIXME: _item_next could be showed by obj later
258 evas_object_hide(VIEW(_item_next));
260 else if (_item_next && _item_next->l_built)
264 eina_list_demote_list(wd->items_built,
265 _item_next->l_built);
270 if (lc > 0 && bc > 0)
276 _item_prev = _item_prev_get(_item_prev);
278 && (!VIEW(_item_prev))
279 && (_item_prev->itc->func.get))
283 _item_prev->itc->func.get(
284 elm_widget_item_data_get(_item_prev), obj);
285 evas_object_smart_member_add(VIEW(_item_prev), obj);
286 _item_prev->l_built = eina_list_append(NULL, _item_prev);
287 wd->items_built = eina_list_merge(wd->items_built,
288 _item_prev->l_built);
289 //FIXME: _item_prev could be showed by obj later
290 evas_object_hide(VIEW(_item_prev));
292 else if (_item_prev && _item_prev->l_built)
296 eina_list_demote_list(wd->items_built,
297 _item_prev->l_built);
303 //delete unused items
305 while ((int)eina_list_count(wd->items_built) > lc)
307 item = eina_list_data_get(wd->items_built);
308 wd->items_built = eina_list_remove_list(wd->items_built,
310 if (item->itc->func.del)
311 item->itc->func.del(elm_widget_item_data_get(item), VIEW(item));
312 evas_object_del(VIEW(item));
318 _end(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
320 Elm_Slideshow_Item *item;
321 Widget_Data *wd = elm_widget_data_get(data);
327 edje_object_part_unswallow(wd->slideshow, VIEW(item));
328 evas_object_hide(VIEW(item));
333 if ((!item) || (!VIEW(item))) return;
336 edje_object_part_unswallow(wd->slideshow, VIEW(item));
338 edje_object_part_swallow(wd->slideshow, "elm.swallow.1", VIEW(item));
339 edje_object_signal_emit(wd->slideshow, "anim,end", "slideshow");
340 if (emission != NULL)
341 evas_object_smart_callback_call(data, SIG_TRANSITION_END, wd->current);
345 _timer_cb(void *data)
347 Evas_Object *obj = data;
348 Widget_Data *wd = elm_widget_data_get(obj);
349 if (!wd) return ECORE_CALLBACK_CANCEL;
351 elm_slideshow_next(obj);
352 return ECORE_CALLBACK_CANCEL;
356 _item_del_pre_hook(Elm_Object_Item *it)
358 Elm_Slideshow_Item *item = (Elm_Slideshow_Item *)it;
359 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
360 if (!wd) return EINA_FALSE;
362 if (wd->previous == item) wd->previous = NULL;
363 if (wd->current == item)
365 Eina_List *l = eina_list_data_find_list(wd->items, item);
366 Eina_List *l2 = eina_list_next(l);
370 l2 = eina_list_prev(l);
372 elm_slideshow_item_show(eina_list_data_get(l2));
376 elm_slideshow_item_show(eina_list_data_get(l2));
379 wd->items = eina_list_remove_list(wd->items, item->l);
380 wd->items_built = eina_list_remove_list(wd->items_built, item->l_built);
382 if ((VIEW(item)) && (item->itc->func.del))
383 item->itc->func.del(elm_widget_item_data_get(item), VIEW(item));
389 elm_slideshow_add(Evas_Object *parent)
395 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
397 ELM_SET_WIDTYPE(widtype, "slideshow");
398 elm_widget_type_set(obj, "slideshow");
399 elm_widget_sub_object_add(parent, obj);
400 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
401 elm_widget_data_set(obj, wd);
402 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
403 elm_widget_del_hook_set(obj, _del_hook);
404 elm_widget_theme_hook_set(obj, _theme_hook);
405 elm_widget_can_focus_set(obj, EINA_TRUE);
406 elm_widget_event_hook_set(obj, _event_hook);
411 wd->slideshow = edje_object_add(e);
412 _elm_theme_object_set(obj, wd->slideshow, "slideshow", "base", "default");
413 wd->count_item_pre_before = 2;
414 wd->count_item_pre_after = 2;
415 elm_widget_resize_object_set(obj, wd->slideshow);
417 wd->transitions = elm_widget_stringlist_get(edje_object_data_get(wd->slideshow, "transitions"));
418 if (eina_list_count(wd->transitions) > 0)
419 wd->transition = eina_stringshare_add(eina_list_data_get(wd->transitions));
421 wd->layout.list = elm_widget_stringlist_get(edje_object_data_get(wd->slideshow, "layouts"));
422 if (eina_list_count(wd->layout.list) > 0)
423 wd->layout.current = eina_list_data_get(wd->layout.list);
425 edje_object_signal_callback_add(wd->slideshow, "end", "slideshow", _end, obj);
427 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
428 evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
430 evas_object_smart_callbacks_descriptions_set(obj, _signals);
432 _mirrored_set(obj, elm_widget_mirrored_get(obj));
437 EAPI Elm_Object_Item*
438 elm_slideshow_item_add(Evas_Object *obj, const Elm_Slideshow_Item_Class *itc, const void *data)
440 Elm_Slideshow_Item *item;
441 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
442 Widget_Data *wd = elm_widget_data_get(obj);
444 if (!wd) return NULL;
445 item = elm_widget_item_new(obj, Elm_Slideshow_Item);
446 if (!item) return NULL;
447 elm_widget_item_del_pre_hook_set(item, _item_del_pre_hook);
449 item->l = eina_list_append(item->l, item);
450 elm_widget_item_data_set(item, data);
452 wd->items = eina_list_merge(wd->items, item->l);
454 if (!wd->current) elm_slideshow_item_show((Elm_Object_Item *)item);
456 return (Elm_Object_Item *)item;
459 EAPI Elm_Object_Item*
460 elm_slideshow_item_sorted_insert(Evas_Object *obj, const Elm_Slideshow_Item_Class *itc, const void *data, Eina_Compare_Cb func)
462 Elm_Slideshow_Item *item;
463 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
464 Widget_Data *wd = elm_widget_data_get(obj);
465 if (!wd) return NULL;
467 item = elm_widget_item_new(obj, Elm_Slideshow_Item);
468 if (!item) return NULL;
469 elm_widget_item_del_pre_hook_set(item, _item_del_pre_hook);
471 item->l = eina_list_append(item->l, item);
472 elm_widget_item_data_set(item, data);
474 wd->items = eina_list_sorted_merge(wd->items, item->l, func);
476 if (!wd->current) elm_slideshow_item_show((Elm_Object_Item *)item);
478 return (Elm_Object_Item *)item;
482 elm_slideshow_item_show(Elm_Object_Item *it)
484 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
487 Elm_Slideshow_Item *item, *next = NULL;
489 item = (Elm_Slideshow_Item *)it;
490 wd = elm_widget_data_get(WIDGET(item));
492 if (item == wd->current) return;
495 _end(WIDGET(item), WIDGET(item), NULL, NULL);
497 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);
529 if (wd->timeout > 0.0)
530 wd->timer = ecore_timer_add(wd->timeout, _timer_cb, obj);
534 edje_object_part_swallow(wd->slideshow, "elm.swallow.2", VIEW(next));
536 snprintf(buf, sizeof(buf), "%s,next", wd->transition);
537 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
539 wd->previous = wd->current;
541 evas_object_smart_callback_call(obj, SIG_CHANGED, wd->current);
545 elm_slideshow_previous(Evas_Object *obj)
548 Elm_Slideshow_Item *prev = NULL;
549 ELM_CHECK_WIDTYPE(obj, widtype);
550 Widget_Data *wd = elm_widget_data_get(obj);
555 prev = _item_prev_get(wd->current);
557 if ((!prev) || (prev == wd->current)) return;
559 _end(obj, obj, NULL, NULL);
561 if (wd->timer) ecore_timer_del(wd->timer);
563 if (wd->timeout > 0.0)
564 wd->timer = ecore_timer_add(wd->timeout, _timer_cb, obj);
568 edje_object_part_swallow(wd->slideshow, "elm.swallow.2", VIEW(prev));
570 snprintf(buf, 1024, "%s,previous", wd->transition);
571 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
573 wd->previous = wd->current;
575 evas_object_smart_callback_call(obj, SIG_CHANGED, wd->current);
578 EAPI const Eina_List *
579 elm_slideshow_transitions_get(const Evas_Object *obj)
581 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
582 Widget_Data *wd = elm_widget_data_get(obj);
583 if (!wd) return NULL;
584 return wd->transitions;
587 EAPI const Eina_List *
588 elm_slideshow_layouts_get(const Evas_Object *obj)
590 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
591 Widget_Data *wd = elm_widget_data_get(obj);
592 if (!wd) return NULL;
593 return wd->layout.list;
597 elm_slideshow_transition_set(Evas_Object *obj, const char *transition)
599 ELM_CHECK_WIDTYPE(obj, widtype);
600 Widget_Data *wd = elm_widget_data_get(obj);
602 eina_stringshare_replace(&wd->transition, transition);
606 elm_slideshow_transition_get(const Evas_Object *obj)
608 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
609 Widget_Data *wd = elm_widget_data_get(obj);
610 if (!wd) return NULL;
611 return wd->transition;
615 elm_slideshow_timeout_set(Evas_Object *obj, double timeout)
617 ELM_CHECK_WIDTYPE(obj, widtype);
618 Widget_Data *wd = elm_widget_data_get(obj);
620 wd->timeout = timeout;
621 if (wd->timer) ecore_timer_del(wd->timer);
624 wd->timer = ecore_timer_add(timeout, _timer_cb, obj);
628 elm_slideshow_timeout_get(const Evas_Object *obj)
630 ELM_CHECK_WIDTYPE(obj, widtype) -1.0;
631 Widget_Data *wd = elm_widget_data_get(obj);
632 if (!wd) return -1.0;
637 elm_slideshow_loop_set(Evas_Object *obj, Eina_Bool loop)
639 ELM_CHECK_WIDTYPE(obj, widtype);
640 Widget_Data *wd = elm_widget_data_get(obj);
646 elm_slideshow_layout_get(const Evas_Object *obj)
648 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
649 Widget_Data *wd = elm_widget_data_get(obj);
650 if (!wd) return EINA_FALSE;
651 return wd->layout.current;
655 elm_slideshow_layout_set(Evas_Object *obj, const char *layout)
658 ELM_CHECK_WIDTYPE(obj, widtype);
659 Widget_Data *wd = elm_widget_data_get(obj);
662 wd->layout.current = layout;
663 snprintf(buf, sizeof(buf), "layout,%s", layout);
664 edje_object_signal_emit(wd->slideshow, buf, "slideshow");
668 elm_slideshow_loop_get(const Evas_Object *obj)
670 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
671 Widget_Data *wd = elm_widget_data_get(obj);
672 if (!wd) return EINA_FALSE;
677 elm_slideshow_clear(Evas_Object *obj)
679 Elm_Slideshow_Item *item;
680 ELM_CHECK_WIDTYPE(obj, widtype);
681 Widget_Data *wd = elm_widget_data_get(obj);
685 EINA_LIST_FREE(wd->items_built, item)
687 if (item->itc->func.del)
688 item->itc->func.del(elm_widget_item_data_get(item), VIEW(item));
691 EINA_LIST_FREE(wd->items, item)
692 elm_widget_item_free(item);
695 EAPI const Eina_List *
696 elm_slideshow_items_get(const Evas_Object *obj)
698 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
699 Widget_Data *wd = elm_widget_data_get(obj);
700 if (!wd) return NULL;
704 EAPI Elm_Object_Item *
705 elm_slideshow_item_current_get(const Evas_Object *obj)
707 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
708 Widget_Data *wd = elm_widget_data_get(obj);
709 if (!wd) return NULL;
710 return (Elm_Object_Item *) wd->current;
714 elm_slideshow_item_object_get(const Elm_Object_Item * it)
716 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
721 elm_slideshow_cache_before_get(const Evas_Object *obj)
723 ELM_CHECK_WIDTYPE(obj, widtype) -1;
724 Widget_Data *wd = elm_widget_data_get(obj);
726 return wd->count_item_pre_before;
730 elm_slideshow_cache_before_set(Evas_Object *obj, int count)
732 ELM_CHECK_WIDTYPE(obj, widtype);
733 Widget_Data *wd = elm_widget_data_get(obj);
735 if (count < 0) count = 0;
736 wd->count_item_pre_before = count;
740 elm_slideshow_cache_after_get(const Evas_Object *obj)
742 ELM_CHECK_WIDTYPE(obj, widtype) -1;
743 Widget_Data *wd = elm_widget_data_get(obj);
745 return wd->count_item_pre_after;
749 elm_slideshow_cache_after_set(Evas_Object *obj, int count)
751 ELM_CHECK_WIDTYPE(obj, widtype);
752 Widget_Data *wd = elm_widget_data_get(obj);
754 if (count < 0) count = 0;
755 wd->count_item_pre_after = count;
758 EAPI Elm_Object_Item *
759 elm_slideshow_item_nth_get(const Evas_Object *obj, unsigned int nth)
761 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
762 Widget_Data *wd = elm_widget_data_get(obj);
763 if (!wd) return NULL;
764 return eina_list_nth(wd->items, nth);
768 elm_slideshow_count_get(const Evas_Object *obj)
770 ELM_CHECK_WIDTYPE(obj, widtype) 0;
771 Widget_Data *wd = elm_widget_data_get(obj);
773 return eina_list_count(wd->items);