3 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
6 * @file elm_imageslider.c
7 * @brief This is the implementation file for Image Slider Elementary.
17 #include <Elementary.h>
19 //#include "winset_util.h"
21 /*********************************************************
22 Image Slider Elementary
23 ********************************************************/
24 ///////////////////////////////////////////////////////////////////////////////////////////////////
25 // Definitions of "elm_imageslider"
26 //-------------------------------------------------------------------------------------------------
27 #define LAYOUT_FILE PREFIX"/"
29 #define ANI_STEP (14 * elm_scale_get())
30 #define ANI_TIME (0.005)
31 #define ANI_TIME_MSEC (12)
32 #define FLICK_TIME_MAX (200)
33 #define FLICK_WIDTH_MIN (elm_finger_size_get() >> 2)
35 #define STEP_WEIGHT_DEF (1)
36 #define STEP_WEIGHT_MAX (2)
37 #define STEP_WEIGHT_MIN (0)
38 #define MOVING_IMAGE_SIZE (128)
39 #define MAX_ZOOM_SIZE (6)
40 #define INTERVAL_WIDTH (15)
41 #define MULTITOUCHDEVICE (11)
50 struct _Imageslider_Item
53 const char *photo_file;
54 void (*func)(void *data, Evas_Object *obj, void *event_info);
56 Evas_Coord x, y, w, h;
57 Evas_Coord ox, oy, ow, oh;
61 typedef struct _Widget_Data Widget_Data;
64 Evas_Object *ly[BLOCK_MAX];
68 Evas_Coord x, y, w, h;
71 Evas_Coord_Point down_pos;
76 unsigned int timestamp;
82 Eina_Bool on_zoom : 1;
83 Eina_Bool on_hold : 1;
85 int mdx, mdy, mmx, mmy;
91 ///////////////////////////////////////////////////////////////////////////////////////////////////
92 // Declare the global variables, registers, and Internal Funntions
93 //-------------------------------------------------------------------------------------------------
94 static const char *widtype = NULL;
95 static Evas_Smart *_imageslider_smart_get(void);
96 static Evas_Object *_imageslider_new(Evas_Object *paren);
97 //static void _imageslider_add(Evas_Object *obj);
98 static void _del_hook(Evas_Object *obj);
99 static void _theme_hook(Evas_Object *obj);
100 static void _sizing_eval(Evas_Object *obj);
101 //static void _imageslider_del(Evas_Object *obj);
102 static void _imageslider_del_all(Widget_Data *wd);
103 //static void _imageslider_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y);
104 //static void _imageslider_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h);
105 static void _imageslider_move(void *data,Evas *e, Evas_Object *obj, void *event_info);
106 static void _imageslider_resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
108 static void _imageslider_show(Evas_Object *obj);
109 static void _imageslider_hide(Evas_Object *obj);
110 static void _imageslider_color_set(Evas_Object *obj, int r, int g, int b, int a);
111 static void _imageslider_clip_set(Evas_Object *obj, Evas_Object *clip);
112 static void _imageslider_clip_unset(Evas_Object *obj);
114 static void _imageslider_update(Widget_Data *wd);
115 static void _imageslider_update_pos(Widget_Data *wd, Evas_Coord x, Evas_Coord y, Evas_Coord w);
116 static void _imageslider_update_center_pos(Widget_Data *wd, Evas_Coord x, Evas_Coord my, Evas_Coord y, Evas_Coord w);
117 static Evas_Object *_imageslider_add_obj(Widget_Data *wd);
118 static void _imageslider_obj_shift(Widget_Data *wd, Eina_Bool left);
119 static void _imageslider_obj_move(Widget_Data *wd, Evas_Coord step);
121 static int _icon_to_image(void *data);
122 static int _check_drag(int state, void *data);
123 static void _check_zoom(void *data);
124 static void _anim(Widget_Data *wd);
125 ///////////////////////////////////////////////////////////////////////////////////////////////////
126 // Declare the Callback Funntions
127 //-------------------------------------------------------------------------------------------------
128 static int _timer_cb(void *data);
129 static void ev_imageslider_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
130 static void ev_imageslider_up_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
131 static void ev_imageslider_move_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
132 //static void ev_imageslider_multi_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
133 //static void ev_imageslider_multi_up_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
134 //static void ev_imageslider_multi_move_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
136 /*==========================================================================
137 * Internal function definitions of Image Slider Elementary
138 *===========================================================================*/
140 static void _imageslider_add(Evas_Object * obj)
145 //wd = (Widget_Data *) calloc(1, sizeof(Widget_Data));
146 wd = elm_widget_data_get(obj);
151 //evas_object_smart_data_set(obj, wd);
152 wd->clip = evas_object_rectangle_add(evas_object_evas_get(obj));
154 for (i=0; i < BLOCK_MAX; i++) {
155 wd->ly[i] = elm_layout_add(obj);
156 // elm_object_style_set(obj, "elm/imageslider");
157 // elm_layout_file_set(wd->ly[i], get_edj_name(), "elm/imageslider");
158 evas_object_smart_member_add(wd->ly[i], obj);
159 evas_object_event_callback_add(wd->ly[i], EVAS_CALLBACK_MOUSE_DOWN, ev_imageslider_down_cb, wd);
160 evas_object_event_callback_add(wd->ly[i], EVAS_CALLBACK_MOUSE_UP, ev_imageslider_up_cb, wd);
161 evas_object_event_callback_add(wd->ly[i], EVAS_CALLBACK_MOUSE_MOVE, ev_imageslider_move_cb, wd);
162 evas_object_clip_set(wd->ly[i], wd->clip);
163 evas_object_show(wd->ly[i]);
172 static void _del_hook(Evas_Object * obj)
176 wd = elm_widget_data_get(obj);
180 for (i = 0; i < BLOCK_MAX; i++) {
181 evas_object_del(wd->ly[i]);
185 eina_list_free(wd->its);
193 static void _theme_hook(Evas_Object * obj)
197 wd = elm_widget_data_get(obj);
199 if (!wd || !wd->ly ) {
203 for (i=0; i < BLOCK_MAX; i++) {
204 wd->ly[i] = elm_layout_add(obj);
205 _elm_theme_object_set(obj, wd->ly[i], "imageslider", "base", "default");
206 elm_widget_resize_object_set(obj, wd->ly[i]);
207 evas_object_show(wd->ly[i]);
214 static void _sizing_eval(Evas_Object * obj)
217 Widget_Data *wd = elm_widget_data_get(obj);
223 e = evas_object_evas_get(wd->obj);
225 _imageslider_move(obj, e, obj, NULL);
226 _imageslider_resize(obj, e, obj, NULL);
231 static void _imageslider_del(Evas_Object * obj)
234 wd = evas_object_smart_data_get(obj);
235 _imageslider_del_all(wd);
239 eina_list_free(wd->its);
247 static void _imageslider_move(Evas_Object * obj, Evas_Coord x, Evas_Coord y)
250 //wd = evas_object_smart_data_get(obj);
251 wd = elm_widget_data_get(obj);
260 evas_object_move(wd->clip, x, y);
262 _imageslider_update_pos(wd, wd->x, wd->y, wd->w);
266 static void _imageslider_resize(Evas_Object * obj, Evas_Coord w, Evas_Coord h)
270 //wd = evas_object_smart_data_get(obj);
271 wd = elm_widget_data_get(obj);
281 for (i = 0; i < BLOCK_MAX; i++) {
282 evas_object_resize(wd->ly[i], w, h);
285 evas_object_resize(wd->clip, w, h);
287 _imageslider_update_pos(wd, wd->x, wd->y, wd->w);
292 static void _imageslider_move(void * data, Evas * e, Evas_Object * obj, void * event_info)
301 //wd = evas_object_smart_data_get(obj);
302 wd = elm_widget_data_get((Evas_Object *) data);
308 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
311 evas_object_move(wd->clip, x, y);
313 _imageslider_update_pos(wd, wd->x, wd->y, wd->w);
317 static void _imageslider_resize(void * data, Evas * e, Evas_Object * obj, void * event_info)
327 //wd = evas_object_smart_data_get(obj);
328 wd = elm_widget_data_get((Evas_Object *) data);
329 if (!wd || !wd->ly) {
334 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
335 fprintf( stderr, "%d %d -resize\n" , w, h );
339 for (i = 0; i < BLOCK_MAX; i++) {
340 evas_object_resize(wd->ly[i], w, h);
343 evas_object_resize(wd->clip, w, h);
345 _imageslider_update_pos(wd, wd->x, wd->y, wd->w);
350 static void _imageslider_show(Evas_Object * obj)
353 //wd = evas_object_smart_data_get(obj);
354 wd = elm_widget_data_get(obj);
360 evas_object_show(wd->clip);
363 static void _imageslider_hide(Evas_Object *obj)
366 //wd = evas_object_smart_data_get(obj);
367 wd = elm_widget_data_get(obj);
374 evas_object_hide(wd->clip);
378 static void _imageslider_color_set(Evas_Object * obj, int r, int g, int b, int a)
382 //wd = evas_object_smart_data_get(obj);
383 wd = elm_widget_data_get(obj);
390 evas_object_color_set(wd->clip, r, g, b, a);
392 for (i = 0; i < BLOCK_MAX; i++) {
393 evas_object_color_set(wd->ly[i], r, g, b, a);
397 static void _imageslider_clip_set(Evas_Object * obj, Evas_Object * clip)
400 //wd = evas_object_smart_data_get(obj);
401 wd = elm_widget_data_get(obj);
408 evas_object_clip_set(wd->clip, clip);
411 static void _imageslider_clip_unset(Evas_Object * obj)
414 //wd = evas_object_smart_data_get(obj);
415 wd = elm_widget_data_get(obj);
422 evas_object_clip_unset(wd->obj);
427 static Evas_Smart *_imageslider_smart_get(void)
429 static Evas_Smart *s = NULL;
430 static Evas_Smart_Class sc = EVAS_SMART_CLASS_INIT_NAME_VERSION("Elm_imageslider");
433 sc.add = _imageslider_add;
434 sc.del = _imageslider_del;
435 sc.move = _imageslider_move;
436 sc.resize = _imageslider_resize;
437 sc.show = _imageslider_show;
438 sc.hide = _imageslider_hide;
439 sc.color_set = _imageslider_color_set;
440 sc.clip_set = _imageslider_clip_set;
441 sc.clip_unset = _imageslider_clip_unset;
442 s = evas_smart_class_new(&sc);
449 static Evas_Object *_imageslider_new(Evas_Object *parent)
453 e = evas_object_evas_get(parent);
459 obj = evas_object_smart_add(e, _imageslider_smart_get());
466 static void _imageslider_del_all(Widget_Data * wd)
471 for (i = 0; i < BLOCK_MAX; i++) {
472 evas_object_del(wd->ly[i]);
476 static void _imageslider_update_pos(Widget_Data * wd, Evas_Coord x, Evas_Coord y, Evas_Coord w)
478 evas_object_move(wd->ly[BLOCK_LEFT], x - (w + INTERVAL_WIDTH), y);
479 evas_object_move(wd->ly[BLOCK_CENTER], x, y);
480 evas_object_move(wd->ly[BLOCK_RIGHT], x + (w + INTERVAL_WIDTH), y);
481 evas_render_idle_flush(evas_object_evas_get(wd->obj));
484 static void _imageslider_update_center_pos(Widget_Data * wd, Evas_Coord x, Evas_Coord my, Evas_Coord y, Evas_Coord w)
487 Evas_Coord ix, iy, iw, ih;
489 eo = edje_object_part_swallow_get(elm_layout_edje_get(wd->ly[BLOCK_CENTER]), "swl.photo");
490 evas_object_geometry_get(eo, &ix, &iy, &iw, &ih);
492 if ((ix > 0) || (ix + iw < wd->w)) {
493 edje_object_signal_emit(elm_layout_edje_get(wd->ly[BLOCK_CENTER]), "block.on", "block");
495 // evas_event_feed_mouse_cancel(evas_object_evas_get(wd->obj), NULL, NULL);
496 // evas_event_feed_mouse_down(evas_object_evas_get(wd->obj), 1, EVAS_BUTTON_NONE, NULL, NULL);
498 _imageslider_update_pos(wd, x, y, w);
499 wd->on_zoom = EINA_FALSE;
503 static Evas_Object *_imageslider_add_obj(Widget_Data *wd)
506 eo = elm_layout_add(wd->obj);
507 //_elm_theme_object_set(wd->obj, eo, "imageslider", "base", elm_widget_style_get(wd->obj));
508 elm_layout_theme_set(eo, "imageslider", "base", "default");
509 elm_widget_resize_object_set(wd->obj, eo);
510 // elm_object_style_set(wd->obj, , "elm/imageslider");
511 // elm_layout_file_set(eo, get_edj_name(), "elm/imageslider");
512 // evas_object_smart_member_add(eo, wd->obj);
513 evas_object_event_callback_add(eo, EVAS_CALLBACK_MOUSE_DOWN, ev_imageslider_down_cb, wd);
514 evas_object_event_callback_add(eo, EVAS_CALLBACK_MOUSE_UP, ev_imageslider_up_cb, wd);
515 evas_object_event_callback_add(eo, EVAS_CALLBACK_MOUSE_MOVE, ev_imageslider_move_cb, wd);
516 evas_object_resize(eo, wd->w, wd->h);
517 evas_object_move(eo, wd->w + INTERVAL_WIDTH, wd->y);
518 evas_object_clip_set(eo, wd->clip);
519 evas_object_show(eo);
524 static void _imageslider_obj_shift(Widget_Data *wd, Eina_Bool left)
527 if (wd->ly[BLOCK_LEFT]) {
528 evas_object_del(wd->ly[BLOCK_LEFT]);
529 wd->ly[BLOCK_LEFT] = NULL;
532 wd->ly[BLOCK_LEFT] = wd->ly[BLOCK_CENTER];
533 wd->ly[BLOCK_CENTER]= wd->ly[BLOCK_RIGHT];
534 wd->ly[BLOCK_RIGHT] = _imageslider_add_obj(wd);
536 if (wd->ly[BLOCK_RIGHT]) {
537 evas_object_del(wd->ly[BLOCK_RIGHT]);
538 wd->ly[BLOCK_RIGHT] = NULL;
541 wd->ly[BLOCK_RIGHT]= wd->ly[BLOCK_CENTER];
542 wd->ly[BLOCK_CENTER]= wd->ly[BLOCK_LEFT];
543 wd->ly[BLOCK_LEFT]= _imageslider_add_obj(wd);
548 static void _imageslider_obj_move(Widget_Data * wd, Evas_Coord step)
551 wd->cur = eina_list_next(wd->cur);
552 if (wd->cur == NULL) {
553 wd->cur = eina_list_last(wd->its);
556 wd->step = -ANI_STEP;
558 _imageslider_obj_shift(wd, 0);
561 } else if (step < 0) {
562 wd->cur = eina_list_prev(wd->cur);
563 if (wd->cur == NULL) {
565 wd->step = -ANI_STEP;
569 _imageslider_obj_shift(wd, 1);
573 if (wd->move_x < 0) wd->step = ANI_STEP;
574 else wd->step = -ANI_STEP;
578 _imageslider_update(wd);
582 /*==========================================================================
583 * Callback function definitions of Image Slider Elementary
584 *===========================================================================*/
585 static void ev_imageslider_down_cb(void * data, Evas * e, Evas_Object * obj, void * event_info)
587 Widget_Data *wd = data;
588 Evas_Event_Mouse_Down *ev = event_info;
589 Evas_Coord ix, iy, iw, ih;
590 Evas_Object *eo = NULL;
592 if (wd->ani_lock) return;
594 wd->down_pos = ev->canvas;
595 wd->timestamp = ev->timestamp;
596 wd->move_cnt = MOVE_STEP;
598 wd->dx = ev->canvas.x;
599 wd->dy = ev->canvas.y;
600 wd->mx = ev->canvas.x;
601 wd->my = ev->canvas.y;
606 eo = edje_object_part_swallow_get(elm_layout_edje_get(obj), "swl.photo");
607 if (eo) evas_object_geometry_get(eo, &ix, &iy, &iw, &ih);
610 wd->on_zoom = EINA_TRUE;
611 edje_object_signal_emit(elm_layout_edje_get(obj), "block.off", "block");
615 fprintf( stderr, "down!\n" );
619 static void ev_imageslider_up_cb(void * data, Evas * e, Evas_Object * obj, void * event_info)
621 Widget_Data *wd = data;
622 Evas_Event_Mouse_Up *ev = event_info;
626 if (wd->ani_lock) return;
630 step = wd->down_pos.x - ev->canvas.x;
631 interval = ev->timestamp - wd->timestamp;
632 if (step == 0 || interval == 0) return;
634 if (interval < FLICK_TIME_MAX) {
635 if (step < FLICK_WIDTH_MIN && step > FLICK_WIDTH_MIN) _imageslider_obj_move(wd, 0);
636 else _imageslider_obj_move(wd, step);
638 step = (wd->x - wd->move_x) << 1;
639 if (step <= wd->w && step >= -(wd->w)) _imageslider_obj_move(wd, 0);
640 else _imageslider_obj_move(wd, step);
646 static void ev_imageslider_move_cb(void * data, Evas * e, Evas_Object * obj, void * event_info)
651 Widget_Data *wd = data;
652 Evas_Event_Mouse_Move *ev = event_info;
653 Elm_Imageslider_Item *it;
655 if (wd->ani_lock) return;
657 if (wd->move_cnt == MOVE_STEP) {
658 if (wd->on_hold == EINA_FALSE) {
662 step = ev->cur.canvas.x - wd->down_pos.x;
663 if (step > 0) idx = BLOCK_LEFT;
664 else idx = BLOCK_RIGHT;
666 wd->move_x = wd->x + ((ev->cur.canvas.x - wd->down_pos.x));
667 wd->move_y = wd->y + ((ev->cur.canvas.y - wd->down_pos.y));
670 _imageslider_update_center_pos(wd, wd->move_x, wd->move_y, wd->y, wd->w);
672 _imageslider_update_pos(wd, wd->move_x, wd->y, wd->w);
676 wd->mx = ev->cur.canvas.x;
677 wd->my = ev->cur.canvas.y;
679 wd->ratio = sqrt((wd->mx -wd->mmx)*(wd->mx -wd->mmx) + (wd->my - wd->mmy)*(wd->my - wd->mmy));
681 eo = edje_object_part_swallow_get(elm_layout_edje_get(obj), "swl.photo");
683 it = eina_list_data_get(wd->cur);
684 if (((it->w * wd->ratio/wd->dratio)/it->ow) < MAX_ZOOM_SIZE ) {
685 edje_object_part_unswallow(elm_layout_edje_get(obj), eo);
686 evas_object_resize(eo, it->w * wd->ratio/wd->dratio, it->h * wd->ratio/wd->dratio);
687 evas_object_size_hint_min_set(eo, it->w * wd->ratio/wd->dratio, it->h * wd->ratio/wd->dratio);
688 edje_object_part_swallow(elm_layout_edje_get(obj), "swl.photo", eo);
699 #if 0 // REMOVED about Multi-touch.
700 static void ev_imageslider_multi_down_cb(void * data, Evas * e, Evas_Object * obj, void * event_info)
702 Evas_Event_Multi_Down *ev = event_info;
703 Widget_Data *wd = data;
705 if (ev->device == MULTITOUCHDEVICE) return;
707 wd->on_hold = EINA_TRUE;
708 wd->mdx = ev->canvas.x;
709 wd->mdy = ev->canvas.y;
710 wd->mmx = ev->canvas.x;
711 wd->mmy = ev->canvas.y;
713 wd->dratio = sqrt((wd->mx - wd->mmx)*(wd->mx - wd->mmx) + (wd->my - wd->mmy)*(wd->my - wd->mmy));
714 wd->ratio = sqrt((wd->mx - wd->mmx)*(wd->mx - wd->mmx)+ (wd->my - wd->mmy)*(wd->my - wd->mmy));
717 wd->on_zoom = EINA_FALSE;
718 edje_object_signal_emit(elm_layout_edje_get(obj), "block.on", "block");
723 static void ev_imageslider_multi_up_cb(void * data, Evas * e, Evas_Object * obj, void * event_info)
725 Evas_Event_Multi_Up *ev = event_info;
726 Widget_Data *wd = data;
727 Elm_Imageslider_Item *it;
729 if (ev->device == MULTITOUCHDEVICE) return;
731 it = eina_list_data_get(wd->cur);
732 it->w = (int)it->w * wd->ratio/wd->dratio;
733 it->h = (int)it->h * wd->ratio/wd->dratio;
735 if (it->w != it->ow) {
736 wd->on_zoom = EINA_TRUE;
737 edje_object_signal_emit(elm_layout_edje_get(obj), "block.off", "block");
740 wd->on_zoom = EINA_FALSE;
743 wd->on_hold = EINA_FALSE;
753 static void ev_imageslider_multi_move_cb(void * data, Evas * e, Evas_Object * obj, void * event_info)
755 Evas_Event_Multi_Move *ev = event_info;
756 Widget_Data *wd = data;
757 Evas_Object *eo = NULL;
758 Elm_Imageslider_Item *it;
760 if (ev->device == MULTITOUCHDEVICE) return;
762 if ((wd->mdx == 0) && (wd->mdy == 0) && (wd->mmx == 0) && (wd->mmy == 0)) {
763 wd->mdx = ev->cur.canvas.x;
764 wd->mdy = ev->cur.canvas.y;
765 wd->mmx = ev->cur.canvas.x;
766 wd->mmy = ev->cur.canvas.y;
768 wd->dratio = sqrt((wd->dx - wd->mdx)*(wd->dx - wd->mdx) + (wd->dy - wd->mdy)*(wd->dy - wd->mdy));
771 wd->mmx = ev->cur.canvas.x;
772 wd->mmy = ev->cur.canvas.y;
773 wd->ratio = sqrt((wd->mx - wd->mmx)*(wd->mx - wd->mmx) + (wd->my - wd->mmy)*(wd->my - wd->mmy));
775 eo = edje_object_part_swallow_get(elm_layout_edje_get(obj), "swl.photo");
778 it = eina_list_data_get(wd->cur);
779 if (((it->w * wd->ratio/wd->dratio)/it->ow) < MAX_ZOOM_SIZE) {
780 edje_object_part_unswallow(elm_layout_edje_get(obj), eo);
781 evas_object_resize(eo, it->w * wd->ratio/wd->dratio, it->h * wd->ratio/wd->dratio);
782 evas_object_size_hint_min_set(eo, it->w * wd->ratio/wd->dratio, it->h * wd->ratio/wd->dratio);
783 edje_object_part_swallow(elm_layout_edje_get(obj), "swl.photo", eo);
788 #endif // about Multi-touch.
790 static inline double time_get(Evas_Coord x, Evas_Coord w)
793 time = (-sin(x / w) + 1) / 500;
795 if (time == 0) time = ANI_TIME;
800 static int _icon_to_image(void *data)
802 Widget_Data *wd = data;
804 _imageslider_update(wd);
809 static int _check_drag(int state, void *data)
811 Widget_Data *wd = data;
812 Elm_Imageslider_Item *it;
813 Evas_Coord ix, iy, iw, ih;
815 Eina_List *l[BLOCK_MAX];
816 Evas_Object *eo = NULL;
817 l[BLOCK_LEFT] = eina_list_prev(wd->cur);
818 l[BLOCK_CENTER] = wd->cur;
819 l[BLOCK_RIGHT] = eina_list_next(wd->cur);
821 it = eina_list_data_get(l[state]);
823 eo = edje_object_part_swallow_get(elm_layout_edje_get(wd->ly[state]), "swl.photo");
824 if (eo) evas_object_geometry_get(eo, &ix, &iy, &iw, &ih);
825 evas_object_geometry_get(eo, &ix, &iy, &iw, &ih);
826 edje_object_part_drag_value_get(elm_layout_edje_get(wd->ly[state]), "swl.photo", &dx, &dy);
828 if ((iw != wd->w) || ((dx != 0 ) || (dy != 0 ))) {
830 evas_object_del(wd->ly[state]);
831 wd->ly[state] = NULL;
833 wd->ly[state] = _imageslider_add_obj(wd);
842 static void _check_zoom(void *data)
844 Widget_Data *wd = data;
845 Elm_Imageslider_Item *it;
846 Evas_Coord ix, iy, iw, ih;
848 Evas_Object *eo = NULL;
850 it = eina_list_data_get(wd->cur);
852 eo = edje_object_part_swallow_get(elm_layout_edje_get(wd->ly[BLOCK_CENTER]), "swl.photo");
853 if (eo) evas_object_geometry_get(eo, &ix, &iy, &iw, &ih);
854 evas_object_geometry_get(eo, &ix, &iy, &iw, &ih);
855 edje_object_part_drag_value_get(elm_layout_edje_get(wd->ly[BLOCK_CENTER]), "swl.photo", &dx, &dy);
857 if ((iw != wd->w) || ((dx != 0) || (dy != 0))) {
858 wd->on_zoom = EINA_TRUE;
859 edje_object_signal_emit(elm_layout_edje_get(wd->ly[BLOCK_CENTER]), "block.off", "block");
862 wd->on_zoom = EINA_FALSE;
863 edje_object_signal_emit(elm_layout_edje_get(wd->ly[BLOCK_CENTER]), "block.on", "block");
869 static int _timer_cb(void *data)
872 Elm_Imageslider_Item *it;
877 if (wd->ani_lock == 0 ) return 0;
879 gettimeofday(&tv, NULL);
881 t = (tv.tv_sec - wd->tv.tv_sec) * 1000 + (tv.tv_usec - wd->tv.tv_usec) / 1000;
882 gettimeofday(&wd->tv, NULL);
884 t = t / ANI_TIME_MSEC;
885 if (t <= STEP_WEIGHT_MIN) t = STEP_WEIGHT_DEF;
886 else if (t > STEP_WEIGHT_MAX) t = STEP_WEIGHT_MAX;
888 wd->move_x += (wd->step) * t;
890 if (wd->step < 0 && wd->move_x < wd->x) wd->move_x = wd->x;
891 else if (wd->step > 0 && wd->move_x > wd->x) wd->move_x = wd->x;
893 _imageslider_update_pos(wd, wd->move_x, wd->y, wd->w);
895 if (wd->move_x == wd->x) {
898 it = eina_list_data_get(wd->cur);
899 if (it->func) it->func(it->data, wd->obj, it);
902 it = eina_list_data_get(wd->cur);
903 evas_object_smart_callback_call(wd->obj, "changed", it);
906 ret = _check_drag(BLOCK_LEFT, wd);
907 ret = _check_drag(BLOCK_RIGHT, wd);
910 ecore_idler_add(_icon_to_image, wd);
918 static void _anim(Widget_Data *wd)
922 if (wd->x == wd->move_x) {
923 _imageslider_update_pos(wd, wd->move_x, wd->y, wd->w);
930 gettimeofday(&wd->tv, NULL);
931 ecore_timer_add(ANI_TIME, _timer_cb, wd);
934 static void _imageslider_update(Widget_Data *wd)
937 Eina_List *l[BLOCK_MAX];
938 Elm_Imageslider_Item *it;
947 _imageslider_del_all(wd);
951 l[BLOCK_LEFT] = eina_list_prev(wd->cur);
952 l[BLOCK_CENTER] = wd->cur;
953 l[BLOCK_RIGHT] = eina_list_next(wd->cur);
955 for (i = 0; i < BLOCK_MAX; i++) {
956 eo = edje_object_part_swallow_get(elm_layout_edje_get(wd->ly[i]), "swl.photo");
958 elm_layout_content_set(wd->ly[i], "swl.photo", NULL);
961 it = eina_list_data_get(l[i]);
965 eo = elm_image_add(wd->obj);
966 elm_layout_content_set(wd->ly[i], "swl.photo", eo);
967 elm_image_prescale_set(eo, wd->w);
968 elm_image_file_set(eo, it->photo_file, NULL);
969 elm_image_object_size_get(eo, &it->w, &it->h);
970 evas_object_geometry_get(eo, &it->ox, &it->oy, &it->ow, &it->oh);
975 if (wd->moving != it->moving) {
976 it->moving = wd->moving;
978 elm_image_prescale_set(eo, MOVING_IMAGE_SIZE);
980 elm_image_prescale_set(eo, it->w > it->h ? it->w : it->h);
992 * add imageslider widget
994 * @fn Evas_Object *elm_imageslider_add(Evas_Object *parent);
995 * @param obj The parent object
996 * @return The new object or NULL if it cannot be created
998 * @ingroup Elm-imageslider
1001 elm_imageslider_add(Evas_Object * parent)
1004 Evas_Object *obj = NULL;
1005 Widget_Data *wd = NULL;
1012 wd = ELM_NEW(Widget_Data);
1013 e = evas_object_evas_get(parent);
1018 obj = elm_widget_add(e);
1019 ELM_SET_WIDTYPE(widtype, "imageslider");
1020 elm_widget_type_set(obj, "imageslider");
1021 elm_widget_sub_object_add(parent, obj);
1022 elm_widget_data_set(obj, wd);
1023 //wd->parent = parent;
1024 elm_widget_del_hook_set(obj, _del_hook);
1025 //elm_widget_theme_hook_set(obj, _theme_hook);
1027 /* Add imageslider layouts */
1028 //_imageslider_add(obj);
1029 wd->clip = evas_object_rectangle_add(e);
1031 for (i=0; i < BLOCK_MAX; i++) {
1032 wd->ly[i] = elm_layout_add(obj);
1033 // _elm_theme_object_set(obj, wd->ly[i], "imageslider", "base", elm_widget_style_get(obj));
1034 elm_layout_theme_set(wd->ly[i], "imageslider", "base", "default");
1035 elm_widget_resize_object_set(obj, wd->ly[i]);
1036 evas_object_smart_member_add(wd->ly[i], obj);
1037 evas_object_event_callback_add(wd->ly[i], EVAS_CALLBACK_MOUSE_DOWN, ev_imageslider_down_cb, wd);
1038 evas_object_event_callback_add(wd->ly[i], EVAS_CALLBACK_MOUSE_UP, ev_imageslider_up_cb, wd);
1039 evas_object_event_callback_add(wd->ly[i], EVAS_CALLBACK_MOUSE_MOVE, ev_imageslider_move_cb, wd);
1040 evas_object_clip_set(wd->ly[i], wd->clip);
1041 evas_object_show(wd->ly[i]);
1046 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _imageslider_resize, obj);
1047 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _imageslider_move, obj);
1048 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _imageslider_show, obj);
1049 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _imageslider_hide, obj);
1058 * append imageslider item
1060 * @fn Elm_Imageslider_Item *elm_imageslider_item_append(Evas_Object *obj, const char *photo_file, Elm_Imageslider_Cb func, void *data)
1061 * @param obj The photoslider object
1062 * @param photo_file photo file path
1063 * @param func callback function
1064 * @param data callback data
1065 * @return The photoslider item handle or NULL
1067 * @ingroup ImageSlider
1069 EAPI Elm_Imageslider_Item *
1070 elm_imageslider_item_append(Evas_Object * obj, const char * photo_file, Elm_Imageslider_Cb func, void * data)
1072 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1074 Elm_Imageslider_Item *it;
1076 if (!obj || !(wd = elm_widget_data_get(obj))) {
1080 it = (Elm_Imageslider_Item *)calloc(1, sizeof(Elm_Imageslider_Item));
1081 if (!it) return NULL;
1082 it->photo_file = eina_stringshare_add(photo_file);
1086 wd->its = eina_list_append(wd->its, it);
1088 if (!wd->cur) wd->cur = wd->its;
1090 _imageslider_update(wd);
1097 * prepend imageslider item
1099 * @fn Elm_Imageslider_Item *elm_imageslider_item_prepend(Evas_Object *obj, const char *photo_file, Elm_Imageslider_Cb func, void *data)
1100 * @param obj The imageslider object
1101 * @param photo_file photo file path
1102 * @param func callback function
1103 * @param data callback data
1104 * @return The imageslider item handle or NULL
1106 * @ingroup ImageSlider
1108 EAPI Elm_Imageslider_Item *
1109 elm_imageslider_item_prepend(Evas_Object * obj, const char * photo_file, Elm_Imageslider_Cb func, void * data)
1111 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1113 Elm_Imageslider_Item *it;
1115 if (!obj || !(wd = elm_widget_data_get(obj))) {
1119 it = (Elm_Imageslider_Item *)calloc(1, sizeof(Elm_Imageslider_Item));
1120 it->photo_file = eina_stringshare_add(photo_file);
1124 wd->its = eina_list_prepend(wd->its, it );
1126 if (!wd->cur) wd->cur = wd->its;
1128 _imageslider_update(wd);
1136 * delete imageslider item
1138 * @fn void elm_imageslider_del(Elm_Imageslider_Item *it)
1139 * @param it imageslider item handle
1141 * @ingroup ImageSlider
1144 elm_imageslider_item_del(Elm_Imageslider_Item * it)
1147 Elm_Imageslider_Item *_it;
1150 if (!it || !(wd = elm_widget_data_get(it->obj))) {
1154 EINA_LIST_FOREACH(wd->its, l, _it) {
1156 if (l == wd->cur) wd->cur = eina_list_prev(wd->cur);
1157 wd->its = eina_list_remove(wd->its, it);
1158 if (!wd->cur) wd->cur = wd->its;
1163 _imageslider_update(wd);
1171 * @fn Elm_Imageslider_Item *elm_imageslider_selected_item_get(Evas_Object *obj)
1172 * @param obj The imageslider object
1173 * @return The selected item or NULL
1175 * @ingroup ImageSlider
1177 EAPI Elm_Imageslider_Item *
1178 elm_imageslider_selected_item_get(Evas_Object * obj)
1180 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1183 if (!obj || (!(wd = elm_widget_data_get(obj)))) {
1187 if (!wd->cur) return NULL;
1189 return eina_list_data_get(wd->cur);
1193 * get whether item is selected or not
1195 * @fn Eina_Bool elm_imageslider_item_selected_get(Elm_Imageslider_Item *it)
1196 * @param it the item
1197 * @return EINA_TRUE or EINA_FALSE
1199 * @ingroup ImageSlider
1202 elm_imageslider_item_selected_get(Elm_Imageslider_Item * it)
1206 if (!it || !it->obj || (!(wd = elm_widget_data_get(it->obj)))) {
1210 if (!wd->cur) return EINA_FALSE;
1212 if (eina_list_data_get(wd->cur) == it ) return EINA_TRUE;
1213 else return EINA_FALSE;
1220 * @fn void elm_imageslider_item_selected_set(Elm_Imageslider_Item *it);
1222 * @ingroup ImageSlider
1225 elm_imageslider_item_selected_set(Elm_Imageslider_Item * it)
1229 Elm_Imageslider_Item *_it;
1233 if (!it || !it->obj || (!(wd = elm_widget_data_get(it->obj)))) {
1237 EINA_LIST_FOREACH(wd->its, l, _it) {
1243 for (i = 0; i < BLOCK_MAX; i++) {
1244 eo = edje_object_part_swallow_get(elm_layout_edje_get(wd->ly[i]), "swl.photo");
1246 elm_layout_content_set(wd->ly[i], "swl.photo", NULL);
1247 evas_object_del(eo);
1251 _imageslider_update(wd);
1257 * get photo file path of give item
1259 * @fn const char *elm_imageslider_item_photo_file_get(Elm_Imageslider_Item *it)
1261 * @return The photo file path or NULL;
1263 * @ingroup ImageSlider
1266 elm_imageslider_item_photo_file_get(Elm_Imageslider_Item * it)
1272 return it->photo_file;
1279 * @fn Elm_Imageslider_Item *elm_imageslider_item_prev(Elm_Imageslider_Item *it)
1281 * @return The previous item or NULL
1283 * @ingroup ImageSlider
1285 EAPI Elm_Imageslider_Item *
1286 elm_imageslider_item_prev(Elm_Imageslider_Item * it)
1289 Elm_Imageslider_Item *_it;
1292 if (!it || (!(wd = elm_widget_data_get(it->obj)))) {
1296 EINA_LIST_FOREACH(wd->its, l, _it) {
1298 l = eina_list_prev(l);
1300 return eina_list_data_get(l);
1311 * @fn Elm_Imageslider_Item *elm_imageslider_item_next(Elm_Imageslider_Item *it)
1313 * @return The next item or NULL
1315 * @ingroup ImageSlider
1317 EAPI Elm_Imageslider_Item *
1318 elm_imageslider_item_next(Elm_Imageslider_Item * it)
1321 Elm_Imageslider_Item *_it;
1324 if (!it || (!(wd = elm_widget_data_get(it->obj)))) {
1328 EINA_LIST_FOREACH(wd->its, l, _it) {
1330 l = eina_list_next(l);
1332 return eina_list_data_get(l);
1341 * move to previous item
1343 * @fn void *elm_imageslider_prev(Evas_Object *obj)
1344 * @param obj imageslider object
1346 * @ingroup ImageSlider
1349 elm_imageslider_prev(Evas_Object * obj)
1351 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1354 if (!obj || (!(wd = elm_widget_data_get(obj)))) {
1358 if (wd->ani_lock) return;
1360 _imageslider_obj_move(wd, -1);
1367 * @fn void *elm_imageslider_next(Evas_Object *obj)
1368 * @param obj imageslider object
1370 * @ingroup ImageSlider
1373 elm_imageslider_next(Evas_Object * obj)
1375 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1378 if (!obj || (!(wd = elm_widget_data_get(obj)))) {
1382 if (wd->ani_lock) return;
1384 _imageslider_obj_move(wd, 1);