2008-09-29 23:58:56 -07:00
|
|
|
#include <Elementary.h>
|
|
|
|
#include "elm_priv.h"
|
|
|
|
|
2008-10-06 18:23:49 -07:00
|
|
|
typedef struct _Widget_Data Widget_Data;
|
|
|
|
|
|
|
|
struct _Widget_Data
|
2008-09-29 23:58:56 -07:00
|
|
|
{
|
2008-10-06 18:23:49 -07:00
|
|
|
Evas_Object *scr;
|
2008-10-06 23:55:11 -07:00
|
|
|
Evas_Object *content;
|
2008-10-22 01:58:56 -07:00
|
|
|
Evas_Bool min_w : 1;
|
|
|
|
Evas_Bool min_h : 1;
|
2008-09-29 23:58:56 -07:00
|
|
|
};
|
|
|
|
|
2008-10-06 18:23:49 -07:00
|
|
|
static void _del_hook(Evas_Object *obj);
|
2008-11-15 05:58:50 -08:00
|
|
|
static void _theme_hook(Evas_Object *obj);
|
2008-10-17 07:40:54 -07:00
|
|
|
static void _show_region_hook(void *data, Evas_Object *obj);
|
2008-10-06 18:23:49 -07:00
|
|
|
static void _sizing_eval(Evas_Object *obj);
|
2008-10-06 23:55:11 -07:00
|
|
|
static void _sub_del(void *data, Evas_Object *obj, void *event_info);
|
2008-10-06 18:23:49 -07:00
|
|
|
|
2008-09-29 23:58:56 -07:00
|
|
|
static void
|
2008-10-06 18:23:49 -07:00
|
|
|
_del_hook(Evas_Object *obj)
|
2008-09-29 23:58:56 -07:00
|
|
|
{
|
2008-10-06 18:23:49 -07:00
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
free(wd);
|
2008-09-29 23:58:56 -07:00
|
|
|
}
|
|
|
|
|
2008-11-15 05:58:50 -08:00
|
|
|
static void
|
|
|
|
_theme_hook(Evas_Object *obj)
|
|
|
|
{
|
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
2008-12-18 05:38:58 -08:00
|
|
|
elm_smart_scroller_theme_set(wd->scr, "scroller", "base", "default");
|
2008-11-15 05:58:50 -08:00
|
|
|
_sizing_eval(obj);
|
|
|
|
}
|
|
|
|
|
2008-10-17 07:40:54 -07:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2008-09-29 23:58:56 -07:00
|
|
|
static void
|
2008-10-06 18:23:49 -07:00
|
|
|
_sizing_eval(Evas_Object *obj)
|
2008-09-29 23:58:56 -07:00
|
|
|
{
|
2008-10-06 18:23:49 -07:00
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
2008-10-22 01:58:56 -07:00
|
|
|
Evas_Coord vw, vh, minw, minh, maxw, maxh, w, h, vmw, vmh;
|
2008-10-06 18:23:49 -07:00
|
|
|
double xw, xy;
|
|
|
|
|
2008-10-06 23:55:11 -07:00
|
|
|
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);
|
2008-10-06 18:23:49 -07:00
|
|
|
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)
|
2008-09-29 23:58:56 -07:00
|
|
|
{
|
2008-10-06 18:23:49 -07:00
|
|
|
if ((minh > 0) && (vh < minh)) vh = minh;
|
|
|
|
else if ((maxh > 0) && (vh > maxh)) vh = maxh;
|
2008-09-29 23:58:56 -07:00
|
|
|
}
|
2008-10-06 18:23:49 -07:00
|
|
|
else if (minh > 0) vh = minh;
|
2008-10-06 23:55:11 -07:00
|
|
|
evas_object_resize(wd->content, vw, vh);
|
2008-10-22 01:58:56 -07:00
|
|
|
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;
|
2009-01-08 19:03:36 -08:00
|
|
|
printf("%i : %i + %i\n",wd->min_w, vmw, minw);
|
2008-10-22 01:58:56 -07:00
|
|
|
evas_object_size_hint_min_set(obj, w, h);
|
2008-09-29 23:58:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-10-06 18:23:49 -07:00
|
|
|
_changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info)
|
2008-09-29 23:58:56 -07:00
|
|
|
{
|
2008-10-06 18:23:49 -07:00
|
|
|
_sizing_eval(data);
|
2008-09-29 23:58:56 -07:00
|
|
|
}
|
|
|
|
|
2008-10-06 23:55:11 -07:00
|
|
|
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)
|
|
|
|
{
|
2008-10-17 07:40:54 -07:00
|
|
|
elm_widget_on_show_region_hook_set(wd->content, NULL, NULL);
|
2008-10-06 23:55:11 -07:00
|
|
|
evas_object_event_callback_del
|
|
|
|
(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints);
|
|
|
|
wd->content = NULL;
|
|
|
|
_sizing_eval(obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-29 23:58:56 -07:00
|
|
|
static void
|
2008-10-06 18:23:49 -07:00
|
|
|
_resize(void *data, Evas *e, Evas_Object *obj, void *event_info)
|
2008-09-29 23:58:56 -07:00
|
|
|
{
|
2008-10-06 18:23:49 -07:00
|
|
|
_sizing_eval(data);
|
2008-09-29 23:58:56 -07:00
|
|
|
}
|
|
|
|
|
2008-10-06 18:23:49 -07:00
|
|
|
EAPI Evas_Object *
|
|
|
|
elm_scroller_add(Evas_Object *parent)
|
2008-09-29 23:58:56 -07:00
|
|
|
{
|
2008-10-06 18:23:49 -07:00
|
|
|
Evas_Object *obj;
|
|
|
|
Evas *e;
|
|
|
|
Widget_Data *wd;
|
|
|
|
Evas_Coord vw, vh, minw, minh;
|
2008-09-29 23:58:56 -07:00
|
|
|
|
2008-10-06 18:23:49 -07:00
|
|
|
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);
|
2008-11-15 05:58:50 -08:00
|
|
|
elm_widget_theme_hook_set(obj, _theme_hook);
|
2008-09-29 23:58:56 -07:00
|
|
|
|
2008-10-06 18:23:49 -07:00
|
|
|
wd->scr = elm_smart_scroller_add(e);
|
|
|
|
elm_widget_resize_object_set(obj, wd->scr);
|
2008-10-22 01:58:56 -07:00
|
|
|
|
|
|
|
edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr), &minw, &minh);
|
2008-10-06 18:23:49 -07:00
|
|
|
evas_object_size_hint_min_set(obj, minw, minh);
|
|
|
|
evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, obj);
|
2008-10-06 23:55:11 -07:00
|
|
|
|
|
|
|
evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
|
2008-09-29 23:58:56 -07:00
|
|
|
|
2008-10-06 18:23:49 -07:00
|
|
|
_sizing_eval(obj);
|
|
|
|
return obj;
|
|
|
|
}
|
2008-09-29 23:58:56 -07:00
|
|
|
|
2008-10-06 18:23:49 -07:00
|
|
|
EAPI void
|
2008-10-06 23:55:11 -07:00
|
|
|
elm_scroller_content_set(Evas_Object *obj, Evas_Object *content)
|
2008-10-06 18:23:49 -07:00
|
|
|
{
|
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
2008-10-06 23:55:11 -07:00
|
|
|
if ((wd->content != content) && (wd->content))
|
|
|
|
elm_widget_sub_object_del(obj, wd->content);
|
|
|
|
wd->content = content;
|
|
|
|
if (content)
|
|
|
|
{
|
2008-10-17 07:40:54 -07:00
|
|
|
elm_widget_on_show_region_hook_set(content, _show_region_hook, obj);
|
2008-10-08 01:14:25 -07:00
|
|
|
elm_widget_sub_object_add(obj, content);
|
2008-10-06 23:55:11 -07:00
|
|
|
elm_smart_scroller_child_set(wd->scr, content);
|
|
|
|
evas_object_event_callback_add(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
|
|
|
|
_changed_size_hints, obj);
|
|
|
|
_sizing_eval(obj);
|
|
|
|
}
|
2008-09-29 23:58:56 -07:00
|
|
|
}
|
2008-10-22 01:58:56 -07:00
|
|
|
|
|
|
|
EAPI void
|
|
|
|
elm_scroller_content_min_limit(Evas_Object *obj, Evas_Bool w, Evas_Bool h)
|
|
|
|
{
|
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
wd->min_w = w;
|
|
|
|
wd->min_h = h;
|
|
|
|
_sizing_eval(obj);
|
|
|
|
}
|