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