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);
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, child);
223 sd->pan_func.child_size_get(sd->pan_obj, &w, &h);
226 _smart_scrollbar_size_adjust(sd);
227 _smart_scrollbar_reset(sd);
231 elm_smart_scroller_extern_pan_set(Evas_Object *obj, Evas_Object *pan,
232 void (*pan_set) (Evas_Object *obj, Evas_Coord x, Evas_Coord y),
233 void (*pan_get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y),
234 void (*pan_max_get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y),
235 void (*pan_min_get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y),
236 void (*pan_child_size_get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y))
240 elm_smart_scroller_child_set(obj, NULL);
244 evas_object_smart_callback_del(sd->pan_obj, "changed", _smart_pan_changed_hook);
245 evas_object_smart_callback_del(sd->pan_obj, "pan_changed", _smart_pan_pan_changed_hook);
252 edje_object_part_unswallow(sd->edje_obj, sd->pan_obj);
260 evas_object_del(sd->pan_obj);
271 sd->pan_func.set = pan_set;
272 sd->pan_func.get = pan_get;
273 sd->pan_func.max_get = pan_max_get;
274 sd->pan_func.min_get = pan_min_get;
275 sd->pan_func.child_size_get = pan_child_size_get;
277 evas_object_smart_callback_add(sd->pan_obj, "changed", _smart_pan_changed_hook, sd);
278 evas_object_smart_callback_add(sd->pan_obj, "pan_changed", _smart_pan_pan_changed_hook, sd);
279 edje_object_part_swallow(sd->edje_obj, "elm.swallow.content", sd->pan_obj);
280 evas_object_show(sd->pan_obj);
284 elm_smart_scroller_custom_edje_file_set(Evas_Object *obj, char *file, char *group)
288 edje_object_file_set(sd->edje_obj, file, group);
290 edje_object_part_swallow(sd->edje_obj, "elm.swallow.content", sd->pan_obj);
291 sd->vbar_visible = !sd->vbar_visible;
292 sd->hbar_visible = !sd->hbar_visible;
293 _smart_scrollbar_bar_visibility_adjust(sd);
294 if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
295 edje_object_signal_emit(sd->edje_obj, "elm,action,show_always,hbar", "elm");
296 else if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
297 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,hbar", "elm");
299 edje_object_signal_emit(sd->edje_obj, "elm,action,show_notalways,hbar", "elm");
300 if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
301 edje_object_signal_emit(sd->edje_obj, "elm,action,show_always,vbar", "elm");
302 else if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
303 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,vbar", "elm");
305 edje_object_signal_emit(sd->edje_obj, "elm,action,show_notalways,vbar", "elm");
309 elm_smart_scroller_momentum_animator_disabled_get(Evas_Object *obj)
311 API_ENTRY return EINA_FALSE;
312 return sd->momentum_animator_disabled;
316 elm_smart_scroller_momentum_animator_disabled_set(Evas_Object *obj, Eina_Bool disabled)
319 sd->momentum_animator_disabled = disabled;
320 if (sd->momentum_animator_disabled)
322 if (sd->down.momentum_animator)
324 ecore_animator_del(sd->down.momentum_animator);
325 sd->down.momentum_animator = NULL;
331 elm_smart_scroller_bounce_animator_disabled_get(Evas_Object *obj)
333 API_ENTRY return EINA_FALSE;
334 return sd->bounce_animator_disabled;
338 elm_smart_scroller_bounce_animator_disabled_set(Evas_Object *obj, Eina_Bool disabled)
341 sd->bounce_animator_disabled = disabled;
342 if (sd->bounce_animator_disabled)
344 if (sd->scrollto.x.animator)
346 ecore_animator_del(sd->scrollto.x.animator);
347 sd->scrollto.x.animator = NULL;
350 if (sd->scrollto.y.animator)
352 ecore_animator_del(sd->scrollto.y.animator);
353 sd->scrollto.y.animator = NULL;
358 /* Update the wanted coordinates according to the x, y passed
359 * widget directionality, child size and etc. */
361 _update_wanted_coordinates(Smart_Data *sd, Evas_Coord x, Evas_Coord y)
365 sd->pan_func.child_size_get(sd->pan_obj, &cw, &ch);
367 /* Update wx/y/w/h - and if the requested positions aren't legal
369 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &sd->ww, &sd->wh);
372 else if ((x + sd->ww) > cw)
373 sd->wx = cw - sd->ww;
374 else if (sd->is_mirrored)
375 sd->wx = _elm_smart_scroller_x_mirrored_get(sd->smart_obj, x);
378 if (y < 0) sd->wy = 0;
379 else if ((y + sd->wh) > ch) sd->wy = ch - sd->wh;
384 _smart_anim_start(Evas_Object *obj)
386 evas_object_smart_callback_call(obj, "animate,start", NULL);
390 _smart_anim_stop(Evas_Object *obj)
392 evas_object_smart_callback_call(obj, "animate,stop", NULL);
396 _smart_drag_start(Evas_Object *obj)
398 evas_object_smart_callback_call(obj, "drag,start", NULL);
402 _smart_drag_stop(Evas_Object *obj)
404 evas_object_smart_callback_call(obj, "drag,stop", NULL);
408 _smart_scrollto_x_animator(void *data)
410 Smart_Data *sd = data;
414 t = ecore_loop_time_get();
415 tt = (t - sd->scrollto.x.t_start) / (sd->scrollto.x.t_end - sd->scrollto.x.t_start);
417 tt = 1.0 - (tt * tt);
418 sd->pan_func.get(sd->pan_obj, &px, &py);
419 px = (sd->scrollto.x.start * (1.0 - tt)) +
420 (sd->scrollto.x.end * tt);
421 if (t >= sd->scrollto.x.t_end)
423 px = sd->scrollto.x.end;
424 elm_smart_scroller_child_pos_set(sd->smart_obj, px, py);
425 sd->scrollto.x.animator = NULL;
426 if ((!sd->scrollto.y.animator) && (!sd->down.bounce_y_animator))
427 _smart_anim_stop(sd->smart_obj);
428 return ECORE_CALLBACK_CANCEL;
430 elm_smart_scroller_child_pos_set(sd->smart_obj, px, py);
431 return ECORE_CALLBACK_RENEW;
435 _smart_momentum_end(Smart_Data *sd)
437 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator)) return;
438 if (sd->down.momentum_animator)
441 elm_smart_scroller_child_pos_get(sd->smart_obj, &px, &py);
442 _update_wanted_coordinates(sd, px, py);
444 ecore_animator_del(sd->down.momentum_animator);
445 sd->down.momentum_animator = NULL;
446 sd->down.bounce_x_hold = 0;
447 sd->down.bounce_y_hold = 0;
456 _smart_scrollto_x(Smart_Data *sd, double t_in, Evas_Coord pos_x)
458 Evas_Coord px, py, x, y, w, h;
461 if (sd->freeze) return;
464 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
465 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
467 elm_smart_scroller_child_region_set(sd->smart_obj, x, y, w, h);
470 t = ecore_loop_time_get();
471 sd->pan_func.get(sd->pan_obj, &px, &py);
472 sd->scrollto.x.start = px;
473 sd->scrollto.x.end = pos_x;
474 sd->scrollto.x.t_start = t;
475 sd->scrollto.x.t_end = t + t_in;
476 if (!sd->scrollto.x.animator)
478 if (!sd->scrollto.y.animator)
479 _smart_anim_start(sd->smart_obj);
480 sd->scrollto.x.animator = ecore_animator_add(_smart_scrollto_x_animator, sd);
482 if (sd->down.bounce_x_animator)
484 ecore_animator_del(sd->down.bounce_x_animator);
485 sd->down.bounce_x_animator = NULL;
486 _smart_momentum_end(sd);
492 _smart_scrollto_y_animator(void *data)
494 Smart_Data *sd = data;
498 t = ecore_loop_time_get();
499 tt = (t - sd->scrollto.y.t_start) / (sd->scrollto.y.t_end - sd->scrollto.y.t_start);
501 tt = 1.0 - (tt * tt);
502 sd->pan_func.get(sd->pan_obj, &px, &py);
503 py = (sd->scrollto.y.start * (1.0 - tt)) +
504 (sd->scrollto.y.end * tt);
505 if (t >= sd->scrollto.y.t_end)
507 py = sd->scrollto.y.end;
508 elm_smart_scroller_child_pos_set(sd->smart_obj, px, py);
509 sd->scrollto.y.animator = NULL;
510 if ((!sd->scrollto.x.animator) && (!sd->down.bounce_x_animator))
511 _smart_anim_stop(sd->smart_obj);
512 return ECORE_CALLBACK_CANCEL;
514 elm_smart_scroller_child_pos_set(sd->smart_obj, px, py);
516 return ECORE_CALLBACK_RENEW;
520 _smart_scrollto_y(Smart_Data *sd, double t_in, Evas_Coord pos_y)
522 Evas_Coord px, py, x, y, w, h;
525 if (sd->freeze) return;
528 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
529 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
531 elm_smart_scroller_child_region_set(sd->smart_obj, x, y, w, h);
534 t = ecore_loop_time_get();
535 sd->pan_func.get(sd->pan_obj, &px, &py);
536 sd->scrollto.y.start = py;
537 sd->scrollto.y.end = pos_y;
538 sd->scrollto.y.t_start = t;
539 sd->scrollto.y.t_end = t + t_in;
540 if (!sd->scrollto.y.animator)
542 if (!sd->scrollto.x.animator)
543 _smart_anim_start(sd->smart_obj);
544 sd->scrollto.y.animator = ecore_animator_add(_smart_scrollto_y_animator, sd);
546 if (sd->down.bounce_y_animator)
548 ecore_animator_del(sd->down.bounce_y_animator);
549 sd->down.bounce_y_animator = NULL;
550 _smart_momentum_end(sd);
556 _smart_do_page(Smart_Data *sd)
558 if ((sd->pagerel_h == 0.0) && (!sd->pagesize_h) &&
559 (sd->pagerel_v == 0.0) && (!sd->pagesize_v))
565 _smart_page_x_get(Smart_Data *sd, int offset)
567 Evas_Coord x, y, w, h, cw, ch, minx = 0;
569 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
570 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
571 sd->pan_func.child_size_get(sd->pan_obj, &cw, &ch);
572 sd->pan_func.min_get(sd->pan_obj, &minx, NULL);
576 if (sd->pagerel_h > 0.0)
578 x = x + (w * sd->pagerel_h * 0.5);
579 x = x / (w * sd->pagerel_h);
580 x = x * (w * sd->pagerel_h);
582 else if (sd->pagesize_h > 0)
584 x = x + (sd->pagesize_h * 0.5);
585 x = x / (sd->pagesize_h);
586 x = x * (sd->pagesize_h);
588 if (x < minx) x = minx;
589 else if ((x + w) > cw) x = cw - w;
594 _smart_page_y_get(Smart_Data *sd, int offset)
596 Evas_Coord x, y, w, h, cw, ch, miny = 0;
598 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
599 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
600 sd->pan_func.child_size_get(sd->pan_obj, &cw, &ch);
601 sd->pan_func.min_get(sd->pan_obj, NULL, &miny);
605 if (sd->pagerel_v > 0.0)
607 y = y + (h * sd->pagerel_v * 0.5);
608 y = y / (h * sd->pagerel_v);
609 y = y * (h * sd->pagerel_v);
611 else if (sd->pagesize_v > 0)
613 y = y + (sd->pagesize_v * 0.5);
614 y = y / (sd->pagesize_v);
615 y = y * (sd->pagesize_v);
617 if (y < miny) y = miny;
618 else if ((y + h) > ch) y = ch - h;
623 _smart_page_adjust(Smart_Data *sd)
625 Evas_Coord x, y, w, h;
627 if (!_smart_do_page(sd)) return;
629 elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
631 x = _smart_page_x_get(sd, 0);
632 y = _smart_page_y_get(sd, 0);
634 elm_smart_scroller_child_region_set(sd->smart_obj, x, y, w, h);
638 _smart_bounce_x_animator(void *data)
645 t = ecore_loop_time_get();
646 dt = t - sd->down.anim_start2;
649 dt = dt / _elm_config->thumbscroll_bounce_friction;
650 if (dt > 1.0) dt = 1.0;
651 p = 1.0 - ((1.0 - dt) * (1.0 - dt));
652 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
653 dx = sd->down.b2x - sd->down.bx;
655 x = sd->down.bx + dx;
656 if (!sd->down.cancelled)
657 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
660 if (sd->down.momentum_animator)
661 sd->down.bounce_x_hold = 1;
662 else if ((!sd->down.bounce_y_animator) &&
663 (!sd->scrollto.y.animator))
664 _smart_anim_stop(sd->smart_obj);
665 sd->down.bounce_x_animator = NULL;
668 _smart_momentum_end(sd);
669 return ECORE_CALLBACK_CANCEL;
672 return ECORE_CALLBACK_RENEW;
676 _smart_bounce_y_animator(void *data)
683 t = ecore_loop_time_get();
684 dt = t - sd->down.anim_start3;
687 dt = dt / _elm_config->thumbscroll_bounce_friction;
688 if (dt > 1.0) dt = 1.0;
689 p = 1.0 - ((1.0 - dt) * (1.0 - dt));
690 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
691 dy = sd->down.b2y - sd->down.by;
693 y = sd->down.by + dy;
694 if (!sd->down.cancelled)
695 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
698 if (sd->down.momentum_animator)
699 sd->down.bounce_y_hold = 1;
700 else if ((!sd->down.bounce_x_animator) &&
701 (!sd->scrollto.y.animator))
702 _smart_anim_stop(sd->smart_obj);
703 sd->down.bounce_y_animator = NULL;
706 _smart_momentum_end(sd);
707 return ECORE_CALLBACK_CANCEL;
710 return ECORE_CALLBACK_RENEW;
718 can_scroll(Smart_Data *sd, int dir)
720 Evas_Coord mx = 0, my = 0, px = 0, py = 0, minx = 0, miny = 0;
722 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
723 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
724 sd->pan_func.get(sd->pan_obj, &px, &py);
728 if (px > minx) return EINA_TRUE;
731 if ((px - minx) < mx) return EINA_TRUE;
734 if (py > miny) return EINA_TRUE;
737 if ((py - miny) < my) return EINA_TRUE;
746 _smart_momentum_animator(void *data)
750 Evas_Coord x, y, dx, dy, px, py, maxx, maxy, minx, miny;
751 Eina_Bool no_bounce_x_end = EINA_FALSE, no_bounce_y_end = EINA_FALSE;
754 t = ecore_loop_time_get();
755 dt = t - sd->down.anim_start;
759 if (sd->down.hold_parent)
761 if ((sd->down.dir_x) && !can_scroll(sd, sd->down.hdir))
765 if ((sd->down.dir_y) && !can_scroll(sd, sd->down.vdir))
770 if ((!sd->down.dir_x) && (!sd->down.dir_y))
772 sd->down.cancelled = 1;
775 dt = dt / (_elm_config->thumbscroll_friction + sd->down.extra_time);
776 if (dt > 1.0) dt = 1.0;
777 p = 1.0 - ((1.0 - dt) * (1.0 - dt));
778 dx = (sd->down.dx * (_elm_config->thumbscroll_friction + sd->down.extra_time) * p);
779 dy = (sd->down.dy * (_elm_config->thumbscroll_friction + sd->down.extra_time) * p);
782 x = sd->down.sx - dx;
783 y = sd->down.sy - dy;
784 elm_smart_scroller_child_pos_get(sd->smart_obj, &px, &py);
785 if ((sd->down.bounce_x_animator) ||
786 (sd->down.bounce_x_hold))
788 sd->down.bx = sd->down.bx0 - dx + sd->down.b0x;
791 if ((sd->down.bounce_y_animator) ||
792 (sd->down.bounce_y_hold))
794 sd->down.by = sd->down.by0 - dy + sd->down.b0y;
797 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
798 sd->pan_func.max_get(sd->pan_obj, &maxx, &maxy);
799 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
800 if (!sd->bounce_horiz)
802 if (x <= minx) no_bounce_x_end = EINA_TRUE;
803 if ((x - minx) >= maxx) no_bounce_x_end = EINA_TRUE;
805 if (!sd->bounce_vert)
807 if (y <= miny) no_bounce_y_end = EINA_TRUE;
808 if ((y - miny) >= maxy) no_bounce_y_end = EINA_TRUE;
811 ((sd->down.bounce_x_hold) && (sd->down.bounce_y_hold)) ||
812 (no_bounce_x_end && no_bounce_y_end))
814 _smart_anim_stop(sd->smart_obj);
815 _update_wanted_coordinates(sd, px, py);
817 sd->down.momentum_animator = NULL;
818 sd->down.bounce_x_hold = 0;
819 sd->down.bounce_y_hold = 0;
824 return ECORE_CALLBACK_CANCEL;
827 return ECORE_CALLBACK_RENEW;
831 bounce_eval(Smart_Data *sd)
833 Evas_Coord mx, my, px, py, bx, by, b2x, b2y, minx = 0, miny = 0;
835 if (sd->freeze) return;
836 if ((!sd->bouncemex) && (!sd->bouncemey)) return;
837 if (sd->down.now) return; // down bounce while still held down
838 if (sd->down.onhold_animator)
840 ecore_animator_del(sd->down.onhold_animator);
841 sd->down.onhold_animator = NULL;
843 if (sd->down.hold_animator)
845 ecore_animator_del(sd->down.hold_animator);
846 sd->down.hold_animator = NULL;
848 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
849 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
850 sd->pan_func.get(sd->pan_obj, &px, &py);
853 if (px < minx) px = minx;
854 if ((px - minx) > mx) px = mx + minx;
855 if (py < miny) py = miny;
856 if ((py - miny) > my) py = my + miny;
860 (!elm_widget_drag_child_locked_x_get(sd->widget)))
862 if (!sd->down.bounce_x_animator && !sd->bounce_animator_disabled)
866 if (sd->scrollto.x.animator)
868 ecore_animator_del(sd->scrollto.x.animator);
869 sd->scrollto.x.animator = NULL;
871 sd->down.bounce_x_animator = ecore_animator_add(_smart_bounce_x_animator, sd);
872 sd->down.anim_start2 = ecore_loop_time_get();
876 if (sd->down.momentum_animator) sd->down.b0x = sd->down.ax;
877 else sd->down.b0x = 0;
882 (!elm_widget_drag_child_locked_y_get(sd->widget)))
884 if (!sd->down.bounce_y_animator && !sd->bounce_animator_disabled)
888 if (sd->scrollto.y.animator)
890 ecore_animator_del(sd->scrollto.y.animator);
891 sd->scrollto.y.animator = NULL;
893 sd->down.bounce_y_animator = ecore_animator_add(_smart_bounce_y_animator, sd);
894 sd->down.anim_start3 = ecore_loop_time_get();
898 if (sd->down.momentum_animator) sd->down.b0y = sd->down.ay;
899 else sd->down.b0y = 0;
906 elm_smart_scroller_child_pos_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
908 Evas_Coord mx = 0, my = 0, px = 0, py = 0, minx = 0, miny = 0;
912 // FIXME: allow for bounce outside of range
913 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
914 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
915 if (mx > 0) vx = (double)(x - minx) / (double)mx;
917 if (vx < 0.0) vx = 0.0;
918 else if (vx > 1.0) vx = 1.0;
919 if (my > 0) vy = (double)(y - miny) / (double)my;
921 if (vy < 0.0) vy = 0.0;
922 else if (vy > 1.0) vy = 1.0;
923 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.vbar", 0.0, vy);
924 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.hbar", vx, 0.0);
925 sd->pan_func.get(sd->pan_obj, &px, &py);
926 if (!_elm_config->thumbscroll_bounce_enable)
928 if (x < minx) x = minx;
929 if ((x - minx) > mx) x = mx + minx;
930 if (y < miny) y = miny;
931 if ((y - miny) > my) y = my + miny;
934 if (!sd->bounce_horiz)
936 if (x < minx) x = minx;
937 if ((x - minx) > mx) x = mx + minx;
939 if (!sd->bounce_vert)
941 if (y < miny) y = miny;
942 if (y - miny > my) y = my + miny;
945 sd->pan_func.set(sd->pan_obj, x, y);
946 if ((px != x) || (py != y))
947 edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
948 if (!sd->down.bounce_x_animator)
950 if ((x < minx) || (x > (mx + minx)))
956 if (!sd->down.bounce_y_animator)
958 if ((y < miny) || (y > my + miny))
964 if ((x != px) || (y != py))
966 evas_object_smart_callback_call(obj, "scroll", NULL);
968 if ((x != px)/* && (!sd->bouncemex)*/)
971 evas_object_smart_callback_call(obj, "edge,left", NULL);
972 if (x == (mx + minx))
973 evas_object_smart_callback_call(obj, "edge,right", NULL);
975 if ((y != py)/* && (!sd->bouncemey)*/)
978 evas_object_smart_callback_call(obj, "edge,top", NULL);
980 evas_object_smart_callback_call(obj, "edge,bottom", NULL);
985 elm_smart_scroller_child_pos_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
988 sd->pan_func.get(sd->pan_obj, x, y);
991 /* "internal_call" actually toggles whether we should save the coords and do
992 * extra "speedup" checks, or not. */
994 _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)
996 Evas_Coord mx = 0, my = 0, cw = 0, ch = 0, px = 0, py = 0, nx, ny, minx = 0, miny = 0;
999 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
1000 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
1001 sd->pan_func.child_size_get(sd->pan_obj, &cw, &ch);
1002 sd->pan_func.get(sd->pan_obj, &px, &py);
1005 if ((x < px) && ((x + w) < (px + (cw - mx)))) nx = x;
1006 else if ((x > px) && ((x + w) > (px + (cw - mx)))) nx = x + w - (cw - mx);
1008 if ((y < py) && ((y + h) < (py + (ch - my)))) ny = y;
1009 else if ((y > py) && ((y + h) > (py + (ch - my)))) ny = y + h - (ch - my);
1016 if ((nx == px) && (ny == py)) return;
1019 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1020 (sd->scrollto.x.animator) || (sd->scrollto.y.animator))
1022 _smart_anim_stop(sd->smart_obj);
1024 if (sd->scrollto.x.animator)
1026 ecore_animator_del(sd->scrollto.x.animator);
1027 sd->scrollto.x.animator = NULL;
1029 if (sd->scrollto.y.animator)
1031 ecore_animator_del(sd->scrollto.y.animator);
1032 sd->scrollto.y.animator = NULL;
1034 if (sd->down.bounce_x_animator)
1036 ecore_animator_del(sd->down.bounce_x_animator);
1037 sd->down.bounce_x_animator = NULL;
1040 if (sd->down.bounce_y_animator)
1042 ecore_animator_del(sd->down.bounce_y_animator);
1043 sd->down.bounce_y_animator = NULL;
1046 if (sd->down.hold_animator)
1048 ecore_animator_del(sd->down.hold_animator);
1049 sd->down.hold_animator = NULL;
1050 _smart_drag_stop(sd->smart_obj);
1052 if (sd->down.momentum_animator)
1054 ecore_animator_del(sd->down.momentum_animator);
1055 sd->down.momentum_animator = NULL;
1056 sd->down.bounce_x_hold = 0;
1057 sd->down.bounce_y_hold = 0;
1064 if (x < minx) x = minx;
1065 else if ((x + w) > cw) x = cw - w;
1067 if (y < miny) y = miny;
1068 else if ((y + h) > ch) y = ch - h;
1069 elm_smart_scroller_child_pos_set(obj, x, y);
1072 /* Set should be used for calculated positions, for example, when we move
1073 * because of an animation or because this is the correct position after
1076 elm_smart_scroller_child_region_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
1078 _elm_smart_scroller_child_region_show_internal(obj, x, y, w, h, EINA_TRUE);
1081 /* Set should be used for setting the wanted position, for example a user scroll
1082 * or moving the cursor in an entry. */
1084 elm_smart_scroller_child_region_show(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
1086 _elm_smart_scroller_child_region_show_internal(obj, x, y, w, h, EINA_FALSE);
1090 elm_smart_scroller_child_viewport_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
1093 if (!sd->pan_obj) return;
1094 edje_object_calc_force(sd->edje_obj);
1095 evas_object_geometry_get(sd->pan_obj, NULL, NULL, w, h);
1099 elm_smart_scroller_step_size_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
1106 _smart_scrollbar_size_adjust(sd);
1110 elm_smart_scroller_step_size_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
1113 if (x) *x = sd->step.x;
1114 if (y) *y = sd->step.y;
1118 elm_smart_scroller_page_size_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
1123 _smart_scrollbar_size_adjust(sd);
1127 elm_smart_scroller_page_size_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
1130 if (x) *x = sd->page.x;
1131 if (y) *y = sd->page.y;
1135 elm_smart_scroller_policy_set(Evas_Object *obj, Elm_Smart_Scroller_Policy hbar, Elm_Smart_Scroller_Policy vbar)
1138 if ((sd->hbar_flags == hbar) && (sd->vbar_flags == vbar)) return;
1139 sd->hbar_flags = hbar;
1140 sd->vbar_flags = vbar;
1141 if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
1142 edje_object_signal_emit(sd->edje_obj, "elm,action,show_always,hbar", "elm");
1143 else if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
1144 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,hbar", "elm");
1146 edje_object_signal_emit(sd->edje_obj, "elm,action,show_notalways,hbar", "elm");
1147 if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
1148 edje_object_signal_emit(sd->edje_obj, "elm,action,show_always,vbar", "elm");
1149 else if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
1150 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,vbar", "elm");
1152 edje_object_signal_emit(sd->edje_obj, "elm,action,show_notalways,vbar", "elm");
1153 _smart_scrollbar_size_adjust(sd);
1157 elm_smart_scroller_policy_get(Evas_Object *obj, Elm_Smart_Scroller_Policy *hbar, Elm_Smart_Scroller_Policy *vbar)
1160 if (hbar) *hbar = sd->hbar_flags;
1161 if (vbar) *vbar = sd->vbar_flags;
1165 elm_smart_scroller_edje_object_get(Evas_Object *obj)
1167 API_ENTRY return NULL;
1168 return sd->edje_obj;
1172 elm_smart_scroller_single_dir_set(Evas_Object *obj, Eina_Bool single_dir)
1175 sd->one_dir_at_a_time = single_dir;
1179 elm_smart_scroller_single_dir_get(Evas_Object *obj)
1181 API_ENTRY return EINA_FALSE;
1182 return sd->one_dir_at_a_time;
1186 elm_smart_scroller_object_theme_set(Evas_Object *parent, Evas_Object *obj, const char *clas, const char *group, const char *style)
1190 //Does this API require parent object absolutely? if then remove this exception.
1191 double parent_scale = parent ? elm_widget_scale_get(parent) : 1;
1192 _elm_theme_object_set(parent, sd->edje_obj, clas, group, style);
1193 edje_object_scale_set(sd->edje_obj, parent_scale * _elm_config->scale);
1195 edje_object_part_swallow(sd->edje_obj, "elm.swallow.content", sd->pan_obj);
1197 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1198 if (edje_object_part_exists(sd->edje_obj, "elm.scrollbar.base"))
1201 base = edje_object_part_swallow_get(sd->edje_obj, "elm.scrollbar.base");
1204 base = evas_object_rectangle_add(evas_object_evas_get(sd->edje_obj));
1205 evas_object_color_set(base, 0, 0, 0, 0);
1206 edje_object_part_swallow(sd->edje_obj, "elm.scrollbar.base", base);
1208 if (!_elm_config->thumbscroll_enable)
1209 evas_object_size_hint_min_set(base, mw, mh);
1211 sd->vbar_visible = !sd->vbar_visible;
1212 sd->hbar_visible = !sd->hbar_visible;
1213 _smart_scrollbar_bar_visibility_adjust(sd);
1217 elm_smart_scroller_hold_set(Evas_Object *obj, Eina_Bool hold)
1224 elm_smart_scroller_freeze_set(Evas_Object *obj, Eina_Bool freeze)
1227 sd->freeze = freeze;
1230 if (sd->down.onhold_animator)
1232 ecore_animator_del(sd->down.onhold_animator);
1233 sd->down.onhold_animator = NULL;
1241 elm_smart_scroller_bounce_allow_set(Evas_Object *obj, Eina_Bool horiz, Eina_Bool vert)
1244 sd->bounce_horiz = horiz;
1245 sd->bounce_vert = vert;
1249 elm_smart_scroller_bounce_allow_get(const Evas_Object *obj, Eina_Bool *horiz, Eina_Bool *vert)
1252 *horiz = sd->bounce_horiz;
1253 *vert = sd->bounce_vert;
1257 elm_smart_scroller_paging_set(Evas_Object *obj, double pagerel_h, double pagerel_v, Evas_Coord pagesize_h, Evas_Coord pagesize_v)
1260 sd->pagerel_h = pagerel_h;
1261 sd->pagerel_v = pagerel_v;
1262 sd->pagesize_h = pagesize_h;
1263 sd->pagesize_v = pagesize_v;
1264 _smart_page_adjust(sd);
1268 elm_smart_scroller_paging_get(Evas_Object *obj, double *pagerel_h, double *pagerel_v, Evas_Coord *pagesize_h, Evas_Coord *pagesize_v)
1271 if(pagerel_h) *pagerel_h = sd->pagerel_h;
1272 if(pagerel_v) *pagerel_v = sd->pagerel_v;
1273 if(pagesize_h) *pagesize_h = sd->pagesize_h;
1274 if(pagesize_v) *pagesize_v = sd->pagesize_v;
1278 elm_smart_scroller_region_bring_in(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
1280 Evas_Coord mx = 0, my = 0, cw = 0, ch = 0, px = 0, py = 0, nx, ny, minx = 0, miny = 0;
1283 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
1284 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
1285 sd->pan_func.child_size_get(sd->pan_obj, &cw, &ch);
1286 sd->pan_func.get(sd->pan_obj, &px, &py);
1289 if ((x < px) && ((x + w) < (px + (cw - mx)))) nx = x;
1290 else if ((x > px) && ((x + w) > (px + (cw - mx)))) nx = x + w - (cw - mx);
1292 if ((y < py) && ((y + h) < (py + (ch - my)))) ny = y;
1293 else if ((y > py) && ((y + h) > (py + (ch - my)))) ny = y + h - (ch - my);
1298 if ((nx == px) && (ny == py)) return;
1299 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1300 (sd->scrollto.x.animator) || (sd->scrollto.y.animator))
1302 _smart_anim_stop(sd->smart_obj);
1304 if (sd->scrollto.x.animator)
1306 ecore_animator_del(sd->scrollto.x.animator);
1307 sd->scrollto.x.animator = NULL;
1309 if (sd->scrollto.y.animator)
1311 ecore_animator_del(sd->scrollto.y.animator);
1312 sd->scrollto.y.animator = NULL;
1314 if (sd->down.bounce_x_animator)
1316 ecore_animator_del(sd->down.bounce_x_animator);
1317 sd->down.bounce_x_animator = NULL;
1320 if (sd->down.bounce_y_animator)
1322 ecore_animator_del(sd->down.bounce_y_animator);
1323 sd->down.bounce_y_animator = NULL;
1326 if (sd->down.hold_animator)
1328 ecore_animator_del(sd->down.hold_animator);
1329 sd->down.hold_animator = NULL;
1330 _smart_drag_stop(sd->smart_obj);
1332 if (sd->down.momentum_animator)
1334 ecore_animator_del(sd->down.momentum_animator);
1335 sd->down.momentum_animator = NULL;
1336 sd->down.bounce_x_hold = 0;
1337 sd->down.bounce_y_hold = 0;
1344 if (x < minx) x = minx;
1345 else if ((x + w) > cw) x = cw - w;
1346 _smart_scrollto_x(sd, _elm_config->bring_in_scroll_friction, x);
1348 if (y < miny) y = miny;
1349 else if ((y + h) > ch) y = ch - h;
1350 _smart_scrollto_y(sd, _elm_config->bring_in_scroll_friction, y);
1354 elm_smart_scroller_widget_set(Evas_Object *obj, Evas_Object *wid)
1361 _elm_smart_scroller_wanted_region_set(Evas_Object *obj)
1364 Evas_Coord ww, wh, wx = sd->wx;
1366 /* Flip to RTL cords only if init in RTL mode */
1368 wx = _elm_smart_scroller_x_mirrored_get(obj, sd->wx);
1372 elm_smart_scroller_child_viewport_size_get(obj, &ww, &wh);
1380 elm_smart_scroller_child_region_set(obj, wx, sd->wy, ww, wh);
1383 /* local subsystem functions */
1385 _smart_edje_drag_v_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1390 _smart_scrollbar_read(sd);
1391 _smart_drag_start(sd->smart_obj);
1392 sd->freeze = EINA_TRUE;
1396 _smart_edje_drag_v_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1401 _smart_scrollbar_read(sd);
1402 _smart_drag_stop(sd->smart_obj);
1403 sd->freeze = EINA_FALSE;
1407 _smart_edje_drag_v(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1412 _smart_scrollbar_read(sd);
1416 _smart_edje_drag_h_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1421 _smart_scrollbar_read(sd);
1422 _smart_drag_start(sd->smart_obj);
1423 sd->freeze = EINA_TRUE;
1427 _smart_edje_drag_h_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1432 _smart_scrollbar_read(sd);
1433 _smart_drag_stop(sd->smart_obj);
1434 sd->freeze = EINA_FALSE;
1438 _smart_edje_drag_h(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1443 _smart_scrollbar_read(sd);
1447 _smart_child_del_hook(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1452 sd->child_obj = NULL;
1453 _smart_scrollbar_size_adjust(sd);
1454 _smart_scrollbar_reset(sd);
1458 _smart_pan_changed_hook(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1464 sd->pan_func.child_size_get(sd->pan_obj, &w, &h);
1465 if ((w != sd->child.w) || (h != sd->child.h))
1469 _smart_scrollbar_size_adjust(sd);
1470 evas_object_size_hint_min_set(sd->smart_obj, sd->child.w, sd->child.h);
1471 _elm_smart_scroller_wanted_region_set(sd->smart_obj);
1476 _smart_pan_pan_changed_hook(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1481 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1482 (sd->scrollto.x.animator) || (sd->scrollto.y.animator))
1484 _smart_anim_stop(sd->smart_obj);
1486 if (sd->scrollto.x.animator)
1488 ecore_animator_del(sd->scrollto.x.animator);
1489 sd->scrollto.x.animator = NULL;
1491 if (sd->scrollto.y.animator)
1493 ecore_animator_del(sd->scrollto.y.animator);
1494 sd->scrollto.y.animator = NULL;
1496 if (sd->down.bounce_x_animator)
1498 ecore_animator_del(sd->down.bounce_x_animator);
1499 sd->down.bounce_x_animator = NULL;
1502 if (sd->down.bounce_y_animator)
1504 ecore_animator_del(sd->down.bounce_y_animator);
1505 sd->down.bounce_y_animator = NULL;
1508 _elm_smart_scroller_wanted_region_set(sd->smart_obj);
1512 _smart_event_wheel(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1514 Evas_Event_Mouse_Wheel *ev;
1516 Evas_Coord x = 0, y = 0;
1520 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
1521 if ((evas_key_modifier_is_set(ev->modifiers, "Control")) ||
1522 (evas_key_modifier_is_set(ev->modifiers, "Alt")) ||
1523 (evas_key_modifier_is_set(ev->modifiers, "Shift")) ||
1524 (evas_key_modifier_is_set(ev->modifiers, "Meta")) ||
1525 (evas_key_modifier_is_set(ev->modifiers, "Hyper")) ||
1526 (evas_key_modifier_is_set(ev->modifiers, "Super")))
1528 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1529 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1530 (sd->scrollto.x.animator) || (sd->scrollto.y.animator))
1532 _smart_anim_stop(sd->smart_obj);
1534 if (sd->scrollto.x.animator)
1536 ecore_animator_del(sd->scrollto.x.animator);
1537 sd->scrollto.x.animator = NULL;
1539 if (sd->scrollto.y.animator)
1541 ecore_animator_del(sd->scrollto.y.animator);
1542 sd->scrollto.y.animator = NULL;
1544 if (sd->down.bounce_x_animator)
1546 ecore_animator_del(sd->down.bounce_x_animator);
1547 sd->down.bounce_x_animator = NULL;
1550 if (sd->down.bounce_y_animator)
1552 ecore_animator_del(sd->down.bounce_y_animator);
1553 sd->down.bounce_y_animator = NULL;
1557 y += ev->z * sd->step.y;
1558 else if (ev->direction == 1)
1559 x += ev->z * sd->step.x;
1561 if ((!sd->hold) && (!sd->freeze))
1563 _update_wanted_coordinates(sd, x, y);
1564 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
1569 _smart_event_mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1571 Evas_Event_Mouse_Down *ev;
1573 Evas_Coord x = 0, y = 0;
1577 // if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
1578 if (_elm_config->thumbscroll_enable)
1581 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1582 (sd->down.momentum_animator) || (sd->scrollto.x.animator) ||
1583 (sd->scrollto.y.animator))
1585 ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL | EVAS_EVENT_FLAG_ON_HOLD;
1586 sd->down.scroll = 1;
1588 _smart_anim_stop(sd->smart_obj);
1590 if (sd->scrollto.x.animator)
1592 ecore_animator_del(sd->scrollto.x.animator);
1593 sd->scrollto.x.animator = NULL;
1595 if (sd->scrollto.y.animator)
1597 ecore_animator_del(sd->scrollto.y.animator);
1598 sd->scrollto.y.animator = NULL;
1600 if (sd->down.bounce_x_animator)
1602 ecore_animator_del(sd->down.bounce_x_animator);
1603 sd->down.bounce_x_animator = NULL;
1606 if (sd->down.bounce_y_animator)
1608 ecore_animator_del(sd->down.bounce_y_animator);
1609 sd->down.bounce_y_animator = NULL;
1612 if (sd->down.hold_animator)
1614 ecore_animator_del(sd->down.hold_animator);
1615 sd->down.hold_animator = NULL;
1616 _smart_drag_stop(sd->smart_obj);
1618 if (sd->down.momentum_animator)
1620 ecore_animator_del(sd->down.momentum_animator);
1621 sd->down.momentum_animator = NULL;
1622 sd->down.bounce_x_hold = 0;
1623 sd->down.bounce_y_hold = 0;
1627 if (ev->button == 1)
1630 sd->down.dragged = 0;
1633 sd->down.x = ev->canvas.x;
1634 sd->down.y = ev->canvas.y;
1635 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1638 sd->down.locked = 0;
1639 memset(&(sd->down.history[0]), 0, sizeof(sd->down.history[0]) * 20);
1641 sd->down.history[0].timestamp = ev->timestamp / 1000.0;
1643 sd->down.history[0].timestamp = ecore_loop_time_get();
1645 sd->down.history[0].x = ev->canvas.x;
1646 sd->down.history[0].y = ev->canvas.y;
1648 sd->down.dragged_began = 0;
1649 sd->down.hold_parent = 0;
1650 sd->down.cancelled = 0;
1655 _smart_hold_animator(void *data)
1657 Smart_Data *sd = data;
1660 elm_smart_scroller_child_pos_get(sd->smart_obj, &ox, &oy);
1663 if ((!sd->widget) ||
1664 (!elm_widget_drag_child_locked_x_get(sd->widget)))
1666 ox = sd->down.hold_x;
1671 if ((!sd->widget) ||
1672 (!elm_widget_drag_child_locked_y_get(sd->widget)))
1674 oy = sd->down.hold_y;
1677 elm_smart_scroller_child_pos_set(sd->smart_obj, ox, oy);
1678 return ECORE_CALLBACK_RENEW;
1682 _smart_event_post_up(void *data, Evas *e __UNUSED__)
1684 Smart_Data *sd = data;
1687 if (sd->down.dragged)
1689 elm_widget_drag_lock_x_set(sd->widget, 0);
1690 elm_widget_drag_lock_y_set(sd->widget, 0);
1697 _smart_event_mouse_up(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *event_info)
1699 Evas_Event_Mouse_Down *ev;
1701 Evas_Coord x = 0, y = 0, ox = 0, oy = 0;
1705 sd->down.hold_parent = 0;
1706 // if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
1707 evas_post_event_callback_push(e, _smart_event_post_up, sd);
1708 // FIXME: respect elm_widget_scroll_hold_get of parent container
1709 if (_elm_config->thumbscroll_enable)
1711 if (ev->button == 1)
1713 if (sd->down.onhold_animator)
1715 ecore_animator_del(sd->down.onhold_animator);
1716 sd->down.onhold_animator = NULL;
1718 x = ev->canvas.x - sd->down.x;
1719 y = ev->canvas.y - sd->down.y;
1720 if (sd->down.dragged)
1722 _smart_drag_stop(sd->smart_obj);
1723 if ((!sd->hold) && (!sd->freeze))
1727 Evas_Coord ax, ay, dx, dy, vel;
1730 t = ev->timestamp / 1000.0;
1732 t = ecore_loop_time_get();
1734 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1739 printf("------ %i %i\n", ev->canvas.x, ev->canvas.y);
1741 for (i = 0; i < 20; i++)
1743 dt = t - sd->down.history[i].timestamp;
1744 if (dt > 0.2) break;
1746 printf("H: %i %i @ %1.3f\n",
1747 sd->down.history[i].x,
1748 sd->down.history[i].y, dt);
1751 ax += sd->down.history[i].x;
1752 ay += sd->down.history[i].y;
1758 dx = ev->canvas.x - ax;
1759 dy = ev->canvas.y - ay;
1762 vel = sqrt((dx * dx) + (dy * dy)) / at;
1763 if ((_elm_config->thumbscroll_friction > 0.0) &&
1764 (vel > _elm_config->thumbscroll_momentum_threshold))
1766 sd->down.dx = ((double)dx / at);
1767 sd->down.dy = ((double)dy / at);
1768 if (((sd->down.dx > 0) && (sd->down.pdx > 0)) ||
1769 ((sd->down.dx < 0) && (sd->down.pdx < 0)))
1770 sd->down.dx += (double)sd->down.pdx * 1.5; // FIXME: * 1.5 - probably should be config
1771 if (((sd->down.dy > 0) && (sd->down.pdy > 0)) ||
1772 ((sd->down.dy < 0) && (sd->down.pdy < 0)))
1773 sd->down.dy += (double)sd->down.pdy * 1.5; // FIXME: * 1.5 - probably should be config
1774 if (((sd->down.dx > 0) && (sd->down.pdx > 0)) ||
1775 ((sd->down.dx < 0) && (sd->down.pdx < 0)) ||
1776 ((sd->down.dy > 0) && (sd->down.pdy > 0)) ||
1777 ((sd->down.dy < 0) && (sd->down.pdy < 0)))
1779 double t = ecore_loop_time_get();
1780 double dt = t - sd->down.anim_start;
1782 if (dt < 0.0) dt = 0.0;
1783 else if (dt > _elm_config->thumbscroll_friction)
1784 dt = _elm_config->thumbscroll_friction;
1785 sd->down.extra_time = _elm_config->thumbscroll_friction - dt;
1788 sd->down.extra_time = 0.0;
1789 sd->down.pdx = sd->down.dx;
1790 sd->down.pdy = sd->down.dy;
1793 if (!_smart_do_page(sd))
1795 if (!sd->down.momentum_animator && !sd->momentum_animator_disabled)
1797 sd->down.momentum_animator = ecore_animator_add(_smart_momentum_animator, sd);
1798 ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL;
1799 _smart_anim_start(sd->smart_obj);
1801 sd->down.anim_start = ecore_loop_time_get();
1802 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1810 if (sd->down.hold_animator)
1812 ecore_animator_del(sd->down.hold_animator);
1813 sd->down.hold_animator = NULL;
1821 evas_event_feed_hold(e, 0, ev->timestamp, ev->data);
1822 if (_smart_do_page(sd))
1824 Evas_Coord pgx, pgy;
1826 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1827 if ((!sd->widget) ||
1828 (!elm_widget_drag_child_locked_x_get(sd->widget)))
1830 pgx = _smart_page_x_get(sd, ox);
1833 ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL;
1834 _smart_scrollto_x(sd, _elm_config->page_scroll_friction, pgx);
1837 if ((!sd->widget) ||
1838 (!elm_widget_drag_child_locked_y_get(sd->widget)))
1840 pgy = _smart_page_y_get(sd, oy);
1843 ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL;
1844 _smart_scrollto_y(sd, _elm_config->page_scroll_friction, pgy);
1853 if (_smart_do_page(sd))
1855 Evas_Coord pgx, pgy;
1857 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1858 if ((!sd->widget) ||
1859 (!elm_widget_drag_child_locked_x_get(sd->widget)))
1861 pgx = _smart_page_x_get(sd, ox);
1862 if (pgx != x) _smart_scrollto_x(sd, _elm_config->page_scroll_friction, pgx);
1864 if ((!sd->widget) ||
1865 (!elm_widget_drag_child_locked_y_get(sd->widget)))
1867 pgy = _smart_page_y_get(sd, oy);
1868 if (pgy != y) _smart_scrollto_y(sd, _elm_config->page_scroll_friction, pgy);
1871 if (sd->down.hold_animator)
1873 ecore_animator_del(sd->down.hold_animator);
1874 sd->down.hold_animator = NULL;
1877 if (sd->down.scroll)
1879 ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL;
1880 sd->down.scroll = 0;
1884 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1887 sd->down.dragged_began = 0;
1890 sd->down.want_dragged = 0;
1891 sd->down.dragged = 0;
1893 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1894 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
1895 _update_wanted_coordinates(sd, x, y);
1897 if (!_smart_do_page(sd))
1904 _smart_onhold_animator(void *data)
1909 Evas_Coord x, y, ox, oy;
1912 t = ecore_loop_time_get();
1913 if (sd->down.onhold_tlast > 0.0)
1915 td = t - sd->down.onhold_tlast;
1916 vx = sd->down.onhold_vx * td * (double)_elm_config->thumbscroll_threshold * 2.0;
1917 vy = sd->down.onhold_vy * td * (double)_elm_config->thumbscroll_threshold * 2.0;
1918 elm_smart_scroller_child_pos_get(sd->smart_obj, &ox, &oy);
1924 if ((!sd->widget) ||
1925 (!elm_widget_drag_child_locked_x_get(sd->widget)))
1927 sd->down.onhold_vxe += vx;
1928 x = ox + (int)sd->down.onhold_vxe;
1929 sd->down.onhold_vxe -= (int)sd->down.onhold_vxe;
1935 if ((!sd->widget) ||
1936 (!elm_widget_drag_child_locked_y_get(sd->widget)))
1938 sd->down.onhold_vye += vy;
1939 y = oy + (int)sd->down.onhold_vye;
1940 sd->down.onhold_vye -= (int)sd->down.onhold_vye;
1944 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
1946 sd->down.onhold_tlast = t;
1947 return ECORE_CALLBACK_RENEW;
1951 _smart_event_post_move(void *data, Evas *e __UNUSED__)
1953 Smart_Data *sd = data;
1955 if (sd->down.want_dragged)
1959 if (sd->down.hold_parent)
1961 if ((sd->down.dir_x) && !can_scroll(sd, sd->down.hdir))
1965 if ((sd->down.dir_y) && !can_scroll(sd, sd->down.vdir))
1972 if ((!sd->widget) ||
1973 (!elm_widget_drag_child_locked_x_get(sd->widget)))
1975 sd->down.want_dragged = 0;
1976 sd->down.dragged = 1;
1979 elm_widget_drag_lock_x_set(sd->widget, 1);
1988 if ((!sd->widget) ||
1989 (!elm_widget_drag_child_locked_y_get(sd->widget)))
1991 sd->down.want_dragged = 0;
1992 sd->down.dragged = 1;
1995 elm_widget_drag_lock_y_set(sd->widget, 1);
2002 if ((!sd->down.dir_x) && (!sd->down.dir_y))
2004 sd->down.cancelled = 1;
2006 if (start) _smart_drag_start(sd->smart_obj);
2012 _smart_event_mouse_move(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *event_info)
2014 Evas_Event_Mouse_Move *ev;
2016 Evas_Coord x = 0, y = 0;
2020 // if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
2021 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) sd->down.hold_parent = 1;
2022 evas_post_event_callback_push(e, _smart_event_post_move, sd);
2023 // FIXME: respect elm_widget_scroll_hold_get of parent container
2024 if (_elm_config->thumbscroll_enable)
2031 printf("::: %i %i\n", ev->cur.canvas.x, ev->cur.canvas.y);
2033 memmove(&(sd->down.history[1]), &(sd->down.history[0]),
2034 sizeof(sd->down.history[0]) * 19);
2036 sd->down.history[0].timestamp = ev->timestamp / 1000.0;
2038 sd->down.history[0].timestamp = ecore_loop_time_get();
2040 sd->down.history[0].x = ev->cur.canvas.x;
2041 sd->down.history[0].y = ev->cur.canvas.y;
2043 if (!sd->down.dragged_began)
2045 x = ev->cur.canvas.x - sd->down.x;
2046 y = ev->cur.canvas.y - sd->down.y;
2051 if (x > 0) sd->down.hdir = LEFT;
2052 else if (x < 0) sd->down.hdir = RIGHT;
2053 if (y > 0) sd->down.vdir = UP;
2054 else if (y < 0) sd->down.vdir = DOWN;
2059 if ((sd->one_dir_at_a_time) &&
2060 (!((sd->down.dir_x) || (sd->down.dir_y))))
2062 if (x > _elm_config->thumbscroll_threshold)
2071 if (y > _elm_config->thumbscroll_threshold)
2088 // can_scroll(sd, LEFT);
2089 // can_scroll(sd, RIGHT);
2090 // can_scroll(sd, UP);
2091 // can_scroll(sd, DOWN);
2096 if ((!sd->hold) && (!sd->freeze))
2098 if ((sd->down.dragged) ||
2099 (((x * x) + (y * y)) >
2100 (_elm_config->thumbscroll_threshold *
2101 _elm_config->thumbscroll_threshold)))
2103 sd->down.dragged_began = 1;
2104 if (!sd->down.dragged)
2106 sd->down.want_dragged = 1;
2107 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2108 // evas_event_feed_hold(e, 1, ev->timestamp, ev->data);
2109 // _smart_drag_start(sd->smart_obj);
2111 if (sd->down.dragged)
2113 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2115 // ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2116 // sd->down.dragged = 1;
2118 x = sd->down.sx - (ev->cur.canvas.x - sd->down.x);
2122 y = sd->down.sy - (ev->cur.canvas.y - sd->down.y);
2125 if ((sd->down.dir_x) || (sd->down.dir_y))
2127 if (!sd->down.locked)
2129 sd->down.locked_x = x;
2130 sd->down.locked_y = y;
2131 sd->down.locked = 1;
2133 if (!((sd->down.dir_x) && (sd->down.dir_y)))
2135 if (sd->down.dir_x) y = sd->down.locked_y;
2136 else x = sd->down.locked_x;
2139 if (_elm_config->thumbscroll_border_friction > 0.0)
2141 Evas_Coord minx, miny;
2142 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2145 _elm_config->thumbscroll_border_friction;
2146 else if (sd->child.h <= sd->h)
2147 y += (sd->down.sy - y) *
2148 _elm_config->thumbscroll_border_friction;
2149 else if ((sd->child.h - sd->h + miny) < y)
2150 y += (sd->child.h - sd->h + miny - y) *
2151 _elm_config->thumbscroll_border_friction;
2154 _elm_config->thumbscroll_border_friction;
2155 else if (sd->child.w <= sd->w)
2156 x += (sd->down.sx - x) *
2157 _elm_config->thumbscroll_border_friction;
2158 else if ((sd->child.w - sd->w + minx) < x)
2159 x += (sd->child.w - sd->w + minx - x) *
2160 _elm_config->thumbscroll_border_friction;
2163 sd->down.hold_x = x;
2164 sd->down.hold_y = y;
2165 if (!sd->down.hold_animator)
2166 sd->down.hold_animator =
2167 ecore_animator_add(_smart_hold_animator, sd);
2168 // printf("a %i %i\n", sd->down.hold_x, sd->down.hold_y);
2169 // _smart_onhold_animator(sd);
2170 // elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
2174 if (sd->down.dragged_began)
2176 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2180 evas_event_feed_hold(e, 1, ev->timestamp, ev->data);
2185 else if (!sd->freeze)
2187 Evas_Coord ex, ey, ew, eh;
2188 double vx = 0.0, vy = 0.0;
2190 evas_object_geometry_get(sd->event_obj, &ex, &ey, &ew, &eh);
2191 x = ev->cur.canvas.x - ex;
2192 y = ev->cur.canvas.y - ey;
2193 if (x < _elm_config->thumbscroll_threshold)
2195 if (_elm_config->thumbscroll_threshold > 0.0)
2196 vx = -(double)(_elm_config->thumbscroll_threshold - x) /
2197 _elm_config->thumbscroll_threshold;
2201 else if (x > (ew - _elm_config->thumbscroll_threshold))
2203 if (_elm_config->thumbscroll_threshold > 0.0)
2204 vx = (double)(_elm_config->thumbscroll_threshold - (ew - x)) /
2205 _elm_config->thumbscroll_threshold;
2209 if (y < _elm_config->thumbscroll_threshold)
2211 if (_elm_config->thumbscroll_threshold > 0.0)
2212 vy = -(double)(_elm_config->thumbscroll_threshold - y) /
2213 _elm_config->thumbscroll_threshold;
2217 else if (y > (eh - _elm_config->thumbscroll_threshold))
2219 if (_elm_config->thumbscroll_threshold > 0.0)
2220 vy = (double)(_elm_config->thumbscroll_threshold - (eh - y)) /
2221 _elm_config->thumbscroll_threshold;
2225 if ((vx != 0.0) || (vy != 0.0))
2227 sd->down.onhold_vx = vx;
2228 sd->down.onhold_vy = vy;
2229 if (!sd->down.onhold_animator)
2231 sd->down.onhold_vxe = 0.0;
2232 sd->down.onhold_vye = 0.0;
2233 sd->down.onhold_tlast = 0.0;
2234 sd->down.onhold_animator = ecore_animator_add(_smart_onhold_animator, sd);
2236 // printf("b %i %i\n", sd->down.hold_x, sd->down.hold_y);
2240 if (sd->down.onhold_animator)
2242 ecore_animator_del(sd->down.onhold_animator);
2243 sd->down.onhold_animator = NULL;
2252 _smart_scrollbar_read(Smart_Data *sd)
2254 Evas_Coord x, y, mx = 0, my = 0, px, py, minx = 0, miny = 0;
2257 edje_object_part_drag_value_get(sd->edje_obj, "elm.dragable.vbar", NULL, &vy);
2258 edje_object_part_drag_value_get(sd->edje_obj, "elm.dragable.hbar", &vx, NULL);
2259 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
2260 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2261 x = vx * (double)mx + minx;
2262 y = vy * (double)my + miny;
2263 sd->pan_func.get(sd->pan_obj, &px, &py);
2264 sd->pan_func.set(sd->pan_obj, x, y);
2265 if ((px != x) || (py != y))
2266 edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
2270 _smart_scrollbar_reset(Smart_Data *sd)
2272 Evas_Coord px = 0, py = 0, minx = 0, miny = 0;
2274 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.vbar", 0.0, 0.0);
2275 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.hbar", 0.0, 0.0);
2276 if ((!sd->child_obj) && (!sd->extern_pan))
2278 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.vbar", 1.0, 1.0);
2279 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.hbar", 1.0, 1.0);
2283 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2284 sd->pan_func.get(sd->pan_obj, &px, &py);
2285 sd->pan_func.set(sd->pan_obj, minx, miny);
2287 if ((px != minx) || (py != miny))
2288 edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
2292 _smart_scrollbar_bar_v_visibility_adjust(Smart_Data *sd)
2294 int scroll_v_vis_change = 0;
2295 Evas_Coord h, vw = 0, vh = 0;
2299 evas_object_geometry_get(sd->pan_obj, NULL, NULL, &vw, &vh);
2300 if (sd->vbar_visible)
2302 if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_AUTO)
2304 if ((sd->child_obj) || (sd->extern_pan))
2308 scroll_v_vis_change = 1;
2309 sd->vbar_visible = 0;
2314 scroll_v_vis_change = 1;
2315 sd->vbar_visible = 0;
2318 else if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
2320 scroll_v_vis_change = 1;
2321 sd->vbar_visible = 0;
2326 if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_AUTO)
2328 if ((sd->child_obj) || (sd->extern_pan))
2332 scroll_v_vis_change = 1;
2333 sd->vbar_visible = 1;
2337 else if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
2339 scroll_v_vis_change = 1;
2340 sd->vbar_visible = 1;
2343 if (scroll_v_vis_change)
2345 if (sd->vbar_flags != ELM_SMART_SCROLLER_POLICY_OFF)
2347 if (sd->vbar_visible)
2348 edje_object_signal_emit(sd->edje_obj, "elm,action,show,vbar", "elm");
2350 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,vbar", "elm");
2351 edje_object_message_signal_process(sd->edje_obj);
2352 _smart_scrollbar_size_adjust(sd);
2355 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,vbar", "elm");
2357 return scroll_v_vis_change;
2361 _smart_scrollbar_bar_h_visibility_adjust(Smart_Data *sd)
2363 int scroll_h_vis_change = 0;
2364 Evas_Coord w, vw = 0, vh = 0;
2368 evas_object_geometry_get(sd->pan_obj, NULL, NULL, &vw, &vh);
2369 if (sd->hbar_visible)
2371 if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_AUTO)
2373 if ((sd->child_obj) || (sd->extern_pan))
2377 scroll_h_vis_change = 1;
2378 sd->hbar_visible = 0;
2383 scroll_h_vis_change = 1;
2384 sd->hbar_visible = 0;
2387 else if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
2389 scroll_h_vis_change = 1;
2390 sd->hbar_visible = 0;
2395 if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_AUTO)
2397 if ((sd->child_obj) || (sd->extern_pan))
2401 scroll_h_vis_change = 1;
2402 sd->hbar_visible = 1;
2406 else if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
2408 scroll_h_vis_change = 1;
2409 sd->hbar_visible = 1;
2412 if (scroll_h_vis_change)
2414 if (sd->hbar_flags != ELM_SMART_SCROLLER_POLICY_OFF)
2416 if (sd->hbar_visible)
2417 edje_object_signal_emit(sd->edje_obj, "elm,action,show,hbar", "elm");
2419 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,hbar", "elm");
2420 edje_object_message_signal_process(sd->edje_obj);
2421 _smart_scrollbar_size_adjust(sd);
2424 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,hbar", "elm");
2425 _smart_scrollbar_size_adjust(sd);
2427 return scroll_h_vis_change;
2431 _smart_scrollbar_bar_visibility_adjust(Smart_Data *sd)
2435 changed |= _smart_scrollbar_bar_h_visibility_adjust(sd);
2436 changed |= _smart_scrollbar_bar_v_visibility_adjust(sd);
2439 _smart_scrollbar_bar_h_visibility_adjust(sd);
2440 _smart_scrollbar_bar_v_visibility_adjust(sd);
2445 _smart_scrollbar_size_adjust(Smart_Data *sd)
2447 if ((sd->child_obj) || (sd->extern_pan))
2449 Evas_Coord x, y, w, h, mx = 0, my = 0, vw = 0, vh = 0, px, py, minx = 0, miny = 0;
2450 double vx, vy, size;
2452 edje_object_part_geometry_get(sd->edje_obj, "elm.swallow.content",
2453 NULL, NULL, &vw, &vh);
2456 size = (double)vw / (double)w;
2460 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.hbar", 0.0, 0.0);
2462 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.hbar", size, 1.0);
2466 size = (double)vh / (double)h;
2470 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.vbar", 0.0, 0.0);
2472 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.vbar", 1.0, size);
2474 edje_object_part_drag_value_get(sd->edje_obj, "elm.dragable.hbar", &vx, NULL);
2475 edje_object_part_drag_value_get(sd->edje_obj, "elm.dragable.vbar", NULL, &vy);
2476 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
2477 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2481 edje_object_part_drag_step_set(sd->edje_obj, "elm.dragable.hbar", (double)sd->step.x / (double)w, 0.0);
2482 edje_object_part_drag_step_set(sd->edje_obj, "elm.dragable.vbar", 0.0, (double)sd->step.y / (double)h);
2484 edje_object_part_drag_page_set(sd->edje_obj, "elm.dragable.hbar", (double)sd->page.x / (double)w, 0.0);
2486 edje_object_part_drag_page_set(sd->edje_obj, "elm.dragable.hbar", -((double)sd->page.x * ((double)vw / (double)w)) / 100.0, 0.0);
2488 edje_object_part_drag_page_set(sd->edje_obj, "elm.dragable.vbar", 0.0, (double)sd->page.y / (double)h);
2490 edje_object_part_drag_page_set(sd->edje_obj, "elm.dragable.vbar", 0.0, -((double)sd->page.y * ((double)vh / (double)h)) / 100.0);
2492 sd->pan_func.get(sd->pan_obj, &px, &py);
2493 if (vx != mx) x = px;
2494 if (vy != my) y = py;
2495 sd->pan_func.set(sd->pan_obj, x, y);
2496 // if ((px != 0) || (py != 0))
2497 // edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
2501 Evas_Coord px = 0, py = 0, minx = 0, miny = 0;
2503 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.vbar", 1.0, 1.0);
2504 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.hbar", 1.0, 1.0);
2505 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2506 sd->pan_func.get(sd->pan_obj, &px, &py);
2507 sd->pan_func.set(sd->pan_obj, minx, miny);
2508 if ((px != minx) || (py != miny))
2509 edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
2511 _smart_scrollbar_bar_visibility_adjust(sd);
2515 _smart_reconfigure(Smart_Data *sd)
2517 evas_object_move(sd->edje_obj, sd->x, sd->y);
2518 evas_object_resize(sd->edje_obj, sd->w, sd->h);
2519 evas_object_move(sd->event_obj, sd->x, sd->y);
2520 evas_object_resize(sd->event_obj, sd->w, sd->h);
2521 _smart_scrollbar_size_adjust(sd);
2525 _smart_add(Evas_Object *obj)
2530 sd = calloc(1, sizeof(Smart_Data));
2532 evas_object_smart_data_set(obj, sd);
2534 sd->smart_obj = obj;
2543 sd->hbar_flags = ELM_SMART_SCROLLER_POLICY_AUTO;
2544 sd->vbar_flags = ELM_SMART_SCROLLER_POLICY_AUTO;
2545 sd->hbar_visible = 1;
2546 sd->vbar_visible = 1;
2548 sd->bounce_horiz = 1;
2549 sd->bounce_vert = 1;
2551 sd->one_dir_at_a_time = 1;
2552 sd->momentum_animator_disabled = 0;
2553 sd->bounce_animator_disabled = 0;
2555 o = edje_object_add(evas_object_evas_get(obj));
2556 evas_object_propagate_events_set(o, 0);
2558 elm_smart_scroller_object_theme_set(NULL, obj, "scroller", "base", "default");
2559 edje_object_signal_callback_add(o, "drag", "elm.dragable.vbar", _smart_edje_drag_v, sd);
2560 edje_object_signal_callback_add(o, "drag,start", "elm.dragable.vbar", _smart_edje_drag_v_start, sd);
2561 edje_object_signal_callback_add(o, "drag,stop", "elm.dragable.vbar", _smart_edje_drag_v_stop, sd);
2562 edje_object_signal_callback_add(o, "drag,step", "elm.dragable.vbar", _smart_edje_drag_v, sd);
2563 edje_object_signal_callback_add(o, "drag,page", "elm.dragable.vbar", _smart_edje_drag_v, sd);
2564 edje_object_signal_callback_add(o, "drag", "elm.dragable.hbar", _smart_edje_drag_h, sd);
2565 edje_object_signal_callback_add(o, "drag,start", "elm.dragable.hbar", _smart_edje_drag_h_start, sd);
2566 edje_object_signal_callback_add(o, "drag,stop", "elm.dragable.hbar", _smart_edje_drag_h_stop, sd);
2567 edje_object_signal_callback_add(o, "drag,step", "elm.dragable.hbar", _smart_edje_drag_h, sd);
2568 edje_object_signal_callback_add(o, "drag,page", "elm.dragable.hbar", _smart_edje_drag_h, sd);
2569 evas_object_smart_member_add(o, obj);
2571 o = evas_object_rectangle_add(evas_object_evas_get(obj));
2573 evas_object_color_set(o, 0, 0, 0, 0);
2574 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_WHEEL, _smart_event_wheel, sd);
2575 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, _smart_event_mouse_down, sd);
2576 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_UP, _smart_event_mouse_up, sd);
2577 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_MOVE, _smart_event_mouse_move, sd);
2578 evas_object_smart_member_add(o, obj);
2579 evas_object_repeat_events_set(o, 1);
2581 sd->pan_func.set = _elm_smart_pan_set;
2582 sd->pan_func.get = _elm_smart_pan_get;
2583 sd->pan_func.max_get = _elm_smart_pan_max_get;
2584 sd->pan_func.min_get = _elm_smart_pan_min_get;
2585 sd->pan_func.child_size_get = _elm_smart_pan_child_size_get;
2587 _smart_scrollbar_reset(sd);
2591 _smart_del(Evas_Object *obj)
2594 elm_smart_scroller_child_set(obj, NULL);
2595 if (!sd->extern_pan) evas_object_del(sd->pan_obj);
2596 evas_object_del(sd->edje_obj);
2597 evas_object_del(sd->event_obj);
2598 if (sd->down.hold_animator) ecore_animator_del(sd->down.hold_animator);
2599 if (sd->down.onhold_animator) ecore_animator_del(sd->down.onhold_animator);
2600 if (sd->down.momentum_animator) ecore_animator_del(sd->down.momentum_animator);
2601 if (sd->down.bounce_x_animator) ecore_animator_del(sd->down.bounce_x_animator);
2602 if (sd->down.bounce_y_animator) ecore_animator_del(sd->down.bounce_y_animator);
2603 if (sd->scrollto.x.animator) ecore_animator_del(sd->scrollto.x.animator);
2604 if (sd->scrollto.y.animator) ecore_animator_del(sd->scrollto.y.animator);
2606 evas_object_smart_data_set(obj, NULL);
2610 _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
2615 _smart_reconfigure(sd);
2619 _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
2624 _smart_reconfigure(sd);
2625 _elm_smart_scroller_wanted_region_set(obj);
2629 _smart_show(Evas_Object *obj)
2632 evas_object_show(sd->edje_obj);
2633 evas_object_show(sd->event_obj);
2637 _smart_hide(Evas_Object *obj)
2640 evas_object_hide(sd->edje_obj);
2641 evas_object_hide(sd->event_obj);
2645 _smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
2648 evas_object_color_set(sd->edje_obj, r, g, b, a);
2652 _smart_clip_set(Evas_Object *obj, Evas_Object *clip)
2655 evas_object_clip_set(sd->edje_obj, clip);
2656 evas_object_clip_set(sd->event_obj, clip);
2660 _smart_clip_unset(Evas_Object *obj)
2663 evas_object_clip_unset(sd->edje_obj);
2664 evas_object_clip_unset(sd->event_obj);
2667 /* never need to touch this */
2674 static const Evas_Smart_Class sc =
2677 EVAS_SMART_CLASS_VERSION,
2695 _smart = evas_smart_class_new(&sc);