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