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 _show_hook(void *data, Evas *e, Evas_Object *obj, void *event_info);
37 static void _hide_hook(void *data, Evas *e, Evas_Object *obj, void *event_info);
38 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
41 _del_hook(Evas_Object *obj)
43 Widget_Data *wd = elm_widget_data_get(obj);
46 EINA_LIST_FREE(wd->subs, si)
48 eina_stringshare_del(si->swallow);
55 _theme_hook(Evas_Object *obj)
57 Widget_Data *wd = elm_widget_data_get(obj);
60 _elm_theme_object_set(obj, wd->lay, wd->clas, wd->group, wd->style);
61 edje_object_scale_set(wd->lay, elm_widget_scale_get(obj) *
67 _changed_hook(Evas_Object *obj)
69 Widget_Data *wd = elm_widget_data_get(obj);
71 if (wd->needs_size_calc)
74 wd->needs_size_calc = 0;
79 _show_hook(void *data, Evas *e, Evas_Object *obj, void *event_info)
81 Widget_Data *wd = elm_widget_data_get(obj);
85 EINA_LIST_FOREACH(wd->subs, l, si)
87 evas_object_show(si->obj);
92 _hide_hook(void *data, Evas *e, Evas_Object *obj, void *event_info)
94 Widget_Data *wd = elm_widget_data_get(obj);
98 EINA_LIST_FOREACH(wd->subs, l, si)
100 evas_object_hide(si->obj);
105 _sizing_eval(Evas_Object *obj)
107 Widget_Data *wd = elm_widget_data_get(obj);
108 Evas_Coord minw = -1, minh = -1;
110 edje_object_size_min_calc(wd->lay, &minw, &minh);
111 evas_object_size_hint_min_set(obj, minw, minh);
112 evas_object_size_hint_max_set(obj, -1, -1);
116 _request_sizing_eval(Evas_Object *obj)
118 Widget_Data *wd = elm_widget_data_get(obj);
120 if (wd->needs_size_calc) return;
121 wd->needs_size_calc = 1;
122 evas_object_smart_changed(obj);
126 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
128 _request_sizing_eval(data);
132 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
134 Widget_Data *wd = elm_widget_data_get(obj);
135 Evas_Object *sub = event_info;
139 EINA_LIST_FOREACH(wd->subs, l, si)
143 evas_object_event_callback_del_full(sub,
144 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
147 wd->subs = eina_list_remove_list(wd->subs, l);
148 eina_stringshare_del(si->swallow);
156 _signal_size_eval(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
158 _request_sizing_eval(data);
162 * Add a new layout to the parent
164 * @param parent The parent object
165 * @return The new object or NULL if it cannot be created
170 elm_layout_add(Evas_Object *parent)
176 wd = ELM_NEW(Widget_Data);
177 e = evas_object_evas_get(parent);
178 obj = elm_widget_add(e);
179 ELM_SET_WIDTYPE(widtype, "layout");
180 elm_widget_type_set(obj, "layout");
181 elm_widget_sub_object_add(parent, obj);
182 elm_widget_data_set(obj, wd);
183 elm_widget_del_hook_set(obj, _del_hook);
184 elm_widget_theme_hook_set(obj, _theme_hook);
185 elm_widget_changed_hook_set(obj, _changed_hook);
187 wd->lay = edje_object_add(e);
188 elm_widget_resize_object_set(obj, wd->lay);
189 edje_object_signal_callback_add(wd->lay, "size,eval", "elm",
190 _signal_size_eval, obj);
191 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
192 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _hide_hook, obj);
193 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _show_hook, obj);
195 _request_sizing_eval(obj);
200 * Set the file that will be used as layout
202 * @param obj The layout object
203 * @param file The path to file (edj) that will be used as layout
204 * @param group The group that the layout belongs in edje file
206 * @return (1 = sucess, 0 = error)
211 elm_layout_file_set(Evas_Object *obj, const char *file, const char *group)
213 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
214 Widget_Data *wd = elm_widget_data_get(obj);
215 if (!wd) return EINA_FALSE;
216 Eina_Bool ret = edje_object_file_set(wd->lay, file, group);
217 if (ret) _request_sizing_eval(obj);
222 * Set the edje group from the elementary theme that will be used as layout
224 * @param obj The layout object
225 * @param clas the clas of the group
226 * @param group the group
227 * @param style the style to used
229 * @return (1 = sucess, 0 = error)
234 elm_layout_theme_set(Evas_Object *obj, const char *clas, const char *group, const char *style)
236 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
237 Widget_Data *wd = elm_widget_data_get(obj);
238 if (!wd) return EINA_FALSE;
239 Eina_Bool ret = _elm_theme_object_set(obj, wd->lay, clas, group, style);
243 if (ret) _request_sizing_eval(obj);
248 * Set the layout content
250 * @param obj The layout object
251 * @param swallow The swallow group name in the edje file
252 * @param content The content will be filled in this layout object
257 elm_layout_content_set(Evas_Object *obj, const char *swallow, Evas_Object *content)
259 ELM_CHECK_WIDTYPE(obj, widtype);
260 Widget_Data *wd = elm_widget_data_get(obj);
264 EINA_LIST_FOREACH(wd->subs, l, si)
266 if (!strcmp(swallow, si->swallow))
268 if (content == si->obj) return;
269 elm_widget_sub_object_del(obj, si->obj);
275 elm_widget_sub_object_add(obj, content);
276 evas_object_event_callback_add(content,
277 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
278 _changed_size_hints, obj);
279 edje_object_part_swallow(wd->lay, swallow, content);
280 si = ELM_NEW(Subinfo);
281 si->swallow = eina_stringshare_add(swallow);
283 wd->subs = eina_list_append(wd->subs, si);
284 _request_sizing_eval(obj);
289 * Unset the layout content
291 * Unparent and return the content object which was set for this widget
293 * @param obj The layout object
294 * @param swallow The swallow group name in the edje file
295 * @return The content that was being used
300 elm_layout_content_unset(Evas_Object *obj, const char *swallow)
302 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
303 Widget_Data *wd = elm_widget_data_get(obj);
306 if (!wd) return NULL;
307 EINA_LIST_FOREACH(wd->subs, l, si)
309 if (!strcmp(swallow, si->swallow))
311 Evas_Object *content;
312 if (!si->obj) return NULL;
313 content = si->obj; /* si will die in _sub_del due elm_widget_sub_object_del() */
314 elm_widget_sub_object_del(obj, content);
315 edje_object_part_unswallow(wd->lay, content);
323 * Get the edje layout
325 * @param obj The layout object
327 * This returns the edje object. It is not expected to be used to then swallow
328 * objects via edje_object_part_swallow() for example. Use
329 * elm_layout_content_set() instead so child object handling and sizing is
330 * done properly. This is more intended for setting text, emitting signals,
331 * hooking to singal callbacks etc.
333 * @return A Evas_Object with the edje layout settings loaded
334 * with function elm_layout_file_set
339 elm_layout_edje_get(const Evas_Object *obj)
341 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
342 Widget_Data *wd = elm_widget_data_get(obj);
343 if (!wd) return NULL;
348 * Get the edje layout
350 * Manually forms a sizing re-evaluation when contents changed state so that
351 * minimum size might have changed and needs re-evaluation. Also note that
352 * a standard signal of "size,eval" "elm" emitted by the edje object will
353 * cause this to happen too
355 * @param obj The layout object
360 elm_layout_sizing_eval(Evas_Object *obj)
362 ELM_CHECK_WIDTYPE(obj, widtype);
363 _request_sizing_eval(obj);