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;
44 double onhold_vx, onhold_vy, onhold_tlast, onhold_vxe, onhold_vye;
46 Evas_Coord hold_x, hold_y;
47 Ecore_Animator *hold_animator;
48 Ecore_Animator *onhold_animator;
49 Ecore_Animator *momentum_animator;
50 Ecore_Animator *bounce_x_animator;
51 Ecore_Animator *bounce_y_animator;
52 Evas_Coord locked_x, locked_y;
54 unsigned char now : 1;
55 unsigned char cancelled : 1;
56 unsigned char hold : 1;
57 unsigned char hold_parent : 1;
58 unsigned char want_dragged : 1;
59 unsigned char dragged : 1;
60 unsigned char dragged_began : 1;
61 unsigned char dir_x : 1;
62 unsigned char dir_y : 1;
63 unsigned char locked : 1;
64 unsigned char bounce_x_hold : 1;
65 unsigned char bounce_y_hold : 1;
66 unsigned char scroll : 1;
67 unsigned char want_reset : 1;
78 void (*set) (Evas_Object *obj, Evas_Coord x, Evas_Coord y);
79 void (*get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y);
80 void (*max_get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y);
81 void (*min_get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y);
82 void (*child_size_get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y);
87 Evas_Coord start, end;
88 double t_start, t_end;
89 Ecore_Animator *animator;
93 double pagerel_h, pagerel_v;
94 Evas_Coord pagesize_h, pagesize_v;
96 unsigned char hbar_visible : 1;
97 unsigned char vbar_visible : 1;
98 unsigned char extern_pan : 1;
99 unsigned char one_dir_at_a_time : 1;
100 unsigned char hold : 1;
101 unsigned char freeze : 1;
102 unsigned char bouncemex : 1;
103 unsigned char bouncemey : 1;
104 unsigned char bounce_horiz : 1;
105 unsigned char bounce_vert : 1;
106 unsigned char momentum_animator_disabled :1;
107 unsigned char bounce_animator_disabled :1;
108 unsigned char event_propagation :1;
111 /* local subsystem functions */
112 static void _smart_child_del_hook(void *data, Evas *e, Evas_Object *obj, void *event_info);
113 static void _smart_pan_changed_hook(void *data, Evas_Object *obj, void *event_info);
114 static void _smart_pan_pan_changed_hook(void *data, Evas_Object *obj, void *event_info);
115 static void _smart_event_wheel(void *data, Evas *e, Evas_Object *obj, void *event_info);
116 static void _smart_event_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info);
117 static Eina_Bool _smart_hold_animator(void *data);
118 static Eina_Bool _smart_momentum_animator(void *data);
119 static void _smart_event_mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info);
120 static Eina_Bool _smart_onhold_animator(void *data);
121 static void _smart_event_mouse_move(void *data, Evas *e, Evas_Object *obj, void *event_info);
122 static void _smart_edje_drag_v_start(void *data, Evas_Object *obj, const char *emission, const char *source);
123 static void _smart_edje_drag_v_stop(void *data, Evas_Object *obj, const char *emission, const char *source);
124 static void _smart_edje_drag_v(void *data, Evas_Object *obj, const char *emission, const char *source);
125 static void _smart_edje_drag_h_start(void *data, Evas_Object *obj, const char *emission, const char *source);
126 static void _smart_edje_drag_h_stop(void *data, Evas_Object *obj, const char *emission, const char *source);
127 static void _smart_edje_drag_h(void *data, Evas_Object *obj, const char *emission, const char *source);
128 static void _smart_scrollbar_read(Smart_Data *sd);
129 static void _smart_scrollbar_reset(Smart_Data *sd);
130 static int _smart_scrollbar_bar_h_visibility_adjust(Smart_Data *sd);
131 static int _smart_scrollbar_bar_v_visibility_adjust(Smart_Data *sd);
132 static void _smart_scrollbar_bar_visibility_adjust(Smart_Data *sd);
133 static void _smart_scrollbar_size_adjust(Smart_Data *sd);
134 static void _smart_reconfigure(Smart_Data *sd);
135 static void _smart_add(Evas_Object *obj);
136 static void _smart_del(Evas_Object *obj);
137 static void _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y);
138 static void _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h);
139 static void _smart_show(Evas_Object *obj);
140 static void _smart_hide(Evas_Object *obj);
141 static void _smart_color_set(Evas_Object *obj, int r, int g, int b, int a);
142 static void _smart_clip_set(Evas_Object *obj, Evas_Object *clip);
143 static void _smart_clip_unset(Evas_Object *obj);
144 static void _smart_init(void);
146 /* local subsystem globals */
147 static Evas_Smart *_smart = NULL;
149 /* externally accessible functions */
151 elm_smart_scroller_add(Evas *evas)
154 return evas_object_smart_add(evas, _smart);
158 elm_smart_scroller_child_set(Evas_Object *obj, Evas_Object *child)
166 _elm_smart_pan_child_set(sd->pan_obj, NULL);
167 evas_object_event_callback_del_full(sd->child_obj, EVAS_CALLBACK_DEL, _smart_child_del_hook, sd);
170 sd->child_obj = child;
171 sd->wx = sd->wy = sd->ww = sd->wh = 0;
176 o = _elm_smart_pan_add(evas_object_evas_get(obj));
178 evas_object_smart_callback_add(o, "changed", _smart_pan_changed_hook, sd);
179 evas_object_smart_callback_add(o, "pan_changed", _smart_pan_pan_changed_hook, sd);
181 edje_object_part_swallow(sd->edje_obj, "elm.swallow.content", o);
184 sd->pan_func.set = _elm_smart_pan_set;
185 sd->pan_func.get = _elm_smart_pan_get;
186 sd->pan_func.max_get = _elm_smart_pan_max_get;
187 sd->pan_func.min_get = _elm_smart_pan_min_get;
188 sd->pan_func.child_size_get = _elm_smart_pan_child_size_get;
190 evas_object_event_callback_add(child, EVAS_CALLBACK_DEL, _smart_child_del_hook, sd);
191 _elm_smart_pan_child_set(sd->pan_obj, sd->child_obj);
192 sd->pan_func.child_size_get(sd->pan_obj, &w, &h);
195 _smart_scrollbar_size_adjust(sd);
196 _smart_scrollbar_reset(sd);
200 elm_smart_scroller_extern_pan_set(Evas_Object *obj, Evas_Object *pan,
201 void (*pan_set) (Evas_Object *obj, Evas_Coord x, Evas_Coord y),
202 void (*pan_get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y),
203 void (*pan_max_get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y),
204 void (*pan_min_get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y),
205 void (*pan_child_size_get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y))
209 elm_smart_scroller_child_set(obj, NULL);
213 evas_object_smart_callback_del(sd->pan_obj, "changed", _smart_pan_changed_hook);
214 evas_object_smart_callback_del(sd->pan_obj, "pan_changed", _smart_pan_pan_changed_hook);
221 edje_object_part_unswallow(sd->edje_obj, sd->pan_obj);
229 evas_object_del(sd->pan_obj);
240 sd->pan_func.set = pan_set;
241 sd->pan_func.get = pan_get;
242 sd->pan_func.max_get = pan_max_get;
243 sd->pan_func.min_get = pan_min_get;
244 sd->pan_func.child_size_get = pan_child_size_get;
246 evas_object_smart_callback_add(sd->pan_obj, "changed", _smart_pan_changed_hook, sd);
247 evas_object_smart_callback_add(sd->pan_obj, "pan_changed", _smart_pan_pan_changed_hook, sd);
248 edje_object_part_swallow(sd->edje_obj, "elm.swallow.content", sd->pan_obj);
249 evas_object_show(sd->pan_obj);
253 elm_smart_scroller_custom_edje_file_set(Evas_Object *obj, char *file, char *group)
257 edje_object_file_set(sd->edje_obj, file, group);
259 edje_object_part_swallow(sd->edje_obj, "elm.swallow.content", sd->pan_obj);
260 sd->vbar_visible = !sd->vbar_visible;
261 sd->hbar_visible = !sd->hbar_visible;
262 _smart_scrollbar_bar_visibility_adjust(sd);
263 if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
264 edje_object_signal_emit(sd->edje_obj, "elm,action,show_always,hbar", "elm");
265 else if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
266 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,hbar", "elm");
268 edje_object_signal_emit(sd->edje_obj, "elm,action,show_notalways,hbar", "elm");
269 if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
270 edje_object_signal_emit(sd->edje_obj, "elm,action,show_always,vbar", "elm");
271 else if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
272 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,vbar", "elm");
274 edje_object_signal_emit(sd->edje_obj, "elm,action,show_notalways,vbar", "elm");
278 elm_smart_scroller_momentum_animator_disabled_get(Evas_Object *obj)
280 API_ENTRY return EINA_FALSE;
281 return sd->momentum_animator_disabled;
285 elm_smart_scroller_momentum_animator_disabled_set(Evas_Object *obj, Eina_Bool disabled)
288 sd->momentum_animator_disabled = disabled;
289 if (sd->momentum_animator_disabled)
291 if (sd->down.momentum_animator)
293 ecore_animator_del(sd->down.momentum_animator);
294 sd->down.momentum_animator = NULL;
300 elm_smart_scroller_bounce_animator_disabled_get(Evas_Object *obj)
302 API_ENTRY return EINA_FALSE;
303 return sd->bounce_animator_disabled;
307 elm_smart_scroller_bounce_animator_disabled_set(Evas_Object *obj, Eina_Bool disabled)
310 sd->bounce_animator_disabled = disabled;
311 if (sd->bounce_animator_disabled)
313 if (sd->scrollto.x.animator)
315 ecore_animator_del(sd->scrollto.x.animator);
316 sd->scrollto.x.animator = NULL;
319 if (sd->scrollto.y.animator)
321 ecore_animator_del(sd->scrollto.y.animator);
322 sd->scrollto.y.animator = NULL;
328 _smart_anim_start(Evas_Object *obj)
330 evas_object_smart_callback_call(obj, "animate,start", NULL);
334 _smart_anim_stop(Evas_Object *obj)
336 evas_object_smart_callback_call(obj, "animate,stop", NULL);
340 _smart_drag_start(Evas_Object *obj)
342 evas_object_smart_callback_call(obj, "drag,start", NULL);
346 _smart_drag_stop(Evas_Object *obj)
348 evas_object_smart_callback_call(obj, "drag,stop", NULL);
352 _smart_scrollto_x_animator(void *data)
354 Smart_Data *sd = data;
358 t = ecore_loop_time_get();
359 tt = (t - sd->scrollto.x.t_start) / (sd->scrollto.x.t_end - sd->scrollto.x.t_start);
361 tt = 1.0 - (tt * tt);
362 sd->pan_func.get(sd->pan_obj, &px, &py);
363 px = (sd->scrollto.x.start * (1.0 - tt)) +
364 (sd->scrollto.x.end * tt);
365 if (t >= sd->scrollto.x.t_end)
367 px = sd->scrollto.x.end;
368 elm_smart_scroller_child_pos_set(sd->smart_obj, px, py);
369 sd->scrollto.x.animator = NULL;
370 if ((!sd->scrollto.y.animator) && (!sd->down.bounce_y_animator))
371 _smart_anim_stop(sd->smart_obj);
372 return ECORE_CALLBACK_CANCEL;
374 elm_smart_scroller_child_pos_set(sd->smart_obj, px, py);
375 return ECORE_CALLBACK_RENEW;
379 _smart_momentum_end(Smart_Data *sd)
381 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator)) return;
382 if (sd->down.momentum_animator)
384 ecore_animator_del(sd->down.momentum_animator);
385 sd->down.momentum_animator = NULL;
386 sd->down.bounce_x_hold = 0;
387 sd->down.bounce_y_hold = 0;
396 _smart_scrollto_x(Smart_Data *sd, double t_in, Evas_Coord pos_x)
398 Evas_Coord px, py, x, y, w, h;
401 if (sd->freeze) return;
404 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
405 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
407 //elm_smart_scroller_child_region_set(sd->smart_obj, x, y, w, h);
410 t = ecore_loop_time_get();
411 sd->pan_func.get(sd->pan_obj, &px, &py);
412 sd->scrollto.x.start = px;
413 sd->scrollto.x.end = pos_x;
414 sd->scrollto.x.t_start = t;
415 sd->scrollto.x.t_end = t + t_in;
416 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
417 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
418 //elm_smart_scroller_child_region_set(sd->smart_obj, x, y, w, h);
419 if (!sd->scrollto.x.animator)
421 if (!sd->scrollto.y.animator)
422 _smart_anim_start(sd->smart_obj);
423 sd->scrollto.x.animator = ecore_animator_add(_smart_scrollto_x_animator, sd);
425 if (sd->down.bounce_x_animator)
427 ecore_animator_del(sd->down.bounce_x_animator);
428 sd->down.bounce_x_animator = NULL;
429 _smart_momentum_end(sd);
435 _smart_scrollto_y_animator(void *data)
437 Smart_Data *sd = data;
441 t = ecore_loop_time_get();
442 tt = (t - sd->scrollto.y.t_start) / (sd->scrollto.y.t_end - sd->scrollto.y.t_start);
444 tt = 1.0 - (tt * tt);
445 sd->pan_func.get(sd->pan_obj, &px, &py);
446 py = (sd->scrollto.y.start * (1.0 - tt)) +
447 (sd->scrollto.y.end * tt);
448 if (t >= sd->scrollto.y.t_end)
450 py = sd->scrollto.y.end;
451 elm_smart_scroller_child_pos_set(sd->smart_obj, px, py);
452 sd->scrollto.y.animator = NULL;
453 if ((!sd->scrollto.x.animator) && (!sd->down.bounce_x_animator))
454 _smart_anim_stop(sd->smart_obj);
455 return ECORE_CALLBACK_CANCEL;
457 elm_smart_scroller_child_pos_set(sd->smart_obj, px, py);
459 return ECORE_CALLBACK_RENEW;
463 _smart_scrollto_y(Smart_Data *sd, double t_in, Evas_Coord pos_y)
465 Evas_Coord px, py, x, y, w, h;
468 if (sd->freeze) return;
471 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
472 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
474 //elm_smart_scroller_child_region_set(sd->smart_obj, x, y, w, h);
477 t = ecore_loop_time_get();
478 sd->pan_func.get(sd->pan_obj, &px, &py);
479 sd->scrollto.y.start = py;
480 sd->scrollto.y.end = pos_y;
481 sd->scrollto.y.t_start = t;
482 sd->scrollto.y.t_end = t + t_in;
483 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
484 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
485 //elm_smart_scroller_child_region_set(sd->smart_obj, x, y, w, h);
486 if (!sd->scrollto.y.animator)
488 if (!sd->scrollto.x.animator)
489 _smart_anim_start(sd->smart_obj);
490 sd->scrollto.y.animator = ecore_animator_add(_smart_scrollto_y_animator, sd);
492 if (sd->down.bounce_y_animator)
494 ecore_animator_del(sd->down.bounce_y_animator);
495 sd->down.bounce_y_animator = NULL;
496 _smart_momentum_end(sd);
502 _smart_do_page(Smart_Data *sd)
504 if ((sd->pagerel_h == 0.0) && (!sd->pagesize_h) &&
505 (sd->pagerel_v == 0.0) && (!sd->pagesize_v))
511 _smart_page_x_get(Smart_Data *sd, int offset)
513 Evas_Coord x, y, w, h, cw, ch, minx = 0;
515 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
516 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
517 sd->pan_func.child_size_get(sd->pan_obj, &cw, &ch);
518 sd->pan_func.min_get(sd->pan_obj, &minx, NULL);
522 if (sd->pagerel_h > 0.0)
524 x = x + (w * sd->pagerel_h * 0.5);
525 x = x / (w * sd->pagerel_h);
526 x = x * (w * sd->pagerel_h);
528 else if (sd->pagesize_h > 0)
530 x = x + (sd->pagesize_h * 0.5);
531 x = x / (sd->pagesize_h);
532 x = x * (sd->pagesize_h);
534 if (x < minx) x = minx;
535 else if ((x + w) > cw) x = cw - w;
540 _smart_page_y_get(Smart_Data *sd, int offset)
542 Evas_Coord x, y, w, h, cw, ch, miny = 0;
544 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
545 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
546 sd->pan_func.child_size_get(sd->pan_obj, &cw, &ch);
547 sd->pan_func.min_get(sd->pan_obj, NULL, &miny);
551 if (sd->pagerel_v > 0.0)
553 y = y + (h * sd->pagerel_v * 0.5);
554 y = y / (h * sd->pagerel_v);
555 y = y * (h * sd->pagerel_v);
557 else if (sd->pagesize_v > 0)
559 y = y + (sd->pagesize_v * 0.5);
560 y = y / (sd->pagesize_v);
561 y = y * (sd->pagesize_v);
563 if (y < miny) y = miny;
564 else if ((y + h) > ch) y = ch - h;
569 _smart_page_adjust(Smart_Data *sd)
571 Evas_Coord x, y, w, h;
573 if (!_smart_do_page(sd)) return;
575 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
577 x = _smart_page_x_get(sd, 0);
578 y = _smart_page_y_get(sd, 0);
580 elm_smart_scroller_child_region_set(sd->smart_obj, x, y, w, h);
584 _smart_bounce_x_animator(void *data)
587 Evas_Coord x, y, dx, px, cw, w;
591 t = ecore_loop_time_get();
592 dt = t - sd->down.anim_start2;
595 dt = dt / _elm_config->thumbscroll_bounce_friction;
596 dx = sd->down.b2x - sd->down.bx;
597 sd->pan_func.get(sd->pan_obj, &px, NULL);
598 sd->pan_func.child_size_get(sd->pan_obj, &cw, NULL);
599 evas_object_geometry_get(sd->edje_obj, &x, NULL, &w, NULL);
600 if(!sd->down.momentum_animator && ((cw - px) > 0) && ((-px) < (w - x)))
602 pd = (double)dx / (double)w;
603 pd = (pd > 0) ? pd : -pd;
604 pd = 1.0 - ((1.0 - pd) * (1.0 - pd));
605 dt = dt / (pd * 1.5);
607 if (dt > 1.0) dt = 1.0;
608 p = 1.0 - ((1.0 - dt) * (1.0 - dt));
609 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
611 x = sd->down.bx + dx;
612 if (!sd->down.cancelled)
613 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
616 if (sd->down.momentum_animator)
617 sd->down.bounce_x_hold = 1;
618 else if ((!sd->down.bounce_y_animator) &&
619 (!sd->scrollto.y.animator))
620 _smart_anim_stop(sd->smart_obj);
621 sd->down.bounce_x_animator = NULL;
624 _smart_momentum_end(sd);
625 return ECORE_CALLBACK_CANCEL;
628 return ECORE_CALLBACK_RENEW;
632 _smart_bounce_y_animator(void *data)
635 Evas_Coord x, y, dy, py, ch, h;
639 t = ecore_loop_time_get();
640 dt = t - sd->down.anim_start3;
643 dt = dt / _elm_config->thumbscroll_bounce_friction;
644 dy = sd->down.b2y - sd->down.by;
645 sd->pan_func.get(sd->pan_obj, NULL, &py);
646 sd->pan_func.child_size_get(sd->pan_obj, NULL, &ch);
647 evas_object_geometry_get(sd->edje_obj, NULL, &y, NULL, &h);
648 if(!sd->down.momentum_animator && ((ch - py) > 0) && ((-py) < (h - y)))
650 pd = (double)dy / (double)(h - y);
651 pd = (pd > 0) ? pd : -pd;
652 pd = 1.0 - ((1.0 - pd) * (1.0 - pd));
653 dt = dt / (pd * 1.5);
655 if (dt > 1.0) dt = 1.0;
656 p = 1.0 - ((1.0 - dt) * (1.0 - dt));
657 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
659 y = sd->down.by + dy;
660 if (!sd->down.cancelled)
661 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
664 if (sd->down.momentum_animator)
665 sd->down.bounce_y_hold = 1;
666 else if ((!sd->down.bounce_x_animator) &&
667 (!sd->scrollto.y.animator))
668 _smart_anim_stop(sd->smart_obj);
669 sd->down.bounce_y_animator = NULL;
672 _smart_momentum_end(sd);
673 return ECORE_CALLBACK_CANCEL;
676 return ECORE_CALLBACK_RENEW;
684 can_scroll(Smart_Data *sd, int dir)
686 Evas_Coord mx = 0, my = 0, px = 0, py = 0, minx = 0, miny = 0;
688 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
689 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
690 sd->pan_func.get(sd->pan_obj, &px, &py);
694 if (px > minx) return EINA_TRUE;
697 if ((px - minx) < mx) return EINA_TRUE;
700 if (py > miny) return EINA_TRUE;
703 if ((py - miny) < my) return EINA_TRUE;
712 _smart_momentum_animator(void *data)
716 Evas_Coord x, y, dx, dy, px, py, maxx, maxy, minx, miny;
717 Eina_Bool no_bounce_x_end = EINA_FALSE, no_bounce_y_end = EINA_FALSE;
720 t = ecore_loop_time_get();
721 dt = t - sd->down.anim_start;
725 if (sd->down.hold_parent)
727 if ((sd->down.dir_x) && !can_scroll(sd, sd->down.hdir))
731 if ((sd->down.dir_y) && !can_scroll(sd, sd->down.vdir))
736 if ((!sd->down.dir_x) && (!sd->down.dir_y))
738 sd->down.cancelled = 1;
741 dt = dt / (_elm_config->thumbscroll_friction + sd->down.extra_time);
742 if (dt > 1.0) dt = 1.0;
743 p = 1.0 - ((1.0 - dt) * (1.0 - dt));
744 dx = (sd->down.dx * (_elm_config->thumbscroll_friction + sd->down.extra_time) * p);
745 dy = (sd->down.dy * (_elm_config->thumbscroll_friction + sd->down.extra_time) * p);
748 x = sd->down.sx - dx;
749 y = sd->down.sy - dy;
750 elm_smart_scroller_child_pos_get(sd->smart_obj, &px, &py);
751 if ((sd->down.bounce_x_animator) ||
752 (sd->down.bounce_x_hold))
754 sd->down.bx = sd->down.bx0 - dx + sd->down.b0x;
757 if ((sd->down.bounce_y_animator) ||
758 (sd->down.bounce_y_hold))
760 sd->down.by = sd->down.by0 - dy + sd->down.b0y;
763 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
764 sd->pan_func.max_get(sd->pan_obj, &maxx, &maxy);
765 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
766 if (!sd->bounce_horiz)
768 if (x <= minx) no_bounce_x_end = EINA_TRUE;
769 if ((x - minx) >= maxx) no_bounce_x_end = EINA_TRUE;
771 if (!sd->bounce_vert)
773 if (y <= miny) no_bounce_y_end = EINA_TRUE;
774 if ((y - miny) >= maxy) no_bounce_y_end = EINA_TRUE;
777 ((sd->down.bounce_x_hold) && (sd->down.bounce_y_hold)) ||
778 (no_bounce_x_end && no_bounce_y_end))
780 _smart_anim_stop(sd->smart_obj);
781 sd->down.momentum_animator = NULL;
782 sd->down.bounce_x_hold = 0;
783 sd->down.bounce_y_hold = 0;
788 return ECORE_CALLBACK_CANCEL;
791 return ECORE_CALLBACK_RENEW;
795 bounce_eval(Smart_Data *sd)
797 Evas_Coord mx, my, px, py, bx, by, b2x, b2y, minx = 0, miny = 0;
799 if (sd->freeze) return;
800 if ((!sd->bouncemex) && (!sd->bouncemey)) return;
801 if (sd->down.now) return; // down bounce while still held down
802 if (sd->down.onhold_animator)
804 ecore_animator_del(sd->down.onhold_animator);
805 sd->down.onhold_animator = NULL;
807 if (sd->down.hold_animator)
809 ecore_animator_del(sd->down.hold_animator);
810 sd->down.hold_animator = NULL;
812 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
813 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
814 sd->pan_func.get(sd->pan_obj, &px, &py);
817 if (px < minx) px = minx;
818 if ((px - minx) > mx) px = mx + minx;
819 if (py < miny) py = miny;
820 if ((py - miny) > my) py = my + miny;
824 (!elm_widget_drag_child_locked_x_get(sd->widget)))
826 if (!sd->down.bounce_x_animator && !sd->bounce_animator_disabled)
830 if (sd->scrollto.x.animator)
832 ecore_animator_del(sd->scrollto.x.animator);
833 sd->scrollto.x.animator = NULL;
835 sd->down.bounce_x_animator = ecore_animator_add(_smart_bounce_x_animator, sd);
836 sd->down.anim_start2 = ecore_loop_time_get();
840 if (sd->down.momentum_animator) sd->down.b0x = sd->down.ax;
841 else sd->down.b0x = 0;
846 (!elm_widget_drag_child_locked_y_get(sd->widget)))
848 if (!sd->down.bounce_y_animator && !sd->bounce_animator_disabled)
852 if (sd->scrollto.y.animator)
854 ecore_animator_del(sd->scrollto.y.animator);
855 sd->scrollto.y.animator = NULL;
857 sd->down.bounce_y_animator = ecore_animator_add(_smart_bounce_y_animator, sd);
858 sd->down.anim_start3 = ecore_loop_time_get();
862 if (sd->down.momentum_animator) sd->down.b0y = sd->down.ay;
863 else sd->down.b0y = 0;
870 elm_smart_scroller_child_pos_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
872 Evas_Coord mx = 0, my = 0, px, py, minx = 0, miny = 0;
876 // FIXME: allow for bounce outside of range
877 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
878 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
879 if (mx > 0) vx = (double)(x - minx) / (double)mx;
881 if (vx < 0.0) vx = 0.0;
882 else if (vx > 1.0) vx = 1.0;
883 if (my > 0) vy = (double)(y - miny) / (double)my;
885 if (vy < 0.0) vy = 0.0;
886 else if (vy > 1.0) vy = 1.0;
887 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.vbar", 0.0, vy);
888 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.hbar", vx, 0.0);
889 sd->pan_func.get(sd->pan_obj, &px, &py);
890 if (!_elm_config->thumbscroll_bounce_enable)
892 if (x < minx) x = minx;
893 if ((x - minx) > mx) x = mx + minx;
894 if (y < miny) y = miny;
895 if ((y - miny) > my) y = my + miny;
898 if (!sd->bounce_horiz)
900 if (x < minx) x = minx;
901 if ((x - minx) > mx) x = mx + minx;
903 if (!sd->bounce_vert)
905 if (y < miny) y = miny;
906 if (y - miny > my) y = my + miny;
909 sd->pan_func.set(sd->pan_obj, x, y);
910 if ((px != x) || (py != y))
911 edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
912 if (!sd->down.bounce_x_animator)
914 if ((x < minx) || (x > (mx + minx)))
920 if (!sd->down.bounce_y_animator)
922 if ((y < miny) || (y > my + miny))
928 if ((x != px) || (y != py))
930 evas_object_smart_callback_call(obj, "scroll", NULL);
932 if ((x != px)/* && (!sd->bouncemex)*/)
935 evas_object_smart_callback_call(obj, "edge,left", NULL);
936 if (x == (mx + minx))
937 evas_object_smart_callback_call(obj, "edge,right", NULL);
939 if ((y != py)/* && (!sd->bouncemey)*/)
942 evas_object_smart_callback_call(obj, "edge,top", NULL);
944 evas_object_smart_callback_call(obj, "edge,bottom", NULL);
949 elm_smart_scroller_child_pos_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
952 sd->pan_func.get(sd->pan_obj, x, y);
955 /* "internal_call" actually toggles whether we should save the coords and do
956 * extra "speedup" checks, or not. */
958 _elm_smart_scroller_child_region_show_internal(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h, Eina_Bool internal_call)
960 Evas_Coord mx = 0, my = 0, cw = 0, ch = 0, px = 0, py = 0, nx, ny, minx = 0, miny = 0;
963 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
964 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
965 sd->pan_func.child_size_get(sd->pan_obj, &cw, &ch);
966 sd->pan_func.get(sd->pan_obj, &px, &py);
969 if ((x < px) && ((x + w) < (px + (cw - mx)))) nx = x;
970 else if ((x > px) && ((x + w) > (px + (cw - mx)))) nx = x + w - (cw - mx);
972 if ((y < py) && ((y + h) < (py + (ch - my)))) ny = y;
973 else if ((y > py) && ((y + h) > (py + (ch - my)))) ny = y + h - (ch - my);
974 // if ((nx == px) && (ny == py)) return;
981 if ((nx == px) && (ny == py)) return;
983 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
984 (sd->scrollto.x.animator) || (sd->scrollto.y.animator))
986 _smart_anim_stop(sd->smart_obj);
988 if (sd->scrollto.x.animator)
990 ecore_animator_del(sd->scrollto.x.animator);
991 sd->scrollto.x.animator = NULL;
993 if (sd->scrollto.y.animator)
995 ecore_animator_del(sd->scrollto.y.animator);
996 sd->scrollto.y.animator = NULL;
998 if (sd->down.bounce_x_animator)
1000 ecore_animator_del(sd->down.bounce_x_animator);
1001 sd->down.bounce_x_animator = NULL;
1004 if (sd->down.bounce_y_animator)
1006 ecore_animator_del(sd->down.bounce_y_animator);
1007 sd->down.bounce_y_animator = NULL;
1010 if (sd->down.hold_animator)
1012 ecore_animator_del(sd->down.hold_animator);
1013 sd->down.hold_animator = NULL;
1014 _smart_drag_stop(sd->smart_obj);
1016 if (sd->down.momentum_animator)
1018 ecore_animator_del(sd->down.momentum_animator);
1019 sd->down.momentum_animator = NULL;
1020 sd->down.bounce_x_hold = 0;
1021 sd->down.bounce_y_hold = 0;
1027 elm_smart_scroller_child_pos_set(sd->smart_obj, nx, ny);
1030 /* Set should be used for calculated positions, for example, when we move
1031 * because of an animation or because this is the correct position after
1034 elm_smart_scroller_child_region_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
1036 _elm_smart_scroller_child_region_show_internal(obj, x, y, w, h, EINA_TRUE);
1039 /* Set should be used for setting the wanted position, for example a user scroll
1040 * or moving the cursor in an entry. */
1042 elm_smart_scroller_child_region_show(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
1044 _elm_smart_scroller_child_region_show_internal(obj, x, y, w, h, EINA_FALSE);
1048 elm_smart_scroller_child_viewport_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
1051 edje_object_calc_force(sd->edje_obj);
1052 evas_object_geometry_get(sd->pan_obj, NULL, NULL, w, h);
1056 elm_smart_scroller_step_size_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
1063 _smart_scrollbar_size_adjust(sd);
1067 elm_smart_scroller_step_size_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
1070 if (x) *x = sd->step.x;
1071 if (y) *y = sd->step.y;
1075 elm_smart_scroller_page_size_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
1080 _smart_scrollbar_size_adjust(sd);
1084 elm_smart_scroller_page_size_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
1087 if (x) *x = sd->page.x;
1088 if (y) *y = sd->page.y;
1092 elm_smart_scroller_policy_set(Evas_Object *obj, Elm_Smart_Scroller_Policy hbar, Elm_Smart_Scroller_Policy vbar)
1095 if ((sd->hbar_flags == hbar) && (sd->vbar_flags == vbar)) return;
1096 sd->hbar_flags = hbar;
1097 sd->vbar_flags = vbar;
1098 if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
1099 edje_object_signal_emit(sd->edje_obj, "elm,action,show_always,hbar", "elm");
1100 else if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
1101 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,hbar", "elm");
1103 edje_object_signal_emit(sd->edje_obj, "elm,action,show_notalways,hbar", "elm");
1104 if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
1105 edje_object_signal_emit(sd->edje_obj, "elm,action,show_always,vbar", "elm");
1106 else if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
1107 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,vbar", "elm");
1109 edje_object_signal_emit(sd->edje_obj, "elm,action,show_notalways,vbar", "elm");
1110 _smart_scrollbar_size_adjust(sd);
1114 elm_smart_scroller_policy_get(Evas_Object *obj, Elm_Smart_Scroller_Policy *hbar, Elm_Smart_Scroller_Policy *vbar)
1117 if (hbar) *hbar = sd->hbar_flags;
1118 if (vbar) *vbar = sd->vbar_flags;
1122 elm_smart_scroller_edje_object_get(Evas_Object *obj)
1124 API_ENTRY return NULL;
1125 return sd->edje_obj;
1129 elm_smart_scroller_single_dir_set(Evas_Object *obj, Eina_Bool single_dir)
1132 sd->one_dir_at_a_time = single_dir;
1136 elm_smart_scroller_single_dir_get(Evas_Object *obj)
1138 API_ENTRY return EINA_FALSE;
1139 return sd->one_dir_at_a_time;
1143 elm_smart_scroller_propagate_events_set(Evas_Object *obj, Eina_Bool propagation)
1146 sd->event_propagation = propagation;
1148 evas_object_propagate_events_set(sd->edje_obj, propagation);
1152 elm_smart_scroller_propagate_events_get(Evas_Object *obj)
1154 API_ENTRY return EINA_FALSE;
1155 return sd->event_propagation;
1159 elm_smart_scroller_object_theme_set(Evas_Object *parent, Evas_Object *obj, const char *clas, const char *group, const char *style)
1163 _elm_theme_object_set(parent, sd->edje_obj, clas, group, style);
1164 edje_object_scale_set(sd->edje_obj, elm_widget_scale_get(parent) * _elm_config->scale);
1166 edje_object_part_swallow(sd->edje_obj, "elm.swallow.content", sd->pan_obj);
1168 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1169 if (edje_object_part_exists(sd->edje_obj, "elm.scrollbar.base"))
1172 base = edje_object_part_swallow_get(sd->edje_obj, "elm.scrollbar.base");
1175 base = evas_object_rectangle_add(evas_object_evas_get(sd->edje_obj));
1176 evas_object_color_set(base, 0, 0, 0, 0);
1177 edje_object_part_swallow(sd->edje_obj, "elm.scrollbar.base", base);
1179 if (!_elm_config->thumbscroll_enable)
1180 evas_object_size_hint_min_set(base, mw, mh);
1182 sd->vbar_visible = !sd->vbar_visible;
1183 sd->hbar_visible = !sd->hbar_visible;
1184 _smart_scrollbar_bar_visibility_adjust(sd);
1188 elm_smart_scroller_hold_set(Evas_Object *obj, Eina_Bool hold)
1195 elm_smart_scroller_freeze_set(Evas_Object *obj, Eina_Bool freeze)
1198 sd->freeze = freeze;
1201 if (sd->down.onhold_animator)
1203 ecore_animator_del(sd->down.onhold_animator);
1204 sd->down.onhold_animator = NULL;
1210 elm_smart_scroller_bounce_allow_set(Evas_Object *obj, Eina_Bool horiz, Eina_Bool vert)
1213 sd->bounce_horiz = horiz;
1214 sd->bounce_vert = vert;
1218 elm_smart_scroller_bounce_allow_get(const Evas_Object *obj, Eina_Bool *horiz, Eina_Bool *vert)
1221 *horiz = sd->bounce_horiz;
1222 *vert = sd->bounce_vert;
1226 elm_smart_scroller_paging_set(Evas_Object *obj, double pagerel_h, double pagerel_v, Evas_Coord pagesize_h, Evas_Coord pagesize_v)
1229 sd->pagerel_h = pagerel_h;
1230 sd->pagerel_v = pagerel_v;
1231 sd->pagesize_h = pagesize_h;
1232 sd->pagesize_v = pagesize_v;
1233 if (sd->child_obj) _smart_page_adjust(sd);
1237 elm_smart_scroller_paging_get(Evas_Object *obj, double *pagerel_h, double *pagerel_v, Evas_Coord *pagesize_h, Evas_Coord *pagesize_v)
1240 if(pagerel_h) *pagerel_h = sd->pagerel_h;
1241 if(pagerel_v) *pagerel_v = sd->pagerel_v;
1242 if(pagesize_h) *pagesize_h = sd->pagesize_h;
1243 if(pagesize_v) *pagesize_v = sd->pagesize_v;
1247 elm_smart_scroller_region_bring_in(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
1249 Evas_Coord mx = 0, my = 0, cw = 0, ch = 0, px = 0, py = 0, nx, ny, minx = 0, miny = 0;
1252 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
1253 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
1254 sd->pan_func.child_size_get(sd->pan_obj, &cw, &ch);
1255 sd->pan_func.get(sd->pan_obj, &px, &py);
1258 if ((x < px) && ((x + w) < (px + (cw - mx)))) nx = x;
1259 else if ((x > px) && ((x + w) > (px + (cw - mx)))) nx = x + w - (cw - mx);
1261 if ((y < py) && ((y + h) < (py + (ch - my)))) ny = y;
1262 else if ((y > py) && ((y + h) > (py + (ch - my)))) ny = y + h - (ch - my);
1263 // if ((nx == px) && (ny == py)) return;
1264 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1265 (sd->scrollto.x.animator) || (sd->scrollto.y.animator))
1267 _smart_anim_stop(sd->smart_obj);
1269 if (sd->scrollto.x.animator)
1271 ecore_animator_del(sd->scrollto.x.animator);
1272 sd->scrollto.x.animator = NULL;
1274 if (sd->scrollto.y.animator)
1276 ecore_animator_del(sd->scrollto.y.animator);
1277 sd->scrollto.y.animator = NULL;
1279 if (sd->down.bounce_x_animator)
1281 ecore_animator_del(sd->down.bounce_x_animator);
1282 sd->down.bounce_x_animator = NULL;
1285 if (sd->down.bounce_y_animator)
1287 ecore_animator_del(sd->down.bounce_y_animator);
1288 sd->down.bounce_y_animator = NULL;
1291 if (sd->down.hold_animator)
1293 ecore_animator_del(sd->down.hold_animator);
1294 sd->down.hold_animator = NULL;
1295 _smart_drag_stop(sd->smart_obj);
1297 if (sd->down.momentum_animator)
1299 ecore_animator_del(sd->down.momentum_animator);
1300 sd->down.momentum_animator = NULL;
1301 sd->down.bounce_x_hold = 0;
1302 sd->down.bounce_y_hold = 0;
1309 if (x < minx) x = minx;
1310 else if ((x + w) > cw) x = cw - w;
1312 if (y < miny) y = miny;
1313 else if ((y + h) > ch) y = ch - h;
1314 _smart_scrollto_x(sd, _elm_config->bring_in_scroll_friction, nx);
1315 _smart_scrollto_y(sd, _elm_config->bring_in_scroll_friction, ny);
1319 elm_smart_scroller_widget_set(Evas_Object *obj, Evas_Object *wid)
1325 /* local subsystem functions */
1327 _smart_edje_drag_v_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1332 _smart_scrollbar_read(sd);
1333 _smart_drag_start(sd->smart_obj);
1337 _smart_edje_drag_v_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1342 _smart_scrollbar_read(sd);
1343 _smart_drag_stop(sd->smart_obj);
1347 _smart_edje_drag_v(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1352 _smart_scrollbar_read(sd);
1356 _smart_edje_drag_h_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1361 _smart_scrollbar_read(sd);
1362 _smart_drag_start(sd->smart_obj);
1366 _smart_edje_drag_h_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1371 _smart_scrollbar_read(sd);
1372 _smart_drag_stop(sd->smart_obj);
1376 _smart_edje_drag_h(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1381 _smart_scrollbar_read(sd);
1385 _smart_child_del_hook(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1390 sd->child_obj = NULL;
1391 _smart_scrollbar_size_adjust(sd);
1392 _smart_scrollbar_reset(sd);
1396 _smart_pan_changed_hook(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1403 sd->pan_func.get(sd->pan_obj, &x, &y);
1404 sd->pan_func.child_size_get(sd->pan_obj, &w, &h);
1405 if ((w != sd->child.w) || (h != sd->child.h))
1409 _smart_scrollbar_size_adjust(sd);
1410 evas_object_size_hint_min_set(sd->smart_obj, sd->child.w, sd->child.h);
1411 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
1416 _smart_pan_pan_changed_hook(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1422 sd->pan_func.get(sd->pan_obj, &x, &y);
1423 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1424 (sd->scrollto.x.animator) || (sd->scrollto.y.animator))
1426 _smart_anim_stop(sd->smart_obj);
1428 if (sd->scrollto.x.animator)
1430 ecore_animator_del(sd->scrollto.x.animator);
1431 sd->scrollto.x.animator = NULL;
1433 if (sd->scrollto.y.animator)
1435 ecore_animator_del(sd->scrollto.y.animator);
1436 sd->scrollto.y.animator = NULL;
1438 if (sd->down.bounce_x_animator)
1440 ecore_animator_del(sd->down.bounce_x_animator);
1441 sd->down.bounce_x_animator = NULL;
1444 if (sd->down.bounce_y_animator)
1446 ecore_animator_del(sd->down.bounce_y_animator);
1447 sd->down.bounce_y_animator = NULL;
1450 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
1454 _smart_event_wheel(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1456 Evas_Event_Mouse_Wheel *ev;
1458 Evas_Coord x = 0, y = 0;
1462 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
1463 if ((evas_key_modifier_is_set(ev->modifiers, "Control")) ||
1464 (evas_key_modifier_is_set(ev->modifiers, "Alt")) ||
1465 (evas_key_modifier_is_set(ev->modifiers, "Shift")) ||
1466 (evas_key_modifier_is_set(ev->modifiers, "Meta")) ||
1467 (evas_key_modifier_is_set(ev->modifiers, "Hyper")) ||
1468 (evas_key_modifier_is_set(ev->modifiers, "Super")))
1470 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1471 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1472 (sd->scrollto.x.animator) || (sd->scrollto.y.animator))
1474 _smart_anim_stop(sd->smart_obj);
1476 if (sd->scrollto.x.animator)
1478 ecore_animator_del(sd->scrollto.x.animator);
1479 sd->scrollto.x.animator = NULL;
1481 if (sd->scrollto.y.animator)
1483 ecore_animator_del(sd->scrollto.y.animator);
1484 sd->scrollto.y.animator = NULL;
1486 if (sd->down.bounce_x_animator)
1488 ecore_animator_del(sd->down.bounce_x_animator);
1489 sd->down.bounce_x_animator = NULL;
1492 if (sd->down.bounce_y_animator)
1494 ecore_animator_del(sd->down.bounce_y_animator);
1495 sd->down.bounce_y_animator = NULL;
1499 y += ev->z * sd->step.y;
1500 else if (ev->direction == 1)
1501 x += ev->z * sd->step.x;
1503 if ((!sd->hold) && (!sd->freeze))
1507 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
1512 _smart_event_mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1514 Evas_Event_Mouse_Down *ev;
1516 Evas_Coord x = 0, y = 0;
1520 // if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
1521 if (_elm_config->thumbscroll_enable)
1524 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1525 (sd->down.momentum_animator) || (sd->scrollto.x.animator) ||
1526 (sd->scrollto.y.animator))
1528 ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL | EVAS_EVENT_FLAG_ON_HOLD;
1529 sd->down.scroll = 1;
1531 _smart_anim_stop(sd->smart_obj);
1533 if (sd->scrollto.x.animator)
1535 ecore_animator_del(sd->scrollto.x.animator);
1536 sd->scrollto.x.animator = NULL;
1538 if (sd->scrollto.y.animator)
1540 ecore_animator_del(sd->scrollto.y.animator);
1541 sd->scrollto.y.animator = NULL;
1543 if (sd->down.bounce_x_animator)
1545 ecore_animator_del(sd->down.bounce_x_animator);
1546 sd->down.bounce_x_animator = NULL;
1549 if (sd->down.bounce_y_animator)
1551 ecore_animator_del(sd->down.bounce_y_animator);
1552 sd->down.bounce_y_animator = NULL;
1555 if (sd->down.hold_animator)
1557 ecore_animator_del(sd->down.hold_animator);
1558 sd->down.hold_animator = NULL;
1559 _smart_drag_stop(sd->smart_obj);
1561 if (sd->down.momentum_animator)
1563 ecore_animator_del(sd->down.momentum_animator);
1564 sd->down.momentum_animator = NULL;
1565 sd->down.bounce_x_hold = 0;
1566 sd->down.bounce_y_hold = 0;
1570 if (ev->button == 1)
1573 sd->down.dragged = 0;
1576 sd->down.x = ev->canvas.x;
1577 sd->down.y = ev->canvas.y;
1578 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1581 sd->down.locked = 0;
1582 memset(&(sd->down.history[0]), 0, sizeof(sd->down.history[0]) * 20);
1584 sd->down.history[0].timestamp = ev->timestamp / 1000.0;
1586 sd->down.history[0].timestamp = ecore_loop_time_get();
1588 sd->down.history[0].x = ev->canvas.x;
1589 sd->down.history[0].y = ev->canvas.y;
1591 sd->down.dragged_began = 0;
1592 sd->down.hold_parent = 0;
1593 sd->down.cancelled = 0;
1594 if(sd->hold || sd->freeze)
1595 sd->down.want_reset = 1;
1597 sd->down.want_reset = 0;
1602 _smart_hold_animator(void *data)
1604 Smart_Data *sd = data;
1607 elm_smart_scroller_child_pos_get(sd->smart_obj, &ox, &oy);
1610 if ((!sd->widget) ||
1611 (!elm_widget_drag_child_locked_x_get(sd->widget)))
1613 ox = sd->down.hold_x;
1618 if ((!sd->widget) ||
1619 (!elm_widget_drag_child_locked_y_get(sd->widget)))
1621 oy = sd->down.hold_y;
1624 elm_smart_scroller_child_pos_set(sd->smart_obj, ox, oy);
1627 return ECORE_CALLBACK_RENEW;
1631 _smart_event_post_up(void *data, Evas *e __UNUSED__)
1633 Smart_Data *sd = data;
1636 if (sd->down.dragged)
1638 elm_widget_drag_lock_x_set(sd->widget, 0);
1639 elm_widget_drag_lock_y_set(sd->widget, 0);
1646 _smart_event_mouse_up(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *event_info)
1648 Evas_Event_Mouse_Down *ev;
1650 Evas_Coord x = 0, y = 0, ox = 0, oy = 0;
1654 sd->down.hold_parent = 0;
1655 // if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
1656 evas_post_event_callback_push(e, _smart_event_post_up, sd);
1657 // FIXME: respect elm_widget_scroll_hold_get of parent container
1658 if (_elm_config->thumbscroll_enable)
1660 if (ev->button == 1)
1662 if (sd->down.onhold_animator)
1664 ecore_animator_del(sd->down.onhold_animator);
1665 sd->down.onhold_animator = NULL;
1667 x = ev->canvas.x - sd->down.x;
1668 y = ev->canvas.y - sd->down.y;
1669 if (sd->down.dragged)
1671 _smart_drag_stop(sd->smart_obj);
1672 if ((!sd->hold) && (!sd->freeze))
1676 Evas_Coord ax, ay, dx, dy, vel;
1679 t = ev->timestamp / 1000.0;
1681 t = ecore_loop_time_get();
1683 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1688 printf("------ %i %i\n", ev->canvas.x, ev->canvas.y);
1690 for (i = 0; i < 20; i++)
1692 dt = t - sd->down.history[i].timestamp;
1693 if (dt > 0.2) break;
1695 printf("H: %i %i @ %1.3f\n",
1696 sd->down.history[i].x,
1697 sd->down.history[i].y, dt);
1700 ax += sd->down.history[i].x;
1701 ay += sd->down.history[i].y;
1707 dx = ev->canvas.x - ax;
1708 dy = ev->canvas.y - ay;
1711 vel = sqrt((dx * dx) + (dy * dy)) / at;
1712 if ((_elm_config->thumbscroll_friction > 0.0) &&
1713 (vel > _elm_config->thumbscroll_momentum_threshold) &&
1716 sd->down.dx = ((double)dx / at);
1717 sd->down.dy = ((double)dy / at);
1718 if (((sd->down.dx > 0) && (sd->down.pdx > 0)) ||
1719 ((sd->down.dx < 0) && (sd->down.pdx < 0)))
1720 sd->down.dx += (double)sd->down.pdx * 1.5; // FIXME: * 1.5 - probably should be config
1721 if (((sd->down.dy > 0) && (sd->down.pdy > 0)) ||
1722 ((sd->down.dy < 0) && (sd->down.pdy < 0)))
1723 sd->down.dy += (double)sd->down.pdy * 1.5; // FIXME: * 1.5 - probably should be config
1724 if (((sd->down.dx > 0) && (sd->down.pdx > 0)) ||
1725 ((sd->down.dx < 0) && (sd->down.pdx < 0)) ||
1726 ((sd->down.dy > 0) && (sd->down.pdy > 0)) ||
1727 ((sd->down.dy < 0) && (sd->down.pdy < 0)))
1729 double t = ecore_loop_time_get();
1730 double dt = t - sd->down.anim_start;
1732 if (dt < 0.0) dt = 0.0;
1733 else if (dt > _elm_config->thumbscroll_friction)
1734 dt = _elm_config->thumbscroll_friction;
1735 sd->down.extra_time = _elm_config->thumbscroll_friction - dt;
1738 sd->down.extra_time = 0.0;
1739 sd->down.pdx = sd->down.dx;
1740 sd->down.pdy = sd->down.dy;
1743 if (!_smart_do_page(sd))
1745 if (!sd->down.momentum_animator && !sd->momentum_animator_disabled)
1747 sd->down.momentum_animator = ecore_animator_add(_smart_momentum_animator, sd);
1748 ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL;
1749 _smart_anim_start(sd->smart_obj);
1751 sd->down.anim_start = ecore_loop_time_get();
1752 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1760 if (sd->down.hold_animator)
1762 ecore_animator_del(sd->down.hold_animator);
1763 sd->down.hold_animator = NULL;
1771 evas_event_feed_hold(e, 0, ev->timestamp, ev->data);
1772 if (_smart_do_page(sd))
1774 Evas_Coord pgx, pgy;
1776 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1777 if ((!sd->widget) ||
1778 (!elm_widget_drag_child_locked_x_get(sd->widget)))
1780 pgx = _smart_page_x_get(sd, ox);
1783 ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL;
1784 _smart_scrollto_x(sd, _elm_config->page_scroll_friction, pgx);
1787 if ((!sd->widget) ||
1788 (!elm_widget_drag_child_locked_y_get(sd->widget)))
1790 pgy = _smart_page_y_get(sd, oy);
1793 ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL;
1794 _smart_scrollto_y(sd, _elm_config->page_scroll_friction, pgy);
1803 if (_smart_do_page(sd))
1805 Evas_Coord pgx, pgy;
1807 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1808 if ((!sd->widget) ||
1809 (!elm_widget_drag_child_locked_x_get(sd->widget)))
1811 pgx = _smart_page_x_get(sd, ox);
1812 if (pgx != x) _smart_scrollto_x(sd, _elm_config->page_scroll_friction, pgx);
1814 if ((!sd->widget) ||
1815 (!elm_widget_drag_child_locked_y_get(sd->widget)))
1817 pgy = _smart_page_y_get(sd, oy);
1818 if (pgy != y) _smart_scrollto_y(sd, _elm_config->page_scroll_friction, pgy);
1821 if (sd->down.hold_animator)
1823 ecore_animator_del(sd->down.hold_animator);
1824 sd->down.hold_animator = NULL;
1827 if (sd->down.scroll)
1829 ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL;
1830 sd->down.scroll = 0;
1834 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1837 sd->down.dragged_began = 0;
1840 sd->down.want_dragged = 0;
1841 sd->down.dragged = 0;
1843 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1844 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
1847 if (!_smart_do_page(sd))
1854 _smart_onhold_animator(void *data)
1859 Evas_Coord x, y, ox, oy;
1862 t = ecore_loop_time_get();
1863 if (sd->down.onhold_tlast > 0.0)
1865 td = t - sd->down.onhold_tlast;
1866 vx = sd->down.onhold_vx * td * (double)_elm_config->thumbscroll_threshold * 2.0;
1867 vy = sd->down.onhold_vy * td * (double)_elm_config->thumbscroll_threshold * 2.0;
1868 elm_smart_scroller_child_pos_get(sd->smart_obj, &ox, &oy);
1874 if ((!sd->widget) ||
1875 (!elm_widget_drag_child_locked_x_get(sd->widget)))
1877 sd->down.onhold_vxe += vx;
1878 x = ox + (int)sd->down.onhold_vxe;
1879 sd->down.onhold_vxe -= (int)sd->down.onhold_vxe;
1885 if ((!sd->widget) ||
1886 (!elm_widget_drag_child_locked_y_get(sd->widget)))
1888 sd->down.onhold_vye += vy;
1889 y = oy + (int)sd->down.onhold_vye;
1890 sd->down.onhold_vye -= (int)sd->down.onhold_vye;
1894 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
1897 // printf("scroll %i %i\n", sd->down.hold_x, sd->down.hold_y);
1899 sd->down.onhold_tlast = t;
1900 return ECORE_CALLBACK_RENEW;
1904 _smart_event_post_move(void *data, Evas *e __UNUSED__)
1906 Smart_Data *sd = data;
1908 if (sd->down.want_dragged)
1912 if (sd->down.hold_parent)
1914 if ((sd->down.dir_x) && !can_scroll(sd, sd->down.hdir))
1918 if ((sd->down.dir_y) && !can_scroll(sd, sd->down.vdir))
1925 if ((!sd->widget) ||
1926 (!elm_widget_drag_child_locked_x_get(sd->widget)))
1928 sd->down.want_dragged = 0;
1929 sd->down.dragged = 1;
1932 elm_widget_drag_lock_x_set(sd->widget, 1);
1941 if ((!sd->widget) ||
1942 (!elm_widget_drag_child_locked_y_get(sd->widget)))
1944 sd->down.want_dragged = 0;
1945 sd->down.dragged = 1;
1948 elm_widget_drag_lock_y_set(sd->widget, 1);
1955 if ((!sd->down.dir_x) && (!sd->down.dir_y))
1957 sd->down.cancelled = 1;
1959 if (start) _smart_drag_start(sd->smart_obj);
1965 _smart_event_mouse_move(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *event_info)
1967 Evas_Event_Mouse_Move *ev;
1969 Evas_Coord x = 0, y = 0;
1973 // if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
1974 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) sd->down.hold_parent = 1;
1975 evas_post_event_callback_push(e, _smart_event_post_move, sd);
1976 // FIXME: respect elm_widget_scroll_hold_get of parent container
1977 if (_elm_config->thumbscroll_enable)
1984 printf("::: %i %i\n", ev->cur.canvas.x, ev->cur.canvas.y);
1986 sd->wx = ev->cur.canvas.x;
1987 sd->wy = ev->cur.canvas.y;
1988 memmove(&(sd->down.history[1]), &(sd->down.history[0]),
1989 sizeof(sd->down.history[0]) * 19);
1991 sd->down.history[0].timestamp = ev->timestamp / 1000.0;
1993 sd->down.history[0].timestamp = ecore_loop_time_get();
1995 sd->down.history[0].x = ev->cur.canvas.x;
1996 sd->down.history[0].y = ev->cur.canvas.y;
1998 if (!sd->down.dragged_began)
2000 x = ev->cur.canvas.x - sd->down.x;
2001 y = ev->cur.canvas.y - sd->down.y;
2006 if (x > 0) sd->down.hdir = LEFT;
2007 else if (x < 0) sd->down.hdir = RIGHT;
2008 if (y > 0) sd->down.vdir = UP;
2009 else if (y < 0) sd->down.vdir = DOWN;
2014 if ((sd->one_dir_at_a_time) &&
2015 (!((sd->down.dir_x) || (sd->down.dir_y))))
2017 if (x > _elm_config->thumbscroll_threshold)
2026 if (y > _elm_config->thumbscroll_threshold)
2043 // can_scroll(sd, LEFT);
2044 // can_scroll(sd, RIGHT);
2045 // can_scroll(sd, UP);
2046 // can_scroll(sd, DOWN);
2051 if ((!sd->hold) && (!sd->freeze))
2053 if ((sd->down.dragged) ||
2054 (((x * x) + (y * y)) >
2055 (_elm_config->thumbscroll_threshold *
2056 _elm_config->thumbscroll_threshold)))
2058 sd->down.dragged_began = 1;
2059 if (!sd->down.dragged)
2061 sd->down.want_dragged = 1;
2062 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2063 // evas_event_feed_hold(e, 1, ev->timestamp, ev->data);
2064 // _smart_drag_start(sd->smart_obj);
2066 if (sd->down.dragged)
2068 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2070 // ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2071 // sd->down.dragged = 1;
2073 x = sd->down.sx - (ev->cur.canvas.x - sd->down.x);
2077 y = sd->down.sy - (ev->cur.canvas.y - sd->down.y);
2080 if(sd->down.want_reset)
2082 sd->down.x = ev->cur.canvas.x;
2083 sd->down.y = ev->cur.canvas.y;
2084 sd->down.want_reset = 0;
2086 if ((sd->down.dir_x) || (sd->down.dir_y))
2088 if (!sd->down.locked)
2090 sd->down.locked_x = x;
2091 sd->down.locked_y = y;
2092 sd->down.locked = 1;
2094 if (!((sd->down.dir_x) && (sd->down.dir_y)))
2096 if (sd->down.dir_x) y = sd->down.locked_y;
2097 else x = sd->down.locked_x;
2100 if (_elm_config->thumbscroll_border_friction > 0.0)
2102 Evas_Coord minx, miny;
2103 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2106 _elm_config->thumbscroll_border_friction;
2107 else if (sd->child.h <= sd->h)
2108 y += (sd->down.sy - y) *
2109 _elm_config->thumbscroll_border_friction;
2110 else if ((sd->child.h - sd->h + miny) < y)
2111 y += (sd->child.h - sd->h + miny - y) *
2112 _elm_config->thumbscroll_border_friction;
2115 _elm_config->thumbscroll_border_friction;
2116 else if (sd->child.w <= sd->w)
2117 x += (sd->down.sx - x) *
2118 _elm_config->thumbscroll_border_friction;
2119 else if ((sd->child.w - sd->w + minx) < x)
2120 x += (sd->child.w - sd->w + minx - x) *
2121 _elm_config->thumbscroll_border_friction;
2124 sd->down.hold_x = x;
2125 sd->down.hold_y = y;
2126 if (!sd->down.hold_animator)
2127 sd->down.hold_animator =
2128 ecore_animator_add(_smart_hold_animator, sd);
2129 // printf("a %i %i\n", sd->down.hold_x, sd->down.hold_y);
2130 // _smart_onhold_animator(sd);
2131 // elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
2135 if (sd->down.dragged_began)
2137 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2141 evas_event_feed_hold(e, 1, ev->timestamp, ev->data);
2146 else if (!sd->freeze)
2148 Evas_Coord ex, ey, ew, eh;
2149 double vx = 0.0, vy = 0.0;
2151 evas_object_geometry_get(sd->event_obj, &ex, &ey, &ew, &eh);
2152 x = ev->cur.canvas.x - ex;
2153 y = ev->cur.canvas.y - ey;
2154 if (x < _elm_config->thumbscroll_threshold)
2156 if (_elm_config->thumbscroll_threshold > 0.0)
2157 vx = -(double)(_elm_config->thumbscroll_threshold - x) /
2158 _elm_config->thumbscroll_threshold;
2162 else if (x > (ew - _elm_config->thumbscroll_threshold))
2164 if (_elm_config->thumbscroll_threshold > 0.0)
2165 vx = (double)(_elm_config->thumbscroll_threshold - (ew - x)) /
2166 _elm_config->thumbscroll_threshold;
2170 if (y < _elm_config->thumbscroll_threshold)
2172 if (_elm_config->thumbscroll_threshold > 0.0)
2173 vy = -(double)(_elm_config->thumbscroll_threshold - y) /
2174 _elm_config->thumbscroll_threshold;
2178 else if (y > (eh - _elm_config->thumbscroll_threshold))
2180 if (_elm_config->thumbscroll_threshold > 0.0)
2181 vy = (double)(_elm_config->thumbscroll_threshold - (eh - y)) /
2182 _elm_config->thumbscroll_threshold;
2186 if ((vx != 0.0) || (vy != 0.0))
2188 sd->down.onhold_vx = vx;
2189 sd->down.onhold_vy = vy;
2190 if (!sd->down.onhold_animator)
2192 sd->down.onhold_vxe = 0.0;
2193 sd->down.onhold_vye = 0.0;
2194 sd->down.onhold_tlast = 0.0;
2195 sd->down.onhold_animator = ecore_animator_add(_smart_onhold_animator, sd);
2197 // printf("b %i %i\n", sd->down.hold_x, sd->down.hold_y);
2201 if (sd->down.onhold_animator)
2203 ecore_animator_del(sd->down.onhold_animator);
2204 sd->down.onhold_animator = NULL;
2213 _smart_scrollbar_read(Smart_Data *sd)
2215 Evas_Coord x, y, mx = 0, my = 0, px, py, minx = 0, miny = 0;
2218 edje_object_part_drag_value_get(sd->edje_obj, "elm.dragable.vbar", NULL, &vy);
2219 edje_object_part_drag_value_get(sd->edje_obj, "elm.dragable.hbar", &vx, NULL);
2220 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
2221 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2222 x = vx * (double)mx + minx;
2223 y = vy * (double)my + miny;
2224 sd->pan_func.get(sd->pan_obj, &px, &py);
2225 sd->pan_func.set(sd->pan_obj, x, y);
2226 if ((px != x) || (py != y))
2227 edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
2231 _smart_scrollbar_reset(Smart_Data *sd)
2233 Evas_Coord px = 0, py = 0, minx = 0, miny = 0;
2235 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.vbar", 0.0, 0.0);
2236 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.hbar", 0.0, 0.0);
2237 if ((!sd->child_obj) && (!sd->extern_pan))
2239 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.vbar", 1.0, 1.0);
2240 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.hbar", 1.0, 1.0);
2242 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2243 sd->pan_func.get(sd->pan_obj, &px, &py);
2244 sd->pan_func.set(sd->pan_obj, minx, miny);
2245 if ((px != minx) || (py != miny))
2246 edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
2250 _smart_scrollbar_bar_v_visibility_adjust(Smart_Data *sd)
2252 int scroll_v_vis_change = 0;
2253 Evas_Coord h, vw, vh;
2256 evas_object_geometry_get(sd->pan_obj, NULL, NULL, &vw, &vh);
2257 if (sd->vbar_visible)
2259 if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_AUTO)
2261 if ((sd->child_obj) || (sd->extern_pan))
2265 scroll_v_vis_change = 1;
2266 sd->vbar_visible = 0;
2271 scroll_v_vis_change = 1;
2272 sd->vbar_visible = 0;
2275 else if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
2277 scroll_v_vis_change = 1;
2278 sd->vbar_visible = 0;
2283 if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_AUTO)
2285 if ((sd->child_obj) || (sd->extern_pan))
2289 scroll_v_vis_change = 1;
2290 sd->vbar_visible = 1;
2294 else if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
2296 scroll_v_vis_change = 1;
2297 sd->vbar_visible = 1;
2300 if (scroll_v_vis_change)
2302 if (sd->vbar_flags != ELM_SMART_SCROLLER_POLICY_OFF)
2304 if (sd->vbar_visible)
2305 edje_object_signal_emit(sd->edje_obj, "elm,action,show,vbar", "elm");
2307 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,vbar", "elm");
2308 edje_object_message_signal_process(sd->edje_obj);
2309 _smart_scrollbar_size_adjust(sd);
2312 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,vbar", "elm");
2314 return scroll_v_vis_change;
2318 _smart_scrollbar_bar_h_visibility_adjust(Smart_Data *sd)
2320 int scroll_h_vis_change = 0;
2321 Evas_Coord w, vw, vh;
2324 evas_object_geometry_get(sd->pan_obj, NULL, NULL, &vw, &vh);
2325 if (sd->hbar_visible)
2327 if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_AUTO)
2329 if ((sd->child_obj) || (sd->extern_pan))
2333 scroll_h_vis_change = 1;
2334 sd->hbar_visible = 0;
2339 scroll_h_vis_change = 1;
2340 sd->hbar_visible = 0;
2343 else if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
2345 scroll_h_vis_change = 1;
2346 sd->hbar_visible = 0;
2351 if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_AUTO)
2353 if ((sd->child_obj) || (sd->extern_pan))
2357 scroll_h_vis_change = 1;
2358 sd->hbar_visible = 1;
2362 else if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
2364 scroll_h_vis_change = 1;
2365 sd->hbar_visible = 1;
2368 if (scroll_h_vis_change)
2370 if (sd->hbar_flags != ELM_SMART_SCROLLER_POLICY_OFF)
2372 if (sd->hbar_visible)
2373 edje_object_signal_emit(sd->edje_obj, "elm,action,show,hbar", "elm");
2375 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,hbar", "elm");
2376 edje_object_message_signal_process(sd->edje_obj);
2377 _smart_scrollbar_size_adjust(sd);
2380 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,hbar", "elm");
2381 _smart_scrollbar_size_adjust(sd);
2383 return scroll_h_vis_change;
2387 _smart_scrollbar_bar_visibility_adjust(Smart_Data *sd)
2391 changed |= _smart_scrollbar_bar_h_visibility_adjust(sd);
2392 changed |= _smart_scrollbar_bar_v_visibility_adjust(sd);
2395 _smart_scrollbar_bar_h_visibility_adjust(sd);
2396 _smart_scrollbar_bar_v_visibility_adjust(sd);
2401 _smart_scrollbar_size_adjust(Smart_Data *sd)
2403 if ((sd->child_obj) || (sd->extern_pan))
2405 Evas_Coord x, y, w, h, mx = 0, my = 0, vw = 0, vh = 0, px, py, minx = 0, miny = 0;
2406 double vx, vy, size;
2408 edje_object_part_geometry_get(sd->edje_obj, "elm.swallow.content",
2409 NULL, NULL, &vw, &vh);
2412 size = (double)vw / (double)w;
2416 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.hbar", 0.0, 0.0);
2418 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.hbar", size, 1.0);
2422 size = (double)vh / (double)h;
2426 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.vbar", 0.0, 0.0);
2428 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.vbar", 1.0, size);
2430 edje_object_part_drag_value_get(sd->edje_obj, "elm.dragable.hbar", &vx, NULL);
2431 edje_object_part_drag_value_get(sd->edje_obj, "elm.dragable.vbar", NULL, &vy);
2432 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
2433 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2437 edje_object_part_drag_step_set(sd->edje_obj, "elm.dragable.hbar", (double)sd->step.x / (double)w, 0.0);
2438 edje_object_part_drag_step_set(sd->edje_obj, "elm.dragable.vbar", 0.0, (double)sd->step.y / (double)h);
2440 edje_object_part_drag_page_set(sd->edje_obj, "elm.dragable.hbar", (double)sd->page.x / (double)w, 0.0);
2442 edje_object_part_drag_page_set(sd->edje_obj, "elm.dragable.hbar", -((double)sd->page.x * ((double)vw / (double)w)) / 100.0, 0.0);
2444 edje_object_part_drag_page_set(sd->edje_obj, "elm.dragable.vbar", 0.0, (double)sd->page.y / (double)h);
2446 edje_object_part_drag_page_set(sd->edje_obj, "elm.dragable.vbar", 0.0, -((double)sd->page.y * ((double)vh / (double)h)) / 100.0);
2448 sd->pan_func.get(sd->pan_obj, &px, &py);
2449 if (vx != mx) x = px;
2450 if (vy != my) y = py;
2451 sd->pan_func.set(sd->pan_obj, x, y);
2452 // if ((px != 0) || (py != 0))
2453 // edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
2457 Evas_Coord px = 0, py = 0, minx = 0, miny = 0;
2459 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.vbar", 1.0, 1.0);
2460 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.hbar", 1.0, 1.0);
2461 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2462 sd->pan_func.get(sd->pan_obj, &px, &py);
2463 sd->pan_func.set(sd->pan_obj, minx, miny);
2464 if ((px != minx) || (py != miny))
2465 edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
2467 _smart_scrollbar_bar_visibility_adjust(sd);
2471 _smart_reconfigure(Smart_Data *sd)
2473 evas_object_move(sd->edje_obj, sd->x, sd->y);
2474 evas_object_resize(sd->edje_obj, sd->w, sd->h);
2475 evas_object_move(sd->event_obj, sd->x, sd->y);
2476 evas_object_resize(sd->event_obj, sd->w, sd->h);
2477 _smart_scrollbar_size_adjust(sd);
2481 _smart_add(Evas_Object *obj)
2486 sd = calloc(1, sizeof(Smart_Data));
2488 evas_object_smart_data_set(obj, sd);
2490 sd->smart_obj = obj;
2499 sd->hbar_flags = ELM_SMART_SCROLLER_POLICY_AUTO;
2500 sd->vbar_flags = ELM_SMART_SCROLLER_POLICY_AUTO;
2501 sd->hbar_visible = 1;
2502 sd->vbar_visible = 1;
2504 sd->bounce_horiz = 1;
2505 sd->bounce_vert = 1;
2507 sd->one_dir_at_a_time = 1;
2508 sd->momentum_animator_disabled = 0;
2509 sd->bounce_animator_disabled = 0;
2511 o = edje_object_add(evas_object_evas_get(obj));
2512 evas_object_propagate_events_set(o, 0);
2514 // FIXME: null parent obj ... :(
2515 elm_smart_scroller_object_theme_set(NULL, obj, "scroller", "base", "default");
2516 edje_object_signal_callback_add(o, "drag", "elm.dragable.vbar", _smart_edje_drag_v, sd);
2517 edje_object_signal_callback_add(o, "drag,start", "elm.dragable.vbar", _smart_edje_drag_v_start, sd);
2518 edje_object_signal_callback_add(o, "drag,stop", "elm.dragable.vbar", _smart_edje_drag_v_stop, sd);
2519 edje_object_signal_callback_add(o, "drag,step", "elm.dragable.vbar", _smart_edje_drag_v, sd);
2520 edje_object_signal_callback_add(o, "drag,page", "elm.dragable.vbar", _smart_edje_drag_v, sd);
2521 edje_object_signal_callback_add(o, "drag", "elm.dragable.hbar", _smart_edje_drag_h, sd);
2522 edje_object_signal_callback_add(o, "drag,start", "elm.dragable.hbar", _smart_edje_drag_h_start, sd);
2523 edje_object_signal_callback_add(o, "drag,stop", "elm.dragable.hbar", _smart_edje_drag_h_stop, sd);
2524 edje_object_signal_callback_add(o, "drag,step", "elm.dragable.hbar", _smart_edje_drag_h, sd);
2525 edje_object_signal_callback_add(o, "drag,page", "elm.dragable.hbar", _smart_edje_drag_h, sd);
2526 evas_object_smart_member_add(o, obj);
2528 o = evas_object_rectangle_add(evas_object_evas_get(obj));
2530 evas_object_color_set(o, 0, 0, 0, 0);
2531 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_WHEEL, _smart_event_wheel, sd);
2532 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, _smart_event_mouse_down, sd);
2533 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_UP, _smart_event_mouse_up, sd);
2534 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_MOVE, _smart_event_mouse_move, sd);
2535 evas_object_smart_member_add(o, obj);
2536 evas_object_repeat_events_set(o, 1);
2538 sd->pan_func.set = _elm_smart_pan_set;
2539 sd->pan_func.get = _elm_smart_pan_get;
2540 sd->pan_func.max_get = _elm_smart_pan_max_get;
2541 sd->pan_func.min_get = _elm_smart_pan_min_get;
2542 sd->pan_func.child_size_get = _elm_smart_pan_child_size_get;
2544 _smart_scrollbar_reset(sd);
2548 _smart_del(Evas_Object *obj)
2551 elm_smart_scroller_child_set(obj, NULL);
2552 if (!sd->extern_pan) evas_object_del(sd->pan_obj);
2553 evas_object_del(sd->edje_obj);
2554 evas_object_del(sd->event_obj);
2555 if (sd->down.hold_animator) ecore_animator_del(sd->down.hold_animator);
2556 if (sd->down.onhold_animator) ecore_animator_del(sd->down.onhold_animator);
2557 if (sd->down.momentum_animator) ecore_animator_del(sd->down.momentum_animator);
2558 if (sd->down.bounce_x_animator) ecore_animator_del(sd->down.bounce_x_animator);
2559 if (sd->down.bounce_y_animator) ecore_animator_del(sd->down.bounce_y_animator);
2560 if (sd->scrollto.x.animator) ecore_animator_del(sd->scrollto.x.animator);
2561 if (sd->scrollto.y.animator) ecore_animator_del(sd->scrollto.y.animator);
2563 evas_object_smart_data_set(obj, NULL);
2567 _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
2572 _smart_reconfigure(sd);
2576 _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
2581 _smart_reconfigure(sd);
2582 elm_smart_scroller_child_region_set(obj, sd->wx, sd->wy, sd->ww, sd->wh);
2586 _smart_show(Evas_Object *obj)
2589 evas_object_show(sd->edje_obj);
2590 evas_object_show(sd->event_obj);
2594 _smart_hide(Evas_Object *obj)
2597 evas_object_hide(sd->edje_obj);
2598 evas_object_hide(sd->event_obj);
2602 _smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
2605 evas_object_color_set(sd->edje_obj, r, g, b, a);
2609 _smart_clip_set(Evas_Object *obj, Evas_Object *clip)
2612 evas_object_clip_set(sd->edje_obj, clip);
2613 evas_object_clip_set(sd->event_obj, clip);
2617 _smart_clip_unset(Evas_Object *obj)
2620 evas_object_clip_unset(sd->edje_obj);
2621 evas_object_clip_unset(sd->event_obj);
2624 /* never need to touch this */
2631 static const Evas_Smart_Class sc =
2634 EVAS_SMART_CLASS_VERSION,
2652 _smart = evas_smart_class_new(&sc);