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 * @param obj The layout object
215 * @param swallow The swallow group name in the edje file
216 * @param content The content will be filled in this layout object
221 elm_layout_content_set(Evas_Object *obj, const char *swallow, Evas_Object *content)
223 ELM_CHECK_WIDTYPE(obj, widtype);
224 Widget_Data *wd = elm_widget_data_get(obj);
228 EINA_LIST_FOREACH(wd->subs, l, si)
230 if (!strcmp(swallow, si->swallow))
232 if (content == si->obj) return;
233 elm_widget_sub_object_del(obj, si->obj);
239 elm_widget_sub_object_add(obj, content);
240 evas_object_event_callback_add(content,
241 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
242 _changed_size_hints, obj);
243 edje_object_part_swallow(wd->lay, swallow, content);
244 si = ELM_NEW(Subinfo);
245 si->swallow = eina_stringshare_add(swallow);
247 wd->subs = eina_list_append(wd->subs, si);
248 _request_sizing_eval(obj);
253 * Get the edje layout
255 * @param obj The layout object
257 * This returns the edje object. It is not expected to be used to then swallow
258 * objects via edje_object_part_swallow() for example. Use
259 * elm_layout_content_set() instead so child object handling and sizing is
260 * done properly. This is more intended for setting text, emitting signals,
261 * hooking to singal callbacks etc.
263 * @return A Evas_Object with the edje layout settings loaded
264 * with function elm_layout_file_set
269 elm_layout_edje_get(const Evas_Object *obj)
271 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
272 Widget_Data *wd = elm_widget_data_get(obj);
273 if (!wd) return NULL;
278 * Get the edje layout
280 * Manually forms a sizing re-evaluation when contents changed state so that
281 * minimum size might have changed and needs re-evaluation. Also note that
282 * a standard signal of "size,eval" "elm" emitted by the edje object will
283 * cause this to happen too
285 * @param obj The layout object
290 elm_layout_sizing_eval(Evas_Object *obj)
292 ELM_CHECK_WIDTYPE(obj, widtype);
293 _request_sizing_eval(obj);