1 #include <Elementary.h>
5 * @defgroup Layout Layout
8 * This takes a standard Edje design file and wraps it very thinly
9 * in a widget and handles swallowing widgets into swallow regions
10 * in the Edje object, allowing Edje to be used as a design and
14 typedef struct _Widget_Data Widget_Data;
15 typedef struct _Subinfo Subinfo;
21 Eina_Bool needs_size_calc:1;
22 const char *clas, *group, *style;
31 static const char *widtype = NULL;
32 static void _del_hook(Evas_Object *obj);
33 static void _theme_hook(Evas_Object *obj);
34 static void _sizing_eval(Evas_Object *obj);
35 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
36 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
39 _del_hook(Evas_Object *obj)
41 Widget_Data *wd = elm_widget_data_get(obj);
44 EINA_LIST_FREE(wd->subs, si)
46 eina_stringshare_del(si->swallow);
53 _theme_hook(Evas_Object *obj)
55 Widget_Data *wd = elm_widget_data_get(obj);
58 _elm_theme_object_set(obj, wd->lay, wd->clas, wd->group, wd->style);
59 edje_object_scale_set(wd->lay, elm_widget_scale_get(obj) *
65 _changed_hook(Evas_Object *obj)
67 Widget_Data *wd = elm_widget_data_get(obj);
69 if (wd->needs_size_calc)
72 wd->needs_size_calc = 0;
77 _sizing_eval(Evas_Object *obj)
79 Widget_Data *wd = elm_widget_data_get(obj);
80 Evas_Coord minw = -1, minh = -1;
82 edje_object_size_min_calc(wd->lay, &minw, &minh);
83 evas_object_size_hint_min_set(obj, minw, minh);
84 evas_object_size_hint_max_set(obj, -1, -1);
88 _request_sizing_eval(Evas_Object *obj)
90 Widget_Data *wd = elm_widget_data_get(obj);
92 if (wd->needs_size_calc) return;
93 wd->needs_size_calc = 1;
94 evas_object_smart_changed(obj);
98 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
100 _request_sizing_eval(data);
104 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
106 Widget_Data *wd = elm_widget_data_get(obj);
107 Evas_Object *sub = event_info;
111 EINA_LIST_FOREACH(wd->subs, l, si)
115 evas_object_event_callback_del_full(sub,
116 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
119 wd->subs = eina_list_remove_list(wd->subs, l);
120 eina_stringshare_del(si->swallow);
128 _signal_size_eval(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
130 _request_sizing_eval(data);
134 * Add a new layout to the parent
136 * @param parent The parent object
137 * @return The new object or NULL if it cannot be created
142 elm_layout_add(Evas_Object *parent)
148 wd = ELM_NEW(Widget_Data);
149 e = evas_object_evas_get(parent);
150 obj = elm_widget_add(e);
151 ELM_SET_WIDTYPE(widtype, "layout");
152 elm_widget_type_set(obj, "layout");
153 elm_widget_sub_object_add(parent, obj);
154 elm_widget_data_set(obj, wd);
155 elm_widget_del_hook_set(obj, _del_hook);
156 elm_widget_theme_hook_set(obj, _theme_hook);
157 elm_widget_changed_hook_set(obj, _changed_hook);
159 wd->lay = edje_object_add(e);
160 elm_widget_resize_object_set(obj, wd->lay);
161 edje_object_signal_callback_add(wd->lay, "size,eval", "elm",
162 _signal_size_eval, obj);
164 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
166 _request_sizing_eval(obj);
171 * Set the file that will be used as layout
173 * @param obj The layout object
174 * @param file The path to file (edj) that will be used as layout
175 * @param group The group that the layout belongs in edje file
177 * @return (1 = sucess, 0 = error)
182 elm_layout_file_set(Evas_Object *obj, const char *file, const char *group)
184 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
185 Widget_Data *wd = elm_widget_data_get(obj);
186 if (!wd) return EINA_FALSE;
187 Eina_Bool ret = edje_object_file_set(wd->lay, file, group);
188 if (ret) _request_sizing_eval(obj);
193 * Set the edje group from the elementary theme that will be used as layout
195 * @param obj The layout object
196 * @param clas the clas of the group
197 * @param group the group
198 * @param style the style to used
200 * @return (1 = sucess, 0 = error)
205 elm_layout_theme_set(Evas_Object *obj, const char *clas, const char *group, const char *style)
207 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
208 Widget_Data *wd = elm_widget_data_get(obj);
209 if (!wd) return EINA_FALSE;
210 Eina_Bool ret = _elm_theme_object_set(obj, wd->lay, clas, group, style);
214 if (ret) _request_sizing_eval(obj);
219 * Set the layout content
221 * @param obj The layout object
222 * @param swallow The swallow group name in the edje file
223 * @param content The content will be filled in this layout object
228 elm_layout_content_set(Evas_Object *obj, const char *swallow, Evas_Object *content)
230 ELM_CHECK_WIDTYPE(obj, widtype);
231 Widget_Data *wd = elm_widget_data_get(obj);
235 EINA_LIST_FOREACH(wd->subs, l, si)
237 if (!strcmp(swallow, si->swallow))
239 if (content == si->obj) return;
240 elm_widget_sub_object_del(obj, si->obj);
246 elm_widget_sub_object_add(obj, content);
247 evas_object_event_callback_add(content,
248 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
249 _changed_size_hints, obj);
250 edje_object_part_swallow(wd->lay, swallow, content);
251 si = ELM_NEW(Subinfo);
252 si->swallow = eina_stringshare_add(swallow);
254 wd->subs = eina_list_append(wd->subs, si);
255 _request_sizing_eval(obj);
260 * Get the edje layout
262 * @param obj The layout object
264 * This returns the edje object. It is not expected to be used to then swallow
265 * objects via edje_object_part_swallow() for example. Use
266 * elm_layout_content_set() instead so child object handling and sizing is
267 * done properly. This is more intended for setting text, emitting signals,
268 * hooking to singal callbacks etc.
270 * @return A Evas_Object with the edje layout settings loaded
271 * with function elm_layout_file_set
276 elm_layout_edje_get(const Evas_Object *obj)
278 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
279 Widget_Data *wd = elm_widget_data_get(obj);
280 if (!wd) return NULL;
285 * Get the edje layout
287 * Manually forms a sizing re-evaluation when contents changed state so that
288 * minimum size might have changed and needs re-evaluation. Also note that
289 * a standard signal of "size,eval" "elm" emitted by the edje object will
290 * cause this to happen too
292 * @param obj The layout object
297 elm_layout_sizing_eval(Evas_Object *obj)
299 ELM_CHECK_WIDTYPE(obj, widtype);
300 _request_sizing_eval(obj);