3 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
7 #include <Elementary.h>
11 * @defgroup Imageslider Imageslider
15 typedef struct _Widget_Data Widget_Data;
17 #define ANI_STEP (14 * elm_scale_get())
18 #define ANI_TIME (0.005)
19 #define ANI_TIME_MSEC (12)
20 #define FLICK_TIME_MAX (200)
21 #define FLICK_WIDTH_MIN (elm_finger_size_get() >> 2)
23 #define STEP_WEIGHT_DEF (1)
24 #define STEP_WEIGHT_MAX (2)
25 #define STEP_WEIGHT_MIN (0)
26 #define MOVING_IMAGE_SIZE (128)
27 #define MAX_ZOOM_SIZE (6)
28 #define INTERVAL_WIDTH (15)
29 #define MULTITOUCHDEVICE (11)
38 struct _Imageslider_Item
41 const char *photo_file;
42 void (*func)(void *data, Evas_Object *obj, void *event_info);
44 Evas_Coord x, y, w, h;
45 Evas_Coord ox, oy, ow, oh;
51 Evas_Object *ly[BLOCK_MAX];
55 Evas_Coord x, y, w, h;
58 Evas_Coord_Point down_pos;
63 unsigned int timestamp;
69 Eina_Bool on_zoom : 1;
70 Eina_Bool on_hold : 1;
72 int mdx, mdy, mmx, mmy;
78 static const char *widtype = NULL;
79 static void _del_hook(Evas_Object *obj);
80 static void _theme_hook(Evas_Object *obj);
81 static void _sizing_eval(Evas_Object *obj);
82 static void _imageslider_del_all(Widget_Data *wd);
83 static void _imageslider_move(void *data,Evas *e, Evas_Object *obj, void *event_info);
84 static void _imageslider_resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
85 //static void _imageslider_show(Evas_Object *obj);
86 //static void _imageslider_hide(Evas_Object *obj);
87 static void _imageslider_show(void * data, Evas * e, Evas_Object * obj, void * event_info);
88 static void _imageslider_hide(void * data, Evas * e, Evas_Object * obj, void * event_info);
89 static void _imageslider_update(Widget_Data *wd);
90 static void _imageslider_update_pos(Widget_Data *wd, Evas_Coord x, Evas_Coord y, Evas_Coord w);
91 static void _imageslider_update_center_pos(Widget_Data *wd, Evas_Coord x, Evas_Coord my, Evas_Coord y, Evas_Coord w);
92 static Evas_Object *_imageslider_add_obj(Widget_Data *wd);
93 static void _imageslider_obj_shift(Widget_Data *wd, Eina_Bool left);
94 static void _imageslider_obj_move(Widget_Data *wd, Evas_Coord step);
95 static int _icon_to_image(void *data);
96 static int _check_drag(int state, void *data);
97 static void _check_zoom(void *data);
98 static void _anim(Widget_Data *wd);
99 static int _timer_cb(void *data);
100 static void ev_imageslider_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
101 static void ev_imageslider_up_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
102 static void ev_imageslider_move_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
104 static void _del_hook(Evas_Object * obj)
108 wd = elm_widget_data_get(obj);
112 for (i = 0; i < BLOCK_MAX; i++) {
113 evas_object_del(wd->ly[i]);
117 eina_list_free(wd->its);
125 static void _theme_hook(Evas_Object * obj)
129 wd = elm_widget_data_get(obj);
131 if (!wd || !wd->ly ) {
135 for (i=0; i < BLOCK_MAX; i++) {
136 wd->ly[i] = elm_layout_add(obj);
137 _elm_theme_object_set(obj, wd->ly[i], "imageslider", "base", "default");
138 elm_widget_resize_object_set(obj, wd->ly[i]);
139 evas_object_show(wd->ly[i]);
146 static void _sizing_eval(Evas_Object * obj)
149 Widget_Data *wd = elm_widget_data_get(obj);
155 e = evas_object_evas_get(wd->obj);
157 _imageslider_move(obj, e, obj, NULL);
158 _imageslider_resize(obj, e, obj, NULL);
162 static void _imageslider_move(void * data, Evas * e, Evas_Object * obj, void * event_info)
171 wd = elm_widget_data_get((Evas_Object *) data);
176 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
179 evas_object_move(wd->clip, x, y);
181 _imageslider_update_pos(wd, wd->x, wd->y, wd->w);
185 static void _imageslider_resize(void * data, Evas * e, Evas_Object * obj, void * event_info)
195 wd = elm_widget_data_get((Evas_Object *) data);
196 if (!wd || !wd->ly) {
200 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
201 fprintf( stderr, "%d %d -resize\n" , w, h );
205 for (i = 0; i < BLOCK_MAX; i++) {
206 evas_object_resize(wd->ly[i], w, h);
209 evas_object_resize(wd->clip, w, h);
211 _imageslider_update_pos(wd, wd->x, wd->y, wd->w);
216 //static void _imageslider_show(Evas_Object * obj)
217 static void _imageslider_show(void *data, Evas *e, Evas_Object * obj, void *event_info)
225 wd = elm_widget_data_get((Evas_Object *) data);
230 evas_object_show(wd->clip);
233 //static void _imageslider_hide(Evas_Object *obj)
234 static void _imageslider_hide(void *data, Evas *e, Evas_Object *obj, void *event_info)
242 wd = elm_widget_data_get((Evas_Object *) data);
246 evas_object_hide(wd->clip);
249 static void _imageslider_del_all(Widget_Data * wd)
257 for (i = 0; i < BLOCK_MAX; i++) {
258 evas_object_del(wd->ly[i]);
262 static void _imageslider_update_pos(Widget_Data * wd, Evas_Coord x, Evas_Coord y, Evas_Coord w)
264 evas_object_move(wd->ly[BLOCK_LEFT], x - (w + INTERVAL_WIDTH), y);
265 evas_object_move(wd->ly[BLOCK_CENTER], x, y);
266 evas_object_move(wd->ly[BLOCK_RIGHT], x + (w + INTERVAL_WIDTH), y);
267 evas_render_idle_flush(evas_object_evas_get(wd->obj));
270 static void _imageslider_update_center_pos(Widget_Data * wd, Evas_Coord x, Evas_Coord my, Evas_Coord y, Evas_Coord w)
273 Evas_Coord ix, iy, iw, ih;
275 eo = edje_object_part_swallow_get(elm_layout_edje_get(wd->ly[BLOCK_CENTER]), "swl.photo");
276 evas_object_geometry_get(eo, &ix, &iy, &iw, &ih);
278 if ((ix > 0) || (ix + iw < wd->w)) {
279 edje_object_signal_emit(elm_layout_edje_get(wd->ly[BLOCK_CENTER]), "block.on", "block");
281 // evas_event_feed_mouse_cancel(evas_object_evas_get(wd->obj), NULL, NULL);
282 // evas_event_feed_mouse_down(evas_object_evas_get(wd->obj), 1, EVAS_BUTTON_NONE, NULL, NULL);
284 _imageslider_update_pos(wd, x, y, w);
285 wd->on_zoom = EINA_FALSE;
289 static Evas_Object *_imageslider_add_obj(Widget_Data *wd)
292 eo = elm_layout_add(wd->obj);
293 elm_layout_theme_set(eo, "imageslider", "base", "default");
294 elm_widget_resize_object_set(wd->obj, eo);
295 // evas_object_smart_member_add(eo, wd->obj);
296 evas_object_event_callback_add(eo, EVAS_CALLBACK_MOUSE_DOWN, ev_imageslider_down_cb, wd);
297 evas_object_event_callback_add(eo, EVAS_CALLBACK_MOUSE_UP, ev_imageslider_up_cb, wd);
298 evas_object_event_callback_add(eo, EVAS_CALLBACK_MOUSE_MOVE, ev_imageslider_move_cb, wd);
299 evas_object_resize(eo, wd->w, wd->h);
300 evas_object_move(eo, wd->w + INTERVAL_WIDTH, wd->y);
301 evas_object_clip_set(eo, wd->clip);
302 evas_object_show(eo);
307 static void _imageslider_obj_shift(Widget_Data *wd, Eina_Bool left)
310 if (wd->ly[BLOCK_LEFT]) {
311 evas_object_del(wd->ly[BLOCK_LEFT]);
312 wd->ly[BLOCK_LEFT] = NULL;
315 wd->ly[BLOCK_LEFT] = wd->ly[BLOCK_CENTER];
316 wd->ly[BLOCK_CENTER]= wd->ly[BLOCK_RIGHT];
317 wd->ly[BLOCK_RIGHT] = _imageslider_add_obj(wd);
319 if (wd->ly[BLOCK_RIGHT]) {
320 evas_object_del(wd->ly[BLOCK_RIGHT]);
321 wd->ly[BLOCK_RIGHT] = NULL;
324 wd->ly[BLOCK_RIGHT]= wd->ly[BLOCK_CENTER];
325 wd->ly[BLOCK_CENTER]= wd->ly[BLOCK_LEFT];
326 wd->ly[BLOCK_LEFT]= _imageslider_add_obj(wd);
331 static void _imageslider_obj_move(Widget_Data * wd, Evas_Coord step)
334 wd->cur = eina_list_next(wd->cur);
335 if (wd->cur == NULL) {
336 wd->cur = eina_list_last(wd->its);
339 wd->step = -ANI_STEP;
341 _imageslider_obj_shift(wd, 0);
344 } else if (step < 0) {
345 wd->cur = eina_list_prev(wd->cur);
346 if (wd->cur == NULL) {
348 wd->step = -ANI_STEP;
352 _imageslider_obj_shift(wd, 1);
356 if (wd->move_x < 0) wd->step = ANI_STEP;
357 else wd->step = -ANI_STEP;
361 _imageslider_update(wd);
364 static void ev_imageslider_down_cb(void * data, Evas * e, Evas_Object * obj, void * event_info)
366 Widget_Data *wd = data;
367 Evas_Event_Mouse_Down *ev = event_info;
368 Evas_Coord ix, iy, iw, ih;
369 Evas_Object *eo = NULL;
371 if (wd->ani_lock) return;
373 wd->down_pos = ev->canvas;
374 wd->timestamp = ev->timestamp;
375 wd->move_cnt = MOVE_STEP;
377 wd->dx = ev->canvas.x;
378 wd->dy = ev->canvas.y;
379 wd->mx = ev->canvas.x;
380 wd->my = ev->canvas.y;
385 eo = edje_object_part_swallow_get(elm_layout_edje_get(obj), "swl.photo");
386 if (eo) evas_object_geometry_get(eo, &ix, &iy, &iw, &ih);
389 wd->on_zoom = EINA_TRUE;
390 edje_object_signal_emit(elm_layout_edje_get(obj), "block.off", "block");
394 fprintf( stderr, "down!\n" );
398 static void ev_imageslider_up_cb(void * data, Evas * e, Evas_Object * obj, void * event_info)
400 Widget_Data *wd = data;
401 Evas_Event_Mouse_Up *ev = event_info;
405 if (wd->ani_lock) return;
409 step = wd->down_pos.x - ev->canvas.x;
410 interval = ev->timestamp - wd->timestamp;
411 if (step == 0 || interval == 0) return;
413 if (interval < FLICK_TIME_MAX) {
414 if (step < FLICK_WIDTH_MIN && step > FLICK_WIDTH_MIN) _imageslider_obj_move(wd, 0);
415 else _imageslider_obj_move(wd, step);
417 step = (wd->x - wd->move_x) << 1;
418 if (step <= wd->w && step >= -(wd->w)) _imageslider_obj_move(wd, 0);
419 else _imageslider_obj_move(wd, step);
425 static void ev_imageslider_move_cb(void * data, Evas * e, Evas_Object * obj, void * event_info)
430 Widget_Data *wd = data;
431 Evas_Event_Mouse_Move *ev = event_info;
432 Elm_Imageslider_Item *it;
434 if (wd->ani_lock) return;
436 if (wd->move_cnt == MOVE_STEP) {
437 if (wd->on_hold == EINA_FALSE) {
441 step = ev->cur.canvas.x - wd->down_pos.x;
442 if (step > 0) idx = BLOCK_LEFT;
443 else idx = BLOCK_RIGHT;
445 wd->move_x = wd->x + ((ev->cur.canvas.x - wd->down_pos.x));
446 wd->move_y = wd->y + ((ev->cur.canvas.y - wd->down_pos.y));
449 _imageslider_update_center_pos(wd, wd->move_x, wd->move_y, wd->y, wd->w);
451 _imageslider_update_pos(wd, wd->move_x, wd->y, wd->w);
455 wd->mx = ev->cur.canvas.x;
456 wd->my = ev->cur.canvas.y;
458 wd->ratio = sqrt((wd->mx -wd->mmx)*(wd->mx -wd->mmx) + (wd->my - wd->mmy)*(wd->my - wd->mmy));
460 eo = edje_object_part_swallow_get(elm_layout_edje_get(obj), "swl.photo");
462 it = eina_list_data_get(wd->cur);
463 if (((it->w * wd->ratio/wd->dratio)/it->ow) < MAX_ZOOM_SIZE ) {
464 edje_object_part_unswallow(elm_layout_edje_get(obj), eo);
465 evas_object_resize(eo, it->w * wd->ratio/wd->dratio, it->h * wd->ratio/wd->dratio);
466 evas_object_size_hint_min_set(eo, it->w * wd->ratio/wd->dratio, it->h * wd->ratio/wd->dratio);
467 edje_object_part_swallow(elm_layout_edje_get(obj), "swl.photo", eo);
478 #if 0 // REMOVED about Multi-touch.
479 static void ev_imageslider_multi_down_cb(void * data, Evas * e, Evas_Object * obj, void * event_info)
481 Evas_Event_Multi_Down *ev = event_info;
482 Widget_Data *wd = data;
484 if (ev->device == MULTITOUCHDEVICE) return;
486 wd->on_hold = EINA_TRUE;
487 wd->mdx = ev->canvas.x;
488 wd->mdy = ev->canvas.y;
489 wd->mmx = ev->canvas.x;
490 wd->mmy = ev->canvas.y;
492 wd->dratio = sqrt((wd->mx - wd->mmx)*(wd->mx - wd->mmx) + (wd->my - wd->mmy)*(wd->my - wd->mmy));
493 wd->ratio = sqrt((wd->mx - wd->mmx)*(wd->mx - wd->mmx)+ (wd->my - wd->mmy)*(wd->my - wd->mmy));
496 wd->on_zoom = EINA_FALSE;
497 edje_object_signal_emit(elm_layout_edje_get(obj), "block.on", "block");
502 static void ev_imageslider_multi_up_cb(void * data, Evas * e, Evas_Object * obj, void * event_info)
504 Evas_Event_Multi_Up *ev = event_info;
505 Widget_Data *wd = data;
506 Elm_Imageslider_Item *it;
508 if (ev->device == MULTITOUCHDEVICE) return;
510 it = eina_list_data_get(wd->cur);
511 it->w = (int)it->w * wd->ratio/wd->dratio;
512 it->h = (int)it->h * wd->ratio/wd->dratio;
514 if (it->w != it->ow) {
515 wd->on_zoom = EINA_TRUE;
516 edje_object_signal_emit(elm_layout_edje_get(obj), "block.off", "block");
519 wd->on_zoom = EINA_FALSE;
522 wd->on_hold = EINA_FALSE;
532 static void ev_imageslider_multi_move_cb(void * data, Evas * e, Evas_Object * obj, void * event_info)
534 Evas_Event_Multi_Move *ev = event_info;
535 Widget_Data *wd = data;
536 Evas_Object *eo = NULL;
537 Elm_Imageslider_Item *it;
539 if (ev->device == MULTITOUCHDEVICE) return;
541 if ((wd->mdx == 0) && (wd->mdy == 0) && (wd->mmx == 0) && (wd->mmy == 0)) {
542 wd->mdx = ev->cur.canvas.x;
543 wd->mdy = ev->cur.canvas.y;
544 wd->mmx = ev->cur.canvas.x;
545 wd->mmy = ev->cur.canvas.y;
547 wd->dratio = sqrt((wd->dx - wd->mdx)*(wd->dx - wd->mdx) + (wd->dy - wd->mdy)*(wd->dy - wd->mdy));
550 wd->mmx = ev->cur.canvas.x;
551 wd->mmy = ev->cur.canvas.y;
552 wd->ratio = sqrt((wd->mx - wd->mmx)*(wd->mx - wd->mmx) + (wd->my - wd->mmy)*(wd->my - wd->mmy));
554 eo = edje_object_part_swallow_get(elm_layout_edje_get(obj), "swl.photo");
557 it = eina_list_data_get(wd->cur);
558 if (((it->w * wd->ratio/wd->dratio)/it->ow) < MAX_ZOOM_SIZE) {
559 edje_object_part_unswallow(elm_layout_edje_get(obj), eo);
560 evas_object_resize(eo, it->w * wd->ratio/wd->dratio, it->h * wd->ratio/wd->dratio);
561 evas_object_size_hint_min_set(eo, it->w * wd->ratio/wd->dratio, it->h * wd->ratio/wd->dratio);
562 edje_object_part_swallow(elm_layout_edje_get(obj), "swl.photo", eo);
567 #endif // about Multi-touch.
569 static inline double time_get(Evas_Coord x, Evas_Coord w)
572 time = (-sin(x / w) + 1) / 500;
574 if (time == 0) time = ANI_TIME;
579 static int _icon_to_image(void *data)
581 Widget_Data *wd = data;
583 _imageslider_update(wd);
588 static int _check_drag(int state, void *data)
590 Widget_Data *wd = data;
591 Elm_Imageslider_Item *it;
592 Evas_Coord ix, iy, iw, ih;
594 Eina_List *l[BLOCK_MAX];
595 Evas_Object *eo = NULL;
596 l[BLOCK_LEFT] = eina_list_prev(wd->cur);
597 l[BLOCK_CENTER] = wd->cur;
598 l[BLOCK_RIGHT] = eina_list_next(wd->cur);
600 it = eina_list_data_get(l[state]);
602 eo = edje_object_part_swallow_get(elm_layout_edje_get(wd->ly[state]), "swl.photo");
603 if (eo) evas_object_geometry_get(eo, &ix, &iy, &iw, &ih);
604 evas_object_geometry_get(eo, &ix, &iy, &iw, &ih);
605 edje_object_part_drag_value_get(elm_layout_edje_get(wd->ly[state]), "swl.photo", &dx, &dy);
607 if ((iw != wd->w) || ((dx != 0 ) || (dy != 0 ))) {
609 evas_object_del(wd->ly[state]);
610 wd->ly[state] = NULL;
612 wd->ly[state] = _imageslider_add_obj(wd);
621 static void _check_zoom(void *data)
623 Widget_Data *wd = data;
624 Elm_Imageslider_Item *it;
625 Evas_Coord ix, iy, iw, ih;
627 Evas_Object *eo = NULL;
629 it = eina_list_data_get(wd->cur);
631 eo = edje_object_part_swallow_get(elm_layout_edje_get(wd->ly[BLOCK_CENTER]), "swl.photo");
632 if (eo) evas_object_geometry_get(eo, &ix, &iy, &iw, &ih);
633 evas_object_geometry_get(eo, &ix, &iy, &iw, &ih);
634 edje_object_part_drag_value_get(elm_layout_edje_get(wd->ly[BLOCK_CENTER]), "swl.photo", &dx, &dy);
636 if ((iw != wd->w) || ((dx != 0) || (dy != 0))) {
637 wd->on_zoom = EINA_TRUE;
638 edje_object_signal_emit(elm_layout_edje_get(wd->ly[BLOCK_CENTER]), "block.off", "block");
641 wd->on_zoom = EINA_FALSE;
642 edje_object_signal_emit(elm_layout_edje_get(wd->ly[BLOCK_CENTER]), "block.on", "block");
648 static int _timer_cb(void *data)
651 Elm_Imageslider_Item *it;
656 if (wd->ani_lock == 0 ) return 0;
658 gettimeofday(&tv, NULL);
660 t = (tv.tv_sec - wd->tv.tv_sec) * 1000 + (tv.tv_usec - wd->tv.tv_usec) / 1000;
661 gettimeofday(&wd->tv, NULL);
663 t = t / ANI_TIME_MSEC;
664 if (t <= STEP_WEIGHT_MIN) t = STEP_WEIGHT_DEF;
665 else if (t > STEP_WEIGHT_MAX) t = STEP_WEIGHT_MAX;
667 wd->move_x += (wd->step) * t;
669 if (wd->step < 0 && wd->move_x < wd->x) wd->move_x = wd->x;
670 else if (wd->step > 0 && wd->move_x > wd->x) wd->move_x = wd->x;
672 _imageslider_update_pos(wd, wd->move_x, wd->y, wd->w);
674 if (wd->move_x == wd->x) {
677 it = eina_list_data_get(wd->cur);
678 if (it->func) it->func(it->data, wd->obj, it);
681 it = eina_list_data_get(wd->cur);
682 evas_object_smart_callback_call(wd->obj, "changed", it);
685 ret = _check_drag(BLOCK_LEFT, wd);
686 ret = _check_drag(BLOCK_RIGHT, wd);
689 ecore_idler_add(_icon_to_image, wd);
697 static void _anim(Widget_Data *wd)
701 if (wd->x == wd->move_x) {
702 _imageslider_update_pos(wd, wd->move_x, wd->y, wd->w);
709 gettimeofday(&wd->tv, NULL);
710 ecore_timer_add(ANI_TIME, _timer_cb, wd);
713 static void _imageslider_update(Widget_Data *wd)
716 Eina_List *l[BLOCK_MAX];
717 Elm_Imageslider_Item *it;
725 _imageslider_del_all(wd);
729 l[BLOCK_LEFT] = eina_list_prev(wd->cur);
730 l[BLOCK_CENTER] = wd->cur;
731 l[BLOCK_RIGHT] = eina_list_next(wd->cur);
733 for (i = 0; i < BLOCK_MAX; i++) {
734 eo = edje_object_part_swallow_get(elm_layout_edje_get(wd->ly[i]), "swl.photo");
736 elm_layout_content_set(wd->ly[i], "swl.photo", NULL);
739 it = eina_list_data_get(l[i]);
743 eo = elm_image_add(wd->obj);
744 elm_layout_content_set(wd->ly[i], "swl.photo", eo);
745 elm_image_prescale_set(eo, wd->w);
746 elm_image_file_set(eo, it->photo_file, NULL);
747 elm_image_object_size_get(eo, &it->w, &it->h);
748 evas_object_geometry_get(eo, &it->ox, &it->oy, &it->ow, &it->oh);
753 if (wd->moving != it->moving) {
754 it->moving = wd->moving;
756 elm_image_prescale_set(eo, MOVING_IMAGE_SIZE);
758 elm_image_prescale_set(eo, it->w > it->h ? it->w : it->h);
770 * Add imageslider widget
772 * @param obj The parent object
773 * @return The new object or NULL if it cannot be created
775 * @ingroup Imageslider
778 elm_imageslider_add(Evas_Object * parent)
781 Evas_Object *obj = NULL;
782 Widget_Data *wd = NULL;
789 wd = ELM_NEW(Widget_Data);
790 e = evas_object_evas_get(parent);
795 obj = elm_widget_add(e);
796 ELM_SET_WIDTYPE(widtype, "imageslider");
797 elm_widget_type_set(obj, "imageslider");
798 elm_widget_sub_object_add(parent, obj);
799 elm_widget_data_set(obj, wd);
800 //wd->parent = parent;
801 elm_widget_del_hook_set(obj, _del_hook);
802 //elm_widget_theme_hook_set(obj, _theme_hook);
804 wd->clip = evas_object_rectangle_add(e);
806 for (i=0; i < BLOCK_MAX; i++) {
807 wd->ly[i] = elm_layout_add(obj);
808 elm_layout_theme_set(wd->ly[i], "imageslider", "base", "default");
809 elm_widget_resize_object_set(obj, wd->ly[i]);
810 evas_object_smart_member_add(wd->ly[i], obj);
811 evas_object_event_callback_add(wd->ly[i], EVAS_CALLBACK_MOUSE_DOWN, ev_imageslider_down_cb, wd);
812 evas_object_event_callback_add(wd->ly[i], EVAS_CALLBACK_MOUSE_UP, ev_imageslider_up_cb, wd);
813 evas_object_event_callback_add(wd->ly[i], EVAS_CALLBACK_MOUSE_MOVE, ev_imageslider_move_cb, wd);
814 evas_object_clip_set(wd->ly[i], wd->clip);
815 evas_object_show(wd->ly[i]);
820 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _imageslider_resize, obj);
821 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _imageslider_move, obj);
822 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _imageslider_show, obj);
823 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _imageslider_hide, obj);
832 * Append imageslider item
834 * @param obj The photoslider object
835 * @param photo_file photo file path
836 * @param func callback function
837 * @param data callback data
838 * @return The photoslider item handle or NULL
840 * @ingroup Imageslider
842 EAPI Elm_Imageslider_Item *
843 elm_imageslider_item_append(Evas_Object * obj, const char * photo_file, Elm_Imageslider_Cb func, void * data)
845 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
847 Elm_Imageslider_Item *it;
849 if (!obj || !(wd = elm_widget_data_get(obj))) {
853 it = (Elm_Imageslider_Item *)calloc(1, sizeof(Elm_Imageslider_Item));
854 if (!it) return NULL;
855 it->photo_file = eina_stringshare_add(photo_file);
859 wd->its = eina_list_append(wd->its, it);
861 if (!wd->cur) wd->cur = wd->its;
863 _imageslider_update(wd);
870 * Prepend imageslider item
872 * @param obj The imageslider object
873 * @param photo_file photo file path
874 * @param func callback function
875 * @param data callback data
876 * @return The imageslider item handle or NULL
878 * @ingroup Imageslider
880 EAPI Elm_Imageslider_Item *
881 elm_imageslider_item_prepend(Evas_Object * obj, const char * photo_file, Elm_Imageslider_Cb func, void * data)
883 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
885 Elm_Imageslider_Item *it;
887 if (!obj || !(wd = elm_widget_data_get(obj))) {
891 it = (Elm_Imageslider_Item *)calloc(1, sizeof(Elm_Imageslider_Item));
892 it->photo_file = eina_stringshare_add(photo_file);
896 wd->its = eina_list_prepend(wd->its, it );
898 if (!wd->cur) wd->cur = wd->its;
900 _imageslider_update(wd);
908 * Delete imageslider item
910 * @param it imageslider item handle
912 * @ingroup Imageslider
915 elm_imageslider_item_del(Elm_Imageslider_Item * it)
918 Elm_Imageslider_Item *_it;
921 if (!it || !(wd = elm_widget_data_get(it->obj))) {
925 EINA_LIST_FOREACH(wd->its, l, _it) {
927 if (l == wd->cur) wd->cur = eina_list_prev(wd->cur);
928 wd->its = eina_list_remove(wd->its, it);
929 if (!wd->cur) wd->cur = wd->its;
934 _imageslider_update(wd);
942 * @param obj The imageslider object
943 * @return The selected item or NULL
945 * @ingroup Imageslider
947 EAPI Elm_Imageslider_Item *
948 elm_imageslider_selected_item_get(Evas_Object * obj)
950 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
953 if (!obj || (!(wd = elm_widget_data_get(obj)))) {
957 if (!wd->cur) return NULL;
959 return eina_list_data_get(wd->cur);
963 * Get whether item is selected or not
966 * @return EINA_TRUE or EINA_FALSE
968 * @ingroup Imageslider
971 elm_imageslider_item_selected_get(Elm_Imageslider_Item * it)
975 if (!it || !it->obj || (!(wd = elm_widget_data_get(it->obj)))) {
979 if (!wd->cur) return EINA_FALSE;
981 if (eina_list_data_get(wd->cur) == it ) return EINA_TRUE;
982 else return EINA_FALSE;
991 * @ingroup Imageslider
994 elm_imageslider_item_selected_set(Elm_Imageslider_Item * it)
998 Elm_Imageslider_Item *_it;
1002 if (!it || !it->obj || (!(wd = elm_widget_data_get(it->obj)))) {
1006 EINA_LIST_FOREACH(wd->its, l, _it) {
1012 for (i = 0; i < BLOCK_MAX; i++) {
1013 eo = edje_object_part_swallow_get(elm_layout_edje_get(wd->ly[i]), "swl.photo");
1015 elm_layout_content_set(wd->ly[i], "swl.photo", NULL);
1016 evas_object_del(eo);
1020 _imageslider_update(wd);
1026 * Get photo file path of give item
1029 * @return The photo file path or NULL;
1031 * @ingroup Imageslider
1034 elm_imageslider_item_photo_file_get(Elm_Imageslider_Item * it)
1040 return it->photo_file;
1045 * Get the previous imageslider item
1048 * @return The previous item or NULL
1050 * @ingroup Imageslider
1052 EAPI Elm_Imageslider_Item *
1053 elm_imageslider_item_prev(Elm_Imageslider_Item * it)
1056 Elm_Imageslider_Item *_it;
1059 if (!it || (!(wd = elm_widget_data_get(it->obj)))) {
1063 EINA_LIST_FOREACH(wd->its, l, _it) {
1065 l = eina_list_prev(l);
1067 return eina_list_data_get(l);
1076 * Get the next imageslider item
1079 * @return The next item or NULL
1081 * @ingroup Imageslider
1083 EAPI Elm_Imageslider_Item *
1084 elm_imageslider_item_next(Elm_Imageslider_Item * it)
1087 Elm_Imageslider_Item *_it;
1090 if (!it || (!(wd = elm_widget_data_get(it->obj)))) {
1094 EINA_LIST_FOREACH(wd->its, l, _it) {
1096 l = eina_list_next(l);
1098 return eina_list_data_get(l);
1107 * Move to the previous imageslider item
1109 * @param obj imageslider object
1111 * @ingroup Imageslider
1114 elm_imageslider_prev(Evas_Object * obj)
1116 ELM_CHECK_WIDTYPE(obj, widtype);
1119 if (!obj || (!(wd = elm_widget_data_get(obj)))) {
1123 if (wd->ani_lock) return;
1125 _imageslider_obj_move(wd, -1);
1130 * Move to the next imageslider item
1132 * @param obj imageslider object
1134 * @ingroup Imageslider
1137 elm_imageslider_next(Evas_Object * obj)
1139 ELM_CHECK_WIDTYPE(obj, widtype);
1142 if (!obj || (!(wd = elm_widget_data_get(obj)))) {
1146 if (wd->ani_lock) return;
1148 _imageslider_obj_move(wd, 1);