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 * @param obj The layout object
226 * @param swallow The swallow group name in the edje file
227 * @param content The content will be filled in this layout object
232 elm_layout_content_set(Evas_Object *obj, const char *swallow, Evas_Object *content)
234 ELM_CHECK_WIDTYPE(obj, widtype);
235 Widget_Data *wd = elm_widget_data_get(obj);
239 EINA_LIST_FOREACH(wd->subs, l, si)
241 if (!strcmp(swallow, si->swallow))
243 if (content == si->obj) return;
244 elm_widget_sub_object_del(obj, si->obj);
250 elm_widget_sub_object_add(obj, content);
251 evas_object_event_callback_add(content,
252 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
253 _changed_size_hints, obj);
254 edje_object_part_swallow(wd->lay, swallow, content);
255 si = ELM_NEW(Subinfo);
256 si->swallow = eina_stringshare_add(swallow);
258 wd->subs = eina_list_append(wd->subs, si);
259 _request_sizing_eval(obj);
264 * Unset the layout content
266 * Unparent and return the content object which was set for this widget
268 * @param obj The layout object
269 * @param swallow The swallow group name in the edje file
270 * @return The content that was being used
275 elm_layout_content_unset(Evas_Object *obj, const char *swallow)
277 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
278 Widget_Data *wd = elm_widget_data_get(obj);
281 if (!wd) return NULL;
282 EINA_LIST_FOREACH(wd->subs, l, si)
284 if (!strcmp(swallow, si->swallow))
286 Evas_Object *content;
287 if (!si->obj) return NULL;
288 content = si->obj; /* si will die in _sub_del due elm_widget_sub_object_del() */
289 elm_widget_sub_object_del(obj, content);
290 edje_object_part_unswallow(wd->lay, content);
298 * Get the edje layout
300 * @param obj The layout object
302 * This returns the edje object. It is not expected to be used to then swallow
303 * objects via edje_object_part_swallow() for example. Use
304 * elm_layout_content_set() instead so child object handling and sizing is
305 * done properly. This is more intended for setting text, emitting signals,
306 * hooking to singal callbacks etc.
308 * @return A Evas_Object with the edje layout settings loaded
309 * with function elm_layout_file_set
314 elm_layout_edje_get(const Evas_Object *obj)
316 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
317 Widget_Data *wd = elm_widget_data_get(obj);
318 if (!wd) return NULL;
323 * Get the edje layout
325 * Manually forms a sizing re-evaluation when contents changed state so that
326 * minimum size might have changed and needs re-evaluation. Also note that
327 * a standard signal of "size,eval" "elm" emitted by the edje object will
328 * cause this to happen too
330 * @param obj The layout object
335 elm_layout_sizing_eval(Evas_Object *obj)
337 ELM_CHECK_WIDTYPE(obj, widtype);
338 _request_sizing_eval(obj);