2013-04-25 22:13:00 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "elementary_config.h"
|
|
|
|
#endif
|
|
|
|
|
2011-08-05 00:45:45 -07:00
|
|
|
#include <Elementary.h>
|
|
|
|
#include "elm_priv.h"
|
|
|
|
|
2011-08-29 05:52:41 -07:00
|
|
|
// FIXME: handle if canvas resizes
|
|
|
|
|
2011-08-05 00:45:45 -07:00
|
|
|
typedef struct _Widget_Data Widget_Data;
|
|
|
|
|
|
|
|
struct _Widget_Data
|
|
|
|
{
|
|
|
|
Evas_Object *obj;
|
|
|
|
Evas_Object *content;
|
2011-09-01 21:09:17 -07:00
|
|
|
int last_calc_count;
|
2011-08-29 05:52:41 -07:00
|
|
|
Evas_Coord maxminw, maxminh;
|
2011-08-05 04:15:03 -07:00
|
|
|
Eina_Bool eval : 1;
|
2011-08-29 05:52:41 -07:00
|
|
|
Eina_Bool szeval : 1;
|
|
|
|
Eina_Bool maxmin : 1;
|
2011-08-05 00:45:45 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
static const char *widtype = NULL;
|
|
|
|
static void _del_hook(Evas_Object *obj);
|
2011-08-05 04:15:03 -07:00
|
|
|
static Eina_Bool _focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next);
|
2011-08-05 00:45:45 -07:00
|
|
|
static void _sizing_eval(Evas_Object *obj);
|
2011-08-05 04:15:03 -07:00
|
|
|
static void _eval(Evas_Object *obj);
|
|
|
|
static void _changed(Evas_Object *obj);
|
2014-01-06 06:30:02 -08:00
|
|
|
static void _move(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED);
|
|
|
|
static void _resize(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED);
|
|
|
|
static void _child_change(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED);
|
|
|
|
static void _child_del(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED);
|
2011-11-16 04:51:53 -08:00
|
|
|
static void _content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content);
|
|
|
|
static Evas_Object *_content_get_hook(const Evas_Object *obj, const char *part);
|
2012-02-14 20:55:43 -08:00
|
|
|
static Evas_Object *_content_unset_hook(Evas_Object *obj, const char *part);
|
2011-08-05 00:45:45 -07:00
|
|
|
|
|
|
|
static const char SIG_REALIZE[] = "realize";
|
|
|
|
static const char SIG_UNREALIZE[] = "unrealize";
|
|
|
|
|
|
|
|
static const Evas_Smart_Cb_Description _signals[] = {
|
|
|
|
{SIG_REALIZE, ""},
|
|
|
|
{SIG_UNREALIZE, ""},
|
|
|
|
{NULL, NULL}
|
|
|
|
};
|
|
|
|
|
2011-08-29 05:52:41 -07:00
|
|
|
static int fac = 0;
|
|
|
|
|
2011-08-05 00:45:45 -07:00
|
|
|
static void
|
|
|
|
_del_hook(Evas_Object *obj)
|
|
|
|
{
|
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
if (!wd) return;
|
2011-08-29 05:52:41 -07:00
|
|
|
if (wd->content)
|
|
|
|
{
|
|
|
|
Evas_Object *o = wd->content;
|
2011-09-01 21:09:17 -07:00
|
|
|
|
2011-08-29 05:52:41 -07:00
|
|
|
evas_object_event_callback_del_full(o,
|
|
|
|
EVAS_CALLBACK_CHANGED_SIZE_HINTS,
|
|
|
|
_child_change, obj);
|
|
|
|
evas_object_event_callback_del_full(o,
|
|
|
|
EVAS_CALLBACK_DEL,
|
|
|
|
_child_del, obj);
|
|
|
|
wd->content = NULL;
|
|
|
|
evas_object_del(o);
|
|
|
|
fac--;
|
2013-06-04 22:40:03 -07:00
|
|
|
// DBG("FAC-- = %i", fac);
|
2011-08-29 05:52:41 -07:00
|
|
|
}
|
2011-08-05 00:45:45 -07:00
|
|
|
free(wd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
|
|
|
|
{
|
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
Evas_Object *cur;
|
2011-08-09 21:35:31 -07:00
|
|
|
|
2011-08-05 00:45:45 -07:00
|
|
|
if ((!wd) || (!wd->content)) return EINA_FALSE;
|
|
|
|
cur = wd->content;
|
|
|
|
return elm_widget_focus_next_get(cur, dir, next);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_sizing_eval(Evas_Object *obj)
|
|
|
|
{
|
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
|
2011-08-09 21:35:31 -07:00
|
|
|
|
2011-08-05 00:45:45 -07:00
|
|
|
if (!wd) return;
|
|
|
|
if (!wd->content) return;
|
|
|
|
evas_object_size_hint_min_get(wd->content, &minw, &minh);
|
|
|
|
evas_object_size_hint_max_get(wd->content, &maxw, &maxh);
|
2011-08-29 05:52:41 -07:00
|
|
|
if (wd->maxmin)
|
|
|
|
{
|
|
|
|
if (minw > wd->maxminw) wd->maxminw = minw;
|
|
|
|
if (minh > wd->maxminh) wd->maxminh = minh;
|
|
|
|
evas_object_size_hint_min_set(obj, wd->maxminw, wd->maxminh);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
evas_object_size_hint_min_set(obj, minw, minh);
|
|
|
|
}
|
2011-08-05 00:45:45 -07:00
|
|
|
evas_object_size_hint_max_set(obj, maxw, maxh);
|
2013-06-04 22:40:03 -07:00
|
|
|
// DBG("FAC SZ: %i %i | %i %i", minw, minh, maxw, maxh);
|
2011-08-05 00:45:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-08-05 04:15:03 -07:00
|
|
|
_eval(Evas_Object *obj)
|
2011-08-05 00:45:45 -07:00
|
|
|
{
|
|
|
|
Evas_Coord x, y, w, h, cvx, cvy, cvw, cvh;
|
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
if (!wd) return;
|
2011-08-09 21:35:31 -07:00
|
|
|
|
2011-08-26 05:27:57 -07:00
|
|
|
evas_event_freeze(evas_object_evas_get(obj));
|
2011-08-05 00:45:45 -07:00
|
|
|
evas_object_geometry_get(obj, &x, &y, &w, &h);
|
2011-08-26 05:27:57 -07:00
|
|
|
if (w < 1) w = 1;
|
|
|
|
if (h < 1) h = 1;
|
2011-08-09 21:35:31 -07:00
|
|
|
evas_output_viewport_get(evas_object_evas_get(obj),
|
2011-08-05 00:45:45 -07:00
|
|
|
&cvx, &cvy, &cvw, &cvh);
|
2011-08-26 05:27:57 -07:00
|
|
|
if ((cvw < 1) || (cvh < 1)) return;
|
2011-08-05 06:22:03 -07:00
|
|
|
// need some fuzz value thats beyond the current viewport
|
2011-08-26 05:27:57 -07:00
|
|
|
// for now just make it the viewport * 3 in size (so 1 vp in each direction)
|
|
|
|
/*
|
|
|
|
cvx -= cvw;
|
|
|
|
cvy -= cvh;
|
|
|
|
cvw *= 3;
|
|
|
|
cvh *= 3;
|
|
|
|
*/
|
2011-08-05 00:45:45 -07:00
|
|
|
if (ELM_RECTS_INTERSECT(x, y, w, h, cvx, cvy, cvw, cvh))
|
|
|
|
{
|
|
|
|
if (!wd->content)
|
2011-08-05 04:15:03 -07:00
|
|
|
{
|
2013-06-04 22:40:03 -07:00
|
|
|
// DBG(" + %i %i %ix%i <> %i %i %ix%i", x, y, w, h, cvx, cvy, cvw, cvh);
|
2011-08-05 04:15:03 -07:00
|
|
|
evas_object_smart_callback_call(obj, SIG_REALIZE, NULL);
|
|
|
|
if (wd->content)
|
|
|
|
{
|
|
|
|
if (evas_object_smart_data_get(wd->content))
|
|
|
|
evas_object_smart_calculate(wd->content);
|
|
|
|
}
|
2011-09-01 21:09:17 -07:00
|
|
|
wd->last_calc_count =
|
2011-08-26 05:27:57 -07:00
|
|
|
evas_smart_objects_calculate_count_get(evas_object_evas_get(obj));
|
2011-08-05 04:15:03 -07:00
|
|
|
}
|
2011-08-05 00:45:45 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (wd->content)
|
2011-08-26 05:27:57 -07:00
|
|
|
{
|
2011-09-01 21:09:17 -07:00
|
|
|
if (wd->last_calc_count !=
|
2011-08-26 05:27:57 -07:00
|
|
|
evas_smart_objects_calculate_count_get(evas_object_evas_get(obj)))
|
|
|
|
evas_object_smart_callback_call(obj, SIG_UNREALIZE, NULL);
|
|
|
|
}
|
2011-08-05 00:45:45 -07:00
|
|
|
}
|
2011-08-26 05:27:57 -07:00
|
|
|
evas_event_thaw(evas_object_evas_get(obj));
|
|
|
|
evas_event_thaw_eval(evas_object_evas_get(obj));
|
2011-08-05 00:45:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-08-05 04:15:03 -07:00
|
|
|
_changed(Evas_Object *obj)
|
2011-08-05 00:45:45 -07:00
|
|
|
{
|
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
if (!wd) return;
|
2011-08-05 04:15:03 -07:00
|
|
|
if (wd->eval)
|
|
|
|
{
|
|
|
|
_eval(obj);
|
|
|
|
wd->eval = EINA_FALSE;
|
|
|
|
}
|
2011-08-29 05:52:41 -07:00
|
|
|
if (wd->szeval)
|
|
|
|
{
|
|
|
|
_sizing_eval(obj);
|
|
|
|
wd->szeval = EINA_FALSE;
|
|
|
|
}
|
2011-08-05 00:45:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-01-06 06:30:02 -08:00
|
|
|
_move(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
|
2011-08-05 00:45:45 -07:00
|
|
|
{
|
2011-08-05 04:15:03 -07:00
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
if (!wd) return;
|
|
|
|
wd->eval = EINA_TRUE;
|
|
|
|
evas_object_smart_changed(obj);
|
2011-08-05 00:45:45 -07:00
|
|
|
}
|
2011-08-09 21:35:31 -07:00
|
|
|
|
2011-08-05 00:45:45 -07:00
|
|
|
static void
|
2014-01-06 06:30:02 -08:00
|
|
|
_resize(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
|
2011-08-09 21:35:31 -07:00
|
|
|
{
|
2011-08-05 04:15:03 -07:00
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
if (!wd) return;
|
|
|
|
wd->eval = EINA_TRUE;
|
|
|
|
evas_object_smart_changed(obj);
|
2011-08-05 00:45:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-01-06 06:30:02 -08:00
|
|
|
_child_change(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
|
2011-08-05 00:45:45 -07:00
|
|
|
{
|
2011-08-05 04:15:03 -07:00
|
|
|
Widget_Data *wd = elm_widget_data_get(data);
|
|
|
|
if (!wd) return;
|
|
|
|
wd->eval = EINA_TRUE;
|
2011-08-29 05:52:41 -07:00
|
|
|
wd->szeval = EINA_TRUE;
|
2011-08-05 04:15:03 -07:00
|
|
|
evas_object_smart_changed(data);
|
2011-08-05 00:45:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-01-06 06:30:02 -08:00
|
|
|
_child_del(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
|
2011-08-05 00:45:45 -07:00
|
|
|
{
|
|
|
|
Evas_Object *fobj = data;
|
|
|
|
Widget_Data *wd = elm_widget_data_get(fobj);
|
|
|
|
if (!wd) return;
|
|
|
|
if (wd->content != obj) return;
|
2011-08-09 21:35:31 -07:00
|
|
|
evas_object_event_callback_del_full(wd->content,
|
2011-08-05 00:45:45 -07:00
|
|
|
EVAS_CALLBACK_CHANGED_SIZE_HINTS,
|
|
|
|
_child_change, obj);
|
2011-08-09 21:35:31 -07:00
|
|
|
evas_object_event_callback_del_full(wd->content,
|
2011-08-05 00:45:45 -07:00
|
|
|
EVAS_CALLBACK_DEL,
|
|
|
|
_child_del, obj);
|
|
|
|
wd->content = NULL;
|
2011-08-29 05:52:41 -07:00
|
|
|
fac--;
|
2013-06-04 22:40:03 -07:00
|
|
|
// DBG("FAC-- = %i", fac);
|
2011-08-05 00:45:45 -07:00
|
|
|
}
|
|
|
|
|
2012-02-14 20:55:43 -08:00
|
|
|
static Evas_Object *
|
|
|
|
_content_unset_hook(Evas_Object *obj, const char *part)
|
|
|
|
{
|
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype) NULL;
|
|
|
|
Widget_Data *wd;
|
|
|
|
Evas_Object *content;
|
|
|
|
|
|
|
|
if (part && strcmp(part, "default")) return NULL;
|
|
|
|
wd = elm_widget_data_get(obj);
|
|
|
|
if (!wd || !wd->content) return NULL;
|
|
|
|
|
|
|
|
content = wd->content;
|
|
|
|
evas_object_event_callback_del_full(content,
|
|
|
|
EVAS_CALLBACK_CHANGED_SIZE_HINTS,
|
|
|
|
_child_change, obj);
|
|
|
|
evas_object_event_callback_del_full(content,
|
|
|
|
EVAS_CALLBACK_DEL,
|
|
|
|
_child_del, obj);
|
|
|
|
wd->content = NULL;
|
|
|
|
fac--;
|
2013-06-04 22:40:03 -07:00
|
|
|
// DBG("FAC-- = %i", fac);
|
2012-02-14 20:55:43 -08:00
|
|
|
return content;
|
|
|
|
}
|
|
|
|
|
2011-10-28 21:32:24 -07:00
|
|
|
static void
|
2011-11-16 04:51:53 -08:00
|
|
|
_content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content)
|
2011-08-05 00:45:45 -07:00
|
|
|
{
|
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype);
|
2011-11-16 04:51:53 -08:00
|
|
|
Widget_Data *wd;
|
2012-02-14 20:55:43 -08:00
|
|
|
Evas_Object *prev_content;
|
2011-11-16 04:51:53 -08:00
|
|
|
|
|
|
|
if (part && strcmp(part, "default")) return;
|
|
|
|
wd = elm_widget_data_get(obj);
|
2011-08-05 00:45:45 -07:00
|
|
|
if (!wd) return;
|
|
|
|
if (wd->content == content) return;
|
2012-02-14 20:55:43 -08:00
|
|
|
|
|
|
|
prev_content = _content_unset_hook(obj, part);
|
2014-01-21 17:38:55 -08:00
|
|
|
evas_object_del(prev_content);
|
2012-02-14 20:55:43 -08:00
|
|
|
|
2011-08-05 00:45:45 -07:00
|
|
|
wd->content = content;
|
2012-02-14 20:55:43 -08:00
|
|
|
if (!content) return;
|
|
|
|
|
2013-10-16 08:54:54 -07:00
|
|
|
elm_widget_resize_object_set(obj, content, EINA_TRUE);
|
2012-02-14 20:55:43 -08:00
|
|
|
evas_object_event_callback_add(content, EVAS_CALLBACK_DEL, _child_del, obj);
|
|
|
|
evas_object_event_callback_add(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
|
|
|
|
_child_change, obj);
|
|
|
|
wd->eval = EINA_TRUE;
|
|
|
|
wd->szeval = EINA_TRUE;
|
|
|
|
evas_object_smart_changed(obj);
|
|
|
|
fac++;
|
2011-08-05 00:45:45 -07:00
|
|
|
}
|
|
|
|
|
2011-10-28 21:32:24 -07:00
|
|
|
static Evas_Object *
|
2011-11-16 04:51:53 -08:00
|
|
|
_content_get_hook(const Evas_Object *obj, const char *part)
|
2011-08-05 00:45:45 -07:00
|
|
|
{
|
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype) NULL;
|
2011-11-16 04:51:53 -08:00
|
|
|
Widget_Data *wd;
|
|
|
|
if (part && strcmp(part, "default")) return NULL;
|
|
|
|
wd = elm_widget_data_get(obj);
|
2011-08-05 00:45:45 -07:00
|
|
|
if (!wd) return NULL;
|
|
|
|
return wd->content;
|
|
|
|
}
|
2011-08-29 05:52:41 -07:00
|
|
|
|
2011-10-28 21:32:24 -07:00
|
|
|
EAPI Evas_Object *
|
|
|
|
elm_factory_add(Evas_Object *parent)
|
|
|
|
{
|
|
|
|
Evas_Object *obj;
|
|
|
|
Evas *e;
|
|
|
|
Widget_Data *wd;
|
|
|
|
|
|
|
|
ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
|
|
|
|
|
|
|
|
ELM_SET_WIDTYPE(widtype, "factory");
|
|
|
|
elm_widget_type_set(obj, "factory");
|
|
|
|
elm_widget_sub_object_add(parent, obj);
|
|
|
|
elm_widget_data_set(obj, wd);
|
|
|
|
elm_widget_del_hook_set(obj, _del_hook);
|
|
|
|
elm_widget_focus_next_hook_set(obj, _focus_next_hook);
|
|
|
|
elm_widget_content_set_hook_set(obj, _content_set_hook);
|
|
|
|
elm_widget_content_get_hook_set(obj, _content_get_hook);
|
2012-02-14 20:55:43 -08:00
|
|
|
elm_widget_content_unset_hook_set(obj, _content_unset_hook);
|
2011-10-28 21:32:24 -07:00
|
|
|
elm_widget_can_focus_set(obj, EINA_FALSE);
|
|
|
|
elm_widget_changed_hook_set(obj, _changed);
|
|
|
|
|
|
|
|
evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _move, NULL);
|
|
|
|
evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, NULL);
|
|
|
|
|
|
|
|
evas_object_smart_callbacks_descriptions_set(obj, _signals);
|
|
|
|
|
|
|
|
wd->obj = obj;
|
|
|
|
wd->last_calc_count = -1;
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2011-08-29 05:52:41 -07:00
|
|
|
EAPI void
|
|
|
|
elm_factory_maxmin_mode_set(Evas_Object *obj, Eina_Bool enabled)
|
|
|
|
{
|
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype);
|
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
if (!wd) return;
|
|
|
|
wd->maxmin = !!enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI Eina_Bool
|
|
|
|
elm_factory_maxmin_mode_get(const Evas_Object *obj)
|
|
|
|
{
|
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
|
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
if (!wd) return EINA_FALSE;
|
|
|
|
return wd->maxmin;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void
|
|
|
|
elm_factory_maxmin_reset_set(Evas_Object *obj)
|
|
|
|
{
|
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype);
|
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
if (!wd) return;
|
|
|
|
wd->maxminw = 0;
|
|
|
|
wd->maxminh = 0;
|
|
|
|
wd->eval = EINA_TRUE;
|
|
|
|
wd->szeval = EINA_TRUE;
|
|
|
|
evas_object_smart_changed(obj);
|
|
|
|
}
|