1 #include <Elementary.h>
4 typedef struct _Widget_Data Widget_Data;
13 static const char *widtype = NULL;
14 static void _del_hook(Evas_Object *obj);
15 static Eina_Bool _focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next);
16 static void _sizing_eval(Evas_Object *obj);
17 static void _eval(Evas_Object *obj);
18 static void _changed(Evas_Object *obj);
19 static void _move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__);
20 static void _resize(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__);
21 static void _child_change(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__);
22 static void _child_del(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__);
24 static const char SIG_REALIZE[] = "realize";
25 static const char SIG_UNREALIZE[] = "unrealize";
27 static const Evas_Smart_Cb_Description _signals[] = {
34 _del_hook(Evas_Object *obj)
36 Widget_Data *wd = elm_widget_data_get(obj);
42 _focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
44 Widget_Data *wd = elm_widget_data_get(obj);
47 if ((!wd) || (!wd->content)) return EINA_FALSE;
49 return elm_widget_focus_next_get(cur, dir, next);
53 _sizing_eval(Evas_Object *obj)
55 Widget_Data *wd = elm_widget_data_get(obj);
56 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
59 if (!wd->content) return;
60 evas_object_size_hint_min_get(wd->content, &minw, &minh);
61 evas_object_size_hint_max_get(wd->content, &maxw, &maxh);
62 evas_object_size_hint_min_set(obj, minw, minh);
63 evas_object_size_hint_max_set(obj, maxw, maxh);
64 printf("fac: %p, size %ix%i -> %ix%i\n", obj, minw, minh, maxw, maxh);
68 _eval(Evas_Object *obj)
70 Evas_Coord x, y, w, h, cvx, cvy, cvw, cvh;
71 Widget_Data *wd = elm_widget_data_get(obj);
74 evas_object_geometry_get(obj, &x, &y, &w, &h);
75 evas_output_viewport_get(evas_object_evas_get(obj),
76 &cvx, &cvy, &cvw, &cvh);
77 if ((w < 1) || (h < 1) || (cvw < 1) || (cvh < 1)) return;
78 if (ELM_RECTS_INTERSECT(x, y, w, h, cvx, cvy, cvw, cvh))
82 printf("intersect: %i %i %ix%i | %i %i %ix%i\n",
83 x, y, w, h, cvx, cvy, cvw, cvh);
84 evas_object_smart_callback_call(obj, SIG_REALIZE, NULL);
87 if (evas_object_smart_data_get(wd->content))
88 evas_object_smart_calculate(wd->content);
95 evas_object_smart_callback_call(obj, SIG_UNREALIZE, NULL);
100 _changed(Evas_Object *obj)
102 Widget_Data *wd = elm_widget_data_get(obj);
108 wd->eval = EINA_FALSE;
113 _move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
115 Widget_Data *wd = elm_widget_data_get(obj);
117 wd->eval = EINA_TRUE;
118 evas_object_smart_changed(obj);
122 _resize(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
124 Widget_Data *wd = elm_widget_data_get(obj);
126 wd->eval = EINA_TRUE;
127 evas_object_smart_changed(obj);
131 _child_change(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
133 Widget_Data *wd = elm_widget_data_get(data);
135 wd->eval = EINA_TRUE;
136 evas_object_smart_changed(data);
140 _child_del(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
142 Evas_Object *fobj = data;
143 Widget_Data *wd = elm_widget_data_get(fobj);
145 if (wd->content != obj) return;
146 evas_object_event_callback_del_full(wd->content,
147 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
149 evas_object_event_callback_del_full(wd->content,
156 elm_factory_add(Evas_Object *parent)
162 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
164 ELM_SET_WIDTYPE(widtype, "factory");
165 elm_widget_type_set(obj, "factory");
166 elm_widget_sub_object_add(parent, obj);
167 elm_widget_data_set(obj, wd);
168 elm_widget_del_hook_set(obj, _del_hook);
169 elm_widget_focus_next_hook_set(obj, _focus_next_hook);
170 elm_widget_can_focus_set(obj, EINA_FALSE);
171 elm_widget_changed_hook_set(obj, _changed);
173 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _move, NULL);
174 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, NULL);
176 evas_object_smart_callbacks_descriptions_set(obj, _signals);
183 elm_factory_content_set(Evas_Object *obj, Evas_Object *content)
185 ELM_CHECK_WIDTYPE(obj, widtype);
186 Widget_Data *wd = elm_widget_data_get(obj);
188 if (wd->content == content) return;
189 if (wd->content) evas_object_del(wd->content);
190 wd->content = content;
191 elm_widget_resize_object_set(obj, wd->content);
192 evas_object_event_callback_add(wd->content, EVAS_CALLBACK_DEL,
194 evas_object_event_callback_add(wd->content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
196 wd->eval = EINA_TRUE;
197 evas_object_smart_changed(obj);
201 elm_factory_content_get(const Evas_Object *obj)
203 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
204 Widget_Data *wd = elm_widget_data_get(obj);
205 if (!wd) return NULL;