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 est_timestamp_diff;
47 double onhold_vx, onhold_vy, onhold_tlast, onhold_vxe, onhold_vye;
49 Evas_Coord hold_x, hold_y;
50 Ecore_Animator *hold_animator;
51 Ecore_Animator *onhold_animator;
52 Ecore_Animator *momentum_animator;
53 Ecore_Animator *bounce_x_animator;
54 Ecore_Animator *bounce_y_animator;
55 Evas_Coord locked_x, locked_y;
57 unsigned char now : 1;
58 unsigned char cancelled : 1;
59 unsigned char hold : 1;
60 unsigned char hold_parent : 1;
61 unsigned char want_dragged : 1;
62 unsigned char dragged : 1;
63 unsigned char dragged_began : 1;
64 unsigned char dir_x : 1;
65 unsigned char dir_y : 1;
66 unsigned char locked : 1;
67 unsigned char bounce_x_hold : 1;
68 unsigned char bounce_y_hold : 1;
69 unsigned char scroll : 1;
70 unsigned char want_reset : 1;
81 void (*set) (Evas_Object *obj, Evas_Coord x, Evas_Coord y);
82 void (*get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y);
83 void (*max_get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y);
84 void (*min_get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y);
85 void (*child_size_get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y);
90 Evas_Coord start, end;
91 double t_start, t_end;
92 Ecore_Animator *animator;
96 double pagerel_h, pagerel_v;
97 Evas_Coord pagesize_h, pagesize_v;
99 unsigned char hbar_visible : 1;
100 unsigned char vbar_visible : 1;
101 unsigned char extern_pan : 1;
102 unsigned char one_dir_at_a_time : 1;
103 unsigned char hold : 1;
104 unsigned char freeze : 1;
105 unsigned char bouncemex : 1;
106 unsigned char bouncemey : 1;
107 unsigned char bounce_horiz : 1;
108 unsigned char bounce_vert : 1;
109 unsigned char momentum_animator_disabled :1;
110 unsigned char bounce_animator_disabled :1;
111 Eina_Bool is_mirrored : 1;
112 unsigned char event_propagation :1;
113 Eina_Bool wheel_disabled : 1;
116 /* local subsystem functions */
117 static void _smart_child_del_hook(void *data, Evas *e, Evas_Object *obj, void *event_info);
118 static void _smart_pan_changed_hook(void *data, Evas_Object *obj, void *event_info);
119 static void _smart_pan_pan_changed_hook(void *data, Evas_Object *obj, void *event_info);
120 static void _smart_event_wheel(void *data, Evas *e, Evas_Object *obj, void *event_info);
121 static void _smart_event_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info);
122 static Eina_Bool _smart_hold_animator(void *data);
123 static Eina_Bool _smart_momentum_animator(void *data);
124 static void _smart_event_mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info);
125 static Eina_Bool _smart_onhold_animator(void *data);
126 static void _smart_event_mouse_move(void *data, Evas *e, Evas_Object *obj, void *event_info);
127 static void _smart_edje_drag_v_start(void *data, Evas_Object *obj, const char *emission, const char *source);
128 static void _smart_edje_drag_v_stop(void *data, Evas_Object *obj, const char *emission, const char *source);
129 static void _smart_edje_drag_v(void *data, Evas_Object *obj, const char *emission, const char *source);
130 static void _smart_edje_drag_h_start(void *data, Evas_Object *obj, const char *emission, const char *source);
131 static void _smart_edje_drag_h_stop(void *data, Evas_Object *obj, const char *emission, const char *source);
132 static void _smart_edje_drag_h(void *data, Evas_Object *obj, const char *emission, const char *source);
133 static void _smart_scrollbar_read(Smart_Data *sd);
134 static void _smart_scrollbar_reset(Smart_Data *sd);
135 static int _smart_scrollbar_bar_h_visibility_adjust(Smart_Data *sd);
136 static int _smart_scrollbar_bar_v_visibility_adjust(Smart_Data *sd);
137 static void _smart_scrollbar_bar_visibility_adjust(Smart_Data *sd);
138 static void _smart_scrollbar_size_adjust(Smart_Data *sd);
139 static void _smart_reconfigure(Smart_Data *sd);
140 static void _smart_add(Evas_Object *obj);
141 static void _smart_del(Evas_Object *obj);
142 static void _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y);
143 static void _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h);
144 static void _smart_show(Evas_Object *obj);
145 static void _smart_hide(Evas_Object *obj);
146 static void _smart_color_set(Evas_Object *obj, int r, int g, int b, int a);
147 static void _smart_clip_set(Evas_Object *obj, Evas_Object *clip);
148 static void _smart_clip_unset(Evas_Object *obj);
149 static void _smart_init(void);
151 /* local subsystem globals */
152 static Evas_Smart *_smart = NULL;
154 /* externally accessible functions */
156 elm_smart_scroller_add(Evas *evas)
159 return evas_object_smart_add(evas, _smart);
163 _elm_smart_scroller_x_mirrored_get(Evas_Object *obj, Evas_Coord x)
167 Evas_Coord cw, ch, w, ret;
168 elm_smart_scroller_child_viewport_size_get(obj, &w, NULL);
169 sd->pan_func.child_size_get(sd->pan_obj, &cw, &ch);
170 ret = (cw - (x + w));
171 return (ret >= 0) ? ret : 0;
175 elm_smart_scroller_mirrored_set(Evas_Object *obj, Eina_Bool mirrored)
179 if (sd->is_mirrored == mirrored)
182 sd->is_mirrored = mirrored;
183 edje_object_mirrored_set(sd->edje_obj, mirrored);
186 wx = _elm_smart_scroller_x_mirrored_get(sd->smart_obj, sd->wx);
190 elm_smart_scroller_child_pos_set(sd->smart_obj, wx, sd->wy);
194 elm_smart_scroller_child_set(Evas_Object *obj, Evas_Object *child)
202 _elm_smart_pan_child_set(sd->pan_obj, NULL);
203 evas_object_event_callback_del_full(sd->child_obj, EVAS_CALLBACK_DEL, _smart_child_del_hook, sd);
206 sd->child_obj = child;
208 /* (-1) means want viewports size */
209 sd->ww = sd->wh = -1;
214 o = _elm_smart_pan_add(evas_object_evas_get(obj));
216 evas_object_smart_callback_add(o, "changed", _smart_pan_changed_hook, sd);
217 evas_object_smart_callback_add(o, "pan_changed", _smart_pan_pan_changed_hook, sd);
218 _elm_smart_pan_child_set(o, child);
219 edje_object_part_swallow(sd->edje_obj, "elm.swallow.content", o);
222 _elm_smart_pan_child_set(sd->pan_obj, child);
224 sd->pan_func.set = _elm_smart_pan_set;
225 sd->pan_func.get = _elm_smart_pan_get;
226 sd->pan_func.max_get = _elm_smart_pan_max_get;
227 sd->pan_func.min_get = _elm_smart_pan_min_get;
228 sd->pan_func.child_size_get = _elm_smart_pan_child_size_get;
230 evas_object_event_callback_add(child, EVAS_CALLBACK_DEL, _smart_child_del_hook, sd);
231 sd->pan_func.child_size_get(sd->pan_obj, &w, &h);
234 _smart_scrollbar_size_adjust(sd);
235 _smart_scrollbar_reset(sd);
239 elm_smart_scroller_extern_pan_set(Evas_Object *obj, Evas_Object *pan,
240 void (*pan_set) (Evas_Object *obj, Evas_Coord x, Evas_Coord y),
241 void (*pan_get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y),
242 void (*pan_max_get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y),
243 void (*pan_min_get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y),
244 void (*pan_child_size_get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y))
248 elm_smart_scroller_child_set(obj, NULL);
252 evas_object_smart_callback_del(sd->pan_obj, "changed", _smart_pan_changed_hook);
253 evas_object_smart_callback_del(sd->pan_obj, "pan_changed", _smart_pan_pan_changed_hook);
260 edje_object_part_unswallow(sd->edje_obj, sd->pan_obj);
268 evas_object_del(sd->pan_obj);
279 sd->pan_func.set = pan_set;
280 sd->pan_func.get = pan_get;
281 sd->pan_func.max_get = pan_max_get;
282 sd->pan_func.min_get = pan_min_get;
283 sd->pan_func.child_size_get = pan_child_size_get;
285 evas_object_smart_callback_add(sd->pan_obj, "changed", _smart_pan_changed_hook, sd);
286 evas_object_smart_callback_add(sd->pan_obj, "pan_changed", _smart_pan_pan_changed_hook, sd);
287 edje_object_part_swallow(sd->edje_obj, "elm.swallow.content", sd->pan_obj);
288 evas_object_show(sd->pan_obj);
292 elm_smart_scroller_custom_edje_file_set(Evas_Object *obj, char *file, char *group)
296 edje_object_file_set(sd->edje_obj, file, group);
298 edje_object_part_swallow(sd->edje_obj, "elm.swallow.content", sd->pan_obj);
299 sd->vbar_visible = !sd->vbar_visible;
300 sd->hbar_visible = !sd->hbar_visible;
301 _smart_scrollbar_bar_visibility_adjust(sd);
302 if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
303 edje_object_signal_emit(sd->edje_obj, "elm,action,show_always,hbar", "elm");
304 else if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
305 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,hbar", "elm");
307 edje_object_signal_emit(sd->edje_obj, "elm,action,show_notalways,hbar", "elm");
308 if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
309 edje_object_signal_emit(sd->edje_obj, "elm,action,show_always,vbar", "elm");
310 else if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
311 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,vbar", "elm");
313 edje_object_signal_emit(sd->edje_obj, "elm,action,show_notalways,vbar", "elm");
317 elm_smart_scroller_momentum_animator_disabled_get(Evas_Object *obj)
319 API_ENTRY return EINA_FALSE;
320 return sd->momentum_animator_disabled;
324 elm_smart_scroller_momentum_animator_disabled_set(Evas_Object *obj, Eina_Bool disabled)
327 sd->momentum_animator_disabled = disabled;
328 if (sd->momentum_animator_disabled)
330 if (sd->down.momentum_animator)
332 ecore_animator_del(sd->down.momentum_animator);
333 sd->down.momentum_animator = NULL;
339 elm_smart_scroller_bounce_animator_disabled_get(Evas_Object *obj)
341 API_ENTRY return EINA_FALSE;
342 return sd->bounce_animator_disabled;
346 elm_smart_scroller_bounce_animator_disabled_set(Evas_Object *obj, Eina_Bool disabled)
349 sd->bounce_animator_disabled = disabled;
350 if (sd->bounce_animator_disabled)
352 if (sd->scrollto.x.animator)
354 ecore_animator_del(sd->scrollto.x.animator);
355 sd->scrollto.x.animator = NULL;
358 if (sd->scrollto.y.animator)
360 ecore_animator_del(sd->scrollto.y.animator);
361 sd->scrollto.y.animator = NULL;
367 elm_smart_scroller_wheel_disabled_get(Evas_Object *obj)
369 API_ENTRY return EINA_FALSE;
370 return sd->wheel_disabled;
374 elm_smart_scroller_wheel_disabled_set(Evas_Object *obj, Eina_Bool disabled)
377 if ((!sd->wheel_disabled) && (disabled))
378 evas_object_event_callback_del_full(sd->event_obj, EVAS_CALLBACK_MOUSE_WHEEL, _smart_event_wheel, sd);
379 else if ((sd->wheel_disabled) && (!disabled))
380 evas_object_event_callback_add(sd->event_obj, EVAS_CALLBACK_MOUSE_WHEEL, _smart_event_wheel, sd);
381 sd->wheel_disabled = disabled;
384 /* Update the wanted coordinates according to the x, y passed
385 * widget directionality, child size and etc. */
387 _update_wanted_coordinates(Smart_Data *sd, Evas_Coord x, Evas_Coord y)
391 sd->pan_func.child_size_get(sd->pan_obj, &cw, &ch);
393 /* Update wx/y/w/h - and if the requested positions aren't legal
395 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &sd->ww, &sd->wh);
398 else if ((x + sd->ww) > cw)
399 sd->wx = cw - sd->ww;
400 else if (sd->is_mirrored)
401 sd->wx = _elm_smart_scroller_x_mirrored_get(sd->smart_obj, x);
404 if (y < 0) sd->wy = 0;
405 else if ((y + sd->wh) > ch) sd->wy = ch - sd->wh;
410 _smart_anim_start(Evas_Object *obj)
412 evas_object_smart_callback_call(obj, "animate,start", NULL);
416 _smart_anim_stop(Evas_Object *obj)
418 evas_object_smart_callback_call(obj, "animate,stop", NULL);
422 _smart_drag_start(Evas_Object *obj)
424 evas_object_smart_callback_call(obj, "drag,start", NULL);
428 _smart_drag_stop(Evas_Object *obj)
430 evas_object_smart_callback_call(obj, "drag,stop", NULL);
434 _smart_scrollto_x_animator(void *data)
436 Smart_Data *sd = data;
440 t = ecore_loop_time_get();
441 tt = (t - sd->scrollto.x.t_start) / (sd->scrollto.x.t_end - sd->scrollto.x.t_start);
443 tt = 1.0 - (tt * tt);
444 sd->pan_func.get(sd->pan_obj, &px, &py);
445 px = (sd->scrollto.x.start * (1.0 - tt)) +
446 (sd->scrollto.x.end * tt);
447 if (t >= sd->scrollto.x.t_end)
449 px = sd->scrollto.x.end;
450 elm_smart_scroller_child_pos_set(sd->smart_obj, px, py);
451 sd->scrollto.x.animator = NULL;
452 if ((!sd->scrollto.y.animator) && (!sd->down.bounce_y_animator))
453 _smart_anim_stop(sd->smart_obj);
454 return ECORE_CALLBACK_CANCEL;
456 elm_smart_scroller_child_pos_set(sd->smart_obj, px, py);
457 return ECORE_CALLBACK_RENEW;
461 _smart_momentum_end(Smart_Data *sd)
463 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator)) return;
464 if (sd->down.momentum_animator)
467 elm_smart_scroller_child_pos_get(sd->smart_obj, &px, &py);
468 _update_wanted_coordinates(sd, px, py);
470 ecore_animator_del(sd->down.momentum_animator);
471 sd->down.momentum_animator = NULL;
472 sd->down.bounce_x_hold = 0;
473 sd->down.bounce_y_hold = 0;
482 _smart_scrollto_x(Smart_Data *sd, double t_in, Evas_Coord pos_x)
484 Evas_Coord px, py, x, y, w, h;
487 if (sd->freeze) return;
490 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
491 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
493 elm_smart_scroller_child_region_set(sd->smart_obj, x, y, w, h);
496 t = ecore_loop_time_get();
497 sd->pan_func.get(sd->pan_obj, &px, &py);
498 sd->scrollto.x.start = px;
499 sd->scrollto.x.end = pos_x;
500 sd->scrollto.x.t_start = t;
501 sd->scrollto.x.t_end = t + t_in;
502 if (!sd->scrollto.x.animator)
504 sd->scrollto.x.animator = ecore_animator_add(_smart_scrollto_x_animator, sd);
505 if (!sd->scrollto.y.animator)
506 _smart_anim_start(sd->smart_obj);
508 if (sd->down.bounce_x_animator)
510 ecore_animator_del(sd->down.bounce_x_animator);
511 sd->down.bounce_x_animator = NULL;
512 _smart_momentum_end(sd);
518 _smart_scrollto_y_animator(void *data)
520 Smart_Data *sd = data;
524 t = ecore_loop_time_get();
525 tt = (t - sd->scrollto.y.t_start) / (sd->scrollto.y.t_end - sd->scrollto.y.t_start);
527 tt = 1.0 - (tt * tt);
528 sd->pan_func.get(sd->pan_obj, &px, &py);
529 py = (sd->scrollto.y.start * (1.0 - tt)) +
530 (sd->scrollto.y.end * tt);
531 if (t >= sd->scrollto.y.t_end)
533 py = sd->scrollto.y.end;
534 elm_smart_scroller_child_pos_set(sd->smart_obj, px, py);
535 sd->scrollto.y.animator = NULL;
536 if ((!sd->scrollto.x.animator) && (!sd->down.bounce_x_animator))
537 _smart_anim_stop(sd->smart_obj);
538 return ECORE_CALLBACK_CANCEL;
540 elm_smart_scroller_child_pos_set(sd->smart_obj, px, py);
542 return ECORE_CALLBACK_RENEW;
546 _smart_scrollto_y(Smart_Data *sd, double t_in, Evas_Coord pos_y)
548 Evas_Coord px, py, x, y, w, h;
551 if (sd->freeze) return;
554 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
555 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
557 elm_smart_scroller_child_region_set(sd->smart_obj, x, y, w, h);
560 t = ecore_loop_time_get();
561 sd->pan_func.get(sd->pan_obj, &px, &py);
562 sd->scrollto.y.start = py;
563 sd->scrollto.y.end = pos_y;
564 sd->scrollto.y.t_start = t;
565 sd->scrollto.y.t_end = t + t_in;
566 if (!sd->scrollto.y.animator)
568 sd->scrollto.y.animator = ecore_animator_add(_smart_scrollto_y_animator, sd);
569 if (!sd->scrollto.x.animator)
570 _smart_anim_start(sd->smart_obj);
572 if (sd->down.bounce_y_animator)
574 ecore_animator_del(sd->down.bounce_y_animator);
575 sd->down.bounce_y_animator = NULL;
576 _smart_momentum_end(sd);
582 _smart_do_page(Smart_Data *sd)
584 if ((sd->pagerel_h == 0.0) && (!sd->pagesize_h) &&
585 (sd->pagerel_v == 0.0) && (!sd->pagesize_v))
591 _smart_page_x_get(Smart_Data *sd, int offset)
593 Evas_Coord x, y, w, h, cw, ch, minx = 0;
595 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
596 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
597 sd->pan_func.child_size_get(sd->pan_obj, &cw, &ch);
598 sd->pan_func.min_get(sd->pan_obj, &minx, NULL);
602 if (sd->pagerel_h > 0.0)
604 x = x + (w * sd->pagerel_h * 0.5);
605 x = x / (w * sd->pagerel_h);
606 x = x * (w * sd->pagerel_h);
608 else if (sd->pagesize_h > 0)
610 x = x + (sd->pagesize_h * 0.5);
611 x = x / (sd->pagesize_h);
612 x = x * (sd->pagesize_h);
614 if ((x + w) > cw) x = cw - w;
615 if (x < minx) x = minx;
620 _smart_page_y_get(Smart_Data *sd, int offset)
622 Evas_Coord x, y, w, h, cw, ch, miny = 0;
624 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
625 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
626 sd->pan_func.child_size_get(sd->pan_obj, &cw, &ch);
627 sd->pan_func.min_get(sd->pan_obj, NULL, &miny);
631 if (sd->pagerel_v > 0.0)
633 y = y + (h * sd->pagerel_v * 0.5);
634 y = y / (h * sd->pagerel_v);
635 y = y * (h * sd->pagerel_v);
637 else if (sd->pagesize_v > 0)
639 y = y + (sd->pagesize_v * 0.5);
640 y = y / (sd->pagesize_v);
641 y = y * (sd->pagesize_v);
643 if ((y + h) > ch) y = ch - h;
644 if (y < miny) y = miny;
649 _smart_page_adjust(Smart_Data *sd)
651 Evas_Coord x, y, w, h;
653 if (!_smart_do_page(sd)) return;
655 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
657 x = _smart_page_x_get(sd, 0);
658 y = _smart_page_y_get(sd, 0);
660 elm_smart_scroller_child_region_set(sd->smart_obj, x, y, w, h);
664 _smart_bounce_x_animator(void *data)
667 Evas_Coord x, y, dx, px, w, odx, ed, md;
668 double t, p, dt, pd, r;
671 t = ecore_loop_time_get();
672 dt = t - sd->down.anim_start2;
675 dt = dt / _elm_config->thumbscroll_bounce_friction;
676 odx = sd->down.b2x - sd->down.bx;
677 sd->pan_func.get(sd->pan_obj, &px, NULL);
678 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, NULL);
679 if (!sd->down.momentum_animator && ((w - px) > 0) && ((-px) < w))
681 pd = (double)odx / (double)w;
682 pd = (pd > 0) ? pd : -pd;
683 pd = 1.0 - ((1.0 - pd) * (1.0 - pd));
686 if (dt > 1.0) dt = 1.0;
687 p = 1.0 - ((1.0 - dt) * (1.0 - dt));
688 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
691 if (sd->down.momentum_animator)
693 ed = abs(sd->down.dx * (_elm_config->thumbscroll_friction + sd->down.extra_time) - sd->down.b0x);
694 md = abs(_elm_config->thumbscroll_friction*5*w);
695 if (ed > md) r = (double)(md)/(double)ed;
697 x = sd->down.b2x + (int)((double)(dx - odx)*r);
698 if (!sd->down.cancelled)
699 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
702 if (sd->down.momentum_animator)
703 sd->down.bounce_x_hold = 1;
704 else if ((!sd->down.bounce_y_animator) &&
705 (!sd->scrollto.y.animator))
706 _smart_anim_stop(sd->smart_obj);
707 sd->down.bounce_x_animator = NULL;
710 _smart_momentum_end(sd);
711 return ECORE_CALLBACK_CANCEL;
714 return ECORE_CALLBACK_RENEW;
718 _smart_bounce_y_animator(void *data)
721 Evas_Coord x, y, dy, py, h, ody, ed, md;
722 double t, p, dt, pd, r;
725 t = ecore_loop_time_get();
726 dt = t - sd->down.anim_start3;
729 dt = dt / _elm_config->thumbscroll_bounce_friction;
730 ody = sd->down.b2y - sd->down.by;
731 sd->pan_func.get(sd->pan_obj, NULL, &py);
732 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, NULL, &h);
733 if (!sd->down.momentum_animator && ((h - py) > 0) && ((-py) < h))
735 pd = (double)ody / (double)h;
736 pd = (pd > 0) ? pd : -pd;
737 pd = 1.0 - ((1.0 - pd) * (1.0 - pd));
740 if (dt > 1.0) dt = 1.0;
741 p = 1.0 - ((1.0 - dt) * (1.0 - dt));
742 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
745 if (sd->down.momentum_animator)
747 ed = abs(sd->down.dy * (_elm_config->thumbscroll_friction + sd->down.extra_time) - sd->down.b0y);
748 md = abs(_elm_config->thumbscroll_friction*5*h);
749 if (ed > md) r = (double)(md)/(double)ed;
751 y = sd->down.b2y + (int)((double)(dy - ody)*r);
752 if (!sd->down.cancelled)
753 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
756 if (sd->down.momentum_animator)
757 sd->down.bounce_y_hold = 1;
758 else if ((!sd->down.bounce_x_animator) &&
759 (!sd->scrollto.y.animator))
760 _smart_anim_stop(sd->smart_obj);
761 sd->down.bounce_y_animator = NULL;
764 _smart_momentum_end(sd);
765 return ECORE_CALLBACK_CANCEL;
768 return ECORE_CALLBACK_RENEW;
776 can_scroll(Smart_Data *sd, int dir)
778 Evas_Coord mx = 0, my = 0, px = 0, py = 0, minx = 0, miny = 0;
780 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
781 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
782 sd->pan_func.get(sd->pan_obj, &px, &py);
786 if (px > minx) return EINA_TRUE;
789 if ((px - minx) < mx) return EINA_TRUE;
792 if (py > miny) return EINA_TRUE;
795 if ((py - miny) < my) return EINA_TRUE;
804 _smart_momentum_animator(void *data)
808 Evas_Coord x, y, dx, dy, px, py, maxx, maxy, minx, miny;
809 Eina_Bool no_bounce_x_end = EINA_FALSE, no_bounce_y_end = EINA_FALSE;
812 t = ecore_loop_time_get();
813 dt = t - sd->down.anim_start;
817 if (sd->down.hold_parent)
819 if ((sd->down.dir_x) && !can_scroll(sd, sd->down.hdir))
823 if ((sd->down.dir_y) && !can_scroll(sd, sd->down.vdir))
828 if ((!sd->down.dir_x) && (!sd->down.dir_y))
830 sd->down.cancelled = 1;
833 dt = dt / (_elm_config->thumbscroll_friction + sd->down.extra_time);
834 if (dt > 1.0) dt = 1.0;
835 p = 1.0 - ((1.0 - dt) * (1.0 - dt));
836 dx = (sd->down.dx * (_elm_config->thumbscroll_friction + sd->down.extra_time) * p);
837 dy = (sd->down.dy * (_elm_config->thumbscroll_friction + sd->down.extra_time) * p);
840 x = sd->down.sx - dx;
841 y = sd->down.sy - dy;
842 elm_smart_scroller_child_pos_get(sd->smart_obj, &px, &py);
843 if ((sd->down.bounce_x_animator) ||
844 (sd->down.bounce_x_hold))
846 sd->down.bx = sd->down.bx0 - dx + sd->down.b0x;
849 if ((sd->down.bounce_y_animator) ||
850 (sd->down.bounce_y_hold))
852 sd->down.by = sd->down.by0 - dy + sd->down.b0y;
855 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
856 _update_wanted_coordinates(sd, px, py);
857 sd->pan_func.max_get(sd->pan_obj, &maxx, &maxy);
858 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
859 if (!sd->bounce_horiz)
861 if (x <= minx) no_bounce_x_end = EINA_TRUE;
862 if ((x - minx) >= maxx) no_bounce_x_end = EINA_TRUE;
864 if (!sd->bounce_vert)
866 if (y <= miny) no_bounce_y_end = EINA_TRUE;
867 if ((y - miny) >= maxy) no_bounce_y_end = EINA_TRUE;
870 ((sd->down.bounce_x_hold) && (sd->down.bounce_y_hold)) ||
871 (no_bounce_x_end && no_bounce_y_end))
873 _smart_anim_stop(sd->smart_obj);
875 sd->down.momentum_animator = NULL;
876 sd->down.bounce_x_hold = 0;
877 sd->down.bounce_y_hold = 0;
882 return ECORE_CALLBACK_CANCEL;
885 return ECORE_CALLBACK_RENEW;
889 bounce_eval(Smart_Data *sd)
891 Evas_Coord mx, my, px, py, bx, by, b2x, b2y, minx = 0, miny = 0;
893 if (sd->freeze) return;
894 if ((!sd->bouncemex) && (!sd->bouncemey)) return;
895 if (sd->down.now) return; // down bounce while still held down
896 if (sd->down.onhold_animator)
898 ecore_animator_del(sd->down.onhold_animator);
899 sd->down.onhold_animator = NULL;
901 if (sd->down.hold_animator)
903 ecore_animator_del(sd->down.hold_animator);
904 sd->down.hold_animator = NULL;
906 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
907 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
908 sd->pan_func.get(sd->pan_obj, &px, &py);
911 if (px < minx) px = minx;
912 if ((px - minx) > mx) px = mx + minx;
913 if (py < miny) py = miny;
914 if ((py - miny) > my) py = my + miny;
918 (!elm_widget_drag_child_locked_x_get(sd->widget)))
920 if (!sd->down.bounce_x_animator && !sd->bounce_animator_disabled)
924 if (sd->scrollto.x.animator)
926 ecore_animator_del(sd->scrollto.x.animator);
927 sd->scrollto.x.animator = NULL;
929 sd->down.bounce_x_animator = ecore_animator_add(_smart_bounce_x_animator, sd);
930 sd->down.anim_start2 = ecore_loop_time_get();
934 if (sd->down.momentum_animator) sd->down.b0x = sd->down.ax;
935 else sd->down.b0x = 0;
940 (!elm_widget_drag_child_locked_y_get(sd->widget)))
942 if (!sd->down.bounce_y_animator && !sd->bounce_animator_disabled)
946 if (sd->scrollto.y.animator)
948 ecore_animator_del(sd->scrollto.y.animator);
949 sd->scrollto.y.animator = NULL;
951 sd->down.bounce_y_animator = ecore_animator_add(_smart_bounce_y_animator, sd);
952 sd->down.anim_start3 = ecore_loop_time_get();
956 if (sd->down.momentum_animator) sd->down.b0y = sd->down.ay;
957 else sd->down.b0y = 0;
964 elm_smart_scroller_child_pos_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
966 Evas_Coord mx = 0, my = 0, px = 0, py = 0, minx = 0, miny = 0;
970 // FIXME: allow for bounce outside of range
971 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
972 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
973 if (mx > 0) vx = (double)(x - minx) / (double)mx;
975 if (vx < 0.0) vx = 0.0;
976 else if (vx > 1.0) vx = 1.0;
977 if (my > 0) vy = (double)(y - miny) / (double)my;
979 if (vy < 0.0) vy = 0.0;
980 else if (vy > 1.0) vy = 1.0;
981 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.vbar", 0.0, vy);
982 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.hbar", vx, 0.0);
983 sd->pan_func.get(sd->pan_obj, &px, &py);
984 if (!_elm_config->thumbscroll_bounce_enable)
986 if (x < minx) x = minx;
987 if ((x - minx) > mx) x = mx + minx;
988 if (y < miny) y = miny;
989 if ((y - miny) > my) y = my + miny;
992 if (!sd->bounce_horiz)
994 if (x < minx) x = minx;
995 if ((x - minx) > mx) x = mx + minx;
997 if (!sd->bounce_vert)
999 if (y < miny) y = miny;
1000 if (y - miny > my) y = my + miny;
1003 sd->pan_func.set(sd->pan_obj, x, y);
1004 if ((px != x) || (py != y))
1005 edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
1006 if (!sd->down.bounce_x_animator)
1008 if ((x < minx) || (x > (mx + minx)))
1014 if (!sd->down.bounce_y_animator)
1016 if ((y < miny) || (y > my + miny))
1022 if ((x != px) || (y != py))
1024 evas_object_smart_callback_call(obj, "scroll", NULL);
1026 if ((x != px)/* && (!sd->bouncemex)*/)
1029 evas_object_smart_callback_call(obj, "edge,left", NULL);
1030 if (x == (mx + minx))
1031 evas_object_smart_callback_call(obj, "edge,right", NULL);
1033 if ((y != py)/* && (!sd->bouncemey)*/)
1036 evas_object_smart_callback_call(obj, "edge,top", NULL);
1038 evas_object_smart_callback_call(obj, "edge,bottom", NULL);
1043 elm_smart_scroller_child_pos_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
1046 sd->pan_func.get(sd->pan_obj, x, y);
1049 /* returns TRUE when we need to move the scroller, FALSE otherwise.
1050 * Updates w and h either way, so save them if you need them. */
1052 _elm_smart_scroller_child_region_show_internal(Evas_Object *obj, Evas_Coord *_x, Evas_Coord *_y, Evas_Coord w, Evas_Coord h)
1054 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;
1056 API_ENTRY return EINA_FALSE;
1057 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
1058 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
1059 sd->pan_func.child_size_get(sd->pan_obj, &cw, &ch);
1060 sd->pan_func.get(sd->pan_obj, &px, &py);
1061 evas_object_geometry_get(sd->pan_obj, NULL, NULL, &pw, &ph);
1064 if ((x < px) && ((x + w) < (px + (cw - mx)))) nx = x;
1065 else if ((x > px) && ((x + w) > (px + (cw - mx)))) nx = x + w - (cw - mx);
1067 if ((y < py) && ((y + h) < (py + (ch - my)))) ny = y;
1068 else if ((y > py) && ((y + h) > (py + (ch - my)))) ny = y + h - (ch - my);
1070 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1071 (sd->scrollto.x.animator) || (sd->scrollto.y.animator))
1073 _smart_anim_stop(sd->smart_obj);
1075 if (sd->scrollto.x.animator)
1077 ecore_animator_del(sd->scrollto.x.animator);
1078 sd->scrollto.x.animator = NULL;
1080 if (sd->scrollto.y.animator)
1082 ecore_animator_del(sd->scrollto.y.animator);
1083 sd->scrollto.y.animator = NULL;
1085 if (sd->down.bounce_x_animator)
1087 ecore_animator_del(sd->down.bounce_x_animator);
1088 sd->down.bounce_x_animator = NULL;
1091 if (sd->down.bounce_y_animator)
1093 ecore_animator_del(sd->down.bounce_y_animator);
1094 sd->down.bounce_y_animator = NULL;
1097 if (sd->down.hold_animator)
1099 ecore_animator_del(sd->down.hold_animator);
1100 sd->down.hold_animator = NULL;
1101 _smart_drag_stop(sd->smart_obj);
1103 if (sd->down.momentum_animator)
1105 ecore_animator_del(sd->down.momentum_animator);
1106 sd->down.momentum_animator = NULL;
1107 sd->down.bounce_x_hold = 0;
1108 sd->down.bounce_y_hold = 0;
1116 if ((x + pw) > cw) x = cw - pw;
1117 if (x < minx) x = minx;
1119 if ((y + ph) > ch) y = ch - ph;
1120 if (y < miny) y = miny;
1122 if ((x == px) && (y == py)) return EINA_FALSE;
1128 /* Set should be used for calculated positions, for example, when we move
1129 * because of an animation or because this is the correct position after
1132 elm_smart_scroller_child_region_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
1134 if (_elm_smart_scroller_child_region_show_internal(obj, &x, &y, w, h))
1135 elm_smart_scroller_child_pos_set(obj, x, y);
1138 /* Set should be used for setting the wanted position, for example a user scroll
1139 * or moving the cursor in an entry. */
1141 elm_smart_scroller_child_region_show(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
1148 if (_elm_smart_scroller_child_region_show_internal(obj, &x, &y, w, h))
1149 elm_smart_scroller_child_pos_set(obj, x, y);
1153 elm_smart_scroller_child_viewport_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
1156 if (!sd->pan_obj) return;
1157 edje_object_calc_force(sd->edje_obj);
1158 evas_object_geometry_get(sd->pan_obj, NULL, NULL, w, h);
1162 elm_smart_scroller_step_size_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
1169 _smart_scrollbar_size_adjust(sd);
1173 elm_smart_scroller_step_size_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
1176 if (x) *x = sd->step.x;
1177 if (y) *y = sd->step.y;
1181 elm_smart_scroller_page_size_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
1186 _smart_scrollbar_size_adjust(sd);
1190 elm_smart_scroller_page_size_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
1193 if (x) *x = sd->page.x;
1194 if (y) *y = sd->page.y;
1198 elm_smart_scroller_policy_set(Evas_Object *obj, Elm_Smart_Scroller_Policy hbar, Elm_Smart_Scroller_Policy vbar)
1201 if ((sd->hbar_flags == hbar) && (sd->vbar_flags == vbar)) return;
1202 sd->hbar_flags = hbar;
1203 sd->vbar_flags = vbar;
1204 if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
1205 edje_object_signal_emit(sd->edje_obj, "elm,action,show_always,hbar", "elm");
1206 else if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
1207 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,hbar", "elm");
1209 edje_object_signal_emit(sd->edje_obj, "elm,action,show_notalways,hbar", "elm");
1210 if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
1211 edje_object_signal_emit(sd->edje_obj, "elm,action,show_always,vbar", "elm");
1212 else if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
1213 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,vbar", "elm");
1215 edje_object_signal_emit(sd->edje_obj, "elm,action,show_notalways,vbar", "elm");
1216 _smart_scrollbar_size_adjust(sd);
1220 elm_smart_scroller_policy_get(Evas_Object *obj, Elm_Smart_Scroller_Policy *hbar, Elm_Smart_Scroller_Policy *vbar)
1223 if (hbar) *hbar = sd->hbar_flags;
1224 if (vbar) *vbar = sd->vbar_flags;
1228 elm_smart_scroller_edje_object_get(Evas_Object *obj)
1230 API_ENTRY return NULL;
1231 return sd->edje_obj;
1235 elm_smart_scroller_single_dir_set(Evas_Object *obj, Eina_Bool single_dir)
1238 sd->one_dir_at_a_time = single_dir;
1242 elm_smart_scroller_single_dir_get(Evas_Object *obj)
1244 API_ENTRY return EINA_FALSE;
1245 return sd->one_dir_at_a_time;
1249 elm_smart_scroller_propagate_events_set(Evas_Object *obj, Eina_Bool propagation)
1252 sd->event_propagation = propagation;
1254 evas_object_propagate_events_set(sd->edje_obj, propagation);
1258 elm_smart_scroller_propagate_events_get(Evas_Object *obj)
1260 API_ENTRY return EINA_FALSE;
1261 return sd->event_propagation;
1265 elm_smart_scroller_object_theme_set(Evas_Object *parent, Evas_Object *obj, const char *clas, const char *group, const char *style)
1269 //Does this API require parent object absolutely? if then remove this exception.
1270 double parent_scale = parent ? elm_widget_scale_get(parent) : 1;
1271 _elm_theme_object_set(parent, sd->edje_obj, clas, group, style);
1272 edje_object_scale_set(sd->edje_obj, parent_scale * _elm_config->scale);
1274 edje_object_part_swallow(sd->edje_obj, "elm.swallow.content", sd->pan_obj);
1276 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1277 if (edje_object_part_exists(sd->edje_obj, "elm.scrollbar.base"))
1280 base = edje_object_part_swallow_get(sd->edje_obj, "elm.scrollbar.base");
1283 base = evas_object_rectangle_add(evas_object_evas_get(sd->edje_obj));
1284 evas_object_color_set(base, 0, 0, 0, 0);
1285 edje_object_part_swallow(sd->edje_obj, "elm.scrollbar.base", base);
1287 if (!_elm_config->thumbscroll_enable)
1288 evas_object_size_hint_min_set(base, mw, mh);
1290 sd->vbar_visible = !sd->vbar_visible;
1291 sd->hbar_visible = !sd->hbar_visible;
1292 _smart_scrollbar_bar_visibility_adjust(sd);
1296 elm_smart_scroller_hold_set(Evas_Object *obj, Eina_Bool hold)
1303 elm_smart_scroller_freeze_set(Evas_Object *obj, Eina_Bool freeze)
1306 sd->freeze = freeze;
1309 if (sd->down.onhold_animator)
1311 ecore_animator_del(sd->down.onhold_animator);
1312 sd->down.onhold_animator = NULL;
1320 elm_smart_scroller_bounce_allow_set(Evas_Object *obj, Eina_Bool horiz, Eina_Bool vert)
1323 sd->bounce_horiz = horiz;
1324 sd->bounce_vert = vert;
1328 elm_smart_scroller_bounce_allow_get(const Evas_Object *obj, Eina_Bool *horiz, Eina_Bool *vert)
1331 *horiz = sd->bounce_horiz;
1332 *vert = sd->bounce_vert;
1336 elm_smart_scroller_paging_set(Evas_Object *obj, double pagerel_h, double pagerel_v, Evas_Coord pagesize_h, Evas_Coord pagesize_v)
1339 sd->pagerel_h = pagerel_h;
1340 sd->pagerel_v = pagerel_v;
1341 sd->pagesize_h = pagesize_h;
1342 sd->pagesize_v = pagesize_v;
1343 if (sd->child_obj) _smart_page_adjust(sd);
1347 elm_smart_scroller_paging_get(Evas_Object *obj, double *pagerel_h, double *pagerel_v, Evas_Coord *pagesize_h, Evas_Coord *pagesize_v)
1350 if(pagerel_h) *pagerel_h = sd->pagerel_h;
1351 if(pagerel_v) *pagerel_v = sd->pagerel_v;
1352 if(pagesize_h) *pagesize_h = sd->pagesize_h;
1353 if(pagesize_v) *pagesize_v = sd->pagesize_v;
1357 elm_smart_scroller_region_bring_in(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
1360 if (_elm_smart_scroller_child_region_show_internal(obj, &x, &y, w, h))
1362 _smart_scrollto_x(sd, _elm_config->bring_in_scroll_friction, x);
1363 _smart_scrollto_y(sd, _elm_config->bring_in_scroll_friction, y);
1368 elm_smart_scroller_widget_set(Evas_Object *obj, Evas_Object *wid)
1375 _elm_smart_scroller_wanted_region_set(Evas_Object *obj)
1378 Evas_Coord ww, wh, wx = sd->wx;
1380 if (sd->down.now || sd->down.momentum_animator ||
1381 sd->down.bounce_x_animator || sd->down.bounce_y_animator ||
1382 sd->down.hold_animator || sd->down.onhold_animator) return;
1384 /* Flip to RTL cords only if init in RTL mode */
1386 wx = _elm_smart_scroller_x_mirrored_get(obj, sd->wx);
1390 elm_smart_scroller_child_viewport_size_get(obj, &ww, &wh);
1398 elm_smart_scroller_child_region_set(obj, wx, sd->wy, ww, wh);
1401 /* local subsystem functions */
1403 _smart_edje_drag_v_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1408 _smart_scrollbar_read(sd);
1409 _smart_drag_start(sd->smart_obj);
1410 sd->freeze = EINA_TRUE;
1414 _smart_edje_drag_v_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1419 _smart_scrollbar_read(sd);
1420 _smart_drag_stop(sd->smart_obj);
1421 sd->freeze = EINA_FALSE;
1425 _smart_edje_drag_v(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1430 _smart_scrollbar_read(sd);
1434 _smart_edje_drag_h_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1439 _smart_scrollbar_read(sd);
1440 _smart_drag_start(sd->smart_obj);
1441 sd->freeze = EINA_TRUE;
1445 _smart_edje_drag_h_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1450 _smart_scrollbar_read(sd);
1451 _smart_drag_stop(sd->smart_obj);
1452 sd->freeze = EINA_FALSE;
1456 _smart_edje_drag_h(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1461 _smart_scrollbar_read(sd);
1465 _smart_child_del_hook(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1470 sd->child_obj = NULL;
1471 _smart_scrollbar_size_adjust(sd);
1472 _smart_scrollbar_reset(sd);
1476 _smart_pan_changed_hook(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1482 sd->pan_func.child_size_get(sd->pan_obj, &w, &h);
1483 if ((w != sd->child.w) || (h != sd->child.h))
1487 _smart_scrollbar_size_adjust(sd);
1488 evas_object_size_hint_min_set(sd->smart_obj, sd->child.w, sd->child.h);
1489 _elm_smart_scroller_wanted_region_set(sd->smart_obj);
1494 _smart_pan_pan_changed_hook(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1499 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1500 (sd->scrollto.x.animator) || (sd->scrollto.y.animator))
1502 _smart_anim_stop(sd->smart_obj);
1504 if (sd->scrollto.x.animator)
1506 ecore_animator_del(sd->scrollto.x.animator);
1507 sd->scrollto.x.animator = NULL;
1509 if (sd->scrollto.y.animator)
1511 ecore_animator_del(sd->scrollto.y.animator);
1512 sd->scrollto.y.animator = NULL;
1514 if (sd->down.bounce_x_animator)
1516 ecore_animator_del(sd->down.bounce_x_animator);
1517 sd->down.bounce_x_animator = NULL;
1520 if (sd->down.bounce_y_animator)
1522 ecore_animator_del(sd->down.bounce_y_animator);
1523 sd->down.bounce_y_animator = NULL;
1526 _elm_smart_scroller_wanted_region_set(sd->smart_obj);
1530 _smart_event_wheel(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1532 Evas_Event_Mouse_Wheel *ev;
1534 Evas_Coord x = 0, y = 0;
1538 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
1539 if ((evas_key_modifier_is_set(ev->modifiers, "Control")) ||
1540 (evas_key_modifier_is_set(ev->modifiers, "Alt")) ||
1541 (evas_key_modifier_is_set(ev->modifiers, "Shift")) ||
1542 (evas_key_modifier_is_set(ev->modifiers, "Meta")) ||
1543 (evas_key_modifier_is_set(ev->modifiers, "Hyper")) ||
1544 (evas_key_modifier_is_set(ev->modifiers, "Super")))
1546 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1547 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1548 (sd->scrollto.x.animator) || (sd->scrollto.y.animator))
1550 _smart_anim_stop(sd->smart_obj);
1552 if (sd->scrollto.x.animator)
1554 ecore_animator_del(sd->scrollto.x.animator);
1555 sd->scrollto.x.animator = NULL;
1557 if (sd->scrollto.y.animator)
1559 ecore_animator_del(sd->scrollto.y.animator);
1560 sd->scrollto.y.animator = NULL;
1562 if (sd->down.bounce_x_animator)
1564 ecore_animator_del(sd->down.bounce_x_animator);
1565 sd->down.bounce_x_animator = NULL;
1568 if (sd->down.bounce_y_animator)
1570 ecore_animator_del(sd->down.bounce_y_animator);
1571 sd->down.bounce_y_animator = NULL;
1575 y += ev->z * sd->step.y;
1576 else if (ev->direction == 1)
1577 x += ev->z * sd->step.x;
1579 if ((!sd->hold) && (!sd->freeze))
1581 _update_wanted_coordinates(sd, x, y);
1582 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
1587 _smart_event_mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1589 Evas_Event_Mouse_Down *ev;
1591 Evas_Coord x = 0, y = 0;
1595 // if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
1596 if (_elm_config->thumbscroll_enable)
1599 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1600 (sd->down.momentum_animator) || (sd->scrollto.x.animator) ||
1601 (sd->scrollto.y.animator))
1603 ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL | EVAS_EVENT_FLAG_ON_HOLD;
1604 sd->down.scroll = 1;
1606 _smart_anim_stop(sd->smart_obj);
1608 if (sd->scrollto.x.animator)
1610 ecore_animator_del(sd->scrollto.x.animator);
1611 sd->scrollto.x.animator = NULL;
1613 if (sd->scrollto.y.animator)
1615 ecore_animator_del(sd->scrollto.y.animator);
1616 sd->scrollto.y.animator = NULL;
1618 if (sd->down.bounce_x_animator)
1620 ecore_animator_del(sd->down.bounce_x_animator);
1621 sd->down.bounce_x_animator = NULL;
1624 if (sd->down.bounce_y_animator)
1626 ecore_animator_del(sd->down.bounce_y_animator);
1627 sd->down.bounce_y_animator = NULL;
1630 if (sd->down.hold_animator)
1632 ecore_animator_del(sd->down.hold_animator);
1633 sd->down.hold_animator = NULL;
1634 _smart_drag_stop(sd->smart_obj);
1636 if (sd->down.momentum_animator)
1638 ecore_animator_del(sd->down.momentum_animator);
1639 sd->down.momentum_animator = NULL;
1640 sd->down.bounce_x_hold = 0;
1641 sd->down.bounce_y_hold = 0;
1645 if (ev->button == 1)
1647 sd->down.hist.est_timestamp_diff =
1648 ecore_loop_time_get() - ((double)ev->timestamp / 1000.0);
1650 sd->down.dragged = 0;
1653 sd->down.x = ev->canvas.x;
1654 sd->down.y = ev->canvas.y;
1655 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1658 sd->down.locked = 0;
1659 memset(&(sd->down.history[0]), 0, sizeof(sd->down.history[0]) * 20);
1661 sd->down.history[0].timestamp = ev->timestamp / 1000.0;
1662 sd->down.history[0].localtimestamp = ecore_loop_time_get();
1664 sd->down.history[0].timestamp = ecore_loop_time_get();
1666 sd->down.history[0].x = ev->canvas.x;
1667 sd->down.history[0].y = ev->canvas.y;
1669 sd->down.dragged_began = 0;
1670 sd->down.hold_parent = 0;
1671 sd->down.cancelled = 0;
1672 if(sd->hold || sd->freeze)
1673 sd->down.want_reset = 1;
1675 sd->down.want_reset = 0;
1680 _down_coord_eval(Smart_Data *sd, Evas_Coord *x, Evas_Coord *y)
1682 Evas_Coord minx, miny;
1684 if (sd->down.dir_x) *x = sd->down.sx - (*x - sd->down.x);
1685 else *x = sd->down.sx;
1686 if (sd->down.dir_y) *y = sd->down.sy - (*y - sd->down.y);
1687 else *y = sd->down.sy;
1689 if ((sd->down.dir_x) || (sd->down.dir_y))
1691 if (!((sd->down.dir_x) && (sd->down.dir_y)))
1693 if (sd->down.dir_x) *y = sd->down.locked_y;
1694 else *x = sd->down.locked_x;
1698 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
1701 *x += (minx - *x) * _elm_config->thumbscroll_border_friction;
1702 else if (sd->child.w <= sd->w)
1703 *x += (sd->down.sx - *x) * _elm_config->thumbscroll_border_friction;
1704 else if ((sd->child.w - sd->w + minx) < *x)
1705 *x += (sd->child.w - sd->w + minx - *x) *
1706 _elm_config->thumbscroll_border_friction;
1709 *y += (miny - *y) * _elm_config->thumbscroll_border_friction;
1710 else if (sd->child.h <= sd->h)
1711 *y += (sd->down.sy - *y) * _elm_config->thumbscroll_border_friction;
1712 else if ((sd->child.h - sd->h + miny) < *y)
1713 *y += (sd->child.h - sd->h + miny - *y) *
1714 _elm_config->thumbscroll_border_friction;
1718 _smart_hold_animator(void *data)
1720 Smart_Data *sd = data;
1721 Evas_Coord ox = 0, oy = 0, fx = 0, fy= 0;
1723 fx = sd->down.hold_x;
1724 fy = sd->down.hold_y;
1726 if ((!sd->hold) && (!sd->freeze) && (_elm_config->scroll_smooth_time_interval > 0.0))
1728 int i, count = 0; //count for the real event number we have to deal with
1729 int queue_size = 10; //for event queue size
1730 int src_index = 0, dst_index = 0;
1731 int xsum = 0, ysum=0;
1732 Evas_Coord x=0, y=0;
1740 double time_interval=_elm_config->scroll_smooth_time_interval;
1741 // FIXME: assume server and client have the same "timezone"
1742 // (0 timepoint) for now. this needs to be figured out in advance
1744 tdiff = sd->down.hist.est_timestamp_diff;
1745 tnow = ecore_time_get() - tdiff;
1747 for(i = 0; i < queue_size; i++)
1749 x = sd->down.history[i].x;
1750 y = sd->down.history[i].y;
1752 //if there is no history value , we don't deal with it
1753 //if there is better wat to know existance of history value , I will modify this code to it
1754 if ( (x == 0) && (y == 0) )
1758 _down_coord_eval(sd, &x, &y);
1762 pos[i].t = tnow - sd->down.history[i].timestamp;
1766 // we only deal with smooth scroll there is enough history
1767 for(i = 0; i < queue_size; i++)
1769 if (src_index > count) break;
1777 while ((pos[src_index].t < time_interval *i) &&
1778 (src_index <= count))
1782 if (src_index <= count)
1784 xsum += pos[src_index].x;
1785 ysum += pos[src_index].y;
1789 fx = xsum / dst_index;
1790 fy = ysum / dst_index;
1793 elm_smart_scroller_child_pos_get(sd->smart_obj, &ox, &oy);
1796 if ((!sd->widget) ||
1797 (!elm_widget_drag_child_locked_x_get(sd->widget)))
1804 if ((!sd->widget) ||
1805 (!elm_widget_drag_child_locked_y_get(sd->widget)))
1810 elm_smart_scroller_child_pos_set(sd->smart_obj, ox, oy);
1811 return ECORE_CALLBACK_RENEW;
1815 _smart_event_post_up(void *data, Evas *e __UNUSED__)
1817 Smart_Data *sd = data;
1820 if (sd->down.dragged)
1822 elm_widget_drag_lock_x_set(sd->widget, 0);
1823 elm_widget_drag_lock_y_set(sd->widget, 0);
1830 _smart_event_mouse_up(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *event_info)
1832 Evas_Event_Mouse_Down *ev;
1834 Evas_Coord x = 0, y = 0, ox = 0, oy = 0;
1838 sd->down.hold_parent = 0;
1839 // if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
1840 evas_post_event_callback_push(e, _smart_event_post_up, sd);
1841 // FIXME: respect elm_widget_scroll_hold_get of parent container
1842 if (_elm_config->thumbscroll_enable)
1844 if (ev->button == 1)
1846 if (sd->down.onhold_animator)
1848 ecore_animator_del(sd->down.onhold_animator);
1849 sd->down.onhold_animator = NULL;
1851 x = ev->canvas.x - sd->down.x;
1852 y = ev->canvas.y - sd->down.y;
1853 if (sd->down.dragged)
1855 _smart_drag_stop(sd->smart_obj);
1856 if ((!sd->hold) && (!sd->freeze))
1860 Evas_Coord ax, ay, dx, dy, vel;
1863 t = ev->timestamp / 1000.0;
1865 t = ecore_loop_time_get();
1867 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1872 printf("------ %i %i\n", ev->canvas.x, ev->canvas.y);
1874 for (i = 0; i < 20; i++)
1876 dt = t - sd->down.history[i].timestamp;
1877 if (dt > 0.2) break;
1879 printf("H: %i %i @ %1.3f\n",
1880 sd->down.history[i].x,
1881 sd->down.history[i].y, dt);
1884 ax += sd->down.history[i].x;
1885 ay += sd->down.history[i].y;
1891 dx = ev->canvas.x - ax;
1892 dy = ev->canvas.y - ay;
1895 vel = sqrt((dx * dx) + (dy * dy)) / at;
1896 if ((_elm_config->thumbscroll_friction > 0.0) &&
1897 (vel > _elm_config->thumbscroll_momentum_threshold))
1899 sd->down.dx = ((double)dx / at);
1900 sd->down.dy = ((double)dy / at);
1901 if (((sd->down.dx > 0) && (sd->down.pdx > 0)) ||
1902 ((sd->down.dx < 0) && (sd->down.pdx < 0)) ||
1903 ((sd->down.dy > 0) && (sd->down.pdy > 0)) ||
1904 ((sd->down.dy < 0) && (sd->down.pdy < 0)))
1906 double t = ecore_loop_time_get();
1907 double dt = t - sd->down.anim_start;
1909 if (dt < 0.0) dt = 0.0;
1910 else if (dt > _elm_config->thumbscroll_friction)
1911 dt = _elm_config->thumbscroll_friction;
1912 sd->down.extra_time = _elm_config->thumbscroll_friction - dt;
1914 if (((sd->down.dx > 0) && (sd->down.pdx > 0)) ||
1915 ((sd->down.dx < 0) && (sd->down.pdx < 0)))
1916 sd->down.dx += (double)sd->down.pdx * 1.5; // FIXME: * 1.5 - probably should be config
1917 if (((sd->down.dy > 0) && (sd->down.pdy > 0)) ||
1918 ((sd->down.dy < 0) && (sd->down.pdy < 0)))
1919 sd->down.dy += (double)sd->down.pdy * 1.5; // FIXME: * 1.5 - probably should be config
1921 sd->down.extra_time = 0.0;
1922 sd->down.pdx = sd->down.dx;
1923 sd->down.pdy = sd->down.dy;
1926 if (!_smart_do_page(sd))
1928 if (!sd->down.momentum_animator && !sd->momentum_animator_disabled)
1930 sd->down.momentum_animator = ecore_animator_add(_smart_momentum_animator, sd);
1931 ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL;
1932 _smart_anim_start(sd->smart_obj);
1934 sd->down.anim_start = ecore_loop_time_get();
1935 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1943 if (sd->down.hold_animator)
1945 ecore_animator_del(sd->down.hold_animator);
1946 sd->down.hold_animator = NULL;
1954 evas_event_feed_hold(e, 0, ev->timestamp, ev->data);
1955 if (_smart_do_page(sd))
1957 Evas_Coord pgx, pgy;
1959 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1960 if ((!sd->widget) ||
1961 (!elm_widget_drag_child_locked_x_get(sd->widget)))
1963 pgx = _smart_page_x_get(sd, ox);
1966 ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL;
1967 _smart_scrollto_x(sd, _elm_config->page_scroll_friction, pgx);
1970 if ((!sd->widget) ||
1971 (!elm_widget_drag_child_locked_y_get(sd->widget)))
1973 pgy = _smart_page_y_get(sd, oy);
1976 ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL;
1977 _smart_scrollto_y(sd, _elm_config->page_scroll_friction, pgy);
1986 if (_smart_do_page(sd))
1988 Evas_Coord pgx, pgy;
1990 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1991 if ((!sd->widget) ||
1992 (!elm_widget_drag_child_locked_x_get(sd->widget)))
1994 pgx = _smart_page_x_get(sd, ox);
1995 if (pgx != x) _smart_scrollto_x(sd, _elm_config->page_scroll_friction, pgx);
1997 if ((!sd->widget) ||
1998 (!elm_widget_drag_child_locked_y_get(sd->widget)))
2000 pgy = _smart_page_y_get(sd, oy);
2001 if (pgy != y) _smart_scrollto_y(sd, _elm_config->page_scroll_friction, pgy);
2004 if (sd->down.hold_animator)
2006 ecore_animator_del(sd->down.hold_animator);
2007 sd->down.hold_animator = NULL;
2010 if (sd->down.scroll)
2012 ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL;
2013 sd->down.scroll = 0;
2017 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2020 sd->down.dragged_began = 0;
2023 sd->down.want_dragged = 0;
2024 sd->down.dragged = 0;
2026 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
2027 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
2028 _update_wanted_coordinates(sd, x, y);
2030 if (!_smart_do_page(sd))
2037 _smart_onhold_animator(void *data)
2042 Evas_Coord x, y, ox, oy;
2045 t = ecore_loop_time_get();
2046 if (sd->down.onhold_tlast > 0.0)
2048 td = t - sd->down.onhold_tlast;
2049 vx = sd->down.onhold_vx * td * (double)_elm_config->thumbscroll_threshold * 2.0;
2050 vy = sd->down.onhold_vy * td * (double)_elm_config->thumbscroll_threshold * 2.0;
2051 elm_smart_scroller_child_pos_get(sd->smart_obj, &ox, &oy);
2057 if ((!sd->widget) ||
2058 (!elm_widget_drag_child_locked_x_get(sd->widget)))
2060 sd->down.onhold_vxe += vx;
2061 x = ox + (int)sd->down.onhold_vxe;
2062 sd->down.onhold_vxe -= (int)sd->down.onhold_vxe;
2068 if ((!sd->widget) ||
2069 (!elm_widget_drag_child_locked_y_get(sd->widget)))
2071 sd->down.onhold_vye += vy;
2072 y = oy + (int)sd->down.onhold_vye;
2073 sd->down.onhold_vye -= (int)sd->down.onhold_vye;
2077 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
2079 sd->down.onhold_tlast = t;
2080 return ECORE_CALLBACK_RENEW;
2084 _smart_event_post_move(void *data, Evas *e __UNUSED__)
2086 Smart_Data *sd = data;
2088 if (sd->down.want_dragged)
2092 if (sd->down.hold_parent)
2094 if ((sd->down.dir_x) && !can_scroll(sd, sd->down.hdir))
2098 if ((sd->down.dir_y) && !can_scroll(sd, sd->down.vdir))
2105 if ((!sd->widget) ||
2106 (!elm_widget_drag_child_locked_x_get(sd->widget)))
2108 sd->down.want_dragged = 0;
2109 sd->down.dragged = 1;
2112 elm_widget_drag_lock_x_set(sd->widget, 1);
2121 if ((!sd->widget) ||
2122 (!elm_widget_drag_child_locked_y_get(sd->widget)))
2124 sd->down.want_dragged = 0;
2125 sd->down.dragged = 1;
2128 elm_widget_drag_lock_y_set(sd->widget, 1);
2135 if ((!sd->down.dir_x) && (!sd->down.dir_y))
2137 sd->down.cancelled = 1;
2139 if (start) _smart_drag_start(sd->smart_obj);
2145 _smart_event_mouse_move(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *event_info)
2147 Evas_Event_Mouse_Move *ev;
2149 Evas_Coord x = 0, y = 0;
2153 // if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
2154 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) sd->down.hold_parent = 1;
2155 evas_post_event_callback_push(e, _smart_event_post_move, sd);
2156 // FIXME: respect elm_widget_scroll_hold_get of parent container
2157 if (_elm_config->thumbscroll_enable)
2164 printf("::: %i %i\n", ev->cur.canvas.x, ev->cur.canvas.y);
2166 memmove(&(sd->down.history[1]), &(sd->down.history[0]),
2167 sizeof(sd->down.history[0]) * 19);
2169 sd->down.history[0].timestamp = ev->timestamp / 1000.0;
2171 sd->down.history[0].timestamp = ecore_loop_time_get();
2173 sd->down.history[0].x = ev->cur.canvas.x;
2174 sd->down.history[0].y = ev->cur.canvas.y;
2176 if (!sd->down.dragged_began)
2178 x = ev->cur.canvas.x - sd->down.x;
2179 y = ev->cur.canvas.y - sd->down.y;
2184 if (x > 0) sd->down.hdir = LEFT;
2185 else if (x < 0) sd->down.hdir = RIGHT;
2186 if (y > 0) sd->down.vdir = UP;
2187 else if (y < 0) sd->down.vdir = DOWN;
2192 if ((sd->one_dir_at_a_time) &&
2193 (!((sd->down.dir_x) || (sd->down.dir_y))))
2195 if (x > _elm_config->thumbscroll_threshold)
2204 if (y > _elm_config->thumbscroll_threshold)
2221 // can_scroll(sd, LEFT);
2222 // can_scroll(sd, RIGHT);
2223 // can_scroll(sd, UP);
2224 // can_scroll(sd, DOWN);
2229 if ((!sd->hold) && (!sd->freeze))
2231 if ((sd->down.dragged) ||
2232 (((x * x) + (y * y)) >
2233 (_elm_config->thumbscroll_threshold *
2234 _elm_config->thumbscroll_threshold)))
2236 sd->down.dragged_began = 1;
2237 if (!sd->down.dragged)
2239 sd->down.want_dragged = 1;
2240 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2241 // evas_event_feed_hold(e, 1, ev->timestamp, ev->data);
2242 // _smart_drag_start(sd->smart_obj);
2244 if (sd->down.dragged)
2246 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2248 // ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2249 // sd->down.dragged = 1;
2251 x = sd->down.sx - (ev->cur.canvas.x - sd->down.x);
2255 y = sd->down.sy - (ev->cur.canvas.y - sd->down.y);
2258 if(sd->down.want_reset)
2260 sd->down.x = ev->cur.canvas.x;
2261 sd->down.y = ev->cur.canvas.y;
2262 sd->down.want_reset = 0;
2264 if ((sd->down.dir_x) || (sd->down.dir_y))
2266 if (!sd->down.locked)
2268 sd->down.locked_x = x;
2269 sd->down.locked_y = y;
2270 sd->down.locked = 1;
2272 if (!((sd->down.dir_x) && (sd->down.dir_y)))
2274 if (sd->down.dir_x) y = sd->down.locked_y;
2275 else x = sd->down.locked_x;
2278 if (_elm_config->thumbscroll_border_friction > 0.0)
2280 Evas_Coord minx, miny;
2281 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2284 _elm_config->thumbscroll_border_friction;
2285 else if (sd->child.h <= sd->h)
2286 y += (sd->down.sy - y) *
2287 _elm_config->thumbscroll_border_friction;
2288 else if ((sd->child.h - sd->h + miny) < y)
2289 y += (sd->child.h - sd->h + miny - y) *
2290 _elm_config->thumbscroll_border_friction;
2293 _elm_config->thumbscroll_border_friction;
2294 else if (sd->child.w <= sd->w)
2295 x += (sd->down.sx - x) *
2296 _elm_config->thumbscroll_border_friction;
2297 else if ((sd->child.w - sd->w + minx) < x)
2298 x += (sd->child.w - sd->w + minx - x) *
2299 _elm_config->thumbscroll_border_friction;
2302 sd->down.hold_x = x;
2303 sd->down.hold_y = y;
2304 if (!sd->down.hold_animator)
2305 sd->down.hold_animator =
2306 ecore_animator_add(_smart_hold_animator, sd);
2307 // printf("a %i %i\n", sd->down.hold_x, sd->down.hold_y);
2308 // _smart_onhold_animator(sd);
2309 // elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
2313 if (sd->down.dragged_began)
2315 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2319 evas_event_feed_hold(e, 1, ev->timestamp, ev->data);
2324 else if (!sd->freeze)
2326 Evas_Coord ex, ey, ew, eh;
2327 double vx = 0.0, vy = 0.0;
2329 evas_object_geometry_get(sd->event_obj, &ex, &ey, &ew, &eh);
2330 x = ev->cur.canvas.x - ex;
2331 y = ev->cur.canvas.y - ey;
2332 if (x < _elm_config->thumbscroll_threshold)
2334 if (_elm_config->thumbscroll_threshold > 0.0)
2335 vx = -(double)(_elm_config->thumbscroll_threshold - x) /
2336 _elm_config->thumbscroll_threshold;
2340 else if (x > (ew - _elm_config->thumbscroll_threshold))
2342 if (_elm_config->thumbscroll_threshold > 0.0)
2343 vx = (double)(_elm_config->thumbscroll_threshold - (ew - x)) /
2344 _elm_config->thumbscroll_threshold;
2348 if (y < _elm_config->thumbscroll_threshold)
2350 if (_elm_config->thumbscroll_threshold > 0.0)
2351 vy = -(double)(_elm_config->thumbscroll_threshold - y) /
2352 _elm_config->thumbscroll_threshold;
2356 else if (y > (eh - _elm_config->thumbscroll_threshold))
2358 if (_elm_config->thumbscroll_threshold > 0.0)
2359 vy = (double)(_elm_config->thumbscroll_threshold - (eh - y)) /
2360 _elm_config->thumbscroll_threshold;
2364 if ((vx != 0.0) || (vy != 0.0))
2366 sd->down.onhold_vx = vx;
2367 sd->down.onhold_vy = vy;
2368 if (!sd->down.onhold_animator)
2370 sd->down.onhold_vxe = 0.0;
2371 sd->down.onhold_vye = 0.0;
2372 sd->down.onhold_tlast = 0.0;
2373 sd->down.onhold_animator = ecore_animator_add(_smart_onhold_animator, sd);
2375 // printf("b %i %i\n", sd->down.hold_x, sd->down.hold_y);
2379 if (sd->down.onhold_animator)
2381 ecore_animator_del(sd->down.onhold_animator);
2382 sd->down.onhold_animator = NULL;
2391 _smart_scrollbar_read(Smart_Data *sd)
2393 Evas_Coord x, y, mx = 0, my = 0, px, py, minx = 0, miny = 0;
2396 edje_object_part_drag_value_get(sd->edje_obj, "elm.dragable.vbar", NULL, &vy);
2397 edje_object_part_drag_value_get(sd->edje_obj, "elm.dragable.hbar", &vx, NULL);
2398 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
2399 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2400 x = vx * (double)mx + minx;
2401 y = vy * (double)my + miny;
2402 sd->pan_func.get(sd->pan_obj, &px, &py);
2403 sd->pan_func.set(sd->pan_obj, x, y);
2404 if ((px != x) || (py != y))
2405 edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
2409 _smart_scrollbar_reset(Smart_Data *sd)
2411 Evas_Coord px = 0, py = 0, minx = 0, miny = 0;
2413 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.vbar", 0.0, 0.0);
2414 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.hbar", 0.0, 0.0);
2415 if ((!sd->child_obj) && (!sd->extern_pan))
2417 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.vbar", 1.0, 1.0);
2418 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.hbar", 1.0, 1.0);
2422 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2423 sd->pan_func.get(sd->pan_obj, &px, &py);
2424 sd->pan_func.set(sd->pan_obj, minx, miny);
2426 if ((px != minx) || (py != miny))
2427 edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
2431 _smart_scrollbar_bar_v_visibility_adjust(Smart_Data *sd)
2433 int scroll_v_vis_change = 0;
2434 Evas_Coord h, vw = 0, vh = 0;
2438 evas_object_geometry_get(sd->pan_obj, NULL, NULL, &vw, &vh);
2439 if (sd->vbar_visible)
2441 if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_AUTO)
2443 if ((sd->child_obj) || (sd->extern_pan))
2447 scroll_v_vis_change = 1;
2448 sd->vbar_visible = 0;
2453 scroll_v_vis_change = 1;
2454 sd->vbar_visible = 0;
2457 else if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
2459 scroll_v_vis_change = 1;
2460 sd->vbar_visible = 0;
2465 if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_AUTO)
2467 if ((sd->child_obj) || (sd->extern_pan))
2471 scroll_v_vis_change = 1;
2472 sd->vbar_visible = 1;
2476 else if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
2478 scroll_v_vis_change = 1;
2479 sd->vbar_visible = 1;
2482 if (scroll_v_vis_change)
2484 if (sd->vbar_flags != ELM_SMART_SCROLLER_POLICY_OFF)
2486 if (sd->vbar_visible)
2487 edje_object_signal_emit(sd->edje_obj, "elm,action,show,vbar", "elm");
2489 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,vbar", "elm");
2490 edje_object_message_signal_process(sd->edje_obj);
2491 _smart_scrollbar_size_adjust(sd);
2494 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,vbar", "elm");
2496 return scroll_v_vis_change;
2500 _smart_scrollbar_bar_h_visibility_adjust(Smart_Data *sd)
2502 int scroll_h_vis_change = 0;
2503 Evas_Coord w, vw = 0, vh = 0;
2507 evas_object_geometry_get(sd->pan_obj, NULL, NULL, &vw, &vh);
2508 if (sd->hbar_visible)
2510 if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_AUTO)
2512 if ((sd->child_obj) || (sd->extern_pan))
2516 scroll_h_vis_change = 1;
2517 sd->hbar_visible = 0;
2522 scroll_h_vis_change = 1;
2523 sd->hbar_visible = 0;
2526 else if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
2528 scroll_h_vis_change = 1;
2529 sd->hbar_visible = 0;
2534 if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_AUTO)
2536 if ((sd->child_obj) || (sd->extern_pan))
2540 scroll_h_vis_change = 1;
2541 sd->hbar_visible = 1;
2545 else if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
2547 scroll_h_vis_change = 1;
2548 sd->hbar_visible = 1;
2551 if (scroll_h_vis_change)
2553 if (sd->hbar_flags != ELM_SMART_SCROLLER_POLICY_OFF)
2555 if (sd->hbar_visible)
2556 edje_object_signal_emit(sd->edje_obj, "elm,action,show,hbar", "elm");
2558 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,hbar", "elm");
2559 edje_object_message_signal_process(sd->edje_obj);
2560 _smart_scrollbar_size_adjust(sd);
2563 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,hbar", "elm");
2564 _smart_scrollbar_size_adjust(sd);
2566 return scroll_h_vis_change;
2570 _smart_scrollbar_bar_visibility_adjust(Smart_Data *sd)
2574 changed |= _smart_scrollbar_bar_h_visibility_adjust(sd);
2575 changed |= _smart_scrollbar_bar_v_visibility_adjust(sd);
2578 _smart_scrollbar_bar_h_visibility_adjust(sd);
2579 _smart_scrollbar_bar_v_visibility_adjust(sd);
2584 _smart_scrollbar_size_adjust(Smart_Data *sd)
2586 if ((sd->child_obj) || (sd->extern_pan))
2588 Evas_Coord x, y, w, h, mx = 0, my = 0, vw = 0, vh = 0, px, py, minx = 0, miny = 0;
2589 double vx, vy, size;
2591 edje_object_part_geometry_get(sd->edje_obj, "elm.swallow.content",
2592 NULL, NULL, &vw, &vh);
2595 size = (double)vw / (double)w;
2599 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.hbar", 0.0, 0.0);
2601 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.hbar", size, 1.0);
2605 size = (double)vh / (double)h;
2609 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.vbar", 0.0, 0.0);
2611 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.vbar", 1.0, size);
2613 edje_object_part_drag_value_get(sd->edje_obj, "elm.dragable.hbar", &vx, NULL);
2614 edje_object_part_drag_value_get(sd->edje_obj, "elm.dragable.vbar", NULL, &vy);
2615 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
2616 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2620 edje_object_part_drag_step_set(sd->edje_obj, "elm.dragable.hbar", (double)sd->step.x / (double)w, 0.0);
2621 edje_object_part_drag_step_set(sd->edje_obj, "elm.dragable.vbar", 0.0, (double)sd->step.y / (double)h);
2623 edje_object_part_drag_page_set(sd->edje_obj, "elm.dragable.hbar", (double)sd->page.x / (double)w, 0.0);
2625 edje_object_part_drag_page_set(sd->edje_obj, "elm.dragable.hbar", -((double)sd->page.x * ((double)vw / (double)w)) / 100.0, 0.0);
2627 edje_object_part_drag_page_set(sd->edje_obj, "elm.dragable.vbar", 0.0, (double)sd->page.y / (double)h);
2629 edje_object_part_drag_page_set(sd->edje_obj, "elm.dragable.vbar", 0.0, -((double)sd->page.y * ((double)vh / (double)h)) / 100.0);
2631 sd->pan_func.get(sd->pan_obj, &px, &py);
2632 if (vx != mx) x = px;
2633 if (vy != my) y = py;
2634 sd->pan_func.set(sd->pan_obj, x, y);
2635 // if ((px != 0) || (py != 0))
2636 // edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
2640 Evas_Coord px = 0, py = 0, minx = 0, miny = 0;
2642 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.vbar", 1.0, 1.0);
2643 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.hbar", 1.0, 1.0);
2646 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2647 sd->pan_func.get(sd->pan_obj, &px, &py);
2648 sd->pan_func.set(sd->pan_obj, minx, miny);
2650 if ((px != minx) || (py != miny))
2651 edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
2653 _smart_scrollbar_bar_visibility_adjust(sd);
2657 _smart_reconfigure(Smart_Data *sd)
2659 evas_object_move(sd->edje_obj, sd->x, sd->y);
2660 evas_object_resize(sd->edje_obj, sd->w, sd->h);
2661 evas_object_move(sd->event_obj, sd->x, sd->y);
2662 evas_object_resize(sd->event_obj, sd->w, sd->h);
2663 _smart_scrollbar_size_adjust(sd);
2667 _smart_add(Evas_Object *obj)
2672 sd = calloc(1, sizeof(Smart_Data));
2674 evas_object_smart_data_set(obj, sd);
2676 sd->smart_obj = obj;
2685 sd->hbar_flags = ELM_SMART_SCROLLER_POLICY_AUTO;
2686 sd->vbar_flags = ELM_SMART_SCROLLER_POLICY_AUTO;
2687 sd->hbar_visible = 1;
2688 sd->vbar_visible = 1;
2690 sd->bounce_horiz = 1;
2691 sd->bounce_vert = 1;
2693 sd->one_dir_at_a_time = 1;
2694 sd->momentum_animator_disabled = 0;
2695 sd->bounce_animator_disabled = 0;
2697 o = edje_object_add(evas_object_evas_get(obj));
2698 evas_object_propagate_events_set(o, 0);
2700 elm_smart_scroller_object_theme_set(NULL, obj, "scroller", "base", "default");
2701 edje_object_signal_callback_add(o, "drag", "elm.dragable.vbar", _smart_edje_drag_v, sd);
2702 edje_object_signal_callback_add(o, "drag,start", "elm.dragable.vbar", _smart_edje_drag_v_start, sd);
2703 edje_object_signal_callback_add(o, "drag,stop", "elm.dragable.vbar", _smart_edje_drag_v_stop, sd);
2704 edje_object_signal_callback_add(o, "drag,step", "elm.dragable.vbar", _smart_edje_drag_v, sd);
2705 edje_object_signal_callback_add(o, "drag,page", "elm.dragable.vbar", _smart_edje_drag_v, sd);
2706 edje_object_signal_callback_add(o, "drag", "elm.dragable.hbar", _smart_edje_drag_h, sd);
2707 edje_object_signal_callback_add(o, "drag,start", "elm.dragable.hbar", _smart_edje_drag_h_start, sd);
2708 edje_object_signal_callback_add(o, "drag,stop", "elm.dragable.hbar", _smart_edje_drag_h_stop, sd);
2709 edje_object_signal_callback_add(o, "drag,step", "elm.dragable.hbar", _smart_edje_drag_h, sd);
2710 edje_object_signal_callback_add(o, "drag,page", "elm.dragable.hbar", _smart_edje_drag_h, sd);
2711 evas_object_smart_member_add(o, obj);
2713 o = evas_object_rectangle_add(evas_object_evas_get(obj));
2715 evas_object_color_set(o, 0, 0, 0, 0);
2716 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_WHEEL, _smart_event_wheel, sd);
2717 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, _smart_event_mouse_down, sd);
2718 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_UP, _smart_event_mouse_up, sd);
2719 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_MOVE, _smart_event_mouse_move, sd);
2720 evas_object_smart_member_add(o, obj);
2721 evas_object_repeat_events_set(o, 1);
2723 sd->pan_func.set = _elm_smart_pan_set;
2724 sd->pan_func.get = _elm_smart_pan_get;
2725 sd->pan_func.max_get = _elm_smart_pan_max_get;
2726 sd->pan_func.min_get = _elm_smart_pan_min_get;
2727 sd->pan_func.child_size_get = _elm_smart_pan_child_size_get;
2729 _smart_scrollbar_reset(sd);
2733 _smart_del(Evas_Object *obj)
2736 elm_smart_scroller_child_set(obj, NULL);
2737 if (!sd->extern_pan) evas_object_del(sd->pan_obj);
2738 evas_object_del(sd->edje_obj);
2739 evas_object_del(sd->event_obj);
2740 if (sd->down.hold_animator) ecore_animator_del(sd->down.hold_animator);
2741 if (sd->down.onhold_animator) ecore_animator_del(sd->down.onhold_animator);
2742 if (sd->down.momentum_animator) ecore_animator_del(sd->down.momentum_animator);
2743 if (sd->down.bounce_x_animator) ecore_animator_del(sd->down.bounce_x_animator);
2744 if (sd->down.bounce_y_animator) ecore_animator_del(sd->down.bounce_y_animator);
2745 if (sd->scrollto.x.animator) ecore_animator_del(sd->scrollto.x.animator);
2746 if (sd->scrollto.y.animator) ecore_animator_del(sd->scrollto.y.animator);
2748 evas_object_smart_data_set(obj, NULL);
2752 _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
2757 _smart_reconfigure(sd);
2761 _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
2766 _smart_reconfigure(sd);
2767 _elm_smart_scroller_wanted_region_set(obj);
2771 _smart_show(Evas_Object *obj)
2774 evas_object_show(sd->edje_obj);
2775 evas_object_show(sd->event_obj);
2779 _smart_hide(Evas_Object *obj)
2782 evas_object_hide(sd->edje_obj);
2783 evas_object_hide(sd->event_obj);
2787 _smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
2790 evas_object_color_set(sd->edje_obj, r, g, b, a);
2794 _smart_clip_set(Evas_Object *obj, Evas_Object *clip)
2797 evas_object_clip_set(sd->edje_obj, clip);
2798 evas_object_clip_set(sd->event_obj, clip);
2802 _smart_clip_unset(Evas_Object *obj)
2805 evas_object_clip_unset(sd->edje_obj);
2806 evas_object_clip_unset(sd->event_obj);
2809 /* never need to touch this */
2816 static const Evas_Smart_Class sc =
2819 EVAS_SMART_CLASS_VERSION,
2837 _smart = evas_smart_class_new(&sc);