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__);
30 static const char SIG_REALIZE[] = "realize";
31 static const char SIG_UNREALIZE[] = "unrealize";
33 static const Evas_Smart_Cb_Description _signals[] = {
42 _del_hook(Evas_Object *obj)
44 Widget_Data *wd = elm_widget_data_get(obj);
48 Evas_Object *o = wd->content;
50 evas_object_event_callback_del_full(o,
51 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
53 evas_object_event_callback_del_full(o,
59 // printf("FAC-- = %i\n", fac);
65 _focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
67 Widget_Data *wd = elm_widget_data_get(obj);
70 if ((!wd) || (!wd->content)) return EINA_FALSE;
72 return elm_widget_focus_next_get(cur, dir, next);
76 _sizing_eval(Evas_Object *obj)
78 Widget_Data *wd = elm_widget_data_get(obj);
79 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
82 if (!wd->content) return;
83 evas_object_size_hint_min_get(wd->content, &minw, &minh);
84 evas_object_size_hint_max_get(wd->content, &maxw, &maxh);
87 if (minw > wd->maxminw) wd->maxminw = minw;
88 if (minh > wd->maxminh) wd->maxminh = minh;
89 evas_object_size_hint_min_set(obj, wd->maxminw, wd->maxminh);
93 evas_object_size_hint_min_set(obj, minw, minh);
95 evas_object_size_hint_max_set(obj, maxw, maxh);
96 // printf("FAC SZ: %i %i | %i %i\n", minw, minh, maxw, maxh);
100 _eval(Evas_Object *obj)
102 Evas_Coord x, y, w, h, cvx, cvy, cvw, cvh;
103 Widget_Data *wd = elm_widget_data_get(obj);
106 evas_event_freeze(evas_object_evas_get(obj));
107 evas_object_geometry_get(obj, &x, &y, &w, &h);
110 evas_output_viewport_get(evas_object_evas_get(obj),
111 &cvx, &cvy, &cvw, &cvh);
112 if ((cvw < 1) || (cvh < 1)) return;
113 // need some fuzz value thats beyond the current viewport
114 // for now just make it the viewport * 3 in size (so 1 vp in each direction)
121 if (ELM_RECTS_INTERSECT(x, y, w, h, cvx, cvy, cvw, cvh))
125 // printf(" + %i %i %ix%i <> %i %i %ix%i\n", x, y, w, h, cvx, cvy, cvw, cvh);
126 evas_object_smart_callback_call(obj, SIG_REALIZE, NULL);
129 if (evas_object_smart_data_get(wd->content))
130 evas_object_smart_calculate(wd->content);
132 wd->last_calc_count =
133 evas_smart_objects_calculate_count_get(evas_object_evas_get(obj));
140 if (wd->last_calc_count !=
141 evas_smart_objects_calculate_count_get(evas_object_evas_get(obj)))
142 evas_object_smart_callback_call(obj, SIG_UNREALIZE, NULL);
145 evas_event_thaw(evas_object_evas_get(obj));
146 evas_event_thaw_eval(evas_object_evas_get(obj));
150 _changed(Evas_Object *obj)
152 Widget_Data *wd = elm_widget_data_get(obj);
157 wd->eval = EINA_FALSE;
162 wd->szeval = EINA_FALSE;
167 _move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
169 Widget_Data *wd = elm_widget_data_get(obj);
171 wd->eval = EINA_TRUE;
172 evas_object_smart_changed(obj);
176 _resize(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
178 Widget_Data *wd = elm_widget_data_get(obj);
180 wd->eval = EINA_TRUE;
181 evas_object_smart_changed(obj);
185 _child_change(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
187 Widget_Data *wd = elm_widget_data_get(data);
189 wd->eval = EINA_TRUE;
190 wd->szeval = EINA_TRUE;
191 evas_object_smart_changed(data);
195 _child_del(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
197 Evas_Object *fobj = data;
198 Widget_Data *wd = elm_widget_data_get(fobj);
200 if (wd->content != obj) return;
201 evas_object_event_callback_del_full(wd->content,
202 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
204 evas_object_event_callback_del_full(wd->content,
209 // printf("FAC-- = %i\n", fac);
213 elm_factory_add(Evas_Object *parent)
219 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
221 ELM_SET_WIDTYPE(widtype, "factory");
222 elm_widget_type_set(obj, "factory");
223 elm_widget_sub_object_add(parent, obj);
224 elm_widget_data_set(obj, wd);
225 elm_widget_del_hook_set(obj, _del_hook);
226 elm_widget_focus_next_hook_set(obj, _focus_next_hook);
227 elm_widget_can_focus_set(obj, EINA_FALSE);
228 elm_widget_changed_hook_set(obj, _changed);
230 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _move, NULL);
231 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, NULL);
233 evas_object_smart_callbacks_descriptions_set(obj, _signals);
236 wd->last_calc_count = -1;
241 elm_factory_content_set(Evas_Object *obj, Evas_Object *content)
243 ELM_CHECK_WIDTYPE(obj, widtype);
244 Widget_Data *wd = elm_widget_data_get(obj);
246 if (wd->content == content) return;
249 Evas_Object *o = wd->content;
251 evas_object_event_callback_del_full(wd->content,
252 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
254 evas_object_event_callback_del_full(wd->content,
260 // printf("FAC-- = %i\n", fac);
262 wd->content = content;
266 // printf("FAC++ = %i\n", fac);
267 elm_widget_resize_object_set(obj, wd->content);
268 evas_object_event_callback_add(wd->content, EVAS_CALLBACK_DEL,
270 evas_object_event_callback_add(wd->content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
272 wd->eval = EINA_TRUE;
273 wd->szeval = EINA_TRUE;
274 evas_object_smart_changed(obj);
279 elm_factory_content_get(const Evas_Object *obj)
281 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
282 Widget_Data *wd = elm_widget_data_get(obj);
283 if (!wd) return NULL;
288 elm_factory_maxmin_mode_set(Evas_Object *obj, Eina_Bool enabled)
290 ELM_CHECK_WIDTYPE(obj, widtype);
291 Widget_Data *wd = elm_widget_data_get(obj);
293 wd->maxmin = !!enabled;
297 elm_factory_maxmin_mode_get(const Evas_Object *obj)
299 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
300 Widget_Data *wd = elm_widget_data_get(obj);
301 if (!wd) return EINA_FALSE;
306 elm_factory_maxmin_reset_set(Evas_Object *obj)
308 ELM_CHECK_WIDTYPE(obj, widtype);
309 Widget_Data *wd = elm_widget_data_get(obj);
313 wd->eval = EINA_TRUE;
314 wd->szeval = EINA_TRUE;
315 evas_object_smart_changed(obj);