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