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