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)
171 Evas_Coord px, py, wx;
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->y);
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;
359 _smart_anim_start(Evas_Object *obj)
361 evas_object_smart_callback_call(obj, "animate,start", NULL);
365 _smart_anim_stop(Evas_Object *obj)
367 evas_object_smart_callback_call(obj, "animate,stop", NULL);
371 _smart_drag_start(Evas_Object *obj)
373 evas_object_smart_callback_call(obj, "drag,start", NULL);
377 _smart_drag_stop(Evas_Object *obj)
379 evas_object_smart_callback_call(obj, "drag,stop", NULL);
383 _smart_scrollto_x_animator(void *data)
385 Smart_Data *sd = data;
389 t = ecore_loop_time_get();
390 tt = (t - sd->scrollto.x.t_start) / (sd->scrollto.x.t_end - sd->scrollto.x.t_start);
392 tt = 1.0 - (tt * tt);
393 sd->pan_func.get(sd->pan_obj, &px, &py);
394 px = (sd->scrollto.x.start * (1.0 - tt)) +
395 (sd->scrollto.x.end * tt);
396 if (t >= sd->scrollto.x.t_end)
398 px = sd->scrollto.x.end;
399 elm_smart_scroller_child_pos_set(sd->smart_obj, px, py);
400 sd->scrollto.x.animator = NULL;
401 if ((!sd->scrollto.y.animator) && (!sd->down.bounce_y_animator))
402 _smart_anim_stop(sd->smart_obj);
403 return ECORE_CALLBACK_CANCEL;
405 elm_smart_scroller_child_pos_set(sd->smart_obj, px, py);
406 return ECORE_CALLBACK_RENEW;
410 _smart_momentum_end(Smart_Data *sd)
412 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator)) return;
413 if (sd->down.momentum_animator)
415 ecore_animator_del(sd->down.momentum_animator);
416 sd->down.momentum_animator = NULL;
417 sd->down.bounce_x_hold = 0;
418 sd->down.bounce_y_hold = 0;
427 _smart_scrollto_x(Smart_Data *sd, double t_in, Evas_Coord pos_x)
429 Evas_Coord px, py, x, y, w, h;
432 if (sd->freeze) return;
435 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
436 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
438 elm_smart_scroller_child_region_set(sd->smart_obj, x, y, w, h);
441 t = ecore_loop_time_get();
442 sd->pan_func.get(sd->pan_obj, &px, &py);
443 sd->scrollto.x.start = px;
444 sd->scrollto.x.end = pos_x;
445 sd->scrollto.x.t_start = t;
446 sd->scrollto.x.t_end = t + t_in;
447 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
448 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
449 elm_smart_scroller_child_region_set(sd->smart_obj, x, y, w, h);
450 if (!sd->scrollto.x.animator)
452 if (!sd->scrollto.y.animator)
453 _smart_anim_start(sd->smart_obj);
454 sd->scrollto.x.animator = ecore_animator_add(_smart_scrollto_x_animator, sd);
456 if (sd->down.bounce_x_animator)
458 ecore_animator_del(sd->down.bounce_x_animator);
459 sd->down.bounce_x_animator = NULL;
460 _smart_momentum_end(sd);
466 _smart_scrollto_y_animator(void *data)
468 Smart_Data *sd = data;
472 t = ecore_loop_time_get();
473 tt = (t - sd->scrollto.y.t_start) / (sd->scrollto.y.t_end - sd->scrollto.y.t_start);
475 tt = 1.0 - (tt * tt);
476 sd->pan_func.get(sd->pan_obj, &px, &py);
477 py = (sd->scrollto.y.start * (1.0 - tt)) +
478 (sd->scrollto.y.end * tt);
479 if (t >= sd->scrollto.y.t_end)
481 py = sd->scrollto.y.end;
482 elm_smart_scroller_child_pos_set(sd->smart_obj, px, py);
483 sd->scrollto.y.animator = NULL;
484 if ((!sd->scrollto.x.animator) && (!sd->down.bounce_x_animator))
485 _smart_anim_stop(sd->smart_obj);
486 return ECORE_CALLBACK_CANCEL;
488 elm_smart_scroller_child_pos_set(sd->smart_obj, px, py);
490 return ECORE_CALLBACK_RENEW;
494 _smart_scrollto_y(Smart_Data *sd, double t_in, Evas_Coord pos_y)
496 Evas_Coord px, py, x, y, w, h;
499 if (sd->freeze) return;
502 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
503 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
505 elm_smart_scroller_child_region_set(sd->smart_obj, x, y, w, h);
508 t = ecore_loop_time_get();
509 sd->pan_func.get(sd->pan_obj, &px, &py);
510 sd->scrollto.y.start = py;
511 sd->scrollto.y.end = pos_y;
512 sd->scrollto.y.t_start = t;
513 sd->scrollto.y.t_end = t + t_in;
514 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
515 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
516 elm_smart_scroller_child_region_set(sd->smart_obj, x, y, w, h);
517 if (!sd->scrollto.y.animator)
519 if (!sd->scrollto.x.animator)
520 _smart_anim_start(sd->smart_obj);
521 sd->scrollto.y.animator = ecore_animator_add(_smart_scrollto_y_animator, sd);
523 if (sd->down.bounce_y_animator)
525 ecore_animator_del(sd->down.bounce_y_animator);
526 sd->down.bounce_y_animator = NULL;
527 _smart_momentum_end(sd);
533 _smart_do_page(Smart_Data *sd)
535 if ((sd->pagerel_h == 0.0) && (!sd->pagesize_h) &&
536 (sd->pagerel_v == 0.0) && (!sd->pagesize_v))
542 _smart_page_x_get(Smart_Data *sd, int offset)
544 Evas_Coord x, y, w, h, cw, ch, minx = 0;
546 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
547 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
548 sd->pan_func.child_size_get(sd->pan_obj, &cw, &ch);
549 sd->pan_func.min_get(sd->pan_obj, &minx, NULL);
553 if (sd->pagerel_h > 0.0)
555 x = x + (w * sd->pagerel_h * 0.5);
556 x = x / (w * sd->pagerel_h);
557 x = x * (w * sd->pagerel_h);
559 else if (sd->pagesize_h > 0)
561 x = x + (sd->pagesize_h * 0.5);
562 x = x / (sd->pagesize_h);
563 x = x * (sd->pagesize_h);
565 if (x < minx) x = minx;
566 else if ((x + w) > cw) x = cw - w;
571 _smart_page_y_get(Smart_Data *sd, int offset)
573 Evas_Coord x, y, w, h, cw, ch, miny = 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, NULL, &miny);
582 if (sd->pagerel_v > 0.0)
584 y = y + (h * sd->pagerel_v * 0.5);
585 y = y / (h * sd->pagerel_v);
586 y = y * (h * sd->pagerel_v);
588 else if (sd->pagesize_v > 0)
590 y = y + (sd->pagesize_v * 0.5);
591 y = y / (sd->pagesize_v);
592 y = y * (sd->pagesize_v);
594 if (y < miny) y = miny;
595 else if ((y + h) > ch) y = ch - h;
600 _smart_page_adjust(Smart_Data *sd)
602 Evas_Coord x, y, w, h;
604 if (!_smart_do_page(sd)) return;
606 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
608 x = _smart_page_x_get(sd, 0);
609 y = _smart_page_y_get(sd, 0);
611 elm_smart_scroller_child_region_set(sd->smart_obj, x, y, w, h);
615 _smart_bounce_x_animator(void *data)
622 t = ecore_loop_time_get();
623 dt = t - sd->down.anim_start2;
626 dt = dt / _elm_config->thumbscroll_bounce_friction;
627 if (dt > 1.0) dt = 1.0;
628 p = 1.0 - ((1.0 - dt) * (1.0 - dt));
629 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
630 dx = sd->down.b2x - sd->down.bx;
632 x = sd->down.bx + dx;
633 if (!sd->down.cancelled)
634 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
637 if (sd->down.momentum_animator)
638 sd->down.bounce_x_hold = 1;
639 else if ((!sd->down.bounce_y_animator) &&
640 (!sd->scrollto.y.animator))
641 _smart_anim_stop(sd->smart_obj);
642 sd->down.bounce_x_animator = NULL;
645 _smart_momentum_end(sd);
646 return ECORE_CALLBACK_CANCEL;
649 return ECORE_CALLBACK_RENEW;
653 _smart_bounce_y_animator(void *data)
660 t = ecore_loop_time_get();
661 dt = t - sd->down.anim_start3;
664 dt = dt / _elm_config->thumbscroll_bounce_friction;
665 if (dt > 1.0) dt = 1.0;
666 p = 1.0 - ((1.0 - dt) * (1.0 - dt));
667 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
668 dy = sd->down.b2y - sd->down.by;
670 y = sd->down.by + dy;
671 if (!sd->down.cancelled)
672 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
675 if (sd->down.momentum_animator)
676 sd->down.bounce_y_hold = 1;
677 else if ((!sd->down.bounce_x_animator) &&
678 (!sd->scrollto.y.animator))
679 _smart_anim_stop(sd->smart_obj);
680 sd->down.bounce_y_animator = NULL;
683 _smart_momentum_end(sd);
684 return ECORE_CALLBACK_CANCEL;
687 return ECORE_CALLBACK_RENEW;
695 can_scroll(Smart_Data *sd, int dir)
697 Evas_Coord mx = 0, my = 0, px = 0, py = 0, minx = 0, miny = 0;
699 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
700 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
701 sd->pan_func.get(sd->pan_obj, &px, &py);
705 if (px > minx) return EINA_TRUE;
708 if ((px - minx) < mx) return EINA_TRUE;
711 if (py > miny) return EINA_TRUE;
714 if ((py - miny) < my) return EINA_TRUE;
723 _smart_momentum_animator(void *data)
727 Evas_Coord x, y, dx, dy, px, py, maxx, maxy, minx, miny;
728 Eina_Bool no_bounce_x_end = EINA_FALSE, no_bounce_y_end = EINA_FALSE;
731 t = ecore_loop_time_get();
732 dt = t - sd->down.anim_start;
736 if (sd->down.hold_parent)
738 if ((sd->down.dir_x) && !can_scroll(sd, sd->down.hdir))
742 if ((sd->down.dir_y) && !can_scroll(sd, sd->down.vdir))
747 if ((!sd->down.dir_x) && (!sd->down.dir_y))
749 sd->down.cancelled = 1;
752 dt = dt / (_elm_config->thumbscroll_friction + sd->down.extra_time);
753 if (dt > 1.0) dt = 1.0;
754 p = 1.0 - ((1.0 - dt) * (1.0 - dt));
755 dx = (sd->down.dx * (_elm_config->thumbscroll_friction + sd->down.extra_time) * p);
756 dy = (sd->down.dy * (_elm_config->thumbscroll_friction + sd->down.extra_time) * p);
759 x = sd->down.sx - dx;
760 y = sd->down.sy - dy;
761 elm_smart_scroller_child_pos_get(sd->smart_obj, &px, &py);
762 if ((sd->down.bounce_x_animator) ||
763 (sd->down.bounce_x_hold))
765 sd->down.bx = sd->down.bx0 - dx + sd->down.b0x;
768 if ((sd->down.bounce_y_animator) ||
769 (sd->down.bounce_y_hold))
771 sd->down.by = sd->down.by0 - dy + sd->down.b0y;
774 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
775 sd->pan_func.max_get(sd->pan_obj, &maxx, &maxy);
776 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
777 if (!sd->bounce_horiz)
779 if (x <= minx) no_bounce_x_end = EINA_TRUE;
780 if ((x - minx) >= maxx) no_bounce_x_end = EINA_TRUE;
782 if (!sd->bounce_vert)
784 if (y <= miny) no_bounce_y_end = EINA_TRUE;
785 if ((y - miny) >= maxy) no_bounce_y_end = EINA_TRUE;
788 ((sd->down.bounce_x_hold) && (sd->down.bounce_y_hold)) ||
789 (no_bounce_x_end && no_bounce_y_end))
791 _smart_anim_stop(sd->smart_obj);
792 sd->down.momentum_animator = NULL;
793 sd->down.bounce_x_hold = 0;
794 sd->down.bounce_y_hold = 0;
799 return ECORE_CALLBACK_CANCEL;
802 return ECORE_CALLBACK_RENEW;
806 bounce_eval(Smart_Data *sd)
808 Evas_Coord mx, my, px, py, bx, by, b2x, b2y, minx = 0, miny = 0;
810 if (sd->freeze) return;
811 if ((!sd->bouncemex) && (!sd->bouncemey)) return;
812 if (sd->down.now) return; // down bounce while still held down
813 if (sd->down.onhold_animator)
815 ecore_animator_del(sd->down.onhold_animator);
816 sd->down.onhold_animator = NULL;
818 if (sd->down.hold_animator)
820 ecore_animator_del(sd->down.hold_animator);
821 sd->down.hold_animator = NULL;
823 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
824 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
825 sd->pan_func.get(sd->pan_obj, &px, &py);
828 if (px < minx) px = minx;
829 if ((px - minx) > mx) px = mx + minx;
830 if (py < miny) py = miny;
831 if ((py - miny) > my) py = my + miny;
835 (!elm_widget_drag_child_locked_x_get(sd->widget)))
837 if (!sd->down.bounce_x_animator && !sd->bounce_animator_disabled)
841 if (sd->scrollto.x.animator)
843 ecore_animator_del(sd->scrollto.x.animator);
844 sd->scrollto.x.animator = NULL;
846 sd->down.bounce_x_animator = ecore_animator_add(_smart_bounce_x_animator, sd);
847 sd->down.anim_start2 = ecore_loop_time_get();
851 if (sd->down.momentum_animator) sd->down.b0x = sd->down.ax;
852 else sd->down.b0x = 0;
857 (!elm_widget_drag_child_locked_y_get(sd->widget)))
859 if (!sd->down.bounce_y_animator && !sd->bounce_animator_disabled)
863 if (sd->scrollto.y.animator)
865 ecore_animator_del(sd->scrollto.y.animator);
866 sd->scrollto.y.animator = NULL;
868 sd->down.bounce_y_animator = ecore_animator_add(_smart_bounce_y_animator, sd);
869 sd->down.anim_start3 = ecore_loop_time_get();
873 if (sd->down.momentum_animator) sd->down.b0y = sd->down.ay;
874 else sd->down.b0y = 0;
881 elm_smart_scroller_child_pos_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
883 Evas_Coord mx = 0, my = 0, px, py, minx = 0, miny = 0;
887 // FIXME: allow for bounce outside of range
888 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
889 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
890 if (mx > 0) vx = (double)(x - minx) / (double)mx;
892 if (vx < 0.0) vx = 0.0;
893 else if (vx > 1.0) vx = 1.0;
894 if (my > 0) vy = (double)(y - miny) / (double)my;
896 if (vy < 0.0) vy = 0.0;
897 else if (vy > 1.0) vy = 1.0;
898 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.vbar", 0.0, vy);
899 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.hbar", vx, 0.0);
900 sd->pan_func.get(sd->pan_obj, &px, &py);
901 if (!_elm_config->thumbscroll_bounce_enable)
903 if (x < minx) x = minx;
904 if ((x - minx) > mx) x = mx + minx;
905 if (y < miny) y = miny;
906 if ((y - miny) > my) y = my + miny;
909 if (!sd->bounce_horiz)
911 if (x < minx) x = minx;
912 if ((x - minx) > mx) x = mx + minx;
914 if (!sd->bounce_vert)
916 if (y < miny) y = miny;
917 if (y - miny > my) y = my + miny;
920 sd->pan_func.set(sd->pan_obj, x, y);
921 if ((px != x) || (py != y))
922 edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
923 if (!sd->down.bounce_x_animator)
925 if ((x < minx) || (x > (mx + minx)))
931 if (!sd->down.bounce_y_animator)
933 if ((y < miny) || (y > my + miny))
939 if ((x != px) || (y != py))
941 evas_object_smart_callback_call(obj, "scroll", NULL);
943 if ((x != px)/* && (!sd->bouncemex)*/)
946 evas_object_smart_callback_call(obj, "edge,left", NULL);
947 if (x == (mx + minx))
948 evas_object_smart_callback_call(obj, "edge,right", NULL);
950 if ((y != py)/* && (!sd->bouncemey)*/)
953 evas_object_smart_callback_call(obj, "edge,top", NULL);
955 evas_object_smart_callback_call(obj, "edge,bottom", NULL);
960 elm_smart_scroller_child_pos_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
963 sd->pan_func.get(sd->pan_obj, x, y);
966 /* "internal_call" actually toggles whether we should save the coords and do
967 * extra "speedup" checks, or not. */
969 _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)
971 Evas_Coord mx = 0, my = 0, cw = 0, ch = 0, px = 0, py = 0, nx, ny, minx = 0, miny = 0;
974 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
975 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
976 sd->pan_func.child_size_get(sd->pan_obj, &cw, &ch);
977 sd->pan_func.get(sd->pan_obj, &px, &py);
980 if ((x < px) && ((x + w) < (px + (cw - mx)))) nx = x;
981 else if ((x > px) && ((x + w) > (px + (cw - mx)))) nx = x + w - (cw - mx);
983 if ((y < py) && ((y + h) < (py + (ch - my)))) ny = y;
984 else if ((y > py) && ((y + h) > (py + (ch - my)))) ny = y + h - (ch - my);
991 if ((nx == px) && (ny == py)) return;
994 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
995 (sd->scrollto.x.animator) || (sd->scrollto.y.animator))
997 _smart_anim_stop(sd->smart_obj);
999 if (sd->scrollto.x.animator)
1001 ecore_animator_del(sd->scrollto.x.animator);
1002 sd->scrollto.x.animator = NULL;
1004 if (sd->scrollto.y.animator)
1006 ecore_animator_del(sd->scrollto.y.animator);
1007 sd->scrollto.y.animator = NULL;
1009 if (sd->down.bounce_x_animator)
1011 ecore_animator_del(sd->down.bounce_x_animator);
1012 sd->down.bounce_x_animator = NULL;
1015 if (sd->down.bounce_y_animator)
1017 ecore_animator_del(sd->down.bounce_y_animator);
1018 sd->down.bounce_y_animator = NULL;
1021 if (sd->down.hold_animator)
1023 ecore_animator_del(sd->down.hold_animator);
1024 sd->down.hold_animator = NULL;
1025 _smart_drag_stop(sd->smart_obj);
1027 if (sd->down.momentum_animator)
1029 ecore_animator_del(sd->down.momentum_animator);
1030 sd->down.momentum_animator = NULL;
1031 sd->down.bounce_x_hold = 0;
1032 sd->down.bounce_y_hold = 0;
1038 elm_smart_scroller_child_pos_set(obj, nx, ny);
1041 /* Set should be used for calculated positions, for example, when we move
1042 * because of an animation or because this is the correct position after
1045 elm_smart_scroller_child_region_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
1047 _elm_smart_scroller_child_region_show_internal(obj, x, y, w, h, EINA_TRUE);
1050 /* Set should be used for setting the wanted position, for example a user scroll
1051 * or moving the cursor in an entry. */
1053 elm_smart_scroller_child_region_show(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
1055 _elm_smart_scroller_child_region_show_internal(obj, x, y, w, h, EINA_FALSE);
1059 elm_smart_scroller_child_viewport_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
1062 edje_object_calc_force(sd->edje_obj);
1063 evas_object_geometry_get(sd->pan_obj, NULL, NULL, w, h);
1067 elm_smart_scroller_step_size_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
1074 _smart_scrollbar_size_adjust(sd);
1078 elm_smart_scroller_step_size_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
1081 if (x) *x = sd->step.x;
1082 if (y) *y = sd->step.y;
1086 elm_smart_scroller_page_size_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
1091 _smart_scrollbar_size_adjust(sd);
1095 elm_smart_scroller_page_size_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
1098 if (x) *x = sd->page.x;
1099 if (y) *y = sd->page.y;
1103 elm_smart_scroller_policy_set(Evas_Object *obj, Elm_Smart_Scroller_Policy hbar, Elm_Smart_Scroller_Policy vbar)
1106 if ((sd->hbar_flags == hbar) && (sd->vbar_flags == vbar)) return;
1107 sd->hbar_flags = hbar;
1108 sd->vbar_flags = vbar;
1109 if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
1110 edje_object_signal_emit(sd->edje_obj, "elm,action,show_always,hbar", "elm");
1111 else if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
1112 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,hbar", "elm");
1114 edje_object_signal_emit(sd->edje_obj, "elm,action,show_notalways,hbar", "elm");
1115 if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
1116 edje_object_signal_emit(sd->edje_obj, "elm,action,show_always,vbar", "elm");
1117 else if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
1118 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,vbar", "elm");
1120 edje_object_signal_emit(sd->edje_obj, "elm,action,show_notalways,vbar", "elm");
1121 _smart_scrollbar_size_adjust(sd);
1125 elm_smart_scroller_policy_get(Evas_Object *obj, Elm_Smart_Scroller_Policy *hbar, Elm_Smart_Scroller_Policy *vbar)
1128 if (hbar) *hbar = sd->hbar_flags;
1129 if (vbar) *vbar = sd->vbar_flags;
1133 elm_smart_scroller_edje_object_get(Evas_Object *obj)
1135 API_ENTRY return NULL;
1136 return sd->edje_obj;
1140 elm_smart_scroller_single_dir_set(Evas_Object *obj, Eina_Bool single_dir)
1143 sd->one_dir_at_a_time = single_dir;
1147 elm_smart_scroller_single_dir_get(Evas_Object *obj)
1149 API_ENTRY return EINA_FALSE;
1150 return sd->one_dir_at_a_time;
1154 elm_smart_scroller_object_theme_set(Evas_Object *parent, Evas_Object *obj, const char *clas, const char *group, const char *style)
1158 _elm_theme_object_set(parent, sd->edje_obj, clas, group, style);
1159 edje_object_scale_set(sd->edje_obj, elm_widget_scale_get(parent) * _elm_config->scale);
1161 edje_object_part_swallow(sd->edje_obj, "elm.swallow.content", sd->pan_obj);
1163 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1164 if (edje_object_part_exists(sd->edje_obj, "elm.scrollbar.base"))
1167 base = edje_object_part_swallow_get(sd->edje_obj, "elm.scrollbar.base");
1170 base = evas_object_rectangle_add(evas_object_evas_get(sd->edje_obj));
1171 evas_object_color_set(base, 0, 0, 0, 0);
1172 edje_object_part_swallow(sd->edje_obj, "elm.scrollbar.base", base);
1174 if (!_elm_config->thumbscroll_enable)
1175 evas_object_size_hint_min_set(base, mw, mh);
1177 sd->vbar_visible = !sd->vbar_visible;
1178 sd->hbar_visible = !sd->hbar_visible;
1179 _smart_scrollbar_bar_visibility_adjust(sd);
1183 elm_smart_scroller_hold_set(Evas_Object *obj, Eina_Bool hold)
1190 elm_smart_scroller_freeze_set(Evas_Object *obj, Eina_Bool freeze)
1193 sd->freeze = freeze;
1196 if (sd->down.onhold_animator)
1198 ecore_animator_del(sd->down.onhold_animator);
1199 sd->down.onhold_animator = NULL;
1205 elm_smart_scroller_bounce_allow_set(Evas_Object *obj, Eina_Bool horiz, Eina_Bool vert)
1208 sd->bounce_horiz = horiz;
1209 sd->bounce_vert = vert;
1213 elm_smart_scroller_bounce_allow_get(const Evas_Object *obj, Eina_Bool *horiz, Eina_Bool *vert)
1216 *horiz = sd->bounce_horiz;
1217 *vert = sd->bounce_vert;
1221 elm_smart_scroller_paging_set(Evas_Object *obj, double pagerel_h, double pagerel_v, Evas_Coord pagesize_h, Evas_Coord pagesize_v)
1224 sd->pagerel_h = pagerel_h;
1225 sd->pagerel_v = pagerel_v;
1226 sd->pagesize_h = pagesize_h;
1227 sd->pagesize_v = pagesize_v;
1228 _smart_page_adjust(sd);
1232 elm_smart_scroller_paging_get(Evas_Object *obj, double *pagerel_h, double *pagerel_v, Evas_Coord *pagesize_h, Evas_Coord *pagesize_v)
1235 if(pagerel_h) *pagerel_h = sd->pagerel_h;
1236 if(pagerel_v) *pagerel_v = sd->pagerel_v;
1237 if(pagesize_h) *pagesize_h = sd->pagesize_h;
1238 if(pagesize_v) *pagesize_v = sd->pagesize_v;
1242 elm_smart_scroller_region_bring_in(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
1244 Evas_Coord mx = 0, my = 0, cw = 0, ch = 0, px = 0, py = 0, nx, ny, minx = 0, miny = 0;
1247 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
1248 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
1249 sd->pan_func.child_size_get(sd->pan_obj, &cw, &ch);
1250 sd->pan_func.get(sd->pan_obj, &px, &py);
1253 if ((x < px) && ((x + w) < (px + (cw - mx)))) nx = x;
1254 else if ((x > px) && ((x + w) > (px + (cw - mx)))) nx = x + w - (cw - mx);
1256 if ((y < py) && ((y + h) < (py + (ch - my)))) ny = y;
1257 else if ((y > py) && ((y + h) > (py + (ch - my)))) ny = y + h - (ch - my);
1258 if ((nx == px) && (ny == py)) return;
1259 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1260 (sd->scrollto.x.animator) || (sd->scrollto.y.animator))
1262 _smart_anim_stop(sd->smart_obj);
1264 if (sd->scrollto.x.animator)
1266 ecore_animator_del(sd->scrollto.x.animator);
1267 sd->scrollto.x.animator = NULL;
1269 if (sd->scrollto.y.animator)
1271 ecore_animator_del(sd->scrollto.y.animator);
1272 sd->scrollto.y.animator = NULL;
1274 if (sd->down.bounce_x_animator)
1276 ecore_animator_del(sd->down.bounce_x_animator);
1277 sd->down.bounce_x_animator = NULL;
1280 if (sd->down.bounce_y_animator)
1282 ecore_animator_del(sd->down.bounce_y_animator);
1283 sd->down.bounce_y_animator = NULL;
1286 if (sd->down.hold_animator)
1288 ecore_animator_del(sd->down.hold_animator);
1289 sd->down.hold_animator = NULL;
1290 _smart_drag_stop(sd->smart_obj);
1292 if (sd->down.momentum_animator)
1294 ecore_animator_del(sd->down.momentum_animator);
1295 sd->down.momentum_animator = NULL;
1296 sd->down.bounce_x_hold = 0;
1297 sd->down.bounce_y_hold = 0;
1304 if (x < minx) x = minx;
1305 else if ((x + w) > cw) x = cw - w;
1306 _smart_scrollto_x(sd, _elm_config->bring_in_scroll_friction, x);
1308 if (y < miny) y = miny;
1309 else if ((y + h) > ch) y = ch - h;
1310 _smart_scrollto_y(sd, _elm_config->bring_in_scroll_friction, y);
1314 elm_smart_scroller_widget_set(Evas_Object *obj, Evas_Object *wid)
1320 /* local subsystem functions */
1322 _smart_edje_drag_v_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1327 _smart_scrollbar_read(sd);
1328 _smart_drag_start(sd->smart_obj);
1332 _smart_edje_drag_v_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1337 _smart_scrollbar_read(sd);
1338 _smart_drag_stop(sd->smart_obj);
1342 _smart_edje_drag_v(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1347 _smart_scrollbar_read(sd);
1351 _smart_edje_drag_h_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1356 _smart_scrollbar_read(sd);
1357 _smart_drag_start(sd->smart_obj);
1361 _smart_edje_drag_h_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1366 _smart_scrollbar_read(sd);
1367 _smart_drag_stop(sd->smart_obj);
1371 _smart_edje_drag_h(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1376 _smart_scrollbar_read(sd);
1380 _smart_child_del_hook(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1385 sd->child_obj = NULL;
1386 _smart_scrollbar_size_adjust(sd);
1387 _smart_scrollbar_reset(sd);
1391 _smart_pan_changed_hook(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1398 sd->pan_func.get(sd->pan_obj, &x, &y);
1399 sd->pan_func.child_size_get(sd->pan_obj, &w, &h);
1400 if ((w != sd->child.w) || (h != sd->child.h))
1404 _smart_scrollbar_size_adjust(sd);
1405 evas_object_size_hint_min_set(sd->smart_obj, sd->child.w, sd->child.h);
1406 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
1411 _smart_pan_pan_changed_hook(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1417 sd->pan_func.get(sd->pan_obj, &x, &y);
1418 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1419 (sd->scrollto.x.animator) || (sd->scrollto.y.animator))
1421 _smart_anim_stop(sd->smart_obj);
1423 if (sd->scrollto.x.animator)
1425 ecore_animator_del(sd->scrollto.x.animator);
1426 sd->scrollto.x.animator = NULL;
1428 if (sd->scrollto.y.animator)
1430 ecore_animator_del(sd->scrollto.y.animator);
1431 sd->scrollto.y.animator = NULL;
1433 if (sd->down.bounce_x_animator)
1435 ecore_animator_del(sd->down.bounce_x_animator);
1436 sd->down.bounce_x_animator = NULL;
1439 if (sd->down.bounce_y_animator)
1441 ecore_animator_del(sd->down.bounce_y_animator);
1442 sd->down.bounce_y_animator = NULL;
1445 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
1449 _smart_event_wheel(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1451 Evas_Event_Mouse_Wheel *ev;
1453 Evas_Coord x = 0, y = 0;
1457 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
1458 if ((evas_key_modifier_is_set(ev->modifiers, "Control")) ||
1459 (evas_key_modifier_is_set(ev->modifiers, "Alt")) ||
1460 (evas_key_modifier_is_set(ev->modifiers, "Shift")) ||
1461 (evas_key_modifier_is_set(ev->modifiers, "Meta")) ||
1462 (evas_key_modifier_is_set(ev->modifiers, "Hyper")) ||
1463 (evas_key_modifier_is_set(ev->modifiers, "Super")))
1465 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1466 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1467 (sd->scrollto.x.animator) || (sd->scrollto.y.animator))
1469 _smart_anim_stop(sd->smart_obj);
1471 if (sd->scrollto.x.animator)
1473 ecore_animator_del(sd->scrollto.x.animator);
1474 sd->scrollto.x.animator = NULL;
1476 if (sd->scrollto.y.animator)
1478 ecore_animator_del(sd->scrollto.y.animator);
1479 sd->scrollto.y.animator = NULL;
1481 if (sd->down.bounce_x_animator)
1483 ecore_animator_del(sd->down.bounce_x_animator);
1484 sd->down.bounce_x_animator = NULL;
1487 if (sd->down.bounce_y_animator)
1489 ecore_animator_del(sd->down.bounce_y_animator);
1490 sd->down.bounce_y_animator = NULL;
1494 y += ev->z * sd->step.y;
1495 else if (ev->direction == 1)
1496 x += ev->z * sd->step.x;
1498 if ((!sd->hold) && (!sd->freeze))
1502 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &sd->ww, &sd->wh);
1503 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
1508 _smart_event_mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1510 Evas_Event_Mouse_Down *ev;
1512 Evas_Coord x = 0, y = 0;
1516 // if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
1517 if (_elm_config->thumbscroll_enable)
1520 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1521 (sd->down.momentum_animator) || (sd->scrollto.x.animator) ||
1522 (sd->scrollto.y.animator))
1524 ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL | EVAS_EVENT_FLAG_ON_HOLD;
1525 sd->down.scroll = 1;
1527 _smart_anim_stop(sd->smart_obj);
1529 if (sd->scrollto.x.animator)
1531 ecore_animator_del(sd->scrollto.x.animator);
1532 sd->scrollto.x.animator = NULL;
1534 if (sd->scrollto.y.animator)
1536 ecore_animator_del(sd->scrollto.y.animator);
1537 sd->scrollto.y.animator = NULL;
1539 if (sd->down.bounce_x_animator)
1541 ecore_animator_del(sd->down.bounce_x_animator);
1542 sd->down.bounce_x_animator = NULL;
1545 if (sd->down.bounce_y_animator)
1547 ecore_animator_del(sd->down.bounce_y_animator);
1548 sd->down.bounce_y_animator = NULL;
1551 if (sd->down.hold_animator)
1553 ecore_animator_del(sd->down.hold_animator);
1554 sd->down.hold_animator = NULL;
1555 _smart_drag_stop(sd->smart_obj);
1557 if (sd->down.momentum_animator)
1559 ecore_animator_del(sd->down.momentum_animator);
1560 sd->down.momentum_animator = NULL;
1561 sd->down.bounce_x_hold = 0;
1562 sd->down.bounce_y_hold = 0;
1566 if (ev->button == 1)
1569 sd->down.dragged = 0;
1572 sd->down.x = ev->canvas.x;
1573 sd->down.y = ev->canvas.y;
1574 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1577 sd->down.locked = 0;
1578 memset(&(sd->down.history[0]), 0, sizeof(sd->down.history[0]) * 20);
1580 sd->down.history[0].timestamp = ev->timestamp / 1000.0;
1582 sd->down.history[0].timestamp = ecore_loop_time_get();
1584 sd->down.history[0].x = ev->canvas.x;
1585 sd->down.history[0].y = ev->canvas.y;
1587 sd->down.dragged_began = 0;
1588 sd->down.hold_parent = 0;
1589 sd->down.cancelled = 0;
1594 _smart_hold_animator(void *data)
1596 Smart_Data *sd = data;
1599 elm_smart_scroller_child_pos_get(sd->smart_obj, &ox, &oy);
1602 if ((!sd->widget) ||
1603 (!elm_widget_drag_child_locked_x_get(sd->widget)))
1605 ox = sd->down.hold_x;
1610 if ((!sd->widget) ||
1611 (!elm_widget_drag_child_locked_y_get(sd->widget)))
1613 oy = sd->down.hold_y;
1616 elm_smart_scroller_child_pos_set(sd->smart_obj, ox, oy);
1617 return ECORE_CALLBACK_RENEW;
1621 _smart_event_post_up(void *data, Evas *e __UNUSED__)
1623 Smart_Data *sd = data;
1626 if (sd->down.dragged)
1628 elm_widget_drag_lock_x_set(sd->widget, 0);
1629 elm_widget_drag_lock_y_set(sd->widget, 0);
1636 _smart_event_mouse_up(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *event_info)
1638 Evas_Event_Mouse_Down *ev;
1640 Evas_Coord x = 0, y = 0, ox = 0, oy = 0;
1644 sd->down.hold_parent = 0;
1645 // if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
1646 evas_post_event_callback_push(e, _smart_event_post_up, sd);
1647 // FIXME: respect elm_widget_scroll_hold_get of parent container
1648 if (_elm_config->thumbscroll_enable)
1650 if (ev->button == 1)
1652 if (sd->down.onhold_animator)
1654 ecore_animator_del(sd->down.onhold_animator);
1655 sd->down.onhold_animator = NULL;
1657 x = ev->canvas.x - sd->down.x;
1658 y = ev->canvas.y - sd->down.y;
1659 if (sd->down.dragged)
1661 _smart_drag_stop(sd->smart_obj);
1662 if ((!sd->hold) && (!sd->freeze))
1666 Evas_Coord ax, ay, dx, dy, vel;
1669 t = ev->timestamp / 1000.0;
1671 t = ecore_loop_time_get();
1673 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1678 printf("------ %i %i\n", ev->canvas.x, ev->canvas.y);
1680 for (i = 0; i < 20; i++)
1682 dt = t - sd->down.history[i].timestamp;
1683 if (dt > 0.2) break;
1685 printf("H: %i %i @ %1.3f\n",
1686 sd->down.history[i].x,
1687 sd->down.history[i].y, dt);
1690 ax += sd->down.history[i].x;
1691 ay += sd->down.history[i].y;
1697 dx = ev->canvas.x - ax;
1698 dy = ev->canvas.y - ay;
1701 vel = sqrt((dx * dx) + (dy * dy)) / at;
1702 if ((_elm_config->thumbscroll_friction > 0.0) &&
1703 (vel > _elm_config->thumbscroll_momentum_threshold) &&
1706 sd->down.dx = ((double)dx / at);
1707 sd->down.dy = ((double)dy / at);
1708 if (((sd->down.dx > 0) && (sd->down.pdx > 0)) ||
1709 ((sd->down.dx < 0) && (sd->down.pdx < 0)))
1710 sd->down.dx += (double)sd->down.pdx * 1.5; // FIXME: * 1.5 - probably should be config
1711 if (((sd->down.dy > 0) && (sd->down.pdy > 0)) ||
1712 ((sd->down.dy < 0) && (sd->down.pdy < 0)))
1713 sd->down.dy += (double)sd->down.pdy * 1.5; // FIXME: * 1.5 - probably should be config
1714 if (((sd->down.dx > 0) && (sd->down.pdx > 0)) ||
1715 ((sd->down.dx < 0) && (sd->down.pdx < 0)) ||
1716 ((sd->down.dy > 0) && (sd->down.pdy > 0)) ||
1717 ((sd->down.dy < 0) && (sd->down.pdy < 0)))
1719 double t = ecore_loop_time_get();
1720 double dt = t - sd->down.anim_start;
1722 if (dt < 0.0) dt = 0.0;
1723 else if (dt > _elm_config->thumbscroll_friction)
1724 dt = _elm_config->thumbscroll_friction;
1725 sd->down.extra_time = _elm_config->thumbscroll_friction - dt;
1728 sd->down.extra_time = 0.0;
1729 sd->down.pdx = sd->down.dx;
1730 sd->down.pdy = sd->down.dy;
1733 if (!_smart_do_page(sd))
1735 if (!sd->down.momentum_animator && !sd->momentum_animator_disabled)
1737 sd->down.momentum_animator = ecore_animator_add(_smart_momentum_animator, sd);
1738 ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL;
1739 _smart_anim_start(sd->smart_obj);
1741 sd->down.anim_start = ecore_loop_time_get();
1742 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1750 if (sd->down.hold_animator)
1752 ecore_animator_del(sd->down.hold_animator);
1753 sd->down.hold_animator = NULL;
1761 evas_event_feed_hold(e, 0, ev->timestamp, ev->data);
1762 if (_smart_do_page(sd))
1764 Evas_Coord pgx, pgy;
1766 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1767 if ((!sd->widget) ||
1768 (!elm_widget_drag_child_locked_x_get(sd->widget)))
1770 pgx = _smart_page_x_get(sd, ox);
1773 ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL;
1774 _smart_scrollto_x(sd, _elm_config->page_scroll_friction, pgx);
1777 if ((!sd->widget) ||
1778 (!elm_widget_drag_child_locked_y_get(sd->widget)))
1780 pgy = _smart_page_y_get(sd, oy);
1783 ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL;
1784 _smart_scrollto_y(sd, _elm_config->page_scroll_friction, pgy);
1793 if (_smart_do_page(sd))
1795 Evas_Coord pgx, pgy;
1797 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1798 if ((!sd->widget) ||
1799 (!elm_widget_drag_child_locked_x_get(sd->widget)))
1801 pgx = _smart_page_x_get(sd, ox);
1802 if (pgx != x) _smart_scrollto_x(sd, _elm_config->page_scroll_friction, pgx);
1804 if ((!sd->widget) ||
1805 (!elm_widget_drag_child_locked_y_get(sd->widget)))
1807 pgy = _smart_page_y_get(sd, oy);
1808 if (pgy != y) _smart_scrollto_y(sd, _elm_config->page_scroll_friction, pgy);
1811 if (sd->down.hold_animator)
1813 ecore_animator_del(sd->down.hold_animator);
1814 sd->down.hold_animator = NULL;
1817 if (sd->down.scroll)
1819 ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL;
1820 sd->down.scroll = 0;
1824 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1827 sd->down.dragged_began = 0;
1830 sd->down.want_dragged = 0;
1831 sd->down.dragged = 0;
1833 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1834 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
1839 sd->wx = _elm_smart_scroller_x_mirrored_get(sd->smart_obj, sd->wx);
1841 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &sd->ww, &sd->wh);
1842 if (!_smart_do_page(sd))
1849 _smart_onhold_animator(void *data)
1854 Evas_Coord x, y, ox, oy;
1857 t = ecore_loop_time_get();
1858 if (sd->down.onhold_tlast > 0.0)
1860 td = t - sd->down.onhold_tlast;
1861 vx = sd->down.onhold_vx * td * (double)_elm_config->thumbscroll_threshold * 2.0;
1862 vy = sd->down.onhold_vy * td * (double)_elm_config->thumbscroll_threshold * 2.0;
1863 elm_smart_scroller_child_pos_get(sd->smart_obj, &ox, &oy);
1869 if ((!sd->widget) ||
1870 (!elm_widget_drag_child_locked_x_get(sd->widget)))
1872 sd->down.onhold_vxe += vx;
1873 x = ox + (int)sd->down.onhold_vxe;
1874 sd->down.onhold_vxe -= (int)sd->down.onhold_vxe;
1880 if ((!sd->widget) ||
1881 (!elm_widget_drag_child_locked_y_get(sd->widget)))
1883 sd->down.onhold_vye += vy;
1884 y = oy + (int)sd->down.onhold_vye;
1885 sd->down.onhold_vye -= (int)sd->down.onhold_vye;
1889 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
1891 sd->down.onhold_tlast = t;
1892 return ECORE_CALLBACK_RENEW;
1896 _smart_event_post_move(void *data, Evas *e __UNUSED__)
1898 Smart_Data *sd = data;
1900 if (sd->down.want_dragged)
1904 if (sd->down.hold_parent)
1906 if ((sd->down.dir_x) && !can_scroll(sd, sd->down.hdir))
1910 if ((sd->down.dir_y) && !can_scroll(sd, sd->down.vdir))
1917 if ((!sd->widget) ||
1918 (!elm_widget_drag_child_locked_x_get(sd->widget)))
1920 sd->down.want_dragged = 0;
1921 sd->down.dragged = 1;
1924 elm_widget_drag_lock_x_set(sd->widget, 1);
1933 if ((!sd->widget) ||
1934 (!elm_widget_drag_child_locked_y_get(sd->widget)))
1936 sd->down.want_dragged = 0;
1937 sd->down.dragged = 1;
1940 elm_widget_drag_lock_y_set(sd->widget, 1);
1947 if ((!sd->down.dir_x) && (!sd->down.dir_y))
1949 sd->down.cancelled = 1;
1951 if (start) _smart_drag_start(sd->smart_obj);
1957 _smart_event_mouse_move(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *event_info)
1959 Evas_Event_Mouse_Move *ev;
1961 Evas_Coord x = 0, y = 0;
1965 // if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
1966 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) sd->down.hold_parent = 1;
1967 evas_post_event_callback_push(e, _smart_event_post_move, sd);
1968 // FIXME: respect elm_widget_scroll_hold_get of parent container
1969 if (_elm_config->thumbscroll_enable)
1976 printf("::: %i %i\n", ev->cur.canvas.x, ev->cur.canvas.y);
1978 memmove(&(sd->down.history[1]), &(sd->down.history[0]),
1979 sizeof(sd->down.history[0]) * 19);
1981 sd->down.history[0].timestamp = ev->timestamp / 1000.0;
1983 sd->down.history[0].timestamp = ecore_loop_time_get();
1985 sd->down.history[0].x = ev->cur.canvas.x;
1986 sd->down.history[0].y = ev->cur.canvas.y;
1988 if (!sd->down.dragged_began)
1990 x = ev->cur.canvas.x - sd->down.x;
1991 y = ev->cur.canvas.y - sd->down.y;
1996 if (x > 0) sd->down.hdir = LEFT;
1997 else if (x < 0) sd->down.hdir = RIGHT;
1998 if (y > 0) sd->down.vdir = UP;
1999 else if (y < 0) sd->down.vdir = DOWN;
2004 if ((sd->one_dir_at_a_time) &&
2005 (!((sd->down.dir_x) || (sd->down.dir_y))))
2007 if (x > _elm_config->thumbscroll_threshold)
2016 if (y > _elm_config->thumbscroll_threshold)
2033 // can_scroll(sd, LEFT);
2034 // can_scroll(sd, RIGHT);
2035 // can_scroll(sd, UP);
2036 // can_scroll(sd, DOWN);
2041 if ((!sd->hold) && (!sd->freeze))
2043 if ((sd->down.dragged) ||
2044 (((x * x) + (y * y)) >
2045 (_elm_config->thumbscroll_threshold *
2046 _elm_config->thumbscroll_threshold)))
2048 sd->down.dragged_began = 1;
2049 if (!sd->down.dragged)
2051 sd->down.want_dragged = 1;
2052 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2053 // evas_event_feed_hold(e, 1, ev->timestamp, ev->data);
2054 // _smart_drag_start(sd->smart_obj);
2056 if (sd->down.dragged)
2058 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2060 // ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2061 // sd->down.dragged = 1;
2063 x = sd->down.sx - (ev->cur.canvas.x - sd->down.x);
2067 y = sd->down.sy - (ev->cur.canvas.y - sd->down.y);
2070 if ((sd->down.dir_x) || (sd->down.dir_y))
2072 if (!sd->down.locked)
2074 sd->down.locked_x = x;
2075 sd->down.locked_y = y;
2076 sd->down.locked = 1;
2078 if (!((sd->down.dir_x) && (sd->down.dir_y)))
2080 if (sd->down.dir_x) y = sd->down.locked_y;
2081 else x = sd->down.locked_x;
2084 if (_elm_config->thumbscroll_border_friction > 0.0)
2086 Evas_Coord minx, miny;
2087 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2090 _elm_config->thumbscroll_border_friction;
2091 else if (sd->child.h <= sd->h)
2092 y += (sd->down.sy - y) *
2093 _elm_config->thumbscroll_border_friction;
2094 else if ((sd->child.h - sd->h + miny) < y)
2095 y += (sd->child.h - sd->h + miny - y) *
2096 _elm_config->thumbscroll_border_friction;
2099 _elm_config->thumbscroll_border_friction;
2100 else if (sd->child.w <= sd->w)
2101 x += (sd->down.sx - x) *
2102 _elm_config->thumbscroll_border_friction;
2103 else if ((sd->child.w - sd->w + minx) < x)
2104 x += (sd->child.w - sd->w + minx - x) *
2105 _elm_config->thumbscroll_border_friction;
2108 sd->down.hold_x = x;
2109 sd->down.hold_y = y;
2110 if (!sd->down.hold_animator)
2111 sd->down.hold_animator =
2112 ecore_animator_add(_smart_hold_animator, sd);
2113 // printf("a %i %i\n", sd->down.hold_x, sd->down.hold_y);
2114 // _smart_onhold_animator(sd);
2115 // elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
2119 if (sd->down.dragged_began)
2121 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2125 evas_event_feed_hold(e, 1, ev->timestamp, ev->data);
2130 else if (!sd->freeze)
2132 Evas_Coord ex, ey, ew, eh;
2133 double vx = 0.0, vy = 0.0;
2135 evas_object_geometry_get(sd->event_obj, &ex, &ey, &ew, &eh);
2136 x = ev->cur.canvas.x - ex;
2137 y = ev->cur.canvas.y - ey;
2138 if (x < _elm_config->thumbscroll_threshold)
2140 if (_elm_config->thumbscroll_threshold > 0.0)
2141 vx = -(double)(_elm_config->thumbscroll_threshold - x) /
2142 _elm_config->thumbscroll_threshold;
2146 else if (x > (ew - _elm_config->thumbscroll_threshold))
2148 if (_elm_config->thumbscroll_threshold > 0.0)
2149 vx = (double)(_elm_config->thumbscroll_threshold - (ew - x)) /
2150 _elm_config->thumbscroll_threshold;
2154 if (y < _elm_config->thumbscroll_threshold)
2156 if (_elm_config->thumbscroll_threshold > 0.0)
2157 vy = -(double)(_elm_config->thumbscroll_threshold - y) /
2158 _elm_config->thumbscroll_threshold;
2162 else if (y > (eh - _elm_config->thumbscroll_threshold))
2164 if (_elm_config->thumbscroll_threshold > 0.0)
2165 vy = (double)(_elm_config->thumbscroll_threshold - (eh - y)) /
2166 _elm_config->thumbscroll_threshold;
2170 if ((vx != 0.0) || (vy != 0.0))
2172 sd->down.onhold_vx = vx;
2173 sd->down.onhold_vy = vy;
2174 if (!sd->down.onhold_animator)
2176 sd->down.onhold_vxe = 0.0;
2177 sd->down.onhold_vye = 0.0;
2178 sd->down.onhold_tlast = 0.0;
2179 sd->down.onhold_animator = ecore_animator_add(_smart_onhold_animator, sd);
2181 // printf("b %i %i\n", sd->down.hold_x, sd->down.hold_y);
2185 if (sd->down.onhold_animator)
2187 ecore_animator_del(sd->down.onhold_animator);
2188 sd->down.onhold_animator = NULL;
2197 _smart_scrollbar_read(Smart_Data *sd)
2199 Evas_Coord x, y, mx = 0, my = 0, px, py, minx = 0, miny = 0;
2202 edje_object_part_drag_value_get(sd->edje_obj, "elm.dragable.vbar", NULL, &vy);
2203 edje_object_part_drag_value_get(sd->edje_obj, "elm.dragable.hbar", &vx, NULL);
2204 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
2205 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2206 x = vx * (double)mx + minx;
2207 y = vy * (double)my + miny;
2208 sd->pan_func.get(sd->pan_obj, &px, &py);
2209 sd->pan_func.set(sd->pan_obj, x, y);
2210 if ((px != x) || (py != y))
2211 edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
2215 _smart_scrollbar_reset(Smart_Data *sd)
2217 Evas_Coord px = 0, py = 0, minx = 0, miny = 0;
2219 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.vbar", 0.0, 0.0);
2220 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.hbar", 0.0, 0.0);
2221 if ((!sd->child_obj) && (!sd->extern_pan))
2223 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.vbar", 1.0, 1.0);
2224 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.hbar", 1.0, 1.0);
2226 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2227 sd->pan_func.get(sd->pan_obj, &px, &py);
2228 sd->pan_func.set(sd->pan_obj, minx, miny);
2229 if ((px != minx) || (py != miny))
2230 edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
2234 _smart_scrollbar_bar_v_visibility_adjust(Smart_Data *sd)
2236 int scroll_v_vis_change = 0;
2237 Evas_Coord h, vw, vh;
2240 evas_object_geometry_get(sd->pan_obj, NULL, NULL, &vw, &vh);
2241 if (sd->vbar_visible)
2243 if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_AUTO)
2245 if ((sd->child_obj) || (sd->extern_pan))
2249 scroll_v_vis_change = 1;
2250 sd->vbar_visible = 0;
2255 scroll_v_vis_change = 1;
2256 sd->vbar_visible = 0;
2259 else if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
2261 scroll_v_vis_change = 1;
2262 sd->vbar_visible = 0;
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 = 1;
2278 else if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
2280 scroll_v_vis_change = 1;
2281 sd->vbar_visible = 1;
2284 if (scroll_v_vis_change)
2286 if (sd->vbar_flags != ELM_SMART_SCROLLER_POLICY_OFF)
2288 if (sd->vbar_visible)
2289 edje_object_signal_emit(sd->edje_obj, "elm,action,show,vbar", "elm");
2291 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,vbar", "elm");
2292 edje_object_message_signal_process(sd->edje_obj);
2293 _smart_scrollbar_size_adjust(sd);
2296 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,vbar", "elm");
2298 return scroll_v_vis_change;
2302 _smart_scrollbar_bar_h_visibility_adjust(Smart_Data *sd)
2304 int scroll_h_vis_change = 0;
2305 Evas_Coord w, vw, vh;
2308 evas_object_geometry_get(sd->pan_obj, NULL, NULL, &vw, &vh);
2309 if (sd->hbar_visible)
2311 if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_AUTO)
2313 if ((sd->child_obj) || (sd->extern_pan))
2317 scroll_h_vis_change = 1;
2318 sd->hbar_visible = 0;
2323 scroll_h_vis_change = 1;
2324 sd->hbar_visible = 0;
2327 else if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
2329 scroll_h_vis_change = 1;
2330 sd->hbar_visible = 0;
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 = 1;
2346 else if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
2348 scroll_h_vis_change = 1;
2349 sd->hbar_visible = 1;
2352 if (scroll_h_vis_change)
2354 if (sd->hbar_flags != ELM_SMART_SCROLLER_POLICY_OFF)
2356 if (sd->hbar_visible)
2357 edje_object_signal_emit(sd->edje_obj, "elm,action,show,hbar", "elm");
2359 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,hbar", "elm");
2360 edje_object_message_signal_process(sd->edje_obj);
2361 _smart_scrollbar_size_adjust(sd);
2364 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,hbar", "elm");
2365 _smart_scrollbar_size_adjust(sd);
2367 return scroll_h_vis_change;
2371 _smart_scrollbar_bar_visibility_adjust(Smart_Data *sd)
2375 changed |= _smart_scrollbar_bar_h_visibility_adjust(sd);
2376 changed |= _smart_scrollbar_bar_v_visibility_adjust(sd);
2379 _smart_scrollbar_bar_h_visibility_adjust(sd);
2380 _smart_scrollbar_bar_v_visibility_adjust(sd);
2385 _smart_scrollbar_size_adjust(Smart_Data *sd)
2387 if ((sd->child_obj) || (sd->extern_pan))
2389 Evas_Coord x, y, w, h, mx = 0, my = 0, vw = 0, vh = 0, px, py, minx = 0, miny = 0;
2390 double vx, vy, size;
2392 edje_object_part_geometry_get(sd->edje_obj, "elm.swallow.content",
2393 NULL, NULL, &vw, &vh);
2396 size = (double)vw / (double)w;
2400 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.hbar", 0.0, 0.0);
2402 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.hbar", size, 1.0);
2406 size = (double)vh / (double)h;
2410 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.vbar", 0.0, 0.0);
2412 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.vbar", 1.0, size);
2414 edje_object_part_drag_value_get(sd->edje_obj, "elm.dragable.hbar", &vx, NULL);
2415 edje_object_part_drag_value_get(sd->edje_obj, "elm.dragable.vbar", NULL, &vy);
2416 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
2417 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2421 edje_object_part_drag_step_set(sd->edje_obj, "elm.dragable.hbar", (double)sd->step.x / (double)w, 0.0);
2422 edje_object_part_drag_step_set(sd->edje_obj, "elm.dragable.vbar", 0.0, (double)sd->step.y / (double)h);
2424 edje_object_part_drag_page_set(sd->edje_obj, "elm.dragable.hbar", (double)sd->page.x / (double)w, 0.0);
2426 edje_object_part_drag_page_set(sd->edje_obj, "elm.dragable.hbar", -((double)sd->page.x * ((double)vw / (double)w)) / 100.0, 0.0);
2428 edje_object_part_drag_page_set(sd->edje_obj, "elm.dragable.vbar", 0.0, (double)sd->page.y / (double)h);
2430 edje_object_part_drag_page_set(sd->edje_obj, "elm.dragable.vbar", 0.0, -((double)sd->page.y * ((double)vh / (double)h)) / 100.0);
2432 sd->pan_func.get(sd->pan_obj, &px, &py);
2433 if (vx != mx) x = px;
2434 if (vy != my) y = py;
2435 sd->pan_func.set(sd->pan_obj, x, y);
2436 // if ((px != 0) || (py != 0))
2437 // edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
2441 Evas_Coord px = 0, py = 0, minx = 0, miny = 0;
2443 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.vbar", 1.0, 1.0);
2444 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.hbar", 1.0, 1.0);
2445 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2446 sd->pan_func.get(sd->pan_obj, &px, &py);
2447 sd->pan_func.set(sd->pan_obj, minx, miny);
2448 if ((px != minx) || (py != miny))
2449 edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
2451 _smart_scrollbar_bar_visibility_adjust(sd);
2455 _smart_reconfigure(Smart_Data *sd)
2457 evas_object_move(sd->edje_obj, sd->x, sd->y);
2458 evas_object_resize(sd->edje_obj, sd->w, sd->h);
2459 evas_object_move(sd->event_obj, sd->x, sd->y);
2460 evas_object_resize(sd->event_obj, sd->w, sd->h);
2461 _smart_scrollbar_size_adjust(sd);
2465 _smart_add(Evas_Object *obj)
2470 sd = calloc(1, sizeof(Smart_Data));
2472 evas_object_smart_data_set(obj, sd);
2474 sd->smart_obj = obj;
2483 sd->hbar_flags = ELM_SMART_SCROLLER_POLICY_AUTO;
2484 sd->vbar_flags = ELM_SMART_SCROLLER_POLICY_AUTO;
2485 sd->hbar_visible = 1;
2486 sd->vbar_visible = 1;
2488 sd->bounce_horiz = 1;
2489 sd->bounce_vert = 1;
2491 sd->one_dir_at_a_time = 1;
2492 sd->momentum_animator_disabled = 0;
2493 sd->bounce_animator_disabled = 0;
2495 o = edje_object_add(evas_object_evas_get(obj));
2496 evas_object_propagate_events_set(o, 0);
2498 // FIXME: null parent obj ... :(
2499 elm_smart_scroller_object_theme_set(NULL, obj, "scroller", "base", "default");
2500 edje_object_signal_callback_add(o, "drag", "elm.dragable.vbar", _smart_edje_drag_v, sd);
2501 edje_object_signal_callback_add(o, "drag,start", "elm.dragable.vbar", _smart_edje_drag_v_start, sd);
2502 edje_object_signal_callback_add(o, "drag,stop", "elm.dragable.vbar", _smart_edje_drag_v_stop, sd);
2503 edje_object_signal_callback_add(o, "drag,step", "elm.dragable.vbar", _smart_edje_drag_v, sd);
2504 edje_object_signal_callback_add(o, "drag,page", "elm.dragable.vbar", _smart_edje_drag_v, sd);
2505 edje_object_signal_callback_add(o, "drag", "elm.dragable.hbar", _smart_edje_drag_h, sd);
2506 edje_object_signal_callback_add(o, "drag,start", "elm.dragable.hbar", _smart_edje_drag_h_start, sd);
2507 edje_object_signal_callback_add(o, "drag,stop", "elm.dragable.hbar", _smart_edje_drag_h_stop, sd);
2508 edje_object_signal_callback_add(o, "drag,step", "elm.dragable.hbar", _smart_edje_drag_h, sd);
2509 edje_object_signal_callback_add(o, "drag,page", "elm.dragable.hbar", _smart_edje_drag_h, sd);
2510 evas_object_smart_member_add(o, obj);
2512 o = evas_object_rectangle_add(evas_object_evas_get(obj));
2514 evas_object_color_set(o, 0, 0, 0, 0);
2515 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_WHEEL, _smart_event_wheel, sd);
2516 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, _smart_event_mouse_down, sd);
2517 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_UP, _smart_event_mouse_up, sd);
2518 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_MOVE, _smart_event_mouse_move, sd);
2519 evas_object_smart_member_add(o, obj);
2520 evas_object_repeat_events_set(o, 1);
2522 sd->pan_func.set = _elm_smart_pan_set;
2523 sd->pan_func.get = _elm_smart_pan_get;
2524 sd->pan_func.max_get = _elm_smart_pan_max_get;
2525 sd->pan_func.min_get = _elm_smart_pan_min_get;
2526 sd->pan_func.child_size_get = _elm_smart_pan_child_size_get;
2528 _smart_scrollbar_reset(sd);
2532 _smart_del(Evas_Object *obj)
2535 elm_smart_scroller_child_set(obj, NULL);
2536 if (!sd->extern_pan) evas_object_del(sd->pan_obj);
2537 evas_object_del(sd->edje_obj);
2538 evas_object_del(sd->event_obj);
2539 if (sd->down.hold_animator) ecore_animator_del(sd->down.hold_animator);
2540 if (sd->down.onhold_animator) ecore_animator_del(sd->down.onhold_animator);
2541 if (sd->down.momentum_animator) ecore_animator_del(sd->down.momentum_animator);
2542 if (sd->down.bounce_x_animator) ecore_animator_del(sd->down.bounce_x_animator);
2543 if (sd->down.bounce_y_animator) ecore_animator_del(sd->down.bounce_y_animator);
2544 if (sd->scrollto.x.animator) ecore_animator_del(sd->scrollto.x.animator);
2545 if (sd->scrollto.y.animator) ecore_animator_del(sd->scrollto.y.animator);
2547 evas_object_smart_data_set(obj, NULL);
2551 _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
2556 _smart_reconfigure(sd);
2560 _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
2563 Evas_Coord ww, wh, wx = sd->wx;
2566 _smart_reconfigure(sd);
2568 /* Flip to RTL cords only if init in RTL mode */
2570 wx = _elm_smart_scroller_x_mirrored_get(obj, sd->wx);
2574 elm_smart_scroller_child_viewport_size_get(obj, &ww, &wh);
2582 elm_smart_scroller_child_region_set(obj, wx, sd->wy, ww, 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);