1 #include <Elementary.h>
5 static const char SIG_CHILD_ADDED[] = "child,added";
6 static const char SIG_CHILD_REMOVED[] = "child,removed";
8 static const Evas_Smart_Cb_Description _signals[] = {
10 {SIG_CHILD_REMOVED, ""},
15 typedef struct _Widget_Data Widget_Data;
16 typedef struct _Transition_Animation_Data Transition_Animation_Data;
21 Eina_Bool horizontal:1;
22 Eina_Bool homogeneous:1;
25 struct _Elm_Box_Transition
29 Eina_Bool animation_ended:1;
30 Eina_Bool recalculate:1;
31 Ecore_Animator *animator;
35 Evas_Object_Box_Layout layout;
37 void(*free_data)(void *data);
40 void(*transition_end_cb)(void *data);
41 void *transition_end_data;
42 void (*transition_end_free_data)(void *data);
47 struct _Transition_Animation_Data
52 Evas_Coord x, y, w, h;
56 static const char *widtype = NULL;
57 static void _del_hook(Evas_Object *obj);
58 static void _sizing_eval(Evas_Object *obj);
59 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
60 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
63 _del_pre_hook(Evas_Object *obj)
65 Widget_Data *wd = elm_widget_data_get(obj);
67 evas_object_event_callback_del_full
68 (wd->box, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
69 evas_object_box_remove_all(wd->box, EINA_FALSE);
73 _del_hook(Evas_Object *obj)
75 Widget_Data *wd = elm_widget_data_get(obj);
81 _elm_box_list_data_get(const Eina_List *list)
83 Evas_Object_Box_Option *opt = eina_list_data_get(list);
88 _cb_proxy_child_added(void *data, Evas_Object *o __UNUSED__, void *event_info)
90 Evas_Object *box = data;
91 Evas_Object_Box_Option *opt = event_info;
92 evas_object_smart_callback_call(box, SIG_CHILD_ADDED, opt->obj);
96 _cb_proxy_child_removed(void *data, Evas_Object *o __UNUSED__, void *event_info)
98 Evas_Object *box = data;
99 Evas_Object *child = event_info;
100 evas_object_smart_callback_call(box, SIG_CHILD_REMOVED, child);
104 _elm_box_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
106 Widget_Data *wd = elm_widget_data_get(obj);
107 const Eina_List *items;
108 void *(*list_data_get) (const Eina_List *list);
110 if ((!wd) || (!wd->box))
114 /* TODO: Change this to use other chain */
115 if ((items = elm_widget_focus_custom_chain_get(obj)))
116 list_data_get = eina_list_data_get;
119 Evas_Object_Box_Data *bd = evas_object_smart_data_get(wd->box);
120 items = bd->children;
121 list_data_get = _elm_box_list_data_get;
123 if (!items) return EINA_FALSE;
126 return elm_widget_focus_list_next_get(obj, items, list_data_get, dir, next);
130 _theme_hook(Evas_Object *obj)
132 Widget_Data *wd = elm_widget_data_get(obj);
134 _elm_widget_mirrored_reload(obj);
135 evas_object_smart_calculate(wd->box);
139 _sizing_eval(Evas_Object *obj)
141 Widget_Data *wd = elm_widget_data_get(obj);
142 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
145 evas_object_size_hint_min_get(wd->box, &minw, &minh);
146 evas_object_size_hint_max_get(wd->box, &maxw, &maxh);
147 evas_object_size_hint_min_set(obj, minw, minh);
148 evas_object_size_hint_max_set(obj, maxw, maxh);
149 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
150 if (w < minw) w = minw;
151 if (h < minh) h = minh;
152 if ((maxw >= 0) && (w > maxw)) w = maxw;
153 if ((maxh >= 0) && (h > maxh)) h = maxh;
154 evas_object_resize(obj, w, h);
158 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
164 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
170 _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data)
172 Evas_Object *obj = (Evas_Object *) data;
173 Widget_Data *wd = elm_widget_data_get(obj);
175 _els_box_layout(o, priv, wd->horizontal, wd->homogeneous,
176 elm_widget_mirrored_get(obj));
180 _transition_animation(void *data)
182 evas_object_smart_changed(data);
183 return ECORE_CALLBACK_RENEW;
187 _transition_layout_child_added(void *data, Evas_Object *obj __UNUSED__, void *event_info)
189 Transition_Animation_Data *tad;
190 Evas_Object_Box_Option *opt = event_info;
191 Elm_Box_Transition *layout_data = data;
193 tad = calloc(1, sizeof(Transition_Animation_Data));
196 layout_data->objs = eina_list_append(layout_data->objs, tad);
197 layout_data->recalculate = EINA_TRUE;
201 _transition_layout_child_removed(void *data, Evas_Object *obj __UNUSED__, void *event_info)
204 Transition_Animation_Data *tad;
205 Elm_Box_Transition *layout_data = data;
207 EINA_LIST_FOREACH(layout_data->objs, l, tad)
209 if (tad->obj == event_info)
211 free(eina_list_data_get(l));
212 layout_data->objs = eina_list_remove_list(layout_data->objs, l);
213 layout_data->recalculate = EINA_TRUE;
220 _transition_layout_obj_resize_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
222 Elm_Box_Transition *layout_data = data;
223 layout_data->recalculate = EINA_TRUE;
227 _transition_layout_calculate_coords(Evas_Object *obj, Evas_Object_Box_Data *priv,
228 Elm_Box_Transition *layout_data)
231 Transition_Animation_Data *tad;
232 Evas_Coord x, y, w, h;
233 const double curtime = ecore_loop_time_get();
235 layout_data->duration =
236 layout_data->duration - (curtime - layout_data->initial_time);
237 layout_data->initial_time = curtime;
239 evas_object_geometry_get(obj, &x, &y, &w, &h);
240 EINA_LIST_FOREACH(layout_data->objs, l, tad)
242 evas_object_geometry_get(tad->obj, &tad->start.x, &tad->start.y,
243 &tad->start.w, &tad->start.h);
244 tad->start.x = tad->start.x - x;
245 tad->start.y = tad->start.y - y;
247 layout_data->end.layout(obj, priv, layout_data->end.data);
248 EINA_LIST_FOREACH(layout_data->objs, l, tad)
250 evas_object_geometry_get(tad->obj, &tad->end.x, &tad->end.y,
251 &tad->end.w, &tad->end.h);
252 tad->end.x = tad->end.x - x;
253 tad->end.y = tad->end.y - y;
258 _transition_layout_load_children_list(Evas_Object_Box_Data *priv,
259 Elm_Box_Transition *layout_data)
262 Evas_Object_Box_Option *opt;
263 Transition_Animation_Data *tad;
265 EINA_LIST_FREE(layout_data->objs, tad)
268 EINA_LIST_FOREACH(priv->children, l, opt)
270 tad = calloc(1, sizeof(Transition_Animation_Data));
273 EINA_LIST_FREE(layout_data->objs, tad)
275 layout_data->objs = NULL;
279 layout_data->objs = eina_list_append(layout_data->objs, tad);
285 _transition_layout_animation_start(Evas_Object *obj, Evas_Object_Box_Data *priv,
286 Elm_Box_Transition *layout_data, Eina_Bool(*transition_animation_cb)(void *data))
288 layout_data->start.layout(obj, priv, layout_data->start.data);
289 layout_data->box = obj;
290 layout_data->initial_time = ecore_loop_time_get();
292 if (!_transition_layout_load_children_list(priv, layout_data))
294 _transition_layout_calculate_coords(obj, priv, layout_data);
296 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE,
297 _transition_layout_obj_resize_cb, layout_data);
298 evas_object_smart_callback_add(obj, SIG_CHILD_ADDED,
299 _transition_layout_child_added, layout_data);
300 evas_object_smart_callback_add(obj, SIG_CHILD_REMOVED,
301 _transition_layout_child_removed, layout_data);
302 if (!layout_data->animator)
303 layout_data->animator = ecore_animator_add(transition_animation_cb, obj);
304 layout_data->animation_ended = EINA_FALSE;
309 _transition_layout_animation_stop(Elm_Box_Transition *layout_data)
311 layout_data->animation_ended = EINA_TRUE;
312 if (layout_data->animator)
314 ecore_animator_del(layout_data->animator);
315 layout_data->animator = NULL;
318 if (layout_data->transition_end_cb)
319 layout_data->transition_end_cb(layout_data->transition_end_data);
323 _transition_layout_animation_exec(Evas_Object *obj, Evas_Object_Box_Data *priv __UNUSED__,
324 Elm_Box_Transition *layout_data, const double curtime)
327 Transition_Animation_Data *tad;
328 Evas_Coord x, y, w, h;
329 Evas_Coord cur_x, cur_y, cur_w, cur_h;
330 double progress = 0.0;
332 progress = (curtime - layout_data->initial_time) / layout_data->duration;
333 evas_object_geometry_get(obj, &x, &y, &w, &h);
335 EINA_LIST_FOREACH(layout_data->objs, l, tad)
337 cur_x = x + tad->start.x + ((tad->end.x - tad->start.x) * progress);
338 cur_y = y + tad->start.y + ((tad->end.y - tad->start.y) * progress);
339 cur_w = tad->start.w + ((tad->end.w - tad->start.w) * progress);
340 cur_h = tad->start.h + ((tad->end.h - tad->start.h) * progress);
341 evas_object_move(tad->obj, cur_x, cur_y);
342 evas_object_resize(tad->obj, cur_w, cur_h);
347 elm_box_add(Evas_Object *parent)
353 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
355 ELM_SET_WIDTYPE(widtype, "box");
356 elm_widget_type_set(obj, "box");
357 elm_widget_sub_object_add(parent, obj);
358 elm_widget_data_set(obj, wd);
359 elm_widget_del_hook_set(obj, _del_hook);
360 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
361 elm_widget_focus_next_hook_set(obj, _elm_box_focus_next_hook);
362 elm_widget_can_focus_set(obj, EINA_FALSE);
363 elm_widget_highlight_ignore_set(obj, EINA_TRUE);
364 elm_widget_theme_hook_set(obj, _theme_hook);
366 wd->box = evas_object_box_add(e);
367 /*evas_object_box_layout_set(wd->box, evas_object_box_layout_vertical,
369 evas_object_box_layout_set(wd->box, _layout, obj, NULL);
371 evas_object_event_callback_add(wd->box, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
372 _changed_size_hints, obj);
373 elm_widget_resize_object_set(obj, wd->box);
374 elm_widget_sub_object_add(obj, wd->box);
376 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
378 evas_object_smart_callbacks_descriptions_set(obj, _signals);
379 evas_object_smart_callback_add
380 (wd->box, SIG_CHILD_ADDED, _cb_proxy_child_added, obj);
381 evas_object_smart_callback_add
382 (wd->box, SIG_CHILD_REMOVED, _cb_proxy_child_removed, obj);
388 elm_box_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
390 ELM_CHECK_WIDTYPE(obj, widtype);
391 Widget_Data *wd = elm_widget_data_get(obj);
393 wd->horizontal = !!horizontal;
394 evas_object_smart_calculate(wd->box);
395 /*if (wd->horizontal)
398 evas_object_box_layout_set(wd->box,
399 evas_object_box_layout_homogeneous_horizontal, NULL, NULL);
401 evas_object_box_layout_set(wd->box, evas_object_box_layout_horizontal,
407 evas_object_box_layout_set(wd->box,
408 evas_object_box_layout_homogeneous_vertical, NULL, NULL);
410 evas_object_box_layout_set(wd->box, evas_object_box_layout_horizontal,
416 elm_box_horizontal_get(const Evas_Object *obj)
418 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
419 Widget_Data *wd = elm_widget_data_get(obj);
420 if (!wd) return EINA_FALSE;
421 return wd->horizontal;
425 elm_box_homogeneous_set(Evas_Object *obj, Eina_Bool homogeneous)
427 ELM_CHECK_WIDTYPE(obj, widtype);
428 Widget_Data *wd = elm_widget_data_get(obj);
430 wd->homogeneous = !!homogeneous;
431 evas_object_smart_calculate(wd->box);
432 /*if (wd->horizontal)
435 evas_object_box_layout_set(wd->box,
436 evas_object_box_layout_homogeneous_horizontal, NULL, NULL);
438 evas_object_box_layout_set(wd->box, evas_object_box_layout_horizontal,
444 evas_object_box_layout_set(wd->box,
445 evas_object_box_layout_homogeneous_vertical, NULL, NULL);
447 evas_object_box_layout_set(wd->box, evas_object_box_layout_horizontal,
452 EINA_DEPRECATED EAPI void
453 elm_box_homogenous_set(Evas_Object *obj, Eina_Bool homogenous)
455 elm_box_homogeneous_set(obj, homogenous);
459 elm_box_homogeneous_get(const Evas_Object *obj)
461 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
462 Widget_Data *wd = elm_widget_data_get(obj);
463 if (!wd) return EINA_FALSE;
464 return wd->homogeneous;
467 EINA_DEPRECATED EAPI Eina_Bool
468 elm_box_homogenous_get(const Evas_Object *obj)
470 return elm_box_homogeneous_get(obj);
474 elm_box_pack_start(Evas_Object *obj, Evas_Object *subobj)
476 ELM_CHECK_WIDTYPE(obj, widtype);
477 Widget_Data *wd = elm_widget_data_get(obj);
479 elm_widget_sub_object_add(obj, subobj);
480 evas_object_box_prepend(wd->box, subobj);
484 elm_box_pack_end(Evas_Object *obj, Evas_Object *subobj)
486 ELM_CHECK_WIDTYPE(obj, widtype);
487 Widget_Data *wd = elm_widget_data_get(obj);
489 elm_widget_sub_object_add(obj, subobj);
490 evas_object_box_append(wd->box, subobj);
494 elm_box_pack_before(Evas_Object *obj, Evas_Object *subobj, Evas_Object *before)
496 ELM_CHECK_WIDTYPE(obj, widtype);
497 Widget_Data *wd = elm_widget_data_get(obj);
499 elm_widget_sub_object_add(obj, subobj);
500 evas_object_box_insert_before(wd->box, subobj, before);
504 elm_box_pack_after(Evas_Object *obj, Evas_Object *subobj, Evas_Object *after)
506 ELM_CHECK_WIDTYPE(obj, widtype);
507 Widget_Data *wd = elm_widget_data_get(obj);
509 elm_widget_sub_object_add(obj, subobj);
510 evas_object_box_insert_after(wd->box, subobj, after);
514 elm_box_clear(Evas_Object *obj)
516 ELM_CHECK_WIDTYPE(obj, widtype);
517 Widget_Data *wd = elm_widget_data_get(obj);
519 evas_object_box_remove_all(wd->box, EINA_TRUE);
523 elm_box_unpack(Evas_Object *obj, Evas_Object *subobj)
525 ELM_CHECK_WIDTYPE(obj, widtype);
526 Widget_Data *wd = elm_widget_data_get(obj);
528 evas_object_box_remove(wd->box, subobj);
532 elm_box_unpack_all(Evas_Object *obj)
534 ELM_CHECK_WIDTYPE(obj, widtype);
535 Widget_Data *wd = elm_widget_data_get(obj);
537 evas_object_box_remove_all(wd->box, EINA_FALSE);
541 elm_box_layout_set(Evas_Object *obj, Evas_Object_Box_Layout cb, const void *data, void (*free_data)(void *data))
543 ELM_CHECK_WIDTYPE(obj, widtype);
544 Widget_Data *wd = elm_widget_data_get(obj);
548 evas_object_box_layout_set(wd->box, cb, data, free_data);
550 evas_object_box_layout_set(wd->box, _layout, obj, NULL);
554 elm_box_layout_transition(Evas_Object *obj, Evas_Object_Box_Data *priv, void *data)
556 Elm_Box_Transition *box_data = data;
557 const double curtime = ecore_loop_time_get();
559 if (box_data->animation_ended)
561 box_data->end.layout(obj, priv, box_data->end.data);
565 if (!box_data->animator)
567 if (!_transition_layout_animation_start(obj, priv, box_data,
568 _transition_animation))
573 if (box_data->recalculate)
575 _transition_layout_calculate_coords(obj, priv, box_data);
576 box_data->recalculate = EINA_FALSE;
580 if ((curtime >= box_data->duration + box_data->initial_time))
581 _transition_layout_animation_stop(box_data);
583 _transition_layout_animation_exec(obj, priv, box_data, curtime);
586 EAPI Elm_Box_Transition *
587 elm_box_transition_new(const double duration,
588 Evas_Object_Box_Layout start_layout, void *start_layout_data,
589 void(*start_layout_free_data)(void *data),
590 Evas_Object_Box_Layout end_layout, void *end_layout_data,
591 void(*end_layout_free_data)(void *data),
592 void(*transition_end_cb)(void *data),
593 void *transition_end_data)
595 Elm_Box_Transition *box_data;
597 EINA_SAFETY_ON_NULL_RETURN_VAL(start_layout, NULL);
598 EINA_SAFETY_ON_NULL_RETURN_VAL(end_layout, NULL);
600 box_data = calloc(1, sizeof(Elm_Box_Transition));
604 box_data->start.layout = start_layout;
605 box_data->start.data = start_layout_data;
606 box_data->start.free_data = start_layout_free_data;
607 box_data->end.layout = end_layout;
608 box_data->end.data = end_layout_data;
609 box_data->end.free_data = end_layout_free_data;
610 box_data->duration = duration;
611 box_data->transition_end_cb = transition_end_cb;
612 box_data->transition_end_data = transition_end_data;
617 elm_box_transition_free(void *data)
619 EINA_SAFETY_ON_NULL_RETURN(data);
621 Transition_Animation_Data *tad;
622 Elm_Box_Transition *box_data = data;
623 if ((box_data->start.free_data) && (box_data->start.data))
624 box_data->start.free_data(box_data->start.data);
625 if ((box_data->end.free_data) && (box_data->end.data))
626 box_data->end.free_data(box_data->end.data);
627 EINA_LIST_FREE(box_data->objs, tad)
629 evas_object_event_callback_del(box_data->box, EVAS_CALLBACK_RESIZE, _transition_layout_obj_resize_cb);
630 evas_object_smart_callback_del(box_data->box, SIG_CHILD_ADDED, _transition_layout_child_added);
631 evas_object_smart_callback_del(box_data->box, SIG_CHILD_REMOVED, _transition_layout_child_removed);
632 if (box_data->animator)
634 ecore_animator_del(box_data->animator);
635 box_data->animator = NULL;
640 EAPI const Eina_List *
641 elm_box_children_get(const Evas_Object *obj)
643 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
644 Widget_Data *wd = elm_widget_data_get(obj);
645 if (!wd) return NULL;
646 return evas_object_box_children_get(wd->box);
650 elm_box_padding_set(Evas_Object *obj, Evas_Coord horizontal, Evas_Coord vertical)
652 ELM_CHECK_WIDTYPE(obj, widtype);
653 Widget_Data *wd = elm_widget_data_get(obj);
655 evas_object_box_padding_set(wd->box, horizontal, vertical);
659 elm_box_padding_get(const Evas_Object *obj, Evas_Coord *horizontal, Evas_Coord *vertical)
661 ELM_CHECK_WIDTYPE(obj, widtype);
662 Widget_Data *wd = elm_widget_data_get(obj);
664 evas_object_box_padding_get(wd->box, horizontal, vertical);
668 elm_box_align_set(Evas_Object *obj, double horizontal, double vertical)
670 ELM_CHECK_WIDTYPE(obj, widtype);
671 Widget_Data *wd = elm_widget_data_get(obj);
673 evas_object_size_hint_align_set(wd->box, horizontal, vertical);
677 elm_box_align_get(const Evas_Object *obj, double *horizontal, double *vertical)
679 ELM_CHECK_WIDTYPE(obj, widtype);
680 Widget_Data *wd = elm_widget_data_get(obj);
682 evas_object_size_hint_align_get(wd->box, horizontal, vertical);
686 elm_box_recalculate(Evas_Object *obj)
688 ELM_CHECK_WIDTYPE(obj, widtype);
689 Widget_Data *wd = elm_widget_data_get(obj);
691 evas_object_smart_need_recalculate_set(wd->box, EINA_TRUE);
692 evas_object_smart_calculate(wd->box);