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, ret;
162 elm_smart_scroller_child_viewport_size_get(obj, &w, NULL);
163 sd->pan_func.child_size_get(sd->pan_obj, &cw, &ch);
164 ret = (cw - (x + w));
165 return (ret >= 0) ? ret : 0;
169 elm_smart_scroller_mirrored_set(Evas_Object *obj, Eina_Bool mirrored)
173 if (sd->is_mirrored == mirrored)
176 sd->is_mirrored = mirrored;
177 edje_object_mirrored_set(sd->edje_obj, mirrored);
180 wx = _elm_smart_scroller_x_mirrored_get(sd->smart_obj, sd->wx);
184 elm_smart_scroller_child_pos_set(sd->smart_obj, wx, sd->wy);
188 elm_smart_scroller_child_set(Evas_Object *obj, Evas_Object *child)
196 _elm_smart_pan_child_set(sd->pan_obj, NULL);
197 evas_object_event_callback_del_full(sd->child_obj, EVAS_CALLBACK_DEL, _smart_child_del_hook, sd);
200 sd->child_obj = child;
202 /* (-1) means want viewports size */
203 sd->ww = sd->wh = -1;
208 o = _elm_smart_pan_add(evas_object_evas_get(obj));
210 evas_object_smart_callback_add(o, "changed", _smart_pan_changed_hook, sd);
211 evas_object_smart_callback_add(o, "pan_changed", _smart_pan_pan_changed_hook, sd);
213 edje_object_part_swallow(sd->edje_obj, "elm.swallow.content", o);
216 sd->pan_func.set = _elm_smart_pan_set;
217 sd->pan_func.get = _elm_smart_pan_get;
218 sd->pan_func.max_get = _elm_smart_pan_max_get;
219 sd->pan_func.min_get = _elm_smart_pan_min_get;
220 sd->pan_func.child_size_get = _elm_smart_pan_child_size_get;
222 evas_object_event_callback_add(child, EVAS_CALLBACK_DEL, _smart_child_del_hook, sd);
223 _elm_smart_pan_child_set(sd->pan_obj, sd->child_obj);
224 sd->pan_func.child_size_get(sd->pan_obj, &w, &h);
227 _smart_scrollbar_size_adjust(sd);
228 _smart_scrollbar_reset(sd);
232 elm_smart_scroller_extern_pan_set(Evas_Object *obj, Evas_Object *pan,
233 void (*pan_set) (Evas_Object *obj, Evas_Coord x, Evas_Coord y),
234 void (*pan_get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y),
235 void (*pan_max_get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y),
236 void (*pan_min_get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y),
237 void (*pan_child_size_get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y))
241 elm_smart_scroller_child_set(obj, NULL);
245 evas_object_smart_callback_del(sd->pan_obj, "changed", _smart_pan_changed_hook);
246 evas_object_smart_callback_del(sd->pan_obj, "pan_changed", _smart_pan_pan_changed_hook);
253 edje_object_part_unswallow(sd->edje_obj, sd->pan_obj);
261 evas_object_del(sd->pan_obj);
272 sd->pan_func.set = pan_set;
273 sd->pan_func.get = pan_get;
274 sd->pan_func.max_get = pan_max_get;
275 sd->pan_func.min_get = pan_min_get;
276 sd->pan_func.child_size_get = pan_child_size_get;
278 evas_object_smart_callback_add(sd->pan_obj, "changed", _smart_pan_changed_hook, sd);
279 evas_object_smart_callback_add(sd->pan_obj, "pan_changed", _smart_pan_pan_changed_hook, sd);
280 edje_object_part_swallow(sd->edje_obj, "elm.swallow.content", sd->pan_obj);
281 evas_object_show(sd->pan_obj);
285 elm_smart_scroller_custom_edje_file_set(Evas_Object *obj, char *file, char *group)
289 edje_object_file_set(sd->edje_obj, file, group);
291 edje_object_part_swallow(sd->edje_obj, "elm.swallow.content", sd->pan_obj);
292 sd->vbar_visible = !sd->vbar_visible;
293 sd->hbar_visible = !sd->hbar_visible;
294 _smart_scrollbar_bar_visibility_adjust(sd);
295 if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
296 edje_object_signal_emit(sd->edje_obj, "elm,action,show_always,hbar", "elm");
297 else if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
298 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,hbar", "elm");
300 edje_object_signal_emit(sd->edje_obj, "elm,action,show_notalways,hbar", "elm");
301 if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
302 edje_object_signal_emit(sd->edje_obj, "elm,action,show_always,vbar", "elm");
303 else if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
304 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,vbar", "elm");
306 edje_object_signal_emit(sd->edje_obj, "elm,action,show_notalways,vbar", "elm");
310 elm_smart_scroller_momentum_animator_disabled_get(Evas_Object *obj)
312 API_ENTRY return EINA_FALSE;
313 return sd->momentum_animator_disabled;
317 elm_smart_scroller_momentum_animator_disabled_set(Evas_Object *obj, Eina_Bool disabled)
320 sd->momentum_animator_disabled = disabled;
321 if (sd->momentum_animator_disabled)
323 if (sd->down.momentum_animator)
325 ecore_animator_del(sd->down.momentum_animator);
326 sd->down.momentum_animator = NULL;
332 elm_smart_scroller_bounce_animator_disabled_get(Evas_Object *obj)
334 API_ENTRY return EINA_FALSE;
335 return sd->bounce_animator_disabled;
339 elm_smart_scroller_bounce_animator_disabled_set(Evas_Object *obj, Eina_Bool disabled)
342 sd->bounce_animator_disabled = disabled;
343 if (sd->bounce_animator_disabled)
345 if (sd->scrollto.x.animator)
347 ecore_animator_del(sd->scrollto.x.animator);
348 sd->scrollto.x.animator = NULL;
351 if (sd->scrollto.y.animator)
353 ecore_animator_del(sd->scrollto.y.animator);
354 sd->scrollto.y.animator = NULL;
359 /* Update the wanted coordinates according to the x, y passed
360 * widget directionality, child size and etc. */
362 _update_wanted_coordinates(Smart_Data *sd, Evas_Coord x, Evas_Coord y)
366 sd->pan_func.child_size_get(sd->pan_obj, &cw, &ch);
368 /* Update wx/y/w/h - and if the requested positions aren't legal
370 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &sd->ww, &sd->wh);
373 else if ((x + sd->ww) > cw)
374 sd->wx = cw - sd->ww;
375 else if (sd->is_mirrored)
376 sd->wx = _elm_smart_scroller_x_mirrored_get(sd->smart_obj, x);
379 if (y < 0) sd->wy = 0;
380 else if ((y + sd->wh) > ch) sd->wy = ch - sd->wh;
385 _smart_anim_start(Evas_Object *obj)
387 evas_object_smart_callback_call(obj, "animate,start", NULL);
391 _smart_anim_stop(Evas_Object *obj)
393 evas_object_smart_callback_call(obj, "animate,stop", NULL);
397 _smart_drag_start(Evas_Object *obj)
399 evas_object_smart_callback_call(obj, "drag,start", NULL);
403 _smart_drag_stop(Evas_Object *obj)
405 evas_object_smart_callback_call(obj, "drag,stop", NULL);
409 _smart_scrollto_x_animator(void *data)
411 Smart_Data *sd = data;
415 t = ecore_loop_time_get();
416 tt = (t - sd->scrollto.x.t_start) / (sd->scrollto.x.t_end - sd->scrollto.x.t_start);
418 tt = 1.0 - (tt * tt);
419 sd->pan_func.get(sd->pan_obj, &px, &py);
420 px = (sd->scrollto.x.start * (1.0 - tt)) +
421 (sd->scrollto.x.end * tt);
422 if (t >= sd->scrollto.x.t_end)
424 px = sd->scrollto.x.end;
425 elm_smart_scroller_child_pos_set(sd->smart_obj, px, py);
426 sd->scrollto.x.animator = NULL;
427 if ((!sd->scrollto.y.animator) && (!sd->down.bounce_y_animator))
428 _smart_anim_stop(sd->smart_obj);
429 return ECORE_CALLBACK_CANCEL;
431 elm_smart_scroller_child_pos_set(sd->smart_obj, px, py);
432 return ECORE_CALLBACK_RENEW;
436 _smart_momentum_end(Smart_Data *sd)
438 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator)) return;
439 if (sd->down.momentum_animator)
442 elm_smart_scroller_child_pos_get(sd->smart_obj, &px, &py);
443 _update_wanted_coordinates(sd, px, py);
445 ecore_animator_del(sd->down.momentum_animator);
446 sd->down.momentum_animator = NULL;
447 sd->down.bounce_x_hold = 0;
448 sd->down.bounce_y_hold = 0;
457 _smart_scrollto_x(Smart_Data *sd, double t_in, Evas_Coord pos_x)
459 Evas_Coord px, py, x, y, w, h;
462 if (sd->freeze) return;
465 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
466 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
468 elm_smart_scroller_child_region_set(sd->smart_obj, x, y, w, h);
471 t = ecore_loop_time_get();
472 sd->pan_func.get(sd->pan_obj, &px, &py);
473 sd->scrollto.x.start = px;
474 sd->scrollto.x.end = pos_x;
475 sd->scrollto.x.t_start = t;
476 sd->scrollto.x.t_end = t + t_in;
477 if (!sd->scrollto.x.animator)
479 if (!sd->scrollto.y.animator)
480 _smart_anim_start(sd->smart_obj);
481 sd->scrollto.x.animator = ecore_animator_add(_smart_scrollto_x_animator, sd);
483 if (sd->down.bounce_x_animator)
485 ecore_animator_del(sd->down.bounce_x_animator);
486 sd->down.bounce_x_animator = NULL;
487 _smart_momentum_end(sd);
493 _smart_scrollto_y_animator(void *data)
495 Smart_Data *sd = data;
499 t = ecore_loop_time_get();
500 tt = (t - sd->scrollto.y.t_start) / (sd->scrollto.y.t_end - sd->scrollto.y.t_start);
502 tt = 1.0 - (tt * tt);
503 sd->pan_func.get(sd->pan_obj, &px, &py);
504 py = (sd->scrollto.y.start * (1.0 - tt)) +
505 (sd->scrollto.y.end * tt);
506 if (t >= sd->scrollto.y.t_end)
508 py = sd->scrollto.y.end;
509 elm_smart_scroller_child_pos_set(sd->smart_obj, px, py);
510 sd->scrollto.y.animator = NULL;
511 if ((!sd->scrollto.x.animator) && (!sd->down.bounce_x_animator))
512 _smart_anim_stop(sd->smart_obj);
513 return ECORE_CALLBACK_CANCEL;
515 elm_smart_scroller_child_pos_set(sd->smart_obj, px, py);
517 return ECORE_CALLBACK_RENEW;
521 _smart_scrollto_y(Smart_Data *sd, double t_in, Evas_Coord pos_y)
523 Evas_Coord px, py, x, y, w, h;
526 if (sd->freeze) return;
529 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
530 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
532 elm_smart_scroller_child_region_set(sd->smart_obj, x, y, w, h);
535 t = ecore_loop_time_get();
536 sd->pan_func.get(sd->pan_obj, &px, &py);
537 sd->scrollto.y.start = py;
538 sd->scrollto.y.end = pos_y;
539 sd->scrollto.y.t_start = t;
540 sd->scrollto.y.t_end = t + t_in;
541 if (!sd->scrollto.y.animator)
543 if (!sd->scrollto.x.animator)
544 _smart_anim_start(sd->smart_obj);
545 sd->scrollto.y.animator = ecore_animator_add(_smart_scrollto_y_animator, sd);
547 if (sd->down.bounce_y_animator)
549 ecore_animator_del(sd->down.bounce_y_animator);
550 sd->down.bounce_y_animator = NULL;
551 _smart_momentum_end(sd);
557 _smart_do_page(Smart_Data *sd)
559 if ((sd->pagerel_h == 0.0) && (!sd->pagesize_h) &&
560 (sd->pagerel_v == 0.0) && (!sd->pagesize_v))
566 _smart_page_x_get(Smart_Data *sd, int offset)
568 Evas_Coord x, y, w, h, cw, ch, minx = 0;
570 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
571 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
572 sd->pan_func.child_size_get(sd->pan_obj, &cw, &ch);
573 sd->pan_func.min_get(sd->pan_obj, &minx, NULL);
577 if (sd->pagerel_h > 0.0)
579 x = x + (w * sd->pagerel_h * 0.5);
580 x = x / (w * sd->pagerel_h);
581 x = x * (w * sd->pagerel_h);
583 else if (sd->pagesize_h > 0)
585 x = x + (sd->pagesize_h * 0.5);
586 x = x / (sd->pagesize_h);
587 x = x * (sd->pagesize_h);
589 if (x < minx) x = minx;
590 else if ((x + w) > cw) x = cw - w;
595 _smart_page_y_get(Smart_Data *sd, int offset)
597 Evas_Coord x, y, w, h, cw, ch, miny = 0;
599 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
600 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
601 sd->pan_func.child_size_get(sd->pan_obj, &cw, &ch);
602 sd->pan_func.min_get(sd->pan_obj, NULL, &miny);
606 if (sd->pagerel_v > 0.0)
608 y = y + (h * sd->pagerel_v * 0.5);
609 y = y / (h * sd->pagerel_v);
610 y = y * (h * sd->pagerel_v);
612 else if (sd->pagesize_v > 0)
614 y = y + (sd->pagesize_v * 0.5);
615 y = y / (sd->pagesize_v);
616 y = y * (sd->pagesize_v);
618 if (y < miny) y = miny;
619 else if ((y + h) > ch) y = ch - h;
624 _smart_page_adjust(Smart_Data *sd)
626 Evas_Coord x, y, w, h;
628 if (!_smart_do_page(sd)) return;
630 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
632 x = _smart_page_x_get(sd, 0);
633 y = _smart_page_y_get(sd, 0);
635 elm_smart_scroller_child_region_set(sd->smart_obj, x, y, w, h);
639 _smart_bounce_x_animator(void *data)
646 t = ecore_loop_time_get();
647 dt = t - sd->down.anim_start2;
650 dt = dt / _elm_config->thumbscroll_bounce_friction;
651 if (dt > 1.0) dt = 1.0;
652 p = 1.0 - ((1.0 - dt) * (1.0 - dt));
653 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
654 dx = sd->down.b2x - sd->down.bx;
656 x = sd->down.bx + dx;
657 if (!sd->down.cancelled)
658 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
661 if (sd->down.momentum_animator)
662 sd->down.bounce_x_hold = 1;
663 else if ((!sd->down.bounce_y_animator) &&
664 (!sd->scrollto.y.animator))
665 _smart_anim_stop(sd->smart_obj);
666 sd->down.bounce_x_animator = NULL;
669 _smart_momentum_end(sd);
670 return ECORE_CALLBACK_CANCEL;
673 return ECORE_CALLBACK_RENEW;
677 _smart_bounce_y_animator(void *data)
684 t = ecore_loop_time_get();
685 dt = t - sd->down.anim_start3;
688 dt = dt / _elm_config->thumbscroll_bounce_friction;
689 if (dt > 1.0) dt = 1.0;
690 p = 1.0 - ((1.0 - dt) * (1.0 - dt));
691 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
692 dy = sd->down.b2y - sd->down.by;
694 y = sd->down.by + dy;
695 if (!sd->down.cancelled)
696 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
699 if (sd->down.momentum_animator)
700 sd->down.bounce_y_hold = 1;
701 else if ((!sd->down.bounce_x_animator) &&
702 (!sd->scrollto.y.animator))
703 _smart_anim_stop(sd->smart_obj);
704 sd->down.bounce_y_animator = NULL;
707 _smart_momentum_end(sd);
708 return ECORE_CALLBACK_CANCEL;
711 return ECORE_CALLBACK_RENEW;
719 can_scroll(Smart_Data *sd, int dir)
721 Evas_Coord mx = 0, my = 0, px = 0, py = 0, minx = 0, miny = 0;
723 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
724 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
725 sd->pan_func.get(sd->pan_obj, &px, &py);
729 if (px > minx) return EINA_TRUE;
732 if ((px - minx) < mx) return EINA_TRUE;
735 if (py > miny) return EINA_TRUE;
738 if ((py - miny) < my) return EINA_TRUE;
747 _smart_momentum_animator(void *data)
751 Evas_Coord x, y, dx, dy, px, py, maxx, maxy, minx, miny;
752 Eina_Bool no_bounce_x_end = EINA_FALSE, no_bounce_y_end = EINA_FALSE;
755 t = ecore_loop_time_get();
756 dt = t - sd->down.anim_start;
760 if (sd->down.hold_parent)
762 if ((sd->down.dir_x) && !can_scroll(sd, sd->down.hdir))
766 if ((sd->down.dir_y) && !can_scroll(sd, sd->down.vdir))
771 if ((!sd->down.dir_x) && (!sd->down.dir_y))
773 sd->down.cancelled = 1;
776 dt = dt / (_elm_config->thumbscroll_friction + sd->down.extra_time);
777 if (dt > 1.0) dt = 1.0;
778 p = 1.0 - ((1.0 - dt) * (1.0 - dt));
779 dx = (sd->down.dx * (_elm_config->thumbscroll_friction + sd->down.extra_time) * p);
780 dy = (sd->down.dy * (_elm_config->thumbscroll_friction + sd->down.extra_time) * p);
783 x = sd->down.sx - dx;
784 y = sd->down.sy - dy;
785 elm_smart_scroller_child_pos_get(sd->smart_obj, &px, &py);
786 if ((sd->down.bounce_x_animator) ||
787 (sd->down.bounce_x_hold))
789 sd->down.bx = sd->down.bx0 - dx + sd->down.b0x;
792 if ((sd->down.bounce_y_animator) ||
793 (sd->down.bounce_y_hold))
795 sd->down.by = sd->down.by0 - dy + sd->down.b0y;
798 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
799 sd->pan_func.max_get(sd->pan_obj, &maxx, &maxy);
800 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
801 if (!sd->bounce_horiz)
803 if (x <= minx) no_bounce_x_end = EINA_TRUE;
804 if ((x - minx) >= maxx) no_bounce_x_end = EINA_TRUE;
806 if (!sd->bounce_vert)
808 if (y <= miny) no_bounce_y_end = EINA_TRUE;
809 if ((y - miny) >= maxy) no_bounce_y_end = EINA_TRUE;
812 ((sd->down.bounce_x_hold) && (sd->down.bounce_y_hold)) ||
813 (no_bounce_x_end && no_bounce_y_end))
815 _smart_anim_stop(sd->smart_obj);
816 _update_wanted_coordinates(sd, px, py);
818 sd->down.momentum_animator = NULL;
819 sd->down.bounce_x_hold = 0;
820 sd->down.bounce_y_hold = 0;
825 return ECORE_CALLBACK_CANCEL;
828 return ECORE_CALLBACK_RENEW;
832 bounce_eval(Smart_Data *sd)
834 Evas_Coord mx, my, px, py, bx, by, b2x, b2y, minx = 0, miny = 0;
836 if (sd->freeze) return;
837 if ((!sd->bouncemex) && (!sd->bouncemey)) return;
838 if (sd->down.now) return; // down bounce while still held down
839 if (sd->down.onhold_animator)
841 ecore_animator_del(sd->down.onhold_animator);
842 sd->down.onhold_animator = NULL;
844 if (sd->down.hold_animator)
846 ecore_animator_del(sd->down.hold_animator);
847 sd->down.hold_animator = NULL;
849 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
850 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
851 sd->pan_func.get(sd->pan_obj, &px, &py);
854 if (px < minx) px = minx;
855 if ((px - minx) > mx) px = mx + minx;
856 if (py < miny) py = miny;
857 if ((py - miny) > my) py = my + miny;
861 (!elm_widget_drag_child_locked_x_get(sd->widget)))
863 if (!sd->down.bounce_x_animator && !sd->bounce_animator_disabled)
867 if (sd->scrollto.x.animator)
869 ecore_animator_del(sd->scrollto.x.animator);
870 sd->scrollto.x.animator = NULL;
872 sd->down.bounce_x_animator = ecore_animator_add(_smart_bounce_x_animator, sd);
873 sd->down.anim_start2 = ecore_loop_time_get();
877 if (sd->down.momentum_animator) sd->down.b0x = sd->down.ax;
878 else sd->down.b0x = 0;
883 (!elm_widget_drag_child_locked_y_get(sd->widget)))
885 if (!sd->down.bounce_y_animator && !sd->bounce_animator_disabled)
889 if (sd->scrollto.y.animator)
891 ecore_animator_del(sd->scrollto.y.animator);
892 sd->scrollto.y.animator = NULL;
894 sd->down.bounce_y_animator = ecore_animator_add(_smart_bounce_y_animator, sd);
895 sd->down.anim_start3 = ecore_loop_time_get();
899 if (sd->down.momentum_animator) sd->down.b0y = sd->down.ay;
900 else sd->down.b0y = 0;
907 elm_smart_scroller_child_pos_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
909 Evas_Coord mx = 0, my = 0, px = 0, py = 0, minx = 0, miny = 0;
913 // FIXME: allow for bounce outside of range
914 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
915 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
916 if (mx > 0) vx = (double)(x - minx) / (double)mx;
918 if (vx < 0.0) vx = 0.0;
919 else if (vx > 1.0) vx = 1.0;
920 if (my > 0) vy = (double)(y - miny) / (double)my;
922 if (vy < 0.0) vy = 0.0;
923 else if (vy > 1.0) vy = 1.0;
924 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.vbar", 0.0, vy);
925 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.hbar", vx, 0.0);
926 sd->pan_func.get(sd->pan_obj, &px, &py);
927 if (!_elm_config->thumbscroll_bounce_enable)
929 if (x < minx) x = minx;
930 if ((x - minx) > mx) x = mx + minx;
931 if (y < miny) y = miny;
932 if ((y - miny) > my) y = my + miny;
935 if (!sd->bounce_horiz)
937 if (x < minx) x = minx;
938 if ((x - minx) > mx) x = mx + minx;
940 if (!sd->bounce_vert)
942 if (y < miny) y = miny;
943 if (y - miny > my) y = my + miny;
946 sd->pan_func.set(sd->pan_obj, x, y);
947 if ((px != x) || (py != y))
948 edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
949 if (!sd->down.bounce_x_animator)
951 if ((x < minx) || (x > (mx + minx)))
957 if (!sd->down.bounce_y_animator)
959 if ((y < miny) || (y > my + miny))
965 if ((x != px) || (y != py))
967 evas_object_smart_callback_call(obj, "scroll", NULL);
969 if ((x != px)/* && (!sd->bouncemex)*/)
972 evas_object_smart_callback_call(obj, "edge,left", NULL);
973 if (x == (mx + minx))
974 evas_object_smart_callback_call(obj, "edge,right", NULL);
976 if ((y != py)/* && (!sd->bouncemey)*/)
979 evas_object_smart_callback_call(obj, "edge,top", NULL);
981 evas_object_smart_callback_call(obj, "edge,bottom", NULL);
986 elm_smart_scroller_child_pos_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
989 sd->pan_func.get(sd->pan_obj, x, y);
992 /* "internal_call" actually toggles whether we should save the coords and do
993 * extra "speedup" checks, or not. */
995 _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)
997 Evas_Coord mx = 0, my = 0, cw = 0, ch = 0, px = 0, py = 0, nx, ny, minx = 0, miny = 0;
1000 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
1001 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
1002 sd->pan_func.child_size_get(sd->pan_obj, &cw, &ch);
1003 sd->pan_func.get(sd->pan_obj, &px, &py);
1006 if ((x < px) && ((x + w) < (px + (cw - mx)))) nx = x;
1007 else if ((x > px) && ((x + w) > (px + (cw - mx)))) nx = x + w - (cw - mx);
1009 if ((y < py) && ((y + h) < (py + (ch - my)))) ny = y;
1010 else if ((y > py) && ((y + h) > (py + (ch - my)))) ny = y + h - (ch - my);
1017 if ((nx == px) && (ny == py)) return;
1020 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1021 (sd->scrollto.x.animator) || (sd->scrollto.y.animator))
1023 _smart_anim_stop(sd->smart_obj);
1025 if (sd->scrollto.x.animator)
1027 ecore_animator_del(sd->scrollto.x.animator);
1028 sd->scrollto.x.animator = NULL;
1030 if (sd->scrollto.y.animator)
1032 ecore_animator_del(sd->scrollto.y.animator);
1033 sd->scrollto.y.animator = NULL;
1035 if (sd->down.bounce_x_animator)
1037 ecore_animator_del(sd->down.bounce_x_animator);
1038 sd->down.bounce_x_animator = NULL;
1041 if (sd->down.bounce_y_animator)
1043 ecore_animator_del(sd->down.bounce_y_animator);
1044 sd->down.bounce_y_animator = NULL;
1047 if (sd->down.hold_animator)
1049 ecore_animator_del(sd->down.hold_animator);
1050 sd->down.hold_animator = NULL;
1051 _smart_drag_stop(sd->smart_obj);
1053 if (sd->down.momentum_animator)
1055 ecore_animator_del(sd->down.momentum_animator);
1056 sd->down.momentum_animator = NULL;
1057 sd->down.bounce_x_hold = 0;
1058 sd->down.bounce_y_hold = 0;
1064 elm_smart_scroller_child_pos_set(obj, nx, ny);
1067 /* Set should be used for calculated positions, for example, when we move
1068 * because of an animation or because this is the correct position after
1071 elm_smart_scroller_child_region_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
1073 _elm_smart_scroller_child_region_show_internal(obj, x, y, w, h, EINA_TRUE);
1076 /* Set should be used for setting the wanted position, for example a user scroll
1077 * or moving the cursor in an entry. */
1079 elm_smart_scroller_child_region_show(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
1081 _elm_smart_scroller_child_region_show_internal(obj, x, y, w, h, EINA_FALSE);
1085 elm_smart_scroller_child_viewport_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
1088 edje_object_calc_force(sd->edje_obj);
1089 evas_object_geometry_get(sd->pan_obj, NULL, NULL, w, h);
1093 elm_smart_scroller_step_size_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
1100 _smart_scrollbar_size_adjust(sd);
1104 elm_smart_scroller_step_size_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
1107 if (x) *x = sd->step.x;
1108 if (y) *y = sd->step.y;
1112 elm_smart_scroller_page_size_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
1117 _smart_scrollbar_size_adjust(sd);
1121 elm_smart_scroller_page_size_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
1124 if (x) *x = sd->page.x;
1125 if (y) *y = sd->page.y;
1129 elm_smart_scroller_policy_set(Evas_Object *obj, Elm_Smart_Scroller_Policy hbar, Elm_Smart_Scroller_Policy vbar)
1132 if ((sd->hbar_flags == hbar) && (sd->vbar_flags == vbar)) return;
1133 sd->hbar_flags = hbar;
1134 sd->vbar_flags = vbar;
1135 if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
1136 edje_object_signal_emit(sd->edje_obj, "elm,action,show_always,hbar", "elm");
1137 else if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
1138 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,hbar", "elm");
1140 edje_object_signal_emit(sd->edje_obj, "elm,action,show_notalways,hbar", "elm");
1141 if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
1142 edje_object_signal_emit(sd->edje_obj, "elm,action,show_always,vbar", "elm");
1143 else if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
1144 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,vbar", "elm");
1146 edje_object_signal_emit(sd->edje_obj, "elm,action,show_notalways,vbar", "elm");
1147 _smart_scrollbar_size_adjust(sd);
1151 elm_smart_scroller_policy_get(Evas_Object *obj, Elm_Smart_Scroller_Policy *hbar, Elm_Smart_Scroller_Policy *vbar)
1154 if (hbar) *hbar = sd->hbar_flags;
1155 if (vbar) *vbar = sd->vbar_flags;
1159 elm_smart_scroller_edje_object_get(Evas_Object *obj)
1161 API_ENTRY return NULL;
1162 return sd->edje_obj;
1166 elm_smart_scroller_single_dir_set(Evas_Object *obj, Eina_Bool single_dir)
1169 sd->one_dir_at_a_time = single_dir;
1173 elm_smart_scroller_single_dir_get(Evas_Object *obj)
1175 API_ENTRY return EINA_FALSE;
1176 return sd->one_dir_at_a_time;
1180 elm_smart_scroller_object_theme_set(Evas_Object *parent, Evas_Object *obj, const char *clas, const char *group, const char *style)
1184 _elm_theme_object_set(parent, sd->edje_obj, clas, group, style);
1185 edje_object_scale_set(sd->edje_obj, elm_widget_scale_get(parent) * _elm_config->scale);
1187 edje_object_part_swallow(sd->edje_obj, "elm.swallow.content", sd->pan_obj);
1189 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1190 if (edje_object_part_exists(sd->edje_obj, "elm.scrollbar.base"))
1193 base = edje_object_part_swallow_get(sd->edje_obj, "elm.scrollbar.base");
1196 base = evas_object_rectangle_add(evas_object_evas_get(sd->edje_obj));
1197 evas_object_color_set(base, 0, 0, 0, 0);
1198 edje_object_part_swallow(sd->edje_obj, "elm.scrollbar.base", base);
1200 if (!_elm_config->thumbscroll_enable)
1201 evas_object_size_hint_min_set(base, mw, mh);
1203 sd->vbar_visible = !sd->vbar_visible;
1204 sd->hbar_visible = !sd->hbar_visible;
1205 _smart_scrollbar_bar_visibility_adjust(sd);
1209 elm_smart_scroller_hold_set(Evas_Object *obj, Eina_Bool hold)
1216 elm_smart_scroller_freeze_set(Evas_Object *obj, Eina_Bool freeze)
1219 sd->freeze = freeze;
1222 if (sd->down.onhold_animator)
1224 ecore_animator_del(sd->down.onhold_animator);
1225 sd->down.onhold_animator = NULL;
1231 elm_smart_scroller_bounce_allow_set(Evas_Object *obj, Eina_Bool horiz, Eina_Bool vert)
1234 sd->bounce_horiz = horiz;
1235 sd->bounce_vert = vert;
1239 elm_smart_scroller_bounce_allow_get(const Evas_Object *obj, Eina_Bool *horiz, Eina_Bool *vert)
1242 *horiz = sd->bounce_horiz;
1243 *vert = sd->bounce_vert;
1247 elm_smart_scroller_paging_set(Evas_Object *obj, double pagerel_h, double pagerel_v, Evas_Coord pagesize_h, Evas_Coord pagesize_v)
1250 sd->pagerel_h = pagerel_h;
1251 sd->pagerel_v = pagerel_v;
1252 sd->pagesize_h = pagesize_h;
1253 sd->pagesize_v = pagesize_v;
1254 _smart_page_adjust(sd);
1258 elm_smart_scroller_paging_get(Evas_Object *obj, double *pagerel_h, double *pagerel_v, Evas_Coord *pagesize_h, Evas_Coord *pagesize_v)
1261 if(pagerel_h) *pagerel_h = sd->pagerel_h;
1262 if(pagerel_v) *pagerel_v = sd->pagerel_v;
1263 if(pagesize_h) *pagesize_h = sd->pagesize_h;
1264 if(pagesize_v) *pagesize_v = sd->pagesize_v;
1268 elm_smart_scroller_region_bring_in(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
1270 Evas_Coord mx = 0, my = 0, cw = 0, ch = 0, px = 0, py = 0, nx, ny, minx = 0, miny = 0;
1273 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
1274 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
1275 sd->pan_func.child_size_get(sd->pan_obj, &cw, &ch);
1276 sd->pan_func.get(sd->pan_obj, &px, &py);
1279 if ((x < px) && ((x + w) < (px + (cw - mx)))) nx = x;
1280 else if ((x > px) && ((x + w) > (px + (cw - mx)))) nx = x + w - (cw - mx);
1282 if ((y < py) && ((y + h) < (py + (ch - my)))) ny = y;
1283 else if ((y > py) && ((y + h) > (py + (ch - my)))) ny = y + h - (ch - my);
1288 if ((nx == px) && (ny == py)) return;
1289 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1290 (sd->scrollto.x.animator) || (sd->scrollto.y.animator))
1292 _smart_anim_stop(sd->smart_obj);
1294 if (sd->scrollto.x.animator)
1296 ecore_animator_del(sd->scrollto.x.animator);
1297 sd->scrollto.x.animator = NULL;
1299 if (sd->scrollto.y.animator)
1301 ecore_animator_del(sd->scrollto.y.animator);
1302 sd->scrollto.y.animator = NULL;
1304 if (sd->down.bounce_x_animator)
1306 ecore_animator_del(sd->down.bounce_x_animator);
1307 sd->down.bounce_x_animator = NULL;
1310 if (sd->down.bounce_y_animator)
1312 ecore_animator_del(sd->down.bounce_y_animator);
1313 sd->down.bounce_y_animator = NULL;
1316 if (sd->down.hold_animator)
1318 ecore_animator_del(sd->down.hold_animator);
1319 sd->down.hold_animator = NULL;
1320 _smart_drag_stop(sd->smart_obj);
1322 if (sd->down.momentum_animator)
1324 ecore_animator_del(sd->down.momentum_animator);
1325 sd->down.momentum_animator = NULL;
1326 sd->down.bounce_x_hold = 0;
1327 sd->down.bounce_y_hold = 0;
1334 if (x < minx) x = minx;
1335 else if ((x + w) > cw) x = cw - w;
1336 _smart_scrollto_x(sd, _elm_config->bring_in_scroll_friction, x);
1338 if (y < miny) y = miny;
1339 else if ((y + h) > ch) y = ch - h;
1340 _smart_scrollto_y(sd, _elm_config->bring_in_scroll_friction, y);
1344 elm_smart_scroller_widget_set(Evas_Object *obj, Evas_Object *wid)
1351 _elm_smart_scroller_wanted_region_set(Evas_Object *obj)
1354 Evas_Coord ww, wh, wx = sd->wx;
1356 /* Flip to RTL cords only if init in RTL mode */
1358 wx = _elm_smart_scroller_x_mirrored_get(obj, sd->wx);
1362 elm_smart_scroller_child_viewport_size_get(obj, &ww, &wh);
1370 elm_smart_scroller_child_region_set(obj, wx, sd->wy, ww, wh);
1373 /* local subsystem functions */
1375 _smart_edje_drag_v_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1380 _smart_scrollbar_read(sd);
1381 _smart_drag_start(sd->smart_obj);
1382 sd->freeze = EINA_TRUE;
1386 _smart_edje_drag_v_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1391 _smart_scrollbar_read(sd);
1392 _smart_drag_stop(sd->smart_obj);
1393 sd->freeze = EINA_FALSE;
1397 _smart_edje_drag_v(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1402 _smart_scrollbar_read(sd);
1406 _smart_edje_drag_h_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1411 _smart_scrollbar_read(sd);
1412 _smart_drag_start(sd->smart_obj);
1413 sd->freeze = EINA_TRUE;
1417 _smart_edje_drag_h_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1422 _smart_scrollbar_read(sd);
1423 _smart_drag_stop(sd->smart_obj);
1424 sd->freeze = EINA_FALSE;
1428 _smart_edje_drag_h(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1433 _smart_scrollbar_read(sd);
1437 _smart_child_del_hook(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1442 sd->child_obj = NULL;
1443 _smart_scrollbar_size_adjust(sd);
1444 _smart_scrollbar_reset(sd);
1448 _smart_pan_changed_hook(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1454 sd->pan_func.child_size_get(sd->pan_obj, &w, &h);
1455 if ((w != sd->child.w) || (h != sd->child.h))
1459 _smart_scrollbar_size_adjust(sd);
1460 evas_object_size_hint_min_set(sd->smart_obj, sd->child.w, sd->child.h);
1461 _elm_smart_scroller_wanted_region_set(sd->smart_obj);
1466 _smart_pan_pan_changed_hook(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1471 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1472 (sd->scrollto.x.animator) || (sd->scrollto.y.animator))
1474 _smart_anim_stop(sd->smart_obj);
1476 if (sd->scrollto.x.animator)
1478 ecore_animator_del(sd->scrollto.x.animator);
1479 sd->scrollto.x.animator = NULL;
1481 if (sd->scrollto.y.animator)
1483 ecore_animator_del(sd->scrollto.y.animator);
1484 sd->scrollto.y.animator = NULL;
1486 if (sd->down.bounce_x_animator)
1488 ecore_animator_del(sd->down.bounce_x_animator);
1489 sd->down.bounce_x_animator = NULL;
1492 if (sd->down.bounce_y_animator)
1494 ecore_animator_del(sd->down.bounce_y_animator);
1495 sd->down.bounce_y_animator = NULL;
1498 _elm_smart_scroller_wanted_region_set(sd->smart_obj);
1502 _smart_event_wheel(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1504 Evas_Event_Mouse_Wheel *ev;
1506 Evas_Coord x = 0, y = 0;
1510 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
1511 if ((evas_key_modifier_is_set(ev->modifiers, "Control")) ||
1512 (evas_key_modifier_is_set(ev->modifiers, "Alt")) ||
1513 (evas_key_modifier_is_set(ev->modifiers, "Shift")) ||
1514 (evas_key_modifier_is_set(ev->modifiers, "Meta")) ||
1515 (evas_key_modifier_is_set(ev->modifiers, "Hyper")) ||
1516 (evas_key_modifier_is_set(ev->modifiers, "Super")))
1518 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1519 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1520 (sd->scrollto.x.animator) || (sd->scrollto.y.animator))
1522 _smart_anim_stop(sd->smart_obj);
1524 if (sd->scrollto.x.animator)
1526 ecore_animator_del(sd->scrollto.x.animator);
1527 sd->scrollto.x.animator = NULL;
1529 if (sd->scrollto.y.animator)
1531 ecore_animator_del(sd->scrollto.y.animator);
1532 sd->scrollto.y.animator = NULL;
1534 if (sd->down.bounce_x_animator)
1536 ecore_animator_del(sd->down.bounce_x_animator);
1537 sd->down.bounce_x_animator = NULL;
1540 if (sd->down.bounce_y_animator)
1542 ecore_animator_del(sd->down.bounce_y_animator);
1543 sd->down.bounce_y_animator = NULL;
1547 y += ev->z * sd->step.y;
1548 else if (ev->direction == 1)
1549 x += ev->z * sd->step.x;
1551 if ((!sd->hold) && (!sd->freeze))
1553 _update_wanted_coordinates(sd, x, y);
1554 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
1559 _smart_event_mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1561 Evas_Event_Mouse_Down *ev;
1563 Evas_Coord x = 0, y = 0;
1567 // if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
1568 if (_elm_config->thumbscroll_enable)
1571 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1572 (sd->down.momentum_animator) || (sd->scrollto.x.animator) ||
1573 (sd->scrollto.y.animator))
1575 ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL | EVAS_EVENT_FLAG_ON_HOLD;
1576 sd->down.scroll = 1;
1578 _smart_anim_stop(sd->smart_obj);
1580 if (sd->scrollto.x.animator)
1582 ecore_animator_del(sd->scrollto.x.animator);
1583 sd->scrollto.x.animator = NULL;
1585 if (sd->scrollto.y.animator)
1587 ecore_animator_del(sd->scrollto.y.animator);
1588 sd->scrollto.y.animator = NULL;
1590 if (sd->down.bounce_x_animator)
1592 ecore_animator_del(sd->down.bounce_x_animator);
1593 sd->down.bounce_x_animator = NULL;
1596 if (sd->down.bounce_y_animator)
1598 ecore_animator_del(sd->down.bounce_y_animator);
1599 sd->down.bounce_y_animator = NULL;
1602 if (sd->down.hold_animator)
1604 ecore_animator_del(sd->down.hold_animator);
1605 sd->down.hold_animator = NULL;
1606 _smart_drag_stop(sd->smart_obj);
1608 if (sd->down.momentum_animator)
1610 ecore_animator_del(sd->down.momentum_animator);
1611 sd->down.momentum_animator = NULL;
1612 sd->down.bounce_x_hold = 0;
1613 sd->down.bounce_y_hold = 0;
1617 if (ev->button == 1)
1620 sd->down.dragged = 0;
1623 sd->down.x = ev->canvas.x;
1624 sd->down.y = ev->canvas.y;
1625 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1628 sd->down.locked = 0;
1629 memset(&(sd->down.history[0]), 0, sizeof(sd->down.history[0]) * 20);
1631 sd->down.history[0].timestamp = ev->timestamp / 1000.0;
1633 sd->down.history[0].timestamp = ecore_loop_time_get();
1635 sd->down.history[0].x = ev->canvas.x;
1636 sd->down.history[0].y = ev->canvas.y;
1638 sd->down.dragged_began = 0;
1639 sd->down.hold_parent = 0;
1640 sd->down.cancelled = 0;
1645 _smart_hold_animator(void *data)
1647 Smart_Data *sd = data;
1650 elm_smart_scroller_child_pos_get(sd->smart_obj, &ox, &oy);
1653 if ((!sd->widget) ||
1654 (!elm_widget_drag_child_locked_x_get(sd->widget)))
1656 ox = sd->down.hold_x;
1661 if ((!sd->widget) ||
1662 (!elm_widget_drag_child_locked_y_get(sd->widget)))
1664 oy = sd->down.hold_y;
1667 elm_smart_scroller_child_pos_set(sd->smart_obj, ox, oy);
1668 return ECORE_CALLBACK_RENEW;
1672 _smart_event_post_up(void *data, Evas *e __UNUSED__)
1674 Smart_Data *sd = data;
1677 if (sd->down.dragged)
1679 elm_widget_drag_lock_x_set(sd->widget, 0);
1680 elm_widget_drag_lock_y_set(sd->widget, 0);
1687 _smart_event_mouse_up(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *event_info)
1689 Evas_Event_Mouse_Down *ev;
1691 Evas_Coord x = 0, y = 0, ox = 0, oy = 0;
1695 sd->down.hold_parent = 0;
1696 // if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
1697 evas_post_event_callback_push(e, _smart_event_post_up, sd);
1698 // FIXME: respect elm_widget_scroll_hold_get of parent container
1699 if (_elm_config->thumbscroll_enable)
1701 if (ev->button == 1)
1703 if (sd->down.onhold_animator)
1705 ecore_animator_del(sd->down.onhold_animator);
1706 sd->down.onhold_animator = NULL;
1708 x = ev->canvas.x - sd->down.x;
1709 y = ev->canvas.y - sd->down.y;
1710 if (sd->down.dragged)
1712 _smart_drag_stop(sd->smart_obj);
1713 if ((!sd->hold) && (!sd->freeze))
1717 Evas_Coord ax, ay, dx, dy, vel;
1720 t = ev->timestamp / 1000.0;
1722 t = ecore_loop_time_get();
1724 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1729 printf("------ %i %i\n", ev->canvas.x, ev->canvas.y);
1731 for (i = 0; i < 20; i++)
1733 dt = t - sd->down.history[i].timestamp;
1734 if (dt > 0.2) break;
1736 printf("H: %i %i @ %1.3f\n",
1737 sd->down.history[i].x,
1738 sd->down.history[i].y, dt);
1741 ax += sd->down.history[i].x;
1742 ay += sd->down.history[i].y;
1748 dx = ev->canvas.x - ax;
1749 dy = ev->canvas.y - ay;
1752 vel = sqrt((dx * dx) + (dy * dy)) / at;
1753 if ((_elm_config->thumbscroll_friction > 0.0) &&
1754 (vel > _elm_config->thumbscroll_momentum_threshold) &&
1757 sd->down.dx = ((double)dx / at);
1758 sd->down.dy = ((double)dy / at);
1759 if (((sd->down.dx > 0) && (sd->down.pdx > 0)) ||
1760 ((sd->down.dx < 0) && (sd->down.pdx < 0)))
1761 sd->down.dx += (double)sd->down.pdx * 1.5; // FIXME: * 1.5 - probably should be config
1762 if (((sd->down.dy > 0) && (sd->down.pdy > 0)) ||
1763 ((sd->down.dy < 0) && (sd->down.pdy < 0)))
1764 sd->down.dy += (double)sd->down.pdy * 1.5; // FIXME: * 1.5 - probably should be config
1765 if (((sd->down.dx > 0) && (sd->down.pdx > 0)) ||
1766 ((sd->down.dx < 0) && (sd->down.pdx < 0)) ||
1767 ((sd->down.dy > 0) && (sd->down.pdy > 0)) ||
1768 ((sd->down.dy < 0) && (sd->down.pdy < 0)))
1770 double t = ecore_loop_time_get();
1771 double dt = t - sd->down.anim_start;
1773 if (dt < 0.0) dt = 0.0;
1774 else if (dt > _elm_config->thumbscroll_friction)
1775 dt = _elm_config->thumbscroll_friction;
1776 sd->down.extra_time = _elm_config->thumbscroll_friction - dt;
1779 sd->down.extra_time = 0.0;
1780 sd->down.pdx = sd->down.dx;
1781 sd->down.pdy = sd->down.dy;
1784 if (!_smart_do_page(sd))
1786 if (!sd->down.momentum_animator && !sd->momentum_animator_disabled)
1788 sd->down.momentum_animator = ecore_animator_add(_smart_momentum_animator, sd);
1789 ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL;
1790 _smart_anim_start(sd->smart_obj);
1792 sd->down.anim_start = ecore_loop_time_get();
1793 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1801 if (sd->down.hold_animator)
1803 ecore_animator_del(sd->down.hold_animator);
1804 sd->down.hold_animator = NULL;
1812 evas_event_feed_hold(e, 0, ev->timestamp, ev->data);
1813 if (_smart_do_page(sd))
1815 Evas_Coord pgx, pgy;
1817 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1818 if ((!sd->widget) ||
1819 (!elm_widget_drag_child_locked_x_get(sd->widget)))
1821 pgx = _smart_page_x_get(sd, ox);
1824 ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL;
1825 _smart_scrollto_x(sd, _elm_config->page_scroll_friction, pgx);
1828 if ((!sd->widget) ||
1829 (!elm_widget_drag_child_locked_y_get(sd->widget)))
1831 pgy = _smart_page_y_get(sd, oy);
1834 ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL;
1835 _smart_scrollto_y(sd, _elm_config->page_scroll_friction, pgy);
1844 if (_smart_do_page(sd))
1846 Evas_Coord pgx, pgy;
1848 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1849 if ((!sd->widget) ||
1850 (!elm_widget_drag_child_locked_x_get(sd->widget)))
1852 pgx = _smart_page_x_get(sd, ox);
1853 if (pgx != x) _smart_scrollto_x(sd, _elm_config->page_scroll_friction, pgx);
1855 if ((!sd->widget) ||
1856 (!elm_widget_drag_child_locked_y_get(sd->widget)))
1858 pgy = _smart_page_y_get(sd, oy);
1859 if (pgy != y) _smart_scrollto_y(sd, _elm_config->page_scroll_friction, pgy);
1862 if (sd->down.hold_animator)
1864 ecore_animator_del(sd->down.hold_animator);
1865 sd->down.hold_animator = NULL;
1868 if (sd->down.scroll)
1870 ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL;
1871 sd->down.scroll = 0;
1875 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1878 sd->down.dragged_began = 0;
1881 sd->down.want_dragged = 0;
1882 sd->down.dragged = 0;
1884 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1885 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
1886 _update_wanted_coordinates(sd, x, y);
1888 if (!_smart_do_page(sd))
1895 _smart_onhold_animator(void *data)
1900 Evas_Coord x, y, ox, oy;
1903 t = ecore_loop_time_get();
1904 if (sd->down.onhold_tlast > 0.0)
1906 td = t - sd->down.onhold_tlast;
1907 vx = sd->down.onhold_vx * td * (double)_elm_config->thumbscroll_threshold * 2.0;
1908 vy = sd->down.onhold_vy * td * (double)_elm_config->thumbscroll_threshold * 2.0;
1909 elm_smart_scroller_child_pos_get(sd->smart_obj, &ox, &oy);
1915 if ((!sd->widget) ||
1916 (!elm_widget_drag_child_locked_x_get(sd->widget)))
1918 sd->down.onhold_vxe += vx;
1919 x = ox + (int)sd->down.onhold_vxe;
1920 sd->down.onhold_vxe -= (int)sd->down.onhold_vxe;
1926 if ((!sd->widget) ||
1927 (!elm_widget_drag_child_locked_y_get(sd->widget)))
1929 sd->down.onhold_vye += vy;
1930 y = oy + (int)sd->down.onhold_vye;
1931 sd->down.onhold_vye -= (int)sd->down.onhold_vye;
1935 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
1937 sd->down.onhold_tlast = t;
1938 return ECORE_CALLBACK_RENEW;
1942 _smart_event_post_move(void *data, Evas *e __UNUSED__)
1944 Smart_Data *sd = data;
1946 if (sd->down.want_dragged)
1950 if (sd->down.hold_parent)
1952 if ((sd->down.dir_x) && !can_scroll(sd, sd->down.hdir))
1956 if ((sd->down.dir_y) && !can_scroll(sd, sd->down.vdir))
1963 if ((!sd->widget) ||
1964 (!elm_widget_drag_child_locked_x_get(sd->widget)))
1966 sd->down.want_dragged = 0;
1967 sd->down.dragged = 1;
1970 elm_widget_drag_lock_x_set(sd->widget, 1);
1979 if ((!sd->widget) ||
1980 (!elm_widget_drag_child_locked_y_get(sd->widget)))
1982 sd->down.want_dragged = 0;
1983 sd->down.dragged = 1;
1986 elm_widget_drag_lock_y_set(sd->widget, 1);
1993 if ((!sd->down.dir_x) && (!sd->down.dir_y))
1995 sd->down.cancelled = 1;
1997 if (start) _smart_drag_start(sd->smart_obj);
2003 _smart_event_mouse_move(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *event_info)
2005 Evas_Event_Mouse_Move *ev;
2007 Evas_Coord x = 0, y = 0;
2011 // if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
2012 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) sd->down.hold_parent = 1;
2013 evas_post_event_callback_push(e, _smart_event_post_move, sd);
2014 // FIXME: respect elm_widget_scroll_hold_get of parent container
2015 if (_elm_config->thumbscroll_enable)
2022 printf("::: %i %i\n", ev->cur.canvas.x, ev->cur.canvas.y);
2024 memmove(&(sd->down.history[1]), &(sd->down.history[0]),
2025 sizeof(sd->down.history[0]) * 19);
2027 sd->down.history[0].timestamp = ev->timestamp / 1000.0;
2029 sd->down.history[0].timestamp = ecore_loop_time_get();
2031 sd->down.history[0].x = ev->cur.canvas.x;
2032 sd->down.history[0].y = ev->cur.canvas.y;
2034 if (!sd->down.dragged_began)
2036 x = ev->cur.canvas.x - sd->down.x;
2037 y = ev->cur.canvas.y - sd->down.y;
2042 if (x > 0) sd->down.hdir = LEFT;
2043 else if (x < 0) sd->down.hdir = RIGHT;
2044 if (y > 0) sd->down.vdir = UP;
2045 else if (y < 0) sd->down.vdir = DOWN;
2050 if ((sd->one_dir_at_a_time) &&
2051 (!((sd->down.dir_x) || (sd->down.dir_y))))
2053 if (x > _elm_config->thumbscroll_threshold)
2062 if (y > _elm_config->thumbscroll_threshold)
2079 // can_scroll(sd, LEFT);
2080 // can_scroll(sd, RIGHT);
2081 // can_scroll(sd, UP);
2082 // can_scroll(sd, DOWN);
2087 if ((!sd->hold) && (!sd->freeze))
2089 if ((sd->down.dragged) ||
2090 (((x * x) + (y * y)) >
2091 (_elm_config->thumbscroll_threshold *
2092 _elm_config->thumbscroll_threshold)))
2094 sd->down.dragged_began = 1;
2095 if (!sd->down.dragged)
2097 sd->down.want_dragged = 1;
2098 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2099 // evas_event_feed_hold(e, 1, ev->timestamp, ev->data);
2100 // _smart_drag_start(sd->smart_obj);
2102 if (sd->down.dragged)
2104 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2106 // ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2107 // sd->down.dragged = 1;
2109 x = sd->down.sx - (ev->cur.canvas.x - sd->down.x);
2113 y = sd->down.sy - (ev->cur.canvas.y - sd->down.y);
2116 if ((sd->down.dir_x) || (sd->down.dir_y))
2118 if (!sd->down.locked)
2120 sd->down.locked_x = x;
2121 sd->down.locked_y = y;
2122 sd->down.locked = 1;
2124 if (!((sd->down.dir_x) && (sd->down.dir_y)))
2126 if (sd->down.dir_x) y = sd->down.locked_y;
2127 else x = sd->down.locked_x;
2130 if (_elm_config->thumbscroll_border_friction > 0.0)
2132 Evas_Coord minx, miny;
2133 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2136 _elm_config->thumbscroll_border_friction;
2137 else if (sd->child.h <= sd->h)
2138 y += (sd->down.sy - y) *
2139 _elm_config->thumbscroll_border_friction;
2140 else if ((sd->child.h - sd->h + miny) < y)
2141 y += (sd->child.h - sd->h + miny - y) *
2142 _elm_config->thumbscroll_border_friction;
2145 _elm_config->thumbscroll_border_friction;
2146 else if (sd->child.w <= sd->w)
2147 x += (sd->down.sx - x) *
2148 _elm_config->thumbscroll_border_friction;
2149 else if ((sd->child.w - sd->w + minx) < x)
2150 x += (sd->child.w - sd->w + minx - x) *
2151 _elm_config->thumbscroll_border_friction;
2154 sd->down.hold_x = x;
2155 sd->down.hold_y = y;
2156 if (!sd->down.hold_animator)
2157 sd->down.hold_animator =
2158 ecore_animator_add(_smart_hold_animator, sd);
2159 // printf("a %i %i\n", sd->down.hold_x, sd->down.hold_y);
2160 // _smart_onhold_animator(sd);
2161 // elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
2165 if (sd->down.dragged_began)
2167 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2171 evas_event_feed_hold(e, 1, ev->timestamp, ev->data);
2176 else if (!sd->freeze)
2178 Evas_Coord ex, ey, ew, eh;
2179 double vx = 0.0, vy = 0.0;
2181 evas_object_geometry_get(sd->event_obj, &ex, &ey, &ew, &eh);
2182 x = ev->cur.canvas.x - ex;
2183 y = ev->cur.canvas.y - ey;
2184 if (x < _elm_config->thumbscroll_threshold)
2186 if (_elm_config->thumbscroll_threshold > 0.0)
2187 vx = -(double)(_elm_config->thumbscroll_threshold - x) /
2188 _elm_config->thumbscroll_threshold;
2192 else if (x > (ew - _elm_config->thumbscroll_threshold))
2194 if (_elm_config->thumbscroll_threshold > 0.0)
2195 vx = (double)(_elm_config->thumbscroll_threshold - (ew - x)) /
2196 _elm_config->thumbscroll_threshold;
2200 if (y < _elm_config->thumbscroll_threshold)
2202 if (_elm_config->thumbscroll_threshold > 0.0)
2203 vy = -(double)(_elm_config->thumbscroll_threshold - y) /
2204 _elm_config->thumbscroll_threshold;
2208 else if (y > (eh - _elm_config->thumbscroll_threshold))
2210 if (_elm_config->thumbscroll_threshold > 0.0)
2211 vy = (double)(_elm_config->thumbscroll_threshold - (eh - y)) /
2212 _elm_config->thumbscroll_threshold;
2216 if ((vx != 0.0) || (vy != 0.0))
2218 sd->down.onhold_vx = vx;
2219 sd->down.onhold_vy = vy;
2220 if (!sd->down.onhold_animator)
2222 sd->down.onhold_vxe = 0.0;
2223 sd->down.onhold_vye = 0.0;
2224 sd->down.onhold_tlast = 0.0;
2225 sd->down.onhold_animator = ecore_animator_add(_smart_onhold_animator, sd);
2227 // printf("b %i %i\n", sd->down.hold_x, sd->down.hold_y);
2231 if (sd->down.onhold_animator)
2233 ecore_animator_del(sd->down.onhold_animator);
2234 sd->down.onhold_animator = NULL;
2243 _smart_scrollbar_read(Smart_Data *sd)
2245 Evas_Coord x, y, mx = 0, my = 0, px, py, minx = 0, miny = 0;
2248 edje_object_part_drag_value_get(sd->edje_obj, "elm.dragable.vbar", NULL, &vy);
2249 edje_object_part_drag_value_get(sd->edje_obj, "elm.dragable.hbar", &vx, NULL);
2250 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
2251 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2252 x = vx * (double)mx + minx;
2253 y = vy * (double)my + miny;
2254 sd->pan_func.get(sd->pan_obj, &px, &py);
2255 sd->pan_func.set(sd->pan_obj, x, y);
2256 if ((px != x) || (py != y))
2257 edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
2261 _smart_scrollbar_reset(Smart_Data *sd)
2263 Evas_Coord px = 0, py = 0, minx = 0, miny = 0;
2265 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.vbar", 0.0, 0.0);
2266 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.hbar", 0.0, 0.0);
2267 if ((!sd->child_obj) && (!sd->extern_pan))
2269 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.vbar", 1.0, 1.0);
2270 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.hbar", 1.0, 1.0);
2272 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2273 sd->pan_func.get(sd->pan_obj, &px, &py);
2274 sd->pan_func.set(sd->pan_obj, minx, miny);
2275 if ((px != minx) || (py != miny))
2276 edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
2280 _smart_scrollbar_bar_v_visibility_adjust(Smart_Data *sd)
2282 int scroll_v_vis_change = 0;
2283 Evas_Coord h, vw, vh;
2286 evas_object_geometry_get(sd->pan_obj, NULL, NULL, &vw, &vh);
2287 if (sd->vbar_visible)
2289 if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_AUTO)
2291 if ((sd->child_obj) || (sd->extern_pan))
2295 scroll_v_vis_change = 1;
2296 sd->vbar_visible = 0;
2301 scroll_v_vis_change = 1;
2302 sd->vbar_visible = 0;
2305 else if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
2307 scroll_v_vis_change = 1;
2308 sd->vbar_visible = 0;
2313 if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_AUTO)
2315 if ((sd->child_obj) || (sd->extern_pan))
2319 scroll_v_vis_change = 1;
2320 sd->vbar_visible = 1;
2324 else if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
2326 scroll_v_vis_change = 1;
2327 sd->vbar_visible = 1;
2330 if (scroll_v_vis_change)
2332 if (sd->vbar_flags != ELM_SMART_SCROLLER_POLICY_OFF)
2334 if (sd->vbar_visible)
2335 edje_object_signal_emit(sd->edje_obj, "elm,action,show,vbar", "elm");
2337 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,vbar", "elm");
2338 edje_object_message_signal_process(sd->edje_obj);
2339 _smart_scrollbar_size_adjust(sd);
2342 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,vbar", "elm");
2344 return scroll_v_vis_change;
2348 _smart_scrollbar_bar_h_visibility_adjust(Smart_Data *sd)
2350 int scroll_h_vis_change = 0;
2351 Evas_Coord w, vw, vh;
2354 evas_object_geometry_get(sd->pan_obj, NULL, NULL, &vw, &vh);
2355 if (sd->hbar_visible)
2357 if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_AUTO)
2359 if ((sd->child_obj) || (sd->extern_pan))
2363 scroll_h_vis_change = 1;
2364 sd->hbar_visible = 0;
2369 scroll_h_vis_change = 1;
2370 sd->hbar_visible = 0;
2373 else if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
2375 scroll_h_vis_change = 1;
2376 sd->hbar_visible = 0;
2381 if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_AUTO)
2383 if ((sd->child_obj) || (sd->extern_pan))
2387 scroll_h_vis_change = 1;
2388 sd->hbar_visible = 1;
2392 else if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
2394 scroll_h_vis_change = 1;
2395 sd->hbar_visible = 1;
2398 if (scroll_h_vis_change)
2400 if (sd->hbar_flags != ELM_SMART_SCROLLER_POLICY_OFF)
2402 if (sd->hbar_visible)
2403 edje_object_signal_emit(sd->edje_obj, "elm,action,show,hbar", "elm");
2405 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,hbar", "elm");
2406 edje_object_message_signal_process(sd->edje_obj);
2407 _smart_scrollbar_size_adjust(sd);
2410 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,hbar", "elm");
2411 _smart_scrollbar_size_adjust(sd);
2413 return scroll_h_vis_change;
2417 _smart_scrollbar_bar_visibility_adjust(Smart_Data *sd)
2421 changed |= _smart_scrollbar_bar_h_visibility_adjust(sd);
2422 changed |= _smart_scrollbar_bar_v_visibility_adjust(sd);
2425 _smart_scrollbar_bar_h_visibility_adjust(sd);
2426 _smart_scrollbar_bar_v_visibility_adjust(sd);
2431 _smart_scrollbar_size_adjust(Smart_Data *sd)
2433 if ((sd->child_obj) || (sd->extern_pan))
2435 Evas_Coord x, y, w, h, mx = 0, my = 0, vw = 0, vh = 0, px, py, minx = 0, miny = 0;
2436 double vx, vy, size;
2438 edje_object_part_geometry_get(sd->edje_obj, "elm.swallow.content",
2439 NULL, NULL, &vw, &vh);
2442 size = (double)vw / (double)w;
2446 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.hbar", 0.0, 0.0);
2448 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.hbar", size, 1.0);
2452 size = (double)vh / (double)h;
2456 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.vbar", 0.0, 0.0);
2458 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.vbar", 1.0, size);
2460 edje_object_part_drag_value_get(sd->edje_obj, "elm.dragable.hbar", &vx, NULL);
2461 edje_object_part_drag_value_get(sd->edje_obj, "elm.dragable.vbar", NULL, &vy);
2462 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
2463 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2467 edje_object_part_drag_step_set(sd->edje_obj, "elm.dragable.hbar", (double)sd->step.x / (double)w, 0.0);
2468 edje_object_part_drag_step_set(sd->edje_obj, "elm.dragable.vbar", 0.0, (double)sd->step.y / (double)h);
2470 edje_object_part_drag_page_set(sd->edje_obj, "elm.dragable.hbar", (double)sd->page.x / (double)w, 0.0);
2472 edje_object_part_drag_page_set(sd->edje_obj, "elm.dragable.hbar", -((double)sd->page.x * ((double)vw / (double)w)) / 100.0, 0.0);
2474 edje_object_part_drag_page_set(sd->edje_obj, "elm.dragable.vbar", 0.0, (double)sd->page.y / (double)h);
2476 edje_object_part_drag_page_set(sd->edje_obj, "elm.dragable.vbar", 0.0, -((double)sd->page.y * ((double)vh / (double)h)) / 100.0);
2478 sd->pan_func.get(sd->pan_obj, &px, &py);
2479 if (vx != mx) x = px;
2480 if (vy != my) y = py;
2481 sd->pan_func.set(sd->pan_obj, x, y);
2482 // if ((px != 0) || (py != 0))
2483 // edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
2487 Evas_Coord px = 0, py = 0, minx = 0, miny = 0;
2489 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.vbar", 1.0, 1.0);
2490 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.hbar", 1.0, 1.0);
2491 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2492 sd->pan_func.get(sd->pan_obj, &px, &py);
2493 sd->pan_func.set(sd->pan_obj, minx, miny);
2494 if ((px != minx) || (py != miny))
2495 edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
2497 _smart_scrollbar_bar_visibility_adjust(sd);
2501 _smart_reconfigure(Smart_Data *sd)
2503 evas_object_move(sd->edje_obj, sd->x, sd->y);
2504 evas_object_resize(sd->edje_obj, sd->w, sd->h);
2505 evas_object_move(sd->event_obj, sd->x, sd->y);
2506 evas_object_resize(sd->event_obj, sd->w, sd->h);
2507 _smart_scrollbar_size_adjust(sd);
2511 _smart_add(Evas_Object *obj)
2516 sd = calloc(1, sizeof(Smart_Data));
2518 evas_object_smart_data_set(obj, sd);
2520 sd->smart_obj = obj;
2529 sd->hbar_flags = ELM_SMART_SCROLLER_POLICY_AUTO;
2530 sd->vbar_flags = ELM_SMART_SCROLLER_POLICY_AUTO;
2531 sd->hbar_visible = 1;
2532 sd->vbar_visible = 1;
2534 sd->bounce_horiz = 1;
2535 sd->bounce_vert = 1;
2537 sd->one_dir_at_a_time = 1;
2538 sd->momentum_animator_disabled = 0;
2539 sd->bounce_animator_disabled = 0;
2541 o = edje_object_add(evas_object_evas_get(obj));
2542 evas_object_propagate_events_set(o, 0);
2544 // FIXME: null parent obj ... :(
2545 elm_smart_scroller_object_theme_set(NULL, obj, "scroller", "base", "default");
2546 edje_object_signal_callback_add(o, "drag", "elm.dragable.vbar", _smart_edje_drag_v, sd);
2547 edje_object_signal_callback_add(o, "drag,start", "elm.dragable.vbar", _smart_edje_drag_v_start, sd);
2548 edje_object_signal_callback_add(o, "drag,stop", "elm.dragable.vbar", _smart_edje_drag_v_stop, sd);
2549 edje_object_signal_callback_add(o, "drag,step", "elm.dragable.vbar", _smart_edje_drag_v, sd);
2550 edje_object_signal_callback_add(o, "drag,page", "elm.dragable.vbar", _smart_edje_drag_v, sd);
2551 edje_object_signal_callback_add(o, "drag", "elm.dragable.hbar", _smart_edje_drag_h, sd);
2552 edje_object_signal_callback_add(o, "drag,start", "elm.dragable.hbar", _smart_edje_drag_h_start, sd);
2553 edje_object_signal_callback_add(o, "drag,stop", "elm.dragable.hbar", _smart_edje_drag_h_stop, sd);
2554 edje_object_signal_callback_add(o, "drag,step", "elm.dragable.hbar", _smart_edje_drag_h, sd);
2555 edje_object_signal_callback_add(o, "drag,page", "elm.dragable.hbar", _smart_edje_drag_h, sd);
2556 evas_object_smart_member_add(o, obj);
2558 o = evas_object_rectangle_add(evas_object_evas_get(obj));
2560 evas_object_color_set(o, 0, 0, 0, 0);
2561 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_WHEEL, _smart_event_wheel, sd);
2562 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, _smart_event_mouse_down, sd);
2563 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_UP, _smart_event_mouse_up, sd);
2564 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_MOVE, _smart_event_mouse_move, sd);
2565 evas_object_smart_member_add(o, obj);
2566 evas_object_repeat_events_set(o, 1);
2568 sd->pan_func.set = _elm_smart_pan_set;
2569 sd->pan_func.get = _elm_smart_pan_get;
2570 sd->pan_func.max_get = _elm_smart_pan_max_get;
2571 sd->pan_func.min_get = _elm_smart_pan_min_get;
2572 sd->pan_func.child_size_get = _elm_smart_pan_child_size_get;
2574 _smart_scrollbar_reset(sd);
2578 _smart_del(Evas_Object *obj)
2581 elm_smart_scroller_child_set(obj, NULL);
2582 if (!sd->extern_pan) evas_object_del(sd->pan_obj);
2583 evas_object_del(sd->edje_obj);
2584 evas_object_del(sd->event_obj);
2585 if (sd->down.hold_animator) ecore_animator_del(sd->down.hold_animator);
2586 if (sd->down.onhold_animator) ecore_animator_del(sd->down.onhold_animator);
2587 if (sd->down.momentum_animator) ecore_animator_del(sd->down.momentum_animator);
2588 if (sd->down.bounce_x_animator) ecore_animator_del(sd->down.bounce_x_animator);
2589 if (sd->down.bounce_y_animator) ecore_animator_del(sd->down.bounce_y_animator);
2590 if (sd->scrollto.x.animator) ecore_animator_del(sd->scrollto.x.animator);
2591 if (sd->scrollto.y.animator) ecore_animator_del(sd->scrollto.y.animator);
2593 evas_object_smart_data_set(obj, NULL);
2597 _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
2602 _smart_reconfigure(sd);
2606 _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
2611 _smart_reconfigure(sd);
2612 _elm_smart_scroller_wanted_region_set(obj);
2616 _smart_show(Evas_Object *obj)
2619 evas_object_show(sd->edje_obj);
2620 evas_object_show(sd->event_obj);
2624 _smart_hide(Evas_Object *obj)
2627 evas_object_hide(sd->edje_obj);
2628 evas_object_hide(sd->event_obj);
2632 _smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
2635 evas_object_color_set(sd->edje_obj, r, g, b, a);
2639 _smart_clip_set(Evas_Object *obj, Evas_Object *clip)
2642 evas_object_clip_set(sd->edje_obj, clip);
2643 evas_object_clip_set(sd->event_obj, clip);
2647 _smart_clip_unset(Evas_Object *obj)
2650 evas_object_clip_unset(sd->edje_obj);
2651 evas_object_clip_unset(sd->event_obj);
2654 /* never need to touch this */
2661 static const Evas_Smart_Class sc =
2664 EVAS_SMART_CLASS_VERSION,
2682 _smart = evas_smart_class_new(&sc);