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;
82 static const char *widtype = NULL;
83 static const char SIG_CLICKED[] = "clicked";
85 static void _del_hook(Evas_Object *obj);
86 static void _theme_hook(Evas_Object *obj);
87 static void _sizing_eval(Evas_Object *obj);
88 static void _imageslider_del_all(Widget_Data *wd);
89 static void _imageslider_move(void *data,Evas *e, Evas_Object *obj, void *event_info);
90 static void _imageslider_resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
91 //static void _imageslider_show(Evas_Object *obj);
92 //static void _imageslider_hide(Evas_Object *obj);
93 static void _imageslider_show(void * data, Evas * e, Evas_Object * obj, void * event_info);
94 static void _imageslider_hide(void * data, Evas * e, Evas_Object * obj, void * event_info);
95 static void _imageslider_update(Widget_Data *wd);
96 static void _imageslider_update_pos(Widget_Data *wd, Evas_Coord x, Evas_Coord y, Evas_Coord w);
97 static void _imageslider_update_center_pos(Widget_Data *wd, Evas_Coord x, Evas_Coord my, Evas_Coord y, Evas_Coord w);
98 static Evas_Object *_imageslider_add_obj(Widget_Data *wd);
99 static void _imageslider_obj_shift(Widget_Data *wd, Eina_Bool left);
100 static void _imageslider_obj_move(Widget_Data *wd, Evas_Coord step);
101 static Eina_Bool _icon_to_image(void *data);
102 static int _check_drag(int state, void *data);
103 static void _check_zoom(void *data);
104 static void _anim(Widget_Data *wd);
105 static Eina_Bool _timer_cb(void *data);
106 static void _signal_clicked(void *data, Evas_Object *obj, const char *emission, const char *source);
107 static void ev_imageslider_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
108 static void ev_imageslider_up_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
109 static void ev_imageslider_move_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
112 static void _del_hook(Evas_Object * obj)
116 wd = elm_widget_data_get(obj);
118 //fprintf( stderr, "Call imageslider del hook!\n" );
122 for (i = 0; i < BLOCK_MAX; i++) {
123 evas_object_del(wd->ly[i]);
127 eina_list_free(wd->its);
131 if (wd->queue_idler) {
132 ecore_idler_del(wd->queue_idler);
133 wd->queue_idler = NULL;
136 if (wd->anim_timer) {
137 ecore_timer_del(wd->anim_timer);
138 wd->anim_timer = NULL;
145 static void _theme_hook(Evas_Object * obj)
149 wd = elm_widget_data_get(obj);
151 if (!wd || !wd->ly ) {
155 for (i=0; i < BLOCK_MAX; i++) {
156 wd->ly[i] = elm_layout_add(obj);
157 _elm_theme_object_set(obj, wd->ly[i], "imageslider", "base", "default");
158 elm_widget_resize_object_set(obj, wd->ly[i]);
159 evas_object_show(wd->ly[i]);
166 static void _sizing_eval(Evas_Object * obj)
169 Widget_Data *wd = elm_widget_data_get(obj);
175 e = evas_object_evas_get(wd->obj);
177 _imageslider_move(obj, e, obj, NULL);
178 _imageslider_resize(obj, e, obj, NULL);
182 static void _imageslider_move(void * data, Evas * e, Evas_Object * obj, void * event_info)
191 wd = elm_widget_data_get((Evas_Object *) data);
196 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
199 evas_object_move(wd->clip, x, y);
201 _imageslider_update_pos(wd, wd->x, wd->y, wd->w);
205 static void _imageslider_resize(void * data, Evas * e, Evas_Object * obj, void * event_info)
215 wd = elm_widget_data_get((Evas_Object *) data);
216 if (!wd || !wd->ly) {
220 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
221 fprintf( stderr, "%d %d -resize\n" , w, h );
225 for (i = 0; i < BLOCK_MAX; i++) {
226 evas_object_resize(wd->ly[i], w, h);
229 evas_object_resize(wd->clip, w, h);
231 _imageslider_update_pos(wd, wd->x, wd->y, wd->w);
236 //static void _imageslider_show(Evas_Object * obj)
237 static void _imageslider_show(void *data, Evas *e, Evas_Object * obj, void *event_info)
245 wd = elm_widget_data_get((Evas_Object *) data);
250 evas_object_show(wd->clip);
253 //static void _imageslider_hide(Evas_Object *obj)
254 static void _imageslider_hide(void *data, Evas *e, Evas_Object *obj, void *event_info)
262 wd = elm_widget_data_get((Evas_Object *) data);
266 evas_object_hide(wd->clip);
269 static void _imageslider_del_all(Widget_Data * wd)
278 for (i = 0; i < BLOCK_MAX; i++) {
279 evas_object_del(wd->ly[i]);
283 static void _imageslider_update_pos(Widget_Data * wd, Evas_Coord x, Evas_Coord y, Evas_Coord w)
285 evas_object_move(wd->ly[BLOCK_LEFT], x - (w + INTERVAL_WIDTH), y);
286 evas_object_move(wd->ly[BLOCK_CENTER], x, y);
287 evas_object_move(wd->ly[BLOCK_RIGHT], x + (w + INTERVAL_WIDTH), y);
288 evas_render_idle_flush(evas_object_evas_get(wd->obj));
291 static void _imageslider_update_center_pos(Widget_Data * wd, Evas_Coord x, Evas_Coord my, Evas_Coord y, Evas_Coord w)
294 Evas_Coord ix, iy, iw, ih;
296 eo = edje_object_part_swallow_get(elm_layout_edje_get(wd->ly[BLOCK_CENTER]), "swl.photo");
297 evas_object_geometry_get(eo, &ix, &iy, &iw, &ih);
299 if ((ix > 0) || (ix + iw < wd->w)) {
300 edje_object_signal_emit(elm_layout_edje_get(wd->ly[BLOCK_CENTER]), "block.on", "block");
302 // evas_event_feed_mouse_cancel(evas_object_evas_get(wd->obj), NULL, NULL);
303 // evas_event_feed_mouse_down(evas_object_evas_get(wd->obj), 1, EVAS_BUTTON_NONE, NULL, NULL);
305 _imageslider_update_pos(wd, x, y, w);
306 wd->on_zoom = EINA_FALSE;
310 static Evas_Object *_imageslider_add_obj(Widget_Data *wd)
313 eo = elm_layout_add(wd->obj);
314 elm_layout_theme_set(eo, "imageslider", "base", "default");
315 elm_widget_resize_object_set(wd->obj, eo);
316 edje_object_signal_callback_add(elm_layout_edje_get(eo), "elm,photo,clicked", "", _signal_clicked, wd->obj);
317 // evas_object_smart_member_add(eo, wd->obj);
318 evas_object_event_callback_add(eo, EVAS_CALLBACK_MOUSE_DOWN, ev_imageslider_down_cb, wd);
319 evas_object_event_callback_add(eo, EVAS_CALLBACK_MOUSE_UP, ev_imageslider_up_cb, wd);
320 evas_object_event_callback_add(eo, EVAS_CALLBACK_MOUSE_MOVE, ev_imageslider_move_cb, wd);
321 evas_object_resize(eo, wd->w, wd->h);
322 evas_object_move(eo, wd->w + INTERVAL_WIDTH, wd->y);
323 evas_object_clip_set(eo, wd->clip);
324 evas_object_show(eo);
329 static void _imageslider_obj_shift(Widget_Data *wd, Eina_Bool left)
332 if (wd->ly[BLOCK_LEFT]) {
333 evas_object_del(wd->ly[BLOCK_LEFT]);
334 wd->ly[BLOCK_LEFT] = NULL;
337 wd->ly[BLOCK_LEFT] = wd->ly[BLOCK_CENTER];
338 wd->ly[BLOCK_CENTER]= wd->ly[BLOCK_RIGHT];
339 wd->ly[BLOCK_RIGHT] = _imageslider_add_obj(wd);
341 if (wd->ly[BLOCK_RIGHT]) {
342 evas_object_del(wd->ly[BLOCK_RIGHT]);
343 wd->ly[BLOCK_RIGHT] = NULL;
346 wd->ly[BLOCK_RIGHT]= wd->ly[BLOCK_CENTER];
347 wd->ly[BLOCK_CENTER]= wd->ly[BLOCK_LEFT];
348 wd->ly[BLOCK_LEFT]= _imageslider_add_obj(wd);
353 static void _imageslider_obj_move(Widget_Data * wd, Evas_Coord step)
356 wd->cur = eina_list_next(wd->cur);
357 if (wd->cur == NULL) {
358 wd->cur = eina_list_last(wd->its);
361 wd->step = -ANI_STEP;
363 _imageslider_obj_shift(wd, 0);
366 } else if (step < 0) {
367 wd->cur = eina_list_prev(wd->cur);
368 if (wd->cur == NULL) {
370 wd->step = -ANI_STEP;
374 _imageslider_obj_shift(wd, 1);
378 if (wd->move_x < 0) wd->step = ANI_STEP;
379 else wd->step = -ANI_STEP;
383 _imageslider_update(wd);
386 static void ev_imageslider_down_cb(void * data, Evas * e, Evas_Object * obj, void * event_info)
388 Widget_Data *wd = data;
389 Evas_Event_Mouse_Down *ev = event_info;
390 Evas_Coord ix, iy, iw, ih;
391 Evas_Object *eo = NULL;
393 if (wd->ani_lock) return;
395 wd->down_pos = ev->canvas;
396 wd->timestamp = ev->timestamp;
397 wd->move_cnt = MOVE_STEP;
399 wd->dx = ev->canvas.x;
400 wd->dy = ev->canvas.y;
401 wd->mx = ev->canvas.x;
402 wd->my = ev->canvas.y;
407 eo = edje_object_part_swallow_get(elm_layout_edje_get(obj), "swl.photo");
408 if (eo) evas_object_geometry_get(eo, &ix, &iy, &iw, &ih);
411 wd->on_zoom = EINA_TRUE;
412 edje_object_signal_emit(elm_layout_edje_get(obj), "block.off", "block");
416 //fprintf( stderr, "-- down! --\n" );
420 static void ev_imageslider_up_cb(void * data, Evas * e, Evas_Object * obj, void * event_info)
422 Widget_Data *wd = data;
423 Evas_Event_Mouse_Up *ev = event_info;
427 if (wd->ani_lock) return;
431 step = wd->down_pos.x - ev->canvas.x;
432 interval = ev->timestamp - wd->timestamp;
433 if (step == 0 || interval == 0) return;
435 if (interval < FLICK_TIME_MAX) {
436 if (step < FLICK_WIDTH_MIN && step > FLICK_WIDTH_MIN) _imageslider_obj_move(wd, 0);
437 else _imageslider_obj_move(wd, step);
439 step = (wd->x - wd->move_x) << 1;
440 if (step <= wd->w && step >= -(wd->w)) _imageslider_obj_move(wd, 0);
441 else _imageslider_obj_move(wd, step);
445 //fprintf( stderr, "-- up! --\n" );
449 static void ev_imageslider_move_cb(void * data, Evas * e, Evas_Object * obj, void * event_info)
454 Widget_Data *wd = data;
455 Evas_Event_Mouse_Move *ev = event_info;
456 Elm_Imageslider_Item *it;
458 if (wd->ani_lock) return;
460 if (wd->move_cnt == MOVE_STEP) {
461 if (wd->on_hold == EINA_FALSE) {
465 step = ev->cur.canvas.x - wd->down_pos.x;
466 if (step > 0) idx = BLOCK_LEFT;
467 else idx = BLOCK_RIGHT;
469 wd->move_x = wd->x + ((ev->cur.canvas.x - wd->down_pos.x));
470 wd->move_y = wd->y + ((ev->cur.canvas.y - wd->down_pos.y));
473 _imageslider_update_center_pos(wd, wd->move_x, wd->move_y, wd->y, wd->w);
475 _imageslider_update_pos(wd, wd->move_x, wd->y, wd->w);
479 wd->mx = ev->cur.canvas.x;
480 wd->my = ev->cur.canvas.y;
482 wd->ratio = sqrt((wd->mx -wd->mmx)*(wd->mx -wd->mmx) + (wd->my - wd->mmy)*(wd->my - wd->mmy));
484 eo = edje_object_part_swallow_get(elm_layout_edje_get(obj), "swl.photo");
486 it = eina_list_data_get(wd->cur);
487 if (((it->w * wd->ratio/wd->dratio)/it->ow) < MAX_ZOOM_SIZE ) {
488 edje_object_part_unswallow(elm_layout_edje_get(obj), eo);
489 evas_object_resize(eo, it->w * wd->ratio/wd->dratio, it->h * wd->ratio/wd->dratio);
490 evas_object_size_hint_min_set(eo, it->w * wd->ratio/wd->dratio, it->h * wd->ratio/wd->dratio);
491 edje_object_part_swallow(elm_layout_edje_get(obj), "swl.photo", eo);
503 _signal_clicked(void *data, Evas_Object *obj, const char *emission, const char *source)
505 //fprintf(stderr, "[[[ DEBUG ]]]: (EFL) SIGNAL CLICKED!!\n");
506 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
509 #if 0 // REMOVED about Multi-touch.
510 static void ev_imageslider_multi_down_cb(void * data, Evas * e, Evas_Object * obj, void * event_info)
512 Evas_Event_Multi_Down *ev = event_info;
513 Widget_Data *wd = data;
515 if (ev->device == MULTITOUCHDEVICE) return;
517 wd->on_hold = EINA_TRUE;
518 wd->mdx = ev->canvas.x;
519 wd->mdy = ev->canvas.y;
520 wd->mmx = ev->canvas.x;
521 wd->mmy = ev->canvas.y;
523 wd->dratio = sqrt((wd->mx - wd->mmx)*(wd->mx - wd->mmx) + (wd->my - wd->mmy)*(wd->my - wd->mmy));
524 wd->ratio = sqrt((wd->mx - wd->mmx)*(wd->mx - wd->mmx)+ (wd->my - wd->mmy)*(wd->my - wd->mmy));
527 wd->on_zoom = EINA_FALSE;
528 edje_object_signal_emit(elm_layout_edje_get(obj), "block.on", "block");
533 static void ev_imageslider_multi_up_cb(void * data, Evas * e, Evas_Object * obj, void * event_info)
535 Evas_Event_Multi_Up *ev = event_info;
536 Widget_Data *wd = data;
537 Elm_Imageslider_Item *it;
539 if (ev->device == MULTITOUCHDEVICE) return;
541 it = eina_list_data_get(wd->cur);
542 it->w = (int)it->w * wd->ratio/wd->dratio;
543 it->h = (int)it->h * wd->ratio/wd->dratio;
545 if (it->w != it->ow) {
546 wd->on_zoom = EINA_TRUE;
547 edje_object_signal_emit(elm_layout_edje_get(obj), "block.off", "block");
550 wd->on_zoom = EINA_FALSE;
553 wd->on_hold = EINA_FALSE;
563 static void ev_imageslider_multi_move_cb(void * data, Evas * e, Evas_Object * obj, void * event_info)
565 Evas_Event_Multi_Move *ev = event_info;
566 Widget_Data *wd = data;
567 Evas_Object *eo = NULL;
568 Elm_Imageslider_Item *it;
570 if (ev->device == MULTITOUCHDEVICE) return;
572 if ((wd->mdx == 0) && (wd->mdy == 0) && (wd->mmx == 0) && (wd->mmy == 0)) {
573 wd->mdx = ev->cur.canvas.x;
574 wd->mdy = ev->cur.canvas.y;
575 wd->mmx = ev->cur.canvas.x;
576 wd->mmy = ev->cur.canvas.y;
578 wd->dratio = sqrt((wd->dx - wd->mdx)*(wd->dx - wd->mdx) + (wd->dy - wd->mdy)*(wd->dy - wd->mdy));
581 wd->mmx = ev->cur.canvas.x;
582 wd->mmy = ev->cur.canvas.y;
583 wd->ratio = sqrt((wd->mx - wd->mmx)*(wd->mx - wd->mmx) + (wd->my - wd->mmy)*(wd->my - wd->mmy));
585 eo = edje_object_part_swallow_get(elm_layout_edje_get(obj), "swl.photo");
588 it = eina_list_data_get(wd->cur);
589 if (((it->w * wd->ratio/wd->dratio)/it->ow) < MAX_ZOOM_SIZE) {
590 edje_object_part_unswallow(elm_layout_edje_get(obj), eo);
591 evas_object_resize(eo, it->w * wd->ratio/wd->dratio, it->h * wd->ratio/wd->dratio);
592 evas_object_size_hint_min_set(eo, it->w * wd->ratio/wd->dratio, it->h * wd->ratio/wd->dratio);
593 edje_object_part_swallow(elm_layout_edje_get(obj), "swl.photo", eo);
598 #endif // about Multi-touch.
600 static inline double time_get(Evas_Coord x, Evas_Coord w)
603 time = (-sin(x / w) + 1) / 500;
605 if (time == 0) time = ANI_TIME;
610 static Eina_Bool _icon_to_image(void *data)
612 Widget_Data *wd = data;
614 _imageslider_update(wd);
616 if (wd->queue_idler) {
617 ecore_idler_del(wd->queue_idler);
618 wd->queue_idler = NULL;
620 return ECORE_CALLBACK_CANCEL;
623 static int _check_drag(int state, void *data)
625 Widget_Data *wd = data;
626 Elm_Imageslider_Item *it;
627 Evas_Coord ix, iy, iw, ih;
629 Eina_List *l[BLOCK_MAX];
630 Evas_Object *eo = NULL;
631 l[BLOCK_LEFT] = eina_list_prev(wd->cur);
632 l[BLOCK_CENTER] = wd->cur;
633 l[BLOCK_RIGHT] = eina_list_next(wd->cur);
635 it = eina_list_data_get(l[state]);
637 eo = edje_object_part_swallow_get(elm_layout_edje_get(wd->ly[state]), "swl.photo");
638 if (eo) evas_object_geometry_get(eo, &ix, &iy, &iw, &ih);
639 evas_object_geometry_get(eo, &ix, &iy, &iw, &ih);
640 edje_object_part_drag_value_get(elm_layout_edje_get(wd->ly[state]), "swl.photo", &dx, &dy);
642 if ((iw != wd->w) || ((dx != 0 ) || (dy != 0 ))) {
644 evas_object_del(wd->ly[state]);
645 wd->ly[state] = NULL;
647 wd->ly[state] = _imageslider_add_obj(wd);
656 static void _check_zoom(void *data)
658 Widget_Data *wd = data;
659 Elm_Imageslider_Item *it;
660 Evas_Coord ix, iy, iw, ih;
662 Evas_Object *eo = NULL;
664 it = eina_list_data_get(wd->cur);
666 eo = edje_object_part_swallow_get(elm_layout_edje_get(wd->ly[BLOCK_CENTER]), "swl.photo");
667 if (eo) evas_object_geometry_get(eo, &ix, &iy, &iw, &ih);
668 evas_object_geometry_get(eo, &ix, &iy, &iw, &ih);
669 edje_object_part_drag_value_get(elm_layout_edje_get(wd->ly[BLOCK_CENTER]), "swl.photo", &dx, &dy);
671 if ((iw != wd->w) || ((dx != 0) || (dy != 0))) {
672 wd->on_zoom = EINA_TRUE;
673 edje_object_signal_emit(elm_layout_edje_get(wd->ly[BLOCK_CENTER]), "block.off", "block");
676 wd->on_zoom = EINA_FALSE;
677 edje_object_signal_emit(elm_layout_edje_get(wd->ly[BLOCK_CENTER]), "block.on", "block");
683 static Eina_Bool _timer_cb(void *data)
686 Elm_Imageslider_Item *it;
691 if (wd->ani_lock == 0 ) return 0;
693 gettimeofday(&tv, NULL);
695 t = (tv.tv_sec - wd->tv.tv_sec) * 1000 + (tv.tv_usec - wd->tv.tv_usec) / 1000;
696 gettimeofday(&wd->tv, NULL);
698 t = t / ANI_TIME_MSEC;
699 if (t <= STEP_WEIGHT_MIN) t = STEP_WEIGHT_DEF;
700 else if (t > STEP_WEIGHT_MAX) t = STEP_WEIGHT_MAX;
702 wd->move_x += (wd->step) * t;
704 if (wd->step < 0 && wd->move_x < wd->x) wd->move_x = wd->x;
705 else if (wd->step > 0 && wd->move_x > wd->x) wd->move_x = wd->x;
707 _imageslider_update_pos(wd, wd->move_x, wd->y, wd->w);
709 if (wd->move_x == wd->x) {
712 it = eina_list_data_get(wd->cur);
713 if (it->func) it->func(it->data, wd->obj, it);
716 it = eina_list_data_get(wd->cur);
717 evas_object_smart_callback_call(wd->obj, "changed", it);
720 ret = _check_drag(BLOCK_LEFT, wd);
721 ret = _check_drag(BLOCK_RIGHT, wd);
724 if (!wd->queue_idler) wd->queue_idler = ecore_idler_add(_icon_to_image, wd);
727 ecore_timer_del(wd->anim_timer);
728 wd->anim_timer = NULL;
731 return ECORE_CALLBACK_CANCEL;
734 return ECORE_CALLBACK_RENEW;
738 static void _anim(Widget_Data *wd)
742 if (wd->x == wd->move_x) {
743 _imageslider_update_pos(wd, wd->move_x, wd->y, wd->w);
750 gettimeofday(&wd->tv, NULL);
752 if (!wd->anim_timer) {
753 wd->anim_timer = ecore_timer_add(ANI_TIME, _timer_cb, wd);
757 static void _imageslider_update(Widget_Data *wd)
760 Eina_List *l[BLOCK_MAX];
761 Elm_Imageslider_Item *it;
769 _imageslider_del_all(wd);
773 l[BLOCK_LEFT] = eina_list_prev(wd->cur);
774 l[BLOCK_CENTER] = wd->cur;
775 l[BLOCK_RIGHT] = eina_list_next(wd->cur);
777 for (i = 0; i < BLOCK_MAX; i++) {
778 eo = edje_object_part_swallow_get(elm_layout_edje_get(wd->ly[i]), "swl.photo");
780 elm_layout_content_set(wd->ly[i], "swl.photo", NULL);
783 it = eina_list_data_get(l[i]);
787 eo = elm_image_add(wd->obj);
788 elm_layout_content_set(wd->ly[i], "swl.photo", eo);
789 elm_image_prescale_set(eo, wd->w);
790 elm_image_file_set(eo, it->photo_file, NULL);
791 elm_image_object_size_get(eo, &it->w, &it->h);
792 evas_object_geometry_get(eo, &it->ox, &it->oy, &it->ow, &it->oh);
797 if (wd->moving != it->moving) {
798 it->moving = wd->moving;
800 elm_image_prescale_set(eo, MOVING_IMAGE_SIZE);
802 elm_image_prescale_set(eo, it->w > it->h ? it->w : it->h);
814 * Add an Image Slider widget
816 * @param parent The parent object
817 * @return The new Image slider object or NULL if it cannot be created
819 * @ingroup Imageslider
822 elm_imageslider_add(Evas_Object * parent)
825 Evas_Object *obj = NULL;
826 Widget_Data *wd = NULL;
833 wd = ELM_NEW(Widget_Data);
834 e = evas_object_evas_get(parent);
839 obj = elm_widget_add(e);
840 ELM_SET_WIDTYPE(widtype, "imageslider");
841 elm_widget_type_set(obj, "imageslider");
842 elm_widget_sub_object_add(parent, obj);
843 elm_widget_data_set(obj, wd);
844 //wd->parent = parent;
845 elm_widget_del_hook_set(obj, _del_hook);
846 //elm_widget_theme_hook_set(obj, _theme_hook);
848 wd->clip = evas_object_rectangle_add(e);
850 for (i=0; i < BLOCK_MAX; i++) {
851 wd->ly[i] = elm_layout_add(obj);
852 elm_layout_theme_set(wd->ly[i], "imageslider", "base", "default");
853 elm_widget_resize_object_set(obj, wd->ly[i]);
854 evas_object_smart_member_add(wd->ly[i], obj);
856 edje_object_signal_callback_add(elm_layout_edje_get(wd->ly[i]), "elm,photo,clicked", "", _signal_clicked, obj);
858 evas_object_event_callback_add(wd->ly[i], EVAS_CALLBACK_MOUSE_DOWN, ev_imageslider_down_cb, wd);
859 evas_object_event_callback_add(wd->ly[i], EVAS_CALLBACK_MOUSE_UP, ev_imageslider_up_cb, wd);
860 evas_object_event_callback_add(wd->ly[i], EVAS_CALLBACK_MOUSE_MOVE, ev_imageslider_move_cb, wd);
861 evas_object_clip_set(wd->ly[i], wd->clip);
862 evas_object_show(wd->ly[i]);
867 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _imageslider_resize, obj);
868 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _imageslider_move, obj);
869 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _imageslider_show, obj);
870 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _imageslider_hide, obj);
879 * Append an Image Slider item
881 * @param obj The Image Slider object
882 * @param photo_file photo file path
883 * @param func callback function
884 * @param data callback data
885 * @return The Image Slider item handle or NULL
887 * @ingroup Imageslider
889 EAPI Elm_Imageslider_Item *
890 elm_imageslider_item_append(Evas_Object * obj, const char * photo_file, Elm_Imageslider_Cb func, void * data)
892 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
894 Elm_Imageslider_Item *it;
896 if (!obj || !(wd = elm_widget_data_get(obj))) {
900 it = (Elm_Imageslider_Item *)calloc(1, sizeof(Elm_Imageslider_Item));
901 if (!it) return NULL;
902 it->photo_file = eina_stringshare_add(photo_file);
906 wd->its = eina_list_append(wd->its, it);
908 if (!wd->cur) wd->cur = wd->its;
910 _imageslider_update(wd);
917 * Prepend Image Slider item
919 * @param obj The Image Slider object
920 * @param photo_file photo file path
921 * @param func callback function
922 * @param data callback data
923 * @return The imageslider item handle or NULL
925 * @ingroup Imageslider
927 EAPI Elm_Imageslider_Item *
928 elm_imageslider_item_prepend(Evas_Object * obj, const char * photo_file, Elm_Imageslider_Cb func, void * data)
930 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
932 Elm_Imageslider_Item *it;
934 if (!obj || !(wd = elm_widget_data_get(obj))) {
938 it = (Elm_Imageslider_Item *)calloc(1, sizeof(Elm_Imageslider_Item));
939 it->photo_file = eina_stringshare_add(photo_file);
943 wd->its = eina_list_prepend(wd->its, it );
945 if (!wd->cur) wd->cur = wd->its;
947 _imageslider_update(wd);
955 * Delete the selected Image Slider item
957 * @param it The selected Image Slider item handle
959 * @ingroup Imageslider
962 elm_imageslider_item_del(Elm_Imageslider_Item * it)
965 Elm_Imageslider_Item *_it;
968 if (!it || !(wd = elm_widget_data_get(it->obj))) {
972 EINA_LIST_FOREACH(wd->its, l, _it) {
974 if (l == wd->cur) wd->cur = eina_list_prev(wd->cur);
975 wd->its = eina_list_remove(wd->its, it);
976 if (!wd->cur) wd->cur = wd->its;
981 _imageslider_update(wd);
987 * Get the selected Image Slider item
989 * @param obj The Image Slider object
990 * @return The selected Image Slider item or NULL
992 * @ingroup Imageslider
994 EAPI Elm_Imageslider_Item *
995 elm_imageslider_selected_item_get(Evas_Object * obj)
997 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1000 if (!obj || (!(wd = elm_widget_data_get(obj)))) {
1004 if (!wd->cur) return NULL;
1006 return eina_list_data_get(wd->cur);
1010 * Get whether an Image Slider item is selected or not
1012 * @param it the selected Image Slider item
1013 * @return EINA_TRUE or EINA_FALSE
1015 * @ingroup Imageslider
1018 elm_imageslider_item_selected_get(Elm_Imageslider_Item * it)
1022 if (!it || !it->obj || (!(wd = elm_widget_data_get(it->obj)))) {
1026 if (!wd->cur) return EINA_FALSE;
1028 if (eina_list_data_get(wd->cur) == it ) return EINA_TRUE;
1029 else return EINA_FALSE;
1034 * Set the selected Image Slider item
1036 * @param it The Imaga Slider item
1038 * @ingroup Imageslider
1041 elm_imageslider_item_selected_set(Elm_Imageslider_Item * it)
1045 Elm_Imageslider_Item *_it;
1049 if (!it || !it->obj || (!(wd = elm_widget_data_get(it->obj)))) {
1053 EINA_LIST_FOREACH(wd->its, l, _it) {
1059 for (i = 0; i < BLOCK_MAX; i++) {
1060 eo = edje_object_part_swallow_get(elm_layout_edje_get(wd->ly[i]), "swl.photo");
1062 elm_layout_content_set(wd->ly[i], "swl.photo", NULL);
1063 evas_object_del(eo);
1067 _imageslider_update(wd);
1073 * Get the photo file path of given Image Slider item
1075 * @param it The Image Slider item
1076 * @return The photo file path or NULL;
1078 * @ingroup Imageslider
1081 elm_imageslider_item_photo_file_get(Elm_Imageslider_Item * it)
1087 return it->photo_file;
1092 * Get the previous Image Slider item
1094 * @param it The Image Slider item
1095 * @return The previous Image Slider item or NULL
1097 * @ingroup Imageslider
1099 EAPI Elm_Imageslider_Item *
1100 elm_imageslider_item_prev(Elm_Imageslider_Item * it)
1103 Elm_Imageslider_Item *_it;
1106 if (!it || (!(wd = elm_widget_data_get(it->obj)))) {
1110 EINA_LIST_FOREACH(wd->its, l, _it) {
1112 l = eina_list_prev(l);
1114 return eina_list_data_get(l);
1123 * Get the next Image Slider item
1125 * @param it The Image Slider item
1126 * @return The next Image Slider item or NULL
1128 * @ingroup Imageslider
1130 EAPI Elm_Imageslider_Item *
1131 elm_imageslider_item_next(Elm_Imageslider_Item * it)
1134 Elm_Imageslider_Item *_it;
1137 if (!it || (!(wd = elm_widget_data_get(it->obj)))) {
1141 EINA_LIST_FOREACH(wd->its, l, _it) {
1143 l = eina_list_next(l);
1145 return eina_list_data_get(l);
1154 * Move to the previous Image Slider item
1156 * @param obj The Image Slider object
1158 * @ingroup Imageslider
1161 elm_imageslider_prev(Evas_Object * obj)
1163 ELM_CHECK_WIDTYPE(obj, widtype);
1166 if (!obj || (!(wd = elm_widget_data_get(obj)))) {
1170 if (wd->ani_lock) return;
1172 _imageslider_obj_move(wd, -1);
1177 * Move to the next Image Slider item
1179 * @param obj The Image Slider object
1181 * @ingroup Imageslider
1184 elm_imageslider_next(Evas_Object * obj)
1186 ELM_CHECK_WIDTYPE(obj, widtype);
1189 if (!obj || (!(wd = elm_widget_data_get(obj)))) {
1193 if (wd->ani_lock) return;
1195 _imageslider_obj_move(wd, 1);