3 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
7 #include <Elementary.h>
11 * @defgroup Imageslider Imageslider
14 * By flicking images on the screen,
15 * you can see the images in specific path.
18 typedef struct _Widget_Data Widget_Data;
20 #define ANI_STEP (14 * elm_scale_get())
21 #define ANI_TIME (0.005)
22 #define ANI_TIME_MSEC (12)
23 #define FLICK_TIME_MAX (200)
24 #define FLICK_WIDTH_MIN (elm_finger_size_get() >> 2)
26 #define STEP_WEIGHT_DEF (1)
27 #define STEP_WEIGHT_MAX (2)
28 #define STEP_WEIGHT_MIN (0)
29 #define MOVING_IMAGE_SIZE (128)
30 #define MAX_ZOOM_SIZE (6)
31 #define INTERVAL_WIDTH (15)
32 #define MULTITOUCHDEVICE (11)
41 struct _Imageslider_Item
44 const char *photo_file;
45 void (*func)(void *data, Evas_Object *obj, void *event_info);
47 Evas_Coord x, y, w, h;
48 Evas_Coord ox, oy, ow, oh;
54 Evas_Object *ly[BLOCK_MAX];
58 Evas_Coord x, y, w, h;
60 Ecore_Idler *queue_idler;
61 Ecore_Timer *anim_timer;
63 Evas_Coord_Point down_pos;
68 unsigned int timestamp;
74 Eina_Bool on_zoom : 1;
75 Eina_Bool on_hold : 1;
77 int mdx, mdy, mmx, mmy;
83 static const char *widtype = NULL;
84 static void _del_hook(Evas_Object *obj);
85 static void _theme_hook(Evas_Object *obj);
86 static void _sizing_eval(Evas_Object *obj);
87 static void _imageslider_del_all(Widget_Data *wd);
88 static void _imageslider_move(void *data,Evas *e, Evas_Object *obj, void *event_info);
89 static void _imageslider_resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
90 //static void _imageslider_show(Evas_Object *obj);
91 //static void _imageslider_hide(Evas_Object *obj);
92 static void _imageslider_show(void * data, Evas * e, Evas_Object * obj, void * event_info);
93 static void _imageslider_hide(void * data, Evas * e, Evas_Object * obj, void * event_info);
94 static void _imageslider_update(Widget_Data *wd);
95 static void _imageslider_update_pos(Widget_Data *wd, Evas_Coord x, Evas_Coord y, Evas_Coord w);
96 static void _imageslider_update_center_pos(Widget_Data *wd, Evas_Coord x, Evas_Coord my, Evas_Coord y, Evas_Coord w);
97 static Evas_Object *_imageslider_add_obj(Widget_Data *wd);
98 static void _imageslider_obj_shift(Widget_Data *wd, Eina_Bool left);
99 static void _imageslider_obj_move(Widget_Data *wd, Evas_Coord step);
100 static int _icon_to_image(void *data);
101 static int _check_drag(int state, void *data);
102 static void _check_zoom(void *data);
103 static void _anim(Widget_Data *wd);
104 static int _timer_cb(void *data);
105 static void ev_imageslider_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
106 static void ev_imageslider_up_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
107 static void ev_imageslider_move_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
109 static void _del_hook(Evas_Object * obj)
113 wd = elm_widget_data_get(obj);
117 for (i = 0; i < BLOCK_MAX; i++) {
118 evas_object_del(wd->ly[i]);
122 eina_list_free(wd->its);
126 if (wd->queue_idler) {
127 ecore_idler_del(wd->queue_idler);
128 wd->queue_idler = NULL;
131 if (wd->anim_timer) {
132 ecore_timer_del(wd->anim_timer);
133 wd->anim_timer = NULL;
140 static void _theme_hook(Evas_Object * obj)
144 wd = elm_widget_data_get(obj);
146 if (!wd || !wd->ly ) {
150 for (i=0; i < BLOCK_MAX; i++) {
151 wd->ly[i] = elm_layout_add(obj);
152 _elm_theme_object_set(obj, wd->ly[i], "imageslider", "base", "default");
153 elm_widget_resize_object_set(obj, wd->ly[i]);
154 evas_object_show(wd->ly[i]);
161 static void _sizing_eval(Evas_Object * obj)
164 Widget_Data *wd = elm_widget_data_get(obj);
170 e = evas_object_evas_get(wd->obj);
172 _imageslider_move(obj, e, obj, NULL);
173 _imageslider_resize(obj, e, obj, NULL);
177 static void _imageslider_move(void * data, Evas * e, Evas_Object * obj, void * event_info)
186 wd = elm_widget_data_get((Evas_Object *) data);
191 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
194 evas_object_move(wd->clip, x, y);
196 _imageslider_update_pos(wd, wd->x, wd->y, wd->w);
200 static void _imageslider_resize(void * data, Evas * e, Evas_Object * obj, void * event_info)
210 wd = elm_widget_data_get((Evas_Object *) data);
211 if (!wd || !wd->ly) {
215 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
216 fprintf( stderr, "%d %d -resize\n" , w, h );
220 for (i = 0; i < BLOCK_MAX; i++) {
221 evas_object_resize(wd->ly[i], w, h);
224 evas_object_resize(wd->clip, w, h);
226 _imageslider_update_pos(wd, wd->x, wd->y, wd->w);
231 //static void _imageslider_show(Evas_Object * obj)
232 static void _imageslider_show(void *data, Evas *e, Evas_Object * obj, void *event_info)
240 wd = elm_widget_data_get((Evas_Object *) data);
245 evas_object_show(wd->clip);
248 //static void _imageslider_hide(Evas_Object *obj)
249 static void _imageslider_hide(void *data, Evas *e, Evas_Object *obj, void *event_info)
257 wd = elm_widget_data_get((Evas_Object *) data);
261 evas_object_hide(wd->clip);
264 static void _imageslider_del_all(Widget_Data * wd)
272 for (i = 0; i < BLOCK_MAX; i++) {
273 evas_object_del(wd->ly[i]);
277 static void _imageslider_update_pos(Widget_Data * wd, Evas_Coord x, Evas_Coord y, Evas_Coord w)
279 evas_object_move(wd->ly[BLOCK_LEFT], x - (w + INTERVAL_WIDTH), y);
280 evas_object_move(wd->ly[BLOCK_CENTER], x, y);
281 evas_object_move(wd->ly[BLOCK_RIGHT], x + (w + INTERVAL_WIDTH), y);
282 evas_render_idle_flush(evas_object_evas_get(wd->obj));
285 static void _imageslider_update_center_pos(Widget_Data * wd, Evas_Coord x, Evas_Coord my, Evas_Coord y, Evas_Coord w)
288 Evas_Coord ix, iy, iw, ih;
290 eo = edje_object_part_swallow_get(elm_layout_edje_get(wd->ly[BLOCK_CENTER]), "swl.photo");
291 evas_object_geometry_get(eo, &ix, &iy, &iw, &ih);
293 if ((ix > 0) || (ix + iw < wd->w)) {
294 edje_object_signal_emit(elm_layout_edje_get(wd->ly[BLOCK_CENTER]), "block.on", "block");
296 // evas_event_feed_mouse_cancel(evas_object_evas_get(wd->obj), NULL, NULL);
297 // evas_event_feed_mouse_down(evas_object_evas_get(wd->obj), 1, EVAS_BUTTON_NONE, NULL, NULL);
299 _imageslider_update_pos(wd, x, y, w);
300 wd->on_zoom = EINA_FALSE;
304 static Evas_Object *_imageslider_add_obj(Widget_Data *wd)
307 eo = elm_layout_add(wd->obj);
308 elm_layout_theme_set(eo, "imageslider", "base", "default");
309 elm_widget_resize_object_set(wd->obj, eo);
310 // evas_object_smart_member_add(eo, wd->obj);
311 evas_object_event_callback_add(eo, EVAS_CALLBACK_MOUSE_DOWN, ev_imageslider_down_cb, wd);
312 evas_object_event_callback_add(eo, EVAS_CALLBACK_MOUSE_UP, ev_imageslider_up_cb, wd);
313 evas_object_event_callback_add(eo, EVAS_CALLBACK_MOUSE_MOVE, ev_imageslider_move_cb, wd);
314 evas_object_resize(eo, wd->w, wd->h);
315 evas_object_move(eo, wd->w + INTERVAL_WIDTH, wd->y);
316 evas_object_clip_set(eo, wd->clip);
317 evas_object_show(eo);
322 static void _imageslider_obj_shift(Widget_Data *wd, Eina_Bool left)
325 if (wd->ly[BLOCK_LEFT]) {
326 evas_object_del(wd->ly[BLOCK_LEFT]);
327 wd->ly[BLOCK_LEFT] = NULL;
330 wd->ly[BLOCK_LEFT] = wd->ly[BLOCK_CENTER];
331 wd->ly[BLOCK_CENTER]= wd->ly[BLOCK_RIGHT];
332 wd->ly[BLOCK_RIGHT] = _imageslider_add_obj(wd);
334 if (wd->ly[BLOCK_RIGHT]) {
335 evas_object_del(wd->ly[BLOCK_RIGHT]);
336 wd->ly[BLOCK_RIGHT] = NULL;
339 wd->ly[BLOCK_RIGHT]= wd->ly[BLOCK_CENTER];
340 wd->ly[BLOCK_CENTER]= wd->ly[BLOCK_LEFT];
341 wd->ly[BLOCK_LEFT]= _imageslider_add_obj(wd);
346 static void _imageslider_obj_move(Widget_Data * wd, Evas_Coord step)
349 wd->cur = eina_list_next(wd->cur);
350 if (wd->cur == NULL) {
351 wd->cur = eina_list_last(wd->its);
354 wd->step = -ANI_STEP;
356 _imageslider_obj_shift(wd, 0);
359 } else if (step < 0) {
360 wd->cur = eina_list_prev(wd->cur);
361 if (wd->cur == NULL) {
363 wd->step = -ANI_STEP;
367 _imageslider_obj_shift(wd, 1);
371 if (wd->move_x < 0) wd->step = ANI_STEP;
372 else wd->step = -ANI_STEP;
376 _imageslider_update(wd);
379 static void ev_imageslider_down_cb(void * data, Evas * e, Evas_Object * obj, void * event_info)
381 Widget_Data *wd = data;
382 Evas_Event_Mouse_Down *ev = event_info;
383 Evas_Coord ix, iy, iw, ih;
384 Evas_Object *eo = NULL;
386 if (wd->ani_lock) return;
388 wd->down_pos = ev->canvas;
389 wd->timestamp = ev->timestamp;
390 wd->move_cnt = MOVE_STEP;
392 wd->dx = ev->canvas.x;
393 wd->dy = ev->canvas.y;
394 wd->mx = ev->canvas.x;
395 wd->my = ev->canvas.y;
400 eo = edje_object_part_swallow_get(elm_layout_edje_get(obj), "swl.photo");
401 if (eo) evas_object_geometry_get(eo, &ix, &iy, &iw, &ih);
404 wd->on_zoom = EINA_TRUE;
405 edje_object_signal_emit(elm_layout_edje_get(obj), "block.off", "block");
409 fprintf( stderr, "down!\n" );
413 static void ev_imageslider_up_cb(void * data, Evas * e, Evas_Object * obj, void * event_info)
415 Widget_Data *wd = data;
416 Evas_Event_Mouse_Up *ev = event_info;
420 if (wd->ani_lock) return;
424 step = wd->down_pos.x - ev->canvas.x;
425 interval = ev->timestamp - wd->timestamp;
426 if (step == 0 || interval == 0) return;
428 if (interval < FLICK_TIME_MAX) {
429 if (step < FLICK_WIDTH_MIN && step > FLICK_WIDTH_MIN) _imageslider_obj_move(wd, 0);
430 else _imageslider_obj_move(wd, step);
432 step = (wd->x - wd->move_x) << 1;
433 if (step <= wd->w && step >= -(wd->w)) _imageslider_obj_move(wd, 0);
434 else _imageslider_obj_move(wd, step);
440 static void ev_imageslider_move_cb(void * data, Evas * e, Evas_Object * obj, void * event_info)
445 Widget_Data *wd = data;
446 Evas_Event_Mouse_Move *ev = event_info;
447 Elm_Imageslider_Item *it;
449 if (wd->ani_lock) return;
451 if (wd->move_cnt == MOVE_STEP) {
452 if (wd->on_hold == EINA_FALSE) {
456 step = ev->cur.canvas.x - wd->down_pos.x;
457 if (step > 0) idx = BLOCK_LEFT;
458 else idx = BLOCK_RIGHT;
460 wd->move_x = wd->x + ((ev->cur.canvas.x - wd->down_pos.x));
461 wd->move_y = wd->y + ((ev->cur.canvas.y - wd->down_pos.y));
464 _imageslider_update_center_pos(wd, wd->move_x, wd->move_y, wd->y, wd->w);
466 _imageslider_update_pos(wd, wd->move_x, wd->y, wd->w);
470 wd->mx = ev->cur.canvas.x;
471 wd->my = ev->cur.canvas.y;
473 wd->ratio = sqrt((wd->mx -wd->mmx)*(wd->mx -wd->mmx) + (wd->my - wd->mmy)*(wd->my - wd->mmy));
475 eo = edje_object_part_swallow_get(elm_layout_edje_get(obj), "swl.photo");
477 it = eina_list_data_get(wd->cur);
478 if (((it->w * wd->ratio/wd->dratio)/it->ow) < MAX_ZOOM_SIZE ) {
479 edje_object_part_unswallow(elm_layout_edje_get(obj), eo);
480 evas_object_resize(eo, it->w * wd->ratio/wd->dratio, it->h * wd->ratio/wd->dratio);
481 evas_object_size_hint_min_set(eo, it->w * wd->ratio/wd->dratio, it->h * wd->ratio/wd->dratio);
482 edje_object_part_swallow(elm_layout_edje_get(obj), "swl.photo", eo);
493 #if 0 // REMOVED about Multi-touch.
494 static void ev_imageslider_multi_down_cb(void * data, Evas * e, Evas_Object * obj, void * event_info)
496 Evas_Event_Multi_Down *ev = event_info;
497 Widget_Data *wd = data;
499 if (ev->device == MULTITOUCHDEVICE) return;
501 wd->on_hold = EINA_TRUE;
502 wd->mdx = ev->canvas.x;
503 wd->mdy = ev->canvas.y;
504 wd->mmx = ev->canvas.x;
505 wd->mmy = ev->canvas.y;
507 wd->dratio = sqrt((wd->mx - wd->mmx)*(wd->mx - wd->mmx) + (wd->my - wd->mmy)*(wd->my - wd->mmy));
508 wd->ratio = sqrt((wd->mx - wd->mmx)*(wd->mx - wd->mmx)+ (wd->my - wd->mmy)*(wd->my - wd->mmy));
511 wd->on_zoom = EINA_FALSE;
512 edje_object_signal_emit(elm_layout_edje_get(obj), "block.on", "block");
517 static void ev_imageslider_multi_up_cb(void * data, Evas * e, Evas_Object * obj, void * event_info)
519 Evas_Event_Multi_Up *ev = event_info;
520 Widget_Data *wd = data;
521 Elm_Imageslider_Item *it;
523 if (ev->device == MULTITOUCHDEVICE) return;
525 it = eina_list_data_get(wd->cur);
526 it->w = (int)it->w * wd->ratio/wd->dratio;
527 it->h = (int)it->h * wd->ratio/wd->dratio;
529 if (it->w != it->ow) {
530 wd->on_zoom = EINA_TRUE;
531 edje_object_signal_emit(elm_layout_edje_get(obj), "block.off", "block");
534 wd->on_zoom = EINA_FALSE;
537 wd->on_hold = EINA_FALSE;
547 static void ev_imageslider_multi_move_cb(void * data, Evas * e, Evas_Object * obj, void * event_info)
549 Evas_Event_Multi_Move *ev = event_info;
550 Widget_Data *wd = data;
551 Evas_Object *eo = NULL;
552 Elm_Imageslider_Item *it;
554 if (ev->device == MULTITOUCHDEVICE) return;
556 if ((wd->mdx == 0) && (wd->mdy == 0) && (wd->mmx == 0) && (wd->mmy == 0)) {
557 wd->mdx = ev->cur.canvas.x;
558 wd->mdy = ev->cur.canvas.y;
559 wd->mmx = ev->cur.canvas.x;
560 wd->mmy = ev->cur.canvas.y;
562 wd->dratio = sqrt((wd->dx - wd->mdx)*(wd->dx - wd->mdx) + (wd->dy - wd->mdy)*(wd->dy - wd->mdy));
565 wd->mmx = ev->cur.canvas.x;
566 wd->mmy = ev->cur.canvas.y;
567 wd->ratio = sqrt((wd->mx - wd->mmx)*(wd->mx - wd->mmx) + (wd->my - wd->mmy)*(wd->my - wd->mmy));
569 eo = edje_object_part_swallow_get(elm_layout_edje_get(obj), "swl.photo");
572 it = eina_list_data_get(wd->cur);
573 if (((it->w * wd->ratio/wd->dratio)/it->ow) < MAX_ZOOM_SIZE) {
574 edje_object_part_unswallow(elm_layout_edje_get(obj), eo);
575 evas_object_resize(eo, it->w * wd->ratio/wd->dratio, it->h * wd->ratio/wd->dratio);
576 evas_object_size_hint_min_set(eo, it->w * wd->ratio/wd->dratio, it->h * wd->ratio/wd->dratio);
577 edje_object_part_swallow(elm_layout_edje_get(obj), "swl.photo", eo);
582 #endif // about Multi-touch.
584 static inline double time_get(Evas_Coord x, Evas_Coord w)
587 time = (-sin(x / w) + 1) / 500;
589 if (time == 0) time = ANI_TIME;
594 static int _icon_to_image(void *data)
596 Widget_Data *wd = data;
598 _imageslider_update(wd);
603 static int _check_drag(int state, void *data)
605 Widget_Data *wd = data;
606 Elm_Imageslider_Item *it;
607 Evas_Coord ix, iy, iw, ih;
609 Eina_List *l[BLOCK_MAX];
610 Evas_Object *eo = NULL;
611 l[BLOCK_LEFT] = eina_list_prev(wd->cur);
612 l[BLOCK_CENTER] = wd->cur;
613 l[BLOCK_RIGHT] = eina_list_next(wd->cur);
615 it = eina_list_data_get(l[state]);
617 eo = edje_object_part_swallow_get(elm_layout_edje_get(wd->ly[state]), "swl.photo");
618 if (eo) evas_object_geometry_get(eo, &ix, &iy, &iw, &ih);
619 evas_object_geometry_get(eo, &ix, &iy, &iw, &ih);
620 edje_object_part_drag_value_get(elm_layout_edje_get(wd->ly[state]), "swl.photo", &dx, &dy);
622 if ((iw != wd->w) || ((dx != 0 ) || (dy != 0 ))) {
624 evas_object_del(wd->ly[state]);
625 wd->ly[state] = NULL;
627 wd->ly[state] = _imageslider_add_obj(wd);
636 static void _check_zoom(void *data)
638 Widget_Data *wd = data;
639 Elm_Imageslider_Item *it;
640 Evas_Coord ix, iy, iw, ih;
642 Evas_Object *eo = NULL;
644 it = eina_list_data_get(wd->cur);
646 eo = edje_object_part_swallow_get(elm_layout_edje_get(wd->ly[BLOCK_CENTER]), "swl.photo");
647 if (eo) evas_object_geometry_get(eo, &ix, &iy, &iw, &ih);
648 evas_object_geometry_get(eo, &ix, &iy, &iw, &ih);
649 edje_object_part_drag_value_get(elm_layout_edje_get(wd->ly[BLOCK_CENTER]), "swl.photo", &dx, &dy);
651 if ((iw != wd->w) || ((dx != 0) || (dy != 0))) {
652 wd->on_zoom = EINA_TRUE;
653 edje_object_signal_emit(elm_layout_edje_get(wd->ly[BLOCK_CENTER]), "block.off", "block");
656 wd->on_zoom = EINA_FALSE;
657 edje_object_signal_emit(elm_layout_edje_get(wd->ly[BLOCK_CENTER]), "block.on", "block");
663 static int _timer_cb(void *data)
666 Elm_Imageslider_Item *it;
671 if (wd->ani_lock == 0 ) return 0;
673 gettimeofday(&tv, NULL);
675 t = (tv.tv_sec - wd->tv.tv_sec) * 1000 + (tv.tv_usec - wd->tv.tv_usec) / 1000;
676 gettimeofday(&wd->tv, NULL);
678 t = t / ANI_TIME_MSEC;
679 if (t <= STEP_WEIGHT_MIN) t = STEP_WEIGHT_DEF;
680 else if (t > STEP_WEIGHT_MAX) t = STEP_WEIGHT_MAX;
682 wd->move_x += (wd->step) * t;
684 if (wd->step < 0 && wd->move_x < wd->x) wd->move_x = wd->x;
685 else if (wd->step > 0 && wd->move_x > wd->x) wd->move_x = wd->x;
687 _imageslider_update_pos(wd, wd->move_x, wd->y, wd->w);
689 if (wd->move_x == wd->x) {
692 it = eina_list_data_get(wd->cur);
693 if (it->func) it->func(it->data, wd->obj, it);
696 it = eina_list_data_get(wd->cur);
697 evas_object_smart_callback_call(wd->obj, "changed", it);
700 ret = _check_drag(BLOCK_LEFT, wd);
701 ret = _check_drag(BLOCK_RIGHT, wd);
705 if (wd->queue_idler) {
706 ecore_idler_del(wd->queue_idler);
707 wd->queue_idler = NULL;
710 if (!wd->queue_idler) wd->queue_idler = ecore_idler_add(_icon_to_image, wd);
718 static void _anim(Widget_Data *wd)
722 if (wd->x == wd->move_x) {
723 _imageslider_update_pos(wd, wd->move_x, wd->y, wd->w);
730 gettimeofday(&wd->tv, NULL);
732 if (wd->anim_timer) {
733 ecore_timer_del(wd->anim_timer);
734 wd->anim_timer = NULL;
737 if (!wd->anim_timer) wd->anim_timer = ecore_timer_add(ANI_TIME, _timer_cb, wd);
741 static void _imageslider_update(Widget_Data *wd)
744 Eina_List *l[BLOCK_MAX];
745 Elm_Imageslider_Item *it;
753 _imageslider_del_all(wd);
757 l[BLOCK_LEFT] = eina_list_prev(wd->cur);
758 l[BLOCK_CENTER] = wd->cur;
759 l[BLOCK_RIGHT] = eina_list_next(wd->cur);
761 for (i = 0; i < BLOCK_MAX; i++) {
762 eo = edje_object_part_swallow_get(elm_layout_edje_get(wd->ly[i]), "swl.photo");
764 elm_layout_content_set(wd->ly[i], "swl.photo", NULL);
767 it = eina_list_data_get(l[i]);
771 eo = elm_image_add(wd->obj);
772 elm_layout_content_set(wd->ly[i], "swl.photo", eo);
773 elm_image_prescale_set(eo, wd->w);
774 elm_image_file_set(eo, it->photo_file, NULL);
775 elm_image_object_size_get(eo, &it->w, &it->h);
776 evas_object_geometry_get(eo, &it->ox, &it->oy, &it->ow, &it->oh);
781 if (wd->moving != it->moving) {
782 it->moving = wd->moving;
784 elm_image_prescale_set(eo, MOVING_IMAGE_SIZE);
786 elm_image_prescale_set(eo, it->w > it->h ? it->w : it->h);
798 * Add an Image Slider widget
800 * @param parent The parent object
801 * @return The new Image slider object or NULL if it cannot be created
803 * @ingroup Imageslider
806 elm_imageslider_add(Evas_Object * parent)
809 Evas_Object *obj = NULL;
810 Widget_Data *wd = NULL;
817 wd = ELM_NEW(Widget_Data);
818 e = evas_object_evas_get(parent);
823 obj = elm_widget_add(e);
824 ELM_SET_WIDTYPE(widtype, "imageslider");
825 elm_widget_type_set(obj, "imageslider");
826 elm_widget_sub_object_add(parent, obj);
827 elm_widget_data_set(obj, wd);
828 //wd->parent = parent;
829 elm_widget_del_hook_set(obj, _del_hook);
830 //elm_widget_theme_hook_set(obj, _theme_hook);
832 wd->clip = evas_object_rectangle_add(e);
834 for (i=0; i < BLOCK_MAX; i++) {
835 wd->ly[i] = elm_layout_add(obj);
836 elm_layout_theme_set(wd->ly[i], "imageslider", "base", "default");
837 elm_widget_resize_object_set(obj, wd->ly[i]);
838 evas_object_smart_member_add(wd->ly[i], obj);
839 evas_object_event_callback_add(wd->ly[i], EVAS_CALLBACK_MOUSE_DOWN, ev_imageslider_down_cb, wd);
840 evas_object_event_callback_add(wd->ly[i], EVAS_CALLBACK_MOUSE_UP, ev_imageslider_up_cb, wd);
841 evas_object_event_callback_add(wd->ly[i], EVAS_CALLBACK_MOUSE_MOVE, ev_imageslider_move_cb, wd);
842 evas_object_clip_set(wd->ly[i], wd->clip);
843 evas_object_show(wd->ly[i]);
848 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _imageslider_resize, obj);
849 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _imageslider_move, obj);
850 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _imageslider_show, obj);
851 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _imageslider_hide, obj);
860 * Append an Image Slider item
862 * @param obj The Image Slider object
863 * @param photo_file photo file path
864 * @param func callback function
865 * @param data callback data
866 * @return The Image Slider item handle or NULL
868 * @ingroup Imageslider
870 EAPI Elm_Imageslider_Item *
871 elm_imageslider_item_append(Evas_Object * obj, const char * photo_file, Elm_Imageslider_Cb func, void * data)
873 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
875 Elm_Imageslider_Item *it;
877 if (!obj || !(wd = elm_widget_data_get(obj))) {
881 it = (Elm_Imageslider_Item *)calloc(1, sizeof(Elm_Imageslider_Item));
882 if (!it) return NULL;
883 it->photo_file = eina_stringshare_add(photo_file);
887 wd->its = eina_list_append(wd->its, it);
889 if (!wd->cur) wd->cur = wd->its;
891 _imageslider_update(wd);
898 * Prepend Image Slider item
900 * @param obj The Image Slider object
901 * @param photo_file photo file path
902 * @param func callback function
903 * @param data callback data
904 * @return The imageslider item handle or NULL
906 * @ingroup Imageslider
908 EAPI Elm_Imageslider_Item *
909 elm_imageslider_item_prepend(Evas_Object * obj, const char * photo_file, Elm_Imageslider_Cb func, void * data)
911 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
913 Elm_Imageslider_Item *it;
915 if (!obj || !(wd = elm_widget_data_get(obj))) {
919 it = (Elm_Imageslider_Item *)calloc(1, sizeof(Elm_Imageslider_Item));
920 it->photo_file = eina_stringshare_add(photo_file);
924 wd->its = eina_list_prepend(wd->its, it );
926 if (!wd->cur) wd->cur = wd->its;
928 _imageslider_update(wd);
936 * Delete the selected Image Slider item
938 * @param it The selected Image Slider item handle
940 * @ingroup Imageslider
943 elm_imageslider_item_del(Elm_Imageslider_Item * it)
946 Elm_Imageslider_Item *_it;
949 if (!it || !(wd = elm_widget_data_get(it->obj))) {
953 EINA_LIST_FOREACH(wd->its, l, _it) {
955 if (l == wd->cur) wd->cur = eina_list_prev(wd->cur);
956 wd->its = eina_list_remove(wd->its, it);
957 if (!wd->cur) wd->cur = wd->its;
962 _imageslider_update(wd);
968 * Get the selected Image Slider item
970 * @param obj The Image Slider object
971 * @return The selected Image Slider item or NULL
973 * @ingroup Imageslider
975 EAPI Elm_Imageslider_Item *
976 elm_imageslider_selected_item_get(Evas_Object * obj)
978 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
981 if (!obj || (!(wd = elm_widget_data_get(obj)))) {
985 if (!wd->cur) return NULL;
987 return eina_list_data_get(wd->cur);
991 * Get whether an Image Slider item is selected or not
993 * @param it the selected Image Slider item
994 * @return EINA_TRUE or EINA_FALSE
996 * @ingroup Imageslider
999 elm_imageslider_item_selected_get(Elm_Imageslider_Item * it)
1003 if (!it || !it->obj || (!(wd = elm_widget_data_get(it->obj)))) {
1007 if (!wd->cur) return EINA_FALSE;
1009 if (eina_list_data_get(wd->cur) == it ) return EINA_TRUE;
1010 else return EINA_FALSE;
1015 * Set the selected Image Slider item
1017 * @param it The Imaga Slider item
1019 * @ingroup Imageslider
1022 elm_imageslider_item_selected_set(Elm_Imageslider_Item * it)
1026 Elm_Imageslider_Item *_it;
1030 if (!it || !it->obj || (!(wd = elm_widget_data_get(it->obj)))) {
1034 EINA_LIST_FOREACH(wd->its, l, _it) {
1040 for (i = 0; i < BLOCK_MAX; i++) {
1041 eo = edje_object_part_swallow_get(elm_layout_edje_get(wd->ly[i]), "swl.photo");
1043 elm_layout_content_set(wd->ly[i], "swl.photo", NULL);
1044 evas_object_del(eo);
1048 _imageslider_update(wd);
1054 * Get the photo file path of given Image Slider item
1056 * @param it The Image Slider item
1057 * @return The photo file path or NULL;
1059 * @ingroup Imageslider
1062 elm_imageslider_item_photo_file_get(Elm_Imageslider_Item * it)
1068 return it->photo_file;
1073 * Get the previous Image Slider item
1075 * @param it The Image Slider item
1076 * @return The previous Image Slider item or NULL
1078 * @ingroup Imageslider
1080 EAPI Elm_Imageslider_Item *
1081 elm_imageslider_item_prev(Elm_Imageslider_Item * it)
1084 Elm_Imageslider_Item *_it;
1087 if (!it || (!(wd = elm_widget_data_get(it->obj)))) {
1091 EINA_LIST_FOREACH(wd->its, l, _it) {
1093 l = eina_list_prev(l);
1095 return eina_list_data_get(l);
1104 * Get the next Image Slider item
1106 * @param it The Image Slider item
1107 * @return The next Image Slider item or NULL
1109 * @ingroup Imageslider
1111 EAPI Elm_Imageslider_Item *
1112 elm_imageslider_item_next(Elm_Imageslider_Item * it)
1115 Elm_Imageslider_Item *_it;
1118 if (!it || (!(wd = elm_widget_data_get(it->obj)))) {
1122 EINA_LIST_FOREACH(wd->its, l, _it) {
1124 l = eina_list_next(l);
1126 return eina_list_data_get(l);
1135 * Move to the previous Image Slider item
1137 * @param obj The Image Slider object
1139 * @ingroup Imageslider
1142 elm_imageslider_prev(Evas_Object * obj)
1144 ELM_CHECK_WIDTYPE(obj, widtype);
1147 if (!obj || (!(wd = elm_widget_data_get(obj)))) {
1151 if (wd->ani_lock) return;
1153 _imageslider_obj_move(wd, -1);
1158 * Move to the next Image Slider item
1160 * @param obj The Image Slider object
1162 * @ingroup Imageslider
1165 elm_imageslider_next(Evas_Object * obj)
1167 ELM_CHECK_WIDTYPE(obj, widtype);
1170 if (!obj || (!(wd = elm_widget_data_get(obj)))) {
1174 if (wd->ani_lock) return;
1176 _imageslider_obj_move(wd, 1);