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, Evas_Object *content);
30 static Evas_Object *_content_get_hook(const Evas_Object *obj, const char *part);
31 static Evas_Object *_content_unset_hook(Evas_Object *obj, const char *part);
33 static const char SIG_REALIZE[] = "realize";
34 static const char SIG_UNREALIZE[] = "unrealize";
36 static const Evas_Smart_Cb_Description _signals[] = {
45 _del_hook(Evas_Object *obj)
47 Widget_Data *wd = elm_widget_data_get(obj);
51 Evas_Object *o = wd->content;
53 evas_object_event_callback_del_full(o,
54 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
56 evas_object_event_callback_del_full(o,
62 // printf("FAC-- = %i\n", fac);
68 _focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
70 Widget_Data *wd = elm_widget_data_get(obj);
73 if ((!wd) || (!wd->content)) return EINA_FALSE;
75 return elm_widget_focus_next_get(cur, dir, next);
79 _sizing_eval(Evas_Object *obj)
81 Widget_Data *wd = elm_widget_data_get(obj);
82 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
85 if (!wd->content) return;
86 evas_object_size_hint_min_get(wd->content, &minw, &minh);
87 evas_object_size_hint_max_get(wd->content, &maxw, &maxh);
90 if (minw > wd->maxminw) wd->maxminw = minw;
91 if (minh > wd->maxminh) wd->maxminh = minh;
92 evas_object_size_hint_min_set(obj, wd->maxminw, wd->maxminh);
96 evas_object_size_hint_min_set(obj, minw, minh);
98 evas_object_size_hint_max_set(obj, maxw, maxh);
99 // printf("FAC SZ: %i %i | %i %i\n", minw, minh, maxw, maxh);
103 _eval(Evas_Object *obj)
105 Evas_Coord x, y, w, h, cvx, cvy, cvw, cvh;
106 Widget_Data *wd = elm_widget_data_get(obj);
109 evas_event_freeze(evas_object_evas_get(obj));
110 evas_object_geometry_get(obj, &x, &y, &w, &h);
113 evas_output_viewport_get(evas_object_evas_get(obj),
114 &cvx, &cvy, &cvw, &cvh);
115 if ((cvw < 1) || (cvh < 1)) return;
116 // need some fuzz value thats beyond the current viewport
117 // for now just make it the viewport * 3 in size (so 1 vp in each direction)
124 if (ELM_RECTS_INTERSECT(x, y, w, h, cvx, cvy, cvw, cvh))
128 // printf(" + %i %i %ix%i <> %i %i %ix%i\n", x, y, w, h, cvx, cvy, cvw, cvh);
129 evas_object_smart_callback_call(obj, SIG_REALIZE, NULL);
132 if (evas_object_smart_data_get(wd->content))
133 evas_object_smart_calculate(wd->content);
135 wd->last_calc_count =
136 evas_smart_objects_calculate_count_get(evas_object_evas_get(obj));
143 if (wd->last_calc_count !=
144 evas_smart_objects_calculate_count_get(evas_object_evas_get(obj)))
145 evas_object_smart_callback_call(obj, SIG_UNREALIZE, NULL);
148 evas_event_thaw(evas_object_evas_get(obj));
149 evas_event_thaw_eval(evas_object_evas_get(obj));
153 _changed(Evas_Object *obj)
155 Widget_Data *wd = elm_widget_data_get(obj);
160 wd->eval = EINA_FALSE;
165 wd->szeval = EINA_FALSE;
170 _move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
172 Widget_Data *wd = elm_widget_data_get(obj);
174 wd->eval = EINA_TRUE;
175 evas_object_smart_changed(obj);
179 _resize(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
181 Widget_Data *wd = elm_widget_data_get(obj);
183 wd->eval = EINA_TRUE;
184 evas_object_smart_changed(obj);
188 _child_change(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
190 Widget_Data *wd = elm_widget_data_get(data);
192 wd->eval = EINA_TRUE;
193 wd->szeval = EINA_TRUE;
194 evas_object_smart_changed(data);
198 _child_del(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
200 Evas_Object *fobj = data;
201 Widget_Data *wd = elm_widget_data_get(fobj);
203 if (wd->content != obj) return;
204 evas_object_event_callback_del_full(wd->content,
205 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
207 evas_object_event_callback_del_full(wd->content,
212 // printf("FAC-- = %i\n", fac);
216 _content_unset_hook(Evas_Object *obj, const char *part)
218 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
220 Evas_Object *content;
222 if (part && strcmp(part, "default")) return NULL;
223 wd = elm_widget_data_get(obj);
224 if (!wd || !wd->content) return NULL;
226 content = wd->content;
227 evas_object_event_callback_del_full(content,
228 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
230 evas_object_event_callback_del_full(content,
235 // printf("FAC-- = %i\n", fac);
240 _content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content)
242 ELM_CHECK_WIDTYPE(obj, widtype);
244 Evas_Object *prev_content;
246 if (part && strcmp(part, "default")) return;
247 wd = elm_widget_data_get(obj);
249 if (wd->content == content) return;
251 prev_content = _content_unset_hook(obj, part);
252 if (prev_content) evas_object_del(prev_content);
254 wd->content = content;
255 if (!content) return;
257 elm_widget_resize_object_set(obj, content);
258 evas_object_event_callback_add(content, EVAS_CALLBACK_DEL, _child_del, obj);
259 evas_object_event_callback_add(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
261 wd->eval = EINA_TRUE;
262 wd->szeval = EINA_TRUE;
263 evas_object_smart_changed(obj);
268 _content_get_hook(const Evas_Object *obj, const char *part)
270 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
272 if (part && strcmp(part, "default")) return NULL;
273 wd = elm_widget_data_get(obj);
274 if (!wd) return NULL;
279 elm_factory_add(Evas_Object *parent)
285 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
287 ELM_SET_WIDTYPE(widtype, "factory");
288 elm_widget_type_set(obj, "factory");
289 elm_widget_sub_object_add(parent, obj);
290 elm_widget_data_set(obj, wd);
291 elm_widget_del_hook_set(obj, _del_hook);
292 elm_widget_focus_next_hook_set(obj, _focus_next_hook);
293 elm_widget_content_set_hook_set(obj, _content_set_hook);
294 elm_widget_content_get_hook_set(obj, _content_get_hook);
295 elm_widget_content_unset_hook_set(obj, _content_unset_hook);
296 elm_widget_can_focus_set(obj, EINA_FALSE);
297 elm_widget_changed_hook_set(obj, _changed);
299 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _move, NULL);
300 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, NULL);
302 evas_object_smart_callbacks_descriptions_set(obj, _signals);
305 wd->last_calc_count = -1;
310 elm_factory_maxmin_mode_set(Evas_Object *obj, Eina_Bool enabled)
312 ELM_CHECK_WIDTYPE(obj, widtype);
313 Widget_Data *wd = elm_widget_data_get(obj);
315 wd->maxmin = !!enabled;
319 elm_factory_maxmin_mode_get(const Evas_Object *obj)
321 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
322 Widget_Data *wd = elm_widget_data_get(obj);
323 if (!wd) return EINA_FALSE;
328 elm_factory_maxmin_reset_set(Evas_Object *obj)
330 ELM_CHECK_WIDTYPE(obj, widtype);
331 Widget_Data *wd = elm_widget_data_get(obj);
335 wd->eval = EINA_TRUE;
336 wd->szeval = EINA_TRUE;
337 evas_object_smart_changed(obj);