Elementary: Added ui-mirroring support for all the widgets.
[framework/uifw/elementary.git] / src / lib / elm_scroller.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3
4 /**
5  * @defgroup Scroller Scroller
6  *
7  * A scroller holds a single object and "scrolls it around". This means that
8  * it allows the user to use a scrollbar (or a finger) to drag the viewable
9  * region around, allowing to move through a much larger object that is
10  * contained in the scroller. The scroiller will always have a small minimum
11  * size by default as it won't be limited by the contents of the scroller.
12  *
13  * Signals that you can add callbacks for are:
14  *
15  * edge,left - the left edge of the content has been reached
16  *
17  * edge,right - the right edge of the content has been reached
18  *
19  * edge,top - the top edge of the content has been reached
20  *
21  * edge,bottom - the bottom edge of the content has been reached
22  *
23  * scroll - the content has been scrolled (moved)
24  *
25  * scroll,anim,start - scrolling animation has started
26  *
27  * scroll,anim,stop - scrolling animation has stopped
28  *
29  * scroll,drag,start - dragging the contents around has started
30  *
31  * scroll,drag,stop - dragging the contents around has stopped
32  */
33 typedef struct _Widget_Data Widget_Data;
34
35 struct _Widget_Data
36 {
37    Evas_Object *scr;
38    Evas_Object *content;
39    const char *widget_name, *widget_base;
40    Eina_Bool min_w : 1;
41    Eina_Bool min_h : 1;
42    double pagerel_h, pagerel_v;
43    Evas_Coord pagesize_h, pagesize_v;
44 };
45
46 static const char *widtype = NULL;
47 static void _del_hook(Evas_Object *obj);
48 static void _theme_hook(Evas_Object *obj);
49 static void _show_region_hook(void *data, Evas_Object *obj);
50 static void _sizing_eval(Evas_Object *obj);
51 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
52 static void _on_focus_hook(void *data, Evas_Object *obj);
53 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src,
54                              Evas_Callback_Type type, void *event_info);
55
56
57 static const char SIG_SCROLL[] = "scroll";
58 static const char SIG_SCROLL_ANIM_START[] = "scroll,anim,start";
59 static const char SIG_SCROLL_ANIM_STOP[] = "scroll,anim,stop";
60 static const char SIG_SCROLL_DRAG_START[] = "scroll,drag,start";
61 static const char SIG_SCROLL_DRAG_STOP[] = "scroll,drag,stop";
62 static const char SIG_EDGE_LEFT[] = "edge,left";
63 static const char SIG_EDGE_RIGHT[] = "edge,right";
64 static const char SIG_EDGE_TOP[] = "edge,top";
65 static const char SIG_EDGE_BOTTOM[] = "edge,bottom";
66 static const Evas_Smart_Cb_Description _signals[] = {
67   {SIG_SCROLL, ""},
68   {SIG_SCROLL_ANIM_START, ""},
69   {SIG_SCROLL_ANIM_STOP, ""},
70   {SIG_SCROLL_DRAG_START, ""},
71   {SIG_SCROLL_DRAG_STOP, ""},
72   {SIG_EDGE_LEFT, ""},
73   {SIG_EDGE_RIGHT, ""},
74   {SIG_EDGE_TOP, ""},
75   {SIG_EDGE_BOTTOM, ""},
76   {NULL, NULL}
77 };
78
79 static Eina_Bool
80 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
81 {
82    if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
83    Evas_Event_Key_Down *ev = event_info;
84    Widget_Data *wd = elm_widget_data_get(obj);
85    if (!wd) return EINA_FALSE;
86    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
87    if (elm_widget_disabled_get(obj)) return EINA_FALSE;
88
89    Evas_Coord x = 0;
90    Evas_Coord y = 0;
91    Evas_Coord step_x = 0;
92    Evas_Coord step_y = 0;
93    Evas_Coord max_x = 0;
94    Evas_Coord max_y = 0;
95    Evas_Coord v_w = 0;
96    Evas_Coord v_h = 0;
97    Evas_Coord page_x = 0;
98    Evas_Coord page_y = 0;
99
100    elm_smart_scroller_child_pos_get(wd->scr, &x, &y);
101    elm_smart_scroller_step_size_get(wd->scr, &step_x, &step_y);
102    elm_smart_scroller_page_size_get(wd->scr, &page_x, &page_y);
103    elm_smart_scroller_child_viewport_size_get(wd->scr, &v_w, &v_h);
104    elm_scroller_child_size_get(obj, &max_x, &max_y);
105
106    if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")))
107      {
108         x -= step_x;
109      }
110    else if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")))
111      {
112         x += step_x;
113      }
114    else if ((!strcmp(ev->keyname, "Up"))  || (!strcmp(ev->keyname, "KP_Up")))
115      {
116         y -= step_y;
117      }
118    else if ((!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
119      {
120         y += step_y;
121      }
122    else if ((!strcmp(ev->keyname, "Home")) || (!strcmp(ev->keyname, "KP_Home")))
123      {
124         y = 0;
125      }
126    else if ((!strcmp(ev->keyname, "End")) || (!strcmp(ev->keyname, "KP_End")))
127      {
128         y = max_y - v_h;
129      }
130    else if ((!strcmp(ev->keyname, "Prior")) || (!strcmp(ev->keyname, "KP_Prior")))
131      {
132         if (page_y < 0)
133           y -= -(page_y * v_h) / 100;
134         else
135            y -= page_y;
136      }
137    else if ((!strcmp(ev->keyname, "Next")) || (!strcmp(ev->keyname, "KP_Next")))
138      {
139         if (page_y < 0)
140           y += -(page_y * v_h) / 100;
141         else
142           y += page_y;
143      }
144    else return EINA_FALSE;
145
146    ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
147    elm_smart_scroller_child_pos_set(wd->scr, x, y);
148    return EINA_TRUE;
149 }
150
151 static void
152 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
153 {
154    Widget_Data *wd = elm_widget_data_get(obj);
155    if (!wd) return;
156    if (elm_widget_focus_get(obj))
157      {
158         edje_object_signal_emit(wd->scr, "elm,action,focus", "elm");
159         evas_object_focus_set(wd->scr, EINA_TRUE);
160      }
161    else
162      {
163         edje_object_signal_emit(wd->scr, "elm,action,unfocus", "elm");
164         evas_object_focus_set(wd->scr, EINA_FALSE);
165      }
166 }
167
168 static void
169 _del_hook(Evas_Object *obj)
170 {
171    Widget_Data *wd = elm_widget_data_get(obj);
172    if (!wd) return;
173    free(wd);
174 }
175
176 static void
177 _mirrored_set(Evas_Object *obj, Eina_Bool mirrored)
178 {
179    Widget_Data *wd = elm_widget_data_get(obj);
180    if (!wd) return;
181    if (wd->scr)
182      elm_smart_scroller_mirrored_set(wd->scr, mirrored);
183 }
184
185 static void
186 _theme_hook(Evas_Object *obj)
187 {
188    Widget_Data *wd = elm_widget_data_get(obj);
189    if (!wd) return;
190    if (wd->scr)
191      {
192         Evas_Object *edj;
193         const char *str;
194
195         _mirrored_set(obj, elm_widget_mirrored_get(obj));
196         elm_smart_scroller_object_theme_set(obj, wd->scr, 
197                                             wd->widget_name, wd->widget_base,
198                                             elm_widget_style_get(obj));
199 //        edje_object_scale_set(wd->scr, elm_widget_scale_get(obj) * _elm_config->scale);
200         edj = elm_smart_scroller_edje_object_get(wd->scr);
201         str = edje_object_data_get(edj, "focus_highlight");
202         if ((str) && (!strcmp(str, "on")))
203           elm_widget_highlight_in_theme_set(obj, EINA_TRUE);
204         else
205           elm_widget_highlight_in_theme_set(obj, EINA_FALSE);
206      }
207    _sizing_eval(obj);
208 }
209
210 static Eina_Bool
211 _elm_scroller_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
212 {
213    Widget_Data *wd = elm_widget_data_get(obj);
214    Evas_Object *cur;
215
216    if ((!wd) || (!wd->content))
217      return EINA_FALSE;
218
219    cur = wd->content;
220
221    /* Try Focus cycle in subitem */
222    if ((elm_widget_can_focus_get(cur)) || (elm_widget_child_can_focus_get(cur)))
223       return elm_widget_focus_next_get(cur, dir, next);
224
225    /* Return */
226    *next = (Evas_Object *)obj;
227    return !elm_widget_focus_get(obj);
228 }
229
230 static void
231 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
232 {
233    Widget_Data *wd = elm_widget_data_get(obj);
234    if (!wd) return;
235    edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
236          emission, source);
237 }
238
239 static void
240 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, void (*func_cb) (void *data, Evas_Object *o, const char *emission, const char *source), void *data)
241 {
242    Widget_Data *wd = elm_widget_data_get(obj);
243    if (!wd) return;
244    edje_object_signal_callback_add(elm_smart_scroller_edje_object_get(wd->scr),
245          emission, source, func_cb, data);
246 }
247
248 static void
249 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, void (*func_cb) (void *data, Evas_Object *o, const char *emission, const char *source), void *data)
250 {
251    Widget_Data *wd = elm_widget_data_get(obj);
252    edje_object_signal_callback_del_full(
253          elm_smart_scroller_edje_object_get(wd->scr), emission, source,
254          func_cb, data);
255 }
256
257 static void
258 _show_region_hook(void *data, Evas_Object *obj)
259 {
260    Widget_Data *wd = elm_widget_data_get(data);
261    Evas_Coord x, y, w, h;
262    if (!wd) return;
263    elm_widget_show_region_get(obj, &x, &y, &w, &h);
264    if (wd->scr)
265      elm_smart_scroller_child_region_show(wd->scr, x, y, w, h);
266 }
267
268 static void
269 _focus_region_hook(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
270 {
271    Widget_Data *wd = elm_widget_data_get(obj);
272    if (wd->scr)
273      elm_smart_scroller_child_region_show(wd->scr, x, y, w, h);
274 }
275
276 static void
277 _sizing_eval(Evas_Object *obj)
278 {
279    Widget_Data *wd = elm_widget_data_get(obj);
280    Evas_Coord  vw, vh, minw, minh, maxw, maxh, w, h, vmw, vmh;
281    double xw, yw;
282
283    if (!wd) return;
284    evas_object_size_hint_min_get(wd->content, &minw, &minh);
285    evas_object_size_hint_max_get(wd->content, &maxw, &maxh);
286    evas_object_size_hint_weight_get(wd->content, &xw, &yw);
287    if (wd->scr)
288      {
289         elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
290         if (xw > 0.0)
291           {
292              if ((minw > 0) && (vw < minw)) vw = minw;
293              else if ((maxw > 0) && (vw > maxw)) vw = maxw;
294           }
295         else if (minw > 0) vw = minw;
296         if (yw > 0.0)
297           {
298              if ((minh > 0) && (vh < minh)) vh = minh;
299              else if ((maxh > 0) && (vh > maxh)) vh = maxh;
300           }
301         else if (minh > 0) vh = minh;
302         evas_object_resize(wd->content, vw, vh);
303         w = -1;
304         h = -1;
305         edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr), &vmw, &vmh);
306         if (wd->min_w) w = vmw + minw;
307         if (wd->min_h) h = vmh + minh;
308         evas_object_size_hint_max_get(obj, &maxw, &maxh);
309         if ((maxw > 0) && (w > maxw)) w = maxw;
310         if ((maxh > 0) && (h > maxh)) h = maxh;
311         evas_object_size_hint_min_set(obj, w, h);
312      }
313 }
314
315 static void
316 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
317 {
318    _sizing_eval(data);
319 }
320
321 static void
322 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
323 {
324    Widget_Data *wd = elm_widget_data_get(obj);
325    Evas_Object *sub = event_info;
326
327    if (!wd) return;
328    if (sub == wd->content)
329      {
330         elm_widget_on_show_region_hook_set(wd->content, NULL, NULL);
331         evas_object_event_callback_del_full (sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
332            _changed_size_hints, obj);
333         wd->content = NULL;
334         _sizing_eval(obj);
335      }
336    else if (sub == wd->scr)
337      wd->scr = NULL;
338 }
339
340 static void
341 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
342 {
343    Widget_Data *wd = elm_widget_data_get(obj);
344
345    if (!wd) return;
346    if (wd->scr)
347      elm_smart_scroller_hold_set(wd->scr, 1);
348 }
349
350 static void
351 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
352 {
353    Widget_Data *wd = elm_widget_data_get(obj);
354
355    if (!wd) return;
356    if (wd->scr)
357      elm_smart_scroller_hold_set(wd->scr, 0);
358 }
359
360 static void
361 _freeze_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
362 {
363    Widget_Data *wd = elm_widget_data_get(obj);
364
365    if (!wd) return;
366    if (wd->scr)
367      elm_smart_scroller_freeze_set(wd->scr, 1);
368 }
369
370 static void
371 _freeze_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
372 {
373    Widget_Data *wd = elm_widget_data_get(obj);
374
375    if (!wd) return;
376    if (wd->scr)
377      elm_smart_scroller_freeze_set(wd->scr, 0);
378 }
379
380 static void
381 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
382 {
383    _sizing_eval(data);
384 }
385
386 static void
387 _edge_left(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
388 {
389    evas_object_smart_callback_call(data, SIG_EDGE_LEFT, NULL);
390 }
391
392 static void
393 _edge_right(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
394 {
395    evas_object_smart_callback_call(data, SIG_EDGE_RIGHT, NULL);
396 }
397
398 static void
399 _edge_top(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
400 {
401    evas_object_smart_callback_call(data, SIG_EDGE_TOP, NULL);
402 }
403
404 static void
405 _edge_bottom(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
406 {
407    evas_object_smart_callback_call(data, SIG_EDGE_BOTTOM, NULL);
408 }
409
410 static void
411 _scroll(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
412 {
413    evas_object_smart_callback_call(data, SIG_SCROLL, NULL);
414 }
415
416 static void
417 _scroll_anim_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
418 {
419    evas_object_smart_callback_call(data, SIG_SCROLL_ANIM_START, NULL);
420 }
421
422 static void
423 _scroll_anim_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
424 {
425    evas_object_smart_callback_call(data, SIG_SCROLL_ANIM_STOP, NULL);
426 }
427
428 static void
429 _scroll_drag_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
430 {
431    evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_START, NULL);
432 }
433
434 static void
435 _scroll_drag_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
436 {
437    evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_STOP, NULL);
438 }
439
440 /**
441  * Add a new scroller to the parent
442  *
443  * @param parent The parent object
444  * @return The new object or NULL if it cannot be created
445  *
446  * @ingroup Scroller
447  */
448 EAPI Evas_Object *
449 elm_scroller_add(Evas_Object *parent)
450 {
451    Evas_Object *obj;
452    Evas *e;
453    Widget_Data *wd;
454    Evas_Coord minw, minh;
455
456    EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
457
458    wd = ELM_NEW(Widget_Data);
459    e = evas_object_evas_get(parent);
460    if (!e) return NULL;
461    obj = elm_widget_add(e);
462    ELM_SET_WIDTYPE(widtype, "scroller");
463    elm_widget_type_set(obj, "scroller");
464    elm_widget_sub_object_add(parent, obj);
465    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
466    elm_widget_data_set(obj, wd);
467    elm_widget_del_hook_set(obj, _del_hook);
468    elm_widget_theme_hook_set(obj, _theme_hook);
469    elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
470    elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
471    elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
472    elm_widget_focus_next_hook_set(obj, _elm_scroller_focus_next_hook);
473    elm_widget_can_focus_set(obj, EINA_TRUE);
474    elm_widget_event_hook_set(obj, _event_hook);
475    elm_widget_focus_region_hook_set(obj, _focus_region_hook);
476
477    wd->widget_name = eina_stringshare_add("scroller");
478    wd->widget_base = eina_stringshare_add("base");
479    
480    wd->scr = elm_smart_scroller_add(e);
481    elm_smart_scroller_widget_set(wd->scr, obj);
482    _theme_hook(obj);
483    elm_widget_resize_object_set(obj, wd->scr);
484    evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
485                                   _changed_size_hints, obj);
486
487    edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr), &minw, &minh);
488    evas_object_size_hint_min_set(obj, minw, minh);
489    evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, obj);
490
491    evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
492    evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
493    evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
494    evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
495    evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
496
497    evas_object_smart_callback_add(wd->scr, "edge,left", _edge_left, obj);
498    evas_object_smart_callback_add(wd->scr, "edge,right", _edge_right, obj);
499    evas_object_smart_callback_add(wd->scr, "edge,top", _edge_top, obj);
500    evas_object_smart_callback_add(wd->scr, "edge,bottom", _edge_bottom, obj);
501    evas_object_smart_callback_add(wd->scr, "scroll", _scroll, obj);
502    evas_object_smart_callback_add(wd->scr, "animate,start", _scroll_anim_start, obj);
503    evas_object_smart_callback_add(wd->scr, "animate,stop", _scroll_anim_stop, obj);
504    evas_object_smart_callback_add(wd->scr, "drag,start", _scroll_drag_start, obj);
505    evas_object_smart_callback_add(wd->scr, "drag,stop", _scroll_drag_stop, obj);
506
507    _sizing_eval(obj);
508
509    // TODO: convert Elementary to subclassing of Evas_Smart_Class
510    // TODO: and save some bytes, making descriptions per-class and not instance!
511    evas_object_smart_callbacks_descriptions_set(obj, _signals);
512    _mirrored_set(obj, elm_widget_mirrored_get(obj));
513    return obj;
514 }
515
516 Evas_Object *
517 _elm_scroller_edje_object_get(Evas_Object *obj)
518 {
519    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
520    Widget_Data *wd = elm_widget_data_get(obj);
521    if (!wd) return NULL;
522    return elm_smart_scroller_edje_object_get(wd->scr);
523 }
524
525 /**
526  * Set the content of the scroller widget (the object to be scrolled around).
527  *
528  * Once the content object is set, a previously set one will be deleted.
529  * If you want to keep that old content object, use the
530  * elm_scroller_content_unset() function.
531  *
532  * @param obj The scroller object
533  * @param content The new content object
534  *
535  * @ingroup Scroller
536  */
537 EAPI void
538 elm_scroller_content_set(Evas_Object *obj, Evas_Object *content)
539 {
540    ELM_CHECK_WIDTYPE(obj, widtype);
541    Widget_Data *wd = elm_widget_data_get(obj);
542    if (!wd) return;
543    if (wd->content == content) return;
544    if (wd->content) evas_object_del(wd->content);
545    wd->content = content;
546    if (content)
547      {
548         elm_widget_on_show_region_hook_set(content, _show_region_hook, obj);
549         elm_widget_sub_object_add(obj, content);
550         if (wd->scr)
551           elm_smart_scroller_child_set(wd->scr, content);
552         evas_object_event_callback_add(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
553                                        _changed_size_hints, obj);
554      }
555    _sizing_eval(obj);
556 }
557
558 /**
559  * Get the content of the scroller widget
560  *
561  * Return the content object which is set for this widget
562  *
563  * @param obj The slider object
564  * @return The content that is being used
565  *
566  * @ingroup Scroller
567  */
568 EAPI Evas_Object *
569 elm_scroller_content_get(const Evas_Object *obj)
570 {
571    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
572    Widget_Data *wd = elm_widget_data_get(obj);
573    if (!wd) return NULL;
574    return wd->content;
575 }
576
577 /**
578  * Unset the content of the scroller widget
579  *
580  * Unparent and return the content object which was set for this widget
581  *
582  * @param obj The slider object
583  * @return The content that was being used
584  *
585  * @ingroup Scroller
586  */
587 EAPI Evas_Object *
588 elm_scroller_content_unset(Evas_Object *obj)
589 {
590    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
591    Widget_Data *wd = elm_widget_data_get(obj);
592    Evas_Object *content;
593    if (!wd) return NULL;
594    if (!wd->content) return NULL;
595    content = wd->content;
596    elm_widget_sub_object_del(obj, wd->content);
597    edje_object_part_unswallow(wd->scr, wd->content);
598    wd->content = NULL;
599    return content;
600 }
601
602 /**
603  * Set custom theme elements for the scroller
604  * 
605  * @param obj The scroller object
606  * @param widget The widget name to use (default is "scroller")
607  * @param base The base name to use (default is "base")
608  *
609  * @ingroup Scroller
610  */
611 EAPI void
612 elm_scroller_custom_widget_base_theme_set(Evas_Object *obj, const char *widget, const char *base)
613 {
614    ELM_CHECK_WIDTYPE(obj, widtype);
615    Widget_Data *wd = elm_widget_data_get(obj);
616    if (!wd) return;
617    EINA_SAFETY_ON_NULL_RETURN(widget);
618    EINA_SAFETY_ON_NULL_RETURN(base);
619    if (eina_stringshare_replace(&wd->widget_name, widget) |
620        eina_stringshare_replace(&wd->widget_base, base))
621      _theme_hook(obj);
622 }
623
624 /**
625  * Make the scroller minimum size limited to the minimum size of the content
626  *
627  * By default the scroller will be as small as its design allows, irrespective
628  * of its content. This will make the scroller minimum size the right size
629  * horizontally and/or vertically to perfectly fit its content.
630  *
631  * @param obj The scroller object
632  * @param w Enable limiting minimum size horizontally
633  * @param h Enable limiting minimum size vertically
634  *
635  * @ingroup Scroller
636  */
637 EAPI void
638 elm_scroller_content_min_limit(Evas_Object *obj, Eina_Bool w, Eina_Bool h)
639 {
640    ELM_CHECK_WIDTYPE(obj, widtype);
641    Widget_Data *wd = elm_widget_data_get(obj);
642    if (!wd) return;
643    wd->min_w = w;
644    wd->min_h = h;
645    _sizing_eval(obj);
646 }
647
648 /**
649  * Show a specific virtual region within the scroller content object
650  *
651  * This will ensure all (or part if it does not fit) of the designated
652  * region in the virtual content object (0, 0 starting at the top-left of the
653  * virtual content object) is shown within the scroller.
654  *
655  * @param obj The scroller object
656  * @param x X coordinate of the region
657  * @param y Y coordinate of the region
658  * @param w Width of the region
659  * @param h Height of the region
660  *
661  * @ingroup Scroller
662  */
663 EAPI void
664 elm_scroller_region_show(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
665 {
666    ELM_CHECK_WIDTYPE(obj, widtype);
667    Widget_Data *wd = elm_widget_data_get(obj);
668    if ((!wd) || (!wd->scr)) return;
669    elm_smart_scroller_child_region_show(wd->scr, x, y, w, h);
670 }
671
672 /**
673  * Set the scroller scrollbar policy
674  *
675  * This sets the scrollbar visibility policy for the given scroller.
676  * ELM_SMART_SCROLLER_POLICY_AUTO means the scrollber is made visible if it
677  * is needed, and otherwise kept hidden. ELM_SMART_SCROLLER_POLICY_ON turns
678  * it on all the time, and ELM_SMART_SCROLLER_POLICY_OFF always keeps it off.
679  * This applies respectively for the horizontal and vertical scrollbars.
680  *
681  * @param obj The scroller object
682  * @param policy_h Horizontal scrollbar policy
683  * @param policy_v Vertical scrollbar policy
684  *
685  * @ingroup Scroller
686  */
687 EAPI void
688 elm_scroller_policy_set(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    const Elm_Scroller_Policy map[3] =
693      {
694         ELM_SMART_SCROLLER_POLICY_AUTO,
695           ELM_SMART_SCROLLER_POLICY_ON,
696           ELM_SMART_SCROLLER_POLICY_OFF
697      };
698    if ((!wd) || (!wd->scr)) return;
699    if ((policy_h >= 3) || (policy_v >= 3)) return;
700    elm_smart_scroller_policy_set(wd->scr, map[policy_h], map[policy_v]);
701 }
702
703 EAPI void
704 elm_scroller_policy_get(const Evas_Object *obj, Elm_Scroller_Policy *policy_h, Elm_Scroller_Policy *policy_v)
705 {
706    ELM_CHECK_WIDTYPE(obj, widtype);
707    Widget_Data *wd = elm_widget_data_get(obj);
708    if ((!wd) || (!wd->scr)) return;
709    elm_smart_scroller_policy_get(wd->scr,
710                                  (Elm_Smart_Scroller_Policy *) policy_h,
711                                  (Elm_Smart_Scroller_Policy *) policy_v);
712 }
713
714 /**
715  * Get the currently visible content region
716  *
717  * This gets the current region in the content object that is visible through
718  * the scroller. Also see elm_scroller_region_show(). The region co-ordinates
719  * are returned in the @p x, @p y, @p w, @p h values pointed to.
720  *
721  * @param obj The scroller object
722  * @param x X coordinate of the region
723  * @param y Y coordinate of the region
724  * @param w Width of the region
725  * @param h Height of the region
726  *
727  * @ingroup Scroller
728  */
729 EAPI void
730 elm_scroller_region_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
731 {
732    ELM_CHECK_WIDTYPE(obj, widtype);
733    Widget_Data *wd = elm_widget_data_get(obj);
734    if ((!wd) || (!wd->scr)) return;
735    if ((x) || (y)) elm_smart_scroller_child_pos_get(wd->scr, x, y);
736    if ((w) || (h)) elm_smart_scroller_child_viewport_size_get(wd->scr, w, h);
737 }
738
739 /**
740  * Get the size of the content child object
741  *
742  * This gets the size of the child object of the scroller. Actually the
743  * content of a scroller doesn't specifically need to be an actual object
744  * as it can be virtual and defined purely by callbacks.
745  *
746  * @param obj The scroller object
747  * @param w Width return
748  * @param h Height return
749  *
750  * @ingroup Scroller
751  */
752 EAPI void
753 elm_scroller_child_size_get(const Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
754 {
755    ELM_CHECK_WIDTYPE(obj, widtype);
756    Widget_Data *wd = elm_widget_data_get(obj);
757    if (!wd) return;
758    evas_object_geometry_get(wd->content, NULL, NULL, w, h);
759 }
760
761 /**
762  * Set bouncing behavior
763  *
764  * When scrolling, the scroller may "bounce" when reaching an edge of the child
765  * object. This is a visual way to indicate the end has been reached. This is
766  * enabled by default for both axes. This will set if it is enabled for that
767  * axis with the boolean parameters for each axis.
768  *
769  * @param obj The scroller object
770  * @param h_bounce Will the scroller bounce horizontally or not
771  * @param v_bounce Will the scroller bounce vertically or not
772  *
773  * @ingroup Scroller
774  */
775 EAPI void
776 elm_scroller_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
777 {
778    ELM_CHECK_WIDTYPE(obj, widtype);
779    Widget_Data *wd = elm_widget_data_get(obj);
780    if ((!wd) || (!wd->scr)) return;
781    elm_smart_scroller_bounce_allow_set(wd->scr, h_bounce, v_bounce);
782 }
783
784 /**
785  * Get the bounce mode
786  *
787  * @param obj The Scroller object
788  * @param h_bounce Allow bounce horizontally
789  * @param v_bounce Allow bounce vertically
790  *
791  * @ingroup Scroller
792  */
793 EAPI void
794 elm_scroller_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
795 {
796    ELM_CHECK_WIDTYPE(obj, widtype);
797    Widget_Data *wd = elm_widget_data_get(obj);
798    if (!wd) return;
799    elm_smart_scroller_bounce_allow_get(wd->scr, h_bounce, v_bounce);
800 }
801
802 /**
803  * Set scroll page size relative to viewport size.
804  *
805  * The scroller is capable of limiting scrolling by the user to "pages". That
806  * is to jump by and only show a "whole page" at a time as if the continuous
807  * area of the scroller content is split into page sized pieces. This sets
808  * the size of a page relative to the viewport of the scroller. 1.0 is "1
809  * viewport" is size (horizontally or vertically). 0.0 turns it off in that
810  * axis. This is mutually exclusive with page size
811  * (see elm_scroller_page_size_set()  for more information). Likewise 0.5
812  * is "half a viewport". Sane usable valus are normally between 0.0 and 1.0
813  * including 1.0. If you only want 1 axis to be page "limited", use 0.0 for
814  * the other axis.
815  *
816  * @param obj The scroller object
817  * @param h_pagerel The horizontal page relative size
818  * @param v_pagerel The vertical page relative size
819  *
820  * @ingroup Scroller
821  */
822 EAPI void
823 elm_scroller_page_relative_set(Evas_Object *obj, double h_pagerel, double v_pagerel)
824 {
825    ELM_CHECK_WIDTYPE(obj, widtype);
826    Widget_Data *wd = elm_widget_data_get(obj);
827    if (!wd) return;
828    wd->pagerel_h = h_pagerel;
829    wd->pagerel_v = v_pagerel;
830    if (wd->scr)
831      elm_smart_scroller_paging_set(wd->scr, wd->pagerel_h, wd->pagerel_v,
832                                    wd->pagesize_h, wd->pagesize_v);
833 }
834
835 /**
836  * Set scroll page size.
837  *
838  * See also elm_scroller_page_relative_set(). This, instead of a page size
839  * being relative to the viewport, sets it to an absolute fixed value, with
840  * 0 turning it off for that axis.
841  *
842  * @param obj The scroller object
843  * @param h_pagesize The horizontal page size
844  * @param v_pagesize The vertical page size
845  *
846  * @ingroup Scroller
847  */
848 EAPI void
849 elm_scroller_page_size_set(Evas_Object *obj, Evas_Coord h_pagesize, Evas_Coord v_pagesize)
850 {
851    ELM_CHECK_WIDTYPE(obj, widtype);
852    Widget_Data *wd = elm_widget_data_get(obj);
853    if (!wd) return;
854    wd->pagesize_h = h_pagesize;
855    wd->pagesize_v = v_pagesize;
856    if (wd->scr)
857      elm_smart_scroller_paging_set(wd->scr, wd->pagerel_h, wd->pagerel_v,
858                                    wd->pagesize_h, wd->pagesize_v);
859 }
860
861 /**
862  * Show a specific virtual region within the scroller content object.
863  *
864  * This will ensure all (or part if it does not fit) of the designated
865  * region in the virtual content object (0, 0 starting at the top-left of the
866  * virtual content object) is shown within the scroller. Unlike
867  * elm_scroller_region_show(), this allow the scroller to "smoothly slide"
868  * to this location (if configuration in general calls for transitions). It
869  * may not jump immediately to the new location and make take a while and
870  * show other content along the way.
871  *
872  * @param obj The scroller object
873  * @param x X coordinate of the region
874  * @param y Y coordinate of the region
875  * @param w Width of the region
876  * @param h Height of the region
877  *
878  * @ingroup Scroller
879  */
880 EAPI void
881 elm_scroller_region_bring_in(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
882 {
883    ELM_CHECK_WIDTYPE(obj, widtype);
884    Widget_Data *wd = elm_widget_data_get(obj);
885    if ((!wd) || (!wd->scr)) return;
886    elm_smart_scroller_region_bring_in(wd->scr, x, y, w, h);
887 }
888
889
890 /**
891  * Set event propagation on a scroller
892  *
893  * This enables or disabled event propagation from the scroller content to
894  * the scroller and its parent. By default event propagation is disabled.
895  * 
896  * @param obj The scroller object
897  * @param propagation If propagation is enabled or not
898  *
899  * @ingroup Scroller
900  */
901 EAPI void
902 elm_scroller_propagate_events_set(Evas_Object *obj, Eina_Bool propagation)
903 {
904    ELM_CHECK_WIDTYPE(obj, widtype);
905    Widget_Data *wd = elm_widget_data_get(obj);
906    if (!wd) return;
907
908    evas_object_propagate_events_set(wd->scr, propagation);
909 }
910
911 /**
912  * Get event propagation for a scroller
913  *
914  * This gets the event propagation for a scroller. See 
915  * elm_scroller_propagate_events_set() for more information
916  * 
917  * @param obj The scroller object
918  * @return The propagation state
919  *
920  * @ingroup Scroller
921  */
922 EAPI Eina_Bool
923 elm_scroller_propagate_events_get(const Evas_Object *obj)
924 {
925    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
926    Widget_Data *wd = elm_widget_data_get(obj);
927    if (!wd) return EINA_FALSE;
928
929    return evas_object_propagate_events_get(wd->scr);
930 }