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