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;
1065 if (x < minx) x = minx;
1066 else if ((x + w) > cw) x = cw - w;
1068 if (y < miny) y = miny;
1069 else if ((y + h) > ch) y = ch - h;
1070 elm_smart_scroller_child_pos_set(obj, x, y);
1073 /* Set should be used for calculated positions, for example, when we move
1074 * because of an animation or because this is the correct position after
1077 elm_smart_scroller_child_region_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
1079 _elm_smart_scroller_child_region_show_internal(obj, x, y, w, h, EINA_TRUE);
1082 /* Set should be used for setting the wanted position, for example a user scroll
1083 * or moving the cursor in an entry. */
1085 elm_smart_scroller_child_region_show(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
1087 _elm_smart_scroller_child_region_show_internal(obj, x, y, w, h, EINA_FALSE);
1091 elm_smart_scroller_child_viewport_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
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 _elm_theme_object_set(parent, sd->edje_obj, clas, group, style);
1191 edje_object_scale_set(sd->edje_obj, elm_widget_scale_get(parent) * _elm_config->scale);
1193 edje_object_part_swallow(sd->edje_obj, "elm.swallow.content", sd->pan_obj);
1195 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1196 if (edje_object_part_exists(sd->edje_obj, "elm.scrollbar.base"))
1199 base = edje_object_part_swallow_get(sd->edje_obj, "elm.scrollbar.base");
1202 base = evas_object_rectangle_add(evas_object_evas_get(sd->edje_obj));
1203 evas_object_color_set(base, 0, 0, 0, 0);
1204 edje_object_part_swallow(sd->edje_obj, "elm.scrollbar.base", base);
1206 if (!_elm_config->thumbscroll_enable)
1207 evas_object_size_hint_min_set(base, mw, mh);
1209 sd->vbar_visible = !sd->vbar_visible;
1210 sd->hbar_visible = !sd->hbar_visible;
1211 _smart_scrollbar_bar_visibility_adjust(sd);
1215 elm_smart_scroller_hold_set(Evas_Object *obj, Eina_Bool hold)
1222 elm_smart_scroller_freeze_set(Evas_Object *obj, Eina_Bool freeze)
1225 sd->freeze = freeze;
1228 if (sd->down.onhold_animator)
1230 ecore_animator_del(sd->down.onhold_animator);
1231 sd->down.onhold_animator = NULL;
1237 elm_smart_scroller_bounce_allow_set(Evas_Object *obj, Eina_Bool horiz, Eina_Bool vert)
1240 sd->bounce_horiz = horiz;
1241 sd->bounce_vert = vert;
1245 elm_smart_scroller_bounce_allow_get(const Evas_Object *obj, Eina_Bool *horiz, Eina_Bool *vert)
1248 *horiz = sd->bounce_horiz;
1249 *vert = sd->bounce_vert;
1253 elm_smart_scroller_paging_set(Evas_Object *obj, double pagerel_h, double pagerel_v, Evas_Coord pagesize_h, Evas_Coord pagesize_v)
1256 sd->pagerel_h = pagerel_h;
1257 sd->pagerel_v = pagerel_v;
1258 sd->pagesize_h = pagesize_h;
1259 sd->pagesize_v = pagesize_v;
1260 _smart_page_adjust(sd);
1264 elm_smart_scroller_paging_get(Evas_Object *obj, double *pagerel_h, double *pagerel_v, Evas_Coord *pagesize_h, Evas_Coord *pagesize_v)
1267 if(pagerel_h) *pagerel_h = sd->pagerel_h;
1268 if(pagerel_v) *pagerel_v = sd->pagerel_v;
1269 if(pagesize_h) *pagesize_h = sd->pagesize_h;
1270 if(pagesize_v) *pagesize_v = sd->pagesize_v;
1274 elm_smart_scroller_region_bring_in(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
1276 Evas_Coord mx = 0, my = 0, cw = 0, ch = 0, px = 0, py = 0, nx, ny, minx = 0, miny = 0;
1279 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
1280 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
1281 sd->pan_func.child_size_get(sd->pan_obj, &cw, &ch);
1282 sd->pan_func.get(sd->pan_obj, &px, &py);
1285 if ((x < px) && ((x + w) < (px + (cw - mx)))) nx = x;
1286 else if ((x > px) && ((x + w) > (px + (cw - mx)))) nx = x + w - (cw - mx);
1288 if ((y < py) && ((y + h) < (py + (ch - my)))) ny = y;
1289 else if ((y > py) && ((y + h) > (py + (ch - my)))) ny = y + h - (ch - my);
1294 if ((nx == px) && (ny == py)) return;
1295 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1296 (sd->scrollto.x.animator) || (sd->scrollto.y.animator))
1298 _smart_anim_stop(sd->smart_obj);
1300 if (sd->scrollto.x.animator)
1302 ecore_animator_del(sd->scrollto.x.animator);
1303 sd->scrollto.x.animator = NULL;
1305 if (sd->scrollto.y.animator)
1307 ecore_animator_del(sd->scrollto.y.animator);
1308 sd->scrollto.y.animator = NULL;
1310 if (sd->down.bounce_x_animator)
1312 ecore_animator_del(sd->down.bounce_x_animator);
1313 sd->down.bounce_x_animator = NULL;
1316 if (sd->down.bounce_y_animator)
1318 ecore_animator_del(sd->down.bounce_y_animator);
1319 sd->down.bounce_y_animator = NULL;
1322 if (sd->down.hold_animator)
1324 ecore_animator_del(sd->down.hold_animator);
1325 sd->down.hold_animator = NULL;
1326 _smart_drag_stop(sd->smart_obj);
1328 if (sd->down.momentum_animator)
1330 ecore_animator_del(sd->down.momentum_animator);
1331 sd->down.momentum_animator = NULL;
1332 sd->down.bounce_x_hold = 0;
1333 sd->down.bounce_y_hold = 0;
1340 if (x < minx) x = minx;
1341 else if ((x + w) > cw) x = cw - w;
1342 _smart_scrollto_x(sd, _elm_config->bring_in_scroll_friction, x);
1344 if (y < miny) y = miny;
1345 else if ((y + h) > ch) y = ch - h;
1346 _smart_scrollto_y(sd, _elm_config->bring_in_scroll_friction, y);
1350 elm_smart_scroller_widget_set(Evas_Object *obj, Evas_Object *wid)
1357 _elm_smart_scroller_wanted_region_set(Evas_Object *obj)
1360 Evas_Coord ww, wh, wx = sd->wx;
1362 /* Flip to RTL cords only if init in RTL mode */
1364 wx = _elm_smart_scroller_x_mirrored_get(obj, sd->wx);
1368 elm_smart_scroller_child_viewport_size_get(obj, &ww, &wh);
1376 elm_smart_scroller_child_region_set(obj, wx, sd->wy, ww, wh);
1379 /* local subsystem functions */
1381 _smart_edje_drag_v_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1386 _smart_scrollbar_read(sd);
1387 _smart_drag_start(sd->smart_obj);
1388 sd->freeze = EINA_TRUE;
1392 _smart_edje_drag_v_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1397 _smart_scrollbar_read(sd);
1398 _smart_drag_stop(sd->smart_obj);
1399 sd->freeze = EINA_FALSE;
1403 _smart_edje_drag_v(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1408 _smart_scrollbar_read(sd);
1412 _smart_edje_drag_h_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1417 _smart_scrollbar_read(sd);
1418 _smart_drag_start(sd->smart_obj);
1419 sd->freeze = EINA_TRUE;
1423 _smart_edje_drag_h_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1428 _smart_scrollbar_read(sd);
1429 _smart_drag_stop(sd->smart_obj);
1430 sd->freeze = EINA_FALSE;
1434 _smart_edje_drag_h(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1439 _smart_scrollbar_read(sd);
1443 _smart_child_del_hook(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1448 sd->child_obj = NULL;
1449 _smart_scrollbar_size_adjust(sd);
1450 _smart_scrollbar_reset(sd);
1454 _smart_pan_changed_hook(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1460 sd->pan_func.child_size_get(sd->pan_obj, &w, &h);
1461 if ((w != sd->child.w) || (h != sd->child.h))
1465 _smart_scrollbar_size_adjust(sd);
1466 evas_object_size_hint_min_set(sd->smart_obj, sd->child.w, sd->child.h);
1467 _elm_smart_scroller_wanted_region_set(sd->smart_obj);
1472 _smart_pan_pan_changed_hook(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1477 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1478 (sd->scrollto.x.animator) || (sd->scrollto.y.animator))
1480 _smart_anim_stop(sd->smart_obj);
1482 if (sd->scrollto.x.animator)
1484 ecore_animator_del(sd->scrollto.x.animator);
1485 sd->scrollto.x.animator = NULL;
1487 if (sd->scrollto.y.animator)
1489 ecore_animator_del(sd->scrollto.y.animator);
1490 sd->scrollto.y.animator = NULL;
1492 if (sd->down.bounce_x_animator)
1494 ecore_animator_del(sd->down.bounce_x_animator);
1495 sd->down.bounce_x_animator = NULL;
1498 if (sd->down.bounce_y_animator)
1500 ecore_animator_del(sd->down.bounce_y_animator);
1501 sd->down.bounce_y_animator = NULL;
1504 _elm_smart_scroller_wanted_region_set(sd->smart_obj);
1508 _smart_event_wheel(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1510 Evas_Event_Mouse_Wheel *ev;
1512 Evas_Coord x = 0, y = 0;
1516 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
1517 if ((evas_key_modifier_is_set(ev->modifiers, "Control")) ||
1518 (evas_key_modifier_is_set(ev->modifiers, "Alt")) ||
1519 (evas_key_modifier_is_set(ev->modifiers, "Shift")) ||
1520 (evas_key_modifier_is_set(ev->modifiers, "Meta")) ||
1521 (evas_key_modifier_is_set(ev->modifiers, "Hyper")) ||
1522 (evas_key_modifier_is_set(ev->modifiers, "Super")))
1524 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1525 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1526 (sd->scrollto.x.animator) || (sd->scrollto.y.animator))
1528 _smart_anim_stop(sd->smart_obj);
1530 if (sd->scrollto.x.animator)
1532 ecore_animator_del(sd->scrollto.x.animator);
1533 sd->scrollto.x.animator = NULL;
1535 if (sd->scrollto.y.animator)
1537 ecore_animator_del(sd->scrollto.y.animator);
1538 sd->scrollto.y.animator = NULL;
1540 if (sd->down.bounce_x_animator)
1542 ecore_animator_del(sd->down.bounce_x_animator);
1543 sd->down.bounce_x_animator = NULL;
1546 if (sd->down.bounce_y_animator)
1548 ecore_animator_del(sd->down.bounce_y_animator);
1549 sd->down.bounce_y_animator = NULL;
1553 y += ev->z * sd->step.y;
1554 else if (ev->direction == 1)
1555 x += ev->z * sd->step.x;
1557 if ((!sd->hold) && (!sd->freeze))
1559 _update_wanted_coordinates(sd, x, y);
1560 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
1565 _smart_event_mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1567 Evas_Event_Mouse_Down *ev;
1569 Evas_Coord x = 0, y = 0;
1573 // if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
1574 if (_elm_config->thumbscroll_enable)
1577 if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1578 (sd->down.momentum_animator) || (sd->scrollto.x.animator) ||
1579 (sd->scrollto.y.animator))
1581 ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL | EVAS_EVENT_FLAG_ON_HOLD;
1582 sd->down.scroll = 1;
1584 _smart_anim_stop(sd->smart_obj);
1586 if (sd->scrollto.x.animator)
1588 ecore_animator_del(sd->scrollto.x.animator);
1589 sd->scrollto.x.animator = NULL;
1591 if (sd->scrollto.y.animator)
1593 ecore_animator_del(sd->scrollto.y.animator);
1594 sd->scrollto.y.animator = NULL;
1596 if (sd->down.bounce_x_animator)
1598 ecore_animator_del(sd->down.bounce_x_animator);
1599 sd->down.bounce_x_animator = NULL;
1602 if (sd->down.bounce_y_animator)
1604 ecore_animator_del(sd->down.bounce_y_animator);
1605 sd->down.bounce_y_animator = NULL;
1608 if (sd->down.hold_animator)
1610 ecore_animator_del(sd->down.hold_animator);
1611 sd->down.hold_animator = NULL;
1612 _smart_drag_stop(sd->smart_obj);
1614 if (sd->down.momentum_animator)
1616 ecore_animator_del(sd->down.momentum_animator);
1617 sd->down.momentum_animator = NULL;
1618 sd->down.bounce_x_hold = 0;
1619 sd->down.bounce_y_hold = 0;
1623 if (ev->button == 1)
1626 sd->down.dragged = 0;
1629 sd->down.x = ev->canvas.x;
1630 sd->down.y = ev->canvas.y;
1631 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1634 sd->down.locked = 0;
1635 memset(&(sd->down.history[0]), 0, sizeof(sd->down.history[0]) * 20);
1637 sd->down.history[0].timestamp = ev->timestamp / 1000.0;
1639 sd->down.history[0].timestamp = ecore_loop_time_get();
1641 sd->down.history[0].x = ev->canvas.x;
1642 sd->down.history[0].y = ev->canvas.y;
1644 sd->down.dragged_began = 0;
1645 sd->down.hold_parent = 0;
1646 sd->down.cancelled = 0;
1651 _smart_hold_animator(void *data)
1653 Smart_Data *sd = data;
1656 elm_smart_scroller_child_pos_get(sd->smart_obj, &ox, &oy);
1659 if ((!sd->widget) ||
1660 (!elm_widget_drag_child_locked_x_get(sd->widget)))
1662 ox = sd->down.hold_x;
1667 if ((!sd->widget) ||
1668 (!elm_widget_drag_child_locked_y_get(sd->widget)))
1670 oy = sd->down.hold_y;
1673 elm_smart_scroller_child_pos_set(sd->smart_obj, ox, oy);
1674 return ECORE_CALLBACK_RENEW;
1678 _smart_event_post_up(void *data, Evas *e __UNUSED__)
1680 Smart_Data *sd = data;
1683 if (sd->down.dragged)
1685 elm_widget_drag_lock_x_set(sd->widget, 0);
1686 elm_widget_drag_lock_y_set(sd->widget, 0);
1693 _smart_event_mouse_up(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *event_info)
1695 Evas_Event_Mouse_Down *ev;
1697 Evas_Coord x = 0, y = 0, ox = 0, oy = 0;
1701 sd->down.hold_parent = 0;
1702 // if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
1703 evas_post_event_callback_push(e, _smart_event_post_up, sd);
1704 // FIXME: respect elm_widget_scroll_hold_get of parent container
1705 if (_elm_config->thumbscroll_enable)
1707 if (ev->button == 1)
1709 if (sd->down.onhold_animator)
1711 ecore_animator_del(sd->down.onhold_animator);
1712 sd->down.onhold_animator = NULL;
1714 x = ev->canvas.x - sd->down.x;
1715 y = ev->canvas.y - sd->down.y;
1716 if (sd->down.dragged)
1718 _smart_drag_stop(sd->smart_obj);
1719 if ((!sd->hold) && (!sd->freeze))
1723 Evas_Coord ax, ay, dx, dy, vel;
1726 t = ev->timestamp / 1000.0;
1728 t = ecore_loop_time_get();
1730 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1735 printf("------ %i %i\n", ev->canvas.x, ev->canvas.y);
1737 for (i = 0; i < 20; i++)
1739 dt = t - sd->down.history[i].timestamp;
1740 if (dt > 0.2) break;
1742 printf("H: %i %i @ %1.3f\n",
1743 sd->down.history[i].x,
1744 sd->down.history[i].y, dt);
1747 ax += sd->down.history[i].x;
1748 ay += sd->down.history[i].y;
1754 dx = ev->canvas.x - ax;
1755 dy = ev->canvas.y - ay;
1758 vel = sqrt((dx * dx) + (dy * dy)) / at;
1759 if ((_elm_config->thumbscroll_friction > 0.0) &&
1760 (vel > _elm_config->thumbscroll_momentum_threshold) &&
1763 sd->down.dx = ((double)dx / at);
1764 sd->down.dy = ((double)dy / at);
1765 if (((sd->down.dx > 0) && (sd->down.pdx > 0)) ||
1766 ((sd->down.dx < 0) && (sd->down.pdx < 0)))
1767 sd->down.dx += (double)sd->down.pdx * 1.5; // FIXME: * 1.5 - probably should be config
1768 if (((sd->down.dy > 0) && (sd->down.pdy > 0)) ||
1769 ((sd->down.dy < 0) && (sd->down.pdy < 0)))
1770 sd->down.dy += (double)sd->down.pdy * 1.5; // FIXME: * 1.5 - probably should be config
1771 if (((sd->down.dx > 0) && (sd->down.pdx > 0)) ||
1772 ((sd->down.dx < 0) && (sd->down.pdx < 0)) ||
1773 ((sd->down.dy > 0) && (sd->down.pdy > 0)) ||
1774 ((sd->down.dy < 0) && (sd->down.pdy < 0)))
1776 double t = ecore_loop_time_get();
1777 double dt = t - sd->down.anim_start;
1779 if (dt < 0.0) dt = 0.0;
1780 else if (dt > _elm_config->thumbscroll_friction)
1781 dt = _elm_config->thumbscroll_friction;
1782 sd->down.extra_time = _elm_config->thumbscroll_friction - dt;
1785 sd->down.extra_time = 0.0;
1786 sd->down.pdx = sd->down.dx;
1787 sd->down.pdy = sd->down.dy;
1790 if (!_smart_do_page(sd))
1792 if (!sd->down.momentum_animator && !sd->momentum_animator_disabled)
1794 sd->down.momentum_animator = ecore_animator_add(_smart_momentum_animator, sd);
1795 ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL;
1796 _smart_anim_start(sd->smart_obj);
1798 sd->down.anim_start = ecore_loop_time_get();
1799 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1807 if (sd->down.hold_animator)
1809 ecore_animator_del(sd->down.hold_animator);
1810 sd->down.hold_animator = NULL;
1818 evas_event_feed_hold(e, 0, ev->timestamp, ev->data);
1819 if (_smart_do_page(sd))
1821 Evas_Coord pgx, pgy;
1823 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1824 if ((!sd->widget) ||
1825 (!elm_widget_drag_child_locked_x_get(sd->widget)))
1827 pgx = _smart_page_x_get(sd, ox);
1830 ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL;
1831 _smart_scrollto_x(sd, _elm_config->page_scroll_friction, pgx);
1834 if ((!sd->widget) ||
1835 (!elm_widget_drag_child_locked_y_get(sd->widget)))
1837 pgy = _smart_page_y_get(sd, oy);
1840 ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL;
1841 _smart_scrollto_y(sd, _elm_config->page_scroll_friction, pgy);
1850 if (_smart_do_page(sd))
1852 Evas_Coord pgx, pgy;
1854 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1855 if ((!sd->widget) ||
1856 (!elm_widget_drag_child_locked_x_get(sd->widget)))
1858 pgx = _smart_page_x_get(sd, ox);
1859 if (pgx != x) _smart_scrollto_x(sd, _elm_config->page_scroll_friction, pgx);
1861 if ((!sd->widget) ||
1862 (!elm_widget_drag_child_locked_y_get(sd->widget)))
1864 pgy = _smart_page_y_get(sd, oy);
1865 if (pgy != y) _smart_scrollto_y(sd, _elm_config->page_scroll_friction, pgy);
1868 if (sd->down.hold_animator)
1870 ecore_animator_del(sd->down.hold_animator);
1871 sd->down.hold_animator = NULL;
1874 if (sd->down.scroll)
1876 ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL;
1877 sd->down.scroll = 0;
1881 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1884 sd->down.dragged_began = 0;
1887 sd->down.want_dragged = 0;
1888 sd->down.dragged = 0;
1890 elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1891 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
1892 _update_wanted_coordinates(sd, x, y);
1894 if (!_smart_do_page(sd))
1901 _smart_onhold_animator(void *data)
1906 Evas_Coord x, y, ox, oy;
1909 t = ecore_loop_time_get();
1910 if (sd->down.onhold_tlast > 0.0)
1912 td = t - sd->down.onhold_tlast;
1913 vx = sd->down.onhold_vx * td * (double)_elm_config->thumbscroll_threshold * 2.0;
1914 vy = sd->down.onhold_vy * td * (double)_elm_config->thumbscroll_threshold * 2.0;
1915 elm_smart_scroller_child_pos_get(sd->smart_obj, &ox, &oy);
1921 if ((!sd->widget) ||
1922 (!elm_widget_drag_child_locked_x_get(sd->widget)))
1924 sd->down.onhold_vxe += vx;
1925 x = ox + (int)sd->down.onhold_vxe;
1926 sd->down.onhold_vxe -= (int)sd->down.onhold_vxe;
1932 if ((!sd->widget) ||
1933 (!elm_widget_drag_child_locked_y_get(sd->widget)))
1935 sd->down.onhold_vye += vy;
1936 y = oy + (int)sd->down.onhold_vye;
1937 sd->down.onhold_vye -= (int)sd->down.onhold_vye;
1941 elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
1943 sd->down.onhold_tlast = t;
1944 return ECORE_CALLBACK_RENEW;
1948 _smart_event_post_move(void *data, Evas *e __UNUSED__)
1950 Smart_Data *sd = data;
1952 if (sd->down.want_dragged)
1956 if (sd->down.hold_parent)
1958 if ((sd->down.dir_x) && !can_scroll(sd, sd->down.hdir))
1962 if ((sd->down.dir_y) && !can_scroll(sd, sd->down.vdir))
1969 if ((!sd->widget) ||
1970 (!elm_widget_drag_child_locked_x_get(sd->widget)))
1972 sd->down.want_dragged = 0;
1973 sd->down.dragged = 1;
1976 elm_widget_drag_lock_x_set(sd->widget, 1);
1985 if ((!sd->widget) ||
1986 (!elm_widget_drag_child_locked_y_get(sd->widget)))
1988 sd->down.want_dragged = 0;
1989 sd->down.dragged = 1;
1992 elm_widget_drag_lock_y_set(sd->widget, 1);
1999 if ((!sd->down.dir_x) && (!sd->down.dir_y))
2001 sd->down.cancelled = 1;
2003 if (start) _smart_drag_start(sd->smart_obj);
2009 _smart_event_mouse_move(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *event_info)
2011 Evas_Event_Mouse_Move *ev;
2013 Evas_Coord x = 0, y = 0;
2017 // if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
2018 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) sd->down.hold_parent = 1;
2019 evas_post_event_callback_push(e, _smart_event_post_move, sd);
2020 // FIXME: respect elm_widget_scroll_hold_get of parent container
2021 if (_elm_config->thumbscroll_enable)
2028 printf("::: %i %i\n", ev->cur.canvas.x, ev->cur.canvas.y);
2030 memmove(&(sd->down.history[1]), &(sd->down.history[0]),
2031 sizeof(sd->down.history[0]) * 19);
2033 sd->down.history[0].timestamp = ev->timestamp / 1000.0;
2035 sd->down.history[0].timestamp = ecore_loop_time_get();
2037 sd->down.history[0].x = ev->cur.canvas.x;
2038 sd->down.history[0].y = ev->cur.canvas.y;
2040 if (!sd->down.dragged_began)
2042 x = ev->cur.canvas.x - sd->down.x;
2043 y = ev->cur.canvas.y - sd->down.y;
2048 if (x > 0) sd->down.hdir = LEFT;
2049 else if (x < 0) sd->down.hdir = RIGHT;
2050 if (y > 0) sd->down.vdir = UP;
2051 else if (y < 0) sd->down.vdir = DOWN;
2056 if ((sd->one_dir_at_a_time) &&
2057 (!((sd->down.dir_x) || (sd->down.dir_y))))
2059 if (x > _elm_config->thumbscroll_threshold)
2068 if (y > _elm_config->thumbscroll_threshold)
2085 // can_scroll(sd, LEFT);
2086 // can_scroll(sd, RIGHT);
2087 // can_scroll(sd, UP);
2088 // can_scroll(sd, DOWN);
2093 if ((!sd->hold) && (!sd->freeze))
2095 if ((sd->down.dragged) ||
2096 (((x * x) + (y * y)) >
2097 (_elm_config->thumbscroll_threshold *
2098 _elm_config->thumbscroll_threshold)))
2100 sd->down.dragged_began = 1;
2101 if (!sd->down.dragged)
2103 sd->down.want_dragged = 1;
2104 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2105 // evas_event_feed_hold(e, 1, ev->timestamp, ev->data);
2106 // _smart_drag_start(sd->smart_obj);
2108 if (sd->down.dragged)
2110 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2112 // ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2113 // sd->down.dragged = 1;
2115 x = sd->down.sx - (ev->cur.canvas.x - sd->down.x);
2119 y = sd->down.sy - (ev->cur.canvas.y - sd->down.y);
2122 if ((sd->down.dir_x) || (sd->down.dir_y))
2124 if (!sd->down.locked)
2126 sd->down.locked_x = x;
2127 sd->down.locked_y = y;
2128 sd->down.locked = 1;
2130 if (!((sd->down.dir_x) && (sd->down.dir_y)))
2132 if (sd->down.dir_x) y = sd->down.locked_y;
2133 else x = sd->down.locked_x;
2136 if (_elm_config->thumbscroll_border_friction > 0.0)
2138 Evas_Coord minx, miny;
2139 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2142 _elm_config->thumbscroll_border_friction;
2143 else if (sd->child.h <= sd->h)
2144 y += (sd->down.sy - y) *
2145 _elm_config->thumbscroll_border_friction;
2146 else if ((sd->child.h - sd->h + miny) < y)
2147 y += (sd->child.h - sd->h + miny - y) *
2148 _elm_config->thumbscroll_border_friction;
2151 _elm_config->thumbscroll_border_friction;
2152 else if (sd->child.w <= sd->w)
2153 x += (sd->down.sx - x) *
2154 _elm_config->thumbscroll_border_friction;
2155 else if ((sd->child.w - sd->w + minx) < x)
2156 x += (sd->child.w - sd->w + minx - x) *
2157 _elm_config->thumbscroll_border_friction;
2160 sd->down.hold_x = x;
2161 sd->down.hold_y = y;
2162 if (!sd->down.hold_animator)
2163 sd->down.hold_animator =
2164 ecore_animator_add(_smart_hold_animator, sd);
2165 // printf("a %i %i\n", sd->down.hold_x, sd->down.hold_y);
2166 // _smart_onhold_animator(sd);
2167 // elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
2171 if (sd->down.dragged_began)
2173 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2177 evas_event_feed_hold(e, 1, ev->timestamp, ev->data);
2182 else if (!sd->freeze)
2184 Evas_Coord ex, ey, ew, eh;
2185 double vx = 0.0, vy = 0.0;
2187 evas_object_geometry_get(sd->event_obj, &ex, &ey, &ew, &eh);
2188 x = ev->cur.canvas.x - ex;
2189 y = ev->cur.canvas.y - ey;
2190 if (x < _elm_config->thumbscroll_threshold)
2192 if (_elm_config->thumbscroll_threshold > 0.0)
2193 vx = -(double)(_elm_config->thumbscroll_threshold - x) /
2194 _elm_config->thumbscroll_threshold;
2198 else if (x > (ew - _elm_config->thumbscroll_threshold))
2200 if (_elm_config->thumbscroll_threshold > 0.0)
2201 vx = (double)(_elm_config->thumbscroll_threshold - (ew - x)) /
2202 _elm_config->thumbscroll_threshold;
2206 if (y < _elm_config->thumbscroll_threshold)
2208 if (_elm_config->thumbscroll_threshold > 0.0)
2209 vy = -(double)(_elm_config->thumbscroll_threshold - y) /
2210 _elm_config->thumbscroll_threshold;
2214 else if (y > (eh - _elm_config->thumbscroll_threshold))
2216 if (_elm_config->thumbscroll_threshold > 0.0)
2217 vy = (double)(_elm_config->thumbscroll_threshold - (eh - y)) /
2218 _elm_config->thumbscroll_threshold;
2222 if ((vx != 0.0) || (vy != 0.0))
2224 sd->down.onhold_vx = vx;
2225 sd->down.onhold_vy = vy;
2226 if (!sd->down.onhold_animator)
2228 sd->down.onhold_vxe = 0.0;
2229 sd->down.onhold_vye = 0.0;
2230 sd->down.onhold_tlast = 0.0;
2231 sd->down.onhold_animator = ecore_animator_add(_smart_onhold_animator, sd);
2233 // printf("b %i %i\n", sd->down.hold_x, sd->down.hold_y);
2237 if (sd->down.onhold_animator)
2239 ecore_animator_del(sd->down.onhold_animator);
2240 sd->down.onhold_animator = NULL;
2249 _smart_scrollbar_read(Smart_Data *sd)
2251 Evas_Coord x, y, mx = 0, my = 0, px, py, minx = 0, miny = 0;
2254 edje_object_part_drag_value_get(sd->edje_obj, "elm.dragable.vbar", NULL, &vy);
2255 edje_object_part_drag_value_get(sd->edje_obj, "elm.dragable.hbar", &vx, NULL);
2256 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
2257 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2258 x = vx * (double)mx + minx;
2259 y = vy * (double)my + miny;
2260 sd->pan_func.get(sd->pan_obj, &px, &py);
2261 sd->pan_func.set(sd->pan_obj, x, y);
2262 if ((px != x) || (py != y))
2263 edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
2267 _smart_scrollbar_reset(Smart_Data *sd)
2269 Evas_Coord px = 0, py = 0, minx = 0, miny = 0;
2271 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.vbar", 0.0, 0.0);
2272 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.hbar", 0.0, 0.0);
2273 if ((!sd->child_obj) && (!sd->extern_pan))
2275 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.vbar", 1.0, 1.0);
2276 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.hbar", 1.0, 1.0);
2278 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2279 sd->pan_func.get(sd->pan_obj, &px, &py);
2280 sd->pan_func.set(sd->pan_obj, minx, miny);
2281 if ((px != minx) || (py != miny))
2282 edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
2286 _smart_scrollbar_bar_v_visibility_adjust(Smart_Data *sd)
2288 int scroll_v_vis_change = 0;
2289 Evas_Coord h, vw, vh;
2292 evas_object_geometry_get(sd->pan_obj, NULL, NULL, &vw, &vh);
2293 if (sd->vbar_visible)
2295 if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_AUTO)
2297 if ((sd->child_obj) || (sd->extern_pan))
2301 scroll_v_vis_change = 1;
2302 sd->vbar_visible = 0;
2307 scroll_v_vis_change = 1;
2308 sd->vbar_visible = 0;
2311 else if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
2313 scroll_v_vis_change = 1;
2314 sd->vbar_visible = 0;
2319 if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_AUTO)
2321 if ((sd->child_obj) || (sd->extern_pan))
2325 scroll_v_vis_change = 1;
2326 sd->vbar_visible = 1;
2330 else if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
2332 scroll_v_vis_change = 1;
2333 sd->vbar_visible = 1;
2336 if (scroll_v_vis_change)
2338 if (sd->vbar_flags != ELM_SMART_SCROLLER_POLICY_OFF)
2340 if (sd->vbar_visible)
2341 edje_object_signal_emit(sd->edje_obj, "elm,action,show,vbar", "elm");
2343 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,vbar", "elm");
2344 edje_object_message_signal_process(sd->edje_obj);
2345 _smart_scrollbar_size_adjust(sd);
2348 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,vbar", "elm");
2350 return scroll_v_vis_change;
2354 _smart_scrollbar_bar_h_visibility_adjust(Smart_Data *sd)
2356 int scroll_h_vis_change = 0;
2357 Evas_Coord w, vw, vh;
2360 evas_object_geometry_get(sd->pan_obj, NULL, NULL, &vw, &vh);
2361 if (sd->hbar_visible)
2363 if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_AUTO)
2365 if ((sd->child_obj) || (sd->extern_pan))
2369 scroll_h_vis_change = 1;
2370 sd->hbar_visible = 0;
2375 scroll_h_vis_change = 1;
2376 sd->hbar_visible = 0;
2379 else if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
2381 scroll_h_vis_change = 1;
2382 sd->hbar_visible = 0;
2387 if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_AUTO)
2389 if ((sd->child_obj) || (sd->extern_pan))
2393 scroll_h_vis_change = 1;
2394 sd->hbar_visible = 1;
2398 else if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
2400 scroll_h_vis_change = 1;
2401 sd->hbar_visible = 1;
2404 if (scroll_h_vis_change)
2406 if (sd->hbar_flags != ELM_SMART_SCROLLER_POLICY_OFF)
2408 if (sd->hbar_visible)
2409 edje_object_signal_emit(sd->edje_obj, "elm,action,show,hbar", "elm");
2411 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,hbar", "elm");
2412 edje_object_message_signal_process(sd->edje_obj);
2413 _smart_scrollbar_size_adjust(sd);
2416 edje_object_signal_emit(sd->edje_obj, "elm,action,hide,hbar", "elm");
2417 _smart_scrollbar_size_adjust(sd);
2419 return scroll_h_vis_change;
2423 _smart_scrollbar_bar_visibility_adjust(Smart_Data *sd)
2427 changed |= _smart_scrollbar_bar_h_visibility_adjust(sd);
2428 changed |= _smart_scrollbar_bar_v_visibility_adjust(sd);
2431 _smart_scrollbar_bar_h_visibility_adjust(sd);
2432 _smart_scrollbar_bar_v_visibility_adjust(sd);
2437 _smart_scrollbar_size_adjust(Smart_Data *sd)
2439 if ((sd->child_obj) || (sd->extern_pan))
2441 Evas_Coord x, y, w, h, mx = 0, my = 0, vw = 0, vh = 0, px, py, minx = 0, miny = 0;
2442 double vx, vy, size;
2444 edje_object_part_geometry_get(sd->edje_obj, "elm.swallow.content",
2445 NULL, NULL, &vw, &vh);
2448 size = (double)vw / (double)w;
2452 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.hbar", 0.0, 0.0);
2454 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.hbar", size, 1.0);
2458 size = (double)vh / (double)h;
2462 edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.vbar", 0.0, 0.0);
2464 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.vbar", 1.0, size);
2466 edje_object_part_drag_value_get(sd->edje_obj, "elm.dragable.hbar", &vx, NULL);
2467 edje_object_part_drag_value_get(sd->edje_obj, "elm.dragable.vbar", NULL, &vy);
2468 sd->pan_func.max_get(sd->pan_obj, &mx, &my);
2469 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2473 edje_object_part_drag_step_set(sd->edje_obj, "elm.dragable.hbar", (double)sd->step.x / (double)w, 0.0);
2474 edje_object_part_drag_step_set(sd->edje_obj, "elm.dragable.vbar", 0.0, (double)sd->step.y / (double)h);
2476 edje_object_part_drag_page_set(sd->edje_obj, "elm.dragable.hbar", (double)sd->page.x / (double)w, 0.0);
2478 edje_object_part_drag_page_set(sd->edje_obj, "elm.dragable.hbar", -((double)sd->page.x * ((double)vw / (double)w)) / 100.0, 0.0);
2480 edje_object_part_drag_page_set(sd->edje_obj, "elm.dragable.vbar", 0.0, (double)sd->page.y / (double)h);
2482 edje_object_part_drag_page_set(sd->edje_obj, "elm.dragable.vbar", 0.0, -((double)sd->page.y * ((double)vh / (double)h)) / 100.0);
2484 sd->pan_func.get(sd->pan_obj, &px, &py);
2485 if (vx != mx) x = px;
2486 if (vy != my) y = py;
2487 sd->pan_func.set(sd->pan_obj, x, y);
2488 // if ((px != 0) || (py != 0))
2489 // edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
2493 Evas_Coord px = 0, py = 0, minx = 0, miny = 0;
2495 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.vbar", 1.0, 1.0);
2496 edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.hbar", 1.0, 1.0);
2497 sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2498 sd->pan_func.get(sd->pan_obj, &px, &py);
2499 sd->pan_func.set(sd->pan_obj, minx, miny);
2500 if ((px != minx) || (py != miny))
2501 edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
2503 _smart_scrollbar_bar_visibility_adjust(sd);
2507 _smart_reconfigure(Smart_Data *sd)
2509 evas_object_move(sd->edje_obj, sd->x, sd->y);
2510 evas_object_resize(sd->edje_obj, sd->w, sd->h);
2511 evas_object_move(sd->event_obj, sd->x, sd->y);
2512 evas_object_resize(sd->event_obj, sd->w, sd->h);
2513 _smart_scrollbar_size_adjust(sd);
2517 _smart_add(Evas_Object *obj)
2522 sd = calloc(1, sizeof(Smart_Data));
2524 evas_object_smart_data_set(obj, sd);
2526 sd->smart_obj = obj;
2535 sd->hbar_flags = ELM_SMART_SCROLLER_POLICY_AUTO;
2536 sd->vbar_flags = ELM_SMART_SCROLLER_POLICY_AUTO;
2537 sd->hbar_visible = 1;
2538 sd->vbar_visible = 1;
2540 sd->bounce_horiz = 1;
2541 sd->bounce_vert = 1;
2543 sd->one_dir_at_a_time = 1;
2544 sd->momentum_animator_disabled = 0;
2545 sd->bounce_animator_disabled = 0;
2547 o = edje_object_add(evas_object_evas_get(obj));
2548 evas_object_propagate_events_set(o, 0);
2550 // FIXME: null parent obj ... :(
2551 elm_smart_scroller_object_theme_set(NULL, obj, "scroller", "base", "default");
2552 edje_object_signal_callback_add(o, "drag", "elm.dragable.vbar", _smart_edje_drag_v, sd);
2553 edje_object_signal_callback_add(o, "drag,start", "elm.dragable.vbar", _smart_edje_drag_v_start, sd);
2554 edje_object_signal_callback_add(o, "drag,stop", "elm.dragable.vbar", _smart_edje_drag_v_stop, sd);
2555 edje_object_signal_callback_add(o, "drag,step", "elm.dragable.vbar", _smart_edje_drag_v, sd);
2556 edje_object_signal_callback_add(o, "drag,page", "elm.dragable.vbar", _smart_edje_drag_v, sd);
2557 edje_object_signal_callback_add(o, "drag", "elm.dragable.hbar", _smart_edje_drag_h, sd);
2558 edje_object_signal_callback_add(o, "drag,start", "elm.dragable.hbar", _smart_edje_drag_h_start, sd);
2559 edje_object_signal_callback_add(o, "drag,stop", "elm.dragable.hbar", _smart_edje_drag_h_stop, sd);
2560 edje_object_signal_callback_add(o, "drag,step", "elm.dragable.hbar", _smart_edje_drag_h, sd);
2561 edje_object_signal_callback_add(o, "drag,page", "elm.dragable.hbar", _smart_edje_drag_h, sd);
2562 evas_object_smart_member_add(o, obj);
2564 o = evas_object_rectangle_add(evas_object_evas_get(obj));
2566 evas_object_color_set(o, 0, 0, 0, 0);
2567 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_WHEEL, _smart_event_wheel, sd);
2568 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, _smart_event_mouse_down, sd);
2569 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_UP, _smart_event_mouse_up, sd);
2570 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_MOVE, _smart_event_mouse_move, sd);
2571 evas_object_smart_member_add(o, obj);
2572 evas_object_repeat_events_set(o, 1);
2574 sd->pan_func.set = _elm_smart_pan_set;
2575 sd->pan_func.get = _elm_smart_pan_get;
2576 sd->pan_func.max_get = _elm_smart_pan_max_get;
2577 sd->pan_func.min_get = _elm_smart_pan_min_get;
2578 sd->pan_func.child_size_get = _elm_smart_pan_child_size_get;
2580 _smart_scrollbar_reset(sd);
2584 _smart_del(Evas_Object *obj)
2587 elm_smart_scroller_child_set(obj, NULL);
2588 if (!sd->extern_pan) evas_object_del(sd->pan_obj);
2589 evas_object_del(sd->edje_obj);
2590 evas_object_del(sd->event_obj);
2591 if (sd->down.hold_animator) ecore_animator_del(sd->down.hold_animator);
2592 if (sd->down.onhold_animator) ecore_animator_del(sd->down.onhold_animator);
2593 if (sd->down.momentum_animator) ecore_animator_del(sd->down.momentum_animator);
2594 if (sd->down.bounce_x_animator) ecore_animator_del(sd->down.bounce_x_animator);
2595 if (sd->down.bounce_y_animator) ecore_animator_del(sd->down.bounce_y_animator);
2596 if (sd->scrollto.x.animator) ecore_animator_del(sd->scrollto.x.animator);
2597 if (sd->scrollto.y.animator) ecore_animator_del(sd->scrollto.y.animator);
2599 evas_object_smart_data_set(obj, NULL);
2603 _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
2608 _smart_reconfigure(sd);
2612 _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
2617 _smart_reconfigure(sd);
2618 _elm_smart_scroller_wanted_region_set(obj);
2622 _smart_show(Evas_Object *obj)
2625 evas_object_show(sd->edje_obj);
2626 evas_object_show(sd->event_obj);
2630 _smart_hide(Evas_Object *obj)
2633 evas_object_hide(sd->edje_obj);
2634 evas_object_hide(sd->event_obj);
2638 _smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
2641 evas_object_color_set(sd->edje_obj, r, g, b, a);
2645 _smart_clip_set(Evas_Object *obj, Evas_Object *clip)
2648 evas_object_clip_set(sd->edje_obj, clip);
2649 evas_object_clip_set(sd->event_obj, clip);
2653 _smart_clip_unset(Evas_Object *obj)
2656 evas_object_clip_unset(sd->edje_obj);
2657 evas_object_clip_unset(sd->event_obj);
2660 /* never need to touch this */
2667 static const Evas_Smart_Class sc =
2670 EVAS_SMART_CLASS_VERSION,
2688 _smart = evas_smart_class_new(&sc);