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