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;
481 _smart_scrollto_x(Smart_Data *sd, double t_in, Evas_Coord pos_x)
483 Evas_Coord px, py, x, y, w, h;
486 if (sd->freeze) return;
489 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
490 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
492 elm_smart_scroller_child_region_set(sd->smart_obj, x, y, w, h);
495 t = ecore_loop_time_get();
496 sd->pan_func.get(sd->pan_obj, &px, &py);
497 sd->scrollto.x.start = px;
498 sd->scrollto.x.end = pos_x;
499 sd->scrollto.x.t_start = t;
500 sd->scrollto.x.t_end = t + t_in;
501 if (!sd->scrollto.x.animator)
503 sd->scrollto.x.animator = ecore_animator_add(_smart_scrollto_x_animator, sd);
504 if (!sd->scrollto.y.animator)
505 _smart_anim_start(sd->smart_obj);
507 if (sd->down.bounce_x_animator)
509 ecore_animator_del(sd->down.bounce_x_animator);
510 sd->down.bounce_x_animator = NULL;
511 _smart_momentum_end(sd);
517 _smart_scrollto_y_animator(void *data)
519 Smart_Data *sd = data;
523 t = ecore_loop_time_get();
524 tt = (t - sd->scrollto.y.t_start) / (sd->scrollto.y.t_end - sd->scrollto.y.t_start);
526 tt = 1.0 - (tt * tt);
527 sd->pan_func.get(sd->pan_obj, &px, &py);
528 py = (sd->scrollto.y.start * (1.0 - tt)) +
529 (sd->scrollto.y.end * tt);
530 if (t >= sd->scrollto.y.t_end)
532 py = sd->scrollto.y.end;
533 elm_smart_scroller_child_pos_set(sd->smart_obj, px, py);
534 sd->scrollto.y.animator = NULL;
535 if ((!sd->scrollto.x.animator) && (!sd->down.bounce_x_animator))
536 _smart_anim_stop(sd->smart_obj);
537 return ECORE_CALLBACK_CANCEL;
539 elm_smart_scroller_child_pos_set(sd->smart_obj, px, py);
541 return ECORE_CALLBACK_RENEW;
545 _smart_scrollto_y(Smart_Data *sd, double t_in, Evas_Coord pos_y)
547 Evas_Coord px, py, x, y, w, h;
550 if (sd->freeze) return;
553 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
554 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
556 elm_smart_scroller_child_region_set(sd->smart_obj, x, y, w, h);
559 t = ecore_loop_time_get();
560 sd->pan_func.get(sd->pan_obj, &px, &py);
561 sd->scrollto.y.start = py;
562 sd->scrollto.y.end = pos_y;
563 sd->scrollto.y.t_start = t;
564 sd->scrollto.y.t_end = t + t_in;
565 if (!sd->scrollto.y.animator)
567 sd->scrollto.y.animator = ecore_animator_add(_smart_scrollto_y_animator, sd);
568 if (!sd->scrollto.x.animator)
569 _smart_anim_start(sd->smart_obj);
571 if (sd->down.bounce_y_animator)
573 ecore_animator_del(sd->down.bounce_y_animator);
574 sd->down.bounce_y_animator = NULL;
575 _smart_momentum_end(sd);
581 _smart_do_page(Smart_Data *sd)
583 if ((sd->pagerel_h == 0.0) && (!sd->pagesize_h) &&
584 (sd->pagerel_v == 0.0) && (!sd->pagesize_v))
590 _smart_page_x_get(Smart_Data *sd, int offset)
592 Evas_Coord x, y, w, h, cw, ch, minx = 0;
594 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
595 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
596 sd->pan_func.child_size_get(sd->pan_obj, &cw, &ch);
597 sd->pan_func.min_get(sd->pan_obj, &minx, NULL);
601 if (sd->pagerel_h > 0.0)
603 x = x + (w * sd->pagerel_h * 0.5);
604 x = x / (w * sd->pagerel_h);
605 x = x * (w * sd->pagerel_h);
607 else if (sd->pagesize_h > 0)
609 x = x + (sd->pagesize_h * 0.5);
610 x = x / (sd->pagesize_h);
611 x = x * (sd->pagesize_h);
613 if ((x + w) > cw) x = cw - w;
614 if (x < minx) x = minx;
619 _smart_page_y_get(Smart_Data *sd, int offset)
621 Evas_Coord x, y, w, h, cw, ch, miny = 0;
623 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
624 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
625 sd->pan_func.child_size_get(sd->pan_obj, &cw, &ch);
626 sd->pan_func.min_get(sd->pan_obj, NULL, &miny);
630 if (sd->pagerel_v > 0.0)
632 y = y + (h * sd->pagerel_v * 0.5);
633 y = y / (h * sd->pagerel_v);
634 y = y * (h * sd->pagerel_v);
636 else if (sd->pagesize_v > 0)
638 y = y + (sd->pagesize_v * 0.5);
639 y = y / (sd->pagesize_v);
640 y = y * (sd->pagesize_v);
642 if ((y + h) > ch) y = ch - h;
643 if (y < miny) y = miny;
648 _smart_page_adjust(Smart_Data *sd)
650 Evas_Coord x, y, w, h;
652 if (!_smart_do_page(sd)) return;
654 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
656 x = _smart_page_x_get(sd, 0);
657 y = _smart_page_y_get(sd, 0);
659 elm_smart_scroller_child_region_set(sd->smart_obj, x, y, w, h);
663 _smart_bounce_x_animator(void *data)
666 Evas_Coord x, y, dx, px, w, odx, ed, md;
667 double t, p, dt, pd, r;
670 t = ecore_loop_time_get();
671 dt = t - sd->down.anim_start2;
674 dt = dt / _elm_config->thumbscroll_bounce_friction;
675 odx = sd->down.b2x - sd->down.bx;
676 sd->pan_func.get(sd->pan_obj, &px, NULL);
677 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, NULL);
678 if (!sd->down.momentum_animator && ((w - px) > 0) && ((-px) < w))
680 pd = (double)odx / (double)w;
681 pd = (pd > 0) ? pd : -pd;
682 pd = 1.0 - ((1.0 - pd) * (1.0 - pd));
685 if (dt > 1.0) dt = 1.0;
686 p = 1.0 - ((1.0 - dt) * (1.0 - dt));
687 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
690 if (sd->down.momentum_animator)
692 ed = abs(sd->down.dx * (_elm_config->thumbscroll_friction + sd->down.extra_time) - sd->down.b0x);
693 md = abs(15*w); // FIXME : 15 - probably should be config
694 if (ed > md) r = (double)(md)/(double)ed;
696 x = sd->down.b2x + (int)((double)(dx - odx)*r);
697 if (!sd->down.cancelled)
698 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
701 if (sd->down.momentum_animator)
702 sd->down.bounce_x_hold = 1;
703 else if ((!sd->down.bounce_y_animator) &&
704 (!sd->scrollto.y.animator))
705 _smart_anim_stop(sd->smart_obj);
706 sd->down.bounce_x_animator = NULL;
709 _smart_momentum_end(sd);
710 return ECORE_CALLBACK_CANCEL;
713 return ECORE_CALLBACK_RENEW;
717 _smart_bounce_y_animator(void *data)
720 Evas_Coord x, y, dy, py, h, ody, ed, md;
721 double t, p, dt, pd, r;
724 t = ecore_loop_time_get();
725 dt = t - sd->down.anim_start3;
728 dt = dt / _elm_config->thumbscroll_bounce_friction;
729 ody = sd->down.b2y - sd->down.by;
730 sd->pan_func.get(sd->pan_obj, NULL, &py);
731 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, NULL, &h);
732 if (!sd->down.momentum_animator && ((h - py) > 0) && ((-py) < h))
734 pd = (double)ody / (double)h;
735 pd = (pd > 0) ? pd : -pd;
736 pd = 1.0 - ((1.0 - pd) * (1.0 - pd));
739 if (dt > 1.0) dt = 1.0;
740 p = 1.0 - ((1.0 - dt) * (1.0 - dt));
741 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
744 if (sd->down.momentum_animator)
746 ed = abs(sd->down.dy * (_elm_config->thumbscroll_friction + sd->down.extra_time) - sd->down.b0y);
747 md = abs(15*h); // FIXME : 15 - probably should be config
748 if (ed > md) r = (double)(md)/(double)ed;
750 y = sd->down.b2y + (int)((double)(dy - ody)*r);
751 if (!sd->down.cancelled)
752 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
755 if (sd->down.momentum_animator)
756 sd->down.bounce_y_hold = 1;
757 else if ((!sd->down.bounce_x_animator) &&
758 (!sd->scrollto.y.animator))
759 _smart_anim_stop(sd->smart_obj);
760 sd->down.bounce_y_animator = NULL;
763 _smart_momentum_end(sd);
764 return ECORE_CALLBACK_CANCEL;
767 return ECORE_CALLBACK_RENEW;
775 can_scroll(Smart_Data *sd, int dir)
777 Evas_Coord mx = 0, my = 0, px = 0, py = 0, minx = 0, miny = 0;
779 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
780 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
781 sd->pan_func.get(sd->pan_obj, &px, &py);
785 if (px > minx) return EINA_TRUE;
788 if ((px - minx) < mx) return EINA_TRUE;
791 if (py > miny) return EINA_TRUE;
794 if ((py - miny) < my) return EINA_TRUE;
803 _smart_momentum_animator(void *data)
807 Evas_Coord x, y, dx, dy, px, py, maxx, maxy, minx, miny;
808 Eina_Bool no_bounce_x_end = EINA_FALSE, no_bounce_y_end = EINA_FALSE;
811 t = ecore_loop_time_get();
812 dt = t - sd->down.anim_start;
816 if (sd->down.hold_parent)
818 if ((sd->down.dir_x) && !can_scroll(sd, sd->down.hdir))
822 if ((sd->down.dir_y) && !can_scroll(sd, sd->down.vdir))
827 if ((!sd->down.dir_x) && (!sd->down.dir_y))
829 sd->down.cancelled = 1;
832 dt = dt / (_elm_config->thumbscroll_friction + sd->down.extra_time);
833 if (dt > 1.0) dt = 1.0;
834 p = 1.0 - ((1.0 - dt) * (1.0 - dt));
835 dx = (sd->down.dx * (_elm_config->thumbscroll_friction + sd->down.extra_time) * p);
836 dy = (sd->down.dy * (_elm_config->thumbscroll_friction + sd->down.extra_time) * p);
839 x = sd->down.sx - dx;
840 y = sd->down.sy - dy;
841 elm_smart_scroller_child_pos_get(sd->smart_obj, &px, &py);
842 if ((sd->down.bounce_x_animator) ||
843 (sd->down.bounce_x_hold))
845 sd->down.bx = sd->down.bx0 - dx + sd->down.b0x;
848 if ((sd->down.bounce_y_animator) ||
849 (sd->down.bounce_y_hold))
851 sd->down.by = sd->down.by0 - dy + sd->down.b0y;
854 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
855 _update_wanted_coordinates(sd, x, y);
856 sd->pan_func.max_get(sd->pan_obj, &maxx, &maxy);
857 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
858 if (!sd->bounce_horiz)
860 if (x <= minx) no_bounce_x_end = EINA_TRUE;
861 if ((x - minx) >= maxx) no_bounce_x_end = EINA_TRUE;
863 if (!sd->bounce_vert)
865 if (y <= miny) no_bounce_y_end = EINA_TRUE;
866 if ((y - miny) >= maxy) no_bounce_y_end = EINA_TRUE;
869 ((sd->down.bounce_x_hold) && (sd->down.bounce_y_hold)) ||
870 (no_bounce_x_end && no_bounce_y_end))
872 _smart_anim_stop(sd->smart_obj);
874 sd->down.momentum_animator = NULL;
875 sd->down.bounce_x_hold = 0;
876 sd->down.bounce_y_hold = 0;
881 return ECORE_CALLBACK_CANCEL;
884 return ECORE_CALLBACK_RENEW;
888 bounce_eval(Smart_Data *sd)
890 Evas_Coord mx, my, px, py, bx, by, b2x, b2y, minx = 0, miny = 0;
892 if (sd->freeze) return;
893 if ((!sd->bouncemex) && (!sd->bouncemey)) return;
894 if (sd->down.now) return; // down bounce while still held down
895 if (sd->down.onhold_animator)
897 ecore_animator_del(sd->down.onhold_animator);
898 sd->down.onhold_animator = NULL;
900 if (sd->down.hold_animator)
902 ecore_animator_del(sd->down.hold_animator);
903 sd->down.hold_animator = NULL;
905 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
906 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
907 sd->pan_func.get(sd->pan_obj, &px, &py);
910 if (px < minx) px = minx;
911 if ((px - minx) > mx) px = mx + minx;
912 if (py < miny) py = miny;
913 if ((py - miny) > my) py = my + miny;
917 (!elm_widget_drag_child_locked_x_get(sd->widget)))
919 if ((!sd->down.bounce_x_animator) && (!sd->bounce_animator_disabled))
923 if (sd->scrollto.x.animator)
925 ecore_animator_del(sd->scrollto.x.animator);
926 sd->scrollto.x.animator = NULL;
928 sd->down.bounce_x_animator = ecore_animator_add(_smart_bounce_x_animator, sd);
929 sd->down.anim_start2 = ecore_loop_time_get();
933 if (sd->down.momentum_animator) sd->down.b0x = sd->down.ax;
934 else sd->down.b0x = 0;
939 (!elm_widget_drag_child_locked_y_get(sd->widget)))
941 if ((!sd->down.bounce_y_animator) && (!sd->bounce_animator_disabled))
945 if (sd->scrollto.y.animator)
947 ecore_animator_del(sd->scrollto.y.animator);
948 sd->scrollto.y.animator = NULL;
950 sd->down.bounce_y_animator = ecore_animator_add(_smart_bounce_y_animator, sd);
951 sd->down.anim_start3 = ecore_loop_time_get();
955 if (sd->down.momentum_animator) sd->down.b0y = sd->down.ay;
956 else sd->down.b0y = 0;
963 elm_smart_scroller_child_pos_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
965 Evas_Coord mx = 0, my = 0, px = 0, py = 0, minx = 0, miny = 0;
969 // FIXME: allow for bounce outside of range
970 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
971 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
972 if (mx > 0) vx = (double)(x - minx) / (double)mx;
974 if (vx < 0.0) vx = 0.0;
975 else if (vx > 1.0) vx = 1.0;
976 if (my > 0) vy = (double)(y - miny) / (double)my;
978 if (vy < 0.0) vy = 0.0;
979 else if (vy > 1.0) vy = 1.0;
980 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.vbar", 0.0, vy);
981 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.hbar", vx, 0.0);
982 sd->pan_func.get(sd->pan_obj, &px, &py);
983 if (!_elm_config->thumbscroll_bounce_enable)
985 if (x < minx) x = minx;
986 if ((x - minx) > mx) x = mx + minx;
987 if (y < miny) y = miny;
988 if ((y - miny) > my) y = my + miny;
991 if (!sd->bounce_horiz)
993 if (x < minx) x = minx;
994 if ((x - minx) > mx) x = mx + minx;
996 if (!sd->bounce_vert)
998 if (y < miny) y = miny;
999 if (y - miny > my) y = my + miny;
1002 sd->pan_func.set(sd->pan_obj, x, y);
1003 if ((px != x) || (py != y))
1004 edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
1005 if (!sd->down.bounce_x_animator)
1007 if ((x < minx) || (x > (mx + minx)))
1013 if (!sd->down.bounce_y_animator)
1015 if ((y < miny) || (y > my + miny))
1021 if ((x != px) || (y != py))
1023 evas_object_smart_callback_call(obj, "scroll", NULL);
1025 if ((x != px)/* && (!sd->bouncemex)*/)
1028 evas_object_smart_callback_call(obj, "edge,left", NULL);
1029 if (x == (mx + minx))
1030 evas_object_smart_callback_call(obj, "edge,right", NULL);
1032 if ((y != py)/* && (!sd->bouncemey)*/)
1035 evas_object_smart_callback_call(obj, "edge,top", NULL);
1037 evas_object_smart_callback_call(obj, "edge,bottom", NULL);
1042 elm_smart_scroller_child_pos_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
1045 sd->pan_func.get(sd->pan_obj, x, y);
1048 /* returns TRUE when we need to move the scroller, FALSE otherwise.
1049 * Updates w and h either way, so save them if you need them. */
1051 _elm_smart_scroller_child_region_show_internal(Evas_Object *obj, Evas_Coord *_x, Evas_Coord *_y, Evas_Coord w, Evas_Coord h)
1053 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;
1055 API_ENTRY return EINA_FALSE;
1056 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
1057 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
1058 sd->pan_func.child_size_get(sd->pan_obj, &cw, &ch);
1059 sd->pan_func.get(sd->pan_obj, &px, &py);
1060 evas_object_geometry_get(sd->pan_obj, NULL, NULL, &pw, &ph);
1063 if ((x < px) && ((x + w) < (px + (cw - mx)))) nx = x;
1064 else if ((x > px) && ((x + w) > (px + (cw - mx)))) nx = x + w - (cw - mx);
1066 if ((y < py) && ((y + h) < (py + (ch - my)))) ny = y;
1067 else if ((y > py) && ((y + h) > (py + (ch - my)))) ny = y + h - (ch - my);
1069 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1070 (sd->scrollto.x.animator) || (sd->scrollto.y.animator))
1072 _smart_anim_stop(sd->smart_obj);
1074 if (sd->scrollto.x.animator)
1076 ecore_animator_del(sd->scrollto.x.animator);
1077 sd->scrollto.x.animator = NULL;
1079 if (sd->scrollto.y.animator)
1081 ecore_animator_del(sd->scrollto.y.animator);
1082 sd->scrollto.y.animator = NULL;
1084 if (sd->down.bounce_x_animator)
1086 ecore_animator_del(sd->down.bounce_x_animator);
1087 sd->down.bounce_x_animator = NULL;
1090 if (sd->down.bounce_y_animator)
1092 ecore_animator_del(sd->down.bounce_y_animator);
1093 sd->down.bounce_y_animator = NULL;
1096 if (sd->down.hold_animator)
1098 ecore_animator_del(sd->down.hold_animator);
1099 sd->down.hold_animator = NULL;
1100 _smart_drag_stop(sd->smart_obj);
1102 if (sd->down.momentum_animator)
1104 ecore_animator_del(sd->down.momentum_animator);
1105 sd->down.momentum_animator = NULL;
1106 sd->down.bounce_x_hold = 0;
1107 sd->down.bounce_y_hold = 0;
1115 if ((x + pw) > cw) x = cw - pw;
1116 if (x < minx) x = minx;
1118 if ((y + ph) > ch) y = ch - ph;
1119 if (y < miny) y = miny;
1121 if ((x == px) && (y == py)) return EINA_FALSE;
1127 /* Set should be used for calculated positions, for example, when we move
1128 * because of an animation or because this is the correct position after
1131 elm_smart_scroller_child_region_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
1133 if (_elm_smart_scroller_child_region_show_internal(obj, &x, &y, w, h))
1134 elm_smart_scroller_child_pos_set(obj, x, y);
1137 /* Set should be used for setting the wanted position, for example a user scroll
1138 * or moving the cursor in an entry. */
1140 elm_smart_scroller_child_region_show(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
1147 if (_elm_smart_scroller_child_region_show_internal(obj, &x, &y, w, h))
1148 elm_smart_scroller_child_pos_set(obj, x, y);
1152 elm_smart_scroller_child_viewport_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
1155 if (!sd->pan_obj) return;
1156 edje_object_calc_force(sd->edje_obj);
1157 evas_object_geometry_get(sd->pan_obj, NULL, NULL, w, h);
1161 elm_smart_scroller_step_size_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
1168 _smart_scrollbar_size_adjust(sd);
1172 elm_smart_scroller_step_size_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
1175 if (x) *x = sd->step.x;
1176 if (y) *y = sd->step.y;
1180 elm_smart_scroller_page_size_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
1185 _smart_scrollbar_size_adjust(sd);
1189 elm_smart_scroller_page_size_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
1192 if (x) *x = sd->page.x;
1193 if (y) *y = sd->page.y;
1197 elm_smart_scroller_policy_set(Evas_Object *obj, Elm_Smart_Scroller_Policy hbar, Elm_Smart_Scroller_Policy vbar)
1200 if ((sd->hbar_flags == hbar) && (sd->vbar_flags == vbar)) return;
1201 sd->hbar_flags = hbar;
1202 sd->vbar_flags = vbar;
1203 if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
1204 edje_object_signal_emit(sd->edje_obj, "elm,action,show_always,hbar", "elm");
1205 else if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
1206 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,hbar", "elm");
1208 edje_object_signal_emit(sd->edje_obj, "elm,action,show_notalways,hbar", "elm");
1209 if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
1210 edje_object_signal_emit(sd->edje_obj, "elm,action,show_always,vbar", "elm");
1211 else if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
1212 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,vbar", "elm");
1214 edje_object_signal_emit(sd->edje_obj, "elm,action,show_notalways,vbar", "elm");
1215 _smart_scrollbar_size_adjust(sd);
1219 elm_smart_scroller_policy_get(Evas_Object *obj, Elm_Smart_Scroller_Policy *hbar, Elm_Smart_Scroller_Policy *vbar)
1222 if (hbar) *hbar = sd->hbar_flags;
1223 if (vbar) *vbar = sd->vbar_flags;
1227 elm_smart_scroller_edje_object_get(Evas_Object *obj)
1229 API_ENTRY return NULL;
1230 return sd->edje_obj;
1234 elm_smart_scroller_single_dir_set(Evas_Object *obj, Eina_Bool single_dir)
1237 sd->one_dir_at_a_time = single_dir;
1241 elm_smart_scroller_single_dir_get(Evas_Object *obj)
1243 API_ENTRY return EINA_FALSE;
1244 return sd->one_dir_at_a_time;
1248 elm_smart_scroller_propagate_events_set(Evas_Object *obj, Eina_Bool propagation)
1251 sd->event_propagation = propagation;
1253 evas_object_propagate_events_set(sd->edje_obj, propagation);
1257 elm_smart_scroller_propagate_events_get(Evas_Object *obj)
1259 API_ENTRY return EINA_FALSE;
1260 return sd->event_propagation;
1264 elm_smart_scroller_object_theme_set(Evas_Object *parent, Evas_Object *obj, const char *clas, const char *group, const char *style)
1268 //Does this API require parent object absolutely? if then remove this exception.
1269 double parent_scale = parent ? elm_widget_scale_get(parent) : 1;
1270 _elm_theme_object_set(parent, sd->edje_obj, clas, group, style);
1271 edje_object_scale_set(sd->edje_obj, parent_scale * _elm_config->scale);
1273 edje_object_part_swallow(sd->edje_obj, "elm.swallow.content", sd->pan_obj);
1275 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1276 if (edje_object_part_exists(sd->edje_obj, "elm.scrollbar.base"))
1279 base = edje_object_part_swallow_get(sd->edje_obj, "elm.scrollbar.base");
1282 base = evas_object_rectangle_add(evas_object_evas_get(sd->edje_obj));
1283 evas_object_color_set(base, 0, 0, 0, 0);
1284 edje_object_part_swallow(sd->edje_obj, "elm.scrollbar.base", base);
1286 if (!_elm_config->thumbscroll_enable)
1287 evas_object_size_hint_min_set(base, mw, mh);
1289 sd->vbar_visible = !sd->vbar_visible;
1290 sd->hbar_visible = !sd->hbar_visible;
1291 _smart_scrollbar_bar_visibility_adjust(sd);
1295 elm_smart_scroller_hold_set(Evas_Object *obj, Eina_Bool hold)
1302 elm_smart_scroller_freeze_set(Evas_Object *obj, Eina_Bool freeze)
1305 sd->freeze = freeze;
1308 if (sd->down.onhold_animator)
1310 ecore_animator_del(sd->down.onhold_animator);
1311 sd->down.onhold_animator = NULL;
1319 elm_smart_scroller_bounce_allow_set(Evas_Object *obj, Eina_Bool horiz, Eina_Bool vert)
1322 sd->bounce_horiz = horiz;
1323 sd->bounce_vert = vert;
1327 elm_smart_scroller_bounce_allow_get(const Evas_Object *obj, Eina_Bool *horiz, Eina_Bool *vert)
1330 *horiz = sd->bounce_horiz;
1331 *vert = sd->bounce_vert;
1335 elm_smart_scroller_paging_set(Evas_Object *obj, double pagerel_h, double pagerel_v, Evas_Coord pagesize_h, Evas_Coord pagesize_v)
1338 sd->pagerel_h = pagerel_h;
1339 sd->pagerel_v = pagerel_v;
1340 sd->pagesize_h = pagesize_h;
1341 sd->pagesize_v = pagesize_v;
1342 _smart_page_adjust(sd);
1346 elm_smart_scroller_paging_get(Evas_Object *obj, double *pagerel_h, double *pagerel_v, Evas_Coord *pagesize_h, Evas_Coord *pagesize_v)
1349 if(pagerel_h) *pagerel_h = sd->pagerel_h;
1350 if(pagerel_v) *pagerel_v = sd->pagerel_v;
1351 if(pagesize_h) *pagesize_h = sd->pagesize_h;
1352 if(pagesize_v) *pagesize_v = sd->pagesize_v;
1356 elm_smart_scroller_region_bring_in(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
1359 if (_elm_smart_scroller_child_region_show_internal(obj, &x, &y, w, h))
1361 _smart_scrollto_x(sd, _elm_config->bring_in_scroll_friction, x);
1362 _smart_scrollto_y(sd, _elm_config->bring_in_scroll_friction, y);
1367 elm_smart_scroller_widget_set(Evas_Object *obj, Evas_Object *wid)
1374 _elm_smart_scroller_wanted_region_set(Evas_Object *obj)
1377 Evas_Coord ww, wh, wx = sd->wx;
1379 if (sd->down.now || sd->down.momentum_animator ||
1380 sd->down.bounce_x_animator || sd->down.bounce_y_animator ||
1381 sd->down.hold_animator || sd->down.onhold_animator) return;
1383 /* Flip to RTL cords only if init in RTL mode */
1385 wx = _elm_smart_scroller_x_mirrored_get(obj, sd->wx);
1389 elm_smart_scroller_child_viewport_size_get(obj, &ww, &wh);
1397 elm_smart_scroller_child_region_set(obj, wx, sd->wy, ww, wh);
1400 /* local subsystem functions */
1402 _smart_edje_drag_v_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1407 _smart_scrollbar_read(sd);
1408 _smart_drag_start(sd->smart_obj);
1409 sd->freeze = EINA_TRUE;
1413 _smart_edje_drag_v_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1418 _smart_scrollbar_read(sd);
1419 _smart_drag_stop(sd->smart_obj);
1420 sd->freeze = EINA_FALSE;
1424 _smart_edje_drag_v(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1429 _smart_scrollbar_read(sd);
1433 _smart_edje_drag_h_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1438 _smart_scrollbar_read(sd);
1439 _smart_drag_start(sd->smart_obj);
1440 sd->freeze = EINA_TRUE;
1444 _smart_edje_drag_h_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1449 _smart_scrollbar_read(sd);
1450 _smart_drag_stop(sd->smart_obj);
1451 sd->freeze = EINA_FALSE;
1455 _smart_edje_drag_h(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1460 _smart_scrollbar_read(sd);
1464 _smart_child_del_hook(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1469 sd->child_obj = NULL;
1470 _smart_scrollbar_size_adjust(sd);
1471 _smart_scrollbar_reset(sd);
1475 _smart_pan_changed_hook(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1481 sd->pan_func.child_size_get(sd->pan_obj, &w, &h);
1482 if ((w != sd->child.w) || (h != sd->child.h))
1486 _smart_scrollbar_size_adjust(sd);
1487 evas_object_size_hint_min_set(sd->smart_obj, sd->child.w, sd->child.h);
1488 _elm_smart_scroller_wanted_region_set(sd->smart_obj);
1493 _smart_pan_pan_changed_hook(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1498 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1499 (sd->scrollto.x.animator) || (sd->scrollto.y.animator))
1501 _smart_anim_stop(sd->smart_obj);
1503 if (sd->scrollto.x.animator)
1505 ecore_animator_del(sd->scrollto.x.animator);
1506 sd->scrollto.x.animator = NULL;
1508 if (sd->scrollto.y.animator)
1510 ecore_animator_del(sd->scrollto.y.animator);
1511 sd->scrollto.y.animator = NULL;
1513 if (sd->down.bounce_x_animator)
1515 ecore_animator_del(sd->down.bounce_x_animator);
1516 sd->down.bounce_x_animator = NULL;
1519 if (sd->down.bounce_y_animator)
1521 ecore_animator_del(sd->down.bounce_y_animator);
1522 sd->down.bounce_y_animator = NULL;
1525 _elm_smart_scroller_wanted_region_set(sd->smart_obj);
1529 _smart_event_wheel(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1531 Evas_Event_Mouse_Wheel *ev;
1533 Evas_Coord x = 0, y = 0;
1537 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
1538 if ((evas_key_modifier_is_set(ev->modifiers, "Control")) ||
1539 (evas_key_modifier_is_set(ev->modifiers, "Alt")) ||
1540 (evas_key_modifier_is_set(ev->modifiers, "Shift")) ||
1541 (evas_key_modifier_is_set(ev->modifiers, "Meta")) ||
1542 (evas_key_modifier_is_set(ev->modifiers, "Hyper")) ||
1543 (evas_key_modifier_is_set(ev->modifiers, "Super")))
1545 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1546 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1547 (sd->scrollto.x.animator) || (sd->scrollto.y.animator))
1549 _smart_anim_stop(sd->smart_obj);
1551 if (sd->scrollto.x.animator)
1553 ecore_animator_del(sd->scrollto.x.animator);
1554 sd->scrollto.x.animator = NULL;
1556 if (sd->scrollto.y.animator)
1558 ecore_animator_del(sd->scrollto.y.animator);
1559 sd->scrollto.y.animator = NULL;
1561 if (sd->down.bounce_x_animator)
1563 ecore_animator_del(sd->down.bounce_x_animator);
1564 sd->down.bounce_x_animator = NULL;
1567 if (sd->down.bounce_y_animator)
1569 ecore_animator_del(sd->down.bounce_y_animator);
1570 sd->down.bounce_y_animator = NULL;
1574 y += ev->z * sd->step.y;
1575 else if (ev->direction == 1)
1576 x += ev->z * sd->step.x;
1578 if ((!sd->hold) && (!sd->freeze))
1580 _update_wanted_coordinates(sd, x, y);
1581 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
1586 _smart_event_mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1588 Evas_Event_Mouse_Down *ev;
1590 Evas_Coord x = 0, y = 0;
1594 // if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
1595 if (_elm_config->thumbscroll_enable)
1598 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1599 (sd->down.momentum_animator) || (sd->scrollto.x.animator) ||
1600 (sd->scrollto.y.animator))
1602 ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL | EVAS_EVENT_FLAG_ON_HOLD;
1603 sd->down.scroll = 1;
1605 _smart_anim_stop(sd->smart_obj);
1607 if (sd->scrollto.x.animator)
1609 ecore_animator_del(sd->scrollto.x.animator);
1610 sd->scrollto.x.animator = NULL;
1612 if (sd->scrollto.y.animator)
1614 ecore_animator_del(sd->scrollto.y.animator);
1615 sd->scrollto.y.animator = NULL;
1617 if (sd->down.bounce_x_animator)
1619 ecore_animator_del(sd->down.bounce_x_animator);
1620 sd->down.bounce_x_animator = NULL;
1623 if (sd->down.bounce_y_animator)
1625 ecore_animator_del(sd->down.bounce_y_animator);
1626 sd->down.bounce_y_animator = NULL;
1629 if (sd->down.hold_animator)
1631 ecore_animator_del(sd->down.hold_animator);
1632 sd->down.hold_animator = NULL;
1633 _smart_drag_stop(sd->smart_obj);
1635 if (sd->down.momentum_animator)
1637 ecore_animator_del(sd->down.momentum_animator);
1638 sd->down.momentum_animator = NULL;
1639 sd->down.bounce_x_hold = 0;
1640 sd->down.bounce_y_hold = 0;
1644 if (ev->button == 1)
1646 sd->down.hist.est_timestamp_diff =
1647 ecore_loop_time_get() - ((double)ev->timestamp / 1000.0);
1648 sd->down.hist.tadd = 0.0;
1649 sd->down.hist.dxsum = 0.0;
1650 sd->down.hist.dysum = 0.0;
1652 sd->down.dragged = 0;
1655 sd->down.x = ev->canvas.x;
1656 sd->down.y = ev->canvas.y;
1657 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1660 sd->down.locked = 0;
1661 memset(&(sd->down.history[0]), 0, sizeof(sd->down.history[0]) * 60);
1663 sd->down.history[0].timestamp = ev->timestamp / 1000.0;
1664 sd->down.history[0].localtimestamp = ecore_loop_time_get();
1666 sd->down.history[0].timestamp = ecore_loop_time_get();
1668 sd->down.history[0].x = ev->canvas.x;
1669 sd->down.history[0].y = ev->canvas.y;
1671 sd->down.dragged_began = 0;
1672 sd->down.hold_parent = 0;
1673 sd->down.cancelled = 0;
1674 if(sd->hold || sd->freeze)
1675 sd->down.want_reset = 1;
1677 sd->down.want_reset = 0;
1682 _down_coord_eval(Smart_Data *sd, Evas_Coord *x, Evas_Coord *y)
1684 Evas_Coord minx, miny;
1686 if (sd->down.dir_x) *x = sd->down.sx - (*x - sd->down.x);
1687 else *x = sd->down.sx;
1688 if (sd->down.dir_y) *y = sd->down.sy - (*y - sd->down.y);
1689 else *y = sd->down.sy;
1691 if ((sd->down.dir_x) || (sd->down.dir_y))
1693 if (!((sd->down.dir_x) && (sd->down.dir_y)))
1695 if (sd->down.dir_x) *y = sd->down.locked_y;
1696 else *x = sd->down.locked_x;
1700 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
1703 *x += (minx - *x) * _elm_config->thumbscroll_border_friction;
1704 else if (sd->child.w <= sd->w)
1705 *x += (sd->down.sx - *x) * _elm_config->thumbscroll_border_friction;
1706 else if ((sd->child.w - sd->w + minx) < *x)
1707 *x += (sd->child.w - sd->w + minx - *x) *
1708 _elm_config->thumbscroll_border_friction;
1711 *y += (miny - *y) * _elm_config->thumbscroll_border_friction;
1712 else if (sd->child.h <= sd->h)
1713 *y += (sd->down.sy - *y) * _elm_config->thumbscroll_border_friction;
1714 else if ((sd->child.h - sd->h + miny) < *y)
1715 *y += (sd->child.h - sd->h + miny - *y) *
1716 _elm_config->thumbscroll_border_friction;
1720 _smart_hold_animator(void *data)
1722 Smart_Data *sd = data;
1723 Evas_Coord ox = 0, oy = 0, fx = 0, fy= 0;
1725 fx = sd->down.hold_x;
1726 fy = sd->down.hold_y;
1728 if (_elm_config->scroll_smooth_time_interval > 0.0)
1730 int i, count = 0; //count for the real event number we have to deal with
1731 int queue_size = 10; //for event queue size
1732 int src_index = 0, dst_index = 0;
1733 int xsum = 0, ysum=0;
1734 Evas_Coord x=0, y=0;
1742 double time_interval=_elm_config->scroll_smooth_time_interval;
1743 // FIXME: assume server and client have the same "timezone"
1744 // (0 timepoint) for now. this needs to be figured out in advance
1746 tdiff = sd->down.hist.est_timestamp_diff;
1747 tnow = ecore_time_get() - tdiff;
1749 for(i = 0; i < queue_size; i++)
1751 x = sd->down.history[i].x;
1752 y = sd->down.history[i].y;
1754 //if there is no history value , we don't deal with it
1755 //if there is better wat to know existance of history value , I will modify this code to it
1756 if ( (x == 0) && (y == 0) )
1760 _down_coord_eval(sd, &x, &y);
1764 pos[i].t = tnow - sd->down.history[i].timestamp;
1768 // we only deal with smooth scroll there is enough history
1769 for(i = 0; i < queue_size; i++)
1771 if (src_index > count) break;
1779 while ((pos[src_index].t < time_interval *i) &&
1780 (src_index <= count))
1784 if (src_index <= count)
1786 xsum += pos[src_index].x;
1787 ysum += pos[src_index].y;
1791 fx = xsum / dst_index;
1792 fy = ysum / dst_index;
1795 elm_smart_scroller_child_pos_get(sd->smart_obj, &ox, &oy);
1798 if ((!sd->widget) ||
1799 (!elm_widget_drag_child_locked_x_get(sd->widget)))
1806 if ((!sd->widget) ||
1807 (!elm_widget_drag_child_locked_y_get(sd->widget)))
1812 elm_smart_scroller_child_pos_set(sd->smart_obj, ox, oy);
1813 return ECORE_CALLBACK_RENEW;
1817 _smart_event_post_up(void *data, Evas *e __UNUSED__)
1819 Smart_Data *sd = data;
1822 if (sd->down.dragged)
1824 elm_widget_drag_lock_x_set(sd->widget, 0);
1825 elm_widget_drag_lock_y_set(sd->widget, 0);
1832 _smart_event_mouse_up(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *event_info)
1834 Evas_Event_Mouse_Down *ev;
1836 Evas_Coord x = 0, y = 0, ox = 0, oy = 0;
1840 sd->down.hold_parent = 0;
1841 // if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
1842 evas_post_event_callback_push(e, _smart_event_post_up, sd);
1843 // FIXME: respect elm_widget_scroll_hold_get of parent container
1844 if (_elm_config->thumbscroll_enable)
1846 if (ev->button == 1)
1848 if (sd->down.onhold_animator)
1850 ecore_animator_del(sd->down.onhold_animator);
1851 sd->down.onhold_animator = NULL;
1853 x = ev->canvas.x - sd->down.x;
1854 y = ev->canvas.y - sd->down.y;
1855 if (sd->down.dragged)
1857 _smart_drag_stop(sd->smart_obj);
1858 if ((!sd->hold) && (!sd->freeze))
1862 Evas_Coord ax, ay, dx, dy, vel;
1865 t = ev->timestamp / 1000.0;
1867 t = ecore_loop_time_get();
1869 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1874 printf("------ %i %i\n", ev->canvas.x, ev->canvas.y);
1876 for (i = 0; i < 60; i++)
1878 dt = t - sd->down.history[i].timestamp;
1879 if (dt > 0.2) break;
1881 printf("H: %i %i @ %1.3f\n",
1882 sd->down.history[i].x,
1883 sd->down.history[i].y, dt);
1886 ax += sd->down.history[i].x;
1887 ay += sd->down.history[i].y;
1892 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
1893 dx = ev->canvas.x - ax;
1894 dy = ev->canvas.y - ay;
1897 vel = sqrt((dx * dx) + (dy * dy)) / at;
1898 if ((_elm_config->thumbscroll_friction > 0.0) &&
1899 (vel > _elm_config->thumbscroll_momentum_threshold))
1901 sd->down.dx = ((double)dx / at);
1902 sd->down.dy = ((double)dy / at);
1903 if (((sd->down.dx > 0) && (sd->down.pdx > 0)) ||
1904 ((sd->down.dx < 0) && (sd->down.pdx < 0)))
1905 sd->down.dx += (double)sd->down.pdx * 1.5; // FIXME: * 1.5 - probably should be config
1906 if (((sd->down.dy > 0) && (sd->down.pdy > 0)) ||
1907 ((sd->down.dy < 0) && (sd->down.pdy < 0)))
1908 sd->down.dy += (double)sd->down.pdy * 1.5; // FIXME: * 1.5 - probably should be config
1909 if (((sd->down.dx > 0) && (sd->down.pdx > 0)) ||
1910 ((sd->down.dx < 0) && (sd->down.pdx < 0)) ||
1911 ((sd->down.dy > 0) && (sd->down.pdy > 0)) ||
1912 ((sd->down.dy < 0) && (sd->down.pdy < 0)))
1914 double t = ecore_loop_time_get();
1915 double dt = t - sd->down.anim_start;
1917 if (dt < 0.0) dt = 0.0;
1918 else if (dt > _elm_config->thumbscroll_friction)
1919 dt = _elm_config->thumbscroll_friction;
1920 sd->down.extra_time = _elm_config->thumbscroll_friction - dt;
1923 sd->down.extra_time = 0.0;
1924 sd->down.pdx = sd->down.dx;
1925 sd->down.pdy = sd->down.dy;
1928 if (!_smart_do_page(sd))
1930 if ((!sd->down.momentum_animator) && (!sd->momentum_animator_disabled))
1932 sd->down.momentum_animator = ecore_animator_add(_smart_momentum_animator, sd);
1933 ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL;
1934 _smart_anim_start(sd->smart_obj);
1936 sd->down.anim_start = ecore_loop_time_get();
1937 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1945 if (sd->down.hold_animator)
1947 ecore_animator_del(sd->down.hold_animator);
1948 sd->down.hold_animator = NULL;
1956 evas_event_feed_hold(e, 0, ev->timestamp, ev->data);
1957 if (_smart_do_page(sd))
1959 Evas_Coord pgx, pgy;
1961 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1962 if ((!sd->widget) ||
1963 (!elm_widget_drag_child_locked_x_get(sd->widget)))
1965 pgx = _smart_page_x_get(sd, ox);
1968 ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL;
1969 _smart_scrollto_x(sd, _elm_config->page_scroll_friction, pgx);
1972 if ((!sd->widget) ||
1973 (!elm_widget_drag_child_locked_y_get(sd->widget)))
1975 pgy = _smart_page_y_get(sd, oy);
1978 ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL;
1979 _smart_scrollto_y(sd, _elm_config->page_scroll_friction, pgy);
1988 if (_smart_do_page(sd))
1990 Evas_Coord pgx, pgy;
1992 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1993 if ((!sd->widget) ||
1994 (!elm_widget_drag_child_locked_x_get(sd->widget)))
1996 pgx = _smart_page_x_get(sd, ox);
1997 if (pgx != x) _smart_scrollto_x(sd, _elm_config->page_scroll_friction, pgx);
1999 if ((!sd->widget) ||
2000 (!elm_widget_drag_child_locked_y_get(sd->widget)))
2002 pgy = _smart_page_y_get(sd, oy);
2003 if (pgy != y) _smart_scrollto_y(sd, _elm_config->page_scroll_friction, pgy);
2006 if (sd->down.hold_animator)
2008 ecore_animator_del(sd->down.hold_animator);
2009 sd->down.hold_animator = NULL;
2012 if (sd->down.scroll)
2014 ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL;
2015 sd->down.scroll = 0;
2019 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2022 sd->down.dragged_began = 0;
2025 sd->down.want_dragged = 0;
2026 sd->down.dragged = 0;
2028 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
2029 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
2030 _update_wanted_coordinates(sd, x, y);
2032 if (!_smart_do_page(sd))
2039 _smart_onhold_animator(void *data)
2044 Evas_Coord x, y, ox, oy;
2047 t = ecore_loop_time_get();
2048 if (sd->down.onhold_tlast > 0.0)
2050 td = t - sd->down.onhold_tlast;
2051 vx = sd->down.onhold_vx * td * (double)_elm_config->thumbscroll_threshold * 2.0;
2052 vy = sd->down.onhold_vy * td * (double)_elm_config->thumbscroll_threshold * 2.0;
2053 elm_smart_scroller_child_pos_get(sd->smart_obj, &ox, &oy);
2059 if ((!sd->widget) ||
2060 (!elm_widget_drag_child_locked_x_get(sd->widget)))
2062 sd->down.onhold_vxe += vx;
2063 x = ox + (int)sd->down.onhold_vxe;
2064 sd->down.onhold_vxe -= (int)sd->down.onhold_vxe;
2070 if ((!sd->widget) ||
2071 (!elm_widget_drag_child_locked_y_get(sd->widget)))
2073 sd->down.onhold_vye += vy;
2074 y = oy + (int)sd->down.onhold_vye;
2075 sd->down.onhold_vye -= (int)sd->down.onhold_vye;
2079 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
2081 sd->down.onhold_tlast = t;
2082 return ECORE_CALLBACK_RENEW;
2086 _smart_event_post_move(void *data, Evas *e __UNUSED__)
2088 Smart_Data *sd = data;
2090 if (sd->down.want_dragged)
2094 if (sd->down.hold_parent)
2096 if ((sd->down.dir_x) && !can_scroll(sd, sd->down.hdir))
2100 if ((sd->down.dir_y) && !can_scroll(sd, sd->down.vdir))
2107 if ((!sd->widget) ||
2108 (!elm_widget_drag_child_locked_x_get(sd->widget)))
2110 sd->down.want_dragged = 0;
2111 sd->down.dragged = 1;
2114 elm_widget_drag_lock_x_set(sd->widget, 1);
2123 if ((!sd->widget) ||
2124 (!elm_widget_drag_child_locked_y_get(sd->widget)))
2126 sd->down.want_dragged = 0;
2127 sd->down.dragged = 1;
2130 elm_widget_drag_lock_y_set(sd->widget, 1);
2137 if ((!sd->down.dir_x) && (!sd->down.dir_y))
2139 sd->down.cancelled = 1;
2141 if (start) _smart_drag_start(sd->smart_obj);
2147 _smart_event_mouse_move(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *event_info)
2149 Evas_Event_Mouse_Move *ev;
2151 Evas_Coord x = 0, y = 0;
2155 // if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
2156 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) sd->down.hold_parent = 1;
2157 evas_post_event_callback_push(e, _smart_event_post_move, sd);
2158 // FIXME: respect elm_widget_scroll_hold_get of parent container
2159 if (_elm_config->thumbscroll_enable)
2166 printf("::: %i %i\n", ev->cur.canvas.x, ev->cur.canvas.y);
2168 memmove(&(sd->down.history[1]), &(sd->down.history[0]),
2169 sizeof(sd->down.history[0]) * (60 - 1));
2171 sd->down.history[0].timestamp = ev->timestamp / 1000.0;
2172 sd->down.history[0].localtimestamp = ecore_loop_time_get();
2174 sd->down.history[0].timestamp = ecore_loop_time_get();
2176 sd->down.history[0].x = ev->cur.canvas.x;
2177 sd->down.history[0].y = ev->cur.canvas.y;
2179 if (!sd->down.dragged_began)
2181 x = ev->cur.canvas.x - sd->down.x;
2182 y = ev->cur.canvas.y - sd->down.y;
2187 if (x > 0) sd->down.hdir = LEFT;
2188 else if (x < 0) sd->down.hdir = RIGHT;
2189 if (y > 0) sd->down.vdir = UP;
2190 else if (y < 0) sd->down.vdir = DOWN;
2195 if ((sd->one_dir_at_a_time) &&
2196 (!((sd->down.dir_x) || (sd->down.dir_y))))
2198 if (x > _elm_config->thumbscroll_threshold)
2207 if (y > _elm_config->thumbscroll_threshold)
2224 // can_scroll(sd, LEFT);
2225 // can_scroll(sd, RIGHT);
2226 // can_scroll(sd, UP);
2227 // can_scroll(sd, DOWN);
2232 if ((!sd->hold) && (!sd->freeze))
2234 if ((sd->down.dragged) ||
2235 (((x * x) + (y * y)) >
2236 (_elm_config->thumbscroll_threshold *
2237 _elm_config->thumbscroll_threshold)))
2239 sd->down.dragged_began = 1;
2240 if (!sd->down.dragged)
2242 sd->down.want_dragged = 1;
2243 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2244 // evas_event_feed_hold(e, 1, ev->timestamp, ev->data);
2245 // _smart_drag_start(sd->smart_obj);
2247 if (sd->down.dragged)
2249 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2251 // ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2252 // sd->down.dragged = 1;
2254 x = sd->down.sx - (ev->cur.canvas.x - sd->down.x);
2258 y = sd->down.sy - (ev->cur.canvas.y - sd->down.y);
2261 if(sd->down.want_reset)
2263 sd->down.x = ev->cur.canvas.x;
2264 sd->down.y = ev->cur.canvas.y;
2265 sd->down.want_reset = 0;
2267 if ((sd->down.dir_x) || (sd->down.dir_y))
2269 if (!sd->down.locked)
2271 sd->down.locked_x = x;
2272 sd->down.locked_y = y;
2273 sd->down.locked = 1;
2275 if (!((sd->down.dir_x) && (sd->down.dir_y)))
2277 if (sd->down.dir_x) y = sd->down.locked_y;
2278 else x = sd->down.locked_x;
2282 Evas_Coord minx, miny;
2283 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2286 _elm_config->thumbscroll_border_friction;
2287 else if (sd->child.h <= sd->h)
2288 y += (sd->down.sy - y) *
2289 _elm_config->thumbscroll_border_friction;
2290 else if ((sd->child.h - sd->h + miny) < y)
2291 y += (sd->child.h - sd->h + miny - y) *
2292 _elm_config->thumbscroll_border_friction;
2295 _elm_config->thumbscroll_border_friction;
2296 else if (sd->child.w <= sd->w)
2297 x += (sd->down.sx - x) *
2298 _elm_config->thumbscroll_border_friction;
2299 else if ((sd->child.w - sd->w + minx) < x)
2300 x += (sd->child.w - sd->w + minx - x) *
2301 _elm_config->thumbscroll_border_friction;
2304 sd->down.hold_x = x;
2305 sd->down.hold_y = y;
2306 if (!sd->down.hold_animator)
2307 sd->down.hold_animator =
2308 ecore_animator_add(_smart_hold_animator, sd);
2309 // printf("a %i %i\n", sd->down.hold_x, sd->down.hold_y);
2310 // _smart_onhold_animator(sd);
2311 // elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
2315 if (sd->down.dragged_began)
2317 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2321 evas_event_feed_hold(e, 1, ev->timestamp, ev->data);
2326 else if (!sd->freeze)
2328 Evas_Coord ex, ey, ew, eh;
2329 double vx = 0.0, vy = 0.0;
2331 evas_object_geometry_get(sd->event_obj, &ex, &ey, &ew, &eh);
2332 x = ev->cur.canvas.x - ex;
2333 y = ev->cur.canvas.y - ey;
2334 if (x < _elm_config->thumbscroll_threshold)
2336 if (_elm_config->thumbscroll_threshold > 0.0)
2337 vx = -(double)(_elm_config->thumbscroll_threshold - x) /
2338 _elm_config->thumbscroll_threshold;
2342 else if (x > (ew - _elm_config->thumbscroll_threshold))
2344 if (_elm_config->thumbscroll_threshold > 0.0)
2345 vx = (double)(_elm_config->thumbscroll_threshold - (ew - x)) /
2346 _elm_config->thumbscroll_threshold;
2350 if (y < _elm_config->thumbscroll_threshold)
2352 if (_elm_config->thumbscroll_threshold > 0.0)
2353 vy = -(double)(_elm_config->thumbscroll_threshold - y) /
2354 _elm_config->thumbscroll_threshold;
2358 else if (y > (eh - _elm_config->thumbscroll_threshold))
2360 if (_elm_config->thumbscroll_threshold > 0.0)
2361 vy = (double)(_elm_config->thumbscroll_threshold - (eh - y)) /
2362 _elm_config->thumbscroll_threshold;
2366 if ((vx != 0.0) || (vy != 0.0))
2368 sd->down.onhold_vx = vx;
2369 sd->down.onhold_vy = vy;
2370 if (!sd->down.onhold_animator)
2372 sd->down.onhold_vxe = 0.0;
2373 sd->down.onhold_vye = 0.0;
2374 sd->down.onhold_tlast = 0.0;
2375 sd->down.onhold_animator = ecore_animator_add(_smart_onhold_animator, sd);
2377 // printf("b %i %i\n", sd->down.hold_x, sd->down.hold_y);
2381 if (sd->down.onhold_animator)
2383 ecore_animator_del(sd->down.onhold_animator);
2384 sd->down.onhold_animator = NULL;
2393 _smart_scrollbar_read(Smart_Data *sd)
2395 Evas_Coord x, y, mx = 0, my = 0, px, py, minx = 0, miny = 0;
2398 edje_object_part_drag_value_get(sd->edje_obj, "elm.dragable.vbar", NULL, &vy);
2399 edje_object_part_drag_value_get(sd->edje_obj, "elm.dragable.hbar", &vx, NULL);
2400 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
2401 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2402 x = vx * (double)mx + minx;
2403 y = vy * (double)my + miny;
2404 sd->pan_func.get(sd->pan_obj, &px, &py);
2405 sd->pan_func.set(sd->pan_obj, x, y);
2406 if ((px != x) || (py != y))
2407 edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
2411 _smart_scrollbar_reset(Smart_Data *sd)
2413 Evas_Coord px = 0, py = 0, minx = 0, miny = 0;
2415 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.vbar", 0.0, 0.0);
2416 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.hbar", 0.0, 0.0);
2417 if ((!sd->child_obj) && (!sd->extern_pan))
2419 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.vbar", 1.0, 1.0);
2420 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.hbar", 1.0, 1.0);
2424 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2425 sd->pan_func.get(sd->pan_obj, &px, &py);
2426 sd->pan_func.set(sd->pan_obj, minx, miny);
2428 if ((px != minx) || (py != miny))
2429 edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
2433 _smart_scrollbar_bar_v_visibility_adjust(Smart_Data *sd)
2435 int scroll_v_vis_change = 0;
2436 Evas_Coord h, vw = 0, vh = 0;
2440 evas_object_geometry_get(sd->pan_obj, NULL, NULL, &vw, &vh);
2441 if (sd->vbar_visible)
2443 if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_AUTO)
2445 if ((sd->child_obj) || (sd->extern_pan))
2449 scroll_v_vis_change = 1;
2450 sd->vbar_visible = 0;
2455 scroll_v_vis_change = 1;
2456 sd->vbar_visible = 0;
2459 else if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
2461 scroll_v_vis_change = 1;
2462 sd->vbar_visible = 0;
2467 if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_AUTO)
2469 if ((sd->child_obj) || (sd->extern_pan))
2473 scroll_v_vis_change = 1;
2474 sd->vbar_visible = 1;
2478 else if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
2480 scroll_v_vis_change = 1;
2481 sd->vbar_visible = 1;
2484 if (scroll_v_vis_change)
2486 if (sd->vbar_flags != ELM_SMART_SCROLLER_POLICY_OFF)
2488 if (sd->vbar_visible)
2489 edje_object_signal_emit(sd->edje_obj, "elm,action,show,vbar", "elm");
2491 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,vbar", "elm");
2492 edje_object_message_signal_process(sd->edje_obj);
2493 _smart_scrollbar_size_adjust(sd);
2496 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,vbar", "elm");
2498 return scroll_v_vis_change;
2502 _smart_scrollbar_bar_h_visibility_adjust(Smart_Data *sd)
2504 int scroll_h_vis_change = 0;
2505 Evas_Coord w, vw = 0, vh = 0;
2509 evas_object_geometry_get(sd->pan_obj, NULL, NULL, &vw, &vh);
2510 if (sd->hbar_visible)
2512 if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_AUTO)
2514 if ((sd->child_obj) || (sd->extern_pan))
2518 scroll_h_vis_change = 1;
2519 sd->hbar_visible = 0;
2524 scroll_h_vis_change = 1;
2525 sd->hbar_visible = 0;
2528 else if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
2530 scroll_h_vis_change = 1;
2531 sd->hbar_visible = 0;
2536 if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_AUTO)
2538 if ((sd->child_obj) || (sd->extern_pan))
2542 scroll_h_vis_change = 1;
2543 sd->hbar_visible = 1;
2547 else if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
2549 scroll_h_vis_change = 1;
2550 sd->hbar_visible = 1;
2553 if (scroll_h_vis_change)
2555 if (sd->hbar_flags != ELM_SMART_SCROLLER_POLICY_OFF)
2557 if (sd->hbar_visible)
2558 edje_object_signal_emit(sd->edje_obj, "elm,action,show,hbar", "elm");
2560 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,hbar", "elm");
2561 edje_object_message_signal_process(sd->edje_obj);
2562 _smart_scrollbar_size_adjust(sd);
2565 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,hbar", "elm");
2566 _smart_scrollbar_size_adjust(sd);
2568 return scroll_h_vis_change;
2572 _smart_scrollbar_bar_visibility_adjust(Smart_Data *sd)
2576 changed |= _smart_scrollbar_bar_h_visibility_adjust(sd);
2577 changed |= _smart_scrollbar_bar_v_visibility_adjust(sd);
2580 _smart_scrollbar_bar_h_visibility_adjust(sd);
2581 _smart_scrollbar_bar_v_visibility_adjust(sd);
2586 _smart_scrollbar_size_adjust(Smart_Data *sd)
2588 if ((sd->child_obj) || (sd->extern_pan))
2590 Evas_Coord x, y, w, h, mx = 0, my = 0, vw = 0, vh = 0, px, py, minx = 0, miny = 0;
2591 double vx, vy, size;
2593 edje_object_part_geometry_get(sd->edje_obj, "elm.swallow.content",
2594 NULL, NULL, &vw, &vh);
2597 size = (double)vw / (double)w;
2601 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.hbar", 0.0, 0.0);
2603 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.hbar", size, 1.0);
2607 size = (double)vh / (double)h;
2611 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.vbar", 0.0, 0.0);
2613 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.vbar", 1.0, size);
2615 edje_object_part_drag_value_get(sd->edje_obj, "elm.dragable.hbar", &vx, NULL);
2616 edje_object_part_drag_value_get(sd->edje_obj, "elm.dragable.vbar", NULL, &vy);
2617 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
2618 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2622 edje_object_part_drag_step_set(sd->edje_obj, "elm.dragable.hbar", (double)sd->step.x / (double)w, 0.0);
2623 edje_object_part_drag_step_set(sd->edje_obj, "elm.dragable.vbar", 0.0, (double)sd->step.y / (double)h);
2625 edje_object_part_drag_page_set(sd->edje_obj, "elm.dragable.hbar", (double)sd->page.x / (double)w, 0.0);
2627 edje_object_part_drag_page_set(sd->edje_obj, "elm.dragable.hbar", -((double)sd->page.x * ((double)vw / (double)w)) / 100.0, 0.0);
2629 edje_object_part_drag_page_set(sd->edje_obj, "elm.dragable.vbar", 0.0, (double)sd->page.y / (double)h);
2631 edje_object_part_drag_page_set(sd->edje_obj, "elm.dragable.vbar", 0.0, -((double)sd->page.y * ((double)vh / (double)h)) / 100.0);
2633 sd->pan_func.get(sd->pan_obj, &px, &py);
2634 if (vx != mx) x = px;
2635 if (vy != my) y = py;
2636 sd->pan_func.set(sd->pan_obj, x, y);
2637 // if ((px != 0) || (py != 0))
2638 // edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
2642 Evas_Coord px = 0, py = 0, minx = 0, miny = 0;
2644 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.vbar", 1.0, 1.0);
2645 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);
2649 if ((px != minx) || (py != miny))
2650 edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
2652 _smart_scrollbar_bar_visibility_adjust(sd);
2656 _smart_reconfigure(Smart_Data *sd)
2658 evas_object_move(sd->edje_obj, sd->x, sd->y);
2659 evas_object_resize(sd->edje_obj, sd->w, sd->h);
2660 evas_object_move(sd->event_obj, sd->x, sd->y);
2661 evas_object_resize(sd->event_obj, sd->w, sd->h);
2662 _smart_scrollbar_size_adjust(sd);
2666 _smart_add(Evas_Object *obj)
2671 sd = calloc(1, sizeof(Smart_Data));
2673 evas_object_smart_data_set(obj, sd);
2675 sd->smart_obj = obj;
2684 sd->hbar_flags = ELM_SMART_SCROLLER_POLICY_AUTO;
2685 sd->vbar_flags = ELM_SMART_SCROLLER_POLICY_AUTO;
2686 sd->hbar_visible = 1;
2687 sd->vbar_visible = 1;
2689 sd->bounce_horiz = 1;
2690 sd->bounce_vert = 1;
2692 sd->one_dir_at_a_time = 1;
2693 sd->momentum_animator_disabled = EINA_FALSE;
2694 sd->bounce_animator_disabled = EINA_FALSE;
2696 o = edje_object_add(evas_object_evas_get(obj));
2697 evas_object_propagate_events_set(o, 0);
2699 elm_smart_scroller_object_theme_set(NULL, obj, "scroller", "base", "default");
2700 edje_object_signal_callback_add(o, "drag", "elm.dragable.vbar", _smart_edje_drag_v, sd);
2701 edje_object_signal_callback_add(o, "drag,start", "elm.dragable.vbar", _smart_edje_drag_v_start, sd);
2702 edje_object_signal_callback_add(o, "drag,stop", "elm.dragable.vbar", _smart_edje_drag_v_stop, sd);
2703 edje_object_signal_callback_add(o, "drag,step", "elm.dragable.vbar", _smart_edje_drag_v, sd);
2704 edje_object_signal_callback_add(o, "drag,page", "elm.dragable.vbar", _smart_edje_drag_v, sd);
2705 edje_object_signal_callback_add(o, "drag", "elm.dragable.hbar", _smart_edje_drag_h, sd);
2706 edje_object_signal_callback_add(o, "drag,start", "elm.dragable.hbar", _smart_edje_drag_h_start, sd);
2707 edje_object_signal_callback_add(o, "drag,stop", "elm.dragable.hbar", _smart_edje_drag_h_stop, sd);
2708 edje_object_signal_callback_add(o, "drag,step", "elm.dragable.hbar", _smart_edje_drag_h, sd);
2709 edje_object_signal_callback_add(o, "drag,page", "elm.dragable.hbar", _smart_edje_drag_h, sd);
2710 evas_object_smart_member_add(o, obj);
2712 o = evas_object_rectangle_add(evas_object_evas_get(obj));
2714 evas_object_color_set(o, 0, 0, 0, 0);
2715 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_WHEEL, _smart_event_wheel, sd);
2716 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, _smart_event_mouse_down, sd);
2717 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_UP, _smart_event_mouse_up, sd);
2718 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_MOVE, _smart_event_mouse_move, sd);
2719 evas_object_smart_member_add(o, obj);
2720 evas_object_repeat_events_set(o, 1);
2722 sd->pan_func.set = _elm_smart_pan_set;
2723 sd->pan_func.get = _elm_smart_pan_get;
2724 sd->pan_func.max_get = _elm_smart_pan_max_get;
2725 sd->pan_func.min_get = _elm_smart_pan_min_get;
2726 sd->pan_func.child_size_get = _elm_smart_pan_child_size_get;
2728 _smart_scrollbar_reset(sd);
2732 _smart_del(Evas_Object *obj)
2735 elm_smart_scroller_child_set(obj, NULL);
2736 if (!sd->extern_pan) evas_object_del(sd->pan_obj);
2737 evas_object_del(sd->edje_obj);
2738 evas_object_del(sd->event_obj);
2739 if (sd->down.hold_animator) ecore_animator_del(sd->down.hold_animator);
2740 if (sd->down.onhold_animator) ecore_animator_del(sd->down.onhold_animator);
2741 if (sd->down.momentum_animator) ecore_animator_del(sd->down.momentum_animator);
2742 if (sd->down.bounce_x_animator) ecore_animator_del(sd->down.bounce_x_animator);
2743 if (sd->down.bounce_y_animator) ecore_animator_del(sd->down.bounce_y_animator);
2744 if (sd->scrollto.x.animator) ecore_animator_del(sd->scrollto.x.animator);
2745 if (sd->scrollto.y.animator) ecore_animator_del(sd->scrollto.y.animator);
2747 evas_object_smart_data_set(obj, NULL);
2751 _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
2756 _smart_reconfigure(sd);
2760 _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
2765 _smart_reconfigure(sd);
2766 _elm_smart_scroller_wanted_region_set(obj);
2770 _smart_show(Evas_Object *obj)
2773 evas_object_show(sd->edje_obj);
2774 evas_object_show(sd->event_obj);
2778 _smart_hide(Evas_Object *obj)
2781 evas_object_hide(sd->edje_obj);
2782 evas_object_hide(sd->event_obj);
2786 _smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
2789 evas_object_color_set(sd->edje_obj, r, g, b, a);
2793 _smart_clip_set(Evas_Object *obj, Evas_Object *clip)
2796 evas_object_clip_set(sd->edje_obj, clip);
2797 evas_object_clip_set(sd->event_obj, clip);
2801 _smart_clip_unset(Evas_Object *obj)
2804 evas_object_clip_unset(sd->edje_obj);
2805 evas_object_clip_unset(sd->event_obj);
2808 /* never need to touch this */
2815 static const Evas_Smart_Class sc =
2818 EVAS_SMART_CLASS_VERSION,
2836 _smart = evas_smart_class_new(&sc);