================================================================
[framework/uifw/elementary.git] / src / lib / els_scroller.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3
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;
8
9 #define EVTIME 1
10 //#define SCROLLDBG 1
11
12 struct _Smart_Data
13 {
14    Evas_Coord   x, y, w, h;
15
16    Evas_Object *smart_obj;
17    Evas_Object *child_obj;
18    Evas_Object *pan_obj;
19    Evas_Object *edje_obj;
20    Evas_Object *event_obj;
21
22    Evas_Object *widget;
23    
24    Elm_Smart_Scroller_Policy hbar_flags, vbar_flags;
25
26    struct {
27       Evas_Coord x, y;
28       Evas_Coord sx, sy;
29       Evas_Coord dx, dy;
30       Evas_Coord pdx, pdy;
31       Evas_Coord bx, by;
32       Evas_Coord ax, ay;
33       Evas_Coord bx0, by0;
34       Evas_Coord b0x, b0y;
35       Evas_Coord b2x, b2y;
36       struct {
37          Evas_Coord    x, y;
38          double        timestamp;
39       } history[20];
40       double anim_start;
41       double anim_start2;
42       double anim_start3;
43       double onhold_vx, onhold_vy, onhold_tlast, onhold_vxe, onhold_vye;
44       double extra_time;
45       Evas_Coord hold_x, hold_y;
46       Ecore_Animator *hold_animator;
47       Ecore_Animator *onhold_animator;
48       Ecore_Animator *momentum_animator;
49       Ecore_Animator *bounce_x_animator;
50       Ecore_Animator *bounce_y_animator;
51       Evas_Coord locked_x, locked_y;
52       int hdir, vdir;
53       unsigned char now : 1;
54       unsigned char cancelled : 1;
55       unsigned char hold : 1;
56       unsigned char hold_parent : 1;
57       unsigned char want_dragged : 1;
58       unsigned char dragged : 1;
59       unsigned char dragged_began : 1;
60       unsigned char dir_x : 1;
61       unsigned char dir_y : 1;
62       unsigned char locked : 1;
63       unsigned char bounce_x_hold : 1;
64       unsigned char bounce_y_hold : 1;
65       unsigned char scroll : 1;
66    } down;
67
68    struct {
69       Evas_Coord w, h;
70    } child;
71    struct {
72       Evas_Coord x, y;
73    } step, page;
74
75    struct {
76       void (*set) (Evas_Object *obj, Evas_Coord x, Evas_Coord y);
77       void (*get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y);
78       void (*max_get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y);
79       void (*min_get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y);
80       void (*child_size_get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y);
81    } pan_func;
82
83    struct {
84       struct {
85          Evas_Coord start, end;
86          double t_start, t_end;
87          Ecore_Animator *animator;
88       } x, y;
89    } scrollto;
90
91    double pagerel_h, pagerel_v;
92    Evas_Coord pagesize_h, pagesize_v;
93
94    unsigned char hbar_visible : 1;
95    unsigned char vbar_visible : 1;
96    unsigned char extern_pan : 1;
97    unsigned char one_dir_at_a_time : 1;
98    unsigned char hold : 1;
99    unsigned char freeze : 1;
100    unsigned char bouncemex : 1;
101    unsigned char bouncemey : 1;
102    unsigned char bounce_horiz : 1;
103    unsigned char bounce_vert : 1;
104    unsigned char momentum_animator_disabled :1;
105    unsigned char bounce_animator_disabled :1;
106 };
107
108 /* local subsystem functions */
109 static void _smart_child_del_hook(void *data, Evas *e, Evas_Object *obj, void *event_info);
110 static void _smart_pan_changed_hook(void *data, Evas_Object *obj, void *event_info);
111 static void _smart_pan_pan_changed_hook(void *data, Evas_Object *obj, void *event_info);
112 static void _smart_event_wheel(void *data, Evas *e, Evas_Object *obj, void *event_info);
113 static void _smart_event_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info);
114 static Eina_Bool  _smart_hold_animator(void *data);
115 static Eina_Bool  _smart_momentum_animator(void *data);
116 static void _smart_event_mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info);
117 static Eina_Bool  _smart_onhold_animator(void *data);
118 static void _smart_event_mouse_move(void *data, Evas *e, Evas_Object *obj, void *event_info);
119 static void _smart_edje_drag_v_start(void *data, Evas_Object *obj, const char *emission, const char *source);
120 static void _smart_edje_drag_v_stop(void *data, Evas_Object *obj, const char *emission, const char *source);
121 static void _smart_edje_drag_v(void *data, Evas_Object *obj, const char *emission, const char *source);
122 static void _smart_edje_drag_h_start(void *data, Evas_Object *obj, const char *emission, const char *source);
123 static void _smart_edje_drag_h_stop(void *data, Evas_Object *obj, const char *emission, const char *source);
124 static void _smart_edje_drag_h(void *data, Evas_Object *obj, const char *emission, const char *source);
125 static void _smart_scrollbar_read(Smart_Data *sd);
126 static void _smart_scrollbar_reset(Smart_Data *sd);
127 static int  _smart_scrollbar_bar_h_visibility_adjust(Smart_Data *sd);
128 static int  _smart_scrollbar_bar_v_visibility_adjust(Smart_Data *sd);
129 static void _smart_scrollbar_bar_visibility_adjust(Smart_Data *sd);
130 static void _smart_scrollbar_size_adjust(Smart_Data *sd);
131 static void _smart_reconfigure(Smart_Data *sd);
132 static void _smart_add(Evas_Object *obj);
133 static void _smart_del(Evas_Object *obj);
134 static void _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y);
135 static void _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h);
136 static void _smart_show(Evas_Object *obj);
137 static void _smart_hide(Evas_Object *obj);
138 static void _smart_color_set(Evas_Object *obj, int r, int g, int b, int a);
139 static void _smart_clip_set(Evas_Object *obj, Evas_Object *clip);
140 static void _smart_clip_unset(Evas_Object *obj);
141 static void _smart_init(void);
142
143 /* local subsystem globals */
144 static Evas_Smart *_smart = NULL;
145
146 /* externally accessible functions */
147 Evas_Object *
148 elm_smart_scroller_add(Evas *evas)
149 {
150    _smart_init();
151    return evas_object_smart_add(evas, _smart);
152 }
153
154 void
155 elm_smart_scroller_child_set(Evas_Object *obj, Evas_Object *child)
156 {
157    Evas_Coord w, h;
158    Evas_Object *o;
159
160    API_ENTRY return;
161    if (sd->child_obj)
162      {
163         _elm_smart_pan_child_set(sd->pan_obj, NULL);
164         evas_object_event_callback_del_full(sd->child_obj, EVAS_CALLBACK_DEL, _smart_child_del_hook, sd);
165      }
166
167    sd->child_obj = child;
168    if (!child) return;
169
170    if (!sd->pan_obj)
171      {
172         o = _elm_smart_pan_add(evas_object_evas_get(obj));
173         sd->pan_obj = o;
174         evas_object_smart_callback_add(o, "changed", _smart_pan_changed_hook, sd);
175         evas_object_smart_callback_add(o, "pan_changed", _smart_pan_pan_changed_hook, sd);
176         evas_object_show(o);
177         edje_object_part_swallow(sd->edje_obj, "elm.swallow.content", o);
178      }
179
180    sd->pan_func.set = _elm_smart_pan_set;
181    sd->pan_func.get = _elm_smart_pan_get;
182    sd->pan_func.max_get = _elm_smart_pan_max_get;
183    sd->pan_func.min_get = _elm_smart_pan_min_get;
184    sd->pan_func.child_size_get = _elm_smart_pan_child_size_get;
185
186    evas_object_event_callback_add(child, EVAS_CALLBACK_DEL, _smart_child_del_hook, sd);
187    _elm_smart_pan_child_set(sd->pan_obj, sd->child_obj);
188    sd->pan_func.child_size_get(sd->pan_obj, &w, &h);
189    sd->child.w = w;
190    sd->child.h = h;
191    _smart_scrollbar_size_adjust(sd);
192    _smart_scrollbar_reset(sd);
193 }
194
195 void
196 elm_smart_scroller_extern_pan_set(Evas_Object *obj, Evas_Object *pan,
197                                   void (*pan_set) (Evas_Object *obj, Evas_Coord x, Evas_Coord y),
198                                   void (*pan_get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y),
199                                   void (*pan_max_get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y),
200                                   void (*pan_min_get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y),
201                                   void (*pan_child_size_get) (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y))
202 {
203    API_ENTRY return;
204
205    elm_smart_scroller_child_set(obj, NULL);
206
207    if (sd->pan_obj)
208      {
209         evas_object_smart_callback_del(sd->pan_obj, "changed", _smart_pan_changed_hook);
210         evas_object_smart_callback_del(sd->pan_obj, "pan_changed", _smart_pan_pan_changed_hook);
211      }
212
213    if (sd->extern_pan)
214      {
215         if (sd->pan_obj)
216           {
217              edje_object_part_unswallow(sd->edje_obj, sd->pan_obj);
218              sd->pan_obj = NULL;
219           }
220      }
221    else
222      {
223         if (sd->pan_obj)
224           {
225              evas_object_del(sd->pan_obj);
226              sd->pan_obj = NULL;
227           }
228      }
229    if (!pan)
230      {
231         sd->extern_pan = 0;
232         return;
233      }
234
235    sd->pan_obj = pan;
236    sd->pan_func.set = pan_set;
237    sd->pan_func.get = pan_get;
238    sd->pan_func.max_get = pan_max_get;
239    sd->pan_func.min_get = pan_min_get;
240    sd->pan_func.child_size_get = pan_child_size_get;
241    sd->extern_pan = 1;
242    evas_object_smart_callback_add(sd->pan_obj, "changed", _smart_pan_changed_hook, sd);
243    evas_object_smart_callback_add(sd->pan_obj, "pan_changed", _smart_pan_pan_changed_hook, sd);
244    edje_object_part_swallow(sd->edje_obj, "elm.swallow.content", sd->pan_obj);
245    evas_object_show(sd->pan_obj);
246 }
247
248 void
249 elm_smart_scroller_custom_edje_file_set(Evas_Object *obj, char *file, char *group)
250 {
251    API_ENTRY return;
252
253    edje_object_file_set(sd->edje_obj, file, group);
254    if (sd->pan_obj)
255      edje_object_part_swallow(sd->edje_obj, "elm.swallow.content", sd->pan_obj);
256    sd->vbar_visible = !sd->vbar_visible;
257    sd->hbar_visible = !sd->hbar_visible;
258    _smart_scrollbar_bar_visibility_adjust(sd);
259    if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
260      edje_object_signal_emit(sd->edje_obj, "elm,action,show_always,hbar", "elm");
261    else if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
262      edje_object_signal_emit(sd->edje_obj, "elm,action,hide,hbar", "elm");
263    else
264      edje_object_signal_emit(sd->edje_obj, "elm,action,show_notalways,hbar", "elm");
265    if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
266      edje_object_signal_emit(sd->edje_obj, "elm,action,show_always,vbar", "elm");
267    else if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
268      edje_object_signal_emit(sd->edje_obj, "elm,action,hide,vbar", "elm");
269    else
270      edje_object_signal_emit(sd->edje_obj, "elm,action,show_notalways,vbar", "elm");
271 }
272
273 Eina_Bool
274 elm_smart_scroller_momentum_animator_disabled_get(Evas_Object *obj)
275 {
276    API_ENTRY return EINA_FALSE;
277    return sd->momentum_animator_disabled;
278 }
279
280 void
281 elm_smart_scroller_momentum_animator_disabled_set(Evas_Object *obj, Eina_Bool disabled)
282 {
283    API_ENTRY return;
284    sd->momentum_animator_disabled = disabled;
285    if (sd->momentum_animator_disabled)
286      {
287         if (sd->down.momentum_animator)
288           {
289              ecore_animator_del(sd->down.momentum_animator);
290              sd->down.momentum_animator = NULL;
291           }
292      }
293 }
294
295 Eina_Bool
296 elm_smart_scroller_bounce_animator_disabled_get(Evas_Object *obj)
297 {
298    API_ENTRY return EINA_FALSE;
299    return sd->bounce_animator_disabled;
300 }
301
302 void
303 elm_smart_scroller_bounce_animator_disabled_set(Evas_Object *obj, Eina_Bool disabled)
304 {
305    API_ENTRY return;
306    sd->bounce_animator_disabled = disabled;
307    if (sd->bounce_animator_disabled)
308      {
309         if (sd->scrollto.x.animator)
310           {
311              ecore_animator_del(sd->scrollto.x.animator);
312              sd->scrollto.x.animator = NULL;
313           }             
314
315         if (sd->scrollto.y.animator)
316           {
317              ecore_animator_del(sd->scrollto.y.animator);
318              sd->scrollto.y.animator = NULL;
319           }
320      }
321 }
322
323 static void
324 _smart_anim_start(Evas_Object *obj)
325 {
326    evas_object_smart_callback_call(obj, "animate,start", NULL);
327 }
328
329 static void
330 _smart_anim_stop(Evas_Object *obj)
331 {
332    evas_object_smart_callback_call(obj, "animate,stop", NULL);
333 }
334
335 static void
336 _smart_drag_start(Evas_Object *obj)
337 {
338    evas_object_smart_callback_call(obj, "drag,start", NULL);
339 }
340
341 static void
342 _smart_drag_stop(Evas_Object *obj)
343 {
344    evas_object_smart_callback_call(obj, "drag,stop", NULL);
345 }
346
347 static Eina_Bool
348 _smart_scrollto_x_animator(void *data)
349 {
350    Smart_Data *sd = data;
351    Evas_Coord px, py;
352    double t, tt;
353
354    t = ecore_loop_time_get();
355    tt = (t - sd->scrollto.x.t_start) / (sd->scrollto.x.t_end - sd->scrollto.x.t_start);
356    tt = 1.0 - tt;
357    tt = 1.0 - (tt * tt);
358    sd->pan_func.get(sd->pan_obj, &px, &py);
359    px = (sd->scrollto.x.start * (1.0 - tt)) +
360      (sd->scrollto.x.end * tt);
361    if (t >= sd->scrollto.x.t_end)
362      {
363         px = sd->scrollto.x.end;
364         elm_smart_scroller_child_pos_set(sd->smart_obj, px, py);
365         sd->scrollto.x.animator = NULL;
366         if ((!sd->scrollto.y.animator) && (!sd->down.bounce_y_animator))
367           _smart_anim_stop(sd->smart_obj);
368         return ECORE_CALLBACK_CANCEL;
369      }
370    elm_smart_scroller_child_pos_set(sd->smart_obj, px, py);
371    return ECORE_CALLBACK_RENEW;
372 }
373
374 static void
375 _smart_momentum_end(Smart_Data *sd)
376 {
377    if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator)) return;
378    if (sd->down.momentum_animator)
379      {
380         ecore_animator_del(sd->down.momentum_animator);
381         sd->down.momentum_animator = NULL;
382         sd->down.bounce_x_hold = 0;
383         sd->down.bounce_y_hold = 0;
384         sd->down.ax = 0;
385         sd->down.ay = 0;
386         sd->down.pdx = 0;
387         sd->down.pdy = 0;
388      }
389 }
390
391 static void
392 _smart_scrollto_x(Smart_Data *sd, double t_in, Evas_Coord pos_x)
393 {
394    Evas_Coord px, py, x, y, w, h;
395    double t;
396
397    if (sd->freeze) return;
398    if (t_in <= 0.0)
399      {
400         elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
401         elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
402         x = pos_x;
403         elm_smart_scroller_child_region_show(sd->smart_obj, x, y, w, h);
404         return;
405      }
406    t = ecore_loop_time_get();
407    sd->pan_func.get(sd->pan_obj, &px, &py);
408    sd->scrollto.x.start = px;
409    sd->scrollto.x.end = pos_x;
410    sd->scrollto.x.t_start = t;
411    sd->scrollto.x.t_end = t + t_in;
412    elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
413    elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
414    elm_smart_scroller_child_region_show(sd->smart_obj, x, y, w, h);
415    if (!sd->scrollto.x.animator)
416      {
417         if (!sd->scrollto.y.animator)
418           _smart_anim_start(sd->smart_obj);
419         sd->scrollto.x.animator = ecore_animator_add(_smart_scrollto_x_animator, sd);
420      }
421    if (sd->down.bounce_x_animator)
422      {
423         ecore_animator_del(sd->down.bounce_x_animator);
424         sd->down.bounce_x_animator = NULL;
425         _smart_momentum_end(sd);
426      }
427    sd->bouncemex = 0;
428 }
429
430 static Eina_Bool
431 _smart_scrollto_y_animator(void *data)
432 {
433    Smart_Data *sd = data;
434    Evas_Coord px, py;
435    double t, tt;
436
437    t = ecore_loop_time_get();
438    tt = (t - sd->scrollto.y.t_start) / (sd->scrollto.y.t_end - sd->scrollto.y.t_start);
439    tt = 1.0 - tt;
440    tt = 1.0 - (tt * tt);
441    sd->pan_func.get(sd->pan_obj, &px, &py);
442    py = (sd->scrollto.y.start * (1.0 - tt)) +
443      (sd->scrollto.y.end * tt);
444    if (t >= sd->scrollto.y.t_end)
445      {
446         py = sd->scrollto.y.end;
447         elm_smart_scroller_child_pos_set(sd->smart_obj, px, py);
448         sd->scrollto.y.animator = NULL;
449         if ((!sd->scrollto.x.animator) && (!sd->down.bounce_x_animator))
450           _smart_anim_stop(sd->smart_obj);
451         return ECORE_CALLBACK_CANCEL;
452      }
453    elm_smart_scroller_child_pos_set(sd->smart_obj, px, py);
454
455    return ECORE_CALLBACK_RENEW;
456 }
457
458 static void
459 _smart_scrollto_y(Smart_Data *sd, double t_in, Evas_Coord pos_y)
460 {
461    Evas_Coord px, py, x, y, w, h;
462    double t;
463
464    if (sd->freeze) return;
465    if (t_in <= 0.0)
466      {
467         elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
468         elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
469         y = pos_y;
470         elm_smart_scroller_child_region_show(sd->smart_obj, x, y, w, h);
471         return;
472      }
473    t = ecore_loop_time_get();
474    sd->pan_func.get(sd->pan_obj, &px, &py);
475    sd->scrollto.y.start = py;
476    sd->scrollto.y.end = pos_y;
477    sd->scrollto.y.t_start = t;
478    sd->scrollto.y.t_end = t + t_in;
479    elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
480    elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
481    elm_smart_scroller_child_region_show(sd->smart_obj, x, y, w, h);
482    if (!sd->scrollto.y.animator)
483      {
484         if (!sd->scrollto.x.animator)
485           _smart_anim_start(sd->smart_obj);
486         sd->scrollto.y.animator = ecore_animator_add(_smart_scrollto_y_animator, sd);
487      }
488    if (sd->down.bounce_y_animator)
489      {
490         ecore_animator_del(sd->down.bounce_y_animator);
491         sd->down.bounce_y_animator = NULL;
492         _smart_momentum_end(sd);
493      }
494    sd->bouncemey = 0;
495 }
496
497 static Eina_Bool
498 _smart_do_page(Smart_Data *sd)
499 {
500    if ((sd->pagerel_h == 0.0) && (!sd->pagesize_h) &&
501        (sd->pagerel_v == 0.0) && (!sd->pagesize_v))
502      return EINA_FALSE;
503    return EINA_TRUE;
504 }
505
506 static Evas_Coord
507 _smart_page_x_get(Smart_Data *sd, int offset)
508 {
509    Evas_Coord x, y, w, h, cw, ch, minx = 0;
510
511    elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
512    elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
513    sd->pan_func.child_size_get(sd->pan_obj, &cw, &ch);
514    sd->pan_func.min_get(sd->pan_obj, &minx, NULL);
515
516    x += offset;
517
518    if (sd->pagerel_h > 0.0)
519      {
520         x = x + (w * sd->pagerel_h * 0.5);
521         x = x / (w * sd->pagerel_h);
522         x = x * (w * sd->pagerel_h);
523      }
524    else if (sd->pagesize_h > 0)
525      {
526         x = x + (sd->pagesize_h * 0.5);
527         x = x / (sd->pagesize_h);
528         x = x * (sd->pagesize_h);
529      }
530    if (x < minx) x = minx;
531    else if ((x + w) > cw) x = cw - w;
532    return x;
533 }
534
535 static Evas_Coord
536 _smart_page_y_get(Smart_Data *sd, int offset)
537 {
538    Evas_Coord x, y, w, h, cw, ch, miny = 0;
539
540    elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
541    elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
542    sd->pan_func.child_size_get(sd->pan_obj, &cw, &ch);
543    sd->pan_func.min_get(sd->pan_obj, NULL, &miny);
544
545    y += offset;
546
547    if (sd->pagerel_v > 0.0)
548      {
549         y = y + (h * sd->pagerel_v * 0.5);
550         y = y / (h * sd->pagerel_v);
551         y = y * (h * sd->pagerel_v);
552      }
553    else if (sd->pagesize_v > 0)
554      {
555         y = y + (sd->pagesize_v * 0.5);
556         y = y / (sd->pagesize_v);
557         y = y * (sd->pagesize_v);
558      }
559    if (y < miny) y = miny;
560    else if ((y + h) > ch) y = ch - h;
561    return y;
562 }
563
564 static void
565 _smart_page_adjust(Smart_Data *sd)
566 {
567    Evas_Coord x, y, w, h;
568
569    if (!_smart_do_page(sd)) return;
570
571    elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
572
573    x = _smart_page_x_get(sd, 0);
574    y = _smart_page_y_get(sd, 0);
575
576    elm_smart_scroller_child_region_show(sd->smart_obj, x, y, w, h);
577 }
578
579 static Eina_Bool
580 _smart_bounce_x_animator(void *data)
581 {
582    Smart_Data *sd;
583    Evas_Coord x, y, dx;
584    double t, p, dt;
585
586    sd = data;
587    t = ecore_loop_time_get();
588    dt = t - sd->down.anim_start2;
589    if (dt >= 0.0)
590      {
591         dt = dt / _elm_config->thumbscroll_bounce_friction;
592         if (dt > 1.0) dt = 1.0;
593         p = 1.0 - ((1.0 - dt) * (1.0 - dt));
594         elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
595         dx = sd->down.b2x - sd->down.bx;
596         dx = (dx * p);
597         x = sd->down.bx + dx;
598         if (!sd->down.cancelled)
599           elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
600         if (dt >= 1.0)
601           {
602              if (sd->down.momentum_animator)
603                sd->down.bounce_x_hold = 1;
604              else if ((!sd->down.bounce_y_animator) && 
605                  (!sd->scrollto.y.animator))
606                _smart_anim_stop(sd->smart_obj);
607              sd->down.bounce_x_animator = NULL;
608              sd->down.pdx = 0;
609              sd->bouncemex = 0;
610              _smart_momentum_end(sd);
611              return ECORE_CALLBACK_CANCEL;
612           }
613      }
614    return ECORE_CALLBACK_RENEW;
615 }
616
617 static Eina_Bool
618 _smart_bounce_y_animator(void *data)
619 {
620    Smart_Data *sd;
621    Evas_Coord x, y, dy;
622    double t, p, dt;
623
624    sd = data;
625    t = ecore_loop_time_get();
626    dt = t - sd->down.anim_start3;
627    if (dt >= 0.0)
628      {
629         dt = dt / _elm_config->thumbscroll_bounce_friction;
630         if (dt > 1.0) dt = 1.0;
631         p = 1.0 - ((1.0 - dt) * (1.0 - dt));
632         elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
633         dy = sd->down.b2y - sd->down.by;
634         dy = (dy * p);
635         y = sd->down.by + dy;
636         if (!sd->down.cancelled)
637           elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
638         if (dt >= 1.0)
639           {
640              if (sd->down.momentum_animator)
641                sd->down.bounce_y_hold = 1;
642              else if ((!sd->down.bounce_x_animator) && 
643                  (!sd->scrollto.y.animator))
644                _smart_anim_stop(sd->smart_obj);
645              sd->down.bounce_y_animator = NULL;
646              sd->down.pdy = 0;
647              sd->bouncemey = 0;
648              _smart_momentum_end(sd);
649              return ECORE_CALLBACK_CANCEL;
650           }
651      }
652    return ECORE_CALLBACK_RENEW;
653 }
654
655 #define LEFT 0
656 #define RIGHT 1
657 #define UP 2
658 #define DOWN 3
659 static Eina_Bool
660 can_scroll(Smart_Data *sd, int dir)
661 {
662    Evas_Coord mx = 0, my = 0, px = 0, py = 0, minx = 0, miny = 0;
663
664    sd->pan_func.max_get(sd->pan_obj, &mx, &my);
665    sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
666    sd->pan_func.get(sd->pan_obj, &px, &py);
667    switch (dir)
668      {
669      case LEFT:
670         if (px > minx) return EINA_TRUE;
671         break;
672      case RIGHT:
673         if ((px - minx) < mx) return EINA_TRUE;
674         break;
675      case UP:
676         if (py > miny) return EINA_TRUE;
677         break;
678      case DOWN:
679         if ((py - miny) < my) return EINA_TRUE;
680         break;
681      default:
682         break;
683      }
684    return EINA_FALSE;
685 }
686
687 static Eina_Bool
688 _smart_momentum_animator(void *data)
689 {
690    Smart_Data *sd;
691    double t, dt, p;
692    Evas_Coord x, y, dx, dy, px, py, maxx, maxy, minx, miny;
693
694    sd = data;
695    t = ecore_loop_time_get();
696    dt = t - sd->down.anim_start;
697    if (dt >= 0.0)
698      {
699         /*
700         if (sd->down.hold_parent)
701           {
702              if ((sd->down.dir_x) && !can_scroll(sd, sd->down.hdir))
703                {
704                   sd->down.dir_x = 0;
705                }
706              if ((sd->down.dir_y) && !can_scroll(sd, sd->down.vdir))
707                {
708                   sd->down.dir_y = 0;
709                }
710           }
711         if ((!sd->down.dir_x) && (!sd->down.dir_y))
712           {
713              sd->down.cancelled = 1;
714           }
715          */
716         dt = dt / (_elm_config->thumbscroll_friction + sd->down.extra_time);
717         if (dt > 1.0) dt = 1.0;
718         p = 1.0 - ((1.0 - dt) * (1.0 - dt));
719         dx = (sd->down.dx * (_elm_config->thumbscroll_friction + sd->down.extra_time) * p);
720         dy = (sd->down.dy * (_elm_config->thumbscroll_friction + sd->down.extra_time) * p);
721         sd->down.ax = dx;
722         sd->down.ay = dy;
723         x = sd->down.sx - dx;
724         y = sd->down.sy - dy;
725         elm_smart_scroller_child_pos_get(sd->smart_obj, &px, &py);
726         if ((sd->down.bounce_x_animator) ||
727             (sd->down.bounce_x_hold))
728           {
729              sd->down.bx = sd->down.bx0 - dx + sd->down.b0x;
730              x = px;
731           }
732         if ((sd->down.bounce_y_animator) ||
733             (sd->down.bounce_y_hold))
734           {
735              sd->down.by = sd->down.by0 - dy + sd->down.b0y;
736              y = py;
737           }
738         elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
739         sd->pan_func.max_get(sd->pan_obj, &maxx, &maxy);
740         sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
741         if ((dt >= 1.0) || 
742             ((sd->down.bounce_x_hold) && (sd->down.bounce_y_hold)))
743           {
744              _smart_anim_stop(sd->smart_obj);
745              sd->down.momentum_animator = NULL;
746              sd->down.bounce_x_hold = 0;
747              sd->down.bounce_y_hold = 0;
748              sd->down.ax = 0;
749              sd->down.ay = 0;
750              sd->down.pdx = 0;
751              sd->down.pdy = 0;
752              return ECORE_CALLBACK_CANCEL;
753           }
754      }
755    return ECORE_CALLBACK_RENEW;
756 }
757
758 static void
759 bounce_eval(Smart_Data *sd)
760 {
761    Evas_Coord mx, my, px, py, bx, by, b2x, b2y, minx = 0, miny = 0;
762
763    if (sd->freeze) return;
764    if ((!sd->bouncemex) && (!sd->bouncemey)) return;
765    if (sd->down.now) return; // down bounce while still held down
766    if (sd->down.onhold_animator)
767      {
768         ecore_animator_del(sd->down.onhold_animator);
769         sd->down.onhold_animator = NULL;
770      }
771    if (sd->down.hold_animator)
772      {
773         ecore_animator_del(sd->down.hold_animator);
774         sd->down.hold_animator = NULL;
775      }
776    sd->pan_func.max_get(sd->pan_obj, &mx, &my);
777    sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
778    sd->pan_func.get(sd->pan_obj, &px, &py);
779    bx = px;
780    by = py;
781    if (px < minx) px = minx;
782    if ((px - minx) > mx) px = mx + minx;
783    if (py < miny) py = miny;
784    if ((py - miny) > my) py = my + miny;
785    b2x = px;
786    b2y = py;
787    if ((!sd->widget) || 
788        (!elm_widget_drag_child_locked_x_get(sd->widget)))
789      {
790         if (!sd->down.bounce_x_animator && !sd->bounce_animator_disabled)
791           {
792              if (sd->bouncemex)
793                {
794                   if (sd->scrollto.x.animator)
795                     {
796                        ecore_animator_del(sd->scrollto.x.animator);
797                        sd->scrollto.x.animator = NULL;
798                     }
799                   sd->down.bounce_x_animator = ecore_animator_add(_smart_bounce_x_animator, sd);
800                   sd->down.anim_start2 = ecore_loop_time_get();
801                   sd->down.bx = bx;
802                   sd->down.bx0 = bx;
803                   sd->down.b2x = b2x;
804                   if (sd->down.momentum_animator) sd->down.b0x = sd->down.ax;
805                   else sd->down.b0x = 0;
806                }
807           }
808      }
809    if ((!sd->widget) || 
810        (!elm_widget_drag_child_locked_y_get(sd->widget)))
811      {
812         if (!sd->down.bounce_y_animator && !sd->bounce_animator_disabled)
813           {
814              if (sd->bouncemey)
815                {
816                   if (sd->scrollto.y.animator)
817                     {
818                        ecore_animator_del(sd->scrollto.y.animator);
819                        sd->scrollto.y.animator = NULL;
820                     }
821                   sd->down.bounce_y_animator = ecore_animator_add(_smart_bounce_y_animator, sd);
822                   sd->down.anim_start3 = ecore_loop_time_get();
823                   sd->down.by = by;
824                   sd->down.by0 = by;
825                   sd->down.b2y = b2y;
826                   if (sd->down.momentum_animator) sd->down.b0y = sd->down.ay;
827                   else sd->down.b0y = 0;
828                }
829           }
830      }
831 }
832
833 void
834 elm_smart_scroller_child_pos_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
835 {
836    Evas_Coord mx = 0, my = 0, px, py, minx = 0, miny = 0;
837    double vx, vy;
838
839    API_ENTRY return;
840    // FIXME: allow for bounce outside of range
841    sd->pan_func.max_get(sd->pan_obj, &mx, &my);
842    sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
843    if (mx > 0) vx = (double)(x - minx) / (double)mx;
844    else vx = 0.0;
845    if (vx < 0.0) vx = 0.0;
846    else if (vx > 1.0) vx = 1.0;
847    if (my > 0) vy = (double)(y - miny) / (double)my;
848    else vy = 0.0;
849    if (vy < 0.0) vy = 0.0;
850    else if (vy > 1.0) vy = 1.0;
851    edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.vbar", 0.0, vy);
852    edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.hbar", vx, 0.0);
853    sd->pan_func.get(sd->pan_obj, &px, &py);
854    if (!_elm_config->thumbscroll_bounce_enable)
855      {
856         if (x < minx) x = minx;
857         if ((x - minx) > mx) x = mx + minx;
858         if (y < miny) y = miny;
859         if ((y - miny) > my) y = my + miny;
860      }
861
862    if (!sd->bounce_horiz)
863      {
864         if (x < minx) x = minx;
865         if ((x - minx) > mx) x = mx + minx;
866      }
867    if (!sd->bounce_vert)
868      {
869         if (y < miny) y = miny;
870         if (y - miny > my) y = my + miny;
871      }
872
873    sd->pan_func.set(sd->pan_obj, x, y);
874    if ((px != x) || (py != y))
875      edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
876    if (!sd->down.bounce_x_animator)
877      {
878         if ((x < minx) || (x > (mx + minx)))
879           {
880              sd->bouncemex = 1;
881              bounce_eval(sd);
882           }
883      }
884    if (!sd->down.bounce_y_animator)
885      {
886         if ((y < miny) || (y > my + miny))
887           {
888              sd->bouncemey = 1;
889              bounce_eval(sd);
890           }
891      }
892    if ((x != px) || (y != py))
893      {
894         evas_object_smart_callback_call(obj, "scroll", NULL);
895      }
896    if ((x != px)/* && (!sd->bouncemex)*/)
897      {
898         if (x == minx)
899           evas_object_smart_callback_call(obj, "edge,left", NULL);
900         if (x == (mx + minx))
901           evas_object_smart_callback_call(obj, "edge,right", NULL);
902      }
903    if ((y != py)/* && (!sd->bouncemey)*/)
904      {
905         if (y == miny)
906           evas_object_smart_callback_call(obj, "edge,top", NULL);
907         if (y == my + miny)
908           evas_object_smart_callback_call(obj, "edge,bottom", NULL);
909      }
910 }
911
912 void
913 elm_smart_scroller_child_pos_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
914 {
915    API_ENTRY return;
916    sd->pan_func.get(sd->pan_obj, x, y);
917 }
918
919 void
920 elm_smart_scroller_child_region_show(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
921 {
922    Evas_Coord mx = 0, my = 0, cw = 0, ch = 0, px = 0, py = 0, nx, ny, minx = 0, miny = 0;
923
924    API_ENTRY return;
925    sd->pan_func.max_get(sd->pan_obj, &mx, &my);
926    sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
927    sd->pan_func.child_size_get(sd->pan_obj, &cw, &ch);
928    sd->pan_func.get(sd->pan_obj, &px, &py);
929
930    nx = px;
931    if (x < px) nx = x;
932    else if ((x + w) > (px + (cw - mx)))
933      {
934         nx = x + w - (cw - mx);
935         if (nx > x) nx = x;
936      }
937    ny = py;
938    if (y < py) ny = y;
939    else if ((y + h) > (py + (ch - my)))
940      {
941         ny = y + h - (ch - my);
942         if (ny > y) ny = y;
943      }
944    if ((nx == px) && (ny == py)) return;
945    if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
946        (sd->scrollto.x.animator) || (sd->scrollto.y.animator))
947      {
948         _smart_anim_stop(sd->smart_obj);
949      }
950    if (sd->scrollto.x.animator)
951      {
952         ecore_animator_del(sd->scrollto.x.animator);
953         sd->scrollto.x.animator = NULL;
954      }
955    if (sd->scrollto.y.animator)
956      {
957         ecore_animator_del(sd->scrollto.y.animator);
958         sd->scrollto.y.animator = NULL;
959      }
960    if (sd->down.bounce_x_animator)
961      {
962         ecore_animator_del(sd->down.bounce_x_animator);
963         sd->down.bounce_x_animator = NULL;
964         sd->bouncemex = 0;
965      }
966    if (sd->down.bounce_y_animator)
967      {
968         ecore_animator_del(sd->down.bounce_y_animator);
969         sd->down.bounce_y_animator = NULL;
970         sd->bouncemey = 0;
971      }
972    if (sd->down.hold_animator)
973      {
974         ecore_animator_del(sd->down.hold_animator);
975         sd->down.hold_animator = NULL;
976         _smart_drag_stop(sd->smart_obj);
977      }
978    if (sd->down.momentum_animator)
979      {
980         ecore_animator_del(sd->down.momentum_animator);
981         sd->down.momentum_animator = NULL;
982         sd->down.bounce_x_hold = 0;
983         sd->down.bounce_y_hold = 0;
984         sd->down.ax = 0;
985         sd->down.ay = 0;
986         sd->down.pdx = 0;
987         sd->down.pdy = 0;
988      }
989    elm_smart_scroller_child_pos_set(obj, nx, ny);
990 }
991
992 void
993 elm_smart_scroller_child_viewport_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
994 {
995    API_ENTRY return;
996    edje_object_calc_force(sd->edje_obj);
997    evas_object_geometry_get(sd->pan_obj, NULL, NULL, w, h);
998 }
999
1000 void
1001 elm_smart_scroller_step_size_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
1002 {
1003    API_ENTRY return;
1004    if (x < 1) x = 1;
1005    if (y < 1) y = 1;
1006    sd->step.x = x;
1007    sd->step.y = y;
1008    _smart_scrollbar_size_adjust(sd);
1009 }
1010
1011 void
1012 elm_smart_scroller_step_size_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
1013 {
1014    API_ENTRY return;
1015    if (x) *x = sd->step.x;
1016    if (y) *y = sd->step.y;
1017 }
1018
1019 void
1020 elm_smart_scroller_page_size_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
1021 {
1022    API_ENTRY return;
1023    sd->page.x = x;
1024    sd->page.y = y;
1025    _smart_scrollbar_size_adjust(sd);
1026 }
1027
1028 void
1029 elm_smart_scroller_page_size_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
1030 {
1031    API_ENTRY return;
1032    if (x) *x = sd->page.x;
1033    if (y) *y = sd->page.y;
1034 }
1035
1036 void
1037 elm_smart_scroller_policy_set(Evas_Object *obj, Elm_Smart_Scroller_Policy hbar, Elm_Smart_Scroller_Policy vbar)
1038 {
1039    API_ENTRY return;
1040    if ((sd->hbar_flags == hbar) && (sd->vbar_flags == vbar)) return;
1041    sd->hbar_flags = hbar;
1042    sd->vbar_flags = vbar;
1043    if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
1044      edje_object_signal_emit(sd->edje_obj, "elm,action,show_always,hbar", "elm");
1045    else if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
1046      edje_object_signal_emit(sd->edje_obj, "elm,action,hide,hbar", "elm");
1047    else
1048      edje_object_signal_emit(sd->edje_obj, "elm,action,show_notalways,hbar", "elm");
1049    if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
1050      edje_object_signal_emit(sd->edje_obj, "elm,action,show_always,vbar", "elm");
1051    else if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
1052      edje_object_signal_emit(sd->edje_obj, "elm,action,hide,vbar", "elm");
1053    else
1054      edje_object_signal_emit(sd->edje_obj, "elm,action,show_notalways,vbar", "elm");
1055    _smart_scrollbar_size_adjust(sd);
1056 }
1057
1058 void
1059 elm_smart_scroller_policy_get(Evas_Object *obj, Elm_Smart_Scroller_Policy *hbar, Elm_Smart_Scroller_Policy *vbar)
1060 {
1061    API_ENTRY return;
1062    if (hbar) *hbar = sd->hbar_flags;
1063    if (vbar) *vbar = sd->vbar_flags;
1064 }
1065
1066 Evas_Object *
1067 elm_smart_scroller_edje_object_get(Evas_Object *obj)
1068 {
1069    API_ENTRY return NULL;
1070    return sd->edje_obj;
1071 }
1072
1073 void
1074 elm_smart_scroller_single_dir_set(Evas_Object *obj, Eina_Bool single_dir)
1075 {
1076    API_ENTRY return;
1077    sd->one_dir_at_a_time = single_dir;
1078 }
1079
1080 Eina_Bool
1081 elm_smart_scroller_single_dir_get(Evas_Object *obj)
1082 {
1083    API_ENTRY return EINA_FALSE;
1084    return sd->one_dir_at_a_time;
1085 }
1086
1087 void
1088 elm_smart_scroller_object_theme_set(Evas_Object *parent, Evas_Object *obj, const char *clas, const char *group, const char *style)
1089 {
1090    API_ENTRY return;
1091    Evas_Coord mw, mh;
1092    _elm_theme_object_set(parent, sd->edje_obj, clas, group, style);
1093    edje_object_scale_set(sd->edje_obj, elm_widget_scale_get(parent) * _elm_config->scale);
1094    if (sd->pan_obj)
1095      edje_object_part_swallow(sd->edje_obj, "elm.swallow.content", sd->pan_obj);
1096    mw = mh = -1;
1097    elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1098    if (edje_object_part_exists(sd->edje_obj, "elm.scrollbar.base"))
1099      {
1100         Evas_Object *base;
1101         base = edje_object_part_swallow_get(sd->edje_obj, "elm.scrollbar.base");
1102         if (!base)
1103           {
1104              base = evas_object_rectangle_add(evas_object_evas_get(sd->edje_obj));
1105              evas_object_color_set(base, 0, 0, 0, 0);
1106              edje_object_part_swallow(sd->edje_obj, "elm.scrollbar.base", base);
1107           }
1108         if (!_elm_config->thumbscroll_enable)
1109            evas_object_size_hint_min_set(base, mw, mh);
1110      }
1111    sd->vbar_visible = !sd->vbar_visible;
1112    sd->hbar_visible = !sd->hbar_visible;
1113    _smart_scrollbar_bar_visibility_adjust(sd);
1114 }
1115
1116 void
1117 elm_smart_scroller_hold_set(Evas_Object *obj, Eina_Bool hold)
1118 {
1119    API_ENTRY return;
1120    sd->hold = hold;
1121 }
1122
1123 void
1124 elm_smart_scroller_freeze_set(Evas_Object *obj, Eina_Bool freeze)
1125 {
1126    API_ENTRY return;
1127    sd->freeze = freeze;
1128    if (sd->freeze)
1129      {
1130         if (sd->down.onhold_animator)
1131           {
1132              ecore_animator_del(sd->down.onhold_animator);
1133              sd->down.onhold_animator = NULL;
1134           }
1135      }
1136 }
1137
1138 void
1139 elm_smart_scroller_bounce_allow_set(Evas_Object *obj, Eina_Bool horiz, Eina_Bool vert)
1140 {
1141    API_ENTRY return;
1142    sd->bounce_horiz = horiz;
1143    sd->bounce_vert = vert;
1144 }
1145
1146 void
1147 elm_smart_scroller_bounce_allow_get(const Evas_Object *obj, Eina_Bool *horiz, Eina_Bool *vert)
1148 {
1149    API_ENTRY return;
1150    *horiz = sd->bounce_horiz;
1151    *vert = sd->bounce_vert;
1152 }
1153
1154 void
1155 elm_smart_scroller_paging_set(Evas_Object *obj, double pagerel_h, double pagerel_v, Evas_Coord pagesize_h, Evas_Coord pagesize_v)
1156 {
1157    API_ENTRY return;
1158    sd->pagerel_h = pagerel_h;
1159    sd->pagerel_v = pagerel_v;
1160    sd->pagesize_h = pagesize_h;
1161    sd->pagesize_v = pagesize_v;
1162    _smart_page_adjust(sd);
1163 }
1164
1165 void
1166 elm_smart_scroller_paging_get(Evas_Object *obj, double *pagerel_h, double *pagerel_v, Evas_Coord *pagesize_h, Evas_Coord *pagesize_v)
1167 {
1168    API_ENTRY return;
1169    if(pagerel_h) *pagerel_h = sd->pagerel_h;
1170    if(pagerel_v) *pagerel_v = sd->pagerel_v;
1171    if(pagesize_h) *pagesize_h = sd->pagesize_h;
1172    if(pagesize_v) *pagesize_v = sd->pagesize_v;
1173 }
1174
1175 void
1176 elm_smart_scroller_region_bring_in(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
1177 {
1178    Evas_Coord mx = 0, my = 0, cw = 0, ch = 0, px = 0, py = 0, nx, ny, minx = 0, miny = 0;
1179
1180    API_ENTRY return;
1181    sd->pan_func.max_get(sd->pan_obj, &mx, &my);
1182    sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
1183    sd->pan_func.child_size_get(sd->pan_obj, &cw, &ch);
1184    sd->pan_func.get(sd->pan_obj, &px, &py);
1185
1186    nx = px;
1187    if (x < px) nx = x;
1188    else if ((x + w) > (px + (cw - mx)))
1189      {
1190         nx = x + w - (cw - mx);
1191         if (nx > x) nx = x;
1192      }
1193    ny = py;
1194    if (y < py) ny = y;
1195    else if ((y + h) > (py + (ch - my)))
1196      {
1197         ny = y + h - (ch - my);
1198         if (ny > y) ny = y;
1199      }
1200    if ((nx == px) && (ny == py)) return;
1201    if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1202        (sd->scrollto.x.animator) || (sd->scrollto.y.animator))
1203      {
1204         _smart_anim_stop(sd->smart_obj);
1205      }
1206    if (sd->scrollto.x.animator)
1207      {
1208         ecore_animator_del(sd->scrollto.x.animator);
1209         sd->scrollto.x.animator = NULL;
1210      }
1211    if (sd->scrollto.y.animator)
1212      {
1213         ecore_animator_del(sd->scrollto.y.animator);
1214         sd->scrollto.y.animator = NULL;
1215      }
1216    if (sd->down.bounce_x_animator)
1217      {
1218         ecore_animator_del(sd->down.bounce_x_animator);
1219         sd->down.bounce_x_animator = NULL;
1220         sd->bouncemex = 0;
1221      }
1222    if (sd->down.bounce_y_animator)
1223      {
1224         ecore_animator_del(sd->down.bounce_y_animator);
1225         sd->down.bounce_y_animator = NULL;
1226         sd->bouncemey = 0;
1227      }
1228    if (sd->down.hold_animator)
1229      {
1230         ecore_animator_del(sd->down.hold_animator);
1231         sd->down.hold_animator = NULL;
1232         _smart_drag_stop(sd->smart_obj);
1233      }
1234    if (sd->down.momentum_animator)
1235      {
1236         ecore_animator_del(sd->down.momentum_animator);
1237         sd->down.momentum_animator = NULL;
1238         sd->down.bounce_x_hold = 0;
1239         sd->down.bounce_y_hold = 0;
1240         sd->down.ax = 0;
1241         sd->down.ay = 0;
1242         sd->down.pdx = 0;
1243         sd->down.pdy = 0;
1244      }
1245    x = nx;
1246    if (x < minx) x = minx;
1247    else if ((x + w) > cw) x = cw - w;
1248    _smart_scrollto_x(sd, _elm_config->bring_in_scroll_friction, x);
1249    y = ny;
1250    if (y < miny) y = miny;
1251    else if ((y + h) > ch) y = ch - h;
1252    _smart_scrollto_y(sd, _elm_config->bring_in_scroll_friction, y);
1253 }
1254
1255 void
1256 elm_smart_scroller_widget_set(Evas_Object *obj, Evas_Object *wid)
1257 {
1258    API_ENTRY return;
1259    sd->widget = wid;
1260 }
1261
1262 /* local subsystem functions */
1263 static void
1264 _smart_edje_drag_v_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1265 {
1266    Smart_Data *sd;
1267
1268    sd = data;
1269    _smart_scrollbar_read(sd);
1270    _smart_drag_start(sd->smart_obj);
1271 }
1272
1273 static void
1274 _smart_edje_drag_v_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1275 {
1276    Smart_Data *sd;
1277
1278    sd = data;
1279    _smart_scrollbar_read(sd);
1280    _smart_drag_stop(sd->smart_obj);
1281 }
1282
1283 static void
1284 _smart_edje_drag_v(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1285 {
1286    Smart_Data *sd;
1287
1288    sd = data;
1289    _smart_scrollbar_read(sd);
1290 }
1291
1292 static void
1293 _smart_edje_drag_h_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1294 {
1295    Smart_Data *sd;
1296
1297    sd = data;
1298    _smart_scrollbar_read(sd);
1299    _smart_drag_start(sd->smart_obj);
1300 }
1301
1302 static void
1303 _smart_edje_drag_h_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1304 {
1305    Smart_Data *sd;
1306
1307    sd = data;
1308    _smart_scrollbar_read(sd);
1309    _smart_drag_stop(sd->smart_obj);
1310 }
1311
1312 static void
1313 _smart_edje_drag_h(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1314 {
1315    Smart_Data *sd;
1316
1317    sd = data;
1318    _smart_scrollbar_read(sd);
1319 }
1320
1321 static void
1322 _smart_child_del_hook(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1323 {
1324    Smart_Data *sd;
1325
1326    sd = data;
1327    sd->child_obj = NULL;
1328    _smart_scrollbar_size_adjust(sd);
1329    _smart_scrollbar_reset(sd);
1330 }
1331
1332 static void
1333 _smart_pan_changed_hook(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1334 {
1335    Evas_Coord x, y;
1336    Evas_Coord w, h;
1337    Smart_Data *sd;
1338
1339    sd = data;
1340    sd->pan_func.get(sd->pan_obj, &x, &y);
1341    sd->pan_func.child_size_get(sd->pan_obj, &w, &h);
1342    if ((w != sd->child.w) || (h != sd->child.h))
1343      {
1344         sd->child.w = w;
1345         sd->child.h = h;
1346         _smart_scrollbar_size_adjust(sd);
1347         evas_object_size_hint_min_set(sd->smart_obj, sd->child.w, sd->child.h);
1348         elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
1349      }
1350 }
1351
1352 static void
1353 _smart_pan_pan_changed_hook(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1354 {
1355    Evas_Coord x, y;
1356    Smart_Data *sd;
1357
1358    sd = data;
1359    sd->pan_func.get(sd->pan_obj, &x, &y);
1360    if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1361        (sd->scrollto.x.animator) || (sd->scrollto.y.animator))
1362      {
1363         _smart_anim_stop(sd->smart_obj);
1364      }
1365    if (sd->scrollto.x.animator)
1366      {
1367         ecore_animator_del(sd->scrollto.x.animator);
1368         sd->scrollto.x.animator = NULL;
1369      }
1370    if (sd->scrollto.y.animator)
1371      {
1372         ecore_animator_del(sd->scrollto.y.animator);
1373         sd->scrollto.y.animator = NULL;
1374      }
1375    if (sd->down.bounce_x_animator)
1376      {
1377         ecore_animator_del(sd->down.bounce_x_animator);
1378         sd->down.bounce_x_animator = NULL;
1379         sd->bouncemex = 0;
1380      }
1381    if (sd->down.bounce_y_animator)
1382      {
1383         ecore_animator_del(sd->down.bounce_y_animator);
1384         sd->down.bounce_y_animator = NULL;
1385         sd->bouncemey = 0;
1386      }
1387    elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
1388 }
1389
1390 static void
1391 _smart_event_wheel(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1392 {
1393    Evas_Event_Mouse_Wheel *ev;
1394    Smart_Data *sd;
1395    Evas_Coord x = 0, y = 0;
1396
1397    sd = data;
1398    ev = event_info;
1399    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
1400    if ((evas_key_modifier_is_set(ev->modifiers, "Control")) ||
1401        (evas_key_modifier_is_set(ev->modifiers, "Alt")) ||
1402        (evas_key_modifier_is_set(ev->modifiers, "Shift")) ||
1403        (evas_key_modifier_is_set(ev->modifiers, "Meta")) ||
1404        (evas_key_modifier_is_set(ev->modifiers, "Hyper")) ||
1405        (evas_key_modifier_is_set(ev->modifiers, "Super")))
1406      return;
1407    elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1408    if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1409        (sd->scrollto.x.animator) || (sd->scrollto.y.animator))
1410      {
1411         _smart_anim_stop(sd->smart_obj);
1412      }
1413    if (sd->scrollto.x.animator)
1414      {
1415         ecore_animator_del(sd->scrollto.x.animator);
1416         sd->scrollto.x.animator = NULL;
1417      }
1418    if (sd->scrollto.y.animator)
1419      {
1420         ecore_animator_del(sd->scrollto.y.animator);
1421         sd->scrollto.y.animator = NULL;
1422      }
1423    if (sd->down.bounce_x_animator)
1424      {
1425         ecore_animator_del(sd->down.bounce_x_animator);
1426         sd->down.bounce_x_animator = NULL;
1427         sd->bouncemex = 0;
1428      }
1429    if (sd->down.bounce_y_animator)
1430      {
1431         ecore_animator_del(sd->down.bounce_y_animator);
1432         sd->down.bounce_y_animator = NULL;
1433         sd->bouncemey = 0;
1434      }
1435    if (!ev->direction)
1436      y += ev->z * sd->step.y;
1437    else if (ev->direction == 1)
1438      x += ev->z * sd->step.x;
1439
1440    if ((!sd->hold) && (!sd->freeze))
1441      elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
1442 }
1443
1444 static void
1445 _smart_event_mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1446 {
1447    Evas_Event_Mouse_Down *ev;
1448    Smart_Data *sd;
1449    Evas_Coord x = 0, y = 0;
1450
1451    sd = data;
1452    ev = event_info;
1453 //   if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
1454    if (_elm_config->thumbscroll_enable)
1455      {
1456         sd->down.hold = 0;
1457         if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1458             (sd->down.momentum_animator) || (sd->scrollto.x.animator) ||
1459             (sd->scrollto.y.animator))
1460           {
1461              ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL | EVAS_EVENT_FLAG_ON_HOLD;
1462              sd->down.scroll = 1;
1463              sd->down.hold = 1;
1464              _smart_anim_stop(sd->smart_obj);
1465           }
1466         if (sd->scrollto.x.animator)
1467           {
1468              ecore_animator_del(sd->scrollto.x.animator);
1469              sd->scrollto.x.animator = NULL;
1470           }
1471         if (sd->scrollto.y.animator)
1472           {
1473              ecore_animator_del(sd->scrollto.y.animator);
1474              sd->scrollto.y.animator = NULL;
1475           }
1476         if (sd->down.bounce_x_animator)
1477           {
1478              ecore_animator_del(sd->down.bounce_x_animator);
1479              sd->down.bounce_x_animator = NULL;
1480              sd->bouncemex = 0;
1481           }
1482         if (sd->down.bounce_y_animator)
1483           {
1484              ecore_animator_del(sd->down.bounce_y_animator);
1485              sd->down.bounce_y_animator = NULL;
1486              sd->bouncemey = 0;
1487           }
1488         if (sd->down.hold_animator)
1489           {
1490              ecore_animator_del(sd->down.hold_animator);
1491              sd->down.hold_animator = NULL;
1492              _smart_drag_stop(sd->smart_obj);
1493           }
1494         if (sd->down.momentum_animator)
1495           {
1496              ecore_animator_del(sd->down.momentum_animator);
1497              sd->down.momentum_animator = NULL;
1498              sd->down.bounce_x_hold = 0;
1499              sd->down.bounce_y_hold = 0;
1500              sd->down.ax = 0;
1501              sd->down.ay = 0;
1502           }
1503         if (ev->button == 1)
1504           {
1505              sd->down.now = 1;
1506              sd->down.dragged = 0;
1507              sd->down.dir_x = 0;
1508              sd->down.dir_y = 0;
1509              sd->down.x = ev->canvas.x;
1510              sd->down.y = ev->canvas.y;
1511              elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1512              sd->down.sx = x;
1513              sd->down.sy = y;
1514              sd->down.locked = 0;
1515              memset(&(sd->down.history[0]), 0, sizeof(sd->down.history[0]) * 20);
1516 #ifdef EVTIME
1517              sd->down.history[0].timestamp = ev->timestamp / 1000.0;
1518 #else
1519              sd->down.history[0].timestamp = ecore_loop_time_get();
1520 #endif
1521              sd->down.history[0].x = ev->canvas.x;
1522              sd->down.history[0].y = ev->canvas.y;
1523           }
1524         sd->down.dragged_began = 0;
1525         sd->down.hold_parent = 0;
1526         sd->down.cancelled = 0;
1527      }
1528 }
1529
1530 static Eina_Bool
1531 _smart_hold_animator(void *data)
1532 {
1533    Smart_Data *sd = data;
1534    Evas_Coord ox, oy;
1535    
1536    elm_smart_scroller_child_pos_get(sd->smart_obj, &ox, &oy);
1537    if (sd->down.dir_x)
1538      {
1539         if ((!sd->widget) || 
1540             (!elm_widget_drag_child_locked_x_get(sd->widget)))
1541           {
1542              ox = sd->down.hold_x;
1543           }
1544      }
1545    if (sd->down.dir_y)
1546      {
1547         if ((!sd->widget) || 
1548             (!elm_widget_drag_child_locked_y_get(sd->widget)))
1549           {
1550              oy = sd->down.hold_y;
1551           }
1552      }
1553    elm_smart_scroller_child_pos_set(sd->smart_obj, ox, oy);
1554    return ECORE_CALLBACK_RENEW;
1555 }
1556
1557 static Eina_Bool
1558 _smart_event_post_up(void *data, Evas *e __UNUSED__)
1559 {
1560    Smart_Data *sd = data;
1561    if (sd->widget)
1562      {
1563         if (sd->down.dragged)
1564           {
1565              elm_widget_drag_lock_x_set(sd->widget, 0);
1566              elm_widget_drag_lock_y_set(sd->widget, 0);
1567           }
1568      }
1569    return EINA_TRUE;
1570 }
1571
1572 static void
1573 _smart_event_mouse_up(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *event_info)
1574 {
1575    Evas_Event_Mouse_Down *ev;
1576    Smart_Data *sd;
1577    Evas_Coord x = 0, y = 0, ox = 0, oy = 0;
1578
1579    sd = data;
1580    ev = event_info;
1581    sd->down.hold_parent = 0;
1582 //   if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
1583    evas_post_event_callback_push(e, _smart_event_post_up, sd);
1584    // FIXME: respect elm_widget_scroll_hold_get of parent container
1585    if (_elm_config->thumbscroll_enable)
1586      {
1587         if (ev->button == 1)
1588           {
1589              if (sd->down.onhold_animator)
1590                {
1591                   ecore_animator_del(sd->down.onhold_animator);
1592                   sd->down.onhold_animator = NULL;
1593                }
1594              x = ev->canvas.x - sd->down.x;
1595              y = ev->canvas.y - sd->down.y;
1596              if (sd->down.dragged)
1597                {
1598                   _smart_drag_stop(sd->smart_obj);
1599                   if ((!sd->hold) && (!sd->freeze))
1600                     {
1601                        double t, at, dt;
1602                        int i;
1603                        Evas_Coord ax, ay, dx, dy, vel;
1604
1605 #ifdef EVTIME
1606                        t = ev->timestamp / 1000.0;
1607 #else
1608                        t = ecore_loop_time_get();
1609 #endif
1610                        ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1611                        ax = ev->canvas.x;
1612                        ay = ev->canvas.y;
1613                        at = 0.0;
1614 #ifdef SCROLLDBG
1615                        printf("------ %i %i\n", ev->canvas.x, ev->canvas.y);
1616 #endif
1617                        for (i = 0; i < 20; i++)
1618                          {
1619                             dt = t - sd->down.history[i].timestamp;
1620                             if (dt > 0.2) break;
1621 #ifdef SCROLLDBG
1622                             printf("H: %i %i @ %1.3f\n",
1623                                    sd->down.history[i].x,
1624                                    sd->down.history[i].y, dt);
1625 #endif
1626                             at += dt;
1627                             ax += sd->down.history[i].x;
1628                             ay += sd->down.history[i].y;
1629                          }
1630                        ax /= (i + 1);
1631                        ay /= (i + 1);
1632                        at /= (i + 1);
1633                        at *= 4.0;
1634                        dx = ev->canvas.x - ax;
1635                        dy = ev->canvas.y - ay;
1636                        if (at > 0)
1637                          {
1638                             vel = sqrt((dx * dx) + (dy * dy)) / at;
1639                             if ((_elm_config->thumbscroll_friction > 0.0) &&
1640                                 (vel > _elm_config->thumbscroll_momentum_threshold) &&
1641                                 (!sd->freeze))
1642                               {
1643                                  sd->down.dx = ((double)dx / at);
1644                                  sd->down.dy = ((double)dy / at);
1645                                  if (((sd->down.dx > 0) && (sd->down.pdx > 0)) ||
1646                                      ((sd->down.dx < 0) && (sd->down.pdx < 0)))
1647                                    sd->down.dx += (double)sd->down.pdx * 1.5; // FIXME: * 1.5 - probably should be config
1648                                  if (((sd->down.dy > 0) && (sd->down.pdy > 0)) ||
1649                                      ((sd->down.dy < 0) && (sd->down.pdy < 0)))
1650                                    sd->down.dy += (double)sd->down.pdy * 1.5; // FIXME: * 1.5 - probably should be config
1651                                  if (((sd->down.dx > 0) && (sd->down.pdx > 0)) ||
1652                                      ((sd->down.dx < 0) && (sd->down.pdx < 0)) ||
1653                                      ((sd->down.dy > 0) && (sd->down.pdy > 0)) ||
1654                                      ((sd->down.dy < 0) && (sd->down.pdy < 0)))
1655                                   {
1656                                     double t = ecore_loop_time_get();
1657                                     double dt = t - sd->down.anim_start;
1658                                     
1659                                     if (dt < 0.0) dt = 0.0;
1660                                     else if (dt > _elm_config->thumbscroll_friction)
1661                                       dt = _elm_config->thumbscroll_friction;
1662                                     sd->down.extra_time = _elm_config->thumbscroll_friction - dt;
1663                                   }
1664                                  else
1665                                   sd->down.extra_time = 0.0;
1666                                  sd->down.pdx = sd->down.dx;
1667                                  sd->down.pdy = sd->down.dy;
1668                                  ox = -sd->down.dx;
1669                                  oy = -sd->down.dy;
1670                                  if (!_smart_do_page(sd))
1671                                    {
1672                                       if (!sd->down.momentum_animator && !sd->momentum_animator_disabled)
1673                                         {
1674                                            sd->down.momentum_animator = ecore_animator_add(_smart_momentum_animator, sd);
1675                                            ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL;
1676                                            _smart_anim_start(sd->smart_obj);
1677                                         }
1678                                       sd->down.anim_start = ecore_loop_time_get();
1679                                       elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1680                                       sd->down.sx = x;
1681                                       sd->down.sy = y;
1682                                       sd->down.b0x = 0;
1683                                       sd->down.b0y = 0;
1684                                    }
1685                               }
1686                          }
1687                        if (sd->down.hold_animator)
1688                          {
1689                             ecore_animator_del(sd->down.hold_animator);
1690                             sd->down.hold_animator = NULL;
1691                          }
1692                     }
1693                   else
1694                     {
1695                        sd->down.pdx = 0;
1696                        sd->down.pdy = 0;
1697                     }
1698                   evas_event_feed_hold(e, 0, ev->timestamp, ev->data);
1699                   if (_smart_do_page(sd))
1700                     {
1701                        Evas_Coord pgx, pgy;
1702
1703                        elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1704                        if ((!sd->widget) || 
1705                            (!elm_widget_drag_child_locked_x_get(sd->widget)))
1706                          {
1707                             pgx = _smart_page_x_get(sd, ox);
1708                             if (pgx != x) 
1709                               {
1710                                  ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL;
1711                                  _smart_scrollto_x(sd, _elm_config->page_scroll_friction, pgx);
1712                               }
1713                          }
1714                        if ((!sd->widget) || 
1715                            (!elm_widget_drag_child_locked_y_get(sd->widget)))
1716                          {
1717                             pgy = _smart_page_y_get(sd, oy);
1718                             if (pgy != y) 
1719                               {
1720                                  ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL;
1721                                  _smart_scrollto_y(sd, _elm_config->page_scroll_friction, pgy);
1722                               }
1723                          }
1724                     }
1725                }
1726              else
1727                {
1728                   sd->down.pdx = 0;
1729                   sd->down.pdy = 0;
1730                   if (_smart_do_page(sd))
1731                     {
1732                        Evas_Coord pgx, pgy;
1733
1734                        elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1735                        if ((!sd->widget) || 
1736                            (!elm_widget_drag_child_locked_x_get(sd->widget)))
1737                          {
1738                             pgx = _smart_page_x_get(sd, ox);
1739                             if (pgx != x) _smart_scrollto_x(sd, _elm_config->page_scroll_friction, pgx);
1740                          }
1741                        if ((!sd->widget) || 
1742                            (!elm_widget_drag_child_locked_y_get(sd->widget)))
1743                          {
1744                             pgy = _smart_page_y_get(sd, oy);
1745                             if (pgy != y) _smart_scrollto_y(sd, _elm_config->page_scroll_friction, pgy);
1746                          }
1747                     }
1748                   if (sd->down.hold_animator)
1749                     {
1750                        ecore_animator_del(sd->down.hold_animator);
1751                        sd->down.hold_animator = NULL;
1752                     }
1753                }
1754              if (sd->down.scroll)
1755                {
1756                   ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL;
1757                   sd->down.scroll = 0;
1758                }
1759              if (sd->down.hold)
1760                {
1761                   ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1762                   sd->down.hold = 0;
1763                }
1764              sd->down.dragged_began = 0;
1765              sd->down.dir_x = 0;
1766              sd->down.dir_y = 0;
1767              sd->down.want_dragged = 0;
1768              sd->down.dragged = 0;
1769              sd->down.now = 0;
1770              elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1771              elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
1772              if (!_smart_do_page(sd))
1773                bounce_eval(sd);
1774           }
1775      }
1776 }
1777
1778 static Eina_Bool
1779 _smart_onhold_animator(void *data)
1780 {
1781    Smart_Data *sd;
1782    double t, td;
1783    double vx, vy;
1784    Evas_Coord x, y, ox, oy;
1785
1786    sd = data;
1787    t = ecore_loop_time_get();
1788    if (sd->down.onhold_tlast > 0.0)
1789      {
1790         td = t - sd->down.onhold_tlast;
1791         vx = sd->down.onhold_vx * td * (double)_elm_config->thumbscroll_threshold * 2.0;
1792         vy = sd->down.onhold_vy * td * (double)_elm_config->thumbscroll_threshold * 2.0;
1793         elm_smart_scroller_child_pos_get(sd->smart_obj, &ox, &oy);
1794         x = ox;
1795         y = oy;
1796         
1797         if (sd->down.dir_x)
1798           {
1799              if ((!sd->widget) || 
1800                  (!elm_widget_drag_child_locked_x_get(sd->widget)))
1801                {
1802                   sd->down.onhold_vxe += vx;
1803                   x = ox + (int)sd->down.onhold_vxe;
1804                   sd->down.onhold_vxe -= (int)sd->down.onhold_vxe;
1805                }
1806           }
1807         
1808         if (sd->down.dir_y)
1809           {
1810              if ((!sd->widget) || 
1811                  (!elm_widget_drag_child_locked_y_get(sd->widget)))
1812                {
1813                   sd->down.onhold_vye += vy;
1814                   y = oy + (int)sd->down.onhold_vye;
1815                   sd->down.onhold_vye -= (int)sd->down.onhold_vye;
1816                }
1817           }
1818         
1819         elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
1820 //        printf("scroll %i %i\n", sd->down.hold_x, sd->down.hold_y);
1821      }
1822    sd->down.onhold_tlast = t;
1823    return ECORE_CALLBACK_RENEW;
1824 }
1825
1826 static Eina_Bool
1827 _smart_event_post_move(void *data, Evas *e __UNUSED__)
1828 {
1829    Smart_Data *sd = data;
1830
1831    if (sd->down.want_dragged)
1832      {
1833         int start = 0;
1834
1835         if (sd->down.hold_parent)
1836           {
1837              if ((sd->down.dir_x) && !can_scroll(sd, sd->down.hdir))
1838                {
1839                   sd->down.dir_x = 0;
1840                }
1841              if ((sd->down.dir_y) && !can_scroll(sd, sd->down.vdir))
1842                {
1843                   sd->down.dir_y = 0;
1844                }
1845           }
1846         if (sd->down.dir_x)
1847           {
1848              if ((!sd->widget) || 
1849                  (!elm_widget_drag_child_locked_x_get(sd->widget)))
1850                {
1851                   sd->down.want_dragged = 0;
1852                   sd->down.dragged = 1;
1853                   if (sd->widget)
1854                     {
1855                        elm_widget_drag_lock_x_set(sd->widget, 1);
1856                     }
1857                   start = 1;
1858                }
1859              else
1860                sd->down.dir_x = 0;
1861           }
1862         if (sd->down.dir_y)
1863           {
1864              if ((!sd->widget) || 
1865                  (!elm_widget_drag_child_locked_y_get(sd->widget)))
1866                {
1867                   sd->down.want_dragged = 0;
1868                   sd->down.dragged = 1;
1869                   if (sd->widget)
1870                     {
1871                        elm_widget_drag_lock_y_set(sd->widget, 1);
1872                     }
1873                   start = 1;
1874                }
1875              else
1876                sd->down.dir_y = 0;
1877           }
1878         if ((!sd->down.dir_x) && (!sd->down.dir_y))
1879           {
1880              sd->down.cancelled = 1;
1881           }
1882         if (start) _smart_drag_start(sd->smart_obj);
1883      }
1884    return EINA_TRUE;
1885 }
1886
1887 static void
1888 _smart_event_mouse_move(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *event_info)
1889 {
1890    Evas_Event_Mouse_Move *ev;
1891    Smart_Data *sd;
1892    Evas_Coord x = 0, y = 0;
1893
1894    sd = data;
1895    ev = event_info;
1896 //   if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
1897    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) sd->down.hold_parent = 1;
1898    evas_post_event_callback_push(e, _smart_event_post_move, sd);
1899    // FIXME: respect elm_widget_scroll_hold_get of parent container
1900    if (_elm_config->thumbscroll_enable)
1901      {
1902         if (sd->down.now)
1903           {
1904              int dodir = 0;
1905
1906 #ifdef SCROLLDBG
1907              printf("::: %i %i\n", ev->cur.canvas.x, ev->cur.canvas.y);
1908 #endif
1909              memmove(&(sd->down.history[1]), &(sd->down.history[0]),
1910                      sizeof(sd->down.history[0]) * 19);
1911 #ifdef EVTIME
1912              sd->down.history[0].timestamp = ev->timestamp / 1000.0;
1913 #else
1914              sd->down.history[0].timestamp = ecore_loop_time_get();
1915 #endif
1916              sd->down.history[0].x = ev->cur.canvas.x;
1917              sd->down.history[0].y = ev->cur.canvas.y;
1918
1919              if (!sd->down.dragged_began)
1920                {
1921                   x = ev->cur.canvas.x - sd->down.x;
1922                   y = ev->cur.canvas.y - sd->down.y;
1923                   
1924                   sd->down.hdir = -1;
1925                   sd->down.vdir = -1;
1926                     
1927                   if      (x > 0) sd->down.hdir = LEFT;
1928                   else if (x < 0) sd->down.hdir = RIGHT;
1929                   if      (y > 0) sd->down.vdir = UP;
1930                   else if (y < 0) sd->down.vdir = DOWN;
1931                   
1932                   if (x < 0) x = -x;
1933                   if (y < 0) y = -y;
1934              
1935                   if ((sd->one_dir_at_a_time) &&
1936                       (!((sd->down.dir_x) || (sd->down.dir_y))))
1937                     {
1938                        if (x > _elm_config->thumbscroll_threshold)
1939                          {
1940                             if (x > (y * 2))
1941                               {
1942                                  sd->down.dir_x = 1;
1943                                  sd->down.dir_y = 0;
1944                                  dodir++;
1945                               }
1946                          }
1947                        if (y > _elm_config->thumbscroll_threshold)
1948                          {
1949                             if (y > (x * 2))
1950                               {
1951                                  sd->down.dir_x = 0;
1952                                  sd->down.dir_y = 1;
1953                                  dodir++;
1954                               }
1955                          }
1956                        if (!dodir)
1957                          {
1958                             sd->down.dir_x = 1;
1959                             sd->down.dir_y = 1;
1960                          }
1961                     }
1962                   else
1963                     {
1964 //                       can_scroll(sd, LEFT);
1965 //                       can_scroll(sd, RIGHT);
1966 //                       can_scroll(sd, UP);
1967 //                       can_scroll(sd, DOWN);
1968                        sd->down.dir_x = 1;
1969                        sd->down.dir_y = 1;
1970                     }
1971                }
1972              if ((!sd->hold) && (!sd->freeze))
1973                {
1974                   if ((sd->down.dragged) ||
1975                       (((x * x) + (y * y)) >
1976                        (_elm_config->thumbscroll_threshold *
1977                         _elm_config->thumbscroll_threshold)))
1978                     {
1979                        sd->down.dragged_began = 1;
1980                        if (!sd->down.dragged)
1981                          {
1982                             sd->down.want_dragged = 1;
1983                             ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1984 //                            evas_event_feed_hold(e, 1, ev->timestamp, ev->data);
1985 //                            _smart_drag_start(sd->smart_obj);
1986                          }
1987                        if (sd->down.dragged)
1988                          {
1989                             ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1990                          }
1991 //                       ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1992 //                       sd->down.dragged = 1;
1993                        if (sd->down.dir_x)
1994                          x = sd->down.sx - (ev->cur.canvas.x - sd->down.x);
1995                        else
1996                          x = sd->down.sx;
1997                        if (sd->down.dir_y)
1998                          y = sd->down.sy - (ev->cur.canvas.y - sd->down.y);
1999                        else
2000                          y = sd->down.sy;
2001                        if ((sd->down.dir_x) || (sd->down.dir_y))
2002                          {
2003                             if (!sd->down.locked)
2004                               {
2005                                  sd->down.locked_x = x;
2006                                  sd->down.locked_y = y;
2007                                  sd->down.locked = 1;
2008                               }
2009                             if (!((sd->down.dir_x) && (sd->down.dir_y)))
2010                               {
2011                                  if (sd->down.dir_x) y = sd->down.locked_y;
2012                                  else x = sd->down.locked_x;
2013                               }
2014                          }
2015                        if (_elm_config->thumbscroll_border_friction > 0.0)
2016                          {
2017                             Evas_Coord minx, miny;
2018                             sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2019                             if (y < miny)
2020                                y += (miny - y) *
2021                                   _elm_config->thumbscroll_border_friction;
2022                             else if (sd->child.h <= sd->h)
2023                                y += (sd->down.sy - y) *
2024                                   _elm_config->thumbscroll_border_friction;
2025                             else if ((sd->child.h - sd->h + miny) < y)
2026                                y += (sd->child.h - sd->h + miny - y) *
2027                                   _elm_config->thumbscroll_border_friction;
2028                             if (x < minx)
2029                                x += (minx - x) *
2030                                   _elm_config->thumbscroll_border_friction;
2031                             else if (sd->child.w <= sd->w)
2032                                x += (sd->down.sx - x) *
2033                                   _elm_config->thumbscroll_border_friction;
2034                             else if ((sd->child.w - sd->w + minx) < x)
2035                                x += (sd->child.w - sd->w + minx - x) *
2036                                   _elm_config->thumbscroll_border_friction;
2037                          }
2038
2039                        sd->down.hold_x = x;
2040                        sd->down.hold_y = y;
2041                        if (!sd->down.hold_animator)
2042                          sd->down.hold_animator = 
2043                          ecore_animator_add(_smart_hold_animator, sd);
2044 //                       printf("a %i %i\n", sd->down.hold_x, sd->down.hold_y);
2045 //                       _smart_onhold_animator(sd);
2046 //                       elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
2047                     }
2048                   else
2049                     {
2050                        if (sd->down.dragged_began)
2051                          {
2052                             ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2053                             if (!sd->down.hold)
2054                               {
2055                                  sd->down.hold = 1;
2056                                  evas_event_feed_hold(e, 1, ev->timestamp, ev->data);
2057                               }
2058                          }
2059                     }
2060                }
2061              else if (!sd->freeze)
2062                {
2063                   Evas_Coord ex, ey, ew, eh;
2064                   double vx = 0.0, vy = 0.0;
2065
2066                   evas_object_geometry_get(sd->event_obj, &ex, &ey, &ew, &eh);
2067                   x = ev->cur.canvas.x - ex;
2068                   y = ev->cur.canvas.y - ey;
2069                   if (x < _elm_config->thumbscroll_threshold)
2070                     {
2071                        if (_elm_config->thumbscroll_threshold > 0.0)
2072                          vx = -(double)(_elm_config->thumbscroll_threshold - x) /
2073                          _elm_config->thumbscroll_threshold;
2074                        else
2075                          vx = -1.0;
2076                     }
2077                   else if (x > (ew - _elm_config->thumbscroll_threshold))
2078                     {
2079                        if (_elm_config->thumbscroll_threshold > 0.0)
2080                          vx = (double)(_elm_config->thumbscroll_threshold - (ew - x)) /
2081                          _elm_config->thumbscroll_threshold;
2082                        else
2083                          vx = 1.0;
2084                     }
2085                   if (y < _elm_config->thumbscroll_threshold)
2086                     {
2087                        if (_elm_config->thumbscroll_threshold > 0.0)
2088                          vy = -(double)(_elm_config->thumbscroll_threshold - y) /
2089                          _elm_config->thumbscroll_threshold;
2090                        else
2091                          vy = -1.0;
2092                     }
2093                   else if (y > (eh - _elm_config->thumbscroll_threshold))
2094                     {
2095                        if (_elm_config->thumbscroll_threshold > 0.0)
2096                          vy = (double)(_elm_config->thumbscroll_threshold - (eh - y)) /
2097                          _elm_config->thumbscroll_threshold;
2098                        else
2099                          vy = 1.0;
2100                     }
2101                   if ((vx != 0.0) || (vy != 0.0))
2102                     {
2103                        sd->down.onhold_vx = vx;
2104                        sd->down.onhold_vy = vy;
2105                        if (!sd->down.onhold_animator)
2106                          {
2107                             sd->down.onhold_vxe = 0.0;
2108                             sd->down.onhold_vye = 0.0;
2109                             sd->down.onhold_tlast = 0.0;
2110                             sd->down.onhold_animator = ecore_animator_add(_smart_onhold_animator, sd);
2111                          }
2112 //                       printf("b %i %i\n", sd->down.hold_x, sd->down.hold_y);
2113                     }
2114                   else
2115                     {
2116                        if (sd->down.onhold_animator)
2117                          {
2118                             ecore_animator_del(sd->down.onhold_animator);
2119                             sd->down.onhold_animator = NULL;
2120                          }
2121                     }
2122                }
2123           }
2124      }
2125 }
2126
2127 static void
2128 _smart_scrollbar_read(Smart_Data *sd)
2129 {
2130    Evas_Coord x, y, mx = 0, my = 0, px, py, minx = 0, miny = 0;
2131    double vx, vy;
2132
2133    edje_object_part_drag_value_get(sd->edje_obj, "elm.dragable.vbar", NULL, &vy);
2134    edje_object_part_drag_value_get(sd->edje_obj, "elm.dragable.hbar", &vx, NULL);
2135    sd->pan_func.max_get(sd->pan_obj, &mx, &my);
2136    sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2137    x = vx * (double)mx + minx;
2138    y = vy * (double)my + miny;
2139    sd->pan_func.get(sd->pan_obj, &px, &py);
2140    sd->pan_func.set(sd->pan_obj, x, y);
2141    if ((px != x) || (py != y))
2142      edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
2143 }
2144
2145 static void
2146 _smart_scrollbar_reset(Smart_Data *sd)
2147 {
2148    Evas_Coord px = 0, py = 0, minx = 0, miny = 0;
2149
2150    edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.vbar", 0.0, 0.0);
2151    edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.hbar", 0.0, 0.0);
2152    if ((!sd->child_obj) && (!sd->extern_pan))
2153      {
2154         edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.vbar", 1.0, 1.0);
2155         edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.hbar", 1.0, 1.0);
2156      }
2157    sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2158    sd->pan_func.get(sd->pan_obj, &px, &py);
2159    sd->pan_func.set(sd->pan_obj, minx, miny);
2160    if ((px != minx) || (py != miny))
2161      edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
2162 }
2163
2164 static int
2165 _smart_scrollbar_bar_v_visibility_adjust(Smart_Data *sd)
2166 {
2167    int scroll_v_vis_change = 0;
2168    Evas_Coord h, vw, vh;
2169
2170    h = sd->child.h;
2171    evas_object_geometry_get(sd->pan_obj, NULL, NULL, &vw, &vh);
2172    if (sd->vbar_visible)
2173      {
2174         if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_AUTO)
2175           {
2176              if ((sd->child_obj) || (sd->extern_pan))
2177                {
2178                   if (h <= vh)
2179                     {
2180                        scroll_v_vis_change = 1;
2181                        sd->vbar_visible = 0;
2182                     }
2183                }
2184              else
2185                {
2186                   scroll_v_vis_change = 1;
2187                   sd->vbar_visible = 0;
2188                }
2189           }
2190         else if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
2191           {
2192              scroll_v_vis_change = 1;
2193              sd->vbar_visible = 0;
2194           }
2195      }
2196    else
2197      {
2198         if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_AUTO)
2199           {
2200              if ((sd->child_obj) || (sd->extern_pan))
2201                {
2202                   if (h > vh)
2203                     {
2204                        scroll_v_vis_change = 1;
2205                        sd->vbar_visible = 1;
2206                     }
2207                }
2208           }
2209         else if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
2210           {
2211              scroll_v_vis_change = 1;
2212              sd->vbar_visible = 1;
2213           }
2214      }
2215    if (scroll_v_vis_change)
2216      {
2217         if (sd->vbar_flags != ELM_SMART_SCROLLER_POLICY_OFF)
2218           {
2219              if (sd->vbar_visible)
2220                edje_object_signal_emit(sd->edje_obj, "elm,action,show,vbar", "elm");
2221              else
2222                edje_object_signal_emit(sd->edje_obj, "elm,action,hide,vbar", "elm");
2223              edje_object_message_signal_process(sd->edje_obj);
2224              _smart_scrollbar_size_adjust(sd);
2225           }
2226         else
2227           edje_object_signal_emit(sd->edje_obj, "elm,action,hide,vbar", "elm");
2228      }
2229    return scroll_v_vis_change;
2230 }
2231
2232 static int
2233 _smart_scrollbar_bar_h_visibility_adjust(Smart_Data *sd)
2234 {
2235    int scroll_h_vis_change = 0;
2236    Evas_Coord w, vw, vh;
2237
2238    w = sd->child.w;
2239    evas_object_geometry_get(sd->pan_obj, NULL, NULL, &vw, &vh);
2240    if (sd->hbar_visible)
2241      {
2242         if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_AUTO)
2243           {
2244              if ((sd->child_obj) || (sd->extern_pan))
2245                {
2246                   if (w <= vw)
2247                     {
2248                        scroll_h_vis_change = 1;
2249                        sd->hbar_visible = 0;
2250                     }
2251                }
2252              else
2253                {
2254                   scroll_h_vis_change = 1;
2255                   sd->hbar_visible = 0;
2256                }
2257           }
2258         else if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
2259           {
2260              scroll_h_vis_change = 1;
2261              sd->hbar_visible = 0;
2262           }
2263      }
2264    else
2265      {
2266         if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_AUTO)
2267           {
2268              if ((sd->child_obj) || (sd->extern_pan))
2269                {
2270                   if (w > vw)
2271                     {
2272                        scroll_h_vis_change = 1;
2273                        sd->hbar_visible = 1;
2274                     }
2275                }
2276           }
2277         else if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
2278           {
2279              scroll_h_vis_change = 1;
2280              sd->hbar_visible = 1;
2281           }
2282      }
2283    if (scroll_h_vis_change)
2284      {
2285         if (sd->hbar_flags != ELM_SMART_SCROLLER_POLICY_OFF)
2286           {
2287              if (sd->hbar_visible)
2288                edje_object_signal_emit(sd->edje_obj, "elm,action,show,hbar", "elm");
2289              else
2290                edje_object_signal_emit(sd->edje_obj, "elm,action,hide,hbar", "elm");
2291              edje_object_message_signal_process(sd->edje_obj);
2292              _smart_scrollbar_size_adjust(sd);
2293           }
2294         else
2295           edje_object_signal_emit(sd->edje_obj, "elm,action,hide,hbar", "elm");
2296         _smart_scrollbar_size_adjust(sd);
2297      }
2298    return scroll_h_vis_change;
2299 }
2300
2301 static void
2302 _smart_scrollbar_bar_visibility_adjust(Smart_Data *sd)
2303 {
2304    int changed = 0;
2305
2306    changed |= _smart_scrollbar_bar_h_visibility_adjust(sd);
2307    changed |= _smart_scrollbar_bar_v_visibility_adjust(sd);
2308    if (changed)
2309      {
2310         _smart_scrollbar_bar_h_visibility_adjust(sd);
2311         _smart_scrollbar_bar_v_visibility_adjust(sd);
2312      }
2313 }
2314
2315 static void
2316 _smart_scrollbar_size_adjust(Smart_Data *sd)
2317 {
2318    if ((sd->child_obj) || (sd->extern_pan))
2319      {
2320         Evas_Coord x, y, w, h, mx = 0, my = 0, vw = 0, vh = 0, px, py, minx = 0, miny = 0;
2321         double vx, vy, size;
2322
2323         edje_object_part_geometry_get(sd->edje_obj, "elm.swallow.content",
2324                                       NULL, NULL, &vw, &vh);
2325         w = sd->child.w;
2326         if (w < 1) w = 1;
2327         size = (double)vw / (double)w;
2328         if (size > 1.0)
2329           {
2330              size = 1.0;
2331              edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.hbar", 0.0, 0.0);
2332           }
2333         edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.hbar", size, 1.0);
2334
2335         h = sd->child.h;
2336         if (h < 1) h = 1;
2337         size = (double)vh / (double)h;
2338         if (size > 1.0)
2339           {
2340              size = 1.0;
2341              edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.vbar", 0.0, 0.0);
2342           }
2343         edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.vbar", 1.0, size);
2344
2345         edje_object_part_drag_value_get(sd->edje_obj, "elm.dragable.hbar", &vx, NULL);
2346         edje_object_part_drag_value_get(sd->edje_obj, "elm.dragable.vbar", NULL, &vy);
2347         sd->pan_func.max_get(sd->pan_obj, &mx, &my);
2348         sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2349         x = vx * mx + minx;
2350         y = vy * my + miny;
2351
2352         edje_object_part_drag_step_set(sd->edje_obj, "elm.dragable.hbar", (double)sd->step.x / (double)w, 0.0);
2353         edje_object_part_drag_step_set(sd->edje_obj, "elm.dragable.vbar", 0.0, (double)sd->step.y / (double)h);
2354         if (sd->page.x > 0)
2355           edje_object_part_drag_page_set(sd->edje_obj, "elm.dragable.hbar", (double)sd->page.x / (double)w, 0.0);
2356         else
2357           edje_object_part_drag_page_set(sd->edje_obj, "elm.dragable.hbar", -((double)sd->page.x * ((double)vw / (double)w)) / 100.0, 0.0);
2358         if (sd->page.y > 0)
2359           edje_object_part_drag_page_set(sd->edje_obj, "elm.dragable.vbar", 0.0, (double)sd->page.y / (double)h);
2360         else
2361           edje_object_part_drag_page_set(sd->edje_obj, "elm.dragable.vbar", 0.0, -((double)sd->page.y * ((double)vh / (double)h)) / 100.0);
2362
2363         sd->pan_func.get(sd->pan_obj, &px, &py);
2364         if (vx != mx) x = px;
2365         if (vy != my) y = py;
2366         sd->pan_func.set(sd->pan_obj, x, y);
2367 //      if ((px != 0) || (py != 0))
2368 //        edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
2369      }
2370    else
2371      {
2372         Evas_Coord px = 0, py = 0, minx = 0, miny = 0;
2373
2374         edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.vbar", 1.0, 1.0);
2375         edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.hbar", 1.0, 1.0);
2376         sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2377         sd->pan_func.get(sd->pan_obj, &px, &py);
2378         sd->pan_func.set(sd->pan_obj, minx, miny);
2379         if ((px != minx) || (py != miny))
2380           edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
2381      }
2382    _smart_scrollbar_bar_visibility_adjust(sd);
2383 }
2384
2385 static void
2386 _smart_reconfigure(Smart_Data *sd)
2387 {
2388    evas_object_move(sd->edje_obj, sd->x, sd->y);
2389    evas_object_resize(sd->edje_obj, sd->w, sd->h);
2390    evas_object_move(sd->event_obj, sd->x, sd->y);
2391    evas_object_resize(sd->event_obj, sd->w, sd->h);
2392    _smart_scrollbar_size_adjust(sd);
2393 }
2394
2395 static void
2396 _smart_add(Evas_Object *obj)
2397 {
2398    Smart_Data *sd;
2399    Evas_Object *o;
2400
2401    sd = calloc(1, sizeof(Smart_Data));
2402    if (!sd) return;
2403    evas_object_smart_data_set(obj, sd);
2404
2405    sd->smart_obj = obj;
2406    sd->x = 0;
2407    sd->y = 0;
2408    sd->w = 0;
2409    sd->h = 0;
2410    sd->step.x = 32;
2411    sd->step.y = 32;
2412    sd->page.x = -50;
2413    sd->page.y = -50;
2414    sd->hbar_flags = ELM_SMART_SCROLLER_POLICY_AUTO;
2415    sd->vbar_flags = ELM_SMART_SCROLLER_POLICY_AUTO;
2416    sd->hbar_visible = 1;
2417    sd->vbar_visible = 1;
2418
2419    sd->bounce_horiz = 1;
2420    sd->bounce_vert = 1;
2421
2422    sd->one_dir_at_a_time = 1;
2423    sd->momentum_animator_disabled = 0;
2424    sd->bounce_animator_disabled = 0;
2425    
2426    o = edje_object_add(evas_object_evas_get(obj));
2427    evas_object_propagate_events_set(o, 0);
2428    sd->edje_obj = o;
2429    // FIXME: null parent obj ... :(
2430    elm_smart_scroller_object_theme_set(NULL, obj, "scroller", "base", "default");
2431    edje_object_signal_callback_add(o, "drag", "elm.dragable.vbar", _smart_edje_drag_v, sd);
2432    edje_object_signal_callback_add(o, "drag,start", "elm.dragable.vbar", _smart_edje_drag_v_start, sd);
2433    edje_object_signal_callback_add(o, "drag,stop", "elm.dragable.vbar", _smart_edje_drag_v_stop, sd);
2434    edje_object_signal_callback_add(o, "drag,step", "elm.dragable.vbar", _smart_edje_drag_v, sd);
2435    edje_object_signal_callback_add(o, "drag,page", "elm.dragable.vbar", _smart_edje_drag_v, sd);
2436    edje_object_signal_callback_add(o, "drag", "elm.dragable.hbar", _smart_edje_drag_h, sd);
2437    edje_object_signal_callback_add(o, "drag,start", "elm.dragable.hbar", _smart_edje_drag_h_start, sd);
2438    edje_object_signal_callback_add(o, "drag,stop", "elm.dragable.hbar", _smart_edje_drag_h_stop, sd);
2439    edje_object_signal_callback_add(o, "drag,step", "elm.dragable.hbar", _smart_edje_drag_h, sd);
2440    edje_object_signal_callback_add(o, "drag,page", "elm.dragable.hbar", _smart_edje_drag_h, sd);
2441    evas_object_smart_member_add(o, obj);
2442
2443    o = evas_object_rectangle_add(evas_object_evas_get(obj));
2444    sd->event_obj = o;
2445    evas_object_color_set(o, 0, 0, 0, 0);
2446    evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_WHEEL, _smart_event_wheel, sd);
2447    evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, _smart_event_mouse_down, sd);
2448    evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_UP, _smart_event_mouse_up, sd);
2449    evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_MOVE, _smart_event_mouse_move, sd);
2450    evas_object_smart_member_add(o, obj);
2451    evas_object_repeat_events_set(o, 1);
2452
2453    sd->pan_func.set = _elm_smart_pan_set;
2454    sd->pan_func.get = _elm_smart_pan_get;
2455    sd->pan_func.max_get = _elm_smart_pan_max_get;
2456    sd->pan_func.min_get = _elm_smart_pan_min_get;
2457    sd->pan_func.child_size_get = _elm_smart_pan_child_size_get;
2458
2459    _smart_scrollbar_reset(sd);
2460 }
2461
2462 static void
2463 _smart_del(Evas_Object *obj)
2464 {
2465    INTERNAL_ENTRY;
2466    elm_smart_scroller_child_set(obj, NULL);
2467    if (!sd->extern_pan) evas_object_del(sd->pan_obj);
2468    evas_object_del(sd->edje_obj);
2469    evas_object_del(sd->event_obj);
2470    if (sd->down.hold_animator) ecore_animator_del(sd->down.hold_animator);
2471    if (sd->down.onhold_animator) ecore_animator_del(sd->down.onhold_animator);
2472    if (sd->down.momentum_animator) ecore_animator_del(sd->down.momentum_animator);
2473    if (sd->down.bounce_x_animator) ecore_animator_del(sd->down.bounce_x_animator);
2474    if (sd->down.bounce_y_animator) ecore_animator_del(sd->down.bounce_y_animator);
2475    if (sd->scrollto.x.animator) ecore_animator_del(sd->scrollto.x.animator);
2476    if (sd->scrollto.y.animator) ecore_animator_del(sd->scrollto.y.animator);
2477    free(sd);
2478    evas_object_smart_data_set(obj, NULL);
2479 }
2480
2481 static void
2482 _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
2483 {
2484    INTERNAL_ENTRY;
2485    sd->x = x;
2486    sd->y = y;
2487    _smart_reconfigure(sd);
2488 }
2489
2490 static void
2491 _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
2492 {
2493    INTERNAL_ENTRY;
2494    sd->w = w;
2495    sd->h = h;
2496    _smart_reconfigure(sd);
2497 }
2498
2499 static void
2500 _smart_show(Evas_Object *obj)
2501 {
2502    INTERNAL_ENTRY;
2503    evas_object_show(sd->edje_obj);
2504    evas_object_show(sd->event_obj);
2505 }
2506
2507 static void
2508 _smart_hide(Evas_Object *obj)
2509 {
2510    INTERNAL_ENTRY;
2511    evas_object_hide(sd->edje_obj);
2512    evas_object_hide(sd->event_obj);
2513 }
2514
2515 static void
2516 _smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
2517 {
2518    INTERNAL_ENTRY;
2519    evas_object_color_set(sd->edje_obj, r, g, b, a);
2520 }
2521
2522 static void
2523 _smart_clip_set(Evas_Object *obj, Evas_Object *clip)
2524 {
2525    INTERNAL_ENTRY;
2526    evas_object_clip_set(sd->edje_obj, clip);
2527    evas_object_clip_set(sd->event_obj, clip);
2528 }
2529
2530 static void
2531 _smart_clip_unset(Evas_Object *obj)
2532 {
2533    INTERNAL_ENTRY;
2534    evas_object_clip_unset(sd->edje_obj);
2535    evas_object_clip_unset(sd->event_obj);
2536 }
2537
2538 /* never need to touch this */
2539
2540 static void
2541 _smart_init(void)
2542 {
2543    if (_smart) return;
2544      {
2545         static const Evas_Smart_Class sc =
2546           {
2547              SMART_NAME,
2548                EVAS_SMART_CLASS_VERSION,
2549                _smart_add,
2550                _smart_del,
2551                _smart_move,
2552                _smart_resize,
2553                _smart_show,
2554                _smart_hide,
2555                _smart_color_set,
2556                _smart_clip_set,
2557                _smart_clip_unset,
2558                NULL,
2559                NULL,
2560                NULL,
2561                NULL,
2562                NULL,
2563                NULL,
2564                NULL
2565           };
2566         _smart = evas_smart_class_new(&sc);
2567      }
2568 }
2569