From: 김재환 <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    Eina_Bool no_bounce_x_end = EINA_FALSE, no_bounce_y_end = EINA_FALSE;
696
697    sd = data;
698    t = ecore_loop_time_get();
699    dt = t - sd->down.anim_start;
700    if (dt >= 0.0)
701      {
702         /*
703         if (sd->down.hold_parent)
704           {
705              if ((sd->down.dir_x) && !can_scroll(sd, sd->down.hdir))
706                {
707                   sd->down.dir_x = 0;
708                }
709              if ((sd->down.dir_y) && !can_scroll(sd, sd->down.vdir))
710                {
711                   sd->down.dir_y = 0;
712                }
713           }
714         if ((!sd->down.dir_x) && (!sd->down.dir_y))
715           {
716              sd->down.cancelled = 1;
717           }
718          */
719         dt = dt / (_elm_config->thumbscroll_friction + sd->down.extra_time);
720         if (dt > 1.0) dt = 1.0;
721         p = 1.0 - ((1.0 - dt) * (1.0 - dt));
722         dx = (sd->down.dx * (_elm_config->thumbscroll_friction + sd->down.extra_time) * p);
723         dy = (sd->down.dy * (_elm_config->thumbscroll_friction + sd->down.extra_time) * p);
724         sd->down.ax = dx;
725         sd->down.ay = dy;
726         x = sd->down.sx - dx;
727         y = sd->down.sy - dy;
728         elm_smart_scroller_child_pos_get(sd->smart_obj, &px, &py);
729         if ((sd->down.bounce_x_animator) ||
730             (sd->down.bounce_x_hold))
731           {
732              sd->down.bx = sd->down.bx0 - dx + sd->down.b0x;
733              x = px;
734           }
735         if ((sd->down.bounce_y_animator) ||
736             (sd->down.bounce_y_hold))
737           {
738              sd->down.by = sd->down.by0 - dy + sd->down.b0y;
739              y = py;
740           }
741         elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
742         sd->pan_func.max_get(sd->pan_obj, &maxx, &maxy);
743         sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
744         if (!sd->bounce_horiz)
745           {
746              if (x <= minx) no_bounce_x_end = EINA_TRUE;
747              if ((x - minx) >= maxx) no_bounce_x_end = EINA_TRUE;
748           }
749         if (!sd->bounce_vert)
750           {
751              if (y <= miny) no_bounce_y_end = EINA_TRUE;
752              if ((y - miny) >= maxy) no_bounce_y_end = EINA_TRUE;
753           }
754         if ((dt >= 1.0) || 
755             ((sd->down.bounce_x_hold) && (sd->down.bounce_y_hold)) ||
756             (no_bounce_x_end && no_bounce_y_end))
757           {
758              _smart_anim_stop(sd->smart_obj);
759              sd->down.momentum_animator = NULL;
760              sd->down.bounce_x_hold = 0;
761              sd->down.bounce_y_hold = 0;
762              sd->down.ax = 0;
763              sd->down.ay = 0;
764              sd->down.pdx = 0;
765              sd->down.pdy = 0;
766              return ECORE_CALLBACK_CANCEL;
767           }
768      }
769    return ECORE_CALLBACK_RENEW;
770 }
771
772 static void
773 bounce_eval(Smart_Data *sd)
774 {
775    Evas_Coord mx, my, px, py, bx, by, b2x, b2y, minx = 0, miny = 0;
776
777    if (sd->freeze) return;
778    if ((!sd->bouncemex) && (!sd->bouncemey)) return;
779    if (sd->down.now) return; // down bounce while still held down
780    if (sd->down.onhold_animator)
781      {
782         ecore_animator_del(sd->down.onhold_animator);
783         sd->down.onhold_animator = NULL;
784      }
785    if (sd->down.hold_animator)
786      {
787         ecore_animator_del(sd->down.hold_animator);
788         sd->down.hold_animator = NULL;
789      }
790    sd->pan_func.max_get(sd->pan_obj, &mx, &my);
791    sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
792    sd->pan_func.get(sd->pan_obj, &px, &py);
793    bx = px;
794    by = py;
795    if (px < minx) px = minx;
796    if ((px - minx) > mx) px = mx + minx;
797    if (py < miny) py = miny;
798    if ((py - miny) > my) py = my + miny;
799    b2x = px;
800    b2y = py;
801    if ((!sd->widget) || 
802        (!elm_widget_drag_child_locked_x_get(sd->widget)))
803      {
804         if (!sd->down.bounce_x_animator && !sd->bounce_animator_disabled)
805           {
806              if (sd->bouncemex)
807                {
808                   if (sd->scrollto.x.animator)
809                     {
810                        ecore_animator_del(sd->scrollto.x.animator);
811                        sd->scrollto.x.animator = NULL;
812                     }
813                   sd->down.bounce_x_animator = ecore_animator_add(_smart_bounce_x_animator, sd);
814                   sd->down.anim_start2 = ecore_loop_time_get();
815                   sd->down.bx = bx;
816                   sd->down.bx0 = bx;
817                   sd->down.b2x = b2x;
818                   if (sd->down.momentum_animator) sd->down.b0x = sd->down.ax;
819                   else sd->down.b0x = 0;
820                }
821           }
822      }
823    if ((!sd->widget) || 
824        (!elm_widget_drag_child_locked_y_get(sd->widget)))
825      {
826         if (!sd->down.bounce_y_animator && !sd->bounce_animator_disabled)
827           {
828              if (sd->bouncemey)
829                {
830                   if (sd->scrollto.y.animator)
831                     {
832                        ecore_animator_del(sd->scrollto.y.animator);
833                        sd->scrollto.y.animator = NULL;
834                     }
835                   sd->down.bounce_y_animator = ecore_animator_add(_smart_bounce_y_animator, sd);
836                   sd->down.anim_start3 = ecore_loop_time_get();
837                   sd->down.by = by;
838                   sd->down.by0 = by;
839                   sd->down.b2y = b2y;
840                   if (sd->down.momentum_animator) sd->down.b0y = sd->down.ay;
841                   else sd->down.b0y = 0;
842                }
843           }
844      }
845 }
846
847 void
848 elm_smart_scroller_child_pos_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
849 {
850    Evas_Coord mx = 0, my = 0, px, py, minx = 0, miny = 0;
851    double vx, vy;
852
853    API_ENTRY return;
854    // FIXME: allow for bounce outside of range
855    sd->pan_func.max_get(sd->pan_obj, &mx, &my);
856    sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
857    if (mx > 0) vx = (double)(x - minx) / (double)mx;
858    else vx = 0.0;
859    if (vx < 0.0) vx = 0.0;
860    else if (vx > 1.0) vx = 1.0;
861    if (my > 0) vy = (double)(y - miny) / (double)my;
862    else vy = 0.0;
863    if (vy < 0.0) vy = 0.0;
864    else if (vy > 1.0) vy = 1.0;
865    edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.vbar", 0.0, vy);
866    edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.hbar", vx, 0.0);
867    sd->pan_func.get(sd->pan_obj, &px, &py);
868    if (!_elm_config->thumbscroll_bounce_enable)
869      {
870         if (x < minx) x = minx;
871         if ((x - minx) > mx) x = mx + minx;
872         if (y < miny) y = miny;
873         if ((y - miny) > my) y = my + miny;
874      }
875
876    if (!sd->bounce_horiz)
877      {
878         if (x < minx) x = minx;
879         if ((x - minx) > mx) x = mx + minx;
880      }
881    if (!sd->bounce_vert)
882      {
883         if (y < miny) y = miny;
884         if (y - miny > my) y = my + miny;
885      }
886
887    sd->pan_func.set(sd->pan_obj, x, y);
888    if ((px != x) || (py != y))
889      edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
890    if (!sd->down.bounce_x_animator)
891      {
892         if ((x < minx) || (x > (mx + minx)))
893           {
894              sd->bouncemex = 1;
895              bounce_eval(sd);
896           }
897      }
898    if (!sd->down.bounce_y_animator)
899      {
900         if ((y < miny) || (y > my + miny))
901           {
902              sd->bouncemey = 1;
903              bounce_eval(sd);
904           }
905      }
906    if ((x != px) || (y != py))
907      {
908         evas_object_smart_callback_call(obj, "scroll", NULL);
909      }
910    if ((x != px)/* && (!sd->bouncemex)*/)
911      {
912         if (x == minx)
913           evas_object_smart_callback_call(obj, "edge,left", NULL);
914         if (x == (mx + minx))
915           evas_object_smart_callback_call(obj, "edge,right", NULL);
916      }
917    if ((y != py)/* && (!sd->bouncemey)*/)
918      {
919         if (y == miny)
920           evas_object_smart_callback_call(obj, "edge,top", NULL);
921         if (y == my + miny)
922           evas_object_smart_callback_call(obj, "edge,bottom", NULL);
923      }
924 }
925
926 void
927 elm_smart_scroller_child_pos_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
928 {
929    API_ENTRY return;
930    sd->pan_func.get(sd->pan_obj, x, y);
931 }
932
933 /* "internal_call" actually toggles whether we should save the coords and do
934  * extra "speedup" checks, or not. */
935 static void
936 _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)
937 {
938    Evas_Coord mx = 0, my = 0, cw = 0, ch = 0, px = 0, py = 0, nx, ny, minx = 0, miny = 0;
939
940    API_ENTRY return;
941    sd->pan_func.max_get(sd->pan_obj, &mx, &my);
942    sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
943    sd->pan_func.child_size_get(sd->pan_obj, &cw, &ch);
944    sd->pan_func.get(sd->pan_obj, &px, &py);
945
946    nx = px;
947    if (x < px) nx = x;
948    else if ((x + w) > (px + (cw - mx)))
949      {
950         nx = x + w - (cw - mx);
951         if (nx > x) nx = x;
952      }
953    ny = py;
954    if (y < py) ny = y;
955    else if ((y + h) > (py + (ch - my)))
956      {
957         ny = y + h - (ch - my);
958         if (ny > y) ny = y;
959      }
960    if (!internal_call)
961      {
962         sd->wx = x;
963         sd->wy = y;
964         sd->ww = w;
965         sd->wh = h;
966         if ((nx == px) && (ny == py)) return;
967      }
968
969    if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
970        (sd->scrollto.x.animator) || (sd->scrollto.y.animator))
971      {
972         _smart_anim_stop(sd->smart_obj);
973      }
974    if (sd->scrollto.x.animator)
975      {
976         ecore_animator_del(sd->scrollto.x.animator);
977         sd->scrollto.x.animator = NULL;
978      }
979    if (sd->scrollto.y.animator)
980      {
981         ecore_animator_del(sd->scrollto.y.animator);
982         sd->scrollto.y.animator = NULL;
983      }
984    if (sd->down.bounce_x_animator)
985      {
986         ecore_animator_del(sd->down.bounce_x_animator);
987         sd->down.bounce_x_animator = NULL;
988         sd->bouncemex = 0;
989      }
990    if (sd->down.bounce_y_animator)
991      {
992         ecore_animator_del(sd->down.bounce_y_animator);
993         sd->down.bounce_y_animator = NULL;
994         sd->bouncemey = 0;
995      }
996    if (sd->down.hold_animator)
997      {
998         ecore_animator_del(sd->down.hold_animator);
999         sd->down.hold_animator = NULL;
1000         _smart_drag_stop(sd->smart_obj);
1001      }
1002    if (sd->down.momentum_animator)
1003      {
1004         ecore_animator_del(sd->down.momentum_animator);
1005         sd->down.momentum_animator = NULL;
1006         sd->down.bounce_x_hold = 0;
1007         sd->down.bounce_y_hold = 0;
1008         sd->down.ax = 0;
1009         sd->down.ay = 0;
1010         sd->down.pdx = 0;
1011         sd->down.pdy = 0;
1012      }
1013    elm_smart_scroller_child_pos_set(obj, nx, ny);
1014 }
1015
1016 /* Set should be used for calculated positions, for example, when we move
1017  * because of an animation or because this is the correct position after
1018  * constraints. */
1019 void
1020 elm_smart_scroller_child_region_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
1021 {
1022    _elm_smart_scroller_child_region_show_internal(obj, x, y, w, h, EINA_TRUE);
1023 }
1024
1025 /* Set should be used for setting the wanted position, for example a user scroll
1026  * or moving the cursor in an entry. */
1027 void
1028 elm_smart_scroller_child_region_show(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
1029 {
1030    _elm_smart_scroller_child_region_show_internal(obj, x, y, w, h, EINA_FALSE);
1031 }
1032
1033 void
1034 elm_smart_scroller_child_viewport_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
1035 {
1036    API_ENTRY return;
1037    edje_object_calc_force(sd->edje_obj);
1038    evas_object_geometry_get(sd->pan_obj, NULL, NULL, w, h);
1039 }
1040
1041 void
1042 elm_smart_scroller_step_size_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
1043 {
1044    API_ENTRY return;
1045    if (x < 1) x = 1;
1046    if (y < 1) y = 1;
1047    sd->step.x = x;
1048    sd->step.y = y;
1049    _smart_scrollbar_size_adjust(sd);
1050 }
1051
1052 void
1053 elm_smart_scroller_step_size_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
1054 {
1055    API_ENTRY return;
1056    if (x) *x = sd->step.x;
1057    if (y) *y = sd->step.y;
1058 }
1059
1060 void
1061 elm_smart_scroller_page_size_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
1062 {
1063    API_ENTRY return;
1064    sd->page.x = x;
1065    sd->page.y = y;
1066    _smart_scrollbar_size_adjust(sd);
1067 }
1068
1069 void
1070 elm_smart_scroller_page_size_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
1071 {
1072    API_ENTRY return;
1073    if (x) *x = sd->page.x;
1074    if (y) *y = sd->page.y;
1075 }
1076
1077 void
1078 elm_smart_scroller_policy_set(Evas_Object *obj, Elm_Smart_Scroller_Policy hbar, Elm_Smart_Scroller_Policy vbar)
1079 {
1080    API_ENTRY return;
1081    if ((sd->hbar_flags == hbar) && (sd->vbar_flags == vbar)) return;
1082    sd->hbar_flags = hbar;
1083    sd->vbar_flags = vbar;
1084    if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
1085      edje_object_signal_emit(sd->edje_obj, "elm,action,show_always,hbar", "elm");
1086    else if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
1087      edje_object_signal_emit(sd->edje_obj, "elm,action,hide,hbar", "elm");
1088    else
1089      edje_object_signal_emit(sd->edje_obj, "elm,action,show_notalways,hbar", "elm");
1090    if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
1091      edje_object_signal_emit(sd->edje_obj, "elm,action,show_always,vbar", "elm");
1092    else if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
1093      edje_object_signal_emit(sd->edje_obj, "elm,action,hide,vbar", "elm");
1094    else
1095      edje_object_signal_emit(sd->edje_obj, "elm,action,show_notalways,vbar", "elm");
1096    _smart_scrollbar_size_adjust(sd);
1097 }
1098
1099 void
1100 elm_smart_scroller_policy_get(Evas_Object *obj, Elm_Smart_Scroller_Policy *hbar, Elm_Smart_Scroller_Policy *vbar)
1101 {
1102    API_ENTRY return;
1103    if (hbar) *hbar = sd->hbar_flags;
1104    if (vbar) *vbar = sd->vbar_flags;
1105 }
1106
1107 Evas_Object *
1108 elm_smart_scroller_edje_object_get(Evas_Object *obj)
1109 {
1110    API_ENTRY return NULL;
1111    return sd->edje_obj;
1112 }
1113
1114 void
1115 elm_smart_scroller_single_dir_set(Evas_Object *obj, Eina_Bool single_dir)
1116 {
1117    API_ENTRY return;
1118    sd->one_dir_at_a_time = single_dir;
1119 }
1120
1121 Eina_Bool
1122 elm_smart_scroller_single_dir_get(Evas_Object *obj)
1123 {
1124    API_ENTRY return EINA_FALSE;
1125    return sd->one_dir_at_a_time;
1126 }
1127
1128 void
1129 elm_smart_scroller_object_theme_set(Evas_Object *parent, Evas_Object *obj, const char *clas, const char *group, const char *style)
1130 {
1131    API_ENTRY return;
1132    Evas_Coord mw, mh;
1133    _elm_theme_object_set(parent, sd->edje_obj, clas, group, style);
1134    edje_object_scale_set(sd->edje_obj, elm_widget_scale_get(parent) * _elm_config->scale);
1135    if (sd->pan_obj)
1136      edje_object_part_swallow(sd->edje_obj, "elm.swallow.content", sd->pan_obj);
1137    mw = mh = -1;
1138    elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1139    if (edje_object_part_exists(sd->edje_obj, "elm.scrollbar.base"))
1140      {
1141         Evas_Object *base;
1142         base = edje_object_part_swallow_get(sd->edje_obj, "elm.scrollbar.base");
1143         if (!base)
1144           {
1145              base = evas_object_rectangle_add(evas_object_evas_get(sd->edje_obj));
1146              evas_object_color_set(base, 0, 0, 0, 0);
1147              edje_object_part_swallow(sd->edje_obj, "elm.scrollbar.base", base);
1148           }
1149         if (!_elm_config->thumbscroll_enable)
1150            evas_object_size_hint_min_set(base, mw, mh);
1151      }
1152    sd->vbar_visible = !sd->vbar_visible;
1153    sd->hbar_visible = !sd->hbar_visible;
1154    _smart_scrollbar_bar_visibility_adjust(sd);
1155 }
1156
1157 void
1158 elm_smart_scroller_hold_set(Evas_Object *obj, Eina_Bool hold)
1159 {
1160    API_ENTRY return;
1161    sd->hold = hold;
1162 }
1163
1164 void
1165 elm_smart_scroller_freeze_set(Evas_Object *obj, Eina_Bool freeze)
1166 {
1167    API_ENTRY return;
1168    sd->freeze = freeze;
1169    if (sd->freeze)
1170      {
1171         if (sd->down.onhold_animator)
1172           {
1173              ecore_animator_del(sd->down.onhold_animator);
1174              sd->down.onhold_animator = NULL;
1175           }
1176      }
1177 }
1178
1179 void
1180 elm_smart_scroller_bounce_allow_set(Evas_Object *obj, Eina_Bool horiz, Eina_Bool vert)
1181 {
1182    API_ENTRY return;
1183    sd->bounce_horiz = horiz;
1184    sd->bounce_vert = vert;
1185 }
1186
1187 void
1188 elm_smart_scroller_bounce_allow_get(const Evas_Object *obj, Eina_Bool *horiz, Eina_Bool *vert)
1189 {
1190    API_ENTRY return;
1191    *horiz = sd->bounce_horiz;
1192    *vert = sd->bounce_vert;
1193 }
1194
1195 void
1196 elm_smart_scroller_paging_set(Evas_Object *obj, double pagerel_h, double pagerel_v, Evas_Coord pagesize_h, Evas_Coord pagesize_v)
1197 {
1198    API_ENTRY return;
1199    sd->pagerel_h = pagerel_h;
1200    sd->pagerel_v = pagerel_v;
1201    sd->pagesize_h = pagesize_h;
1202    sd->pagesize_v = pagesize_v;
1203    _smart_page_adjust(sd);
1204 }
1205
1206 void
1207 elm_smart_scroller_paging_get(Evas_Object *obj, double *pagerel_h, double *pagerel_v, Evas_Coord *pagesize_h, Evas_Coord *pagesize_v)
1208 {
1209    API_ENTRY return;
1210    if(pagerel_h) *pagerel_h = sd->pagerel_h;
1211    if(pagerel_v) *pagerel_v = sd->pagerel_v;
1212    if(pagesize_h) *pagesize_h = sd->pagesize_h;
1213    if(pagesize_v) *pagesize_v = sd->pagesize_v;
1214 }
1215
1216 void
1217 elm_smart_scroller_region_bring_in(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
1218 {
1219    Evas_Coord mx = 0, my = 0, cw = 0, ch = 0, px = 0, py = 0, nx, ny, minx = 0, miny = 0;
1220
1221    API_ENTRY return;
1222    sd->pan_func.max_get(sd->pan_obj, &mx, &my);
1223    sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
1224    sd->pan_func.child_size_get(sd->pan_obj, &cw, &ch);
1225    sd->pan_func.get(sd->pan_obj, &px, &py);
1226
1227    nx = px;
1228    if ((x < px) && ((x + w) < (px + (cw - mx)))) nx = x;
1229    else if ((x > px) && ((x + w) > (px + (cw - mx)))) nx = x + w - (cw - mx);
1230    ny = py;
1231    if ((y < py) && ((y + h) < (py + (ch - my)))) ny = y;
1232    else if ((y > py) && ((y + h) > (py + (ch - my)))) ny = y + h - (ch - my);
1233    if ((nx == px) && (ny == py)) return;
1234    if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1235        (sd->scrollto.x.animator) || (sd->scrollto.y.animator))
1236      {
1237         _smart_anim_stop(sd->smart_obj);
1238      }
1239    if (sd->scrollto.x.animator)
1240      {
1241         ecore_animator_del(sd->scrollto.x.animator);
1242         sd->scrollto.x.animator = NULL;
1243      }
1244    if (sd->scrollto.y.animator)
1245      {
1246         ecore_animator_del(sd->scrollto.y.animator);
1247         sd->scrollto.y.animator = NULL;
1248      }
1249    if (sd->down.bounce_x_animator)
1250      {
1251         ecore_animator_del(sd->down.bounce_x_animator);
1252         sd->down.bounce_x_animator = NULL;
1253         sd->bouncemex = 0;
1254      }
1255    if (sd->down.bounce_y_animator)
1256      {
1257         ecore_animator_del(sd->down.bounce_y_animator);
1258         sd->down.bounce_y_animator = NULL;
1259         sd->bouncemey = 0;
1260      }
1261    if (sd->down.hold_animator)
1262      {
1263         ecore_animator_del(sd->down.hold_animator);
1264         sd->down.hold_animator = NULL;
1265         _smart_drag_stop(sd->smart_obj);
1266      }
1267    if (sd->down.momentum_animator)
1268      {
1269         ecore_animator_del(sd->down.momentum_animator);
1270         sd->down.momentum_animator = NULL;
1271         sd->down.bounce_x_hold = 0;
1272         sd->down.bounce_y_hold = 0;
1273         sd->down.ax = 0;
1274         sd->down.ay = 0;
1275         sd->down.pdx = 0;
1276         sd->down.pdy = 0;
1277      }
1278    x = nx;
1279    if (x < minx) x = minx;
1280    else if ((x + w) > cw) x = cw - w;
1281    _smart_scrollto_x(sd, _elm_config->bring_in_scroll_friction, x);
1282    y = ny;
1283    if (y < miny) y = miny;
1284    else if ((y + h) > ch) y = ch - h;
1285    _smart_scrollto_y(sd, _elm_config->bring_in_scroll_friction, y);
1286 }
1287
1288 void
1289 elm_smart_scroller_widget_set(Evas_Object *obj, Evas_Object *wid)
1290 {
1291    API_ENTRY return;
1292    sd->widget = wid;
1293 }
1294
1295 /* local subsystem functions */
1296 static void
1297 _smart_edje_drag_v_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1298 {
1299    Smart_Data *sd;
1300
1301    sd = data;
1302    _smart_scrollbar_read(sd);
1303    _smart_drag_start(sd->smart_obj);
1304 }
1305
1306 static void
1307 _smart_edje_drag_v_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1308 {
1309    Smart_Data *sd;
1310
1311    sd = data;
1312    _smart_scrollbar_read(sd);
1313    _smart_drag_stop(sd->smart_obj);
1314 }
1315
1316 static void
1317 _smart_edje_drag_v(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1318 {
1319    Smart_Data *sd;
1320
1321    sd = data;
1322    _smart_scrollbar_read(sd);
1323 }
1324
1325 static void
1326 _smart_edje_drag_h_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1327 {
1328    Smart_Data *sd;
1329
1330    sd = data;
1331    _smart_scrollbar_read(sd);
1332    _smart_drag_start(sd->smart_obj);
1333 }
1334
1335 static void
1336 _smart_edje_drag_h_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1337 {
1338    Smart_Data *sd;
1339
1340    sd = data;
1341    _smart_scrollbar_read(sd);
1342    _smart_drag_stop(sd->smart_obj);
1343 }
1344
1345 static void
1346 _smart_edje_drag_h(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1347 {
1348    Smart_Data *sd;
1349
1350    sd = data;
1351    _smart_scrollbar_read(sd);
1352 }
1353
1354 static void
1355 _smart_child_del_hook(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1356 {
1357    Smart_Data *sd;
1358
1359    sd = data;
1360    sd->child_obj = NULL;
1361    _smart_scrollbar_size_adjust(sd);
1362    _smart_scrollbar_reset(sd);
1363 }
1364
1365 static void
1366 _smart_pan_changed_hook(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1367 {
1368    Evas_Coord x, y;
1369    Evas_Coord w, h;
1370    Smart_Data *sd;
1371
1372    sd = data;
1373    sd->pan_func.get(sd->pan_obj, &x, &y);
1374    sd->pan_func.child_size_get(sd->pan_obj, &w, &h);
1375    if ((w != sd->child.w) || (h != sd->child.h))
1376      {
1377         sd->child.w = w;
1378         sd->child.h = h;
1379         _smart_scrollbar_size_adjust(sd);
1380         evas_object_size_hint_min_set(sd->smart_obj, sd->child.w, sd->child.h);
1381         elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
1382      }
1383 }
1384
1385 static void
1386 _smart_pan_pan_changed_hook(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1387 {
1388    Evas_Coord x, y;
1389    Smart_Data *sd;
1390
1391    sd = data;
1392    sd->pan_func.get(sd->pan_obj, &x, &y);
1393    if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1394        (sd->scrollto.x.animator) || (sd->scrollto.y.animator))
1395      {
1396         _smart_anim_stop(sd->smart_obj);
1397      }
1398    if (sd->scrollto.x.animator)
1399      {
1400         ecore_animator_del(sd->scrollto.x.animator);
1401         sd->scrollto.x.animator = NULL;
1402      }
1403    if (sd->scrollto.y.animator)
1404      {
1405         ecore_animator_del(sd->scrollto.y.animator);
1406         sd->scrollto.y.animator = NULL;
1407      }
1408    if (sd->down.bounce_x_animator)
1409      {
1410         ecore_animator_del(sd->down.bounce_x_animator);
1411         sd->down.bounce_x_animator = NULL;
1412         sd->bouncemex = 0;
1413      }
1414    if (sd->down.bounce_y_animator)
1415      {
1416         ecore_animator_del(sd->down.bounce_y_animator);
1417         sd->down.bounce_y_animator = NULL;
1418         sd->bouncemey = 0;
1419      }
1420    elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
1421 }
1422
1423 static void
1424 _smart_event_wheel(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1425 {
1426    Evas_Event_Mouse_Wheel *ev;
1427    Smart_Data *sd;
1428    Evas_Coord x = 0, y = 0;
1429
1430    sd = data;
1431    ev = event_info;
1432    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
1433    if ((evas_key_modifier_is_set(ev->modifiers, "Control")) ||
1434        (evas_key_modifier_is_set(ev->modifiers, "Alt")) ||
1435        (evas_key_modifier_is_set(ev->modifiers, "Shift")) ||
1436        (evas_key_modifier_is_set(ev->modifiers, "Meta")) ||
1437        (evas_key_modifier_is_set(ev->modifiers, "Hyper")) ||
1438        (evas_key_modifier_is_set(ev->modifiers, "Super")))
1439      return;
1440    elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1441    if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1442        (sd->scrollto.x.animator) || (sd->scrollto.y.animator))
1443      {
1444         _smart_anim_stop(sd->smart_obj);
1445      }
1446    if (sd->scrollto.x.animator)
1447      {
1448         ecore_animator_del(sd->scrollto.x.animator);
1449         sd->scrollto.x.animator = NULL;
1450      }
1451    if (sd->scrollto.y.animator)
1452      {
1453         ecore_animator_del(sd->scrollto.y.animator);
1454         sd->scrollto.y.animator = NULL;
1455      }
1456    if (sd->down.bounce_x_animator)
1457      {
1458         ecore_animator_del(sd->down.bounce_x_animator);
1459         sd->down.bounce_x_animator = NULL;
1460         sd->bouncemex = 0;
1461      }
1462    if (sd->down.bounce_y_animator)
1463      {
1464         ecore_animator_del(sd->down.bounce_y_animator);
1465         sd->down.bounce_y_animator = NULL;
1466         sd->bouncemey = 0;
1467      }
1468    if (!ev->direction)
1469      y += ev->z * sd->step.y;
1470    else if (ev->direction == 1)
1471      x += ev->z * sd->step.x;
1472
1473    if ((!sd->hold) && (!sd->freeze))
1474      {
1475         sd->wx = x;
1476         sd->wy = y;
1477         elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &sd->ww, &sd->wh);
1478         elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
1479      }
1480 }
1481
1482 static void
1483 _smart_event_mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1484 {
1485    Evas_Event_Mouse_Down *ev;
1486    Smart_Data *sd;
1487    Evas_Coord x = 0, y = 0;
1488
1489    sd = data;
1490    ev = event_info;
1491 //   if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
1492    if (_elm_config->thumbscroll_enable)
1493      {
1494         sd->down.hold = 0;
1495         if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
1496             (sd->down.momentum_animator) || (sd->scrollto.x.animator) ||
1497             (sd->scrollto.y.animator))
1498           {
1499              ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL | EVAS_EVENT_FLAG_ON_HOLD;
1500              sd->down.scroll = 1;
1501              sd->down.hold = 1;
1502              _smart_anim_stop(sd->smart_obj);
1503           }
1504         if (sd->scrollto.x.animator)
1505           {
1506              ecore_animator_del(sd->scrollto.x.animator);
1507              sd->scrollto.x.animator = NULL;
1508           }
1509         if (sd->scrollto.y.animator)
1510           {
1511              ecore_animator_del(sd->scrollto.y.animator);
1512              sd->scrollto.y.animator = NULL;
1513           }
1514         if (sd->down.bounce_x_animator)
1515           {
1516              ecore_animator_del(sd->down.bounce_x_animator);
1517              sd->down.bounce_x_animator = NULL;
1518              sd->bouncemex = 0;
1519           }
1520         if (sd->down.bounce_y_animator)
1521           {
1522              ecore_animator_del(sd->down.bounce_y_animator);
1523              sd->down.bounce_y_animator = NULL;
1524              sd->bouncemey = 0;
1525           }
1526         if (sd->down.hold_animator)
1527           {
1528              ecore_animator_del(sd->down.hold_animator);
1529              sd->down.hold_animator = NULL;
1530              _smart_drag_stop(sd->smart_obj);
1531           }
1532         if (sd->down.momentum_animator)
1533           {
1534              ecore_animator_del(sd->down.momentum_animator);
1535              sd->down.momentum_animator = NULL;
1536              sd->down.bounce_x_hold = 0;
1537              sd->down.bounce_y_hold = 0;
1538              sd->down.ax = 0;
1539              sd->down.ay = 0;
1540           }
1541         if (ev->button == 1)
1542           {
1543              sd->down.now = 1;
1544              sd->down.dragged = 0;
1545              sd->down.dir_x = 0;
1546              sd->down.dir_y = 0;
1547              sd->down.x = ev->canvas.x;
1548              sd->down.y = ev->canvas.y;
1549              elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1550              sd->down.sx = x;
1551              sd->down.sy = y;
1552              sd->down.locked = 0;
1553              memset(&(sd->down.history[0]), 0, sizeof(sd->down.history[0]) * 20);
1554 #ifdef EVTIME
1555              sd->down.history[0].timestamp = ev->timestamp / 1000.0;
1556 #else
1557              sd->down.history[0].timestamp = ecore_loop_time_get();
1558 #endif
1559              sd->down.history[0].x = ev->canvas.x;
1560              sd->down.history[0].y = ev->canvas.y;
1561           }
1562         sd->down.dragged_began = 0;
1563         sd->down.hold_parent = 0;
1564         sd->down.cancelled = 0;
1565      }
1566 }
1567
1568 static Eina_Bool
1569 _smart_hold_animator(void *data)
1570 {
1571    Smart_Data *sd = data;
1572    Evas_Coord ox, oy;
1573    
1574    elm_smart_scroller_child_pos_get(sd->smart_obj, &ox, &oy);
1575    if (sd->down.dir_x)
1576      {
1577         if ((!sd->widget) || 
1578             (!elm_widget_drag_child_locked_x_get(sd->widget)))
1579           {
1580              ox = sd->down.hold_x;
1581           }
1582      }
1583    if (sd->down.dir_y)
1584      {
1585         if ((!sd->widget) || 
1586             (!elm_widget_drag_child_locked_y_get(sd->widget)))
1587           {
1588              oy = sd->down.hold_y;
1589           }
1590      }
1591    elm_smart_scroller_child_pos_set(sd->smart_obj, ox, oy);
1592    return ECORE_CALLBACK_RENEW;
1593 }
1594
1595 static Eina_Bool
1596 _smart_event_post_up(void *data, Evas *e __UNUSED__)
1597 {
1598    Smart_Data *sd = data;
1599    if (sd->widget)
1600      {
1601         if (sd->down.dragged)
1602           {
1603              elm_widget_drag_lock_x_set(sd->widget, 0);
1604              elm_widget_drag_lock_y_set(sd->widget, 0);
1605           }
1606      }
1607    return EINA_TRUE;
1608 }
1609
1610 static void
1611 _smart_event_mouse_up(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *event_info)
1612 {
1613    Evas_Event_Mouse_Down *ev;
1614    Smart_Data *sd;
1615    Evas_Coord x = 0, y = 0, ox = 0, oy = 0;
1616
1617    sd = data;
1618    ev = event_info;
1619    sd->down.hold_parent = 0;
1620 //   if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
1621    evas_post_event_callback_push(e, _smart_event_post_up, sd);
1622    // FIXME: respect elm_widget_scroll_hold_get of parent container
1623    if (_elm_config->thumbscroll_enable)
1624      {
1625         if (ev->button == 1)
1626           {
1627              if (sd->down.onhold_animator)
1628                {
1629                   ecore_animator_del(sd->down.onhold_animator);
1630                   sd->down.onhold_animator = NULL;
1631                }
1632              x = ev->canvas.x - sd->down.x;
1633              y = ev->canvas.y - sd->down.y;
1634              if (sd->down.dragged)
1635                {
1636                   _smart_drag_stop(sd->smart_obj);
1637                   if ((!sd->hold) && (!sd->freeze))
1638                     {
1639                        double t, at, dt;
1640                        int i;
1641                        Evas_Coord ax, ay, dx, dy, vel;
1642
1643 #ifdef EVTIME
1644                        t = ev->timestamp / 1000.0;
1645 #else
1646                        t = ecore_loop_time_get();
1647 #endif
1648                        ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1649                        ax = ev->canvas.x;
1650                        ay = ev->canvas.y;
1651                        at = 0.0;
1652 #ifdef SCROLLDBG
1653                        printf("------ %i %i\n", ev->canvas.x, ev->canvas.y);
1654 #endif
1655                        for (i = 0; i < 20; i++)
1656                          {
1657                             dt = t - sd->down.history[i].timestamp;
1658                             if (dt > 0.2) break;
1659 #ifdef SCROLLDBG
1660                             printf("H: %i %i @ %1.3f\n",
1661                                    sd->down.history[i].x,
1662                                    sd->down.history[i].y, dt);
1663 #endif
1664                             at += dt;
1665                             ax += sd->down.history[i].x;
1666                             ay += sd->down.history[i].y;
1667                          }
1668                        ax /= (i + 1);
1669                        ay /= (i + 1);
1670                        at /= (i + 1);
1671                        at *= 4.0;
1672                        dx = ev->canvas.x - ax;
1673                        dy = ev->canvas.y - ay;
1674                        if (at > 0)
1675                          {
1676                             vel = sqrt((dx * dx) + (dy * dy)) / at;
1677                             if ((_elm_config->thumbscroll_friction > 0.0) &&
1678                                 (vel > _elm_config->thumbscroll_momentum_threshold) &&
1679                                 (!sd->freeze))
1680                               {
1681                                  sd->down.dx = ((double)dx / at);
1682                                  sd->down.dy = ((double)dy / at);
1683                                  if (((sd->down.dx > 0) && (sd->down.pdx > 0)) ||
1684                                      ((sd->down.dx < 0) && (sd->down.pdx < 0)))
1685                                    sd->down.dx += (double)sd->down.pdx * 1.5; // FIXME: * 1.5 - probably should be config
1686                                  if (((sd->down.dy > 0) && (sd->down.pdy > 0)) ||
1687                                      ((sd->down.dy < 0) && (sd->down.pdy < 0)))
1688                                    sd->down.dy += (double)sd->down.pdy * 1.5; // FIXME: * 1.5 - probably should be config
1689                                  if (((sd->down.dx > 0) && (sd->down.pdx > 0)) ||
1690                                      ((sd->down.dx < 0) && (sd->down.pdx < 0)) ||
1691                                      ((sd->down.dy > 0) && (sd->down.pdy > 0)) ||
1692                                      ((sd->down.dy < 0) && (sd->down.pdy < 0)))
1693                                   {
1694                                     double t = ecore_loop_time_get();
1695                                     double dt = t - sd->down.anim_start;
1696                                     
1697                                     if (dt < 0.0) dt = 0.0;
1698                                     else if (dt > _elm_config->thumbscroll_friction)
1699                                       dt = _elm_config->thumbscroll_friction;
1700                                     sd->down.extra_time = _elm_config->thumbscroll_friction - dt;
1701                                   }
1702                                  else
1703                                   sd->down.extra_time = 0.0;
1704                                  sd->down.pdx = sd->down.dx;
1705                                  sd->down.pdy = sd->down.dy;
1706                                  ox = -sd->down.dx;
1707                                  oy = -sd->down.dy;
1708                                  if (!_smart_do_page(sd))
1709                                    {
1710                                       if (!sd->down.momentum_animator && !sd->momentum_animator_disabled)
1711                                         {
1712                                            sd->down.momentum_animator = ecore_animator_add(_smart_momentum_animator, sd);
1713                                            ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL;
1714                                            _smart_anim_start(sd->smart_obj);
1715                                         }
1716                                       sd->down.anim_start = ecore_loop_time_get();
1717                                       elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1718                                       sd->down.sx = x;
1719                                       sd->down.sy = y;
1720                                       sd->down.b0x = 0;
1721                                       sd->down.b0y = 0;
1722                                    }
1723                               }
1724                          }
1725                        if (sd->down.hold_animator)
1726                          {
1727                             ecore_animator_del(sd->down.hold_animator);
1728                             sd->down.hold_animator = NULL;
1729                          }
1730                     }
1731                   else
1732                     {
1733                        sd->down.pdx = 0;
1734                        sd->down.pdy = 0;
1735                     }
1736                   evas_event_feed_hold(e, 0, ev->timestamp, ev->data);
1737                   if (_smart_do_page(sd))
1738                     {
1739                        Evas_Coord pgx, pgy;
1740
1741                        elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1742                        if ((!sd->widget) || 
1743                            (!elm_widget_drag_child_locked_x_get(sd->widget)))
1744                          {
1745                             pgx = _smart_page_x_get(sd, ox);
1746                             if (pgx != x) 
1747                               {
1748                                  ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL;
1749                                  _smart_scrollto_x(sd, _elm_config->page_scroll_friction, pgx);
1750                               }
1751                          }
1752                        if ((!sd->widget) || 
1753                            (!elm_widget_drag_child_locked_y_get(sd->widget)))
1754                          {
1755                             pgy = _smart_page_y_get(sd, oy);
1756                             if (pgy != y) 
1757                               {
1758                                  ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL;
1759                                  _smart_scrollto_y(sd, _elm_config->page_scroll_friction, pgy);
1760                               }
1761                          }
1762                     }
1763                }
1764              else
1765                {
1766                   sd->down.pdx = 0;
1767                   sd->down.pdy = 0;
1768                   if (_smart_do_page(sd))
1769                     {
1770                        Evas_Coord pgx, pgy;
1771
1772                        elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1773                        if ((!sd->widget) || 
1774                            (!elm_widget_drag_child_locked_x_get(sd->widget)))
1775                          {
1776                             pgx = _smart_page_x_get(sd, ox);
1777                             if (pgx != x) _smart_scrollto_x(sd, _elm_config->page_scroll_friction, pgx);
1778                          }
1779                        if ((!sd->widget) || 
1780                            (!elm_widget_drag_child_locked_y_get(sd->widget)))
1781                          {
1782                             pgy = _smart_page_y_get(sd, oy);
1783                             if (pgy != y) _smart_scrollto_y(sd, _elm_config->page_scroll_friction, pgy);
1784                          }
1785                     }
1786                   if (sd->down.hold_animator)
1787                     {
1788                        ecore_animator_del(sd->down.hold_animator);
1789                        sd->down.hold_animator = NULL;
1790                     }
1791                }
1792              if (sd->down.scroll)
1793                {
1794                   ev->event_flags |= EVAS_EVENT_FLAG_ON_SCROLL;
1795                   sd->down.scroll = 0;
1796                }
1797              if (sd->down.hold)
1798                {
1799                   ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1800                   sd->down.hold = 0;
1801                }
1802              sd->down.dragged_began = 0;
1803              sd->down.dir_x = 0;
1804              sd->down.dir_y = 0;
1805              sd->down.want_dragged = 0;
1806              sd->down.dragged = 0;
1807              sd->down.now = 0;
1808              elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
1809              elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
1810              sd->wx = x;
1811              sd->wy = y;
1812              elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &sd->ww, &sd->wh);
1813              if (!_smart_do_page(sd))
1814                bounce_eval(sd);
1815           }
1816      }
1817 }
1818
1819 static Eina_Bool
1820 _smart_onhold_animator(void *data)
1821 {
1822    Smart_Data *sd;
1823    double t, td;
1824    double vx, vy;
1825    Evas_Coord x, y, ox, oy;
1826
1827    sd = data;
1828    t = ecore_loop_time_get();
1829    if (sd->down.onhold_tlast > 0.0)
1830      {
1831         td = t - sd->down.onhold_tlast;
1832         vx = sd->down.onhold_vx * td * (double)_elm_config->thumbscroll_threshold * 2.0;
1833         vy = sd->down.onhold_vy * td * (double)_elm_config->thumbscroll_threshold * 2.0;
1834         elm_smart_scroller_child_pos_get(sd->smart_obj, &ox, &oy);
1835         x = ox;
1836         y = oy;
1837         
1838         if (sd->down.dir_x)
1839           {
1840              if ((!sd->widget) || 
1841                  (!elm_widget_drag_child_locked_x_get(sd->widget)))
1842                {
1843                   sd->down.onhold_vxe += vx;
1844                   x = ox + (int)sd->down.onhold_vxe;
1845                   sd->down.onhold_vxe -= (int)sd->down.onhold_vxe;
1846                }
1847           }
1848         
1849         if (sd->down.dir_y)
1850           {
1851              if ((!sd->widget) || 
1852                  (!elm_widget_drag_child_locked_y_get(sd->widget)))
1853                {
1854                   sd->down.onhold_vye += vy;
1855                   y = oy + (int)sd->down.onhold_vye;
1856                   sd->down.onhold_vye -= (int)sd->down.onhold_vye;
1857                }
1858           }
1859         
1860         elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
1861      }
1862    sd->down.onhold_tlast = t;
1863    return ECORE_CALLBACK_RENEW;
1864 }
1865
1866 static Eina_Bool
1867 _smart_event_post_move(void *data, Evas *e __UNUSED__)
1868 {
1869    Smart_Data *sd = data;
1870
1871    if (sd->down.want_dragged)
1872      {
1873         int start = 0;
1874
1875         if (sd->down.hold_parent)
1876           {
1877              if ((sd->down.dir_x) && !can_scroll(sd, sd->down.hdir))
1878                {
1879                   sd->down.dir_x = 0;
1880                }
1881              if ((sd->down.dir_y) && !can_scroll(sd, sd->down.vdir))
1882                {
1883                   sd->down.dir_y = 0;
1884                }
1885           }
1886         if (sd->down.dir_x)
1887           {
1888              if ((!sd->widget) || 
1889                  (!elm_widget_drag_child_locked_x_get(sd->widget)))
1890                {
1891                   sd->down.want_dragged = 0;
1892                   sd->down.dragged = 1;
1893                   if (sd->widget)
1894                     {
1895                        elm_widget_drag_lock_x_set(sd->widget, 1);
1896                     }
1897                   start = 1;
1898                }
1899              else
1900                sd->down.dir_x = 0;
1901           }
1902         if (sd->down.dir_y)
1903           {
1904              if ((!sd->widget) || 
1905                  (!elm_widget_drag_child_locked_y_get(sd->widget)))
1906                {
1907                   sd->down.want_dragged = 0;
1908                   sd->down.dragged = 1;
1909                   if (sd->widget)
1910                     {
1911                        elm_widget_drag_lock_y_set(sd->widget, 1);
1912                     }
1913                   start = 1;
1914                }
1915              else
1916                sd->down.dir_y = 0;
1917           }
1918         if ((!sd->down.dir_x) && (!sd->down.dir_y))
1919           {
1920              sd->down.cancelled = 1;
1921           }
1922         if (start) _smart_drag_start(sd->smart_obj);
1923      }
1924    return EINA_TRUE;
1925 }
1926
1927 static void
1928 _smart_event_mouse_move(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *event_info)
1929 {
1930    Evas_Event_Mouse_Move *ev;
1931    Smart_Data *sd;
1932    Evas_Coord x = 0, y = 0;
1933
1934    sd = data;
1935    ev = event_info;
1936 //   if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
1937    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) sd->down.hold_parent = 1;
1938    evas_post_event_callback_push(e, _smart_event_post_move, sd);
1939    // FIXME: respect elm_widget_scroll_hold_get of parent container
1940    if (_elm_config->thumbscroll_enable)
1941      {
1942         if (sd->down.now)
1943           {
1944              int dodir = 0;
1945
1946 #ifdef SCROLLDBG
1947              printf("::: %i %i\n", ev->cur.canvas.x, ev->cur.canvas.y);
1948 #endif
1949              memmove(&(sd->down.history[1]), &(sd->down.history[0]),
1950                      sizeof(sd->down.history[0]) * 19);
1951 #ifdef EVTIME
1952              sd->down.history[0].timestamp = ev->timestamp / 1000.0;
1953 #else
1954              sd->down.history[0].timestamp = ecore_loop_time_get();
1955 #endif
1956              sd->down.history[0].x = ev->cur.canvas.x;
1957              sd->down.history[0].y = ev->cur.canvas.y;
1958
1959              if (!sd->down.dragged_began)
1960                {
1961                   x = ev->cur.canvas.x - sd->down.x;
1962                   y = ev->cur.canvas.y - sd->down.y;
1963                   
1964                   sd->down.hdir = -1;
1965                   sd->down.vdir = -1;
1966                     
1967                   if      (x > 0) sd->down.hdir = LEFT;
1968                   else if (x < 0) sd->down.hdir = RIGHT;
1969                   if      (y > 0) sd->down.vdir = UP;
1970                   else if (y < 0) sd->down.vdir = DOWN;
1971                   
1972                   if (x < 0) x = -x;
1973                   if (y < 0) y = -y;
1974              
1975                   if ((sd->one_dir_at_a_time) &&
1976                       (!((sd->down.dir_x) || (sd->down.dir_y))))
1977                     {
1978                        if (x > _elm_config->thumbscroll_threshold)
1979                          {
1980                             if (x > (y * 2))
1981                               {
1982                                  sd->down.dir_x = 1;
1983                                  sd->down.dir_y = 0;
1984                                  dodir++;
1985                               }
1986                          }
1987                        if (y > _elm_config->thumbscroll_threshold)
1988                          {
1989                             if (y > (x * 2))
1990                               {
1991                                  sd->down.dir_x = 0;
1992                                  sd->down.dir_y = 1;
1993                                  dodir++;
1994                               }
1995                          }
1996                        if (!dodir)
1997                          {
1998                             sd->down.dir_x = 1;
1999                             sd->down.dir_y = 1;
2000                          }
2001                     }
2002                   else
2003                     {
2004 //                       can_scroll(sd, LEFT);
2005 //                       can_scroll(sd, RIGHT);
2006 //                       can_scroll(sd, UP);
2007 //                       can_scroll(sd, DOWN);
2008                        sd->down.dir_x = 1;
2009                        sd->down.dir_y = 1;
2010                     }
2011                }
2012              if ((!sd->hold) && (!sd->freeze))
2013                {
2014                   if ((sd->down.dragged) ||
2015                       (((x * x) + (y * y)) >
2016                        (_elm_config->thumbscroll_threshold *
2017                         _elm_config->thumbscroll_threshold)))
2018                     {
2019                        sd->down.dragged_began = 1;
2020                        if (!sd->down.dragged)
2021                          {
2022                             sd->down.want_dragged = 1;
2023                             ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2024 //                            evas_event_feed_hold(e, 1, ev->timestamp, ev->data);
2025 //                            _smart_drag_start(sd->smart_obj);
2026                          }
2027                        if (sd->down.dragged)
2028                          {
2029                             ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2030                          }
2031 //                       ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2032 //                       sd->down.dragged = 1;
2033                        if (sd->down.dir_x)
2034                          x = sd->down.sx - (ev->cur.canvas.x - sd->down.x);
2035                        else
2036                          x = sd->down.sx;
2037                        if (sd->down.dir_y)
2038                          y = sd->down.sy - (ev->cur.canvas.y - sd->down.y);
2039                        else
2040                          y = sd->down.sy;
2041                        if ((sd->down.dir_x) || (sd->down.dir_y))
2042                          {
2043                             if (!sd->down.locked)
2044                               {
2045                                  sd->down.locked_x = x;
2046                                  sd->down.locked_y = y;
2047                                  sd->down.locked = 1;
2048                               }
2049                             if (!((sd->down.dir_x) && (sd->down.dir_y)))
2050                               {
2051                                  if (sd->down.dir_x) y = sd->down.locked_y;
2052                                  else x = sd->down.locked_x;
2053                               }
2054                          }
2055                        if (_elm_config->thumbscroll_border_friction > 0.0)
2056                          {
2057                             Evas_Coord minx, miny;
2058                             sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2059                             if (y < miny)
2060                                y += (miny - y) *
2061                                   _elm_config->thumbscroll_border_friction;
2062                             else if (sd->child.h <= sd->h)
2063                                y += (sd->down.sy - y) *
2064                                   _elm_config->thumbscroll_border_friction;
2065                             else if ((sd->child.h - sd->h + miny) < y)
2066                                y += (sd->child.h - sd->h + miny - y) *
2067                                   _elm_config->thumbscroll_border_friction;
2068                             if (x < minx)
2069                                x += (minx - x) *
2070                                   _elm_config->thumbscroll_border_friction;
2071                             else if (sd->child.w <= sd->w)
2072                                x += (sd->down.sx - x) *
2073                                   _elm_config->thumbscroll_border_friction;
2074                             else if ((sd->child.w - sd->w + minx) < x)
2075                                x += (sd->child.w - sd->w + minx - x) *
2076                                   _elm_config->thumbscroll_border_friction;
2077                          }
2078
2079                        sd->down.hold_x = x;
2080                        sd->down.hold_y = y;
2081                        if (!sd->down.hold_animator)
2082                          sd->down.hold_animator = 
2083                             ecore_animator_add(_smart_hold_animator, sd);
2084 //                       printf("a %i %i\n", sd->down.hold_x, sd->down.hold_y);
2085 //                       _smart_onhold_animator(sd);
2086 //                       elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
2087                     }
2088                   else
2089                     {
2090                        if (sd->down.dragged_began)
2091                          {
2092                             ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2093                             if (!sd->down.hold)
2094                               {
2095                                  sd->down.hold = 1;
2096                                  evas_event_feed_hold(e, 1, ev->timestamp, ev->data);
2097                               }
2098                          }
2099                     }
2100                }
2101              else if (!sd->freeze)
2102                {
2103                   Evas_Coord ex, ey, ew, eh;
2104                   double vx = 0.0, vy = 0.0;
2105
2106                   evas_object_geometry_get(sd->event_obj, &ex, &ey, &ew, &eh);
2107                   x = ev->cur.canvas.x - ex;
2108                   y = ev->cur.canvas.y - ey;
2109                   if (x < _elm_config->thumbscroll_threshold)
2110                     {
2111                        if (_elm_config->thumbscroll_threshold > 0.0)
2112                          vx = -(double)(_elm_config->thumbscroll_threshold - x) /
2113                          _elm_config->thumbscroll_threshold;
2114                        else
2115                          vx = -1.0;
2116                     }
2117                   else if (x > (ew - _elm_config->thumbscroll_threshold))
2118                     {
2119                        if (_elm_config->thumbscroll_threshold > 0.0)
2120                          vx = (double)(_elm_config->thumbscroll_threshold - (ew - x)) /
2121                          _elm_config->thumbscroll_threshold;
2122                        else
2123                          vx = 1.0;
2124                     }
2125                   if (y < _elm_config->thumbscroll_threshold)
2126                     {
2127                        if (_elm_config->thumbscroll_threshold > 0.0)
2128                          vy = -(double)(_elm_config->thumbscroll_threshold - y) /
2129                          _elm_config->thumbscroll_threshold;
2130                        else
2131                          vy = -1.0;
2132                     }
2133                   else if (y > (eh - _elm_config->thumbscroll_threshold))
2134                     {
2135                        if (_elm_config->thumbscroll_threshold > 0.0)
2136                          vy = (double)(_elm_config->thumbscroll_threshold - (eh - y)) /
2137                          _elm_config->thumbscroll_threshold;
2138                        else
2139                          vy = 1.0;
2140                     }
2141                   if ((vx != 0.0) || (vy != 0.0))
2142                     {
2143                        sd->down.onhold_vx = vx;
2144                        sd->down.onhold_vy = vy;
2145                        if (!sd->down.onhold_animator)
2146                          {
2147                             sd->down.onhold_vxe = 0.0;
2148                             sd->down.onhold_vye = 0.0;
2149                             sd->down.onhold_tlast = 0.0;
2150                             sd->down.onhold_animator = ecore_animator_add(_smart_onhold_animator, sd);
2151                          }
2152 //                       printf("b %i %i\n", sd->down.hold_x, sd->down.hold_y);
2153                     }
2154                   else
2155                     {
2156                        if (sd->down.onhold_animator)
2157                          {
2158                             ecore_animator_del(sd->down.onhold_animator);
2159                             sd->down.onhold_animator = NULL;
2160                          }
2161                     }
2162                }
2163           }
2164      }
2165 }
2166
2167 static void
2168 _smart_scrollbar_read(Smart_Data *sd)
2169 {
2170    Evas_Coord x, y, mx = 0, my = 0, px, py, minx = 0, miny = 0;
2171    double vx, vy;
2172
2173    edje_object_part_drag_value_get(sd->edje_obj, "elm.dragable.vbar", NULL, &vy);
2174    edje_object_part_drag_value_get(sd->edje_obj, "elm.dragable.hbar", &vx, NULL);
2175    sd->pan_func.max_get(sd->pan_obj, &mx, &my);
2176    sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2177    x = vx * (double)mx + minx;
2178    y = vy * (double)my + miny;
2179    sd->pan_func.get(sd->pan_obj, &px, &py);
2180    sd->pan_func.set(sd->pan_obj, x, y);
2181    if ((px != x) || (py != y))
2182      edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
2183 }
2184
2185 static void
2186 _smart_scrollbar_reset(Smart_Data *sd)
2187 {
2188    Evas_Coord px = 0, py = 0, minx = 0, miny = 0;
2189
2190    edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.vbar", 0.0, 0.0);
2191    edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.hbar", 0.0, 0.0);
2192    if ((!sd->child_obj) && (!sd->extern_pan))
2193      {
2194         edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.vbar", 1.0, 1.0);
2195         edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.hbar", 1.0, 1.0);
2196      }
2197    sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2198    sd->pan_func.get(sd->pan_obj, &px, &py);
2199    sd->pan_func.set(sd->pan_obj, minx, miny);
2200    if ((px != minx) || (py != miny))
2201      edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
2202 }
2203
2204 static int
2205 _smart_scrollbar_bar_v_visibility_adjust(Smart_Data *sd)
2206 {
2207    int scroll_v_vis_change = 0;
2208    Evas_Coord h, vw, vh;
2209
2210    h = sd->child.h;
2211    evas_object_geometry_get(sd->pan_obj, NULL, NULL, &vw, &vh);
2212    if (sd->vbar_visible)
2213      {
2214         if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_AUTO)
2215           {
2216              if ((sd->child_obj) || (sd->extern_pan))
2217                {
2218                   if (h <= vh)
2219                     {
2220                        scroll_v_vis_change = 1;
2221                        sd->vbar_visible = 0;
2222                     }
2223                }
2224              else
2225                {
2226                   scroll_v_vis_change = 1;
2227                   sd->vbar_visible = 0;
2228                }
2229           }
2230         else if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
2231           {
2232              scroll_v_vis_change = 1;
2233              sd->vbar_visible = 0;
2234           }
2235      }
2236    else
2237      {
2238         if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_AUTO)
2239           {
2240              if ((sd->child_obj) || (sd->extern_pan))
2241                {
2242                   if (h > vh)
2243                     {
2244                        scroll_v_vis_change = 1;
2245                        sd->vbar_visible = 1;
2246                     }
2247                }
2248           }
2249         else if (sd->vbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
2250           {
2251              scroll_v_vis_change = 1;
2252              sd->vbar_visible = 1;
2253           }
2254      }
2255    if (scroll_v_vis_change)
2256      {
2257         if (sd->vbar_flags != ELM_SMART_SCROLLER_POLICY_OFF)
2258           {
2259              if (sd->vbar_visible)
2260                edje_object_signal_emit(sd->edje_obj, "elm,action,show,vbar", "elm");
2261              else
2262                edje_object_signal_emit(sd->edje_obj, "elm,action,hide,vbar", "elm");
2263              edje_object_message_signal_process(sd->edje_obj);
2264              _smart_scrollbar_size_adjust(sd);
2265           }
2266         else
2267           edje_object_signal_emit(sd->edje_obj, "elm,action,hide,vbar", "elm");
2268      }
2269    return scroll_v_vis_change;
2270 }
2271
2272 static int
2273 _smart_scrollbar_bar_h_visibility_adjust(Smart_Data *sd)
2274 {
2275    int scroll_h_vis_change = 0;
2276    Evas_Coord w, vw, vh;
2277
2278    w = sd->child.w;
2279    evas_object_geometry_get(sd->pan_obj, NULL, NULL, &vw, &vh);
2280    if (sd->hbar_visible)
2281      {
2282         if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_AUTO)
2283           {
2284              if ((sd->child_obj) || (sd->extern_pan))
2285                {
2286                   if (w <= vw)
2287                     {
2288                        scroll_h_vis_change = 1;
2289                        sd->hbar_visible = 0;
2290                     }
2291                }
2292              else
2293                {
2294                   scroll_h_vis_change = 1;
2295                   sd->hbar_visible = 0;
2296                }
2297           }
2298         else if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_OFF)
2299           {
2300              scroll_h_vis_change = 1;
2301              sd->hbar_visible = 0;
2302           }
2303      }
2304    else
2305      {
2306         if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_AUTO)
2307           {
2308              if ((sd->child_obj) || (sd->extern_pan))
2309                {
2310                   if (w > vw)
2311                     {
2312                        scroll_h_vis_change = 1;
2313                        sd->hbar_visible = 1;
2314                     }
2315                }
2316           }
2317         else if (sd->hbar_flags == ELM_SMART_SCROLLER_POLICY_ON)
2318           {
2319              scroll_h_vis_change = 1;
2320              sd->hbar_visible = 1;
2321           }
2322      }
2323    if (scroll_h_vis_change)
2324      {
2325         if (sd->hbar_flags != ELM_SMART_SCROLLER_POLICY_OFF)
2326           {
2327              if (sd->hbar_visible)
2328                edje_object_signal_emit(sd->edje_obj, "elm,action,show,hbar", "elm");
2329              else
2330                edje_object_signal_emit(sd->edje_obj, "elm,action,hide,hbar", "elm");
2331              edje_object_message_signal_process(sd->edje_obj);
2332              _smart_scrollbar_size_adjust(sd);
2333           }
2334         else
2335           edje_object_signal_emit(sd->edje_obj, "elm,action,hide,hbar", "elm");
2336         _smart_scrollbar_size_adjust(sd);
2337      }
2338    return scroll_h_vis_change;
2339 }
2340
2341 static void
2342 _smart_scrollbar_bar_visibility_adjust(Smart_Data *sd)
2343 {
2344    int changed = 0;
2345
2346    changed |= _smart_scrollbar_bar_h_visibility_adjust(sd);
2347    changed |= _smart_scrollbar_bar_v_visibility_adjust(sd);
2348    if (changed)
2349      {
2350         _smart_scrollbar_bar_h_visibility_adjust(sd);
2351         _smart_scrollbar_bar_v_visibility_adjust(sd);
2352      }
2353 }
2354
2355 static void
2356 _smart_scrollbar_size_adjust(Smart_Data *sd)
2357 {
2358    if ((sd->child_obj) || (sd->extern_pan))
2359      {
2360         Evas_Coord x, y, w, h, mx = 0, my = 0, vw = 0, vh = 0, px, py, minx = 0, miny = 0;
2361         double vx, vy, size;
2362
2363         edje_object_part_geometry_get(sd->edje_obj, "elm.swallow.content",
2364                                       NULL, NULL, &vw, &vh);
2365         w = sd->child.w;
2366         if (w < 1) w = 1;
2367         size = (double)vw / (double)w;
2368         if (size > 1.0)
2369           {
2370              size = 1.0;
2371              edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.hbar", 0.0, 0.0);
2372           }
2373         edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.hbar", size, 1.0);
2374
2375         h = sd->child.h;
2376         if (h < 1) h = 1;
2377         size = (double)vh / (double)h;
2378         if (size > 1.0)
2379           {
2380              size = 1.0;
2381              edje_object_part_drag_value_set(sd->edje_obj, "elm.dragable.vbar", 0.0, 0.0);
2382           }
2383         edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.vbar", 1.0, size);
2384
2385         edje_object_part_drag_value_get(sd->edje_obj, "elm.dragable.hbar", &vx, NULL);
2386         edje_object_part_drag_value_get(sd->edje_obj, "elm.dragable.vbar", NULL, &vy);
2387         sd->pan_func.max_get(sd->pan_obj, &mx, &my);
2388         sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2389         x = vx * mx + minx;
2390         y = vy * my + miny;
2391
2392         edje_object_part_drag_step_set(sd->edje_obj, "elm.dragable.hbar", (double)sd->step.x / (double)w, 0.0);
2393         edje_object_part_drag_step_set(sd->edje_obj, "elm.dragable.vbar", 0.0, (double)sd->step.y / (double)h);
2394         if (sd->page.x > 0)
2395           edje_object_part_drag_page_set(sd->edje_obj, "elm.dragable.hbar", (double)sd->page.x / (double)w, 0.0);
2396         else
2397           edje_object_part_drag_page_set(sd->edje_obj, "elm.dragable.hbar", -((double)sd->page.x * ((double)vw / (double)w)) / 100.0, 0.0);
2398         if (sd->page.y > 0)
2399           edje_object_part_drag_page_set(sd->edje_obj, "elm.dragable.vbar", 0.0, (double)sd->page.y / (double)h);
2400         else
2401           edje_object_part_drag_page_set(sd->edje_obj, "elm.dragable.vbar", 0.0, -((double)sd->page.y * ((double)vh / (double)h)) / 100.0);
2402
2403         sd->pan_func.get(sd->pan_obj, &px, &py);
2404         if (vx != mx) x = px;
2405         if (vy != my) y = py;
2406         sd->pan_func.set(sd->pan_obj, x, y);
2407 //      if ((px != 0) || (py != 0))
2408 //        edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
2409      }
2410    else
2411      {
2412         Evas_Coord px = 0, py = 0, minx = 0, miny = 0;
2413
2414         edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.vbar", 1.0, 1.0);
2415         edje_object_part_drag_size_set(sd->edje_obj, "elm.dragable.hbar", 1.0, 1.0);
2416         sd->pan_func.min_get(sd->pan_obj, &minx, &miny);
2417         sd->pan_func.get(sd->pan_obj, &px, &py);
2418         sd->pan_func.set(sd->pan_obj, minx, miny);
2419         if ((px != minx) || (py != miny))
2420           edje_object_signal_emit(sd->edje_obj, "elm,action,scroll", "elm");
2421      }
2422    _smart_scrollbar_bar_visibility_adjust(sd);
2423 }
2424
2425 static void
2426 _smart_reconfigure(Smart_Data *sd)
2427 {
2428    evas_object_move(sd->edje_obj, sd->x, sd->y);
2429    evas_object_resize(sd->edje_obj, sd->w, sd->h);
2430    evas_object_move(sd->event_obj, sd->x, sd->y);
2431    evas_object_resize(sd->event_obj, sd->w, sd->h);
2432    _smart_scrollbar_size_adjust(sd);
2433 }
2434
2435 static void
2436 _smart_add(Evas_Object *obj)
2437 {
2438    Smart_Data *sd;
2439    Evas_Object *o;
2440
2441    sd = calloc(1, sizeof(Smart_Data));
2442    if (!sd) return;
2443    evas_object_smart_data_set(obj, sd);
2444
2445    sd->smart_obj = obj;
2446    sd->x = 0;
2447    sd->y = 0;
2448    sd->w = 0;
2449    sd->h = 0;
2450    sd->step.x = 32;
2451    sd->step.y = 32;
2452    sd->page.x = -50;
2453    sd->page.y = -50;
2454    sd->hbar_flags = ELM_SMART_SCROLLER_POLICY_AUTO;
2455    sd->vbar_flags = ELM_SMART_SCROLLER_POLICY_AUTO;
2456    sd->hbar_visible = 1;
2457    sd->vbar_visible = 1;
2458
2459    sd->bounce_horiz = 1;
2460    sd->bounce_vert = 1;
2461
2462    sd->one_dir_at_a_time = 1;
2463    sd->momentum_animator_disabled = 0;
2464    sd->bounce_animator_disabled = 0;
2465    
2466    o = edje_object_add(evas_object_evas_get(obj));
2467    evas_object_propagate_events_set(o, 0);
2468    sd->edje_obj = o;
2469    // FIXME: null parent obj ... :(
2470    elm_smart_scroller_object_theme_set(NULL, obj, "scroller", "base", "default");
2471    edje_object_signal_callback_add(o, "drag", "elm.dragable.vbar", _smart_edje_drag_v, sd);
2472    edje_object_signal_callback_add(o, "drag,start", "elm.dragable.vbar", _smart_edje_drag_v_start, sd);
2473    edje_object_signal_callback_add(o, "drag,stop", "elm.dragable.vbar", _smart_edje_drag_v_stop, sd);
2474    edje_object_signal_callback_add(o, "drag,step", "elm.dragable.vbar", _smart_edje_drag_v, sd);
2475    edje_object_signal_callback_add(o, "drag,page", "elm.dragable.vbar", _smart_edje_drag_v, sd);
2476    edje_object_signal_callback_add(o, "drag", "elm.dragable.hbar", _smart_edje_drag_h, sd);
2477    edje_object_signal_callback_add(o, "drag,start", "elm.dragable.hbar", _smart_edje_drag_h_start, sd);
2478    edje_object_signal_callback_add(o, "drag,stop", "elm.dragable.hbar", _smart_edje_drag_h_stop, sd);
2479    edje_object_signal_callback_add(o, "drag,step", "elm.dragable.hbar", _smart_edje_drag_h, sd);
2480    edje_object_signal_callback_add(o, "drag,page", "elm.dragable.hbar", _smart_edje_drag_h, sd);
2481    evas_object_smart_member_add(o, obj);
2482
2483    o = evas_object_rectangle_add(evas_object_evas_get(obj));
2484    sd->event_obj = o;
2485    evas_object_color_set(o, 0, 0, 0, 0);
2486    evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_WHEEL, _smart_event_wheel, sd);
2487    evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, _smart_event_mouse_down, sd);
2488    evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_UP, _smart_event_mouse_up, sd);
2489    evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_MOVE, _smart_event_mouse_move, sd);
2490    evas_object_smart_member_add(o, obj);
2491    evas_object_repeat_events_set(o, 1);
2492
2493    sd->pan_func.set = _elm_smart_pan_set;
2494    sd->pan_func.get = _elm_smart_pan_get;
2495    sd->pan_func.max_get = _elm_smart_pan_max_get;
2496    sd->pan_func.min_get = _elm_smart_pan_min_get;
2497    sd->pan_func.child_size_get = _elm_smart_pan_child_size_get;
2498
2499    _smart_scrollbar_reset(sd);
2500 }
2501
2502 static void
2503 _smart_del(Evas_Object *obj)
2504 {
2505    INTERNAL_ENTRY;
2506    elm_smart_scroller_child_set(obj, NULL);
2507    if (!sd->extern_pan) evas_object_del(sd->pan_obj);
2508    evas_object_del(sd->edje_obj);
2509    evas_object_del(sd->event_obj);
2510    if (sd->down.hold_animator) ecore_animator_del(sd->down.hold_animator);
2511    if (sd->down.onhold_animator) ecore_animator_del(sd->down.onhold_animator);
2512    if (sd->down.momentum_animator) ecore_animator_del(sd->down.momentum_animator);
2513    if (sd->down.bounce_x_animator) ecore_animator_del(sd->down.bounce_x_animator);
2514    if (sd->down.bounce_y_animator) ecore_animator_del(sd->down.bounce_y_animator);
2515    if (sd->scrollto.x.animator) ecore_animator_del(sd->scrollto.x.animator);
2516    if (sd->scrollto.y.animator) ecore_animator_del(sd->scrollto.y.animator);
2517    free(sd);
2518    evas_object_smart_data_set(obj, NULL);
2519 }
2520
2521 static void
2522 _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
2523 {
2524    INTERNAL_ENTRY;
2525    sd->x = x;
2526    sd->y = y;
2527    _smart_reconfigure(sd);
2528 }
2529
2530 static void
2531 _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
2532 {
2533    INTERNAL_ENTRY;
2534    sd->w = w;
2535    sd->h = h;
2536    _smart_reconfigure(sd);
2537    elm_smart_scroller_child_region_set(obj, sd->wx, sd->wy, sd->ww, sd->h);
2538 }
2539
2540 static void
2541 _smart_show(Evas_Object *obj)
2542 {
2543    INTERNAL_ENTRY;
2544    evas_object_show(sd->edje_obj);
2545    evas_object_show(sd->event_obj);
2546 }
2547
2548 static void
2549 _smart_hide(Evas_Object *obj)
2550 {
2551    INTERNAL_ENTRY;
2552    evas_object_hide(sd->edje_obj);
2553    evas_object_hide(sd->event_obj);
2554 }
2555
2556 static void
2557 _smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
2558 {
2559    INTERNAL_ENTRY;
2560    evas_object_color_set(sd->edje_obj, r, g, b, a);
2561 }
2562
2563 static void
2564 _smart_clip_set(Evas_Object *obj, Evas_Object *clip)
2565 {
2566    INTERNAL_ENTRY;
2567    evas_object_clip_set(sd->edje_obj, clip);
2568    evas_object_clip_set(sd->event_obj, clip);
2569 }
2570
2571 static void
2572 _smart_clip_unset(Evas_Object *obj)
2573 {
2574    INTERNAL_ENTRY;
2575    evas_object_clip_unset(sd->edje_obj);
2576    evas_object_clip_unset(sd->event_obj);
2577 }
2578
2579 /* never need to touch this */
2580
2581 static void
2582 _smart_init(void)
2583 {
2584    if (_smart) return;
2585      {
2586         static const Evas_Smart_Class sc =
2587           {
2588              SMART_NAME,
2589                EVAS_SMART_CLASS_VERSION,
2590                _smart_add,
2591                _smart_del,
2592                _smart_move,
2593                _smart_resize,
2594                _smart_show,
2595                _smart_hide,
2596                _smart_color_set,
2597                _smart_clip_set,
2598                _smart_clip_unset,
2599                NULL,
2600                NULL,
2601                NULL,
2602                NULL,
2603                NULL,
2604                NULL,
2605                NULL
2606           };
2607         _smart = evas_smart_class_new(&sc);
2608      }
2609 }
2610