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 int _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 int _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 // evas_object_smart_member_add(eo, wd->obj);
317 evas_object_event_callback_add(eo, EVAS_CALLBACK_MOUSE_DOWN, ev_imageslider_down_cb, wd);
318 evas_object_event_callback_add(eo, EVAS_CALLBACK_MOUSE_UP, ev_imageslider_up_cb, wd);
319 evas_object_event_callback_add(eo, EVAS_CALLBACK_MOUSE_MOVE, ev_imageslider_move_cb, wd);
320 evas_object_resize(eo, wd->w, wd->h);
321 evas_object_move(eo, wd->w + INTERVAL_WIDTH, wd->y);
322 evas_object_clip_set(eo, wd->clip);
323 evas_object_show(eo);
328 static void _imageslider_obj_shift(Widget_Data *wd, Eina_Bool left)
331 if (wd->ly[BLOCK_LEFT]) {
332 evas_object_del(wd->ly[BLOCK_LEFT]);
333 wd->ly[BLOCK_LEFT] = NULL;
336 wd->ly[BLOCK_LEFT] = wd->ly[BLOCK_CENTER];
337 wd->ly[BLOCK_CENTER]= wd->ly[BLOCK_RIGHT];
338 wd->ly[BLOCK_RIGHT] = _imageslider_add_obj(wd);
340 if (wd->ly[BLOCK_RIGHT]) {
341 evas_object_del(wd->ly[BLOCK_RIGHT]);
342 wd->ly[BLOCK_RIGHT] = NULL;
345 wd->ly[BLOCK_RIGHT]= wd->ly[BLOCK_CENTER];
346 wd->ly[BLOCK_CENTER]= wd->ly[BLOCK_LEFT];
347 wd->ly[BLOCK_LEFT]= _imageslider_add_obj(wd);
352 static void _imageslider_obj_move(Widget_Data * wd, Evas_Coord step)
355 wd->cur = eina_list_next(wd->cur);
356 if (wd->cur == NULL) {
357 wd->cur = eina_list_last(wd->its);
360 wd->step = -ANI_STEP;
362 _imageslider_obj_shift(wd, 0);
365 } else if (step < 0) {
366 wd->cur = eina_list_prev(wd->cur);
367 if (wd->cur == NULL) {
369 wd->step = -ANI_STEP;
373 _imageslider_obj_shift(wd, 1);
377 if (wd->move_x < 0) wd->step = ANI_STEP;
378 else wd->step = -ANI_STEP;
382 _imageslider_update(wd);
385 static void ev_imageslider_down_cb(void * data, Evas * e, Evas_Object * obj, void * event_info)
387 Widget_Data *wd = data;
388 Evas_Event_Mouse_Down *ev = event_info;
389 Evas_Coord ix, iy, iw, ih;
390 Evas_Object *eo = NULL;
392 if (wd->ani_lock) return;
394 wd->down_pos = ev->canvas;
395 wd->timestamp = ev->timestamp;
396 wd->move_cnt = MOVE_STEP;
398 wd->dx = ev->canvas.x;
399 wd->dy = ev->canvas.y;
400 wd->mx = ev->canvas.x;
401 wd->my = ev->canvas.y;
406 eo = edje_object_part_swallow_get(elm_layout_edje_get(obj), "swl.photo");
407 if (eo) evas_object_geometry_get(eo, &ix, &iy, &iw, &ih);
410 wd->on_zoom = EINA_TRUE;
411 edje_object_signal_emit(elm_layout_edje_get(obj), "block.off", "block");
415 fprintf( stderr, "-- down! --\n" );
419 static void ev_imageslider_up_cb(void * data, Evas * e, Evas_Object * obj, void * event_info)
421 Widget_Data *wd = data;
422 Evas_Event_Mouse_Up *ev = event_info;
426 if (wd->ani_lock) return;
430 step = wd->down_pos.x - ev->canvas.x;
431 interval = ev->timestamp - wd->timestamp;
432 if (step == 0 || interval == 0) return;
434 if (interval < FLICK_TIME_MAX) {
435 if (step < FLICK_WIDTH_MIN && step > FLICK_WIDTH_MIN) _imageslider_obj_move(wd, 0);
436 else _imageslider_obj_move(wd, step);
438 step = (wd->x - wd->move_x) << 1;
439 if (step <= wd->w && step >= -(wd->w)) _imageslider_obj_move(wd, 0);
440 else _imageslider_obj_move(wd, step);
444 fprintf( stderr, "-- up! --\n" );
448 static void ev_imageslider_move_cb(void * data, Evas * e, Evas_Object * obj, void * event_info)
453 Widget_Data *wd = data;
454 Evas_Event_Mouse_Move *ev = event_info;
455 Elm_Imageslider_Item *it;
457 if (wd->ani_lock) return;
459 if (wd->move_cnt == MOVE_STEP) {
460 if (wd->on_hold == EINA_FALSE) {
464 step = ev->cur.canvas.x - wd->down_pos.x;
465 if (step > 0) idx = BLOCK_LEFT;
466 else idx = BLOCK_RIGHT;
468 wd->move_x = wd->x + ((ev->cur.canvas.x - wd->down_pos.x));
469 wd->move_y = wd->y + ((ev->cur.canvas.y - wd->down_pos.y));
472 _imageslider_update_center_pos(wd, wd->move_x, wd->move_y, wd->y, wd->w);
474 _imageslider_update_pos(wd, wd->move_x, wd->y, wd->w);
478 wd->mx = ev->cur.canvas.x;
479 wd->my = ev->cur.canvas.y;
481 wd->ratio = sqrt((wd->mx -wd->mmx)*(wd->mx -wd->mmx) + (wd->my - wd->mmy)*(wd->my - wd->mmy));
483 eo = edje_object_part_swallow_get(elm_layout_edje_get(obj), "swl.photo");
485 it = eina_list_data_get(wd->cur);
486 if (((it->w * wd->ratio/wd->dratio)/it->ow) < MAX_ZOOM_SIZE ) {
487 edje_object_part_unswallow(elm_layout_edje_get(obj), eo);
488 evas_object_resize(eo, it->w * wd->ratio/wd->dratio, it->h * wd->ratio/wd->dratio);
489 evas_object_size_hint_min_set(eo, it->w * wd->ratio/wd->dratio, it->h * wd->ratio/wd->dratio);
490 edje_object_part_swallow(elm_layout_edje_get(obj), "swl.photo", eo);
502 _signal_clicked(void *data, Evas_Object *obj, const char *emission, const char *source)
504 //fprintf(stderr, "[[[ DEBUG ]]]: (EFL) SIGNAL CLICKED!!\n");
505 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
508 #if 0 // REMOVED about Multi-touch.
509 static void ev_imageslider_multi_down_cb(void * data, Evas * e, Evas_Object * obj, void * event_info)
511 Evas_Event_Multi_Down *ev = event_info;
512 Widget_Data *wd = data;
514 if (ev->device == MULTITOUCHDEVICE) return;
516 wd->on_hold = EINA_TRUE;
517 wd->mdx = ev->canvas.x;
518 wd->mdy = ev->canvas.y;
519 wd->mmx = ev->canvas.x;
520 wd->mmy = ev->canvas.y;
522 wd->dratio = sqrt((wd->mx - wd->mmx)*(wd->mx - wd->mmx) + (wd->my - wd->mmy)*(wd->my - wd->mmy));
523 wd->ratio = sqrt((wd->mx - wd->mmx)*(wd->mx - wd->mmx)+ (wd->my - wd->mmy)*(wd->my - wd->mmy));
526 wd->on_zoom = EINA_FALSE;
527 edje_object_signal_emit(elm_layout_edje_get(obj), "block.on", "block");
532 static void ev_imageslider_multi_up_cb(void * data, Evas * e, Evas_Object * obj, void * event_info)
534 Evas_Event_Multi_Up *ev = event_info;
535 Widget_Data *wd = data;
536 Elm_Imageslider_Item *it;
538 if (ev->device == MULTITOUCHDEVICE) return;
540 it = eina_list_data_get(wd->cur);
541 it->w = (int)it->w * wd->ratio/wd->dratio;
542 it->h = (int)it->h * wd->ratio/wd->dratio;
544 if (it->w != it->ow) {
545 wd->on_zoom = EINA_TRUE;
546 edje_object_signal_emit(elm_layout_edje_get(obj), "block.off", "block");
549 wd->on_zoom = EINA_FALSE;
552 wd->on_hold = EINA_FALSE;
562 static void ev_imageslider_multi_move_cb(void * data, Evas * e, Evas_Object * obj, void * event_info)
564 Evas_Event_Multi_Move *ev = event_info;
565 Widget_Data *wd = data;
566 Evas_Object *eo = NULL;
567 Elm_Imageslider_Item *it;
569 if (ev->device == MULTITOUCHDEVICE) return;
571 if ((wd->mdx == 0) && (wd->mdy == 0) && (wd->mmx == 0) && (wd->mmy == 0)) {
572 wd->mdx = ev->cur.canvas.x;
573 wd->mdy = ev->cur.canvas.y;
574 wd->mmx = ev->cur.canvas.x;
575 wd->mmy = ev->cur.canvas.y;
577 wd->dratio = sqrt((wd->dx - wd->mdx)*(wd->dx - wd->mdx) + (wd->dy - wd->mdy)*(wd->dy - wd->mdy));
580 wd->mmx = ev->cur.canvas.x;
581 wd->mmy = ev->cur.canvas.y;
582 wd->ratio = sqrt((wd->mx - wd->mmx)*(wd->mx - wd->mmx) + (wd->my - wd->mmy)*(wd->my - wd->mmy));
584 eo = edje_object_part_swallow_get(elm_layout_edje_get(obj), "swl.photo");
587 it = eina_list_data_get(wd->cur);
588 if (((it->w * wd->ratio/wd->dratio)/it->ow) < MAX_ZOOM_SIZE) {
589 edje_object_part_unswallow(elm_layout_edje_get(obj), eo);
590 evas_object_resize(eo, it->w * wd->ratio/wd->dratio, it->h * wd->ratio/wd->dratio);
591 evas_object_size_hint_min_set(eo, it->w * wd->ratio/wd->dratio, it->h * wd->ratio/wd->dratio);
592 edje_object_part_swallow(elm_layout_edje_get(obj), "swl.photo", eo);
597 #endif // about Multi-touch.
599 static inline double time_get(Evas_Coord x, Evas_Coord w)
602 time = (-sin(x / w) + 1) / 500;
604 if (time == 0) time = ANI_TIME;
609 static int _icon_to_image(void *data)
611 Widget_Data *wd = data;
613 _imageslider_update(wd);
615 if (wd->queue_idler) {
616 ecore_idler_del(wd->queue_idler);
617 wd->queue_idler = NULL;
619 return ECORE_CALLBACK_CANCEL;
622 static int _check_drag(int state, void *data)
624 Widget_Data *wd = data;
625 Elm_Imageslider_Item *it;
626 Evas_Coord ix, iy, iw, ih;
628 Eina_List *l[BLOCK_MAX];
629 Evas_Object *eo = NULL;
630 l[BLOCK_LEFT] = eina_list_prev(wd->cur);
631 l[BLOCK_CENTER] = wd->cur;
632 l[BLOCK_RIGHT] = eina_list_next(wd->cur);
634 it = eina_list_data_get(l[state]);
636 eo = edje_object_part_swallow_get(elm_layout_edje_get(wd->ly[state]), "swl.photo");
637 if (eo) evas_object_geometry_get(eo, &ix, &iy, &iw, &ih);
638 evas_object_geometry_get(eo, &ix, &iy, &iw, &ih);
639 edje_object_part_drag_value_get(elm_layout_edje_get(wd->ly[state]), "swl.photo", &dx, &dy);
641 if ((iw != wd->w) || ((dx != 0 ) || (dy != 0 ))) {
643 evas_object_del(wd->ly[state]);
644 wd->ly[state] = NULL;
646 wd->ly[state] = _imageslider_add_obj(wd);
655 static void _check_zoom(void *data)
657 Widget_Data *wd = data;
658 Elm_Imageslider_Item *it;
659 Evas_Coord ix, iy, iw, ih;
661 Evas_Object *eo = NULL;
663 it = eina_list_data_get(wd->cur);
665 eo = edje_object_part_swallow_get(elm_layout_edje_get(wd->ly[BLOCK_CENTER]), "swl.photo");
666 if (eo) evas_object_geometry_get(eo, &ix, &iy, &iw, &ih);
667 evas_object_geometry_get(eo, &ix, &iy, &iw, &ih);
668 edje_object_part_drag_value_get(elm_layout_edje_get(wd->ly[BLOCK_CENTER]), "swl.photo", &dx, &dy);
670 if ((iw != wd->w) || ((dx != 0) || (dy != 0))) {
671 wd->on_zoom = EINA_TRUE;
672 edje_object_signal_emit(elm_layout_edje_get(wd->ly[BLOCK_CENTER]), "block.off", "block");
675 wd->on_zoom = EINA_FALSE;
676 edje_object_signal_emit(elm_layout_edje_get(wd->ly[BLOCK_CENTER]), "block.on", "block");
682 static int _timer_cb(void *data)
685 Elm_Imageslider_Item *it;
690 if (wd->ani_lock == 0 ) return 0;
692 gettimeofday(&tv, NULL);
694 t = (tv.tv_sec - wd->tv.tv_sec) * 1000 + (tv.tv_usec - wd->tv.tv_usec) / 1000;
695 gettimeofday(&wd->tv, NULL);
697 t = t / ANI_TIME_MSEC;
698 if (t <= STEP_WEIGHT_MIN) t = STEP_WEIGHT_DEF;
699 else if (t > STEP_WEIGHT_MAX) t = STEP_WEIGHT_MAX;
701 wd->move_x += (wd->step) * t;
703 if (wd->step < 0 && wd->move_x < wd->x) wd->move_x = wd->x;
704 else if (wd->step > 0 && wd->move_x > wd->x) wd->move_x = wd->x;
706 _imageslider_update_pos(wd, wd->move_x, wd->y, wd->w);
708 if (wd->move_x == wd->x) {
711 it = eina_list_data_get(wd->cur);
712 if (it->func) it->func(it->data, wd->obj, it);
715 it = eina_list_data_get(wd->cur);
716 evas_object_smart_callback_call(wd->obj, "changed", it);
719 ret = _check_drag(BLOCK_LEFT, wd);
720 ret = _check_drag(BLOCK_RIGHT, wd);
723 if (!wd->queue_idler) wd->queue_idler = ecore_idler_add(_icon_to_image, wd);
726 ecore_timer_del(wd->anim_timer);
727 wd->anim_timer = NULL;
730 return ECORE_CALLBACK_CANCEL;
733 return ECORE_CALLBACK_RENEW;
737 static void _anim(Widget_Data *wd)
741 if (wd->x == wd->move_x) {
742 _imageslider_update_pos(wd, wd->move_x, wd->y, wd->w);
749 gettimeofday(&wd->tv, NULL);
751 if (!wd->anim_timer) {
752 wd->anim_timer = ecore_timer_add(ANI_TIME, _timer_cb, wd);
756 static void _imageslider_update(Widget_Data *wd)
759 Eina_List *l[BLOCK_MAX];
760 Elm_Imageslider_Item *it;
768 _imageslider_del_all(wd);
772 l[BLOCK_LEFT] = eina_list_prev(wd->cur);
773 l[BLOCK_CENTER] = wd->cur;
774 l[BLOCK_RIGHT] = eina_list_next(wd->cur);
776 for (i = 0; i < BLOCK_MAX; i++) {
777 eo = edje_object_part_swallow_get(elm_layout_edje_get(wd->ly[i]), "swl.photo");
779 elm_layout_content_set(wd->ly[i], "swl.photo", NULL);
782 it = eina_list_data_get(l[i]);
786 eo = elm_image_add(wd->obj);
787 elm_layout_content_set(wd->ly[i], "swl.photo", eo);
788 elm_image_prescale_set(eo, wd->w);
789 elm_image_file_set(eo, it->photo_file, NULL);
790 elm_image_object_size_get(eo, &it->w, &it->h);
791 evas_object_geometry_get(eo, &it->ox, &it->oy, &it->ow, &it->oh);
796 if (wd->moving != it->moving) {
797 it->moving = wd->moving;
799 elm_image_prescale_set(eo, MOVING_IMAGE_SIZE);
801 elm_image_prescale_set(eo, it->w > it->h ? it->w : it->h);
813 * Add an Image Slider widget
815 * @param parent The parent object
816 * @return The new Image slider object or NULL if it cannot be created
818 * @ingroup Imageslider
821 elm_imageslider_add(Evas_Object * parent)
824 Evas_Object *obj = NULL;
825 Widget_Data *wd = NULL;
832 wd = ELM_NEW(Widget_Data);
833 e = evas_object_evas_get(parent);
838 obj = elm_widget_add(e);
839 ELM_SET_WIDTYPE(widtype, "imageslider");
840 elm_widget_type_set(obj, "imageslider");
841 elm_widget_sub_object_add(parent, obj);
842 elm_widget_data_set(obj, wd);
843 //wd->parent = parent;
844 elm_widget_del_hook_set(obj, _del_hook);
845 //elm_widget_theme_hook_set(obj, _theme_hook);
847 wd->clip = evas_object_rectangle_add(e);
849 for (i=0; i < BLOCK_MAX; i++) {
850 wd->ly[i] = elm_layout_add(obj);
851 elm_layout_theme_set(wd->ly[i], "imageslider", "base", "default");
852 elm_widget_resize_object_set(obj, wd->ly[i]);
853 evas_object_smart_member_add(wd->ly[i], obj);
855 edje_object_signal_callback_add(elm_layout_edje_get(wd->ly[i]), "elm,photo,clicked", "", _signal_clicked, obj);
857 evas_object_event_callback_add(wd->ly[i], EVAS_CALLBACK_MOUSE_DOWN, ev_imageslider_down_cb, wd);
858 evas_object_event_callback_add(wd->ly[i], EVAS_CALLBACK_MOUSE_UP, ev_imageslider_up_cb, wd);
859 evas_object_event_callback_add(wd->ly[i], EVAS_CALLBACK_MOUSE_MOVE, ev_imageslider_move_cb, wd);
860 evas_object_clip_set(wd->ly[i], wd->clip);
861 evas_object_show(wd->ly[i]);
866 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _imageslider_resize, obj);
867 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _imageslider_move, obj);
868 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _imageslider_show, obj);
869 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _imageslider_hide, obj);
878 * Append an Image Slider item
880 * @param obj The Image Slider object
881 * @param photo_file photo file path
882 * @param func callback function
883 * @param data callback data
884 * @return The Image Slider item handle or NULL
886 * @ingroup Imageslider
888 EAPI Elm_Imageslider_Item *
889 elm_imageslider_item_append(Evas_Object * obj, const char * photo_file, Elm_Imageslider_Cb func, void * data)
891 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
893 Elm_Imageslider_Item *it;
895 if (!obj || !(wd = elm_widget_data_get(obj))) {
899 it = (Elm_Imageslider_Item *)calloc(1, sizeof(Elm_Imageslider_Item));
900 if (!it) return NULL;
901 it->photo_file = eina_stringshare_add(photo_file);
905 wd->its = eina_list_append(wd->its, it);
907 if (!wd->cur) wd->cur = wd->its;
909 _imageslider_update(wd);
916 * Prepend Image Slider item
918 * @param obj The Image Slider object
919 * @param photo_file photo file path
920 * @param func callback function
921 * @param data callback data
922 * @return The imageslider item handle or NULL
924 * @ingroup Imageslider
926 EAPI Elm_Imageslider_Item *
927 elm_imageslider_item_prepend(Evas_Object * obj, const char * photo_file, Elm_Imageslider_Cb func, void * data)
929 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
931 Elm_Imageslider_Item *it;
933 if (!obj || !(wd = elm_widget_data_get(obj))) {
937 it = (Elm_Imageslider_Item *)calloc(1, sizeof(Elm_Imageslider_Item));
938 it->photo_file = eina_stringshare_add(photo_file);
942 wd->its = eina_list_prepend(wd->its, it );
944 if (!wd->cur) wd->cur = wd->its;
946 _imageslider_update(wd);
954 * Delete the selected Image Slider item
956 * @param it The selected Image Slider item handle
958 * @ingroup Imageslider
961 elm_imageslider_item_del(Elm_Imageslider_Item * it)
964 Elm_Imageslider_Item *_it;
967 if (!it || !(wd = elm_widget_data_get(it->obj))) {
971 EINA_LIST_FOREACH(wd->its, l, _it) {
973 if (l == wd->cur) wd->cur = eina_list_prev(wd->cur);
974 wd->its = eina_list_remove(wd->its, it);
975 if (!wd->cur) wd->cur = wd->its;
980 _imageslider_update(wd);
986 * Get the selected Image Slider item
988 * @param obj The Image Slider object
989 * @return The selected Image Slider item or NULL
991 * @ingroup Imageslider
993 EAPI Elm_Imageslider_Item *
994 elm_imageslider_selected_item_get(Evas_Object * obj)
996 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
999 if (!obj || (!(wd = elm_widget_data_get(obj)))) {
1003 if (!wd->cur) return NULL;
1005 return eina_list_data_get(wd->cur);
1009 * Get whether an Image Slider item is selected or not
1011 * @param it the selected Image Slider item
1012 * @return EINA_TRUE or EINA_FALSE
1014 * @ingroup Imageslider
1017 elm_imageslider_item_selected_get(Elm_Imageslider_Item * it)
1021 if (!it || !it->obj || (!(wd = elm_widget_data_get(it->obj)))) {
1025 if (!wd->cur) return EINA_FALSE;
1027 if (eina_list_data_get(wd->cur) == it ) return EINA_TRUE;
1028 else return EINA_FALSE;
1033 * Set the selected Image Slider item
1035 * @param it The Imaga Slider item
1037 * @ingroup Imageslider
1040 elm_imageslider_item_selected_set(Elm_Imageslider_Item * it)
1044 Elm_Imageslider_Item *_it;
1048 if (!it || !it->obj || (!(wd = elm_widget_data_get(it->obj)))) {
1052 EINA_LIST_FOREACH(wd->its, l, _it) {
1058 for (i = 0; i < BLOCK_MAX; i++) {
1059 eo = edje_object_part_swallow_get(elm_layout_edje_get(wd->ly[i]), "swl.photo");
1061 elm_layout_content_set(wd->ly[i], "swl.photo", NULL);
1062 evas_object_del(eo);
1066 _imageslider_update(wd);
1072 * Get the photo file path of given Image Slider item
1074 * @param it The Image Slider item
1075 * @return The photo file path or NULL;
1077 * @ingroup Imageslider
1080 elm_imageslider_item_photo_file_get(Elm_Imageslider_Item * it)
1086 return it->photo_file;
1091 * Get the previous Image Slider item
1093 * @param it The Image Slider item
1094 * @return The previous Image Slider item or NULL
1096 * @ingroup Imageslider
1098 EAPI Elm_Imageslider_Item *
1099 elm_imageslider_item_prev(Elm_Imageslider_Item * it)
1102 Elm_Imageslider_Item *_it;
1105 if (!it || (!(wd = elm_widget_data_get(it->obj)))) {
1109 EINA_LIST_FOREACH(wd->its, l, _it) {
1111 l = eina_list_prev(l);
1113 return eina_list_data_get(l);
1122 * Get the next Image Slider item
1124 * @param it The Image Slider item
1125 * @return The next Image Slider item or NULL
1127 * @ingroup Imageslider
1129 EAPI Elm_Imageslider_Item *
1130 elm_imageslider_item_next(Elm_Imageslider_Item * it)
1133 Elm_Imageslider_Item *_it;
1136 if (!it || (!(wd = elm_widget_data_get(it->obj)))) {
1140 EINA_LIST_FOREACH(wd->its, l, _it) {
1142 l = eina_list_next(l);
1144 return eina_list_data_get(l);
1153 * Move to the previous Image Slider item
1155 * @param obj The Image Slider object
1157 * @ingroup Imageslider
1160 elm_imageslider_prev(Evas_Object * obj)
1162 ELM_CHECK_WIDTYPE(obj, widtype);
1165 if (!obj || (!(wd = elm_widget_data_get(obj)))) {
1169 if (wd->ani_lock) return;
1171 _imageslider_obj_move(wd, -1);
1176 * Move to the next Image Slider item
1178 * @param obj The Image Slider object
1180 * @ingroup Imageslider
1183 elm_imageslider_next(Evas_Object * obj)
1185 ELM_CHECK_WIDTYPE(obj, widtype);
1188 if (!obj || (!(wd = elm_widget_data_get(obj)))) {
1192 if (wd->ani_lock) return;
1194 _imageslider_obj_move(wd, 1);