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;
77 void (*set) (Evas_Object *obj, Evas_Coord x, Evas_Coord y);
78 void (*get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y);
79 void (*max_get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y);
80 void (*min_get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y);
81 void (*child_size_get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y);
86 Evas_Coord start, end;
87 double t_start, t_end;
88 Ecore_Animator *animator;
92 double pagerel_h, pagerel_v;
93 Evas_Coord pagesize_h, pagesize_v;
95 unsigned char hbar_visible : 1;
96 unsigned char vbar_visible : 1;
97 unsigned char extern_pan : 1;
98 unsigned char one_dir_at_a_time : 1;
99 unsigned char hold : 1;
100 unsigned char freeze : 1;
101 unsigned char bouncemex : 1;
102 unsigned char bouncemey : 1;
103 unsigned char bounce_horiz : 1;
104 unsigned char bounce_vert : 1;
105 unsigned char momentum_animator_disabled :1;
106 unsigned char bounce_animator_disabled :1;
107 Eina_Bool is_mirrored : 1;
110 /* local subsystem functions */
111 static void _smart_child_del_hook(void *data, Evas *e, Evas_Object *obj, void *event_info);
112 static void _smart_pan_changed_hook(void *data, Evas_Object *obj, void *event_info);
113 static void _smart_pan_pan_changed_hook(void *data, Evas_Object *obj, void *event_info);
114 static void _smart_event_wheel(void *data, Evas *e, Evas_Object *obj, void *event_info);
115 static void _smart_event_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info);
116 static Eina_Bool _smart_hold_animator(void *data);
117 static Eina_Bool _smart_momentum_animator(void *data);
118 static void _smart_event_mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info);
119 static Eina_Bool _smart_onhold_animator(void *data);
120 static void _smart_event_mouse_move(void *data, Evas *e, Evas_Object *obj, void *event_info);
121 static void _smart_edje_drag_v_start(void *data, Evas_Object *obj, const char *emission, const char *source);
122 static void _smart_edje_drag_v_stop(void *data, Evas_Object *obj, const char *emission, const char *source);
123 static void _smart_edje_drag_v(void *data, Evas_Object *obj, const char *emission, const char *source);
124 static void _smart_edje_drag_h_start(void *data, Evas_Object *obj, const char *emission, const char *source);
125 static void _smart_edje_drag_h_stop(void *data, Evas_Object *obj, const char *emission, const char *source);
126 static void _smart_edje_drag_h(void *data, Evas_Object *obj, const char *emission, const char *source);
127 static void _smart_scrollbar_read(Smart_Data *sd);
128 static void _smart_scrollbar_reset(Smart_Data *sd);
129 static int _smart_scrollbar_bar_h_visibility_adjust(Smart_Data *sd);
130 static int _smart_scrollbar_bar_v_visibility_adjust(Smart_Data *sd);
131 static void _smart_scrollbar_bar_visibility_adjust(Smart_Data *sd);
132 static void _smart_scrollbar_size_adjust(Smart_Data *sd);
133 static void _smart_reconfigure(Smart_Data *sd);
134 static void _smart_add(Evas_Object *obj);
135 static void _smart_del(Evas_Object *obj);
136 static void _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y);
137 static void _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h);
138 static void _smart_show(Evas_Object *obj);
139 static void _smart_hide(Evas_Object *obj);
140 static void _smart_color_set(Evas_Object *obj, int r, int g, int b, int a);
141 static void _smart_clip_set(Evas_Object *obj, Evas_Object *clip);
142 static void _smart_clip_unset(Evas_Object *obj);
143 static void _smart_init(void);
145 /* local subsystem globals */
146 static Evas_Smart *_smart = NULL;
148 /* externally accessible functions */
150 elm_smart_scroller_add(Evas *evas)
153 return evas_object_smart_add(evas, _smart);
157 _elm_smart_scroller_x_mirrored_get(Evas_Object *obj, Evas_Coord x)
161 Evas_Coord cw, ch, w;
162 elm_smart_scroller_child_viewport_size_get(obj, &w, NULL);
163 sd->pan_func.child_size_get(sd->pan_obj, &cw, &ch);
164 return (cw - (x + w));
168 elm_smart_scroller_mirrored_set(Evas_Object *obj, Eina_Bool mirrored)
172 if (sd->is_mirrored == mirrored)
175 sd->is_mirrored = mirrored;
176 edje_object_mirrored_set(sd->edje_obj, mirrored);
179 wx = _elm_smart_scroller_x_mirrored_get(sd->smart_obj, sd->wx);
183 elm_smart_scroller_child_pos_set(sd->smart_obj, wx, sd->wy);
187 elm_smart_scroller_child_set(Evas_Object *obj, Evas_Object *child)
195 _elm_smart_pan_child_set(sd->pan_obj, NULL);
196 evas_object_event_callback_del_full(sd->child_obj, EVAS_CALLBACK_DEL, _smart_child_del_hook, sd);
199 sd->child_obj = child;
201 /* (-1) means want viewports size */
202 sd->ww = sd->wh = -1;
207 o = _elm_smart_pan_add(evas_object_evas_get(obj));
209 evas_object_smart_callback_add(o, "changed", _smart_pan_changed_hook, sd);
210 evas_object_smart_callback_add(o, "pan_changed", _smart_pan_pan_changed_hook, sd);
212 edje_object_part_swallow(sd->edje_obj, "elm.swallow.content", o);
215 sd->pan_func.set = _elm_smart_pan_set;
216 sd->pan_func.get = _elm_smart_pan_get;
217 sd->pan_func.max_get = _elm_smart_pan_max_get;
218 sd->pan_func.min_get = _elm_smart_pan_min_get;
219 sd->pan_func.child_size_get = _elm_smart_pan_child_size_get;
221 evas_object_event_callback_add(child, EVAS_CALLBACK_DEL, _smart_child_del_hook, sd);
222 _elm_smart_pan_child_set(sd->pan_obj, sd->child_obj);
223 sd->pan_func.child_size_get(sd->pan_obj, &w, &h);
226 _smart_scrollbar_size_adjust(sd);
227 _smart_scrollbar_reset(sd);
231 elm_smart_scroller_extern_pan_set(Evas_Object *obj, Evas_Object *pan,
232 void (*pan_set) (Evas_Object *obj, Evas_Coord x, Evas_Coord y),
233 void (*pan_get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y),
234 void (*pan_max_get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y),
235 void (*pan_min_get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y),
236 void (*pan_child_size_get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y))
240 elm_smart_scroller_child_set(obj, NULL);
244 evas_object_smart_callback_del(sd->pan_obj, "changed", _smart_pan_changed_hook);
245 evas_object_smart_callback_del(sd->pan_obj, "pan_changed", _smart_pan_pan_changed_hook);
252 edje_object_part_unswallow(sd->edje_obj, sd->pan_obj);
260 evas_object_del(sd->pan_obj);
271 sd->pan_func.set = pan_set;
272 sd->pan_func.get = pan_get;
273 sd->pan_func.max_get = pan_max_get;
274 sd->pan_func.min_get = pan_min_get;
275 sd->pan_func.child_size_get = pan_child_size_get;
277 evas_object_smart_callback_add(sd->pan_obj, "changed", _smart_pan_changed_hook, sd);
278 evas_object_smart_callback_add(sd->pan_obj, "pan_changed", _smart_pan_pan_changed_hook, sd);
279 edje_object_part_swallow(sd->edje_obj, "elm.swallow.content", sd->pan_obj);
280 evas_object_show(sd->pan_obj);
284 elm_smart_scroller_custom_edje_file_set(Evas_Object *obj, char *file, char *group)
288 edje_object_file_set(sd->edje_obj, file, group);
290 edje_object_part_swallow(sd->edje_obj, "elm.swallow.content", sd->pan_obj);
291 sd->vbar_visible = !sd->vbar_visible;
292 sd->hbar_visible = !sd->hbar_visible;
293 _smart_scrollbar_bar_visibility_adjust(sd);
294 if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
295 edje_object_signal_emit(sd->edje_obj, "elm,action,show_always,hbar", "elm");
296 else if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
297 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,hbar", "elm");
299 edje_object_signal_emit(sd->edje_obj, "elm,action,show_notalways,hbar", "elm");
300 if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
301 edje_object_signal_emit(sd->edje_obj, "elm,action,show_always,vbar", "elm");
302 else if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
303 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,vbar", "elm");
305 edje_object_signal_emit(sd->edje_obj, "elm,action,show_notalways,vbar", "elm");
309 elm_smart_scroller_momentum_animator_disabled_get(Evas_Object *obj)
311 API_ENTRY return EINA_FALSE;
312 return sd->momentum_animator_disabled;
316 elm_smart_scroller_momentum_animator_disabled_set(Evas_Object *obj, Eina_Bool disabled)
319 sd->momentum_animator_disabled = disabled;
320 if (sd->momentum_animator_disabled)
322 if (sd->down.momentum_animator)
324 ecore_animator_del(sd->down.momentum_animator);
325 sd->down.momentum_animator = NULL;
331 elm_smart_scroller_bounce_animator_disabled_get(Evas_Object *obj)
333 API_ENTRY return EINA_FALSE;
334 return sd->bounce_animator_disabled;
338 elm_smart_scroller_bounce_animator_disabled_set(Evas_Object *obj, Eina_Bool disabled)
341 sd->bounce_animator_disabled = disabled;
342 if (sd->bounce_animator_disabled)
344 if (sd->scrollto.x.animator)
346 ecore_animator_del(sd->scrollto.x.animator);
347 sd->scrollto.x.animator = NULL;
350 if (sd->scrollto.y.animator)
352 ecore_animator_del(sd->scrollto.y.animator);
353 sd->scrollto.y.animator = NULL;
358 /* Update the wanted coordinates according to the x, y passed
359 * widget directionality, child size and etc. */
361 _update_wanted_coordinates(Smart_Data *sd, Evas_Coord x, Evas_Coord y)
365 sd->pan_func.child_size_get(sd->pan_obj, &cw, &ch);
367 /* Update wx/y/w/h - and if the requested positions aren't legal
369 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &sd->ww, &sd->wh);
372 else if ((x + sd->ww) > cw)
373 sd->wx = cw - sd->ww;
374 else if (sd->is_mirrored)
375 sd->wx = _elm_smart_scroller_x_mirrored_get(sd->smart_obj, x);
378 if (y < 0) sd->wy = 0;
379 else if ((y + sd->wh) > ch) sd->wy = ch - sd->wh;
384 _smart_anim_start(Evas_Object *obj)
386 evas_object_smart_callback_call(obj, "animate,start", NULL);
390 _smart_anim_stop(Evas_Object *obj)
392 evas_object_smart_callback_call(obj, "animate,stop", NULL);
396 _smart_drag_start(Evas_Object *obj)
398 evas_object_smart_callback_call(obj, "drag,start", NULL);
402 _smart_drag_stop(Evas_Object *obj)
404 evas_object_smart_callback_call(obj, "drag,stop", NULL);
408 _smart_scrollto_x_animator(void *data)
410 Smart_Data *sd = data;
414 t = ecore_loop_time_get();
415 tt = (t - sd->scrollto.x.t_start) / (sd->scrollto.x.t_end - sd->scrollto.x.t_start);
417 tt = 1.0 - (tt * tt);
418 sd->pan_func.get(sd->pan_obj, &px, &py);
419 px = (sd->scrollto.x.start * (1.0 - tt)) +
420 (sd->scrollto.x.end * tt);
421 if (t >= sd->scrollto.x.t_end)
423 px = sd->scrollto.x.end;
424 elm_smart_scroller_child_pos_set(sd->smart_obj, px, py);
425 sd->scrollto.x.animator = NULL;
426 if ((!sd->scrollto.y.animator) && (!sd->down.bounce_y_animator))
427 _smart_anim_stop(sd->smart_obj);
428 return ECORE_CALLBACK_CANCEL;
430 elm_smart_scroller_child_pos_set(sd->smart_obj, px, py);
431 return ECORE_CALLBACK_RENEW;
435 _smart_momentum_end(Smart_Data *sd)
437 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator)) return;
438 if (sd->down.momentum_animator)
441 elm_smart_scroller_child_pos_get(sd->smart_obj, &px, &py);
442 _update_wanted_coordinates(sd, px, py);
444 ecore_animator_del(sd->down.momentum_animator);
445 sd->down.momentum_animator = NULL;
446 sd->down.bounce_x_hold = 0;
447 sd->down.bounce_y_hold = 0;
456 _smart_scrollto_x(Smart_Data *sd, double t_in, Evas_Coord pos_x)
458 Evas_Coord px, py, x, y, w, h;
461 if (sd->freeze) return;
464 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
465 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
467 elm_smart_scroller_child_region_set(sd->smart_obj, x, y, w, h);
470 t = ecore_loop_time_get();
471 sd->pan_func.get(sd->pan_obj, &px, &py);
472 sd->scrollto.x.start = px;
473 sd->scrollto.x.end = pos_x;
474 sd->scrollto.x.t_start = t;
475 sd->scrollto.x.t_end = t + t_in;
476 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
477 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
478 elm_smart_scroller_child_region_set(sd->smart_obj, x, y, w, h);
479 if (!sd->scrollto.x.animator)
481 if (!sd->scrollto.y.animator)
482 _smart_anim_start(sd->smart_obj);
483 sd->scrollto.x.animator = ecore_animator_add(_smart_scrollto_x_animator, sd);
485 if (sd->down.bounce_x_animator)
487 ecore_animator_del(sd->down.bounce_x_animator);
488 sd->down.bounce_x_animator = NULL;
489 _smart_momentum_end(sd);
495 _smart_scrollto_y_animator(void *data)
497 Smart_Data *sd = data;
501 t = ecore_loop_time_get();
502 tt = (t - sd->scrollto.y.t_start) / (sd->scrollto.y.t_end - sd->scrollto.y.t_start);
504 tt = 1.0 - (tt * tt);
505 sd->pan_func.get(sd->pan_obj, &px, &py);
506 py = (sd->scrollto.y.start * (1.0 - tt)) +
507 (sd->scrollto.y.end * tt);
508 if (t >= sd->scrollto.y.t_end)
510 py = sd->scrollto.y.end;
511 elm_smart_scroller_child_pos_set(sd->smart_obj, px, py);
512 sd->scrollto.y.animator = NULL;
513 if ((!sd->scrollto.x.animator) && (!sd->down.bounce_x_animator))
514 _smart_anim_stop(sd->smart_obj);
515 return ECORE_CALLBACK_CANCEL;
517 elm_smart_scroller_child_pos_set(sd->smart_obj, px, py);
519 return ECORE_CALLBACK_RENEW;
523 _smart_scrollto_y(Smart_Data *sd, double t_in, Evas_Coord pos_y)
525 Evas_Coord px, py, x, y, w, h;
528 if (sd->freeze) return;
531 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
532 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
534 elm_smart_scroller_child_region_set(sd->smart_obj, x, y, w, h);
537 t = ecore_loop_time_get();
538 sd->pan_func.get(sd->pan_obj, &px, &py);
539 sd->scrollto.y.start = py;
540 sd->scrollto.y.end = pos_y;
541 sd->scrollto.y.t_start = t;
542 sd->scrollto.y.t_end = t + t_in;
543 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
544 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
545 elm_smart_scroller_child_region_set(sd->smart_obj, x, y, w, h);
546 if (!sd->scrollto.y.animator)
548 if (!sd->scrollto.x.animator)
549 _smart_anim_start(sd->smart_obj);
550 sd->scrollto.y.animator = ecore_animator_add(_smart_scrollto_y_animator, sd);
552 if (sd->down.bounce_y_animator)
554 ecore_animator_del(sd->down.bounce_y_animator);
555 sd->down.bounce_y_animator = NULL;
556 _smart_momentum_end(sd);
562 _smart_do_page(Smart_Data *sd)
564 if ((sd->pagerel_h == 0.0) && (!sd->pagesize_h) &&
565 (sd->pagerel_v == 0.0) && (!sd->pagesize_v))
571 _smart_page_x_get(Smart_Data *sd, int offset)
573 Evas_Coord x, y, w, h, cw, ch, minx = 0;
575 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
576 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
577 sd->pan_func.child_size_get(sd->pan_obj, &cw, &ch);
578 sd->pan_func.min_get(sd->pan_obj, &minx, NULL);
582 if (sd->pagerel_h > 0.0)
584 x = x + (w * sd->pagerel_h * 0.5);
585 x = x / (w * sd->pagerel_h);
586 x = x * (w * sd->pagerel_h);
588 else if (sd->pagesize_h > 0)
590 x = x + (sd->pagesize_h * 0.5);
591 x = x / (sd->pagesize_h);
592 x = x * (sd->pagesize_h);
594 if (x < minx) x = minx;
595 else if ((x + w) > cw) x = cw - w;
600 _smart_page_y_get(Smart_Data *sd, int offset)
602 Evas_Coord x, y, w, h, cw, ch, miny = 0;
604 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
605 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
606 sd->pan_func.child_size_get(sd->pan_obj, &cw, &ch);
607 sd->pan_func.min_get(sd->pan_obj, NULL, &miny);
611 if (sd->pagerel_v > 0.0)
613 y = y + (h * sd->pagerel_v * 0.5);
614 y = y / (h * sd->pagerel_v);
615 y = y * (h * sd->pagerel_v);
617 else if (sd->pagesize_v > 0)
619 y = y + (sd->pagesize_v * 0.5);
620 y = y / (sd->pagesize_v);
621 y = y * (sd->pagesize_v);
623 if (y < miny) y = miny;
624 else if ((y + h) > ch) y = ch - h;
629 _smart_page_adjust(Smart_Data *sd)
631 Evas_Coord x, y, w, h;
633 if (!_smart_do_page(sd)) return;
635 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
637 x = _smart_page_x_get(sd, 0);
638 y = _smart_page_y_get(sd, 0);
640 elm_smart_scroller_child_region_set(sd->smart_obj, x, y, w, h);
644 _smart_bounce_x_animator(void *data)
651 t = ecore_loop_time_get();
652 dt = t - sd->down.anim_start2;
655 dt = dt / _elm_config->thumbscroll_bounce_friction;
656 if (dt > 1.0) dt = 1.0;
657 p = 1.0 - ((1.0 - dt) * (1.0 - dt));
658 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
659 dx = sd->down.b2x - sd->down.bx;
661 x = sd->down.bx + dx;
662 if (!sd->down.cancelled)
663 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
666 if (sd->down.momentum_animator)
667 sd->down.bounce_x_hold = 1;
668 else if ((!sd->down.bounce_y_animator) &&
669 (!sd->scrollto.y.animator))
670 _smart_anim_stop(sd->smart_obj);
671 sd->down.bounce_x_animator = NULL;
674 _smart_momentum_end(sd);
675 return ECORE_CALLBACK_CANCEL;
678 return ECORE_CALLBACK_RENEW;
682 _smart_bounce_y_animator(void *data)
689 t = ecore_loop_time_get();
690 dt = t - sd->down.anim_start3;
693 dt = dt / _elm_config->thumbscroll_bounce_friction;
694 if (dt > 1.0) dt = 1.0;
695 p = 1.0 - ((1.0 - dt) * (1.0 - dt));
696 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
697 dy = sd->down.b2y - sd->down.by;
699 y = sd->down.by + dy;
700 if (!sd->down.cancelled)
701 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
704 if (sd->down.momentum_animator)
705 sd->down.bounce_y_hold = 1;
706 else if ((!sd->down.bounce_x_animator) &&
707 (!sd->scrollto.y.animator))
708 _smart_anim_stop(sd->smart_obj);
709 sd->down.bounce_y_animator = NULL;
712 _smart_momentum_end(sd);
713 return ECORE_CALLBACK_CANCEL;
716 return ECORE_CALLBACK_RENEW;
724 can_scroll(Smart_Data *sd, int dir)
726 Evas_Coord mx = 0, my = 0, px = 0, py = 0, minx = 0, miny = 0;
728 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
729 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
730 sd->pan_func.get(sd->pan_obj, &px, &py);
734 if (px > minx) return EINA_TRUE;
737 if ((px - minx) < mx) return EINA_TRUE;
740 if (py > miny) return EINA_TRUE;
743 if ((py - miny) < my) return EINA_TRUE;
752 _smart_momentum_animator(void *data)
756 Evas_Coord x, y, dx, dy, px, py, maxx, maxy, minx, miny;
757 Eina_Bool no_bounce_x_end = EINA_FALSE, no_bounce_y_end = EINA_FALSE;
760 t = ecore_loop_time_get();
761 dt = t - sd->down.anim_start;
765 if (sd->down.hold_parent)
767 if ((sd->down.dir_x) && !can_scroll(sd, sd->down.hdir))
771 if ((sd->down.dir_y) && !can_scroll(sd, sd->down.vdir))
776 if ((!sd->down.dir_x) && (!sd->down.dir_y))
778 sd->down.cancelled = 1;
781 dt = dt / (_elm_config->thumbscroll_friction + sd->down.extra_time);
782 if (dt > 1.0) dt = 1.0;
783 p = 1.0 - ((1.0 - dt) * (1.0 - dt));
784 dx = (sd->down.dx * (_elm_config->thumbscroll_friction + sd->down.extra_time) * p);
785 dy = (sd->down.dy * (_elm_config->thumbscroll_friction + sd->down.extra_time) * p);
788 x = sd->down.sx - dx;
789 y = sd->down.sy - dy;
790 elm_smart_scroller_child_pos_get(sd->smart_obj, &px, &py);
791 if ((sd->down.bounce_x_animator) ||
792 (sd->down.bounce_x_hold))
794 sd->down.bx = sd->down.bx0 - dx + sd->down.b0x;
797 if ((sd->down.bounce_y_animator) ||
798 (sd->down.bounce_y_hold))
800 sd->down.by = sd->down.by0 - dy + sd->down.b0y;
803 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
804 sd->pan_func.max_get(sd->pan_obj, &maxx, &maxy);
805 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
806 if (!sd->bounce_horiz)
808 if (x <= minx) no_bounce_x_end = EINA_TRUE;
809 if ((x - minx) >= maxx) no_bounce_x_end = EINA_TRUE;
811 if (!sd->bounce_vert)
813 if (y <= miny) no_bounce_y_end = EINA_TRUE;
814 if ((y - miny) >= maxy) no_bounce_y_end = EINA_TRUE;
817 ((sd->down.bounce_x_hold) && (sd->down.bounce_y_hold)) ||
818 (no_bounce_x_end && no_bounce_y_end))
820 _smart_anim_stop(sd->smart_obj);
821 _update_wanted_coordinates(sd, px, py);
823 sd->down.momentum_animator = NULL;
824 sd->down.bounce_x_hold = 0;
825 sd->down.bounce_y_hold = 0;
830 return ECORE_CALLBACK_CANCEL;
833 return ECORE_CALLBACK_RENEW;
837 bounce_eval(Smart_Data *sd)
839 Evas_Coord mx, my, px, py, bx, by, b2x, b2y, minx = 0, miny = 0;
841 if (sd->freeze) return;
842 if ((!sd->bouncemex) && (!sd->bouncemey)) return;
843 if (sd->down.now) return; // down bounce while still held down
844 if (sd->down.onhold_animator)
846 ecore_animator_del(sd->down.onhold_animator);
847 sd->down.onhold_animator = NULL;
849 if (sd->down.hold_animator)
851 ecore_animator_del(sd->down.hold_animator);
852 sd->down.hold_animator = NULL;
854 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
855 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
856 sd->pan_func.get(sd->pan_obj, &px, &py);
859 if (px < minx) px = minx;
860 if ((px - minx) > mx) px = mx + minx;
861 if (py < miny) py = miny;
862 if ((py - miny) > my) py = my + miny;
866 (!elm_widget_drag_child_locked_x_get(sd->widget)))
868 if (!sd->down.bounce_x_animator && !sd->bounce_animator_disabled)
872 if (sd->scrollto.x.animator)
874 ecore_animator_del(sd->scrollto.x.animator);
875 sd->scrollto.x.animator = NULL;
877 sd->down.bounce_x_animator = ecore_animator_add(_smart_bounce_x_animator, sd);
878 sd->down.anim_start2 = ecore_loop_time_get();
882 if (sd->down.momentum_animator) sd->down.b0x = sd->down.ax;
883 else sd->down.b0x = 0;
888 (!elm_widget_drag_child_locked_y_get(sd->widget)))
890 if (!sd->down.bounce_y_animator && !sd->bounce_animator_disabled)
894 if (sd->scrollto.y.animator)
896 ecore_animator_del(sd->scrollto.y.animator);
897 sd->scrollto.y.animator = NULL;
899 sd->down.bounce_y_animator = ecore_animator_add(_smart_bounce_y_animator, sd);
900 sd->down.anim_start3 = ecore_loop_time_get();
904 if (sd->down.momentum_animator) sd->down.b0y = sd->down.ay;
905 else sd->down.b0y = 0;
912 elm_smart_scroller_child_pos_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
914 Evas_Coord mx = 0, my = 0, px = 0, py = 0, minx = 0, miny = 0;
918 // FIXME: allow for bounce outside of range
919 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
920 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
921 if (mx > 0) vx = (double)(x - minx) / (double)mx;
923 if (vx < 0.0) vx = 0.0;
924 else if (vx > 1.0) vx = 1.0;
925 if (my > 0) vy = (double)(y - miny) / (double)my;
927 if (vy < 0.0) vy = 0.0;
928 else if (vy > 1.0) vy = 1.0;
929 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.vbar", 0.0, vy);
930 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.hbar", vx, 0.0);
931 sd->pan_func.get(sd->pan_obj, &px, &py);
932 if (!_elm_config->thumbscroll_bounce_enable)
934 if (x < minx) x = minx;
935 if ((x - minx) > mx) x = mx + minx;
936 if (y < miny) y = miny;
937 if ((y - miny) > my) y = my + miny;
940 if (!sd->bounce_horiz)
942 if (x < minx) x = minx;
943 if ((x - minx) > mx) x = mx + minx;
945 if (!sd->bounce_vert)
947 if (y < miny) y = miny;
948 if (y - miny > my) y = my + miny;
951 sd->pan_func.set(sd->pan_obj, x, y);
952 if ((px != x) || (py != y))
953 edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
954 if (!sd->down.bounce_x_animator)
956 if ((x < minx) || (x > (mx + minx)))
962 if (!sd->down.bounce_y_animator)
964 if ((y < miny) || (y > my + miny))
970 if ((x != px) || (y != py))
972 evas_object_smart_callback_call(obj, "scroll", NULL);
974 if ((x != px)/* && (!sd->bouncemex)*/)
977 evas_object_smart_callback_call(obj, "edge,left", NULL);
978 if (x == (mx + minx))
979 evas_object_smart_callback_call(obj, "edge,right", NULL);
981 if ((y != py)/* && (!sd->bouncemey)*/)
984 evas_object_smart_callback_call(obj, "edge,top", NULL);
986 evas_object_smart_callback_call(obj, "edge,bottom", NULL);
991 elm_smart_scroller_child_pos_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
994 sd->pan_func.get(sd->pan_obj, x, y);
997 /* "internal_call" actually toggles whether we should save the coords and do
998 * extra "speedup" checks, or not. */
1000 _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)
1002 Evas_Coord mx = 0, my = 0, cw = 0, ch = 0, px = 0, py = 0, nx, ny, minx = 0, miny = 0;
1005 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
1006 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
1007 sd->pan_func.child_size_get(sd->pan_obj, &cw, &ch);
1008 sd->pan_func.get(sd->pan_obj, &px, &py);
1011 if ((x < px) && ((x + w) < (px + (cw - mx)))) nx = x;
1012 else if ((x > px) && ((x + w) > (px + (cw - mx)))) nx = x + w - (cw - mx);
1014 if ((y < py) && ((y + h) < (py + (ch - my)))) ny = y;
1015 else if ((y > py) && ((y + h) > (py + (ch - my)))) ny = y + h - (ch - my);
1022 if ((nx == px) && (ny == py)) return;
1025 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1026 (sd->scrollto.x.animator) || (sd->scrollto.y.animator))
1028 _smart_anim_stop(sd->smart_obj);
1030 if (sd->scrollto.x.animator)
1032 ecore_animator_del(sd->scrollto.x.animator);
1033 sd->scrollto.x.animator = NULL;
1035 if (sd->scrollto.y.animator)
1037 ecore_animator_del(sd->scrollto.y.animator);
1038 sd->scrollto.y.animator = NULL;
1040 if (sd->down.bounce_x_animator)
1042 ecore_animator_del(sd->down.bounce_x_animator);
1043 sd->down.bounce_x_animator = NULL;
1046 if (sd->down.bounce_y_animator)
1048 ecore_animator_del(sd->down.bounce_y_animator);
1049 sd->down.bounce_y_animator = NULL;
1052 if (sd->down.hold_animator)
1054 ecore_animator_del(sd->down.hold_animator);
1055 sd->down.hold_animator = NULL;
1056 _smart_drag_stop(sd->smart_obj);
1058 if (sd->down.momentum_animator)
1060 ecore_animator_del(sd->down.momentum_animator);
1061 sd->down.momentum_animator = NULL;
1062 sd->down.bounce_x_hold = 0;
1063 sd->down.bounce_y_hold = 0;
1069 elm_smart_scroller_child_pos_set(obj, nx, ny);
1072 /* Set should be used for calculated positions, for example, when we move
1073 * because of an animation or because this is the correct position after
1076 elm_smart_scroller_child_region_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
1078 _elm_smart_scroller_child_region_show_internal(obj, x, y, w, h, EINA_TRUE);
1081 /* Set should be used for setting the wanted position, for example a user scroll
1082 * or moving the cursor in an entry. */
1084 elm_smart_scroller_child_region_show(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
1086 _elm_smart_scroller_child_region_show_internal(obj, x, y, w, h, EINA_FALSE);
1090 elm_smart_scroller_child_viewport_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
1093 edje_object_calc_force(sd->edje_obj);
1094 evas_object_geometry_get(sd->pan_obj, NULL, NULL, w, h);
1098 elm_smart_scroller_step_size_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
1105 _smart_scrollbar_size_adjust(sd);
1109 elm_smart_scroller_step_size_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
1112 if (x) *x = sd->step.x;
1113 if (y) *y = sd->step.y;
1117 elm_smart_scroller_page_size_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
1122 _smart_scrollbar_size_adjust(sd);
1126 elm_smart_scroller_page_size_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
1129 if (x) *x = sd->page.x;
1130 if (y) *y = sd->page.y;
1134 elm_smart_scroller_policy_set(Evas_Object *obj, Elm_Smart_Scroller_Policy hbar, Elm_Smart_Scroller_Policy vbar)
1137 if ((sd->hbar_flags == hbar) && (sd->vbar_flags == vbar)) return;
1138 sd->hbar_flags = hbar;
1139 sd->vbar_flags = vbar;
1140 if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
1141 edje_object_signal_emit(sd->edje_obj, "elm,action,show_always,hbar", "elm");
1142 else if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
1143 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,hbar", "elm");
1145 edje_object_signal_emit(sd->edje_obj, "elm,action,show_notalways,hbar", "elm");
1146 if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
1147 edje_object_signal_emit(sd->edje_obj, "elm,action,show_always,vbar", "elm");
1148 else if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
1149 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,vbar", "elm");
1151 edje_object_signal_emit(sd->edje_obj, "elm,action,show_notalways,vbar", "elm");
1152 _smart_scrollbar_size_adjust(sd);
1156 elm_smart_scroller_policy_get(Evas_Object *obj, Elm_Smart_Scroller_Policy *hbar, Elm_Smart_Scroller_Policy *vbar)
1159 if (hbar) *hbar = sd->hbar_flags;
1160 if (vbar) *vbar = sd->vbar_flags;
1164 elm_smart_scroller_edje_object_get(Evas_Object *obj)
1166 API_ENTRY return NULL;
1167 return sd->edje_obj;
1171 elm_smart_scroller_single_dir_set(Evas_Object *obj, Eina_Bool single_dir)
1174 sd->one_dir_at_a_time = single_dir;
1178 elm_smart_scroller_single_dir_get(Evas_Object *obj)
1180 API_ENTRY return EINA_FALSE;
1181 return sd->one_dir_at_a_time;
1185 elm_smart_scroller_object_theme_set(Evas_Object *parent, Evas_Object *obj, const char *clas, const char *group, const char *style)
1189 _elm_theme_object_set(parent, sd->edje_obj, clas, group, style);
1190 edje_object_scale_set(sd->edje_obj, elm_widget_scale_get(parent) * _elm_config->scale);
1192 edje_object_part_swallow(sd->edje_obj, "elm.swallow.content", sd->pan_obj);
1194 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1195 if (edje_object_part_exists(sd->edje_obj, "elm.scrollbar.base"))
1198 base = edje_object_part_swallow_get(sd->edje_obj, "elm.scrollbar.base");
1201 base = evas_object_rectangle_add(evas_object_evas_get(sd->edje_obj));
1202 evas_object_color_set(base, 0, 0, 0, 0);
1203 edje_object_part_swallow(sd->edje_obj, "elm.scrollbar.base", base);
1205 if (!_elm_config->thumbscroll_enable)
1206 evas_object_size_hint_min_set(base, mw, mh);
1208 sd->vbar_visible = !sd->vbar_visible;
1209 sd->hbar_visible = !sd->hbar_visible;
1210 _smart_scrollbar_bar_visibility_adjust(sd);
1214 elm_smart_scroller_hold_set(Evas_Object *obj, Eina_Bool hold)
1221 elm_smart_scroller_freeze_set(Evas_Object *obj, Eina_Bool freeze)
1224 sd->freeze = freeze;
1227 if (sd->down.onhold_animator)
1229 ecore_animator_del(sd->down.onhold_animator);
1230 sd->down.onhold_animator = NULL;
1236 elm_smart_scroller_bounce_allow_set(Evas_Object *obj, Eina_Bool horiz, Eina_Bool vert)
1239 sd->bounce_horiz = horiz;
1240 sd->bounce_vert = vert;
1244 elm_smart_scroller_bounce_allow_get(const Evas_Object *obj, Eina_Bool *horiz, Eina_Bool *vert)
1247 *horiz = sd->bounce_horiz;
1248 *vert = sd->bounce_vert;
1252 elm_smart_scroller_paging_set(Evas_Object *obj, double pagerel_h, double pagerel_v, Evas_Coord pagesize_h, Evas_Coord pagesize_v)
1255 sd->pagerel_h = pagerel_h;
1256 sd->pagerel_v = pagerel_v;
1257 sd->pagesize_h = pagesize_h;
1258 sd->pagesize_v = pagesize_v;
1259 _smart_page_adjust(sd);
1263 elm_smart_scroller_paging_get(Evas_Object *obj, double *pagerel_h, double *pagerel_v, Evas_Coord *pagesize_h, Evas_Coord *pagesize_v)
1266 if(pagerel_h) *pagerel_h = sd->pagerel_h;
1267 if(pagerel_v) *pagerel_v = sd->pagerel_v;
1268 if(pagesize_h) *pagesize_h = sd->pagesize_h;
1269 if(pagesize_v) *pagesize_v = sd->pagesize_v;
1273 elm_smart_scroller_region_bring_in(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
1275 Evas_Coord mx = 0, my = 0, cw = 0, ch = 0, px = 0, py = 0, nx, ny, minx = 0, miny = 0;
1278 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
1279 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
1280 sd->pan_func.child_size_get(sd->pan_obj, &cw, &ch);
1281 sd->pan_func.get(sd->pan_obj, &px, &py);
1284 if ((x < px) && ((x + w) < (px + (cw - mx)))) nx = x;
1285 else if ((x > px) && ((x + w) > (px + (cw - mx)))) nx = x + w - (cw - mx);
1287 if ((y < py) && ((y + h) < (py + (ch - my)))) ny = y;
1288 else if ((y > py) && ((y + h) > (py + (ch - my)))) ny = y + h - (ch - my);
1289 if ((nx == px) && (ny == py)) return;
1290 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1291 (sd->scrollto.x.animator) || (sd->scrollto.y.animator))
1293 _smart_anim_stop(sd->smart_obj);
1295 if (sd->scrollto.x.animator)
1297 ecore_animator_del(sd->scrollto.x.animator);
1298 sd->scrollto.x.animator = NULL;
1300 if (sd->scrollto.y.animator)
1302 ecore_animator_del(sd->scrollto.y.animator);
1303 sd->scrollto.y.animator = NULL;
1305 if (sd->down.bounce_x_animator)
1307 ecore_animator_del(sd->down.bounce_x_animator);
1308 sd->down.bounce_x_animator = NULL;
1311 if (sd->down.bounce_y_animator)
1313 ecore_animator_del(sd->down.bounce_y_animator);
1314 sd->down.bounce_y_animator = NULL;
1317 if (sd->down.hold_animator)
1319 ecore_animator_del(sd->down.hold_animator);
1320 sd->down.hold_animator = NULL;
1321 _smart_drag_stop(sd->smart_obj);
1323 if (sd->down.momentum_animator)
1325 ecore_animator_del(sd->down.momentum_animator);
1326 sd->down.momentum_animator = NULL;
1327 sd->down.bounce_x_hold = 0;
1328 sd->down.bounce_y_hold = 0;
1335 if (x < minx) x = minx;
1336 else if ((x + w) > cw) x = cw - w;
1337 _smart_scrollto_x(sd, _elm_config->bring_in_scroll_friction, x);
1339 if (y < miny) y = miny;
1340 else if ((y + h) > ch) y = ch - h;
1341 _smart_scrollto_y(sd, _elm_config->bring_in_scroll_friction, y);
1345 elm_smart_scroller_widget_set(Evas_Object *obj, Evas_Object *wid)
1351 /* local subsystem functions */
1353 _smart_edje_drag_v_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1358 _smart_scrollbar_read(sd);
1359 _smart_drag_start(sd->smart_obj);
1363 _smart_edje_drag_v_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1368 _smart_scrollbar_read(sd);
1369 _smart_drag_stop(sd->smart_obj);
1373 _smart_edje_drag_v(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1378 _smart_scrollbar_read(sd);
1382 _smart_edje_drag_h_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1387 _smart_scrollbar_read(sd);
1388 _smart_drag_start(sd->smart_obj);
1392 _smart_edje_drag_h_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1397 _smart_scrollbar_read(sd);
1398 _smart_drag_stop(sd->smart_obj);
1402 _smart_edje_drag_h(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1407 _smart_scrollbar_read(sd);
1411 _smart_child_del_hook(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1416 sd->child_obj = NULL;
1417 _smart_scrollbar_size_adjust(sd);
1418 _smart_scrollbar_reset(sd);
1422 _smart_pan_changed_hook(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1429 sd->pan_func.get(sd->pan_obj, &x, &y);
1430 sd->pan_func.child_size_get(sd->pan_obj, &w, &h);
1431 if ((w != sd->child.w) || (h != sd->child.h))
1435 _smart_scrollbar_size_adjust(sd);
1436 evas_object_size_hint_min_set(sd->smart_obj, sd->child.w, sd->child.h);
1437 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
1442 _smart_pan_pan_changed_hook(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1448 sd->pan_func.get(sd->pan_obj, &x, &y);
1449 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1450 (sd->scrollto.x.animator) || (sd->scrollto.y.animator))
1452 _smart_anim_stop(sd->smart_obj);
1454 if (sd->scrollto.x.animator)
1456 ecore_animator_del(sd->scrollto.x.animator);
1457 sd->scrollto.x.animator = NULL;
1459 if (sd->scrollto.y.animator)
1461 ecore_animator_del(sd->scrollto.y.animator);
1462 sd->scrollto.y.animator = NULL;
1464 if (sd->down.bounce_x_animator)
1466 ecore_animator_del(sd->down.bounce_x_animator);
1467 sd->down.bounce_x_animator = NULL;
1470 if (sd->down.bounce_y_animator)
1472 ecore_animator_del(sd->down.bounce_y_animator);
1473 sd->down.bounce_y_animator = NULL;
1476 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
1480 _smart_event_wheel(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1482 Evas_Event_Mouse_Wheel *ev;
1484 Evas_Coord x = 0, y = 0;
1488 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
1489 if ((evas_key_modifier_is_set(ev->modifiers, "Control")) ||
1490 (evas_key_modifier_is_set(ev->modifiers, "Alt")) ||
1491 (evas_key_modifier_is_set(ev->modifiers, "Shift")) ||
1492 (evas_key_modifier_is_set(ev->modifiers, "Meta")) ||
1493 (evas_key_modifier_is_set(ev->modifiers, "Hyper")) ||
1494 (evas_key_modifier_is_set(ev->modifiers, "Super")))
1496 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1497 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1498 (sd->scrollto.x.animator) || (sd->scrollto.y.animator))
1500 _smart_anim_stop(sd->smart_obj);
1502 if (sd->scrollto.x.animator)
1504 ecore_animator_del(sd->scrollto.x.animator);
1505 sd->scrollto.x.animator = NULL;
1507 if (sd->scrollto.y.animator)
1509 ecore_animator_del(sd->scrollto.y.animator);
1510 sd->scrollto.y.animator = NULL;
1512 if (sd->down.bounce_x_animator)
1514 ecore_animator_del(sd->down.bounce_x_animator);
1515 sd->down.bounce_x_animator = NULL;
1518 if (sd->down.bounce_y_animator)
1520 ecore_animator_del(sd->down.bounce_y_animator);
1521 sd->down.bounce_y_animator = NULL;
1525 y += ev->z * sd->step.y;
1526 else if (ev->direction == 1)
1527 x += ev->z * sd->step.x;
1529 if ((!sd->hold) && (!sd->freeze))
1531 _update_wanted_coordinates(sd, x, y);
1532 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
1537 _smart_event_mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1539 Evas_Event_Mouse_Down *ev;
1541 Evas_Coord x = 0, y = 0;
1545 // if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
1546 if (_elm_config->thumbscroll_enable)
1549 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1550 (sd->down.momentum_animator) || (sd->scrollto.x.animator) ||
1551 (sd->scrollto.y.animator))
1553 ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL | EVAS_EVENT_FLAG_ON_HOLD;
1554 sd->down.scroll = 1;
1556 _smart_anim_stop(sd->smart_obj);
1558 if (sd->scrollto.x.animator)
1560 ecore_animator_del(sd->scrollto.x.animator);
1561 sd->scrollto.x.animator = NULL;
1563 if (sd->scrollto.y.animator)
1565 ecore_animator_del(sd->scrollto.y.animator);
1566 sd->scrollto.y.animator = NULL;
1568 if (sd->down.bounce_x_animator)
1570 ecore_animator_del(sd->down.bounce_x_animator);
1571 sd->down.bounce_x_animator = NULL;
1574 if (sd->down.bounce_y_animator)
1576 ecore_animator_del(sd->down.bounce_y_animator);
1577 sd->down.bounce_y_animator = NULL;
1580 if (sd->down.hold_animator)
1582 ecore_animator_del(sd->down.hold_animator);
1583 sd->down.hold_animator = NULL;
1584 _smart_drag_stop(sd->smart_obj);
1586 if (sd->down.momentum_animator)
1588 ecore_animator_del(sd->down.momentum_animator);
1589 sd->down.momentum_animator = NULL;
1590 sd->down.bounce_x_hold = 0;
1591 sd->down.bounce_y_hold = 0;
1595 if (ev->button == 1)
1598 sd->down.dragged = 0;
1601 sd->down.x = ev->canvas.x;
1602 sd->down.y = ev->canvas.y;
1603 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1606 sd->down.locked = 0;
1607 memset(&(sd->down.history[0]), 0, sizeof(sd->down.history[0]) * 20);
1609 sd->down.history[0].timestamp = ev->timestamp / 1000.0;
1611 sd->down.history[0].timestamp = ecore_loop_time_get();
1613 sd->down.history[0].x = ev->canvas.x;
1614 sd->down.history[0].y = ev->canvas.y;
1616 sd->down.dragged_began = 0;
1617 sd->down.hold_parent = 0;
1618 sd->down.cancelled = 0;
1623 _smart_hold_animator(void *data)
1625 Smart_Data *sd = data;
1628 elm_smart_scroller_child_pos_get(sd->smart_obj, &ox, &oy);
1631 if ((!sd->widget) ||
1632 (!elm_widget_drag_child_locked_x_get(sd->widget)))
1634 ox = sd->down.hold_x;
1639 if ((!sd->widget) ||
1640 (!elm_widget_drag_child_locked_y_get(sd->widget)))
1642 oy = sd->down.hold_y;
1645 elm_smart_scroller_child_pos_set(sd->smart_obj, ox, oy);
1646 return ECORE_CALLBACK_RENEW;
1650 _smart_event_post_up(void *data, Evas *e __UNUSED__)
1652 Smart_Data *sd = data;
1655 if (sd->down.dragged)
1657 elm_widget_drag_lock_x_set(sd->widget, 0);
1658 elm_widget_drag_lock_y_set(sd->widget, 0);
1665 _smart_event_mouse_up(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *event_info)
1667 Evas_Event_Mouse_Down *ev;
1669 Evas_Coord x = 0, y = 0, ox = 0, oy = 0;
1673 sd->down.hold_parent = 0;
1674 // if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
1675 evas_post_event_callback_push(e, _smart_event_post_up, sd);
1676 // FIXME: respect elm_widget_scroll_hold_get of parent container
1677 if (_elm_config->thumbscroll_enable)
1679 if (ev->button == 1)
1681 if (sd->down.onhold_animator)
1683 ecore_animator_del(sd->down.onhold_animator);
1684 sd->down.onhold_animator = NULL;
1686 x = ev->canvas.x - sd->down.x;
1687 y = ev->canvas.y - sd->down.y;
1688 if (sd->down.dragged)
1690 _smart_drag_stop(sd->smart_obj);
1691 if ((!sd->hold) && (!sd->freeze))
1695 Evas_Coord ax, ay, dx, dy, vel;
1698 t = ev->timestamp / 1000.0;
1700 t = ecore_loop_time_get();
1702 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1707 printf("------ %i %i\n", ev->canvas.x, ev->canvas.y);
1709 for (i = 0; i < 20; i++)
1711 dt = t - sd->down.history[i].timestamp;
1712 if (dt > 0.2) break;
1714 printf("H: %i %i @ %1.3f\n",
1715 sd->down.history[i].x,
1716 sd->down.history[i].y, dt);
1719 ax += sd->down.history[i].x;
1720 ay += sd->down.history[i].y;
1726 dx = ev->canvas.x - ax;
1727 dy = ev->canvas.y - ay;
1730 vel = sqrt((dx * dx) + (dy * dy)) / at;
1731 if ((_elm_config->thumbscroll_friction > 0.0) &&
1732 (vel > _elm_config->thumbscroll_momentum_threshold) &&
1735 sd->down.dx = ((double)dx / at);
1736 sd->down.dy = ((double)dy / at);
1737 if (((sd->down.dx > 0) && (sd->down.pdx > 0)) ||
1738 ((sd->down.dx < 0) && (sd->down.pdx < 0)))
1739 sd->down.dx += (double)sd->down.pdx * 1.5; // FIXME: * 1.5 - probably should be config
1740 if (((sd->down.dy > 0) && (sd->down.pdy > 0)) ||
1741 ((sd->down.dy < 0) && (sd->down.pdy < 0)))
1742 sd->down.dy += (double)sd->down.pdy * 1.5; // FIXME: * 1.5 - probably should be config
1743 if (((sd->down.dx > 0) && (sd->down.pdx > 0)) ||
1744 ((sd->down.dx < 0) && (sd->down.pdx < 0)) ||
1745 ((sd->down.dy > 0) && (sd->down.pdy > 0)) ||
1746 ((sd->down.dy < 0) && (sd->down.pdy < 0)))
1748 double t = ecore_loop_time_get();
1749 double dt = t - sd->down.anim_start;
1751 if (dt < 0.0) dt = 0.0;
1752 else if (dt > _elm_config->thumbscroll_friction)
1753 dt = _elm_config->thumbscroll_friction;
1754 sd->down.extra_time = _elm_config->thumbscroll_friction - dt;
1757 sd->down.extra_time = 0.0;
1758 sd->down.pdx = sd->down.dx;
1759 sd->down.pdy = sd->down.dy;
1762 if (!_smart_do_page(sd))
1764 if (!sd->down.momentum_animator && !sd->momentum_animator_disabled)
1766 sd->down.momentum_animator = ecore_animator_add(_smart_momentum_animator, sd);
1767 ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL;
1768 _smart_anim_start(sd->smart_obj);
1770 sd->down.anim_start = ecore_loop_time_get();
1771 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1779 if (sd->down.hold_animator)
1781 ecore_animator_del(sd->down.hold_animator);
1782 sd->down.hold_animator = NULL;
1790 evas_event_feed_hold(e, 0, ev->timestamp, ev->data);
1791 if (_smart_do_page(sd))
1793 Evas_Coord pgx, pgy;
1795 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1796 if ((!sd->widget) ||
1797 (!elm_widget_drag_child_locked_x_get(sd->widget)))
1799 pgx = _smart_page_x_get(sd, ox);
1802 ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL;
1803 _smart_scrollto_x(sd, _elm_config->page_scroll_friction, pgx);
1806 if ((!sd->widget) ||
1807 (!elm_widget_drag_child_locked_y_get(sd->widget)))
1809 pgy = _smart_page_y_get(sd, oy);
1812 ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL;
1813 _smart_scrollto_y(sd, _elm_config->page_scroll_friction, pgy);
1822 if (_smart_do_page(sd))
1824 Evas_Coord pgx, pgy;
1826 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1827 if ((!sd->widget) ||
1828 (!elm_widget_drag_child_locked_x_get(sd->widget)))
1830 pgx = _smart_page_x_get(sd, ox);
1831 if (pgx != x) _smart_scrollto_x(sd, _elm_config->page_scroll_friction, pgx);
1833 if ((!sd->widget) ||
1834 (!elm_widget_drag_child_locked_y_get(sd->widget)))
1836 pgy = _smart_page_y_get(sd, oy);
1837 if (pgy != y) _smart_scrollto_y(sd, _elm_config->page_scroll_friction, pgy);
1840 if (sd->down.hold_animator)
1842 ecore_animator_del(sd->down.hold_animator);
1843 sd->down.hold_animator = NULL;
1846 if (sd->down.scroll)
1848 ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL;
1849 sd->down.scroll = 0;
1853 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1856 sd->down.dragged_began = 0;
1859 sd->down.want_dragged = 0;
1860 sd->down.dragged = 0;
1862 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1863 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
1864 _update_wanted_coordinates(sd, x, y);
1866 if (!_smart_do_page(sd))
1873 _smart_onhold_animator(void *data)
1878 Evas_Coord x, y, ox, oy;
1881 t = ecore_loop_time_get();
1882 if (sd->down.onhold_tlast > 0.0)
1884 td = t - sd->down.onhold_tlast;
1885 vx = sd->down.onhold_vx * td * (double)_elm_config->thumbscroll_threshold * 2.0;
1886 vy = sd->down.onhold_vy * td * (double)_elm_config->thumbscroll_threshold * 2.0;
1887 elm_smart_scroller_child_pos_get(sd->smart_obj, &ox, &oy);
1893 if ((!sd->widget) ||
1894 (!elm_widget_drag_child_locked_x_get(sd->widget)))
1896 sd->down.onhold_vxe += vx;
1897 x = ox + (int)sd->down.onhold_vxe;
1898 sd->down.onhold_vxe -= (int)sd->down.onhold_vxe;
1904 if ((!sd->widget) ||
1905 (!elm_widget_drag_child_locked_y_get(sd->widget)))
1907 sd->down.onhold_vye += vy;
1908 y = oy + (int)sd->down.onhold_vye;
1909 sd->down.onhold_vye -= (int)sd->down.onhold_vye;
1913 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
1915 sd->down.onhold_tlast = t;
1916 return ECORE_CALLBACK_RENEW;
1920 _smart_event_post_move(void *data, Evas *e __UNUSED__)
1922 Smart_Data *sd = data;
1924 if (sd->down.want_dragged)
1928 if (sd->down.hold_parent)
1930 if ((sd->down.dir_x) && !can_scroll(sd, sd->down.hdir))
1934 if ((sd->down.dir_y) && !can_scroll(sd, sd->down.vdir))
1941 if ((!sd->widget) ||
1942 (!elm_widget_drag_child_locked_x_get(sd->widget)))
1944 sd->down.want_dragged = 0;
1945 sd->down.dragged = 1;
1948 elm_widget_drag_lock_x_set(sd->widget, 1);
1957 if ((!sd->widget) ||
1958 (!elm_widget_drag_child_locked_y_get(sd->widget)))
1960 sd->down.want_dragged = 0;
1961 sd->down.dragged = 1;
1964 elm_widget_drag_lock_y_set(sd->widget, 1);
1971 if ((!sd->down.dir_x) && (!sd->down.dir_y))
1973 sd->down.cancelled = 1;
1975 if (start) _smart_drag_start(sd->smart_obj);
1981 _smart_event_mouse_move(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *event_info)
1983 Evas_Event_Mouse_Move *ev;
1985 Evas_Coord x = 0, y = 0;
1989 // if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
1990 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) sd->down.hold_parent = 1;
1991 evas_post_event_callback_push(e, _smart_event_post_move, sd);
1992 // FIXME: respect elm_widget_scroll_hold_get of parent container
1993 if (_elm_config->thumbscroll_enable)
2000 printf("::: %i %i\n", ev->cur.canvas.x, ev->cur.canvas.y);
2002 memmove(&(sd->down.history[1]), &(sd->down.history[0]),
2003 sizeof(sd->down.history[0]) * 19);
2005 sd->down.history[0].timestamp = ev->timestamp / 1000.0;
2007 sd->down.history[0].timestamp = ecore_loop_time_get();
2009 sd->down.history[0].x = ev->cur.canvas.x;
2010 sd->down.history[0].y = ev->cur.canvas.y;
2012 if (!sd->down.dragged_began)
2014 x = ev->cur.canvas.x - sd->down.x;
2015 y = ev->cur.canvas.y - sd->down.y;
2020 if (x > 0) sd->down.hdir = LEFT;
2021 else if (x < 0) sd->down.hdir = RIGHT;
2022 if (y > 0) sd->down.vdir = UP;
2023 else if (y < 0) sd->down.vdir = DOWN;
2028 if ((sd->one_dir_at_a_time) &&
2029 (!((sd->down.dir_x) || (sd->down.dir_y))))
2031 if (x > _elm_config->thumbscroll_threshold)
2040 if (y > _elm_config->thumbscroll_threshold)
2057 // can_scroll(sd, LEFT);
2058 // can_scroll(sd, RIGHT);
2059 // can_scroll(sd, UP);
2060 // can_scroll(sd, DOWN);
2065 if ((!sd->hold) && (!sd->freeze))
2067 if ((sd->down.dragged) ||
2068 (((x * x) + (y * y)) >
2069 (_elm_config->thumbscroll_threshold *
2070 _elm_config->thumbscroll_threshold)))
2072 sd->down.dragged_began = 1;
2073 if (!sd->down.dragged)
2075 sd->down.want_dragged = 1;
2076 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2077 // evas_event_feed_hold(e, 1, ev->timestamp, ev->data);
2078 // _smart_drag_start(sd->smart_obj);
2080 if (sd->down.dragged)
2082 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2084 // ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2085 // sd->down.dragged = 1;
2087 x = sd->down.sx - (ev->cur.canvas.x - sd->down.x);
2091 y = sd->down.sy - (ev->cur.canvas.y - sd->down.y);
2094 if ((sd->down.dir_x) || (sd->down.dir_y))
2096 if (!sd->down.locked)
2098 sd->down.locked_x = x;
2099 sd->down.locked_y = y;
2100 sd->down.locked = 1;
2102 if (!((sd->down.dir_x) && (sd->down.dir_y)))
2104 if (sd->down.dir_x) y = sd->down.locked_y;
2105 else x = sd->down.locked_x;
2108 if (_elm_config->thumbscroll_border_friction > 0.0)
2110 Evas_Coord minx, miny;
2111 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2114 _elm_config->thumbscroll_border_friction;
2115 else if (sd->child.h <= sd->h)
2116 y += (sd->down.sy - y) *
2117 _elm_config->thumbscroll_border_friction;
2118 else if ((sd->child.h - sd->h + miny) < y)
2119 y += (sd->child.h - sd->h + miny - y) *
2120 _elm_config->thumbscroll_border_friction;
2123 _elm_config->thumbscroll_border_friction;
2124 else if (sd->child.w <= sd->w)
2125 x += (sd->down.sx - x) *
2126 _elm_config->thumbscroll_border_friction;
2127 else if ((sd->child.w - sd->w + minx) < x)
2128 x += (sd->child.w - sd->w + minx - x) *
2129 _elm_config->thumbscroll_border_friction;
2132 sd->down.hold_x = x;
2133 sd->down.hold_y = y;
2134 if (!sd->down.hold_animator)
2135 sd->down.hold_animator =
2136 ecore_animator_add(_smart_hold_animator, sd);
2137 // printf("a %i %i\n", sd->down.hold_x, sd->down.hold_y);
2138 // _smart_onhold_animator(sd);
2139 // elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
2143 if (sd->down.dragged_began)
2145 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2149 evas_event_feed_hold(e, 1, ev->timestamp, ev->data);
2154 else if (!sd->freeze)
2156 Evas_Coord ex, ey, ew, eh;
2157 double vx = 0.0, vy = 0.0;
2159 evas_object_geometry_get(sd->event_obj, &ex, &ey, &ew, &eh);
2160 x = ev->cur.canvas.x - ex;
2161 y = ev->cur.canvas.y - ey;
2162 if (x < _elm_config->thumbscroll_threshold)
2164 if (_elm_config->thumbscroll_threshold > 0.0)
2165 vx = -(double)(_elm_config->thumbscroll_threshold - x) /
2166 _elm_config->thumbscroll_threshold;
2170 else if (x > (ew - _elm_config->thumbscroll_threshold))
2172 if (_elm_config->thumbscroll_threshold > 0.0)
2173 vx = (double)(_elm_config->thumbscroll_threshold - (ew - x)) /
2174 _elm_config->thumbscroll_threshold;
2178 if (y < _elm_config->thumbscroll_threshold)
2180 if (_elm_config->thumbscroll_threshold > 0.0)
2181 vy = -(double)(_elm_config->thumbscroll_threshold - y) /
2182 _elm_config->thumbscroll_threshold;
2186 else if (y > (eh - _elm_config->thumbscroll_threshold))
2188 if (_elm_config->thumbscroll_threshold > 0.0)
2189 vy = (double)(_elm_config->thumbscroll_threshold - (eh - y)) /
2190 _elm_config->thumbscroll_threshold;
2194 if ((vx != 0.0) || (vy != 0.0))
2196 sd->down.onhold_vx = vx;
2197 sd->down.onhold_vy = vy;
2198 if (!sd->down.onhold_animator)
2200 sd->down.onhold_vxe = 0.0;
2201 sd->down.onhold_vye = 0.0;
2202 sd->down.onhold_tlast = 0.0;
2203 sd->down.onhold_animator = ecore_animator_add(_smart_onhold_animator, sd);
2205 // printf("b %i %i\n", sd->down.hold_x, sd->down.hold_y);
2209 if (sd->down.onhold_animator)
2211 ecore_animator_del(sd->down.onhold_animator);
2212 sd->down.onhold_animator = NULL;
2221 _smart_scrollbar_read(Smart_Data *sd)
2223 Evas_Coord x, y, mx = 0, my = 0, px, py, minx = 0, miny = 0;
2226 edje_object_part_drag_value_get(sd->edje_obj, "elm.dragable.vbar", NULL, &vy);
2227 edje_object_part_drag_value_get(sd->edje_obj, "elm.dragable.hbar", &vx, NULL);
2228 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
2229 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2230 x = vx * (double)mx + minx;
2231 y = vy * (double)my + miny;
2232 sd->pan_func.get(sd->pan_obj, &px, &py);
2233 sd->pan_func.set(sd->pan_obj, x, y);
2234 if ((px != x) || (py != y))
2235 edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
2239 _smart_scrollbar_reset(Smart_Data *sd)
2241 Evas_Coord px = 0, py = 0, minx = 0, miny = 0;
2243 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.vbar", 0.0, 0.0);
2244 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.hbar", 0.0, 0.0);
2245 if ((!sd->child_obj) && (!sd->extern_pan))
2247 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.vbar", 1.0, 1.0);
2248 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.hbar", 1.0, 1.0);
2250 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2251 sd->pan_func.get(sd->pan_obj, &px, &py);
2252 sd->pan_func.set(sd->pan_obj, minx, miny);
2253 if ((px != minx) || (py != miny))
2254 edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
2258 _smart_scrollbar_bar_v_visibility_adjust(Smart_Data *sd)
2260 int scroll_v_vis_change = 0;
2261 Evas_Coord h, vw, vh;
2264 evas_object_geometry_get(sd->pan_obj, NULL, NULL, &vw, &vh);
2265 if (sd->vbar_visible)
2267 if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_AUTO)
2269 if ((sd->child_obj) || (sd->extern_pan))
2273 scroll_v_vis_change = 1;
2274 sd->vbar_visible = 0;
2279 scroll_v_vis_change = 1;
2280 sd->vbar_visible = 0;
2283 else if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
2285 scroll_v_vis_change = 1;
2286 sd->vbar_visible = 0;
2291 if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_AUTO)
2293 if ((sd->child_obj) || (sd->extern_pan))
2297 scroll_v_vis_change = 1;
2298 sd->vbar_visible = 1;
2302 else if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
2304 scroll_v_vis_change = 1;
2305 sd->vbar_visible = 1;
2308 if (scroll_v_vis_change)
2310 if (sd->vbar_flags != ELM_SMART_SCROLLER_POLICY_OFF)
2312 if (sd->vbar_visible)
2313 edje_object_signal_emit(sd->edje_obj, "elm,action,show,vbar", "elm");
2315 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,vbar", "elm");
2316 edje_object_message_signal_process(sd->edje_obj);
2317 _smart_scrollbar_size_adjust(sd);
2320 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,vbar", "elm");
2322 return scroll_v_vis_change;
2326 _smart_scrollbar_bar_h_visibility_adjust(Smart_Data *sd)
2328 int scroll_h_vis_change = 0;
2329 Evas_Coord w, vw, vh;
2332 evas_object_geometry_get(sd->pan_obj, NULL, NULL, &vw, &vh);
2333 if (sd->hbar_visible)
2335 if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_AUTO)
2337 if ((sd->child_obj) || (sd->extern_pan))
2341 scroll_h_vis_change = 1;
2342 sd->hbar_visible = 0;
2347 scroll_h_vis_change = 1;
2348 sd->hbar_visible = 0;
2351 else if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
2353 scroll_h_vis_change = 1;
2354 sd->hbar_visible = 0;
2359 if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_AUTO)
2361 if ((sd->child_obj) || (sd->extern_pan))
2365 scroll_h_vis_change = 1;
2366 sd->hbar_visible = 1;
2370 else if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
2372 scroll_h_vis_change = 1;
2373 sd->hbar_visible = 1;
2376 if (scroll_h_vis_change)
2378 if (sd->hbar_flags != ELM_SMART_SCROLLER_POLICY_OFF)
2380 if (sd->hbar_visible)
2381 edje_object_signal_emit(sd->edje_obj, "elm,action,show,hbar", "elm");
2383 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,hbar", "elm");
2384 edje_object_message_signal_process(sd->edje_obj);
2385 _smart_scrollbar_size_adjust(sd);
2388 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,hbar", "elm");
2389 _smart_scrollbar_size_adjust(sd);
2391 return scroll_h_vis_change;
2395 _smart_scrollbar_bar_visibility_adjust(Smart_Data *sd)
2399 changed |= _smart_scrollbar_bar_h_visibility_adjust(sd);
2400 changed |= _smart_scrollbar_bar_v_visibility_adjust(sd);
2403 _smart_scrollbar_bar_h_visibility_adjust(sd);
2404 _smart_scrollbar_bar_v_visibility_adjust(sd);
2409 _smart_scrollbar_size_adjust(Smart_Data *sd)
2411 if ((sd->child_obj) || (sd->extern_pan))
2413 Evas_Coord x, y, w, h, mx = 0, my = 0, vw = 0, vh = 0, px, py, minx = 0, miny = 0;
2414 double vx, vy, size;
2416 edje_object_part_geometry_get(sd->edje_obj, "elm.swallow.content",
2417 NULL, NULL, &vw, &vh);
2420 size = (double)vw / (double)w;
2424 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.hbar", 0.0, 0.0);
2426 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.hbar", size, 1.0);
2430 size = (double)vh / (double)h;
2434 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.vbar", 0.0, 0.0);
2436 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.vbar", 1.0, size);
2438 edje_object_part_drag_value_get(sd->edje_obj, "elm.dragable.hbar", &vx, NULL);
2439 edje_object_part_drag_value_get(sd->edje_obj, "elm.dragable.vbar", NULL, &vy);
2440 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
2441 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2445 edje_object_part_drag_step_set(sd->edje_obj, "elm.dragable.hbar", (double)sd->step.x / (double)w, 0.0);
2446 edje_object_part_drag_step_set(sd->edje_obj, "elm.dragable.vbar", 0.0, (double)sd->step.y / (double)h);
2448 edje_object_part_drag_page_set(sd->edje_obj, "elm.dragable.hbar", (double)sd->page.x / (double)w, 0.0);
2450 edje_object_part_drag_page_set(sd->edje_obj, "elm.dragable.hbar", -((double)sd->page.x * ((double)vw / (double)w)) / 100.0, 0.0);
2452 edje_object_part_drag_page_set(sd->edje_obj, "elm.dragable.vbar", 0.0, (double)sd->page.y / (double)h);
2454 edje_object_part_drag_page_set(sd->edje_obj, "elm.dragable.vbar", 0.0, -((double)sd->page.y * ((double)vh / (double)h)) / 100.0);
2456 sd->pan_func.get(sd->pan_obj, &px, &py);
2457 if (vx != mx) x = px;
2458 if (vy != my) y = py;
2459 sd->pan_func.set(sd->pan_obj, x, y);
2460 // if ((px != 0) || (py != 0))
2461 // edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
2465 Evas_Coord px = 0, py = 0, minx = 0, miny = 0;
2467 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.vbar", 1.0, 1.0);
2468 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.hbar", 1.0, 1.0);
2469 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2470 sd->pan_func.get(sd->pan_obj, &px, &py);
2471 sd->pan_func.set(sd->pan_obj, minx, miny);
2472 if ((px != minx) || (py != miny))
2473 edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
2475 _smart_scrollbar_bar_visibility_adjust(sd);
2479 _smart_reconfigure(Smart_Data *sd)
2481 evas_object_move(sd->edje_obj, sd->x, sd->y);
2482 evas_object_resize(sd->edje_obj, sd->w, sd->h);
2483 evas_object_move(sd->event_obj, sd->x, sd->y);
2484 evas_object_resize(sd->event_obj, sd->w, sd->h);
2485 _smart_scrollbar_size_adjust(sd);
2489 _smart_add(Evas_Object *obj)
2494 sd = calloc(1, sizeof(Smart_Data));
2496 evas_object_smart_data_set(obj, sd);
2498 sd->smart_obj = obj;
2507 sd->hbar_flags = ELM_SMART_SCROLLER_POLICY_AUTO;
2508 sd->vbar_flags = ELM_SMART_SCROLLER_POLICY_AUTO;
2509 sd->hbar_visible = 1;
2510 sd->vbar_visible = 1;
2512 sd->bounce_horiz = 1;
2513 sd->bounce_vert = 1;
2515 sd->one_dir_at_a_time = 1;
2516 sd->momentum_animator_disabled = 0;
2517 sd->bounce_animator_disabled = 0;
2519 o = edje_object_add(evas_object_evas_get(obj));
2520 evas_object_propagate_events_set(o, 0);
2522 // FIXME: null parent obj ... :(
2523 elm_smart_scroller_object_theme_set(NULL, obj, "scroller", "base", "default");
2524 edje_object_signal_callback_add(o, "drag", "elm.dragable.vbar", _smart_edje_drag_v, sd);
2525 edje_object_signal_callback_add(o, "drag,start", "elm.dragable.vbar", _smart_edje_drag_v_start, sd);
2526 edje_object_signal_callback_add(o, "drag,stop", "elm.dragable.vbar", _smart_edje_drag_v_stop, sd);
2527 edje_object_signal_callback_add(o, "drag,step", "elm.dragable.vbar", _smart_edje_drag_v, sd);
2528 edje_object_signal_callback_add(o, "drag,page", "elm.dragable.vbar", _smart_edje_drag_v, sd);
2529 edje_object_signal_callback_add(o, "drag", "elm.dragable.hbar", _smart_edje_drag_h, sd);
2530 edje_object_signal_callback_add(o, "drag,start", "elm.dragable.hbar", _smart_edje_drag_h_start, sd);
2531 edje_object_signal_callback_add(o, "drag,stop", "elm.dragable.hbar", _smart_edje_drag_h_stop, sd);
2532 edje_object_signal_callback_add(o, "drag,step", "elm.dragable.hbar", _smart_edje_drag_h, sd);
2533 edje_object_signal_callback_add(o, "drag,page", "elm.dragable.hbar", _smart_edje_drag_h, sd);
2534 evas_object_smart_member_add(o, obj);
2536 o = evas_object_rectangle_add(evas_object_evas_get(obj));
2538 evas_object_color_set(o, 0, 0, 0, 0);
2539 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_WHEEL, _smart_event_wheel, sd);
2540 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, _smart_event_mouse_down, sd);
2541 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_UP, _smart_event_mouse_up, sd);
2542 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_MOVE, _smart_event_mouse_move, sd);
2543 evas_object_smart_member_add(o, obj);
2544 evas_object_repeat_events_set(o, 1);
2546 sd->pan_func.set = _elm_smart_pan_set;
2547 sd->pan_func.get = _elm_smart_pan_get;
2548 sd->pan_func.max_get = _elm_smart_pan_max_get;
2549 sd->pan_func.min_get = _elm_smart_pan_min_get;
2550 sd->pan_func.child_size_get = _elm_smart_pan_child_size_get;
2552 _smart_scrollbar_reset(sd);
2556 _smart_del(Evas_Object *obj)
2559 elm_smart_scroller_child_set(obj, NULL);
2560 if (!sd->extern_pan) evas_object_del(sd->pan_obj);
2561 evas_object_del(sd->edje_obj);
2562 evas_object_del(sd->event_obj);
2563 if (sd->down.hold_animator) ecore_animator_del(sd->down.hold_animator);
2564 if (sd->down.onhold_animator) ecore_animator_del(sd->down.onhold_animator);
2565 if (sd->down.momentum_animator) ecore_animator_del(sd->down.momentum_animator);
2566 if (sd->down.bounce_x_animator) ecore_animator_del(sd->down.bounce_x_animator);
2567 if (sd->down.bounce_y_animator) ecore_animator_del(sd->down.bounce_y_animator);
2568 if (sd->scrollto.x.animator) ecore_animator_del(sd->scrollto.x.animator);
2569 if (sd->scrollto.y.animator) ecore_animator_del(sd->scrollto.y.animator);
2571 evas_object_smart_data_set(obj, NULL);
2575 _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
2580 _smart_reconfigure(sd);
2584 _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
2587 Evas_Coord ww, wh, wx = sd->wx;
2590 _smart_reconfigure(sd);
2592 /* Flip to RTL cords only if init in RTL mode */
2594 wx = _elm_smart_scroller_x_mirrored_get(obj, sd->wx);
2598 elm_smart_scroller_child_viewport_size_get(obj, &ww, &wh);
2606 elm_smart_scroller_child_region_set(obj, wx, sd->wy, ww, wh);
2610 _smart_show(Evas_Object *obj)
2613 evas_object_show(sd->edje_obj);
2614 evas_object_show(sd->event_obj);
2618 _smart_hide(Evas_Object *obj)
2621 evas_object_hide(sd->edje_obj);
2622 evas_object_hide(sd->event_obj);
2626 _smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
2629 evas_object_color_set(sd->edje_obj, r, g, b, a);
2633 _smart_clip_set(Evas_Object *obj, Evas_Object *clip)
2636 evas_object_clip_set(sd->edje_obj, clip);
2637 evas_object_clip_set(sd->event_obj, clip);
2641 _smart_clip_unset(Evas_Object *obj)
2644 evas_object_clip_unset(sd->edje_obj);
2645 evas_object_clip_unset(sd->event_obj);
2648 /* never need to touch this */
2655 static const Evas_Smart_Class sc =
2658 EVAS_SMART_CLASS_VERSION,
2676 _smart = evas_smart_class_new(&sc);