1 #include <Elementary.h>
4 typedef struct _Widget_Data Widget_Data;
14 static const char *widtype = NULL;
15 static void _del_hook(Evas_Object *obj);
16 static Eina_Bool _focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next);
17 static void _sizing_eval(Evas_Object *obj);
18 static void _eval(Evas_Object *obj);
19 static void _changed(Evas_Object *obj);
20 static void _move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__);
21 static void _resize(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__);
22 static void _child_change(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__);
23 static void _child_del(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__);
25 static const char SIG_REALIZE[] = "realize";
26 static const char SIG_UNREALIZE[] = "unrealize";
28 static const Evas_Smart_Cb_Description _signals[] = {
35 _del_hook(Evas_Object *obj)
37 Widget_Data *wd = elm_widget_data_get(obj);
43 _focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
45 Widget_Data *wd = elm_widget_data_get(obj);
48 if ((!wd) || (!wd->content)) return EINA_FALSE;
50 return elm_widget_focus_next_get(cur, dir, next);
54 _sizing_eval(Evas_Object *obj)
56 Widget_Data *wd = elm_widget_data_get(obj);
57 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
60 if (!wd->content) return;
61 evas_object_size_hint_min_get(wd->content, &minw, &minh);
62 evas_object_size_hint_max_get(wd->content, &maxw, &maxh);
63 evas_object_size_hint_min_set(obj, minw, minh);
64 evas_object_size_hint_max_set(obj, 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_event_freeze(evas_object_evas_get(obj));
75 evas_object_geometry_get(obj, &x, &y, &w, &h);
78 evas_output_viewport_get(evas_object_evas_get(obj),
79 &cvx, &cvy, &cvw, &cvh);
80 if ((cvw < 1) || (cvh < 1)) return;
81 // need some fuzz value thats beyond the current viewport
82 // for now just make it the viewport * 3 in size (so 1 vp in each direction)
89 if (ELM_RECTS_INTERSECT(x, y, w, h, cvx, cvy, cvw, cvh))
93 evas_object_smart_callback_call(obj, SIG_REALIZE, NULL);
96 if (evas_object_smart_data_get(wd->content))
97 evas_object_smart_calculate(wd->content);
100 evas_smart_objects_calculate_count_get(evas_object_evas_get(obj));
107 if (wd->last_calc_count !=
108 evas_smart_objects_calculate_count_get(evas_object_evas_get(obj)))
109 evas_object_smart_callback_call(obj, SIG_UNREALIZE, NULL);
112 evas_event_thaw(evas_object_evas_get(obj));
113 evas_event_thaw_eval(evas_object_evas_get(obj));
117 _changed(Evas_Object *obj)
119 Widget_Data *wd = elm_widget_data_get(obj);
125 wd->eval = EINA_FALSE;
130 _move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
132 Widget_Data *wd = elm_widget_data_get(obj);
134 wd->eval = EINA_TRUE;
135 evas_object_smart_changed(obj);
139 _resize(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
141 Widget_Data *wd = elm_widget_data_get(obj);
143 wd->eval = EINA_TRUE;
144 evas_object_smart_changed(obj);
148 _child_change(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
150 Widget_Data *wd = elm_widget_data_get(data);
152 wd->eval = EINA_TRUE;
153 evas_object_smart_changed(data);
157 _child_del(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
159 Evas_Object *fobj = data;
160 Widget_Data *wd = elm_widget_data_get(fobj);
162 if (wd->content != obj) return;
163 evas_object_event_callback_del_full(wd->content,
164 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
166 evas_object_event_callback_del_full(wd->content,
173 elm_factory_add(Evas_Object *parent)
179 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
181 ELM_SET_WIDTYPE(widtype, "factory");
182 elm_widget_type_set(obj, "factory");
183 elm_widget_sub_object_add(parent, obj);
184 elm_widget_data_set(obj, wd);
185 elm_widget_del_hook_set(obj, _del_hook);
186 elm_widget_focus_next_hook_set(obj, _focus_next_hook);
187 elm_widget_can_focus_set(obj, EINA_FALSE);
188 elm_widget_changed_hook_set(obj, _changed);
190 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _move, NULL);
191 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, NULL);
193 evas_object_smart_callbacks_descriptions_set(obj, _signals);
196 wd->last_calc_count = -1;
201 elm_factory_content_set(Evas_Object *obj, Evas_Object *content)
203 ELM_CHECK_WIDTYPE(obj, widtype);
204 Widget_Data *wd = elm_widget_data_get(obj);
206 if (wd->content == content) return;
207 if (wd->content) evas_object_del(wd->content);
208 wd->content = content;
209 elm_widget_resize_object_set(obj, wd->content);
210 evas_object_event_callback_add(wd->content, EVAS_CALLBACK_DEL,
212 evas_object_event_callback_add(wd->content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
214 wd->eval = EINA_TRUE;
215 evas_object_smart_changed(obj);
219 elm_factory_content_get(const Evas_Object *obj)
221 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
222 Widget_Data *wd = elm_widget_data_get(obj);
223 if (!wd) return NULL;