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