1 #include <Elementary.h>
4 #define SMART_NAME "els_scroller"
5 #define API_ENTRY Smart_Data *sd; sd = evas_object_smart_data_get(obj); if ((!obj) || (!sd) || (evas_object_type_get(obj) && strcmp(evas_object_type_get(obj), SMART_NAME)))
6 #define INTERNAL_ENTRY Smart_Data *sd; sd = evas_object_smart_data_get(obj); if (!sd) return;
7 typedef struct _Smart_Data Smart_Data;
14 Evas_Coord x, y, w, h;
15 Evas_Coord wx, wy, ww, wh; /* Last "wanted" geometry */
17 Evas_Object *smart_obj;
18 Evas_Object *child_obj;
20 Evas_Object *edje_obj;
21 Evas_Object *event_obj;
25 Elm_Smart_Scroller_Policy hbar_flags, vbar_flags;
39 double timestamp, localtimestamp;
42 double tadd, dxsum, dysum;
43 double est_timestamp_diff;
48 double onhold_vx, onhold_vy, onhold_tlast, onhold_vxe, onhold_vye;
50 Evas_Coord hold_x, hold_y;
51 Ecore_Animator *hold_animator;
52 Ecore_Animator *onhold_animator;
53 Ecore_Animator *momentum_animator;
54 Ecore_Animator *bounce_x_animator;
55 Ecore_Animator *bounce_y_animator;
56 Evas_Coord locked_x, locked_y;
58 unsigned char now : 1;
59 unsigned char cancelled : 1;
60 unsigned char hold : 1;
61 unsigned char hold_parent : 1;
62 unsigned char want_dragged : 1;
63 unsigned char dragged : 1;
64 unsigned char dragged_began : 1;
65 unsigned char dir_x : 1;
66 unsigned char dir_y : 1;
67 unsigned char locked : 1;
68 unsigned char bounce_x_hold : 1;
69 unsigned char bounce_y_hold : 1;
70 unsigned char scroll : 1;
71 unsigned char want_reset : 1;
82 void (*set) (Evas_Object *obj, Evas_Coord x, Evas_Coord y);
83 void (*get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y);
84 void (*max_get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y);
85 void (*min_get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y);
86 void (*child_size_get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y);
91 Evas_Coord start, end;
92 double t_start, t_end;
93 Ecore_Animator *animator;
97 double pagerel_h, pagerel_v;
98 Evas_Coord pagesize_h, pagesize_v;
100 unsigned char hbar_visible : 1;
101 unsigned char vbar_visible : 1;
102 unsigned char extern_pan : 1;
103 unsigned char one_dir_at_a_time : 1;
104 unsigned char hold : 1;
105 unsigned char freeze : 1;
106 unsigned char bouncemex : 1;
107 unsigned char bouncemey : 1;
108 unsigned char bounce_horiz : 1;
109 unsigned char bounce_vert : 1;
110 unsigned char event_propagation :1;
111 Eina_Bool momentum_animator_disabled :1;
112 Eina_Bool bounce_animator_disabled :1;
113 Eina_Bool is_mirrored : 1;
114 Eina_Bool wheel_disabled : 1;
117 /* local subsystem functions */
118 static void _smart_child_del_hook(void *data, Evas *e, Evas_Object *obj, void *event_info);
119 static void _smart_pan_changed_hook(void *data, Evas_Object *obj, void *event_info);
120 static void _smart_pan_pan_changed_hook(void *data, Evas_Object *obj, void *event_info);
121 static void _smart_event_wheel(void *data, Evas *e, Evas_Object *obj, void *event_info);
122 static void _smart_event_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info);
123 static Eina_Bool _smart_hold_animator(void *data);
124 static Eina_Bool _smart_momentum_animator(void *data);
125 static void _smart_event_mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info);
126 static Eina_Bool _smart_onhold_animator(void *data);
127 static void _smart_event_mouse_move(void *data, Evas *e, Evas_Object *obj, void *event_info);
128 static void _smart_edje_drag_v_start(void *data, Evas_Object *obj, const char *emission, const char *source);
129 static void _smart_edje_drag_v_stop(void *data, Evas_Object *obj, const char *emission, const char *source);
130 static void _smart_edje_drag_v(void *data, Evas_Object *obj, const char *emission, const char *source);
131 static void _smart_edje_drag_h_start(void *data, Evas_Object *obj, const char *emission, const char *source);
132 static void _smart_edje_drag_h_stop(void *data, Evas_Object *obj, const char *emission, const char *source);
133 static void _smart_edje_drag_h(void *data, Evas_Object *obj, const char *emission, const char *source);
134 static void _smart_scrollbar_read(Smart_Data *sd);
135 static void _smart_scrollbar_reset(Smart_Data *sd);
136 static int _smart_scrollbar_bar_h_visibility_adjust(Smart_Data *sd);
137 static int _smart_scrollbar_bar_v_visibility_adjust(Smart_Data *sd);
138 static void _smart_scrollbar_bar_visibility_adjust(Smart_Data *sd);
139 static void _smart_scrollbar_size_adjust(Smart_Data *sd);
140 static void _smart_reconfigure(Smart_Data *sd);
141 static void _smart_add(Evas_Object *obj);
142 static void _smart_del(Evas_Object *obj);
143 static void _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y);
144 static void _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h);
145 static void _smart_show(Evas_Object *obj);
146 static void _smart_hide(Evas_Object *obj);
147 static void _smart_color_set(Evas_Object *obj, int r, int g, int b, int a);
148 static void _smart_clip_set(Evas_Object *obj, Evas_Object *clip);
149 static void _smart_clip_unset(Evas_Object *obj);
150 static void _smart_init(void);
152 /* local subsystem globals */
153 static Evas_Smart *_smart = NULL;
155 /* externally accessible functions */
157 elm_smart_scroller_add(Evas *evas)
160 return evas_object_smart_add(evas, _smart);
164 _elm_smart_scroller_x_mirrored_get(Evas_Object *obj, Evas_Coord x)
168 Evas_Coord cw, ch, w, ret;
169 elm_smart_scroller_child_viewport_size_get(obj, &w, NULL);
170 sd->pan_func.child_size_get(sd->pan_obj, &cw, &ch);
171 ret = (cw - (x + w));
172 return (ret >= 0) ? ret : 0;
176 elm_smart_scroller_mirrored_set(Evas_Object *obj, Eina_Bool mirrored)
180 if (sd->is_mirrored == mirrored)
183 sd->is_mirrored = mirrored;
184 edje_object_mirrored_set(sd->edje_obj, mirrored);
187 wx = _elm_smart_scroller_x_mirrored_get(sd->smart_obj, sd->wx);
191 elm_smart_scroller_child_pos_set(sd->smart_obj, wx, sd->wy);
195 elm_smart_scroller_child_set(Evas_Object *obj, Evas_Object *child)
203 _elm_smart_pan_child_set(sd->pan_obj, NULL);
204 evas_object_event_callback_del_full(sd->child_obj, EVAS_CALLBACK_DEL, _smart_child_del_hook, sd);
207 sd->child_obj = child;
209 /* (-1) means want viewports size */
210 sd->ww = sd->wh = -1;
215 o = _elm_smart_pan_add(evas_object_evas_get(obj));
217 evas_object_smart_callback_add(o, "changed", _smart_pan_changed_hook, sd);
218 evas_object_smart_callback_add(o, "pan_changed", _smart_pan_pan_changed_hook, sd);
219 edje_object_part_swallow(sd->edje_obj, "elm.swallow.content", o);
222 sd->pan_func.set = _elm_smart_pan_set;
223 sd->pan_func.get = _elm_smart_pan_get;
224 sd->pan_func.max_get = _elm_smart_pan_max_get;
225 sd->pan_func.min_get = _elm_smart_pan_min_get;
226 sd->pan_func.child_size_get = _elm_smart_pan_child_size_get;
228 evas_object_event_callback_add(child, EVAS_CALLBACK_DEL, _smart_child_del_hook, sd);
229 _elm_smart_pan_child_set(sd->pan_obj, child);
230 sd->pan_func.child_size_get(sd->pan_obj, &w, &h);
233 _smart_scrollbar_size_adjust(sd);
234 _smart_scrollbar_reset(sd);
238 elm_smart_scroller_extern_pan_set(Evas_Object *obj, Evas_Object *pan,
239 void (*pan_set) (Evas_Object *obj, Evas_Coord x, Evas_Coord y),
240 void (*pan_get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y),
241 void (*pan_max_get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y),
242 void (*pan_min_get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y),
243 void (*pan_child_size_get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y))
247 elm_smart_scroller_child_set(obj, NULL);
251 evas_object_smart_callback_del(sd->pan_obj, "changed", _smart_pan_changed_hook);
252 evas_object_smart_callback_del(sd->pan_obj, "pan_changed", _smart_pan_pan_changed_hook);
259 edje_object_part_unswallow(sd->edje_obj, sd->pan_obj);
267 evas_object_del(sd->pan_obj);
278 sd->pan_func.set = pan_set;
279 sd->pan_func.get = pan_get;
280 sd->pan_func.max_get = pan_max_get;
281 sd->pan_func.min_get = pan_min_get;
282 sd->pan_func.child_size_get = pan_child_size_get;
284 evas_object_smart_callback_add(sd->pan_obj, "changed", _smart_pan_changed_hook, sd);
285 evas_object_smart_callback_add(sd->pan_obj, "pan_changed", _smart_pan_pan_changed_hook, sd);
286 edje_object_part_swallow(sd->edje_obj, "elm.swallow.content", sd->pan_obj);
287 evas_object_show(sd->pan_obj);
291 elm_smart_scroller_custom_edje_file_set(Evas_Object *obj, char *file, char *group)
295 edje_object_file_set(sd->edje_obj, file, group);
297 edje_object_part_swallow(sd->edje_obj, "elm.swallow.content", sd->pan_obj);
298 sd->vbar_visible = !sd->vbar_visible;
299 sd->hbar_visible = !sd->hbar_visible;
300 _smart_scrollbar_bar_visibility_adjust(sd);
301 if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
302 edje_object_signal_emit(sd->edje_obj, "elm,action,show_always,hbar", "elm");
303 else if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
304 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,hbar", "elm");
306 edje_object_signal_emit(sd->edje_obj, "elm,action,show_notalways,hbar", "elm");
307 if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
308 edje_object_signal_emit(sd->edje_obj, "elm,action,show_always,vbar", "elm");
309 else if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
310 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,vbar", "elm");
312 edje_object_signal_emit(sd->edje_obj, "elm,action,show_notalways,vbar", "elm");
316 elm_smart_scroller_momentum_animator_disabled_get(Evas_Object *obj)
318 API_ENTRY return EINA_FALSE;
319 return sd->momentum_animator_disabled;
323 elm_smart_scroller_momentum_animator_disabled_set(Evas_Object *obj, Eina_Bool disabled)
326 sd->momentum_animator_disabled = disabled;
327 if (sd->momentum_animator_disabled)
329 if (sd->down.momentum_animator)
331 ecore_animator_del(sd->down.momentum_animator);
332 sd->down.momentum_animator = NULL;
338 elm_smart_scroller_bounce_animator_disabled_get(Evas_Object *obj)
340 API_ENTRY return EINA_FALSE;
341 return sd->bounce_animator_disabled;
345 elm_smart_scroller_bounce_animator_disabled_set(Evas_Object *obj, Eina_Bool disabled)
348 sd->bounce_animator_disabled = disabled;
349 if (sd->bounce_animator_disabled)
351 if (sd->scrollto.x.animator)
353 ecore_animator_del(sd->scrollto.x.animator);
354 sd->scrollto.x.animator = NULL;
357 if (sd->scrollto.y.animator)
359 ecore_animator_del(sd->scrollto.y.animator);
360 sd->scrollto.y.animator = NULL;
366 elm_smart_scroller_wheel_disabled_get(Evas_Object *obj)
368 API_ENTRY return EINA_FALSE;
369 return sd->wheel_disabled;
373 elm_smart_scroller_wheel_disabled_set(Evas_Object *obj, Eina_Bool disabled)
376 if ((!sd->wheel_disabled) && (disabled))
377 evas_object_event_callback_del_full(sd->event_obj, EVAS_CALLBACK_MOUSE_WHEEL, _smart_event_wheel, sd);
378 else if ((sd->wheel_disabled) && (!disabled))
379 evas_object_event_callback_add(sd->event_obj, EVAS_CALLBACK_MOUSE_WHEEL, _smart_event_wheel, sd);
380 sd->wheel_disabled = disabled;
383 /* Update the wanted coordinates according to the x, y passed
384 * widget directionality, child size and etc. */
386 _update_wanted_coordinates(Smart_Data *sd, Evas_Coord x, Evas_Coord y)
390 sd->pan_func.child_size_get(sd->pan_obj, &cw, &ch);
392 /* Update wx/y/w/h - and if the requested positions aren't legal
394 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &sd->ww, &sd->wh);
397 else if ((x + sd->ww) > cw)
398 sd->wx = cw - sd->ww;
399 else if (sd->is_mirrored)
400 sd->wx = _elm_smart_scroller_x_mirrored_get(sd->smart_obj, x);
403 if (y < 0) sd->wy = 0;
404 else if ((y + sd->wh) > ch) sd->wy = ch - sd->wh;
409 _smart_anim_start(Evas_Object *obj)
411 evas_object_smart_callback_call(obj, "animate,start", NULL);
415 _smart_anim_stop(Evas_Object *obj)
417 evas_object_smart_callback_call(obj, "animate,stop", NULL);
421 _smart_drag_start(Evas_Object *obj)
423 evas_object_smart_callback_call(obj, "drag,start", NULL);
427 _smart_drag_stop(Evas_Object *obj)
429 evas_object_smart_callback_call(obj, "drag,stop", NULL);
433 _smart_scrollto_x_animator(void *data)
435 Smart_Data *sd = data;
439 t = ecore_loop_time_get();
440 tt = (t - sd->scrollto.x.t_start) / (sd->scrollto.x.t_end - sd->scrollto.x.t_start);
442 tt = 1.0 - (tt * tt);
443 sd->pan_func.get(sd->pan_obj, &px, &py);
444 px = (sd->scrollto.x.start * (1.0 - tt)) +
445 (sd->scrollto.x.end * tt);
446 if (t >= sd->scrollto.x.t_end)
448 px = sd->scrollto.x.end;
449 elm_smart_scroller_child_pos_set(sd->smart_obj, px, py);
450 sd->scrollto.x.animator = NULL;
451 if ((!sd->scrollto.y.animator) && (!sd->down.bounce_y_animator))
452 _smart_anim_stop(sd->smart_obj);
453 return ECORE_CALLBACK_CANCEL;
455 elm_smart_scroller_child_pos_set(sd->smart_obj, px, py);
456 return ECORE_CALLBACK_RENEW;
460 _smart_momentum_end(Smart_Data *sd)
462 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator)) return;
463 if (sd->down.momentum_animator)
466 elm_smart_scroller_child_pos_get(sd->smart_obj, &px, &py);
467 _update_wanted_coordinates(sd, px, py);
469 ecore_animator_del(sd->down.momentum_animator);
470 sd->down.momentum_animator = NULL;
471 sd->down.bounce_x_hold = 0;
472 sd->down.bounce_y_hold = 0;
483 _smart_scrollto_x(Smart_Data *sd, double t_in, Evas_Coord pos_x)
485 Evas_Coord px, py, x, y, w, h;
488 if (sd->freeze) return;
491 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
492 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
494 elm_smart_scroller_child_region_set(sd->smart_obj, x, y, w, h);
497 t = ecore_loop_time_get();
498 sd->pan_func.get(sd->pan_obj, &px, &py);
499 sd->scrollto.x.start = px;
500 sd->scrollto.x.end = pos_x;
501 sd->scrollto.x.t_start = t;
502 sd->scrollto.x.t_end = t + t_in;
503 if (!sd->scrollto.x.animator)
505 sd->scrollto.x.animator = ecore_animator_add(_smart_scrollto_x_animator, sd);
506 if (!sd->scrollto.y.animator)
507 _smart_anim_start(sd->smart_obj);
509 if (sd->down.bounce_x_animator)
511 ecore_animator_del(sd->down.bounce_x_animator);
512 sd->down.bounce_x_animator = NULL;
513 _smart_momentum_end(sd);
519 _smart_scrollto_y_animator(void *data)
521 Smart_Data *sd = data;
525 t = ecore_loop_time_get();
526 tt = (t - sd->scrollto.y.t_start) / (sd->scrollto.y.t_end - sd->scrollto.y.t_start);
528 tt = 1.0 - (tt * tt);
529 sd->pan_func.get(sd->pan_obj, &px, &py);
530 py = (sd->scrollto.y.start * (1.0 - tt)) +
531 (sd->scrollto.y.end * tt);
532 if (t >= sd->scrollto.y.t_end)
534 py = sd->scrollto.y.end;
535 elm_smart_scroller_child_pos_set(sd->smart_obj, px, py);
536 sd->scrollto.y.animator = NULL;
537 if ((!sd->scrollto.x.animator) && (!sd->down.bounce_x_animator))
538 _smart_anim_stop(sd->smart_obj);
539 return ECORE_CALLBACK_CANCEL;
541 elm_smart_scroller_child_pos_set(sd->smart_obj, px, py);
543 return ECORE_CALLBACK_RENEW;
547 _smart_scrollto_y(Smart_Data *sd, double t_in, Evas_Coord pos_y)
549 Evas_Coord px, py, x, y, w, h;
552 if (sd->freeze) return;
555 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
556 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
558 elm_smart_scroller_child_region_set(sd->smart_obj, x, y, w, h);
561 t = ecore_loop_time_get();
562 sd->pan_func.get(sd->pan_obj, &px, &py);
563 sd->scrollto.y.start = py;
564 sd->scrollto.y.end = pos_y;
565 sd->scrollto.y.t_start = t;
566 sd->scrollto.y.t_end = t + t_in;
567 if (!sd->scrollto.y.animator)
569 sd->scrollto.y.animator = ecore_animator_add(_smart_scrollto_y_animator, sd);
570 if (!sd->scrollto.x.animator)
571 _smart_anim_start(sd->smart_obj);
573 if (sd->down.bounce_y_animator)
575 ecore_animator_del(sd->down.bounce_y_animator);
576 sd->down.bounce_y_animator = NULL;
577 _smart_momentum_end(sd);
583 _smart_do_page(Smart_Data *sd)
585 if ((sd->pagerel_h == 0.0) && (!sd->pagesize_h) &&
586 (sd->pagerel_v == 0.0) && (!sd->pagesize_v))
592 _smart_page_x_get(Smart_Data *sd, int offset)
594 Evas_Coord x, y, w, h, cw, ch, minx = 0;
596 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
597 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
598 sd->pan_func.child_size_get(sd->pan_obj, &cw, &ch);
599 sd->pan_func.min_get(sd->pan_obj, &minx, NULL);
603 if (sd->pagerel_h > 0.0)
605 x = x + (w * sd->pagerel_h * 0.5);
606 x = x / (w * sd->pagerel_h);
607 x = x * (w * sd->pagerel_h);
609 else if (sd->pagesize_h > 0)
611 x = x + (sd->pagesize_h * 0.5);
612 x = x / (sd->pagesize_h);
613 x = x * (sd->pagesize_h);
615 if ((x + w) > cw) x = cw - w;
616 if (x < minx) x = minx;
621 _smart_page_y_get(Smart_Data *sd, int offset)
623 Evas_Coord x, y, w, h, cw, ch, miny = 0;
625 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
626 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
627 sd->pan_func.child_size_get(sd->pan_obj, &cw, &ch);
628 sd->pan_func.min_get(sd->pan_obj, NULL, &miny);
632 if (sd->pagerel_v > 0.0)
634 y = y + (h * sd->pagerel_v * 0.5);
635 y = y / (h * sd->pagerel_v);
636 y = y * (h * sd->pagerel_v);
638 else if (sd->pagesize_v > 0)
640 y = y + (sd->pagesize_v * 0.5);
641 y = y / (sd->pagesize_v);
642 y = y * (sd->pagesize_v);
644 if ((y + h) > ch) y = ch - h;
645 if (y < miny) y = miny;
650 _smart_page_adjust(Smart_Data *sd)
652 Evas_Coord x, y, w, h;
654 if (!_smart_do_page(sd)) return;
656 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
658 x = _smart_page_x_get(sd, 0);
659 y = _smart_page_y_get(sd, 0);
661 elm_smart_scroller_child_region_set(sd->smart_obj, x, y, w, h);
665 _smart_bounce_x_animator(void *data)
668 Evas_Coord x, y, dx, px, w, odx, ed, md;
669 double t, p, dt, pd, r;
672 t = ecore_loop_time_get();
673 dt = t - sd->down.anim_start2;
676 dt = dt / _elm_config->thumbscroll_bounce_friction;
677 odx = sd->down.b2x - sd->down.bx;
678 sd->pan_func.get(sd->pan_obj, &px, NULL);
679 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, NULL);
680 if (!sd->down.momentum_animator && ((w - px) > 0) && ((-px) < w))
682 pd = (double)odx / (double)w;
683 pd = (pd > 0) ? pd : -pd;
684 pd = 1.0 - ((1.0 - pd) * (1.0 - pd));
687 if (dt > 1.0) dt = 1.0;
688 p = 1.0 - ((1.0 - dt) * (1.0 - dt));
689 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
692 if (sd->down.momentum_animator)
694 ed = abs(sd->down.dx * (_elm_config->thumbscroll_friction + sd->down.extra_time) - sd->down.b0x);
695 md = abs(_elm_config->thumbscroll_friction*5*w);
696 if (ed > md) r = (double)(md)/(double)ed;
698 x = sd->down.b2x + (int)((double)(dx - odx)*r);
699 if (!sd->down.cancelled)
700 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
703 if (sd->down.momentum_animator)
704 sd->down.bounce_x_hold = 1;
705 else if ((!sd->down.bounce_y_animator) &&
706 (!sd->scrollto.y.animator))
707 _smart_anim_stop(sd->smart_obj);
708 sd->down.bounce_x_animator = NULL;
711 _smart_momentum_end(sd);
712 return ECORE_CALLBACK_CANCEL;
715 return ECORE_CALLBACK_RENEW;
719 _smart_bounce_y_animator(void *data)
722 Evas_Coord x, y, dy, py, h, ody, ed, md;
723 double t, p, dt, pd, r;
726 t = ecore_loop_time_get();
727 dt = t - sd->down.anim_start3;
730 dt = dt / _elm_config->thumbscroll_bounce_friction;
731 ody = sd->down.b2y - sd->down.by;
732 sd->pan_func.get(sd->pan_obj, NULL, &py);
733 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, NULL, &h);
734 if (!sd->down.momentum_animator && ((h - py) > 0) && ((-py) < h))
736 pd = (double)ody / (double)h;
737 pd = (pd > 0) ? pd : -pd;
738 pd = 1.0 - ((1.0 - pd) * (1.0 - pd));
741 if (dt > 1.0) dt = 1.0;
742 p = 1.0 - ((1.0 - dt) * (1.0 - dt));
743 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
746 if (sd->down.momentum_animator)
748 ed = abs(sd->down.dy * (_elm_config->thumbscroll_friction + sd->down.extra_time) - sd->down.b0y);
749 md = abs(_elm_config->thumbscroll_friction*5*h);
750 if (ed > md) r = (double)(md)/(double)ed;
752 y = sd->down.b2y + (int)((double)(dy - ody)*r);
753 if (!sd->down.cancelled)
754 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
757 if (sd->down.momentum_animator)
758 sd->down.bounce_y_hold = 1;
759 else if ((!sd->down.bounce_x_animator) &&
760 (!sd->scrollto.y.animator))
761 _smart_anim_stop(sd->smart_obj);
762 sd->down.bounce_y_animator = NULL;
765 _smart_momentum_end(sd);
766 return ECORE_CALLBACK_CANCEL;
769 return ECORE_CALLBACK_RENEW;
777 can_scroll(Smart_Data *sd, int dir)
779 Evas_Coord mx = 0, my = 0, px = 0, py = 0, minx = 0, miny = 0;
781 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
782 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
783 sd->pan_func.get(sd->pan_obj, &px, &py);
787 if (px > minx) return EINA_TRUE;
790 if ((px - minx) < mx) return EINA_TRUE;
793 if (py > miny) return EINA_TRUE;
796 if ((py - miny) < my) return EINA_TRUE;
805 _smart_momentum_animator(void *data)
809 Evas_Coord x, y, dx, dy, px, py, maxx, maxy, minx, miny;
810 Eina_Bool no_bounce_x_end = EINA_FALSE, no_bounce_y_end = EINA_FALSE;
813 t = ecore_loop_time_get();
814 dt = t - sd->down.anim_start;
818 if (sd->down.hold_parent)
820 if ((sd->down.dir_x) && !can_scroll(sd, sd->down.hdir))
824 if ((sd->down.dir_y) && !can_scroll(sd, sd->down.vdir))
829 if ((!sd->down.dir_x) && (!sd->down.dir_y))
831 sd->down.cancelled = 1;
834 dt = dt / (_elm_config->thumbscroll_friction + sd->down.extra_time);
835 if (dt > 1.0) dt = 1.0;
836 p = 1.0 - ((1.0 - dt) * (1.0 - dt));
837 dx = (sd->down.dx * (_elm_config->thumbscroll_friction + sd->down.extra_time) * p);
838 dy = (sd->down.dy * (_elm_config->thumbscroll_friction + sd->down.extra_time) * p);
841 x = sd->down.sx - dx;
842 y = sd->down.sy - dy;
843 elm_smart_scroller_child_pos_get(sd->smart_obj, &px, &py);
844 if ((sd->down.bounce_x_animator) ||
845 (sd->down.bounce_x_hold))
847 sd->down.bx = sd->down.bx0 - dx + sd->down.b0x;
850 if ((sd->down.bounce_y_animator) ||
851 (sd->down.bounce_y_hold))
853 sd->down.by = sd->down.by0 - dy + sd->down.b0y;
856 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
857 _update_wanted_coordinates(sd, x, y);
858 sd->pan_func.max_get(sd->pan_obj, &maxx, &maxy);
859 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
860 if (!sd->bounce_horiz)
862 if (x <= minx) no_bounce_x_end = EINA_TRUE;
863 if ((x - minx) >= maxx) no_bounce_x_end = EINA_TRUE;
865 if (!sd->bounce_vert)
867 if (y <= miny) no_bounce_y_end = EINA_TRUE;
868 if ((y - miny) >= maxy) no_bounce_y_end = EINA_TRUE;
871 ((sd->down.bounce_x_hold) && (sd->down.bounce_y_hold)) ||
872 (no_bounce_x_end && no_bounce_y_end))
874 _smart_anim_stop(sd->smart_obj);
876 sd->down.momentum_animator = NULL;
877 sd->down.bounce_x_hold = 0;
878 sd->down.bounce_y_hold = 0;
883 return ECORE_CALLBACK_CANCEL;
886 return ECORE_CALLBACK_RENEW;
890 bounce_eval(Smart_Data *sd)
892 Evas_Coord mx, my, px, py, bx, by, b2x, b2y, minx = 0, miny = 0;
894 if (sd->freeze) return;
895 if ((!sd->bouncemex) && (!sd->bouncemey)) return;
896 if (sd->down.now) return; // down bounce while still held down
897 if (sd->down.onhold_animator)
899 ecore_animator_del(sd->down.onhold_animator);
900 sd->down.onhold_animator = NULL;
902 if (sd->down.hold_animator)
904 ecore_animator_del(sd->down.hold_animator);
905 sd->down.hold_animator = NULL;
907 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
908 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
909 sd->pan_func.get(sd->pan_obj, &px, &py);
912 if (px < minx) px = minx;
913 if ((px - minx) > mx) px = mx + minx;
914 if (py < miny) py = miny;
915 if ((py - miny) > my) py = my + miny;
919 (!elm_widget_drag_child_locked_x_get(sd->widget)))
921 if ((!sd->down.bounce_x_animator) && (!sd->bounce_animator_disabled))
925 if (sd->scrollto.x.animator)
927 ecore_animator_del(sd->scrollto.x.animator);
928 sd->scrollto.x.animator = NULL;
930 sd->down.bounce_x_animator = ecore_animator_add(_smart_bounce_x_animator, sd);
931 sd->down.anim_start2 = ecore_loop_time_get();
935 if (sd->down.momentum_animator) sd->down.b0x = sd->down.ax;
936 else sd->down.b0x = 0;
941 (!elm_widget_drag_child_locked_y_get(sd->widget)))
943 if ((!sd->down.bounce_y_animator) && (!sd->bounce_animator_disabled))
947 if (sd->scrollto.y.animator)
949 ecore_animator_del(sd->scrollto.y.animator);
950 sd->scrollto.y.animator = NULL;
952 sd->down.bounce_y_animator = ecore_animator_add(_smart_bounce_y_animator, sd);
953 sd->down.anim_start3 = ecore_loop_time_get();
957 if (sd->down.momentum_animator) sd->down.b0y = sd->down.ay;
958 else sd->down.b0y = 0;
965 elm_smart_scroller_child_pos_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
967 Evas_Coord mx = 0, my = 0, px = 0, py = 0, minx = 0, miny = 0;
971 // FIXME: allow for bounce outside of range
972 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
973 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
974 if (mx > 0) vx = (double)(x - minx) / (double)mx;
976 if (vx < 0.0) vx = 0.0;
977 else if (vx > 1.0) vx = 1.0;
978 if (my > 0) vy = (double)(y - miny) / (double)my;
980 if (vy < 0.0) vy = 0.0;
981 else if (vy > 1.0) vy = 1.0;
982 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.vbar", 0.0, vy);
983 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.hbar", vx, 0.0);
984 sd->pan_func.get(sd->pan_obj, &px, &py);
985 if (!_elm_config->thumbscroll_bounce_enable)
987 if (x < minx) x = minx;
988 if ((x - minx) > mx) x = mx + minx;
989 if (y < miny) y = miny;
990 if ((y - miny) > my) y = my + miny;
993 if (!sd->bounce_horiz)
995 if (x < minx) x = minx;
996 if ((x - minx) > mx) x = mx + minx;
998 if (!sd->bounce_vert)
1000 if (y < miny) y = miny;
1001 if (y - miny > my) y = my + miny;
1004 sd->pan_func.set(sd->pan_obj, x, y);
1005 if ((px != x) || (py != y))
1006 edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
1007 if (!sd->down.bounce_x_animator)
1009 if (((x < minx) && (0 <= sd->down.dx)) ||
1010 ((x > (mx + minx)) && (0 >= sd->down.dx)))
1018 if (!sd->down.bounce_y_animator)
1020 if (((y < miny) && (0 <= sd->down.dy)) ||
1021 ((y > (my + miny)) && (0 >= sd->down.dy)))
1029 if ((x != px) || (y != py))
1031 evas_object_smart_callback_call(obj, "scroll", NULL);
1033 if ((x != px)/* && (!sd->bouncemex)*/)
1036 evas_object_smart_callback_call(obj, "edge,left", NULL);
1037 if (x == (mx + minx))
1038 evas_object_smart_callback_call(obj, "edge,right", NULL);
1040 if ((y != py)/* && (!sd->bouncemey)*/)
1043 evas_object_smart_callback_call(obj, "edge,top", NULL);
1045 evas_object_smart_callback_call(obj, "edge,bottom", NULL);
1050 elm_smart_scroller_child_pos_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
1053 sd->pan_func.get(sd->pan_obj, x, y);
1056 /* returns TRUE when we need to move the scroller, FALSE otherwise.
1057 * Updates w and h either way, so save them if you need them. */
1059 _elm_smart_scroller_child_region_show_internal(Evas_Object *obj, Evas_Coord *_x, Evas_Coord *_y, Evas_Coord w, Evas_Coord h)
1061 Evas_Coord mx = 0, my = 0, cw = 0, ch = 0, px = 0, py = 0, nx, ny, minx = 0, miny = 0, pw = 0, ph = 0, x = *_x, y = *_y;
1063 API_ENTRY return EINA_FALSE;
1064 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
1065 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
1066 sd->pan_func.child_size_get(sd->pan_obj, &cw, &ch);
1067 sd->pan_func.get(sd->pan_obj, &px, &py);
1068 evas_object_geometry_get(sd->pan_obj, NULL, NULL, &pw, &ph);
1071 if ((x < px) && ((x + w) < (px + (cw - mx)))) nx = x;
1072 else if ((x > px) && ((x + w) > (px + (cw - mx)))) nx = x + w - (cw - mx);
1074 if ((y < py) && ((y + h) < (py + (ch - my)))) ny = y;
1075 else if ((y > py) && ((y + h) > (py + (ch - my)))) ny = y + h - (ch - my);
1077 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1078 (sd->scrollto.x.animator) || (sd->scrollto.y.animator))
1080 _smart_anim_stop(sd->smart_obj);
1082 if (sd->scrollto.x.animator)
1084 ecore_animator_del(sd->scrollto.x.animator);
1085 sd->scrollto.x.animator = NULL;
1087 if (sd->scrollto.y.animator)
1089 ecore_animator_del(sd->scrollto.y.animator);
1090 sd->scrollto.y.animator = NULL;
1092 if (sd->down.bounce_x_animator)
1094 ecore_animator_del(sd->down.bounce_x_animator);
1095 sd->down.bounce_x_animator = NULL;
1098 if (sd->down.bounce_y_animator)
1100 ecore_animator_del(sd->down.bounce_y_animator);
1101 sd->down.bounce_y_animator = NULL;
1104 if (sd->down.hold_animator)
1106 ecore_animator_del(sd->down.hold_animator);
1107 sd->down.hold_animator = NULL;
1108 _smart_drag_stop(sd->smart_obj);
1110 if (sd->down.momentum_animator)
1112 ecore_animator_del(sd->down.momentum_animator);
1113 sd->down.momentum_animator = NULL;
1114 sd->down.bounce_x_hold = 0;
1115 sd->down.bounce_y_hold = 0;
1123 if ((x + pw) > cw) x = cw - pw;
1124 if (x < minx) x = minx;
1126 if ((y + ph) > ch) y = ch - ph;
1127 if (y < miny) y = miny;
1129 if ((x == px) && (y == py)) return EINA_FALSE;
1135 /* Set should be used for calculated positions, for example, when we move
1136 * because of an animation or because this is the correct position after
1139 elm_smart_scroller_child_region_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
1141 if (_elm_smart_scroller_child_region_show_internal(obj, &x, &y, w, h))
1142 elm_smart_scroller_child_pos_set(obj, x, y);
1145 /* Set should be used for setting the wanted position, for example a user scroll
1146 * or moving the cursor in an entry. */
1148 elm_smart_scroller_child_region_show(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
1155 if (_elm_smart_scroller_child_region_show_internal(obj, &x, &y, w, h))
1156 elm_smart_scroller_child_pos_set(obj, x, y);
1160 elm_smart_scroller_child_viewport_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
1163 if (!sd->pan_obj) return;
1164 edje_object_calc_force(sd->edje_obj);
1165 evas_object_geometry_get(sd->pan_obj, NULL, NULL, w, h);
1169 elm_smart_scroller_step_size_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
1176 _smart_scrollbar_size_adjust(sd);
1180 elm_smart_scroller_step_size_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
1183 if (x) *x = sd->step.x;
1184 if (y) *y = sd->step.y;
1188 elm_smart_scroller_page_size_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
1193 _smart_scrollbar_size_adjust(sd);
1197 elm_smart_scroller_page_size_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
1200 if (x) *x = sd->page.x;
1201 if (y) *y = sd->page.y;
1205 elm_smart_scroller_policy_set(Evas_Object *obj, Elm_Smart_Scroller_Policy hbar, Elm_Smart_Scroller_Policy vbar)
1208 if ((sd->hbar_flags == hbar) && (sd->vbar_flags == vbar)) return;
1209 sd->hbar_flags = hbar;
1210 sd->vbar_flags = vbar;
1211 if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
1212 edje_object_signal_emit(sd->edje_obj, "elm,action,show_always,hbar", "elm");
1213 else if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
1214 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,hbar", "elm");
1216 edje_object_signal_emit(sd->edje_obj, "elm,action,show_notalways,hbar", "elm");
1217 if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
1218 edje_object_signal_emit(sd->edje_obj, "elm,action,show_always,vbar", "elm");
1219 else if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
1220 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,vbar", "elm");
1222 edje_object_signal_emit(sd->edje_obj, "elm,action,show_notalways,vbar", "elm");
1223 _smart_scrollbar_size_adjust(sd);
1227 elm_smart_scroller_policy_get(Evas_Object *obj, Elm_Smart_Scroller_Policy *hbar, Elm_Smart_Scroller_Policy *vbar)
1230 if (hbar) *hbar = sd->hbar_flags;
1231 if (vbar) *vbar = sd->vbar_flags;
1235 elm_smart_scroller_edje_object_get(Evas_Object *obj)
1237 API_ENTRY return NULL;
1238 return sd->edje_obj;
1242 elm_smart_scroller_single_dir_set(Evas_Object *obj, Eina_Bool single_dir)
1245 sd->one_dir_at_a_time = single_dir;
1249 elm_smart_scroller_single_dir_get(Evas_Object *obj)
1251 API_ENTRY return EINA_FALSE;
1252 return sd->one_dir_at_a_time;
1256 elm_smart_scroller_propagate_events_set(Evas_Object *obj, Eina_Bool propagation)
1259 sd->event_propagation = propagation;
1261 evas_object_propagate_events_set(sd->edje_obj, propagation);
1265 elm_smart_scroller_propagate_events_get(Evas_Object *obj)
1267 API_ENTRY return EINA_FALSE;
1268 return sd->event_propagation;
1272 elm_smart_scroller_object_theme_set(Evas_Object *parent, Evas_Object *obj, const char *clas, const char *group, const char *style)
1276 //Does this API require parent object absolutely? if then remove this exception.
1277 double parent_scale = parent ? elm_widget_scale_get(parent) : 1;
1278 _elm_theme_object_set(parent, sd->edje_obj, clas, group, style);
1279 edje_object_scale_set(sd->edje_obj, parent_scale * _elm_config->scale);
1281 edje_object_part_swallow(sd->edje_obj, "elm.swallow.content", sd->pan_obj);
1283 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1284 if (edje_object_part_exists(sd->edje_obj, "elm.scrollbar.base"))
1287 base = edje_object_part_swallow_get(sd->edje_obj, "elm.scrollbar.base");
1290 base = evas_object_rectangle_add(evas_object_evas_get(sd->edje_obj));
1291 evas_object_color_set(base, 0, 0, 0, 0);
1292 edje_object_part_swallow(sd->edje_obj, "elm.scrollbar.base", base);
1294 if (!_elm_config->thumbscroll_enable)
1295 evas_object_size_hint_min_set(base, mw, mh);
1297 sd->vbar_visible = !sd->vbar_visible;
1298 sd->hbar_visible = !sd->hbar_visible;
1299 _smart_scrollbar_bar_visibility_adjust(sd);
1303 elm_smart_scroller_hold_set(Evas_Object *obj, Eina_Bool hold)
1310 elm_smart_scroller_freeze_set(Evas_Object *obj, Eina_Bool freeze)
1313 sd->freeze = freeze;
1316 if (sd->down.onhold_animator)
1318 ecore_animator_del(sd->down.onhold_animator);
1319 sd->down.onhold_animator = NULL;
1327 elm_smart_scroller_bounce_allow_set(Evas_Object *obj, Eina_Bool horiz, Eina_Bool vert)
1330 sd->bounce_horiz = horiz;
1331 sd->bounce_vert = vert;
1335 elm_smart_scroller_bounce_allow_get(const Evas_Object *obj, Eina_Bool *horiz, Eina_Bool *vert)
1338 if (horiz) *horiz = sd->bounce_horiz;
1339 if (vert) *vert = sd->bounce_vert;
1343 elm_smart_scroller_paging_set(Evas_Object *obj, double pagerel_h, double pagerel_v, Evas_Coord pagesize_h, Evas_Coord pagesize_v)
1346 sd->pagerel_h = pagerel_h;
1347 sd->pagerel_v = pagerel_v;
1348 sd->pagesize_h = pagesize_h;
1349 sd->pagesize_v = pagesize_v;
1350 _smart_page_adjust(sd);
1354 elm_smart_scroller_paging_get(Evas_Object *obj, double *pagerel_h, double *pagerel_v, Evas_Coord *pagesize_h, Evas_Coord *pagesize_v)
1357 if(pagerel_h) *pagerel_h = sd->pagerel_h;
1358 if(pagerel_v) *pagerel_v = sd->pagerel_v;
1359 if(pagesize_h) *pagesize_h = sd->pagesize_h;
1360 if(pagesize_v) *pagesize_v = sd->pagesize_v;
1364 elm_smart_scroller_region_bring_in(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
1367 if (_elm_smart_scroller_child_region_show_internal(obj, &x, &y, w, h))
1369 _smart_scrollto_x(sd, _elm_config->bring_in_scroll_friction, x);
1370 _smart_scrollto_y(sd, _elm_config->bring_in_scroll_friction, y);
1375 elm_smart_scroller_widget_set(Evas_Object *obj, Evas_Object *wid)
1382 _elm_smart_scroller_wanted_region_set(Evas_Object *obj)
1385 Evas_Coord ww, wh, wx = sd->wx;
1387 if (sd->down.now || sd->down.momentum_animator ||
1388 sd->down.bounce_x_animator || sd->down.bounce_y_animator ||
1389 sd->down.hold_animator || sd->down.onhold_animator) return;
1391 /* Flip to RTL cords only if init in RTL mode */
1393 wx = _elm_smart_scroller_x_mirrored_get(obj, sd->wx);
1397 elm_smart_scroller_child_viewport_size_get(obj, &ww, &wh);
1405 elm_smart_scroller_child_region_set(obj, wx, sd->wy, ww, wh);
1408 /* local subsystem functions */
1410 _smart_edje_drag_v_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1415 _smart_scrollbar_read(sd);
1416 _smart_drag_start(sd->smart_obj);
1417 sd->freeze = EINA_TRUE;
1421 _smart_edje_drag_v_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1426 _smart_scrollbar_read(sd);
1427 _smart_drag_stop(sd->smart_obj);
1428 sd->freeze = EINA_FALSE;
1432 _smart_edje_drag_v(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1437 _smart_scrollbar_read(sd);
1441 _smart_edje_drag_h_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1446 _smart_scrollbar_read(sd);
1447 _smart_drag_start(sd->smart_obj);
1448 sd->freeze = EINA_TRUE;
1452 _smart_edje_drag_h_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1457 _smart_scrollbar_read(sd);
1458 _smart_drag_stop(sd->smart_obj);
1459 sd->freeze = EINA_FALSE;
1463 _smart_edje_drag_h(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1468 _smart_scrollbar_read(sd);
1472 _smart_child_del_hook(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1477 sd->child_obj = NULL;
1478 _smart_scrollbar_size_adjust(sd);
1479 _smart_scrollbar_reset(sd);
1483 _smart_pan_changed_hook(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1489 sd->pan_func.child_size_get(sd->pan_obj, &w, &h);
1490 if ((w != sd->child.w) || (h != sd->child.h))
1494 _smart_scrollbar_size_adjust(sd);
1495 evas_object_size_hint_min_set(sd->smart_obj, sd->child.w, sd->child.h);
1496 _elm_smart_scroller_wanted_region_set(sd->smart_obj);
1501 _smart_pan_pan_changed_hook(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1506 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1507 (sd->scrollto.x.animator) || (sd->scrollto.y.animator))
1509 _smart_anim_stop(sd->smart_obj);
1511 if (sd->scrollto.x.animator)
1513 ecore_animator_del(sd->scrollto.x.animator);
1514 sd->scrollto.x.animator = NULL;
1516 if (sd->scrollto.y.animator)
1518 ecore_animator_del(sd->scrollto.y.animator);
1519 sd->scrollto.y.animator = NULL;
1521 if (sd->down.bounce_x_animator)
1523 ecore_animator_del(sd->down.bounce_x_animator);
1524 sd->down.bounce_x_animator = NULL;
1527 if (sd->down.bounce_y_animator)
1529 ecore_animator_del(sd->down.bounce_y_animator);
1530 sd->down.bounce_y_animator = NULL;
1533 _elm_smart_scroller_wanted_region_set(sd->smart_obj);
1537 _smart_event_wheel(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1539 Evas_Event_Mouse_Wheel *ev;
1541 Evas_Coord x = 0, y = 0;
1545 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
1546 if ((evas_key_modifier_is_set(ev->modifiers, "Control")) ||
1547 (evas_key_modifier_is_set(ev->modifiers, "Alt")) ||
1548 (evas_key_modifier_is_set(ev->modifiers, "Shift")) ||
1549 (evas_key_modifier_is_set(ev->modifiers, "Meta")) ||
1550 (evas_key_modifier_is_set(ev->modifiers, "Hyper")) ||
1551 (evas_key_modifier_is_set(ev->modifiers, "Super")))
1553 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1554 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1555 (sd->scrollto.x.animator) || (sd->scrollto.y.animator))
1557 _smart_anim_stop(sd->smart_obj);
1559 if (sd->scrollto.x.animator)
1561 ecore_animator_del(sd->scrollto.x.animator);
1562 sd->scrollto.x.animator = NULL;
1564 if (sd->scrollto.y.animator)
1566 ecore_animator_del(sd->scrollto.y.animator);
1567 sd->scrollto.y.animator = NULL;
1569 if (sd->down.bounce_x_animator)
1571 ecore_animator_del(sd->down.bounce_x_animator);
1572 sd->down.bounce_x_animator = NULL;
1575 if (sd->down.bounce_y_animator)
1577 ecore_animator_del(sd->down.bounce_y_animator);
1578 sd->down.bounce_y_animator = NULL;
1582 y += ev->z * sd->step.y;
1583 else if (ev->direction == 1)
1584 x += ev->z * sd->step.x;
1586 if ((!sd->hold) && (!sd->freeze))
1588 _update_wanted_coordinates(sd, x, y);
1589 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
1594 _smart_event_mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1596 Evas_Event_Mouse_Down *ev;
1598 Evas_Coord x = 0, y = 0;
1602 // if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
1603 if (_elm_config->thumbscroll_enable)
1606 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1607 (sd->down.momentum_animator) || (sd->scrollto.x.animator) ||
1608 (sd->scrollto.y.animator))
1610 ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL | EVAS_EVENT_FLAG_ON_HOLD;
1611 sd->down.scroll = 1;
1613 _smart_anim_stop(sd->smart_obj);
1615 if (sd->scrollto.x.animator)
1617 ecore_animator_del(sd->scrollto.x.animator);
1618 sd->scrollto.x.animator = NULL;
1620 if (sd->scrollto.y.animator)
1622 ecore_animator_del(sd->scrollto.y.animator);
1623 sd->scrollto.y.animator = NULL;
1625 if (sd->down.bounce_x_animator)
1627 ecore_animator_del(sd->down.bounce_x_animator);
1628 sd->down.bounce_x_animator = NULL;
1631 if (sd->down.bounce_y_animator)
1633 ecore_animator_del(sd->down.bounce_y_animator);
1634 sd->down.bounce_y_animator = NULL;
1637 if (sd->down.hold_animator)
1639 ecore_animator_del(sd->down.hold_animator);
1640 sd->down.hold_animator = NULL;
1641 _smart_drag_stop(sd->smart_obj);
1643 if (sd->down.momentum_animator)
1645 ecore_animator_del(sd->down.momentum_animator);
1646 sd->down.momentum_animator = NULL;
1647 sd->down.bounce_x_hold = 0;
1648 sd->down.bounce_y_hold = 0;
1652 if (ev->button == 1)
1654 sd->down.hist.est_timestamp_diff =
1655 ecore_loop_time_get() - ((double)ev->timestamp / 1000.0);
1656 sd->down.hist.tadd = 0.0;
1657 sd->down.hist.dxsum = 0.0;
1658 sd->down.hist.dysum = 0.0;
1660 sd->down.dragged = 0;
1663 sd->down.x = ev->canvas.x;
1664 sd->down.y = ev->canvas.y;
1665 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1668 sd->down.locked = 0;
1669 memset(&(sd->down.history[0]), 0, sizeof(sd->down.history[0]) * 60);
1671 sd->down.history[0].timestamp = ev->timestamp / 1000.0;
1672 sd->down.history[0].localtimestamp = ecore_loop_time_get();
1674 sd->down.history[0].timestamp = ecore_loop_time_get();
1676 sd->down.history[0].x = ev->canvas.x;
1677 sd->down.history[0].y = ev->canvas.y;
1679 sd->down.dragged_began = 0;
1680 sd->down.hold_parent = 0;
1681 sd->down.cancelled = 0;
1682 if(sd->hold || sd->freeze)
1683 sd->down.want_reset = 1;
1685 sd->down.want_reset = 0;
1690 _down_coord_eval(Smart_Data *sd, Evas_Coord *x, Evas_Coord *y)
1692 Evas_Coord minx, miny;
1694 if (sd->down.dir_x) *x = sd->down.sx - (*x - sd->down.x);
1695 else *x = sd->down.sx;
1696 if (sd->down.dir_y) *y = sd->down.sy - (*y - sd->down.y);
1697 else *y = sd->down.sy;
1699 if ((sd->down.dir_x) || (sd->down.dir_y))
1701 if (!((sd->down.dir_x) && (sd->down.dir_y)))
1703 if (sd->down.dir_x) *y = sd->down.locked_y;
1704 else *x = sd->down.locked_x;
1708 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
1711 *x += (minx - *x) * _elm_config->thumbscroll_border_friction;
1712 else if (sd->child.w <= sd->w)
1713 *x += (sd->down.sx - *x) * _elm_config->thumbscroll_border_friction;
1714 else if ((sd->child.w - sd->w + minx) < *x)
1715 *x += (sd->child.w - sd->w + minx - *x) *
1716 _elm_config->thumbscroll_border_friction;
1719 *y += (miny - *y) * _elm_config->thumbscroll_border_friction;
1720 else if (sd->child.h <= sd->h)
1721 *y += (sd->down.sy - *y) * _elm_config->thumbscroll_border_friction;
1722 else if ((sd->child.h - sd->h + miny) < *y)
1723 *y += (sd->child.h - sd->h + miny - *y) *
1724 _elm_config->thumbscroll_border_friction;
1728 _smart_hold_animator(void *data)
1730 Smart_Data *sd = data;
1731 Evas_Coord ox = 0, oy = 0, fx = 0, fy= 0;
1733 fx = sd->down.hold_x;
1734 fy = sd->down.hold_y;
1736 if ((!sd->hold) && (!sd->freeze) && (_elm_config->scroll_smooth_time_interval > 0.0))
1738 int i, count = 0; //count for the real event number we have to deal with
1739 int queue_size = 10; //for event queue size
1740 int src_index = 0, dst_index = 0;
1741 int xsum = 0, ysum=0;
1742 Evas_Coord x=0, y=0;
1750 double time_interval=_elm_config->scroll_smooth_time_interval;
1751 // FIXME: assume server and client have the same "timezone"
1752 // (0 timepoint) for now. this needs to be figured out in advance
1754 tdiff = sd->down.hist.est_timestamp_diff;
1755 tnow = ecore_time_get() - tdiff;
1757 for(i = 0; i < queue_size; i++)
1759 x = sd->down.history[i].x;
1760 y = sd->down.history[i].y;
1762 //if there is no history value , we don't deal with it
1763 //if there is better wat to know existance of history value , I will modify this code to it
1764 if ( (x == 0) && (y == 0) )
1768 _down_coord_eval(sd, &x, &y);
1772 pos[i].t = tnow - sd->down.history[i].timestamp;
1776 // we only deal with smooth scroll there is enough history
1777 for(i = 0; i < queue_size; i++)
1779 if (src_index > count) break;
1787 while ((pos[src_index].t < time_interval *i) &&
1788 (src_index <= count))
1792 if (src_index <= count)
1794 xsum += pos[src_index].x;
1795 ysum += pos[src_index].y;
1799 fx = xsum / dst_index;
1800 fy = ysum / dst_index;
1803 elm_smart_scroller_child_pos_get(sd->smart_obj, &ox, &oy);
1806 if ((!sd->widget) ||
1807 (!elm_widget_drag_child_locked_x_get(sd->widget)))
1814 if ((!sd->widget) ||
1815 (!elm_widget_drag_child_locked_y_get(sd->widget)))
1820 elm_smart_scroller_child_pos_set(sd->smart_obj, ox, oy);
1821 return ECORE_CALLBACK_RENEW;
1825 _smart_event_post_up(void *data, Evas *e __UNUSED__)
1827 Smart_Data *sd = data;
1830 if (sd->down.dragged)
1832 elm_widget_drag_lock_x_set(sd->widget, 0);
1833 elm_widget_drag_lock_y_set(sd->widget, 0);
1840 _smart_event_mouse_up(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *event_info)
1842 Evas_Event_Mouse_Down *ev;
1844 Evas_Coord x = 0, y = 0, ox = 0, oy = 0;
1845 Evas_Coord vw, vh, aw, ah;
1849 sd->down.hold_parent = 0;
1850 // if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
1851 evas_post_event_callback_push(e, _smart_event_post_up, sd);
1852 // FIXME: respect elm_widget_scroll_hold_get of parent container
1853 if (_elm_config->thumbscroll_enable)
1855 if (ev->button == 1)
1857 if (sd->down.onhold_animator)
1859 ecore_animator_del(sd->down.onhold_animator);
1860 sd->down.onhold_animator = NULL;
1862 x = ev->canvas.x - sd->down.x;
1863 y = ev->canvas.y - sd->down.y;
1864 if (sd->down.dragged)
1866 _smart_drag_stop(sd->smart_obj);
1867 if ((!sd->hold) && (!sd->freeze))
1871 Evas_Coord ax, ay, dx, dy, vel;
1874 t = ev->timestamp / 1000.0;
1876 t = ecore_loop_time_get();
1878 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1883 printf("------ %i %i\n", ev->canvas.x, ev->canvas.y);
1885 for (i = 0; i < 60; i++)
1887 dt = t - sd->down.history[i].timestamp;
1888 if (dt > 0.2) break;
1890 printf("H: %i %i @ %1.3f\n",
1891 sd->down.history[i].x,
1892 sd->down.history[i].y, dt);
1895 ax += sd->down.history[i].x;
1896 ay += sd->down.history[i].y;
1901 at *= 4.0; // magic number! just trial and error shows this makes it behave "nicer" and not run off at high speed all the time
1902 dx = ev->canvas.x - ax;
1903 dy = ev->canvas.y - ay;
1906 vel = sqrt((dx * dx) + (dy * dy)) / at;
1907 if ((_elm_config->thumbscroll_friction > 0.0) &&
1908 (vel > _elm_config->thumbscroll_momentum_threshold))
1910 int minx, miny, mx, my, px, py;
1911 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
1912 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
1913 sd->pan_func.get(sd->pan_obj, &px, &py);
1914 sd->down.dx = ((double)dx / at);
1915 sd->down.dy = ((double)dy / at);
1916 if (((sd->down.dx > 0) && (sd->down.pdx > 0)) ||
1917 ((sd->down.dx < 0) && (sd->down.pdx < 0)))
1918 if (px > minx && px < mx)
1919 sd->down.dx += (double)sd->down.pdx * 1.5; // FIXME: * 1.5 - probably should be config
1920 if (((sd->down.dy > 0) && (sd->down.pdy > 0)) ||
1921 ((sd->down.dy < 0) && (sd->down.pdy < 0)))
1922 if (py > miny && py < my)
1923 sd->down.dy += (double)sd->down.pdy * 1.5; // FIXME: * 1.5 - probably should be config
1924 if (((sd->down.dx > 0) && (sd->down.pdx > 0)) ||
1925 ((sd->down.dx < 0) && (sd->down.pdx < 0)) ||
1926 ((sd->down.dy > 0) && (sd->down.pdy > 0)) ||
1927 ((sd->down.dy < 0) && (sd->down.pdy < 0)))
1929 double t = ecore_loop_time_get();
1930 double dt = t - sd->down.anim_start;
1932 if (dt < 0.0) dt = 0.0;
1933 else if (dt > _elm_config->thumbscroll_friction)
1934 dt = _elm_config->thumbscroll_friction;
1935 sd->down.extra_time = _elm_config->thumbscroll_friction - dt;
1938 sd->down.extra_time = 0.0;
1939 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &vw, &vh);
1940 aw = abs(sd->down.dx);
1943 if (sd->down.dx > 0) sd->down.dx = vw*3;
1944 else sd->down.dx = -(vw*3);
1946 ah = abs(sd->down.dy);
1949 if (sd->down.dy > 0) sd->down.dy = vh*3;
1950 else sd->down.dy = -(vh*3);
1952 sd->down.pdx = sd->down.dx;
1953 sd->down.pdy = sd->down.dy;
1956 if (!_smart_do_page(sd))
1958 if ((!sd->down.momentum_animator) && (!sd->momentum_animator_disabled))
1960 sd->down.momentum_animator = ecore_animator_add(_smart_momentum_animator, sd);
1961 ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL;
1962 _smart_anim_start(sd->smart_obj);
1964 sd->down.anim_start = ecore_loop_time_get();
1965 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1973 if (sd->down.hold_animator)
1975 ecore_animator_del(sd->down.hold_animator);
1976 sd->down.hold_animator = NULL;
1984 evas_event_feed_hold(e, 0, ev->timestamp, ev->data);
1985 if (_smart_do_page(sd))
1987 Evas_Coord pgx, pgy;
1989 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1990 if ((!sd->widget) ||
1991 (!elm_widget_drag_child_locked_x_get(sd->widget)))
1993 pgx = _smart_page_x_get(sd, ox);
1996 ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL;
1997 _smart_scrollto_x(sd, _elm_config->page_scroll_friction, pgx);
2000 if ((!sd->widget) ||
2001 (!elm_widget_drag_child_locked_y_get(sd->widget)))
2003 pgy = _smart_page_y_get(sd, oy);
2006 ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL;
2007 _smart_scrollto_y(sd, _elm_config->page_scroll_friction, pgy);
2016 if (_smart_do_page(sd))
2018 Evas_Coord pgx, pgy;
2020 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
2021 if ((!sd->widget) ||
2022 (!elm_widget_drag_child_locked_x_get(sd->widget)))
2024 pgx = _smart_page_x_get(sd, ox);
2025 if (pgx != x) _smart_scrollto_x(sd, _elm_config->page_scroll_friction, pgx);
2027 if ((!sd->widget) ||
2028 (!elm_widget_drag_child_locked_y_get(sd->widget)))
2030 pgy = _smart_page_y_get(sd, oy);
2031 if (pgy != y) _smart_scrollto_y(sd, _elm_config->page_scroll_friction, pgy);
2034 if (sd->down.hold_animator)
2036 ecore_animator_del(sd->down.hold_animator);
2037 sd->down.hold_animator = NULL;
2040 if (sd->down.scroll)
2042 ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL;
2043 sd->down.scroll = 0;
2047 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2050 sd->down.dragged_began = 0;
2053 sd->down.want_dragged = 0;
2054 sd->down.dragged = 0;
2056 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
2057 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
2058 _update_wanted_coordinates(sd, x, y);
2060 if (!_smart_do_page(sd))
2067 _smart_onhold_animator(void *data)
2072 Evas_Coord x, y, ox, oy;
2075 t = ecore_loop_time_get();
2076 if (sd->down.onhold_tlast > 0.0)
2078 td = t - sd->down.onhold_tlast;
2079 vx = sd->down.onhold_vx * td * (double)_elm_config->thumbscroll_threshold * 2.0;
2080 vy = sd->down.onhold_vy * td * (double)_elm_config->thumbscroll_threshold * 2.0;
2081 elm_smart_scroller_child_pos_get(sd->smart_obj, &ox, &oy);
2087 if ((!sd->widget) ||
2088 (!elm_widget_drag_child_locked_x_get(sd->widget)))
2090 sd->down.onhold_vxe += vx;
2091 x = ox + (int)sd->down.onhold_vxe;
2092 sd->down.onhold_vxe -= (int)sd->down.onhold_vxe;
2098 if ((!sd->widget) ||
2099 (!elm_widget_drag_child_locked_y_get(sd->widget)))
2101 sd->down.onhold_vye += vy;
2102 y = oy + (int)sd->down.onhold_vye;
2103 sd->down.onhold_vye -= (int)sd->down.onhold_vye;
2107 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
2109 sd->down.onhold_tlast = t;
2110 return ECORE_CALLBACK_RENEW;
2114 _smart_event_post_move(void *data, Evas *e __UNUSED__)
2116 Smart_Data *sd = data;
2118 if (sd->down.want_dragged)
2122 if (sd->down.hold_parent)
2124 if ((sd->down.dir_x) && !can_scroll(sd, sd->down.hdir))
2128 if ((sd->down.dir_y) && !can_scroll(sd, sd->down.vdir))
2135 if ((!sd->widget) ||
2136 (!elm_widget_drag_child_locked_x_get(sd->widget)))
2138 sd->down.want_dragged = 0;
2139 sd->down.dragged = 1;
2142 elm_widget_drag_lock_x_set(sd->widget, 1);
2151 if ((!sd->widget) ||
2152 (!elm_widget_drag_child_locked_y_get(sd->widget)))
2154 sd->down.want_dragged = 0;
2155 sd->down.dragged = 1;
2158 elm_widget_drag_lock_y_set(sd->widget, 1);
2165 if ((!sd->down.dir_x) && (!sd->down.dir_y))
2167 sd->down.cancelled = 1;
2169 if (start) _smart_drag_start(sd->smart_obj);
2175 _smart_event_mouse_move(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *event_info)
2177 Evas_Event_Mouse_Move *ev;
2179 Evas_Coord x = 0, y = 0;
2183 // if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
2184 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) sd->down.hold_parent = 1;
2185 evas_post_event_callback_push(e, _smart_event_post_move, sd);
2186 // FIXME: respect elm_widget_scroll_hold_get of parent container
2187 if (_elm_config->thumbscroll_enable)
2194 printf("::: %i %i\n", ev->cur.canvas.x, ev->cur.canvas.y);
2196 memmove(&(sd->down.history[1]), &(sd->down.history[0]),
2197 sizeof(sd->down.history[0]) * (60 - 1));
2199 sd->down.history[0].timestamp = ev->timestamp / 1000.0;
2200 sd->down.history[0].localtimestamp = ecore_loop_time_get();
2202 sd->down.history[0].timestamp = ecore_loop_time_get();
2204 sd->down.history[0].x = ev->cur.canvas.x;
2205 sd->down.history[0].y = ev->cur.canvas.y;
2207 if (!sd->down.dragged_began)
2209 x = ev->cur.canvas.x - sd->down.x;
2210 y = ev->cur.canvas.y - sd->down.y;
2215 if (x > 0) sd->down.hdir = LEFT;
2216 else if (x < 0) sd->down.hdir = RIGHT;
2217 if (y > 0) sd->down.vdir = UP;
2218 else if (y < 0) sd->down.vdir = DOWN;
2223 if ((sd->one_dir_at_a_time) &&
2224 (!((sd->down.dir_x) || (sd->down.dir_y))))
2226 if (x > _elm_config->thumbscroll_threshold)
2235 if (y > _elm_config->thumbscroll_threshold)
2252 // can_scroll(sd, LEFT);
2253 // can_scroll(sd, RIGHT);
2254 // can_scroll(sd, UP);
2255 // can_scroll(sd, DOWN);
2260 if ((!sd->hold) && (!sd->freeze))
2262 if ((sd->down.dragged) ||
2263 (((x * x) + (y * y)) >
2264 (_elm_config->thumbscroll_threshold *
2265 _elm_config->thumbscroll_threshold)))
2267 sd->down.dragged_began = 1;
2268 if (!sd->down.dragged)
2270 sd->down.want_dragged = 1;
2271 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2272 // evas_event_feed_hold(e, 1, ev->timestamp, ev->data);
2273 // _smart_drag_start(sd->smart_obj);
2275 if (sd->down.dragged)
2277 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2279 // ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2280 // sd->down.dragged = 1;
2282 x = sd->down.sx - (ev->cur.canvas.x - sd->down.x);
2286 y = sd->down.sy - (ev->cur.canvas.y - sd->down.y);
2289 if(sd->down.want_reset)
2291 sd->down.x = ev->cur.canvas.x;
2292 sd->down.y = ev->cur.canvas.y;
2293 sd->down.want_reset = 0;
2295 if ((sd->down.dir_x) || (sd->down.dir_y))
2297 if (!sd->down.locked)
2299 sd->down.locked_x = x;
2300 sd->down.locked_y = y;
2301 sd->down.locked = 1;
2303 if (!((sd->down.dir_x) && (sd->down.dir_y)))
2305 if (sd->down.dir_x) y = sd->down.locked_y;
2306 else x = sd->down.locked_x;
2310 Evas_Coord minx, miny;
2311 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2314 _elm_config->thumbscroll_border_friction;
2315 else if (sd->child.h <= sd->h)
2316 y += (sd->down.sy - y) *
2317 _elm_config->thumbscroll_border_friction;
2318 else if ((sd->child.h - sd->h + miny) < y)
2319 y += (sd->child.h - sd->h + miny - y) *
2320 _elm_config->thumbscroll_border_friction;
2323 _elm_config->thumbscroll_border_friction;
2324 else if (sd->child.w <= sd->w)
2325 x += (sd->down.sx - x) *
2326 _elm_config->thumbscroll_border_friction;
2327 else if ((sd->child.w - sd->w + minx) < x)
2328 x += (sd->child.w - sd->w + minx - x) *
2329 _elm_config->thumbscroll_border_friction;
2332 sd->down.hold_x = x;
2333 sd->down.hold_y = y;
2334 if (!sd->down.hold_animator)
2335 sd->down.hold_animator =
2336 ecore_animator_add(_smart_hold_animator, sd);
2337 // printf("a %i %i\n", sd->down.hold_x, sd->down.hold_y);
2338 // _smart_onhold_animator(sd);
2339 // elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
2343 if (sd->down.dragged_began)
2345 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2349 evas_event_feed_hold(e, 1, ev->timestamp, ev->data);
2354 else if (!sd->freeze)
2356 Evas_Coord ex, ey, ew, eh;
2357 double vx = 0.0, vy = 0.0;
2359 evas_object_geometry_get(sd->event_obj, &ex, &ey, &ew, &eh);
2360 x = ev->cur.canvas.x - ex;
2361 y = ev->cur.canvas.y - ey;
2362 if (x < _elm_config->thumbscroll_threshold)
2364 if (_elm_config->thumbscroll_threshold > 0.0)
2365 vx = -(double)(_elm_config->thumbscroll_threshold - x) /
2366 _elm_config->thumbscroll_threshold;
2370 else if (x > (ew - _elm_config->thumbscroll_threshold))
2372 if (_elm_config->thumbscroll_threshold > 0.0)
2373 vx = (double)(_elm_config->thumbscroll_threshold - (ew - x)) /
2374 _elm_config->thumbscroll_threshold;
2378 if (y < _elm_config->thumbscroll_threshold)
2380 if (_elm_config->thumbscroll_threshold > 0.0)
2381 vy = -(double)(_elm_config->thumbscroll_threshold - y) /
2382 _elm_config->thumbscroll_threshold;
2386 else if (y > (eh - _elm_config->thumbscroll_threshold))
2388 if (_elm_config->thumbscroll_threshold > 0.0)
2389 vy = (double)(_elm_config->thumbscroll_threshold - (eh - y)) /
2390 _elm_config->thumbscroll_threshold;
2394 if ((vx != 0.0) || (vy != 0.0))
2396 sd->down.onhold_vx = vx;
2397 sd->down.onhold_vy = vy;
2398 if (!sd->down.onhold_animator)
2400 sd->down.onhold_vxe = 0.0;
2401 sd->down.onhold_vye = 0.0;
2402 sd->down.onhold_tlast = 0.0;
2403 sd->down.onhold_animator = ecore_animator_add(_smart_onhold_animator, sd);
2405 // printf("b %i %i\n", sd->down.hold_x, sd->down.hold_y);
2409 if (sd->down.onhold_animator)
2411 ecore_animator_del(sd->down.onhold_animator);
2412 sd->down.onhold_animator = NULL;
2421 _smart_scrollbar_read(Smart_Data *sd)
2423 Evas_Coord x, y, mx = 0, my = 0, px, py, minx = 0, miny = 0;
2426 edje_object_part_drag_value_get(sd->edje_obj, "elm.dragable.vbar", NULL, &vy);
2427 edje_object_part_drag_value_get(sd->edje_obj, "elm.dragable.hbar", &vx, NULL);
2428 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
2429 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2430 x = vx * (double)mx + minx;
2431 y = vy * (double)my + miny;
2432 sd->pan_func.get(sd->pan_obj, &px, &py);
2433 sd->pan_func.set(sd->pan_obj, x, y);
2434 if ((px != x) || (py != y))
2435 edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
2439 _smart_scrollbar_reset(Smart_Data *sd)
2441 Evas_Coord px = 0, py = 0, minx = 0, miny = 0;
2443 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.vbar", 0.0, 0.0);
2444 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.hbar", 0.0, 0.0);
2445 if ((!sd->child_obj) && (!sd->extern_pan))
2447 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.vbar", 1.0, 1.0);
2448 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.hbar", 1.0, 1.0);
2452 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2453 sd->pan_func.get(sd->pan_obj, &px, &py);
2454 sd->pan_func.set(sd->pan_obj, minx, miny);
2456 if ((px != minx) || (py != miny))
2457 edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
2461 _smart_scrollbar_bar_v_visibility_adjust(Smart_Data *sd)
2463 int scroll_v_vis_change = 0;
2464 Evas_Coord h, vw = 0, vh = 0;
2468 evas_object_geometry_get(sd->pan_obj, NULL, NULL, &vw, &vh);
2469 if (sd->vbar_visible)
2471 if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_AUTO)
2473 if ((sd->child_obj) || (sd->extern_pan))
2477 scroll_v_vis_change = 1;
2478 sd->vbar_visible = 0;
2483 scroll_v_vis_change = 1;
2484 sd->vbar_visible = 0;
2487 else if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
2489 scroll_v_vis_change = 1;
2490 sd->vbar_visible = 0;
2495 if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_AUTO)
2497 if ((sd->child_obj) || (sd->extern_pan))
2501 scroll_v_vis_change = 1;
2502 sd->vbar_visible = 1;
2506 else if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
2508 scroll_v_vis_change = 1;
2509 sd->vbar_visible = 1;
2512 if (scroll_v_vis_change)
2514 if (sd->vbar_flags != ELM_SMART_SCROLLER_POLICY_OFF)
2516 if (sd->vbar_visible)
2517 edje_object_signal_emit(sd->edje_obj, "elm,action,show,vbar", "elm");
2519 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,vbar", "elm");
2520 edje_object_message_signal_process(sd->edje_obj);
2521 _smart_scrollbar_size_adjust(sd);
2524 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,vbar", "elm");
2526 return scroll_v_vis_change;
2530 _smart_scrollbar_bar_h_visibility_adjust(Smart_Data *sd)
2532 int scroll_h_vis_change = 0;
2533 Evas_Coord w, vw = 0, vh = 0;
2537 evas_object_geometry_get(sd->pan_obj, NULL, NULL, &vw, &vh);
2538 if (sd->hbar_visible)
2540 if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_AUTO)
2542 if ((sd->child_obj) || (sd->extern_pan))
2546 scroll_h_vis_change = 1;
2547 sd->hbar_visible = 0;
2552 scroll_h_vis_change = 1;
2553 sd->hbar_visible = 0;
2556 else if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
2558 scroll_h_vis_change = 1;
2559 sd->hbar_visible = 0;
2564 if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_AUTO)
2566 if ((sd->child_obj) || (sd->extern_pan))
2570 scroll_h_vis_change = 1;
2571 sd->hbar_visible = 1;
2575 else if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
2577 scroll_h_vis_change = 1;
2578 sd->hbar_visible = 1;
2581 if (scroll_h_vis_change)
2583 if (sd->hbar_flags != ELM_SMART_SCROLLER_POLICY_OFF)
2585 if (sd->hbar_visible)
2586 edje_object_signal_emit(sd->edje_obj, "elm,action,show,hbar", "elm");
2588 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,hbar", "elm");
2589 edje_object_message_signal_process(sd->edje_obj);
2590 _smart_scrollbar_size_adjust(sd);
2593 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,hbar", "elm");
2594 _smart_scrollbar_size_adjust(sd);
2596 return scroll_h_vis_change;
2600 _smart_scrollbar_bar_visibility_adjust(Smart_Data *sd)
2604 changed |= _smart_scrollbar_bar_h_visibility_adjust(sd);
2605 changed |= _smart_scrollbar_bar_v_visibility_adjust(sd);
2608 _smart_scrollbar_bar_h_visibility_adjust(sd);
2609 _smart_scrollbar_bar_v_visibility_adjust(sd);
2614 _smart_scrollbar_size_adjust(Smart_Data *sd)
2616 if ((sd->child_obj) || (sd->extern_pan))
2618 Evas_Coord x, y, w, h, mx = 0, my = 0, vw = 0, vh = 0, px, py, minx = 0, miny = 0;
2619 double vx, vy, size;
2621 edje_object_part_geometry_get(sd->edje_obj, "elm.swallow.content",
2622 NULL, NULL, &vw, &vh);
2625 size = (double)vw / (double)w;
2629 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.hbar", 0.0, 0.0);
2631 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.hbar", size, 1.0);
2635 size = (double)vh / (double)h;
2639 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.vbar", 0.0, 0.0);
2641 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.vbar", 1.0, size);
2643 edje_object_part_drag_value_get(sd->edje_obj, "elm.dragable.hbar", &vx, NULL);
2644 edje_object_part_drag_value_get(sd->edje_obj, "elm.dragable.vbar", NULL, &vy);
2645 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
2646 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2650 edje_object_part_drag_step_set(sd->edje_obj, "elm.dragable.hbar", (double)sd->step.x / (double)w, 0.0);
2651 edje_object_part_drag_step_set(sd->edje_obj, "elm.dragable.vbar", 0.0, (double)sd->step.y / (double)h);
2653 edje_object_part_drag_page_set(sd->edje_obj, "elm.dragable.hbar", (double)sd->page.x / (double)w, 0.0);
2655 edje_object_part_drag_page_set(sd->edje_obj, "elm.dragable.hbar", -((double)sd->page.x * ((double)vw / (double)w)) / 100.0, 0.0);
2657 edje_object_part_drag_page_set(sd->edje_obj, "elm.dragable.vbar", 0.0, (double)sd->page.y / (double)h);
2659 edje_object_part_drag_page_set(sd->edje_obj, "elm.dragable.vbar", 0.0, -((double)sd->page.y * ((double)vh / (double)h)) / 100.0);
2661 sd->pan_func.get(sd->pan_obj, &px, &py);
2662 if (vx != mx) x = px;
2663 if (vy != my) y = py;
2664 sd->pan_func.set(sd->pan_obj, x, y);
2665 // if ((px != 0) || (py != 0))
2666 // edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
2670 Evas_Coord px = 0, py = 0, minx = 0, miny = 0;
2672 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.vbar", 1.0, 1.0);
2673 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.hbar", 1.0, 1.0);
2674 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2675 sd->pan_func.get(sd->pan_obj, &px, &py);
2676 sd->pan_func.set(sd->pan_obj, minx, miny);
2677 if ((px != minx) || (py != miny))
2678 edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
2680 _smart_scrollbar_bar_visibility_adjust(sd);
2684 _smart_reconfigure(Smart_Data *sd)
2686 evas_object_move(sd->edje_obj, sd->x, sd->y);
2687 evas_object_resize(sd->edje_obj, sd->w, sd->h);
2688 evas_object_move(sd->event_obj, sd->x, sd->y);
2689 evas_object_resize(sd->event_obj, sd->w, sd->h);
2690 _smart_scrollbar_size_adjust(sd);
2694 _smart_add(Evas_Object *obj)
2699 sd = calloc(1, sizeof(Smart_Data));
2701 evas_object_smart_data_set(obj, sd);
2703 sd->smart_obj = obj;
2712 sd->hbar_flags = ELM_SMART_SCROLLER_POLICY_AUTO;
2713 sd->vbar_flags = ELM_SMART_SCROLLER_POLICY_AUTO;
2714 sd->hbar_visible = 1;
2715 sd->vbar_visible = 1;
2717 sd->bounce_horiz = 1;
2718 sd->bounce_vert = 1;
2720 sd->one_dir_at_a_time = 1;
2721 sd->momentum_animator_disabled = EINA_FALSE;
2722 sd->bounce_animator_disabled = EINA_FALSE;
2724 o = edje_object_add(evas_object_evas_get(obj));
2725 evas_object_propagate_events_set(o, 0);
2727 elm_smart_scroller_object_theme_set(NULL, obj, "scroller", "base", "default");
2728 edje_object_signal_callback_add(o, "drag", "elm.dragable.vbar", _smart_edje_drag_v, sd);
2729 edje_object_signal_callback_add(o, "drag,start", "elm.dragable.vbar", _smart_edje_drag_v_start, sd);
2730 edje_object_signal_callback_add(o, "drag,stop", "elm.dragable.vbar", _smart_edje_drag_v_stop, sd);
2731 edje_object_signal_callback_add(o, "drag,step", "elm.dragable.vbar", _smart_edje_drag_v, sd);
2732 edje_object_signal_callback_add(o, "drag,page", "elm.dragable.vbar", _smart_edje_drag_v, sd);
2733 edje_object_signal_callback_add(o, "drag", "elm.dragable.hbar", _smart_edje_drag_h, sd);
2734 edje_object_signal_callback_add(o, "drag,start", "elm.dragable.hbar", _smart_edje_drag_h_start, sd);
2735 edje_object_signal_callback_add(o, "drag,stop", "elm.dragable.hbar", _smart_edje_drag_h_stop, sd);
2736 edje_object_signal_callback_add(o, "drag,step", "elm.dragable.hbar", _smart_edje_drag_h, sd);
2737 edje_object_signal_callback_add(o, "drag,page", "elm.dragable.hbar", _smart_edje_drag_h, sd);
2738 evas_object_smart_member_add(o, obj);
2740 o = evas_object_rectangle_add(evas_object_evas_get(obj));
2742 evas_object_color_set(o, 0, 0, 0, 0);
2743 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_WHEEL, _smart_event_wheel, sd);
2744 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, _smart_event_mouse_down, sd);
2745 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_UP, _smart_event_mouse_up, sd);
2746 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_MOVE, _smart_event_mouse_move, sd);
2747 evas_object_smart_member_add(o, obj);
2748 evas_object_repeat_events_set(o, 1);
2750 sd->pan_func.set = _elm_smart_pan_set;
2751 sd->pan_func.get = _elm_smart_pan_get;
2752 sd->pan_func.max_get = _elm_smart_pan_max_get;
2753 sd->pan_func.min_get = _elm_smart_pan_min_get;
2754 sd->pan_func.child_size_get = _elm_smart_pan_child_size_get;
2756 _smart_scrollbar_reset(sd);
2760 _smart_del(Evas_Object *obj)
2763 elm_smart_scroller_child_set(obj, NULL);
2764 if (!sd->extern_pan) evas_object_del(sd->pan_obj);
2765 evas_object_del(sd->edje_obj);
2766 evas_object_del(sd->event_obj);
2767 if (sd->down.hold_animator) ecore_animator_del(sd->down.hold_animator);
2768 if (sd->down.onhold_animator) ecore_animator_del(sd->down.onhold_animator);
2769 if (sd->down.momentum_animator) ecore_animator_del(sd->down.momentum_animator);
2770 if (sd->down.bounce_x_animator) ecore_animator_del(sd->down.bounce_x_animator);
2771 if (sd->down.bounce_y_animator) ecore_animator_del(sd->down.bounce_y_animator);
2772 if (sd->scrollto.x.animator) ecore_animator_del(sd->scrollto.x.animator);
2773 if (sd->scrollto.y.animator) ecore_animator_del(sd->scrollto.y.animator);
2775 evas_object_smart_data_set(obj, NULL);
2779 _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
2784 _smart_reconfigure(sd);
2788 _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
2793 _smart_reconfigure(sd);
2794 _elm_smart_scroller_wanted_region_set(obj);
2798 _smart_show(Evas_Object *obj)
2801 evas_object_show(sd->edje_obj);
2802 evas_object_show(sd->event_obj);
2806 _smart_hide(Evas_Object *obj)
2809 evas_object_hide(sd->edje_obj);
2810 evas_object_hide(sd->event_obj);
2814 _smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
2817 evas_object_color_set(sd->edje_obj, r, g, b, a);
2821 _smart_clip_set(Evas_Object *obj, Evas_Object *clip)
2824 evas_object_clip_set(sd->edje_obj, clip);
2825 evas_object_clip_set(sd->event_obj, clip);
2829 _smart_clip_unset(Evas_Object *obj)
2832 evas_object_clip_unset(sd->edje_obj);
2833 evas_object_clip_unset(sd->event_obj);
2836 /* never need to touch this */
2843 static const Evas_Smart_Class sc =
2846 EVAS_SMART_CLASS_VERSION,
2864 _smart = evas_smart_class_new(&sc);