2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
5 #include <Elementary.h>
9 * @defgroup Layout Layout
12 * This takes a standard Edje design file and wraps it very thinly
13 * in a widget and handles swallowing widgets into swallow regions
14 * in the Edje object, allowing Edje to be used as a design and
18 typedef struct _Widget_Data Widget_Data;
19 typedef struct _Subinfo Subinfo;
25 Eina_Bool needs_size_calc:1;
26 const char *clas, *group, *style;
35 static const char *widtype = NULL;
36 static void _del_hook(Evas_Object *obj);
37 static void _theme_hook(Evas_Object *obj);
38 static void _sizing_eval(Evas_Object *obj);
39 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
40 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
43 _del_hook(Evas_Object *obj)
45 Widget_Data *wd = elm_widget_data_get(obj);
48 EINA_LIST_FREE(wd->subs, si)
50 eina_stringshare_del(si->swallow);
57 _theme_hook(Evas_Object *obj)
59 Widget_Data *wd = elm_widget_data_get(obj);
62 _elm_theme_object_set(obj, wd->lay, wd->clas, wd->group, wd->style);
63 edje_object_scale_set(wd->lay, elm_widget_scale_get(obj) *
69 _changed_hook(Evas_Object *obj)
71 Widget_Data *wd = elm_widget_data_get(obj);
73 if (wd->needs_size_calc)
76 wd->needs_size_calc = 0;
81 _sizing_eval(Evas_Object *obj)
83 Widget_Data *wd = elm_widget_data_get(obj);
84 Evas_Coord minw = -1, minh = -1;
86 edje_object_size_min_calc(wd->lay, &minw, &minh);
87 evas_object_size_hint_min_set(obj, minw, minh);
88 evas_object_size_hint_max_set(obj, -1, -1);
92 _request_sizing_eval(Evas_Object *obj)
94 Widget_Data *wd = elm_widget_data_get(obj);
96 if (wd->needs_size_calc) return;
97 wd->needs_size_calc = 1;
98 evas_object_smart_changed(obj);
102 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
104 _request_sizing_eval(data);
108 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
110 Widget_Data *wd = elm_widget_data_get(obj);
111 Evas_Object *sub = event_info;
115 EINA_LIST_FOREACH(wd->subs, l, si)
119 evas_object_event_callback_del_full(sub,
120 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
123 wd->subs = eina_list_remove_list(wd->subs, l);
124 eina_stringshare_del(si->swallow);
132 _signal_size_eval(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
134 _request_sizing_eval(data);
138 * Add a new layout to the parent
140 * @param parent The parent object
141 * @return The new object or NULL if it cannot be created
146 elm_layout_add(Evas_Object *parent)
152 wd = ELM_NEW(Widget_Data);
153 e = evas_object_evas_get(parent);
154 obj = elm_widget_add(e);
155 ELM_SET_WIDTYPE(widtype, "layout");
156 elm_widget_type_set(obj, "layout");
157 elm_widget_sub_object_add(parent, obj);
158 elm_widget_data_set(obj, wd);
159 elm_widget_del_hook_set(obj, _del_hook);
160 elm_widget_theme_hook_set(obj, _theme_hook);
161 elm_widget_changed_hook_set(obj, _changed_hook);
163 wd->lay = edje_object_add(e);
164 elm_widget_resize_object_set(obj, wd->lay);
165 edje_object_signal_callback_add(wd->lay, "size,eval", "elm",
166 _signal_size_eval, obj);
168 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
170 _request_sizing_eval(obj);
175 * Set the file that will be used as layout
177 * @param obj The layout object
178 * @param file The path to file (edj) that will be used as layout
179 * @param group The group that the layout belongs in edje file
181 * @return (1 = sucess, 0 = error)
186 elm_layout_file_set(Evas_Object *obj, const char *file, const char *group)
188 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
189 Widget_Data *wd = elm_widget_data_get(obj);
190 if (!wd) return EINA_FALSE;
191 Eina_Bool ret = edje_object_file_set(wd->lay, file, group);
192 if (ret) _request_sizing_eval(obj);
197 * Set the edje group from the elementary theme that will be used as layout
199 * @param obj The layout object
200 * @param clas the clas of the group
201 * @param group the group
202 * @param style the style to used
204 * @return (1 = sucess, 0 = error)
209 elm_layout_theme_set(Evas_Object *obj, const char *clas, const char *group, const char *style)
211 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
212 Widget_Data *wd = elm_widget_data_get(obj);
213 if (!wd) return EINA_FALSE;
214 Eina_Bool ret = _elm_theme_object_set(obj, wd->lay, clas, group, style);
218 if (ret) _request_sizing_eval(obj);
223 * Set the layout content
225 * Once the content object is set, a previously set one will be deleted.
226 * If you want to keep that old content object, use the
227 * elm_layout_content_unset() function.
229 * @param obj The layout object
230 * @param swallow The swallow group name in the edje file
231 * @param content The content will be filled in this layout object
236 elm_layout_content_set(Evas_Object *obj, const char *swallow, Evas_Object *content)
238 ELM_CHECK_WIDTYPE(obj, widtype);
239 Widget_Data *wd = elm_widget_data_get(obj);
243 EINA_LIST_FOREACH(wd->subs, l, si)
245 if (!strcmp(swallow, si->swallow))
247 if (content == si->obj) return;
248 evas_object_del(si->obj);
254 elm_widget_sub_object_add(obj, content);
255 evas_object_event_callback_add(content,
256 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
257 _changed_size_hints, obj);
258 edje_object_part_swallow(wd->lay, swallow, content);
259 si = ELM_NEW(Subinfo);
260 si->swallow = eina_stringshare_add(swallow);
262 wd->subs = eina_list_append(wd->subs, si);
264 _request_sizing_eval(obj);
268 * Unset the layout content
270 * Unparent and return the content object which was set for this widget
272 * @param obj The layout object
273 * @param swallow The swallow group name in the edje file
274 * @return The content that was being used
279 elm_layout_content_unset(Evas_Object *obj, const char *swallow)
281 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
282 Widget_Data *wd = elm_widget_data_get(obj);
285 if (!wd) return NULL;
286 EINA_LIST_FOREACH(wd->subs, l, si)
288 if (!strcmp(swallow, si->swallow))
290 Evas_Object *content;
291 if (!si->obj) return NULL;
292 content = si->obj; /* si will die in _sub_del due elm_widget_sub_object_del() */
293 elm_widget_sub_object_del(obj, content);
294 edje_object_part_unswallow(wd->lay, content);
302 * Get the edje layout
304 * @param obj The layout object
306 * This returns the edje object. It is not expected to be used to then swallow
307 * objects via edje_object_part_swallow() for example. Use
308 * elm_layout_content_set() instead so child object handling and sizing is
309 * done properly. This is more intended for setting text, emitting signals,
310 * hooking to singal callbacks etc.
312 * @return A Evas_Object with the edje layout settings loaded
313 * with function elm_layout_file_set
318 elm_layout_edje_get(const Evas_Object *obj)
320 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
321 Widget_Data *wd = elm_widget_data_get(obj);
322 if (!wd) return NULL;
327 * Get the edje layout
329 * Manually forms a sizing re-evaluation when contents changed state so that
330 * minimum size might have changed and needs re-evaluation. Also note that
331 * a standard signal of "size,eval" "elm" emitted by the edje object will
332 * cause this to happen too
334 * @param obj The layout object
339 elm_layout_sizing_eval(Evas_Object *obj)
341 ELM_CHECK_WIDTYPE(obj, widtype);
342 _request_sizing_eval(obj);