elementary/elm_scroller : Modified event_hook function. Now arrow keys
[framework/uifw/elementary.git] / src / lib / elm_scroller.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3 #include "els_scroller.h"
4
5 typedef struct _Widget_Data Widget_Data;
6
7 struct _Widget_Data
8 {
9    Evas_Object *scr;
10    Evas_Object *content;
11    const char *widget_name, *widget_base;
12    Eina_Bool min_w : 1;
13    Eina_Bool min_h : 1;
14    double pagerel_h, pagerel_v;
15    Evas_Coord pagesize_h, pagesize_v;
16 };
17
18 static const char *widtype = NULL;
19 static void _del_hook(Evas_Object *obj);
20 static void _theme_hook(Evas_Object *obj);
21 static void _show_region_hook(void *data, Evas_Object *obj);
22 static void _sizing_eval(Evas_Object *obj);
23 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
24 static void _on_focus_hook(void *data, Evas_Object *obj);
25 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src,
26                              Evas_Callback_Type type, void *event_info);
27
28
29 static const char SIG_SCROLL[] = "scroll";
30 static const char SIG_SCROLL_ANIM_START[] = "scroll,anim,start";
31 static const char SIG_SCROLL_ANIM_STOP[] = "scroll,anim,stop";
32 static const char SIG_SCROLL_DRAG_START[] = "scroll,drag,start";
33 static const char SIG_SCROLL_DRAG_STOP[] = "scroll,drag,stop";
34 static const char SIG_EDGE_LEFT[] = "edge,left";
35 static const char SIG_EDGE_RIGHT[] = "edge,right";
36 static const char SIG_EDGE_TOP[] = "edge,top";
37 static const char SIG_EDGE_BOTTOM[] = "edge,bottom";
38 static const Evas_Smart_Cb_Description _signals[] = {
39   {SIG_SCROLL, ""},
40   {SIG_SCROLL_ANIM_START, ""},
41   {SIG_SCROLL_ANIM_STOP, ""},
42   {SIG_SCROLL_DRAG_START, ""},
43   {SIG_SCROLL_DRAG_STOP, ""},
44   {SIG_EDGE_LEFT, ""},
45   {SIG_EDGE_RIGHT, ""},
46   {SIG_EDGE_TOP, ""},
47   {SIG_EDGE_BOTTOM, ""},
48   {NULL, NULL}
49 };
50
51 static Eina_Bool
52 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
53 {
54    if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
55    Evas_Event_Key_Down *ev = event_info;
56    Widget_Data *wd = elm_widget_data_get(obj);
57
58    if (!wd) return EINA_FALSE;
59    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
60    if (elm_widget_disabled_get(obj)) return EINA_FALSE;
61
62    Evas_Coord x = 0;
63    Evas_Coord y = 0;
64    Evas_Coord step_x = 0;
65    Evas_Coord step_y = 0;
66    Evas_Coord max_x = 0;
67    Evas_Coord max_y = 0;
68    Evas_Coord v_w = 0;
69    Evas_Coord v_h = 0;
70    Evas_Coord page_x = 0;
71    Evas_Coord page_y = 0;
72    Evas_Coord c_x = 0;
73    Evas_Coord c_y = 0;
74
75    elm_smart_scroller_child_pos_get(wd->scr, &x, &y);
76    elm_smart_scroller_step_size_get(wd->scr, &step_x, &step_y);
77    elm_smart_scroller_page_size_get(wd->scr, &page_x, &page_y);
78    elm_smart_scroller_child_viewport_size_get(wd->scr, &v_w, &v_h);
79    evas_object_geometry_get(wd->content, &c_x, &c_y, &max_x, &max_y);
80
81    if ((!strcmp(ev->keyname, "Left")) ||
82        (!strcmp(ev->keyname, "KP_Left")) ||
83        (!strcmp(ev->keyname, "Right")) ||
84        (!strcmp(ev->keyname, "KP_Right")) ||
85        (!strcmp(ev->keyname, "Up"))  ||
86        (!strcmp(ev->keyname, "KP_Up")) ||
87        (!strcmp(ev->keyname, "Down")) ||
88        (!strcmp(ev->keyname, "KP_Down")))
89      {
90         Evas_Object *current_focus = NULL;
91         Evas_Object *new_focus = NULL;
92         Eina_List *can_focus_list = NULL;
93         Evas_Coord f_x = 0;
94         Evas_Coord f_y = 0;
95         Evas_Coord f_w = 0;
96         Evas_Coord f_h = 0;
97
98         current_focus = elm_widget_focused_object_get(obj);
99         evas_object_geometry_get(current_focus, &f_x, &f_y, &f_w, &f_h);
100         can_focus_list = elm_widget_can_focus_child_list_get(obj);
101         if ((current_focus == obj) ||
102             (!ELM_RECTS_INTERSECT(x, y, v_w, v_h,
103                                   (f_x - c_x), (f_y - c_y), f_w, f_h)))
104           {
105              Evas_Object *cur;
106              Eina_List *l;
107              double weight = 0.0;
108
109              EINA_LIST_FOREACH(can_focus_list, l, cur)
110                {
111                   double cur_weight = 0.0;
112                   evas_object_geometry_get(cur, &f_x, &f_y, &f_w, &f_h);
113                   if (ELM_RECTS_INTERSECT(x, y, v_w, v_h,
114                                           (f_x - c_x), (f_y - c_y), f_w, f_h))
115                     {
116                        if ((f_x - c_x) > x)
117                          cur_weight += ((f_x - c_x) - x) * ((f_x - c_x) - x);
118                        if ((f_y - c_y) > y)
119                          cur_weight += ((f_y - c_y) - y) * ((f_y - c_y) - y);
120                        if (cur_weight == 0.0)
121                          {
122                             elm_widget_focus_steal(cur);
123                             return EINA_TRUE;
124                          }
125                        cur_weight = 1.0 / cur_weight;
126                        if (cur_weight > weight)
127                          {
128                             new_focus = cur;
129                             weight = cur_weight;
130                          }
131                     }
132                }
133              if (new_focus)
134                {
135                   elm_widget_focus_steal(new_focus);
136                   return EINA_TRUE;
137                }
138           }
139         else
140           {
141              Evas_Object *tmp = NULL;
142              Elm_Focus_Direction dir = ELM_FOCUS_PREVIOUS;
143              void *(*list_data_get) (const Eina_List *list);
144              list_data_get = eina_list_data_get;
145
146              if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")))
147                dir = ELM_FOCUS_LEFT;
148              else if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")))
149                dir = ELM_FOCUS_RIGHT;
150              else if ((!strcmp(ev->keyname, "Up"))  || (!strcmp(ev->keyname, "KP_Up")))
151                dir = ELM_FOCUS_UP;
152              else if ((!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
153                dir = ELM_FOCUS_DOWN;
154
155              if (elm_widget_focus_list_next_get(obj, can_focus_list, list_data_get, dir, &tmp))
156                new_focus = tmp;
157
158              if (new_focus)
159                {
160                   Evas_Coord l_x = 0;
161                   Evas_Coord l_y = 0;
162                   Evas_Coord l_w = 0;
163                   Evas_Coord l_h = 0;
164
165                   evas_object_geometry_get(new_focus, &f_x, &f_y, &f_w, &f_h);
166                   l_x = f_x - c_x - step_x;
167                   l_y = f_y - c_y - step_y;
168                   l_w = f_w + (step_x * 2);
169                   l_h = f_h + (step_y * 2);
170                   if (ELM_RECTS_INTERSECT(x, y, v_w, v_h, l_x, l_y, l_w, l_h))
171                       {
172                        elm_widget_focus_steal(new_focus);
173                        return EINA_TRUE;
174                     }
175                }
176           }
177      }
178
179    if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")))
180      {
181         if (x <= 0) return EINA_FALSE;
182         x -= step_x;
183      }
184    else if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")))
185      {
186         if (x >= (max_x - v_w)) return EINA_FALSE;
187         x += step_x;
188      }
189    else if ((!strcmp(ev->keyname, "Up"))  || (!strcmp(ev->keyname, "KP_Up")))
190      {
191         if (y == 0) return EINA_FALSE;
192         y -= step_y;
193      }
194    else if ((!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
195      {
196         if (y >= (max_y - v_h)) return EINA_FALSE;
197         y += step_y;
198      }
199    else if ((!strcmp(ev->keyname, "Home")) || (!strcmp(ev->keyname, "KP_Home")))
200      {
201         y = 0;
202      }
203    else if ((!strcmp(ev->keyname, "End")) || (!strcmp(ev->keyname, "KP_End")))
204      {
205         y = max_y - v_h;
206      }
207    else if ((!strcmp(ev->keyname, "Prior")) || (!strcmp(ev->keyname, "KP_Prior")))
208      {
209         if (page_y < 0)
210           y -= -(page_y * v_h) / 100;
211         else
212           y -= page_y;
213      }
214    else if ((!strcmp(ev->keyname, "Next")) || (!strcmp(ev->keyname, "KP_Next")))
215      {
216         if (page_y < 0)
217           y += -(page_y * v_h) / 100;
218         else
219           y += page_y;
220      }
221    else return EINA_FALSE;
222
223    ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
224    elm_smart_scroller_child_pos_set(wd->scr, x, y);
225    return EINA_TRUE;
226 }
227
228 static void
229 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
230 {
231    Widget_Data *wd = elm_widget_data_get(obj);
232    if (!wd) return;
233    if (elm_widget_focus_get(obj))
234      {
235         edje_object_signal_emit(wd->scr, "elm,action,focus", "elm");
236         evas_object_focus_set(wd->scr, EINA_TRUE);
237      }
238    else
239      {
240         edje_object_signal_emit(wd->scr, "elm,action,unfocus", "elm");
241         evas_object_focus_set(wd->scr, EINA_FALSE);
242      }
243 }
244
245 static void
246 _del_hook(Evas_Object *obj)
247 {
248    Widget_Data *wd = elm_widget_data_get(obj);
249    if (!wd) return;
250    free(wd);
251 }
252
253 static void
254 _mirrored_set(Evas_Object *obj, Eina_Bool mirrored)
255 {
256    Widget_Data *wd = elm_widget_data_get(obj);
257    if (!wd) return;
258    if (wd->scr)
259      elm_smart_scroller_mirrored_set(wd->scr, mirrored);
260 }
261
262 static void
263 _theme_hook(Evas_Object *obj)
264 {
265    Widget_Data *wd = elm_widget_data_get(obj);
266    if (!wd) return;
267    _elm_widget_mirrored_reload(obj);
268    if (wd->scr)
269      {
270         Evas_Object *edj;
271         const char *str;
272
273         _mirrored_set(obj, elm_widget_mirrored_get(obj));
274         elm_smart_scroller_object_theme_set(obj, wd->scr,
275                                             wd->widget_name, wd->widget_base,
276                                             elm_widget_style_get(obj));
277         //        edje_object_scale_set(wd->scr, elm_widget_scale_get(obj) * _elm_config->scale);
278         edj = elm_smart_scroller_edje_object_get(wd->scr);
279         str = edje_object_data_get(edj, "focus_highlight");
280         if ((str) && (!strcmp(str, "on")))
281           elm_widget_highlight_in_theme_set(obj, EINA_TRUE);
282         else
283           elm_widget_highlight_in_theme_set(obj, EINA_FALSE);
284      }
285    _sizing_eval(obj);
286 }
287
288 static Eina_Bool
289 _elm_scroller_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
290 {
291    Widget_Data *wd = elm_widget_data_get(obj);
292    Evas_Object *cur;
293
294    if ((!wd) || (!wd->content))
295      return EINA_FALSE;
296
297    cur = wd->content;
298
299    /* Try Focus cycle in subitem */
300    if ((elm_widget_can_focus_get(cur)) || (elm_widget_child_can_focus_get(cur)))
301      return elm_widget_focus_next_get(cur, dir, next);
302
303    /* Return */
304    *next = (Evas_Object *)obj;
305    return !elm_widget_focus_get(obj);
306 }
307
308 static void
309 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
310 {
311    Widget_Data *wd = elm_widget_data_get(obj);
312    if (!wd) return;
313    edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
314                            emission, source);
315 }
316
317 static void
318 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
319 {
320    Widget_Data *wd = elm_widget_data_get(obj);
321    if (!wd) return;
322    edje_object_signal_callback_add(elm_smart_scroller_edje_object_get(wd->scr),
323                                    emission, source, func_cb, data);
324 }
325
326 static void
327 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
328 {
329    Widget_Data *wd = elm_widget_data_get(obj);
330    edje_object_signal_callback_del_full(
331       elm_smart_scroller_edje_object_get(wd->scr), emission, source,
332       func_cb, data);
333 }
334
335 static void
336 _show_region_hook(void *data, Evas_Object *obj)
337 {
338    Widget_Data *wd = elm_widget_data_get(data);
339    Evas_Coord x, y, w, h;
340    if (!wd) return;
341    elm_widget_show_region_get(obj, &x, &y, &w, &h);
342    if (wd->scr)
343      elm_smart_scroller_child_region_show(wd->scr, x, y, w, h);
344 }
345
346 static void
347 _focus_region_hook(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
348 {
349    Widget_Data *wd = elm_widget_data_get(obj);
350    if (wd->scr)
351      elm_smart_scroller_child_region_show(wd->scr, x, y, w, h);
352 }
353
354 static void
355 _sizing_eval(Evas_Object *obj)
356 {
357    Widget_Data *wd = elm_widget_data_get(obj);
358    Evas_Coord  vw, vh, minw = 0, minh = 0, maxw = 0, maxh = 0, w, h, vmw, vmh;
359    double xw = 0.0, yw = 0.0;
360
361    if (!wd) return;
362    if (wd->content)
363      {
364         evas_object_size_hint_min_get(wd->content, &minw, &minh);
365         evas_object_size_hint_max_get(wd->content, &maxw, &maxh);
366         evas_object_size_hint_weight_get(wd->content, &xw, &yw);
367      }
368    if (wd->scr)
369      {
370         elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
371         if (xw > 0.0)
372           {
373              if ((minw > 0) && (vw < minw)) vw = minw;
374              else if ((maxw > 0) && (vw > maxw)) vw = maxw;
375           }
376         else if (minw > 0) vw = minw;
377         if (yw > 0.0)
378           {
379              if ((minh > 0) && (vh < minh)) vh = minh;
380              else if ((maxh > 0) && (vh > maxh)) vh = maxh;
381           }
382         else if (minh > 0) vh = minh;
383         if (wd->content) evas_object_resize(wd->content, vw, vh);
384         w = -1;
385         h = -1;
386         edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr), &vmw, &vmh);
387         if (wd->min_w) w = vmw + minw;
388         if (wd->min_h) h = vmh + minh;
389         evas_object_size_hint_max_get(obj, &maxw, &maxh);
390         if ((maxw > 0) && (w > maxw)) w = maxw;
391         if ((maxh > 0) && (h > maxh)) h = maxh;
392         evas_object_size_hint_min_set(obj, w, h);
393      }
394 }
395
396 static void
397 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
398 {
399    _sizing_eval(data);
400 }
401
402 static void
403 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
404 {
405    Widget_Data *wd = elm_widget_data_get(obj);
406    Evas_Object *sub = event_info;
407
408    if (!wd) return;
409    if (sub == wd->content)
410      {
411         elm_widget_on_show_region_hook_set(wd->content, NULL, NULL);
412         evas_object_event_callback_del_full (sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
413                                              _changed_size_hints, obj);
414         wd->content = NULL;
415         _sizing_eval(obj);
416      }
417    else if (sub == wd->scr)
418      wd->scr = NULL;
419 }
420
421 static void
422 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
423 {
424    Widget_Data *wd = elm_widget_data_get(obj);
425
426    if (!wd) return;
427    if (wd->scr)
428      elm_smart_scroller_hold_set(wd->scr, 1);
429 }
430
431 static void
432 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
433 {
434    Widget_Data *wd = elm_widget_data_get(obj);
435
436    if (!wd) return;
437    if (wd->scr)
438      elm_smart_scroller_hold_set(wd->scr, 0);
439 }
440
441 static void
442 _freeze_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
443 {
444    Widget_Data *wd = elm_widget_data_get(obj);
445
446    if (!wd) return;
447    if (wd->scr)
448      elm_smart_scroller_freeze_set(wd->scr, 1);
449 }
450
451 static void
452 _freeze_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
453 {
454    Widget_Data *wd = elm_widget_data_get(obj);
455
456    if (!wd) return;
457    if (wd->scr)
458      elm_smart_scroller_freeze_set(wd->scr, 0);
459 }
460
461 static void
462 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
463 {
464    _sizing_eval(data);
465 }
466
467 static void
468 _edge_left(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
469 {
470    evas_object_smart_callback_call(data, SIG_EDGE_LEFT, NULL);
471 }
472
473 static void
474 _edge_right(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
475 {
476    evas_object_smart_callback_call(data, SIG_EDGE_RIGHT, NULL);
477 }
478
479 static void
480 _edge_top(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
481 {
482    evas_object_smart_callback_call(data, SIG_EDGE_TOP, NULL);
483 }
484
485 static void
486 _edge_bottom(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
487 {
488    evas_object_smart_callback_call(data, SIG_EDGE_BOTTOM, NULL);
489 }
490
491 static void
492 _scroll(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
493 {
494    evas_object_smart_callback_call(data, SIG_SCROLL, NULL);
495 }
496
497 static void
498 _scroll_anim_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
499 {
500    evas_object_smart_callback_call(data, SIG_SCROLL_ANIM_START, NULL);
501 }
502
503 static void
504 _scroll_anim_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
505 {
506    evas_object_smart_callback_call(data, SIG_SCROLL_ANIM_STOP, NULL);
507 }
508
509 static void
510 _scroll_drag_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
511 {
512    evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_START, NULL);
513 }
514
515 static void
516 _scroll_drag_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
517 {
518    evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_STOP, NULL);
519 }
520
521 Evas_Object *
522 _elm_scroller_edje_object_get(Evas_Object *obj)
523 {
524    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
525    Widget_Data *wd = elm_widget_data_get(obj);
526    if (!wd) return NULL;
527    return elm_smart_scroller_edje_object_get(wd->scr);
528 }
529
530 static void
531 _content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content)
532 {
533    ELM_CHECK_WIDTYPE(obj, widtype);
534    Widget_Data *wd;
535    if (part && strcmp(part, "default")) return;
536    wd = elm_widget_data_get(obj);
537    if (!wd) return;
538    if (wd->content == content) return;
539    if (wd->content) evas_object_del(wd->content);
540    wd->content = content;
541    if (content)
542      {
543         elm_widget_on_show_region_hook_set(content, _show_region_hook, obj);
544         elm_widget_sub_object_add(obj, content);
545         if (wd->scr)
546           elm_smart_scroller_child_set(wd->scr, content);
547         evas_object_event_callback_add(content,
548                                        EVAS_CALLBACK_CHANGED_SIZE_HINTS,
549                                        _changed_size_hints, obj);
550      }
551    _sizing_eval(obj);
552 }
553
554 static Evas_Object *
555 _content_get_hook(const Evas_Object *obj, const char *part)
556 {
557    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
558    Widget_Data *wd;
559    if (part && strcmp(part, "default")) return NULL;
560    wd = elm_widget_data_get(obj);
561    if (!wd) return NULL;
562    return wd->content;
563 }
564
565 static Evas_Object *
566 _content_unset_hook(Evas_Object *obj, const char *part)
567 {
568    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
569    Widget_Data *wd;
570    Evas_Object *content;
571    if (part && strcmp(part, "default")) return NULL;
572    wd = elm_widget_data_get(obj);
573    if (!wd) return NULL;
574    if (!wd->content) return NULL;
575    content = wd->content;
576    elm_widget_sub_object_del(obj, wd->content);
577    evas_object_event_callback_del_full(wd->content,
578                                        EVAS_CALLBACK_CHANGED_SIZE_HINTS,
579                                        _changed_size_hints, obj);
580    edje_object_part_unswallow(elm_smart_scroller_edje_object_get(wd->scr),
581                               wd->content);
582    wd->content = NULL;
583    return content;
584 }
585
586 EAPI Evas_Object *
587 elm_scroller_add(Evas_Object *parent)
588 {
589    Evas_Object *obj;
590    Evas *e;
591    Widget_Data *wd;
592    Evas_Coord minw, minh;
593
594    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
595
596    ELM_SET_WIDTYPE(widtype, "scroller");
597    elm_widget_type_set(obj, "scroller");
598    elm_widget_sub_object_add(parent, obj);
599    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
600    elm_widget_data_set(obj, wd);
601    elm_widget_del_hook_set(obj, _del_hook);
602    elm_widget_theme_hook_set(obj, _theme_hook);
603    elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
604    elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
605    elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
606    elm_widget_focus_next_hook_set(obj, _elm_scroller_focus_next_hook);
607    elm_widget_can_focus_set(obj, EINA_TRUE);
608    elm_widget_event_hook_set(obj, _event_hook);
609    elm_widget_focus_region_hook_set(obj, _focus_region_hook);
610    elm_widget_content_set_hook_set(obj, _content_set_hook);
611    elm_widget_content_get_hook_set(obj, _content_get_hook);
612    elm_widget_content_unset_hook_set(obj, _content_unset_hook);
613
614    wd->widget_name = eina_stringshare_add("scroller");
615    wd->widget_base = eina_stringshare_add("base");
616
617    wd->scr = elm_smart_scroller_add(e);
618    elm_smart_scroller_widget_set(wd->scr, obj);
619    _theme_hook(obj);
620    elm_widget_resize_object_set(obj, wd->scr);
621    evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
622                                   _changed_size_hints, obj);
623
624    edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr), &minw, &minh);
625    evas_object_size_hint_min_set(obj, minw, minh);
626    evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, obj);
627
628    evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
629    evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
630    evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
631    evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
632    evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
633
634    evas_object_smart_callback_add(wd->scr, "edge,left", _edge_left, obj);
635    evas_object_smart_callback_add(wd->scr, "edge,right", _edge_right, obj);
636    evas_object_smart_callback_add(wd->scr, "edge,top", _edge_top, obj);
637    evas_object_smart_callback_add(wd->scr, "edge,bottom", _edge_bottom, obj);
638    evas_object_smart_callback_add(wd->scr, "scroll", _scroll, obj);
639    evas_object_smart_callback_add(wd->scr, "animate,start", _scroll_anim_start, obj);
640    evas_object_smart_callback_add(wd->scr, "animate,stop", _scroll_anim_stop, obj);
641    evas_object_smart_callback_add(wd->scr, "drag,start", _scroll_drag_start, obj);
642    evas_object_smart_callback_add(wd->scr, "drag,stop", _scroll_drag_stop, obj);
643
644    _sizing_eval(obj);
645
646    // TODO: convert Elementary to subclassing of Evas_Smart_Class
647    // TODO: and save some bytes, making descriptions per-class and not instance!
648    evas_object_smart_callbacks_descriptions_set(obj, _signals);
649    _mirrored_set(obj, elm_widget_mirrored_get(obj));
650    return obj;
651 }
652
653 EAPI void
654 elm_scroller_content_set(Evas_Object *obj, Evas_Object *content)
655 {
656    _content_set_hook(obj, NULL, content);
657 }
658
659 EAPI Evas_Object *
660 elm_scroller_content_get(const Evas_Object *obj)
661 {
662    return _content_get_hook(obj, NULL);
663 }
664
665 EAPI Evas_Object *
666 elm_scroller_content_unset(Evas_Object *obj)
667 {
668    return _content_unset_hook(obj, NULL);
669 }
670
671 EAPI void
672 elm_scroller_custom_widget_base_theme_set(Evas_Object *obj, const char *widget, const char *base)
673 {
674    ELM_CHECK_WIDTYPE(obj, widtype);
675    Widget_Data *wd = elm_widget_data_get(obj);
676    if (!wd) return;
677    EINA_SAFETY_ON_NULL_RETURN(widget);
678    EINA_SAFETY_ON_NULL_RETURN(base);
679    if (eina_stringshare_replace(&wd->widget_name, widget) |
680        eina_stringshare_replace(&wd->widget_base, base))
681      _theme_hook(obj);
682 }
683
684 EAPI void
685 elm_scroller_content_min_limit(Evas_Object *obj, Eina_Bool w, Eina_Bool h)
686 {
687    ELM_CHECK_WIDTYPE(obj, widtype);
688    Widget_Data *wd = elm_widget_data_get(obj);
689    if (!wd) return;
690    wd->min_w = w;
691    wd->min_h = h;
692    _sizing_eval(obj);
693 }
694
695 EAPI void
696 elm_scroller_region_show(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
697 {
698    ELM_CHECK_WIDTYPE(obj, widtype);
699    Widget_Data *wd = elm_widget_data_get(obj);
700    if ((!wd) || (!wd->scr)) return;
701    elm_smart_scroller_child_region_show(wd->scr, x, y, w, h);
702 }
703
704 EAPI void
705 elm_scroller_policy_set(Evas_Object *obj, Elm_Scroller_Policy policy_h, Elm_Scroller_Policy policy_v)
706 {
707    ELM_CHECK_WIDTYPE(obj, widtype);
708    Widget_Data *wd = elm_widget_data_get(obj);
709    const Elm_Scroller_Policy map[3] =
710      {
711         ELM_SMART_SCROLLER_POLICY_AUTO,
712         ELM_SMART_SCROLLER_POLICY_ON,
713         ELM_SMART_SCROLLER_POLICY_OFF
714      };
715    if ((!wd) || (!wd->scr)) return;
716    if ((policy_h >= 3) || (policy_v >= 3)) return;
717    elm_smart_scroller_policy_set(wd->scr, map[policy_h], map[policy_v]);
718 }
719
720 EAPI void
721 elm_scroller_policy_get(const Evas_Object *obj, Elm_Scroller_Policy *policy_h, Elm_Scroller_Policy *policy_v)
722 {
723    ELM_CHECK_WIDTYPE(obj, widtype);
724    Widget_Data *wd = elm_widget_data_get(obj);
725    if ((!wd) || (!wd->scr)) return;
726    elm_smart_scroller_policy_get(wd->scr,
727                                  (Elm_Smart_Scroller_Policy *) policy_h,
728                                  (Elm_Smart_Scroller_Policy *) policy_v);
729 }
730
731 EAPI void
732 elm_scroller_region_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
733 {
734    ELM_CHECK_WIDTYPE(obj, widtype);
735    Widget_Data *wd = elm_widget_data_get(obj);
736    if ((!wd) || (!wd->scr)) return;
737    if ((x) || (y)) elm_smart_scroller_child_pos_get(wd->scr, x, y);
738    if ((w) || (h)) elm_smart_scroller_child_viewport_size_get(wd->scr, w, h);
739 }
740
741 EAPI void
742 elm_scroller_child_size_get(const Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
743 {
744    ELM_CHECK_WIDTYPE(obj, widtype);
745    Widget_Data *wd = elm_widget_data_get(obj);
746    if (!wd) return;
747    evas_object_geometry_get(wd->content, NULL, NULL, w, h);
748 }
749
750 EAPI void
751 elm_scroller_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
752 {
753    ELM_CHECK_WIDTYPE(obj, widtype);
754    Widget_Data *wd = elm_widget_data_get(obj);
755    if ((!wd) || (!wd->scr)) return;
756    elm_smart_scroller_bounce_allow_set(wd->scr, h_bounce, v_bounce);
757 }
758
759 EAPI void
760 elm_scroller_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
761 {
762    ELM_CHECK_WIDTYPE(obj, widtype);
763    Widget_Data *wd = elm_widget_data_get(obj);
764    if (!wd) return;
765    elm_smart_scroller_bounce_allow_get(wd->scr, h_bounce, v_bounce);
766 }
767
768 EAPI void
769 elm_scroller_page_relative_set(Evas_Object *obj, double h_pagerel, double v_pagerel)
770 {
771    ELM_CHECK_WIDTYPE(obj, widtype);
772    Widget_Data *wd = elm_widget_data_get(obj);
773    if (!wd) return;
774    wd->pagerel_h = h_pagerel;
775    wd->pagerel_v = v_pagerel;
776    if (wd->scr)
777      elm_smart_scroller_paging_set(wd->scr, wd->pagerel_h, wd->pagerel_v,
778                                    wd->pagesize_h, wd->pagesize_v);
779 }
780
781 EAPI void
782 elm_scroller_page_size_set(Evas_Object *obj, Evas_Coord h_pagesize, Evas_Coord v_pagesize)
783 {
784    ELM_CHECK_WIDTYPE(obj, widtype);
785    Widget_Data *wd = elm_widget_data_get(obj);
786    if (!wd) return;
787    wd->pagesize_h = h_pagesize;
788    wd->pagesize_v = v_pagesize;
789    if (wd->scr)
790      elm_smart_scroller_paging_set(wd->scr, wd->pagerel_h, wd->pagerel_v,
791                                    wd->pagesize_h, wd->pagesize_v);
792 }
793
794 EAPI void
795 elm_scroller_current_page_get(const Evas_Object *obj, int *h_pagenumber, int *v_pagenumber)
796 {
797    ELM_CHECK_WIDTYPE(obj, widtype);
798    Widget_Data *wd = elm_widget_data_get(obj);
799    if (!wd) return;
800    if (wd->scr)
801      elm_smart_scroller_current_page_get(wd->scr, h_pagenumber, v_pagenumber);
802 }
803
804 EAPI void
805 elm_scroller_last_page_get(const Evas_Object *obj, int *h_pagenumber, int *v_pagenumber)
806 {
807    ELM_CHECK_WIDTYPE(obj, widtype);
808    Widget_Data *wd = elm_widget_data_get(obj);
809    if (!wd) return;
810    if (wd->scr)
811      elm_smart_scroller_last_page_get(wd->scr, h_pagenumber, v_pagenumber);
812 }
813
814 EAPI void
815 elm_scroller_page_show(Evas_Object *obj, int h_pagenumber, int v_pagenumber)
816 {
817    ELM_CHECK_WIDTYPE(obj, widtype);
818    Widget_Data *wd = elm_widget_data_get(obj);
819    if (!wd) return;
820    if (wd->scr)
821      elm_smart_scroller_page_show(wd->scr, h_pagenumber, v_pagenumber);
822 }
823
824 EAPI void
825 elm_scroller_page_bring_in(Evas_Object *obj, int h_pagenumber, int v_pagenumber)
826 {
827    ELM_CHECK_WIDTYPE(obj, widtype);
828    Widget_Data *wd = elm_widget_data_get(obj);
829    if (!wd) return;
830    if (wd->scr)
831      elm_smart_scroller_page_bring_in(wd->scr, h_pagenumber, v_pagenumber);
832 }
833
834 EAPI void
835 elm_scroller_region_bring_in(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
836 {
837    ELM_CHECK_WIDTYPE(obj, widtype);
838    Widget_Data *wd = elm_widget_data_get(obj);
839    if ((!wd) || (!wd->scr)) return;
840    elm_smart_scroller_region_bring_in(wd->scr, x, y, w, h);
841 }
842
843 EAPI void
844 elm_scroller_propagate_events_set(Evas_Object *obj, Eina_Bool propagation)
845 {
846    ELM_CHECK_WIDTYPE(obj, widtype);
847    Widget_Data *wd = elm_widget_data_get(obj);
848    if (!wd) return;
849
850    elm_smart_scroller_propagate_events_set(wd->scr, propagation);
851 }
852
853 EAPI Eina_Bool
854 elm_scroller_propagate_events_get(const Evas_Object *obj)
855 {
856    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
857    Widget_Data *wd = elm_widget_data_get(obj);
858    if (!wd) return EINA_FALSE;
859
860    return elm_smart_scroller_propagate_events_get(wd->scr);
861 }
862
863 EAPI void
864 elm_scroller_gravity_set(Evas_Object *obj, double x, double y)
865 {
866    ELM_CHECK_WIDTYPE(obj, widtype);
867    Widget_Data *wd = elm_widget_data_get(obj);
868    if (!wd) return;
869
870    elm_smart_scroller_gravity_set(wd->scr, x, y);
871 }
872
873 EAPI void
874 elm_scroller_gravity_get(const Evas_Object *obj, double *x, double *y)
875 {
876    ELM_CHECK_WIDTYPE(obj, widtype);
877    Widget_Data *wd = elm_widget_data_get(obj);
878    if (!wd) return;
879
880    elm_smart_scroller_gravity_get(wd->scr, x, y);
881 }
882
883 EAPI void
884 elm_scroller_page_move_set(Evas_Object *obj, Eina_Bool set)
885 {
886    return ;
887 }