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