1 #include <Elementary.h>
4 // FIXME: handle if canvas resizes
6 typedef struct _Widget_Data Widget_Data;
13 Evas_Coord maxminw, maxminh;
19 static const char *widtype = NULL;
20 static void _del_hook(Evas_Object *obj);
21 static Eina_Bool _focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next);
22 static void _sizing_eval(Evas_Object *obj);
23 static void _eval(Evas_Object *obj);
24 static void _changed(Evas_Object *obj);
25 static void _move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__);
26 static void _resize(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__);
27 static void _child_change(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__);
28 static void _child_del(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__);
29 static void _content_set_hook(Evas_Object *obj, const char *part __UNUSED__, Evas_Object *content);
30 static Evas_Object *_content_get_hook(const Evas_Object *obj, const char *part __UNUSED__);
32 static const char SIG_REALIZE[] = "realize";
33 static const char SIG_UNREALIZE[] = "unrealize";
35 static const Evas_Smart_Cb_Description _signals[] = {
44 _del_hook(Evas_Object *obj)
46 Widget_Data *wd = elm_widget_data_get(obj);
50 Evas_Object *o = wd->content;
52 evas_object_event_callback_del_full(o,
53 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
55 evas_object_event_callback_del_full(o,
61 // printf("FAC-- = %i\n", fac);
67 _focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
69 Widget_Data *wd = elm_widget_data_get(obj);
72 if ((!wd) || (!wd->content)) return EINA_FALSE;
74 return elm_widget_focus_next_get(cur, dir, next);
78 _sizing_eval(Evas_Object *obj)
80 Widget_Data *wd = elm_widget_data_get(obj);
81 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
84 if (!wd->content) return;
85 evas_object_size_hint_min_get(wd->content, &minw, &minh);
86 evas_object_size_hint_max_get(wd->content, &maxw, &maxh);
89 if (minw > wd->maxminw) wd->maxminw = minw;
90 if (minh > wd->maxminh) wd->maxminh = minh;
91 evas_object_size_hint_min_set(obj, wd->maxminw, wd->maxminh);
95 evas_object_size_hint_min_set(obj, minw, minh);
97 evas_object_size_hint_max_set(obj, maxw, maxh);
98 // printf("FAC SZ: %i %i | %i %i\n", minw, minh, maxw, maxh);
102 _eval(Evas_Object *obj)
104 Evas_Coord x, y, w, h, cvx, cvy, cvw, cvh;
105 Widget_Data *wd = elm_widget_data_get(obj);
108 evas_event_freeze(evas_object_evas_get(obj));
109 evas_object_geometry_get(obj, &x, &y, &w, &h);
112 evas_output_viewport_get(evas_object_evas_get(obj),
113 &cvx, &cvy, &cvw, &cvh);
114 if ((cvw < 1) || (cvh < 1)) return;
115 // need some fuzz value thats beyond the current viewport
116 // for now just make it the viewport * 3 in size (so 1 vp in each direction)
123 if (ELM_RECTS_INTERSECT(x, y, w, h, cvx, cvy, cvw, cvh))
127 // printf(" + %i %i %ix%i <> %i %i %ix%i\n", x, y, w, h, cvx, cvy, cvw, cvh);
128 evas_object_smart_callback_call(obj, SIG_REALIZE, NULL);
131 if (evas_object_smart_data_get(wd->content))
132 evas_object_smart_calculate(wd->content);
134 wd->last_calc_count =
135 evas_smart_objects_calculate_count_get(evas_object_evas_get(obj));
142 if (wd->last_calc_count !=
143 evas_smart_objects_calculate_count_get(evas_object_evas_get(obj)))
144 evas_object_smart_callback_call(obj, SIG_UNREALIZE, NULL);
147 evas_event_thaw(evas_object_evas_get(obj));
148 evas_event_thaw_eval(evas_object_evas_get(obj));
152 _changed(Evas_Object *obj)
154 Widget_Data *wd = elm_widget_data_get(obj);
159 wd->eval = EINA_FALSE;
164 wd->szeval = EINA_FALSE;
169 _move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
171 Widget_Data *wd = elm_widget_data_get(obj);
173 wd->eval = EINA_TRUE;
174 evas_object_smart_changed(obj);
178 _resize(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
180 Widget_Data *wd = elm_widget_data_get(obj);
182 wd->eval = EINA_TRUE;
183 evas_object_smart_changed(obj);
187 _child_change(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
189 Widget_Data *wd = elm_widget_data_get(data);
191 wd->eval = EINA_TRUE;
192 wd->szeval = EINA_TRUE;
193 evas_object_smart_changed(data);
197 _child_del(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
199 Evas_Object *fobj = data;
200 Widget_Data *wd = elm_widget_data_get(fobj);
202 if (wd->content != obj) return;
203 evas_object_event_callback_del_full(wd->content,
204 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
206 evas_object_event_callback_del_full(wd->content,
211 // printf("FAC-- = %i\n", fac);
215 _content_set_hook(Evas_Object *obj, const char *part __UNUSED__, Evas_Object *content)
217 ELM_CHECK_WIDTYPE(obj, widtype);
218 Widget_Data *wd = elm_widget_data_get(obj);
220 if (wd->content == content) return;
223 Evas_Object *o = wd->content;
225 evas_object_event_callback_del_full(wd->content,
226 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
228 evas_object_event_callback_del_full(wd->content,
234 // printf("FAC-- = %i\n", fac);
236 wd->content = content;
240 // printf("FAC++ = %i\n", fac);
241 elm_widget_resize_object_set(obj, wd->content);
242 evas_object_event_callback_add(wd->content, EVAS_CALLBACK_DEL,
244 evas_object_event_callback_add(wd->content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
246 wd->eval = EINA_TRUE;
247 wd->szeval = EINA_TRUE;
248 evas_object_smart_changed(obj);
253 _content_get_hook(const Evas_Object *obj, const char *part __UNUSED__)
255 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
256 Widget_Data *wd = elm_widget_data_get(obj);
257 if (!wd) return NULL;
262 elm_factory_add(Evas_Object *parent)
268 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
270 ELM_SET_WIDTYPE(widtype, "factory");
271 elm_widget_type_set(obj, "factory");
272 elm_widget_sub_object_add(parent, obj);
273 elm_widget_data_set(obj, wd);
274 elm_widget_del_hook_set(obj, _del_hook);
275 elm_widget_focus_next_hook_set(obj, _focus_next_hook);
276 elm_widget_content_set_hook_set(obj, _content_set_hook);
277 elm_widget_content_get_hook_set(obj, _content_get_hook);
278 elm_widget_can_focus_set(obj, EINA_FALSE);
279 elm_widget_changed_hook_set(obj, _changed);
281 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _move, NULL);
282 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, NULL);
284 evas_object_smart_callbacks_descriptions_set(obj, _signals);
287 wd->last_calc_count = -1;
292 elm_factory_content_set(Evas_Object *obj, Evas_Object *content)
294 _content_set_hook(obj, NULL, content);
298 elm_factory_content_get(const Evas_Object *obj)
300 return _content_get_hook(obj, NULL);
304 elm_factory_maxmin_mode_set(Evas_Object *obj, Eina_Bool enabled)
306 ELM_CHECK_WIDTYPE(obj, widtype);
307 Widget_Data *wd = elm_widget_data_get(obj);
309 wd->maxmin = !!enabled;
313 elm_factory_maxmin_mode_get(const Evas_Object *obj)
315 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
316 Widget_Data *wd = elm_widget_data_get(obj);
317 if (!wd) return EINA_FALSE;
322 elm_factory_maxmin_reset_set(Evas_Object *obj)
324 ELM_CHECK_WIDTYPE(obj, widtype);
325 Widget_Data *wd = elm_widget_data_get(obj);
329 wd->eval = EINA_TRUE;
330 wd->szeval = EINA_TRUE;
331 evas_object_smart_changed(obj);