1 #include <Elementary.h>
4 #define SIG_CHILD_ADDED "child,added"
5 #define SIG_CHILD_REMOVED "child,removed"
7 typedef struct _Widget_Data Widget_Data;
8 typedef struct _Transition_Animation_Data Transition_Animation_Data;
13 Eina_Bool horizontal:1;
14 Eina_Bool homogeneous:1;
17 struct _Elm_Box_Transition
21 Eina_Bool animation_ended:1;
22 Eina_Bool recalculate:1;
23 Ecore_Animator *animator;
27 Evas_Object_Box_Layout layout;
29 void(*free_data)(void *data);
32 void(*transition_end_cb)(void *data);
33 void *transition_end_data;
34 void (*transition_end_free_data)(void *data);
39 struct _Transition_Animation_Data
44 Evas_Coord x, y, w, h;
48 static const char *widtype = NULL;
49 static void _del_hook(Evas_Object *obj);
50 static void _sizing_eval(Evas_Object *obj);
51 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
52 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
55 _del_pre_hook(Evas_Object *obj)
57 Widget_Data *wd = elm_widget_data_get(obj);
59 evas_object_event_callback_del_full
60 (wd->box, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
61 evas_object_box_remove_all(wd->box, EINA_FALSE);
65 _del_hook(Evas_Object *obj)
67 Widget_Data *wd = elm_widget_data_get(obj);
73 _elm_box_list_data_get(const Eina_List *list)
75 Evas_Object_Box_Option *opt = eina_list_data_get(list);
80 _elm_box_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
82 Widget_Data *wd = elm_widget_data_get(obj);
83 const Eina_List *items;
84 void *(*list_data_get) (const Eina_List *list);
86 if ((!wd) || (!wd->box))
90 /* TODO: Change this to use other chain */
91 if ((items = elm_widget_focus_custom_chain_get(obj)))
92 list_data_get = eina_list_data_get;
95 Evas_Object_Box_Data *bd = evas_object_smart_data_get(wd->box);
97 list_data_get = _elm_box_list_data_get;
99 if (!items) return EINA_FALSE;
102 return elm_widget_focus_list_next_get(obj, items, list_data_get, dir, next);
106 _theme_hook(Evas_Object *obj)
108 Widget_Data *wd = elm_widget_data_get(obj);
110 _elm_widget_mirrored_reload(obj);
111 evas_object_smart_calculate(wd->box);
115 _sizing_eval(Evas_Object *obj)
117 Widget_Data *wd = elm_widget_data_get(obj);
118 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
121 evas_object_size_hint_min_get(wd->box, &minw, &minh);
122 evas_object_size_hint_max_get(wd->box, &maxw, &maxh);
123 evas_object_size_hint_min_set(obj, minw, minh);
124 evas_object_size_hint_max_set(obj, maxw, maxh);
125 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
126 if (w < minw) w = minw;
127 if (h < minh) h = minh;
128 if ((maxw >= 0) && (w > maxw)) w = maxw;
129 if ((maxh >= 0) && (h > maxh)) h = maxh;
130 evas_object_resize(obj, w, h);
134 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
140 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
146 _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data)
148 Evas_Object *obj = (Evas_Object *) data;
149 Widget_Data *wd = elm_widget_data_get(obj);
151 _els_box_layout(o, priv, wd->horizontal, wd->homogeneous,
152 elm_widget_mirrored_get(obj));
156 _transition_animation(void *data)
158 evas_object_smart_changed(data);
159 return ECORE_CALLBACK_RENEW;
163 _transition_layout_child_added(void *data, Evas_Object *obj __UNUSED__, void *event_info)
165 Transition_Animation_Data *tad;
166 Evas_Object_Box_Option *opt = event_info;
167 Elm_Box_Transition *layout_data = data;
169 tad = calloc(1, sizeof(Transition_Animation_Data));
172 layout_data->objs = eina_list_append(layout_data->objs, tad);
173 layout_data->recalculate = EINA_TRUE;
177 _transition_layout_child_removed(void *data, Evas_Object *obj __UNUSED__, void *event_info)
180 Transition_Animation_Data *tad;
181 Elm_Box_Transition *layout_data = data;
183 EINA_LIST_FOREACH(layout_data->objs, l, tad)
185 if (tad->obj == event_info)
187 free(eina_list_data_get(l));
188 layout_data->objs = eina_list_remove_list(layout_data->objs, l);
189 layout_data->recalculate = EINA_TRUE;
196 _transition_layout_obj_resize_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
198 Elm_Box_Transition *layout_data = data;
199 layout_data->recalculate = EINA_TRUE;
203 _transition_layout_calculate_coords(Evas_Object *obj, Evas_Object_Box_Data *priv,
204 Elm_Box_Transition *layout_data)
207 Transition_Animation_Data *tad;
208 Evas_Coord x, y, w, h;
209 const double curtime = ecore_loop_time_get();
211 layout_data->duration =
212 layout_data->duration - (curtime - layout_data->initial_time);
213 layout_data->initial_time = curtime;
215 evas_object_geometry_get(obj, &x, &y, &w, &h);
216 EINA_LIST_FOREACH(layout_data->objs, l, tad)
218 evas_object_geometry_get(tad->obj, &tad->start.x, &tad->start.y,
219 &tad->start.w, &tad->start.h);
220 tad->start.x = tad->start.x - x;
221 tad->start.y = tad->start.y - y;
223 layout_data->end.layout(obj, priv, layout_data->end.data);
224 EINA_LIST_FOREACH(layout_data->objs, l, tad)
226 evas_object_geometry_get(tad->obj, &tad->end.x, &tad->end.y,
227 &tad->end.w, &tad->end.h);
228 tad->end.x = tad->end.x - x;
229 tad->end.y = tad->end.y - y;
234 _transition_layout_load_children_list(Evas_Object_Box_Data *priv,
235 Elm_Box_Transition *layout_data)
238 Evas_Object_Box_Option *opt;
239 Transition_Animation_Data *tad;
241 EINA_LIST_FREE(layout_data->objs, tad)
244 EINA_LIST_FOREACH(priv->children, l, opt)
246 tad = calloc(1, sizeof(Transition_Animation_Data));
249 EINA_LIST_FREE(layout_data->objs, tad)
251 layout_data->objs = NULL;
255 layout_data->objs = eina_list_append(layout_data->objs, tad);
261 _transition_layout_animation_start(Evas_Object *obj, Evas_Object_Box_Data *priv,
262 Elm_Box_Transition *layout_data, Eina_Bool(*transition_animation_cb)(void *data))
264 layout_data->start.layout(obj, priv, layout_data->start.data);
265 layout_data->box = obj;
266 layout_data->initial_time = ecore_loop_time_get();
268 if (!_transition_layout_load_children_list(priv, layout_data))
270 _transition_layout_calculate_coords(obj, priv, layout_data);
272 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE,
273 _transition_layout_obj_resize_cb, layout_data);
274 evas_object_smart_callback_add(obj, SIG_CHILD_ADDED,
275 _transition_layout_child_added, layout_data);
276 evas_object_smart_callback_add(obj, SIG_CHILD_REMOVED,
277 _transition_layout_child_removed, layout_data);
278 if (!layout_data->animator)
279 layout_data->animator = ecore_animator_add(transition_animation_cb, obj);
280 layout_data->animation_ended = EINA_FALSE;
285 _transition_layout_animation_stop(Elm_Box_Transition *layout_data)
287 layout_data->animation_ended = EINA_TRUE;
288 if (layout_data->animator)
290 ecore_animator_del(layout_data->animator);
291 layout_data->animator = NULL;
294 if (layout_data->transition_end_cb)
295 layout_data->transition_end_cb(layout_data->transition_end_data);
299 _transition_layout_animation_exec(Evas_Object *obj, Evas_Object_Box_Data *priv __UNUSED__,
300 Elm_Box_Transition *layout_data, const double curtime)
303 Transition_Animation_Data *tad;
304 Evas_Coord x, y, w, h;
305 Evas_Coord cur_x, cur_y, cur_w, cur_h;
306 double progress = 0.0;
308 progress = (curtime - layout_data->initial_time) / layout_data->duration;
309 evas_object_geometry_get(obj, &x, &y, &w, &h);
311 EINA_LIST_FOREACH(layout_data->objs, l, tad)
313 cur_x = x + tad->start.x + ((tad->end.x - tad->start.x) * progress);
314 cur_y = y + tad->start.y + ((tad->end.y - tad->start.y) * progress);
315 cur_w = tad->start.w + ((tad->end.w - tad->start.w) * progress);
316 cur_h = tad->start.h + ((tad->end.h - tad->start.h) * progress);
317 evas_object_move(tad->obj, cur_x, cur_y);
318 evas_object_resize(tad->obj, cur_w, cur_h);
323 elm_box_add(Evas_Object *parent)
329 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
331 ELM_SET_WIDTYPE(widtype, "box");
332 elm_widget_type_set(obj, "box");
333 elm_widget_sub_object_add(parent, obj);
334 elm_widget_data_set(obj, wd);
335 elm_widget_del_hook_set(obj, _del_hook);
336 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
337 elm_widget_focus_next_hook_set(obj, _elm_box_focus_next_hook);
338 elm_widget_can_focus_set(obj, EINA_FALSE);
339 elm_widget_highlight_ignore_set(obj, EINA_TRUE);
340 elm_widget_theme_hook_set(obj, _theme_hook);
342 wd->box = evas_object_box_add(e);
343 /*evas_object_box_layout_set(wd->box, evas_object_box_layout_vertical,
345 evas_object_box_layout_set(wd->box, _layout, obj, NULL);
347 evas_object_event_callback_add(wd->box, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
348 _changed_size_hints, obj);
349 elm_widget_resize_object_set(obj, wd->box);
351 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
357 elm_box_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
359 ELM_CHECK_WIDTYPE(obj, widtype);
360 Widget_Data *wd = elm_widget_data_get(obj);
362 wd->horizontal = !!horizontal;
363 evas_object_smart_calculate(wd->box);
364 /*if (wd->horizontal)
367 evas_object_box_layout_set(wd->box,
368 evas_object_box_layout_homogeneous_horizontal, NULL, NULL);
370 evas_object_box_layout_set(wd->box, evas_object_box_layout_horizontal,
376 evas_object_box_layout_set(wd->box,
377 evas_object_box_layout_homogeneous_vertical, NULL, NULL);
379 evas_object_box_layout_set(wd->box, evas_object_box_layout_horizontal,
385 elm_box_horizontal_get(const Evas_Object *obj)
387 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
388 Widget_Data *wd = elm_widget_data_get(obj);
389 if (!wd) return EINA_FALSE;
390 return wd->horizontal;
394 elm_box_homogeneous_set(Evas_Object *obj, Eina_Bool homogeneous)
396 ELM_CHECK_WIDTYPE(obj, widtype);
397 Widget_Data *wd = elm_widget_data_get(obj);
399 wd->homogeneous = !!homogeneous;
400 evas_object_smart_calculate(wd->box);
401 /*if (wd->horizontal)
404 evas_object_box_layout_set(wd->box,
405 evas_object_box_layout_homogeneous_horizontal, NULL, NULL);
407 evas_object_box_layout_set(wd->box, evas_object_box_layout_horizontal,
413 evas_object_box_layout_set(wd->box,
414 evas_object_box_layout_homogeneous_vertical, NULL, NULL);
416 evas_object_box_layout_set(wd->box, evas_object_box_layout_horizontal,
421 EINA_DEPRECATED EAPI void
422 elm_box_homogenous_set(Evas_Object *obj, Eina_Bool homogenous)
424 elm_box_homogeneous_set(obj, homogenous);
428 elm_box_homogeneous_get(const Evas_Object *obj)
430 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
431 Widget_Data *wd = elm_widget_data_get(obj);
432 if (!wd) return EINA_FALSE;
433 return wd->homogeneous;
436 EINA_DEPRECATED EAPI Eina_Bool
437 elm_box_homogenous_get(const Evas_Object *obj)
439 return elm_box_homogeneous_get(obj);
443 elm_box_pack_start(Evas_Object *obj, Evas_Object *subobj)
445 ELM_CHECK_WIDTYPE(obj, widtype);
446 Widget_Data *wd = elm_widget_data_get(obj);
448 elm_widget_sub_object_add(obj, subobj);
449 evas_object_box_prepend(wd->box, subobj);
453 elm_box_pack_end(Evas_Object *obj, Evas_Object *subobj)
455 ELM_CHECK_WIDTYPE(obj, widtype);
456 Widget_Data *wd = elm_widget_data_get(obj);
458 elm_widget_sub_object_add(obj, subobj);
459 evas_object_box_append(wd->box, subobj);
463 elm_box_pack_before(Evas_Object *obj, Evas_Object *subobj, Evas_Object *before)
465 ELM_CHECK_WIDTYPE(obj, widtype);
466 Widget_Data *wd = elm_widget_data_get(obj);
468 elm_widget_sub_object_add(obj, subobj);
469 evas_object_box_insert_before(wd->box, subobj, before);
473 elm_box_pack_after(Evas_Object *obj, Evas_Object *subobj, Evas_Object *after)
475 ELM_CHECK_WIDTYPE(obj, widtype);
476 Widget_Data *wd = elm_widget_data_get(obj);
478 elm_widget_sub_object_add(obj, subobj);
479 evas_object_box_insert_after(wd->box, subobj, after);
483 elm_box_clear(Evas_Object *obj)
485 ELM_CHECK_WIDTYPE(obj, widtype);
486 Widget_Data *wd = elm_widget_data_get(obj);
488 evas_object_box_remove_all(wd->box, EINA_TRUE);
492 elm_box_unpack(Evas_Object *obj, Evas_Object *subobj)
494 ELM_CHECK_WIDTYPE(obj, widtype);
495 Widget_Data *wd = elm_widget_data_get(obj);
497 evas_object_box_remove(wd->box, subobj);
501 elm_box_unpack_all(Evas_Object *obj)
503 ELM_CHECK_WIDTYPE(obj, widtype);
504 Widget_Data *wd = elm_widget_data_get(obj);
506 evas_object_box_remove_all(wd->box, EINA_FALSE);
510 elm_box_layout_set(Evas_Object *obj, Evas_Object_Box_Layout cb, const void *data, void (*free_data)(void *data))
512 ELM_CHECK_WIDTYPE(obj, widtype);
513 Widget_Data *wd = elm_widget_data_get(obj);
517 evas_object_box_layout_set(wd->box, cb, data, free_data);
519 evas_object_box_layout_set(wd->box, _layout, obj, NULL);
523 elm_box_layout_transition(Evas_Object *obj, Evas_Object_Box_Data *priv, void *data)
525 Elm_Box_Transition *box_data = data;
526 const double curtime = ecore_loop_time_get();
528 if (box_data->animation_ended)
530 box_data->end.layout(obj, priv, box_data->end.data);
534 if (!box_data->animator)
536 if (!_transition_layout_animation_start(obj, priv, box_data,
537 _transition_animation))
542 if (box_data->recalculate)
544 _transition_layout_calculate_coords(obj, priv, box_data);
545 box_data->recalculate = EINA_FALSE;
549 if ((curtime >= box_data->duration + box_data->initial_time))
550 _transition_layout_animation_stop(box_data);
552 _transition_layout_animation_exec(obj, priv, box_data, curtime);
555 EAPI Elm_Box_Transition *
556 elm_box_transition_new(const double duration,
557 Evas_Object_Box_Layout start_layout, void *start_layout_data,
558 void(*start_layout_free_data)(void *data),
559 Evas_Object_Box_Layout end_layout, void *end_layout_data,
560 void(*end_layout_free_data)(void *data),
561 void(*transition_end_cb)(void *data),
562 void *transition_end_data)
564 Elm_Box_Transition *box_data;
566 EINA_SAFETY_ON_NULL_RETURN_VAL(start_layout, NULL);
567 EINA_SAFETY_ON_NULL_RETURN_VAL(end_layout, NULL);
569 box_data = calloc(1, sizeof(Elm_Box_Transition));
573 box_data->start.layout = start_layout;
574 box_data->start.data = start_layout_data;
575 box_data->start.free_data = start_layout_free_data;
576 box_data->end.layout = end_layout;
577 box_data->end.data = end_layout_data;
578 box_data->end.free_data = end_layout_free_data;
579 box_data->duration = duration;
580 box_data->transition_end_cb = transition_end_cb;
581 box_data->transition_end_data = transition_end_data;
586 elm_box_transition_free(void *data)
588 EINA_SAFETY_ON_NULL_RETURN(data);
590 Transition_Animation_Data *tad;
591 Elm_Box_Transition *box_data = data;
592 if ((box_data->start.free_data) && (box_data->start.data))
593 box_data->start.free_data(box_data->start.data);
594 if ((box_data->end.free_data) && (box_data->end.data))
595 box_data->end.free_data(box_data->end.data);
596 EINA_LIST_FREE(box_data->objs, tad)
598 evas_object_event_callback_del(box_data->box, EVAS_CALLBACK_RESIZE, _transition_layout_obj_resize_cb);
599 evas_object_smart_callback_del(box_data->box, SIG_CHILD_ADDED, _transition_layout_child_added);
600 evas_object_smart_callback_del(box_data->box, SIG_CHILD_REMOVED, _transition_layout_child_removed);
601 if (box_data->animator)
603 ecore_animator_del(box_data->animator);
604 box_data->animator = NULL;
609 EAPI const Eina_List *
610 elm_box_children_get(const Evas_Object *obj)
612 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
613 Widget_Data *wd = elm_widget_data_get(obj);
614 if (!wd) return NULL;
615 return evas_object_box_children_get(wd->box);
619 elm_box_padding_set(Evas_Object *obj, Evas_Coord horizontal, Evas_Coord vertical)
621 ELM_CHECK_WIDTYPE(obj, widtype);
622 Widget_Data *wd = elm_widget_data_get(obj);
624 evas_object_box_padding_set(wd->box, horizontal, vertical);
628 elm_box_padding_get(const Evas_Object *obj, Evas_Coord *horizontal, Evas_Coord *vertical)
630 ELM_CHECK_WIDTYPE(obj, widtype);
631 Widget_Data *wd = elm_widget_data_get(obj);
633 evas_object_box_padding_get(wd->box, horizontal, vertical);
637 elm_box_align_set(Evas_Object *obj, double horizontal, double vertical)
639 ELM_CHECK_WIDTYPE(obj, widtype);
640 Widget_Data *wd = elm_widget_data_get(obj);
642 evas_object_box_align_set(wd->box, horizontal, vertical);
646 elm_box_align_get(const Evas_Object *obj, double *horizontal, double *vertical)
648 ELM_CHECK_WIDTYPE(obj, widtype);
649 Widget_Data *wd = elm_widget_data_get(obj);
651 evas_object_box_align_get(wd->box, horizontal, vertical);