1 #include <Elementary.h>
4 typedef struct _Widget_Data Widget_Data;
10 const char *widget_name, *widget_base;
13 double pagerel_h, pagerel_v;
14 Evas_Coord pagesize_h, pagesize_v;
17 static const char *widtype = NULL;
18 static void _del_hook(Evas_Object *obj);
19 static void _theme_hook(Evas_Object *obj);
20 static void _show_region_hook(void *data, Evas_Object *obj);
21 static void _sizing_eval(Evas_Object *obj);
22 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
23 static void _on_focus_hook(void *data, Evas_Object *obj);
24 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src,
25 Evas_Callback_Type type, void *event_info);
28 static const char SIG_SCROLL[] = "scroll";
29 static const char SIG_SCROLL_ANIM_START[] = "scroll,anim,start";
30 static const char SIG_SCROLL_ANIM_STOP[] = "scroll,anim,stop";
31 static const char SIG_SCROLL_DRAG_START[] = "scroll,drag,start";
32 static const char SIG_SCROLL_DRAG_STOP[] = "scroll,drag,stop";
33 static const char SIG_EDGE_LEFT[] = "edge,left";
34 static const char SIG_EDGE_RIGHT[] = "edge,right";
35 static const char SIG_EDGE_TOP[] = "edge,top";
36 static const char SIG_EDGE_BOTTOM[] = "edge,bottom";
37 static const Evas_Smart_Cb_Description _signals[] = {
39 {SIG_SCROLL_ANIM_START, ""},
40 {SIG_SCROLL_ANIM_STOP, ""},
41 {SIG_SCROLL_DRAG_START, ""},
42 {SIG_SCROLL_DRAG_STOP, ""},
46 {SIG_EDGE_BOTTOM, ""},
51 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
53 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
54 Evas_Event_Key_Down *ev = event_info;
55 Widget_Data *wd = elm_widget_data_get(obj);
56 if (!wd) return EINA_FALSE;
57 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
58 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
62 Evas_Coord step_x = 0;
63 Evas_Coord step_y = 0;
68 Evas_Coord page_x = 0;
69 Evas_Coord page_y = 0;
71 elm_smart_scroller_child_pos_get(wd->scr, &x, &y);
72 elm_smart_scroller_step_size_get(wd->scr, &step_x, &step_y);
73 elm_smart_scroller_page_size_get(wd->scr, &page_x, &page_y);
74 elm_smart_scroller_child_viewport_size_get(wd->scr, &v_w, &v_h);
75 elm_scroller_child_size_get(obj, &max_x, &max_y);
77 if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")))
81 else if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")))
85 else if ((!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")))
89 else if ((!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
93 else if ((!strcmp(ev->keyname, "Home")) || (!strcmp(ev->keyname, "KP_Home")))
97 else if ((!strcmp(ev->keyname, "End")) || (!strcmp(ev->keyname, "KP_End")))
101 else if ((!strcmp(ev->keyname, "Prior")) || (!strcmp(ev->keyname, "KP_Prior")))
104 y -= -(page_y * v_h) / 100;
108 else if ((!strcmp(ev->keyname, "Next")) || (!strcmp(ev->keyname, "KP_Next")))
111 y += -(page_y * v_h) / 100;
115 else return EINA_FALSE;
117 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
118 elm_smart_scroller_child_pos_set(wd->scr, x, y);
123 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
125 Widget_Data *wd = elm_widget_data_get(obj);
127 if (elm_widget_focus_get(obj))
129 edje_object_signal_emit(wd->scr, "elm,action,focus", "elm");
130 evas_object_focus_set(wd->scr, EINA_TRUE);
134 edje_object_signal_emit(wd->scr, "elm,action,unfocus", "elm");
135 evas_object_focus_set(wd->scr, EINA_FALSE);
140 _del_hook(Evas_Object *obj)
142 Widget_Data *wd = elm_widget_data_get(obj);
148 _mirrored_set(Evas_Object *obj, Eina_Bool mirrored)
150 Widget_Data *wd = elm_widget_data_get(obj);
153 elm_smart_scroller_mirrored_set(wd->scr, mirrored);
157 _theme_hook(Evas_Object *obj)
159 Widget_Data *wd = elm_widget_data_get(obj);
161 _elm_widget_mirrored_reload(obj);
167 _mirrored_set(obj, elm_widget_mirrored_get(obj));
168 elm_smart_scroller_object_theme_set(obj, wd->scr,
169 wd->widget_name, wd->widget_base,
170 elm_widget_style_get(obj));
171 // edje_object_scale_set(wd->scr, elm_widget_scale_get(obj) * _elm_config->scale);
172 edj = elm_smart_scroller_edje_object_get(wd->scr);
173 str = edje_object_data_get(edj, "focus_highlight");
174 if ((str) && (!strcmp(str, "on")))
175 elm_widget_highlight_in_theme_set(obj, EINA_TRUE);
177 elm_widget_highlight_in_theme_set(obj, EINA_FALSE);
183 _elm_scroller_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
185 Widget_Data *wd = elm_widget_data_get(obj);
188 if ((!wd) || (!wd->content))
193 /* Try Focus cycle in subitem */
194 if ((elm_widget_can_focus_get(cur)) || (elm_widget_child_can_focus_get(cur)))
195 return elm_widget_focus_next_get(cur, dir, next);
198 *next = (Evas_Object *)obj;
199 return !elm_widget_focus_get(obj);
203 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
205 Widget_Data *wd = elm_widget_data_get(obj);
207 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
212 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
214 Widget_Data *wd = elm_widget_data_get(obj);
216 edje_object_signal_callback_add(elm_smart_scroller_edje_object_get(wd->scr),
217 emission, source, func_cb, data);
221 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
223 Widget_Data *wd = elm_widget_data_get(obj);
224 edje_object_signal_callback_del_full(
225 elm_smart_scroller_edje_object_get(wd->scr), emission, source,
230 _show_region_hook(void *data, Evas_Object *obj)
232 Widget_Data *wd = elm_widget_data_get(data);
233 Evas_Coord x, y, w, h;
235 elm_widget_show_region_get(obj, &x, &y, &w, &h);
237 elm_smart_scroller_child_region_show(wd->scr, x, y, w, h);
241 _focus_region_hook(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
243 Widget_Data *wd = elm_widget_data_get(obj);
245 elm_smart_scroller_child_region_show(wd->scr, x, y, w, h);
249 _sizing_eval(Evas_Object *obj)
251 Widget_Data *wd = elm_widget_data_get(obj);
252 Evas_Coord vw, vh, minw = 0, minh = 0, maxw = 0, maxh = 0, w, h, vmw, vmh;
253 double xw = 0.0, yw = 0.0;
258 evas_object_size_hint_min_get(wd->content, &minw, &minh);
259 evas_object_size_hint_max_get(wd->content, &maxw, &maxh);
260 evas_object_size_hint_weight_get(wd->content, &xw, &yw);
264 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
267 if ((minw > 0) && (vw < minw)) vw = minw;
268 else if ((maxw > 0) && (vw > maxw)) vw = maxw;
270 else if (minw > 0) vw = minw;
273 if ((minh > 0) && (vh < minh)) vh = minh;
274 else if ((maxh > 0) && (vh > maxh)) vh = maxh;
276 else if (minh > 0) vh = minh;
277 if (wd->content) evas_object_resize(wd->content, vw, vh);
280 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr), &vmw, &vmh);
281 if (wd->min_w) w = vmw + minw;
282 if (wd->min_h) h = vmh + minh;
283 evas_object_size_hint_max_get(obj, &maxw, &maxh);
284 if ((maxw > 0) && (w > maxw)) w = maxw;
285 if ((maxh > 0) && (h > maxh)) h = maxh;
286 evas_object_size_hint_min_set(obj, w, h);
291 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
297 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
299 Widget_Data *wd = elm_widget_data_get(obj);
300 Evas_Object *sub = event_info;
303 if (sub == wd->content)
305 elm_widget_on_show_region_hook_set(wd->content, NULL, NULL);
306 evas_object_event_callback_del_full (sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
307 _changed_size_hints, obj);
311 else if (sub == wd->scr)
316 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
318 Widget_Data *wd = elm_widget_data_get(obj);
322 elm_smart_scroller_hold_set(wd->scr, 1);
326 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
328 Widget_Data *wd = elm_widget_data_get(obj);
332 elm_smart_scroller_hold_set(wd->scr, 0);
336 _freeze_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
338 Widget_Data *wd = elm_widget_data_get(obj);
342 elm_smart_scroller_freeze_set(wd->scr, 1);
346 _freeze_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
348 Widget_Data *wd = elm_widget_data_get(obj);
352 elm_smart_scroller_freeze_set(wd->scr, 0);
356 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
362 _edge_left(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
364 evas_object_smart_callback_call(data, SIG_EDGE_LEFT, NULL);
368 _edge_right(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
370 evas_object_smart_callback_call(data, SIG_EDGE_RIGHT, NULL);
374 _edge_top(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
376 evas_object_smart_callback_call(data, SIG_EDGE_TOP, NULL);
380 _edge_bottom(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
382 evas_object_smart_callback_call(data, SIG_EDGE_BOTTOM, NULL);
386 _scroll(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
388 evas_object_smart_callback_call(data, SIG_SCROLL, NULL);
392 _scroll_anim_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
394 evas_object_smart_callback_call(data, SIG_SCROLL_ANIM_START, NULL);
398 _scroll_anim_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
400 evas_object_smart_callback_call(data, SIG_SCROLL_ANIM_STOP, NULL);
404 _scroll_drag_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
406 evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_START, NULL);
410 _scroll_drag_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
412 evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_STOP, NULL);
416 elm_scroller_add(Evas_Object *parent)
421 Evas_Coord minw, minh;
423 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
425 ELM_SET_WIDTYPE(widtype, "scroller");
426 elm_widget_type_set(obj, "scroller");
427 elm_widget_sub_object_add(parent, obj);
428 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
429 elm_widget_data_set(obj, wd);
430 elm_widget_del_hook_set(obj, _del_hook);
431 elm_widget_theme_hook_set(obj, _theme_hook);
432 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
433 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
434 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
435 elm_widget_focus_next_hook_set(obj, _elm_scroller_focus_next_hook);
436 elm_widget_can_focus_set(obj, EINA_TRUE);
437 elm_widget_event_hook_set(obj, _event_hook);
438 elm_widget_focus_region_hook_set(obj, _focus_region_hook);
440 wd->widget_name = eina_stringshare_add("scroller");
441 wd->widget_base = eina_stringshare_add("base");
443 wd->scr = elm_smart_scroller_add(e);
444 elm_smart_scroller_widget_set(wd->scr, obj);
446 elm_widget_resize_object_set(obj, wd->scr);
447 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
448 _changed_size_hints, obj);
450 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr), &minw, &minh);
451 evas_object_size_hint_min_set(obj, minw, minh);
452 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, obj);
454 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
455 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
456 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
457 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
458 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
460 evas_object_smart_callback_add(wd->scr, "edge,left", _edge_left, obj);
461 evas_object_smart_callback_add(wd->scr, "edge,right", _edge_right, obj);
462 evas_object_smart_callback_add(wd->scr, "edge,top", _edge_top, obj);
463 evas_object_smart_callback_add(wd->scr, "edge,bottom", _edge_bottom, obj);
464 evas_object_smart_callback_add(wd->scr, "scroll", _scroll, obj);
465 evas_object_smart_callback_add(wd->scr, "animate,start", _scroll_anim_start, obj);
466 evas_object_smart_callback_add(wd->scr, "animate,stop", _scroll_anim_stop, obj);
467 evas_object_smart_callback_add(wd->scr, "drag,start", _scroll_drag_start, obj);
468 evas_object_smart_callback_add(wd->scr, "drag,stop", _scroll_drag_stop, obj);
472 // TODO: convert Elementary to subclassing of Evas_Smart_Class
473 // TODO: and save some bytes, making descriptions per-class and not instance!
474 evas_object_smart_callbacks_descriptions_set(obj, _signals);
475 _mirrored_set(obj, elm_widget_mirrored_get(obj));
480 _elm_scroller_edje_object_get(Evas_Object *obj)
482 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
483 Widget_Data *wd = elm_widget_data_get(obj);
484 if (!wd) return NULL;
485 return elm_smart_scroller_edje_object_get(wd->scr);
489 elm_scroller_content_set(Evas_Object *obj, Evas_Object *content)
491 ELM_CHECK_WIDTYPE(obj, widtype);
492 Widget_Data *wd = elm_widget_data_get(obj);
494 if (wd->content == content) return;
495 if (wd->content) evas_object_del(wd->content);
496 wd->content = content;
499 elm_widget_on_show_region_hook_set(content, _show_region_hook, obj);
500 elm_widget_sub_object_add(obj, content);
502 elm_smart_scroller_child_set(wd->scr, content);
503 evas_object_event_callback_add(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
504 _changed_size_hints, obj);
510 elm_scroller_content_get(const Evas_Object *obj)
512 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
513 Widget_Data *wd = elm_widget_data_get(obj);
514 if (!wd) return NULL;
519 elm_scroller_content_unset(Evas_Object *obj)
521 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
522 Widget_Data *wd = elm_widget_data_get(obj);
523 Evas_Object *content;
524 if (!wd) return NULL;
525 if (!wd->content) return NULL;
526 content = wd->content;
527 elm_widget_sub_object_del(obj, wd->content);
528 edje_object_part_unswallow(wd->scr, wd->content);
534 elm_scroller_custom_widget_base_theme_set(Evas_Object *obj, const char *widget, const char *base)
536 ELM_CHECK_WIDTYPE(obj, widtype);
537 Widget_Data *wd = elm_widget_data_get(obj);
539 EINA_SAFETY_ON_NULL_RETURN(widget);
540 EINA_SAFETY_ON_NULL_RETURN(base);
541 if (eina_stringshare_replace(&wd->widget_name, widget) |
542 eina_stringshare_replace(&wd->widget_base, base))
547 elm_scroller_content_min_limit(Evas_Object *obj, Eina_Bool w, Eina_Bool h)
549 ELM_CHECK_WIDTYPE(obj, widtype);
550 Widget_Data *wd = elm_widget_data_get(obj);
558 elm_scroller_region_show(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
560 ELM_CHECK_WIDTYPE(obj, widtype);
561 Widget_Data *wd = elm_widget_data_get(obj);
562 if ((!wd) || (!wd->scr)) return;
563 elm_smart_scroller_child_region_show(wd->scr, x, y, w, h);
567 elm_scroller_policy_set(Evas_Object *obj, Elm_Scroller_Policy policy_h, Elm_Scroller_Policy policy_v)
569 ELM_CHECK_WIDTYPE(obj, widtype);
570 Widget_Data *wd = elm_widget_data_get(obj);
571 const Elm_Scroller_Policy map[3] =
573 ELM_SMART_SCROLLER_POLICY_AUTO,
574 ELM_SMART_SCROLLER_POLICY_ON,
575 ELM_SMART_SCROLLER_POLICY_OFF
577 if ((!wd) || (!wd->scr)) return;
578 if ((policy_h >= 3) || (policy_v >= 3)) return;
579 elm_smart_scroller_policy_set(wd->scr, map[policy_h], map[policy_v]);
583 elm_scroller_policy_get(const Evas_Object *obj, Elm_Scroller_Policy *policy_h, Elm_Scroller_Policy *policy_v)
585 ELM_CHECK_WIDTYPE(obj, widtype);
586 Widget_Data *wd = elm_widget_data_get(obj);
587 if ((!wd) || (!wd->scr)) return;
588 elm_smart_scroller_policy_get(wd->scr,
589 (Elm_Smart_Scroller_Policy *) policy_h,
590 (Elm_Smart_Scroller_Policy *) policy_v);
594 elm_scroller_region_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
596 ELM_CHECK_WIDTYPE(obj, widtype);
597 Widget_Data *wd = elm_widget_data_get(obj);
598 if ((!wd) || (!wd->scr)) return;
599 if ((x) || (y)) elm_smart_scroller_child_pos_get(wd->scr, x, y);
600 if ((w) || (h)) elm_smart_scroller_child_viewport_size_get(wd->scr, w, h);
604 elm_scroller_child_size_get(const Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
606 ELM_CHECK_WIDTYPE(obj, widtype);
607 Widget_Data *wd = elm_widget_data_get(obj);
609 evas_object_geometry_get(wd->content, NULL, NULL, w, h);
613 elm_scroller_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
615 ELM_CHECK_WIDTYPE(obj, widtype);
616 Widget_Data *wd = elm_widget_data_get(obj);
617 if ((!wd) || (!wd->scr)) return;
618 elm_smart_scroller_bounce_allow_set(wd->scr, h_bounce, v_bounce);
622 elm_scroller_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
624 ELM_CHECK_WIDTYPE(obj, widtype);
625 Widget_Data *wd = elm_widget_data_get(obj);
627 elm_smart_scroller_bounce_allow_get(wd->scr, h_bounce, v_bounce);
631 elm_scroller_page_relative_set(Evas_Object *obj, double h_pagerel, double v_pagerel)
633 ELM_CHECK_WIDTYPE(obj, widtype);
634 Widget_Data *wd = elm_widget_data_get(obj);
636 wd->pagerel_h = h_pagerel;
637 wd->pagerel_v = v_pagerel;
639 elm_smart_scroller_paging_set(wd->scr, wd->pagerel_h, wd->pagerel_v,
640 wd->pagesize_h, wd->pagesize_v);
644 elm_scroller_page_size_set(Evas_Object *obj, Evas_Coord h_pagesize, Evas_Coord v_pagesize)
646 ELM_CHECK_WIDTYPE(obj, widtype);
647 Widget_Data *wd = elm_widget_data_get(obj);
649 wd->pagesize_h = h_pagesize;
650 wd->pagesize_v = v_pagesize;
652 elm_smart_scroller_paging_set(wd->scr, wd->pagerel_h, wd->pagerel_v,
653 wd->pagesize_h, wd->pagesize_v);
657 elm_scroller_region_bring_in(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
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_region_bring_in(wd->scr, x, y, w, h);
666 elm_scroller_propagate_events_set(Evas_Object *obj, Eina_Bool propagation)
668 ELM_CHECK_WIDTYPE(obj, widtype);
669 Widget_Data *wd = elm_widget_data_get(obj);
672 evas_object_propagate_events_set(wd->scr, propagation);
676 elm_scroller_propagate_events_get(const Evas_Object *obj)
678 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
679 Widget_Data *wd = elm_widget_data_get(obj);
680 if (!wd) return EINA_FALSE;
682 return evas_object_propagate_events_get(wd->scr);