1 #include <Elementary.h>
5 * @defgroup Layout Layout
7 * This takes a standard Edje design file and wraps it very thinly
8 * in a widget and handles swallowing widgets into swallow regions
9 * in the Edje object, allowing Edje to be used as a design and
13 typedef struct _Widget_Data Widget_Data;
14 typedef struct _Subinfo Subinfo;
20 Eina_Bool needs_size_calc:1;
29 static const char *widtype = NULL;
30 static void _del_hook(Evas_Object *obj);
31 static void _theme_hook(Evas_Object *obj);
32 static void _sizing_eval(Evas_Object *obj);
33 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
34 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
37 _del_hook(Evas_Object *obj)
39 Widget_Data *wd = elm_widget_data_get(obj);
42 EINA_LIST_FREE(wd->subs, si)
44 eina_stringshare_del(si->swallow);
51 _theme_hook(Evas_Object *obj)
53 Widget_Data *wd = elm_widget_data_get(obj);
55 edje_object_scale_set(wd->lay, elm_widget_scale_get(obj) *
61 _changed_hook(Evas_Object *obj)
63 Widget_Data *wd = elm_widget_data_get(obj);
65 if (wd->needs_size_calc)
68 wd->needs_size_calc = 0;
73 _sizing_eval(Evas_Object *obj)
75 Widget_Data *wd = elm_widget_data_get(obj);
76 Evas_Coord minw = -1, minh = -1;
78 edje_object_size_min_calc(wd->lay, &minw, &minh);
79 evas_object_size_hint_min_set(obj, minw, minh);
80 evas_object_size_hint_max_set(obj, -1, -1);
84 _request_sizing_eval(Evas_Object *obj)
86 Widget_Data *wd = elm_widget_data_get(obj);
88 if (wd->needs_size_calc) return;
89 wd->needs_size_calc = 1;
90 evas_object_smart_changed(obj);
94 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
96 _request_sizing_eval(data);
100 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
102 Widget_Data *wd = elm_widget_data_get(obj);
103 Evas_Object *sub = event_info;
107 EINA_LIST_FOREACH(wd->subs, l, si)
111 evas_object_event_callback_del_full(sub,
112 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
115 wd->subs = eina_list_remove_list(wd->subs, l);
116 eina_stringshare_del(si->swallow);
124 _signal_size_eval(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
126 _request_sizing_eval(data);
130 * Add a new layout to the parent
132 * @param parent The parent object
133 * @return The new object or NULL if it cannot be created
138 elm_layout_add(Evas_Object *parent)
144 wd = ELM_NEW(Widget_Data);
145 e = evas_object_evas_get(parent);
146 obj = elm_widget_add(e);
147 ELM_SET_WIDTYPE(widtype, "layout");
148 elm_widget_type_set(obj, "layout");
149 elm_widget_sub_object_add(parent, obj);
150 elm_widget_data_set(obj, wd);
151 elm_widget_del_hook_set(obj, _del_hook);
152 elm_widget_theme_hook_set(obj, _theme_hook);
153 elm_widget_changed_hook_set(obj, _changed_hook);
155 wd->lay = edje_object_add(e);
156 elm_widget_resize_object_set(obj, wd->lay);
157 edje_object_signal_callback_add(wd->lay, "size,eval", "elm",
158 _signal_size_eval, obj);
160 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
162 _request_sizing_eval(obj);
167 * Set the file that will be used as layout
169 * @param obj The layout object
170 * @param file The path to file (edj) that will be used as layout
171 * @param group The group that the layout belongs in edje file
173 * @return (1 = sucess, 0 = error)
178 elm_layout_file_set(Evas_Object *obj, const char *file, const char *group)
180 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
181 Widget_Data *wd = elm_widget_data_get(obj);
182 if (!wd) return EINA_FALSE;
183 Eina_Bool ret = edje_object_file_set(wd->lay, file, group);
184 if (ret) _request_sizing_eval(obj);
189 * Set the edje group from the elementary theme that will be used as layout
191 * @param obj The layout object
192 * @param clas the clas of the group
193 * @param group the group
194 * @param style the style to used
196 * @return (1 = sucess, 0 = error)
201 elm_layout_theme_set(Evas_Object *obj, const char *clas, const char *group, const char *style)
203 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
204 Widget_Data *wd = elm_widget_data_get(obj);
205 if (!wd) return EINA_FALSE;
206 Eina_Bool ret = _elm_theme_object_set(obj, wd->lay, clas, group, style);
207 if (ret) _request_sizing_eval(obj);
212 * Set the layout content
214 * Once the content object is set, a previously set one will be deleted.
215 * If you want to keep that old content object, use the
216 * elm_layout_content_unset() function.
218 * @param obj The layout object
219 * @param swallow The swallow group name in the edje file
220 * @param content The content will be filled in this layout object
225 elm_layout_content_set(Evas_Object *obj, const char *swallow, Evas_Object *content)
227 ELM_CHECK_WIDTYPE(obj, widtype);
228 Widget_Data *wd = elm_widget_data_get(obj);
232 EINA_LIST_FOREACH(wd->subs, l, si)
234 if (!strcmp(swallow, si->swallow))
236 if (content == si->obj) return;
237 evas_object_del(si->obj);
243 elm_widget_sub_object_add(obj, content);
244 evas_object_event_callback_add(content,
245 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
246 _changed_size_hints, obj);
247 edje_object_part_swallow(wd->lay, swallow, content);
248 si = ELM_NEW(Subinfo);
249 si->swallow = eina_stringshare_add(swallow);
251 wd->subs = eina_list_append(wd->subs, si);
253 _request_sizing_eval(obj);
257 * Unset the layout content
259 * Unparent and return the content object which was set for this widget
261 * @param obj The layout object
262 * @param swallow The swallow group name in the edje file
263 * @return The content that was being used
268 elm_layout_content_unset(Evas_Object *obj, const char *swallow)
270 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
271 Widget_Data *wd = elm_widget_data_get(obj);
274 if (!wd) return NULL;
275 EINA_LIST_FOREACH(wd->subs, l, si)
277 if (!strcmp(swallow, si->swallow))
279 Evas_Object *content;
280 if (!si->obj) return NULL;
281 content = si->obj; /* si will die in _sub_del due elm_widget_sub_object_del() */
282 elm_widget_sub_object_del(obj, content);
283 edje_object_part_unswallow(wd->lay, content);
291 * Get the edje layout
293 * @param obj The layout object
295 * This returns the edje object. It is not expected to be used to then swallow
296 * objects via edje_object_part_swallow() for example. Use
297 * elm_layout_content_set() instead so child object handling and sizing is
298 * done properly. This is more intended for setting text, emitting signals,
299 * hooking to singal callbacks etc.
301 * @return A Evas_Object with the edje layout settings loaded
302 * with function elm_layout_file_set
307 elm_layout_edje_get(const Evas_Object *obj)
309 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
310 Widget_Data *wd = elm_widget_data_get(obj);
311 if (!wd) return NULL;
316 * Get the edje layout
318 * Manually forms a sizing re-evaluation when contents changed state so that
319 * minimum size might have changed and needs re-evaluation. Also note that
320 * a standard signal of "size,eval" "elm" emitted by the edje object will
321 * cause this to happen too
323 * @param obj The layout object
328 elm_layout_sizing_eval(Evas_Object *obj)
330 ELM_CHECK_WIDTYPE(obj, widtype);
331 _request_sizing_eval(obj);