efl/legacy/elementary/src/lib/elm_genlist.c

137 lines
3.7 KiB
C
Raw Normal View History

#include <Elementary.h>
#include "elm_priv.h"
typedef struct _Widget_Data Widget_Data;
struct _Widget_Data
{
Evas_Object *scr;
Evas_Object *content;
Evas_Bool min_w : 1;
Evas_Bool min_h : 1;
};
static void _del_hook(Evas_Object *obj);
static void _theme_hook(Evas_Object *obj);
static void _show_region_hook(void *data, Evas_Object *obj);
static void _sizing_eval(Evas_Object *obj);
static void _sub_del(void *data, Evas_Object *obj, void *event_info);
static void
_del_hook(Evas_Object *obj)
{
Widget_Data *wd = elm_widget_data_get(obj);
free(wd);
}
static void
_theme_hook(Evas_Object *obj)
{
Widget_Data *wd = elm_widget_data_get(obj);
elm_smart_scroller_theme_set(wd->scr, "scroller", "base", "default");
edje_object_scale_set(wd->scr, elm_widget_scale_get(obj) * _elm_config->scale);
_sizing_eval(obj);
}
static void
_show_region_hook(void *data, Evas_Object *obj)
{
Widget_Data *wd = elm_widget_data_get(data);
Evas_Coord x, y, w, h;
elm_widget_show_region_get(obj, &x, &y, &w, &h);
elm_smart_scroller_child_region_show(wd->scr, x, y, w, h);
}
static void
_sizing_eval(Evas_Object *obj)
{
Widget_Data *wd = elm_widget_data_get(obj);
Evas_Coord vw, vh, minw, minh, maxw, maxh, w, h, vmw, vmh;
double xw, xy;
evas_object_size_hint_min_get(wd->content, &minw, &minh);
evas_object_size_hint_max_get(wd->content, &maxw, &maxh);
evas_object_size_hint_weight_get(wd->content, &xw, &xy);
elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
if (xw > 0.0)
{
if ((minw > 0) && (vw < minw)) vw = minw;
else if ((maxw > 0) && (vw > maxw)) vw = maxw;
}
else if (minw > 0) vw = minw;
if (xy > 0.0)
{
if ((minh > 0) && (vh < minh)) vh = minh;
else if ((maxh > 0) && (vh > maxh)) vh = maxh;
}
else if (minh > 0) vh = minh;
evas_object_resize(wd->content, vw, vh);
w = -1;
h = -1;
edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr), &vmw, &vmh);
if (wd->min_w) w = vmw + minw;
if (wd->min_h) h = vmh + minh;
evas_object_size_hint_min_set(obj, w, h);
}
static void
_changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
_sizing_eval(data);
}
static void
_sub_del(void *data, Evas_Object *obj, void *event_info)
{
Widget_Data *wd = elm_widget_data_get(obj);
Evas_Object *sub = event_info;
if (sub == wd->content)
{
elm_widget_on_show_region_hook_set(wd->content, NULL, NULL);
evas_object_event_callback_del
(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints);
wd->content = NULL;
_sizing_eval(obj);
}
}
static void
_resize(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
_sizing_eval(data);
}
EAPI Evas_Object *
elm_genlist_add(Evas_Object *parent)
{
Evas_Object *obj;
Evas *e;
Widget_Data *wd;
Evas_Coord vw, vh, minw, minh;
wd = ELM_NEW(Widget_Data);
e = evas_object_evas_get(parent);
obj = elm_widget_add(e);
elm_widget_data_set(obj, wd);
elm_widget_del_hook_set(obj, _del_hook);
elm_widget_theme_hook_set(obj, _theme_hook);
wd->scr = elm_smart_scroller_add(e);
elm_widget_resize_object_set(obj, wd->scr);
edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr), &minw, &minh);
evas_object_size_hint_min_set(obj, minw, minh);
evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, obj);
// evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
_sizing_eval(obj);
return obj;
}
EAPI Elm_Genlist_Item *
elm_genlist_item_add(Evas_Object *obj, const Elm_Genlist_Item_Class *itc, const void *data, Elm_Genlist_Item *parent, Elm_Genlist_Item_Flags flags)
{
Widget_Data *wd = elm_widget_data_get(obj);
}