From e2176ed6a3b52c015dd503df592ee24fd5ddf955 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Andre Date: Fri, 22 Apr 2016 14:58:49 +0900 Subject: [PATCH] Edje: Replace edje_box_part with a fake eo proxy This is basically an implementation of eo_part() but only for Edje Box APIs. Legacy API is implemented on top of the EO API. --- src/Makefile_Edje.am | 18 +- src/Makefile_Elementary.am | 2 +- src/lib/edje/Edje_Legacy.h | 141 ++++++++++++ src/lib/edje/edje_containers.c | 304 +++++++++++++++++++++++++ src/lib/edje/edje_load.c | 1 + src/lib/edje/edje_object.eo | 123 ---------- src/lib/edje/edje_private.h | 14 ++ src/lib/edje/edje_util.c | 78 +++++-- src/lib/edje/efl_canvas_layout_internal_box.eo | 38 ++++ src/lib/evas/canvas/evas_box.eo | 6 +- src/lib/evas/canvas/evas_object_box.c | 7 + src/tests/edje/edje_test_edje.c | 69 +++++- 12 files changed, 652 insertions(+), 149 deletions(-) create mode 100644 src/lib/edje/edje_containers.c create mode 100644 src/lib/edje/efl_canvas_layout_internal_box.eo diff --git a/src/Makefile_Edje.am b/src/Makefile_Edje.am index c9187fa..f2bb792 100644 --- a/src/Makefile_Edje.am +++ b/src/Makefile_Edje.am @@ -8,23 +8,34 @@ edje_eolian_files = \ edje_eolian_type_files = \ lib/edje/edje_types.eot +edje_eolian_priv_files = \ + lib/edje/efl_canvas_layout_internal_box.eo + edje_eolian_c = $(edje_eolian_files:%.eo=%.eo.c) edje_eolian_h = $(edje_eolian_files:%.eo=%.eo.h) \ $(edje_eolian_files:%.eo=%.eo.legacy.h) \ $(edje_eolian_type_files:%.eot=%.eot.h) +edje_eolian_priv_c = $(edje_eolian_priv_files:%.eo=%.eo.c) +edje_eolian_priv_h = $(edje_eolian_priv_files:%.eo=%.eo.h) + BUILT_SOURCES += \ $(edje_eolian_c) \ - $(edje_eolian_h) + $(edje_eolian_h) \ + $(edje_eolian_priv_c) \ + $(edje_eolian_priv_h) edjeeolianfilesdir = $(datadir)/eolian/include/edje-@VMAJ@ edjeeolianfiles_DATA = \ $(edje_eolian_files) \ $(edje_eolian_type_files) +noinst_DATA += $(edje_eolian_priv_c) $(edje_eolian_priv_h) + EXTRA_DIST += lib/edje/Makefile.am \ lib/edje/Makefile.in \ - ${edjeeolianfiles_DATA} + ${edjeeolianfiles_DATA} \ + $(edje_eolian_priv_files lib_LTLIBRARIES += lib/edje/libedje.la @@ -78,7 +89,8 @@ lib/edje/edje_text.c \ lib/edje/edje_textblock_styles.c \ lib/edje/edje_util.c \ lib/edje/edje_var.c \ -lib/edje/edje_signal.c +lib/edje/edje_signal.c \ +lib/edje/edje_containers.c lib_edje_libedje_la_CPPFLAGS = -I$(top_builddir)/src/lib/efl $(EDJE_COMMON_CPPFLAGS) lib_edje_libedje_la_LIBADD = @EDJE_LIBS@ diff --git a/src/Makefile_Elementary.am b/src/Makefile_Elementary.am index 9755c88..231b0f7 100644 --- a/src/Makefile_Elementary.am +++ b/src/Makefile_Elementary.am @@ -149,7 +149,7 @@ BUILT_SOURCES += \ elementaryeolianfilesdir = $(datadir)/eolian/include/elementary-@VMAJ@ elementaryeolianfiles_DATA = $(elm_public_eolian_files) $(elm_eolian_type_files) -noinst_DATA = $(elm_legacy_eolian_eo_h) +noinst_DATA += $(elm_legacy_eolian_eo_h) EXTRA_DIST += ${elementaryeolianfiles_DATA} $(elm_legacy_eolian_files) diff --git a/src/lib/edje/Edje_Legacy.h b/src/lib/edje/Edje_Legacy.h index 9e6adf5..0e5916a 100644 --- a/src/lib/edje/Edje_Legacy.h +++ b/src/lib/edje/Edje_Legacy.h @@ -300,6 +300,147 @@ EAPI void edje_object_part_unswallow(Edje_Object *obj, Evas_Object *obj_swallow) */ EAPI Eina_List *edje_object_access_part_list_get(const Edje_Object *obj); +/** + * @brief Appends an object to the box. + * + * Appends child to the box indicated by part. + * + * See also @ref edje_object_part_box_prepend(), + * @ref edje_object_part_box_insert_before(), + * @ref edje_object_part_box_insert_after() and + * @ref edje_object_part_box_insert_at() + * + * @param[in] child The object to append + * + * @return @c true: Successfully added. @c false: An error occurred. + * + * @ingroup Edje_Object + */ +EAPI Eina_Bool edje_object_part_box_append(Edje_Object *obj, const char *part, Evas_Object *child); + +/** + * @brief Prepends an object to the box. + * + * Prepends child to the box indicated by part. + * + * See also @ref edje_object_part_box_append(), + * @ref edje_object_part_box_insert_before(), + * @ref edje_object_part_box_insert_after and + * @ref edje_object_part_box_insert_at() + * + * @param[in] child The object to prepend + * + * @return @c true: Successfully added. @c false: An error occurred. + * + * @ingroup Edje_Object + */ +EAPI Eina_Bool edje_object_part_box_prepend(Edje_Object *obj, const char *part, Evas_Object *child); + +/** + * @brief Adds an object to the box. + * + * Inserts child in the box given by part, in the position marked by reference. + * + * See also @ref edje_object_part_box_append(), + * @ref edje_object_part_box_prepend(), + * @ref edje_object_part_box_insert_after() and + * @ref edje_object_part_box_insert_at() + * + * @param[in] child The object to insert + * @param[in] reference The object to be used as reference + * + * @return @c true: Successfully added. @c false: An error occurred. + * + * @ingroup Edje_Object + */ +EAPI Eina_Bool edje_object_part_box_insert_before(Edje_Object *obj, const char *part, Evas_Object *child, const Evas_Object *reference); + +/** + * @brief Adds an object to the box. + * + * Inserts child in the box given by part, in the position marked by reference. + * + * See also @ref edje_object_part_box_append(), + * @ref edje_object_part_box_prepend(), + * @ref edje_object_part_box_insert_before() and + * @ref edje_object_part_box_insert_at() + * + * @param[in] child The object to insert + * @param[in] reference The object to be used as reference + * + * @return @c true: Successfully added. @c false: An error occurred. + * + * @ingroup Edje_Object + */ +EAPI Eina_Bool edje_object_part_box_insert_after(Edje_Object *obj, const char *part, Evas_Object *child, const Evas_Object *reference); + +/** + * @brief Inserts an object to the box. + * + * Adds child to the box indicated by part, in the position given by pos. + * + * See also @ref edje_object_part_box_append(), + * @ref edje_object_part_box_prepend(), + * @ref edje_object_part_box_insert_before() and + * @ref edje_object_part_box_insert_after() + * + * @param[in] child The object to insert + * @param[in] pos The position where to insert child + * + * @return @c true: Successfully added. @c false: An error occurred. + * + * @ingroup Edje_Object + */ +EAPI Eina_Bool edje_object_part_box_insert_at(Edje_Object *obj, const char *part, Evas_Object *child, unsigned int pos); + +/** + * @brief Removes an object from the box. + * + * Removes from the box indicated by part, the object in the position pos. + * + * See also @ref edje_object_part_box_remove() and + * @ref edje_object_part_box_remove_all() + * + * @param[in] pos The position index of the object (starts counting from 0) + * + * @return Pointer to the object removed, or @c null. + * + * @ingroup Edje_Object + */ +EAPI Evas_Object *edje_object_part_box_remove_at(Edje_Object *obj, const char *part, unsigned int pos); + +/** + * @brief Removes an object from the box. + * + * Removes child from the box indicated by part. + * + * See also @ref edje_object_part_box_remove_at() and + * @ref edje_object_part_box_remove_all() + * + * @param[in] child The object to remove + * + * @return Pointer to the object removed, or @c null. + * + * @ingroup Edje_Object + */ +EAPI Evas_Object *edje_object_part_box_remove(Edje_Object *obj, const char *part, Evas_Object *child); + +/** + * @brief Removes all elements from the box. + * + * Removes all the external objects from the box indicated by part. Elements + * created from the theme will not be removed. + * + * See also @ref edje_object_part_box_remove() and + * @ref edje_object_part_box_remove_at() + * + * @param[in] clear Delete objects on removal + * + * @return 1: Successfully cleared. 0: An error occurred. + * + * @ingroup Edje_Object + */ +EAPI Eina_Bool edje_object_part_box_remove_all(Edje_Object *obj, const char *part, Eina_Bool clear); #include "edje_object.eo.legacy.h" #include "edje_edit.eo.legacy.h" diff --git a/src/lib/edje/edje_containers.c b/src/lib/edje/edje_containers.c new file mode 100644 index 0000000..e25509d --- /dev/null +++ b/src/lib/edje/edje_containers.c @@ -0,0 +1,304 @@ +#include "edje_private.h" + +#define EFL_CANVAS_LAYOUT_INTERNAL_BOX_PROTECTED + +#include "efl_canvas_layout_internal_box.eo.h" +#include "../evas/canvas/evas_box.eo.h" +#include "../evas/canvas/evas_line.eo.h" +#include "../evas/canvas/evas_text.eo.h" + +#define BOX_CLASS EFL_CANVAS_LAYOUT_INTERNAL_BOX_CLASS + +typedef struct _Edje_Box_Data Edje_Box_Data; +typedef struct _Box_Item_Iterator Box_Item_Iterator; + +struct _Edje_Box_Data +{ + Edje *ed; + Edje_Real_Part *rp; + const char *part; +}; + +struct _Box_Item_Iterator +{ + Eina_Iterator iterator; + Eina_List *list; + Eina_Iterator *real_iterator; + Eo *object; +}; + +static Eina_Bool +_del_cb(void *data, const Eo_Event *event EINA_UNUSED) +{ + Edje_Real_Part *rp = data; + rp->typedata.container->eo_proxy = NULL; + return EO_CALLBACK_CONTINUE; +} + +Eo * +_edje_box_internal_proxy_get(Edje_Object *obj, Edje *ed, Edje_Real_Part *rp) +{ + Efl_Canvas_Layout_Internal_Box *eo = rp->typedata.container->eo_proxy; + + if (eo) return eo; + + eo = eo_add(BOX_CLASS, obj, efl_canvas_layout_internal_box_real_part_set(eo_self, ed, rp, rp->part->name)); + eo_event_callback_add(eo, EO_BASE_EVENT_DEL, _del_cb, rp); + + rp->typedata.container->eo_proxy = eo; + return eo; +} + +EOLIAN static void +_efl_canvas_layout_internal_box_real_part_set(Eo *obj EINA_UNUSED, Edje_Box_Data *pd, void *ed, void *rp, const char *part) +{ + pd->ed = ed; + pd->rp = rp; + pd->part = part; +} + +EOLIAN static Eo_Base * +_efl_canvas_layout_internal_box_eo_base_finalize(Eo *obj, Edje_Box_Data *pd) +{ + EINA_SAFETY_ON_FALSE_RETURN_VAL(pd->rp && pd->ed && pd->part, NULL); + return eo_finalize(eo_super(obj, BOX_CLASS)); +} + +/* Legacy features */ + +EOLIAN static void +_efl_canvas_layout_internal_box_efl_pack_pack_clear(Eo *obj EINA_UNUSED, Edje_Box_Data *pd) +{ + _edje_part_box_remove_all(pd->ed, pd->part, EINA_TRUE); +} + +EOLIAN static void +_efl_canvas_layout_internal_box_efl_pack_unpack_all(Eo *obj EINA_UNUSED, Edje_Box_Data *pd) +{ + _edje_part_box_remove_all(pd->ed, pd->part, EINA_FALSE); +} + +EOLIAN static Eina_Bool +_efl_canvas_layout_internal_box_efl_pack_unpack(Eo *obj EINA_UNUSED, Edje_Box_Data *pd, Efl_Gfx_Base *subobj) +{ + Evas_Object *removed; + removed = _edje_part_box_remove(pd->ed, pd->part, subobj); + return (removed == subobj); +} + +EOLIAN static void +_efl_canvas_layout_internal_box_efl_pack_pack(Eo *obj EINA_UNUSED, Edje_Box_Data *pd, Efl_Gfx_Base *subobj) +{ + _edje_part_box_append(pd->ed, pd->part, subobj); +} + +EOLIAN static void +_efl_canvas_layout_internal_box_efl_pack_linear_pack_begin(Eo *obj EINA_UNUSED, Edje_Box_Data *pd, Efl_Gfx_Base *subobj) +{ + _edje_part_box_prepend(pd->ed, pd->part, subobj); +} + +EOLIAN static void +_efl_canvas_layout_internal_box_efl_pack_linear_pack_end(Eo *obj EINA_UNUSED, Edje_Box_Data *pd, Efl_Gfx_Base *subobj) +{ + _edje_part_box_append(pd->ed, pd->part, subobj); +} + +EOLIAN static Eina_Bool +_efl_canvas_layout_internal_box_efl_pack_linear_pack_before(Eo *obj EINA_UNUSED, Edje_Box_Data *pd, Efl_Gfx_Base *subobj, const Efl_Gfx_Base *existing) +{ + return _edje_part_box_insert_before(pd->ed, pd->part, subobj, existing); +} + +EOLIAN static Eina_Bool +_efl_canvas_layout_internal_box_efl_pack_linear_pack_after(Eo *obj EINA_UNUSED, Edje_Box_Data *pd, Efl_Gfx_Base *subobj, const Efl_Gfx_Base *existing) +{ + return _edje_part_box_insert_after(pd->ed, pd->part, subobj, existing); +} + +EOLIAN static void +_efl_canvas_layout_internal_box_efl_pack_linear_pack_insert(Eo *obj, Edje_Box_Data *pd, Efl_Gfx_Base *subobj, int index) +{ + int cnt = efl_content_count(obj); + if ((index >= 0) && (index < cnt)) + _edje_part_box_insert_at(pd->ed, pd->part, subobj, index); + else + _edje_part_box_append(pd->ed, pd->part, subobj); +} + +EOLIAN static Efl_Gfx_Base * +_efl_canvas_layout_internal_box_efl_pack_linear_content_at_remove(Eo *obj EINA_UNUSED, Edje_Box_Data *pd, int index) +{ + if (index < 0) index += efl_content_count(obj); + return _edje_part_box_remove_at(pd->ed, pd->part, index); +} + +/* New APIs with Eo */ + +EOLIAN static Efl_Gfx_Base * +_efl_canvas_layout_internal_box_efl_pack_linear_content_at_get(Eo *obj EINA_UNUSED, Edje_Box_Data *pd, int index) +{ + if (index < 0) index += efl_content_count(obj); + return _edje_part_box_content_at(pd->ed, pd->part, index); +} + +EOLIAN static Eina_Bool +_efl_canvas_layout_internal_box_efl_container_content_remove(Eo *obj, Edje_Box_Data *pd EINA_UNUSED, Efl_Gfx_Base *subobj) +{ + return efl_pack_unpack(obj, subobj); +} + +EOLIAN static int +_efl_canvas_layout_internal_box_efl_pack_linear_content_index_get(Eo *obj EINA_UNUSED, Edje_Box_Data *pd, Efl_Gfx_Base * subobj) +{ + Evas_Object_Box_Option *opt; + Evas_Object_Box_Data *priv; + Eina_List *l; + int k = 0; + + priv = eo_data_scope_get(pd->rp->object, EVAS_BOX_CLASS); + if (!priv) return -1; + EINA_LIST_FOREACH(priv->children, l, opt) + { + if (opt->obj == subobj) + return k; + k++; + } + return -1; +} + +/* this iterator is the same as efl_ui_box */ +static Eina_Bool +_box_item_iterator_next(Box_Item_Iterator *it, void **data) +{ + Efl_Gfx_Base *sub; + + if (!eina_iterator_next(it->real_iterator, (void **) &sub)) + return EINA_FALSE; + + if (data) *data = sub; + return EINA_TRUE; +} + +static Eo * +_box_item_iterator_get_container(Box_Item_Iterator *it) +{ + return it->object; +} + +static void +_box_item_iterator_free(Box_Item_Iterator *it) +{ + eina_iterator_free(it->real_iterator); + eina_list_free(it->list); + eo_unref(it->object); + free(it); +} + +EOLIAN static Eina_Iterator * +_efl_canvas_layout_internal_box_efl_container_content_iterate(Eo *obj, Edje_Box_Data *pd) +{ + Box_Item_Iterator *it; + + if (!pd->rp->typedata.container) return NULL; + + it = calloc(1, sizeof(*it)); + if (!it) return NULL; + + EINA_MAGIC_SET(&it->iterator, EINA_MAGIC_ITERATOR); + + it->list = evas_object_box_children_get(pd->rp->object); + it->real_iterator = eina_list_iterator_new(it->list); + it->iterator.version = EINA_ITERATOR_VERSION; + it->iterator.next = FUNC_ITERATOR_NEXT(_box_item_iterator_next); + it->iterator.get_container = FUNC_ITERATOR_GET_CONTAINER(_box_item_iterator_get_container); + it->iterator.free = FUNC_ITERATOR_FREE(_box_item_iterator_free); + it->object = eo_ref(obj); + + return &it->iterator; +} + +EOLIAN static int +_efl_canvas_layout_internal_box_efl_container_content_count(Eo *obj EINA_UNUSED, Edje_Box_Data *pd) +{ + if (!pd->rp->typedata.container) return 0; + return evas_obj_box_count(pd->rp->object); +} + +/* Legacy API implementation */ + +#define PART_BOX_GET(obj, part, ...) ({ \ + Eo *__box = efl_content_get(obj, part); \ + if (!__box || !eo_isa(__box, EFL_CANVAS_LAYOUT_INTERNAL_BOX_CLASS)) \ + { \ + ERR("No such box part '%s' in layout %p", part, obj); \ + return __VA_ARGS__; \ + } \ + __box; }) + +EAPI Eina_Bool +edje_object_part_box_append(Edje_Object *obj, const char *part, Evas_Object *child) +{ + Eo *box = PART_BOX_GET(obj, part, EINA_FALSE); + efl_pack_end(box, child); + return EINA_TRUE; +} + +EAPI Eina_Bool +edje_object_part_box_prepend(Edje_Object *obj, const char *part, Evas_Object *child) +{ + Eo *box = PART_BOX_GET(obj, part, EINA_FALSE); + efl_pack_begin(box, child); + return EINA_TRUE; +} + +EAPI Eina_Bool +edje_object_part_box_insert_before(Edje_Object *obj, const char *part, Evas_Object *child, const Evas_Object *reference) +{ + Eo *box = PART_BOX_GET(obj, part, EINA_FALSE); + return efl_pack_before(box, child, reference); +} + +EAPI Eina_Bool +edje_object_part_box_insert_after(Edje_Object *obj, const char *part, Evas_Object *child, const Evas_Object *reference) +{ + Eo *box = PART_BOX_GET(obj, part, EINA_FALSE); + return efl_pack_after(box, child, reference); +} + +EAPI Eina_Bool +edje_object_part_box_insert_at(Edje_Object *obj, const char *part, Evas_Object *child, unsigned int pos) +{ + Eo *box = PART_BOX_GET(obj, part, EINA_FALSE); + efl_pack_insert(box, child, pos); + return EINA_TRUE; +} + +EAPI Evas_Object * +edje_object_part_box_remove_at(Edje_Object *obj, const char *part, unsigned int pos) +{ + Eo *box = PART_BOX_GET(obj, part, NULL); + return efl_pack_content_at_remove(box, pos); +} + +EAPI Evas_Object * +edje_object_part_box_remove(Edje_Object *obj, const char *part, Evas_Object *child) +{ + Eo *box = PART_BOX_GET(obj, part, NULL); + if (efl_pack_unpack(box, child)) + return child; + return NULL; +} + +EAPI Eina_Bool +edje_object_part_box_remove_all(Edje_Object *obj, const char *part, Eina_Bool clear) +{ + Eo *box = PART_BOX_GET(obj, part, EINA_FALSE); + if (clear) + efl_pack_clear(box); + else + efl_pack_unpack_all(box); + return EINA_TRUE; +} + +#include "efl_canvas_layout_internal_box.eo.c" diff --git a/src/lib/edje/edje_load.c b/src/lib/edje/edje_load.c index 16bc5ee..1aff5c9 100644 --- a/src/lib/edje/edje_load.c +++ b/src/lib/edje/edje_load.c @@ -1582,6 +1582,7 @@ _edje_file_del(Edje *ed) _edje_box_layout_free_data(rp->typedata.container->anim); rp->typedata.container->anim = NULL; } + eo_del(rp->typedata.container->eo_proxy); free(rp->typedata.container); } else if ((rp->type == EDJE_RP_TYPE_TEXT) && diff --git a/src/lib/edje/edje_object.eo b/src/lib/edje/edje_object.eo index a214e5d..7930cd9 100644 --- a/src/lib/edje/edje_object.eo +++ b/src/lib/edje/edje_object.eo @@ -730,20 +730,6 @@ class Edje.Object (Evas.Smart_Clipped, Efl.File, Efl.Container) @in text: const(char)*; [[The text string]] } } - part_box_remove_at { - [[Removes an object from the box. - - Removes from the box indicated by part, the object in the position - pos. - - See also @.part_box_remove() and @.part_box_remove_all()]] - - return: Evas.Object *; [[Pointer to the object removed, or $null.]] - params { - @in part: const(char)*; [[The part name]] - @in pos: uint; [[The position index of the object (starts counting from 0)]] - } - } part_text_cursor_copy { [[Copy the cursor to another cursor.]] @@ -1021,23 +1007,6 @@ class Edje.Object (Evas.Smart_Clipped, Efl.File, Efl.Container) @in part: const(char)*; [[The part name]] } } - part_box_insert_at { - [[Inserts an object to the box. - - Adds child to the box indicated by part, in the position given by - pos. - - See also @.part_box_append(), @.part_box_prepend(), - @.part_box_insert_before() and @.part_box_insert_after()]] - - return: bool; [[$true: Successfully added. - $false: An error occurred.]] - params { - @in part: const(char)*; [[The part name]] - @in child: Evas.Object *; [[The object to insert]] - @in pos: uint; [[The position where to insert child]] - } - } part_text_anchor_geometry_get @const { [[Return a list of Evas_Textblock_Rectangle anchor rectangles. @@ -1090,21 +1059,6 @@ class Edje.Object (Evas.Smart_Clipped, Efl.File, Efl.Container) @out dy: double; [[The dy page increment pointer]] } } - part_box_prepend { - [[Prepends an object to the box. - - Prepends child to the box indicated by part. - - See also @.part_box_append(), @.part_box_insert_before(), - @.part_box_insert_after and @.part_box_insert_at()]] - - return: bool; [[$true: Successfully added. - $false: An error occurred.]] - params { - @in part: const(char)*; [[The part name]] - @in child: Evas.Object *; [[The object to prepend]] - } - } signal_emit { [[Send/emit an Edje signal to a given Edje object @@ -1502,19 +1456,6 @@ class Edje.Object (Evas.Smart_Clipped, Efl.File, Efl.Container) be processed only at idle time.]] } - part_box_remove { - [[Removes an object from the box. - - Removes child from the box indicated by part. - - See also @.part_box_remove_at() and @.part_box_remove_all()]] - - return: Evas.Object *; [[Pointer to the object removed, or $null.]] - params { - @in part: const(char)*; [[The part name]] - @in child: Evas.Object *; [[The object to remove]] - } - } thaw { [[Thaws the Edje object. @@ -1570,40 +1511,6 @@ class Edje.Object (Evas.Smart_Clipped, Efl.File, Efl.Container) @in row: uint; [[The row of the child to get]] } } - part_box_insert_before { - [[Adds an object to the box. - - Inserts child in the box given by part, in the position marked by - reference. - - See also @.part_box_append(), @.part_box_prepend(), - @.part_box_insert_after() and @.part_box_insert_at()]] - - return: bool; [[$true: Successfully added. - $false: An error occurred.]] - params { - @in part: const(char)*; [[The part name]] - @in child: Evas.Object *; [[The object to insert]] - @in reference: const(Evas.Object)*; [[The object to be used as reference]] - } - } - part_box_insert_after { - [[Adds an object to the box. - - Inserts child in the box given by part, in the position marked by - reference. - - See also @.part_box_append(), @.part_box_prepend(), - @.part_box_insert_before() and @.part_box_insert_at()]] - - return: bool; [[$true: Successfully added. - $false: An error occurred.]] - params { - @in part: const(char)*; [[The part name]] - @in child: Evas.Object *; [[The object to insert]] - @in reference: const(Evas.Object)*; [[The object to be used as reference]] - } - } part_external_param_set { [[Set the parameter for the external part. @@ -1675,21 +1582,6 @@ class Edje.Object (Evas.Smart_Clipped, Efl.File, Efl.Container) required height]] } } - part_box_append { - [[Appends an object to the box. - - Appends child to the box indicated by part. - - See also @.part_box_prepend(), @.part_box_insert_before(), - @.part_box_insert_after() and @.part_box_insert_at()]] - - return: bool; [[$true: Successfully added. - $false: An error occurred.]] - params { - @in part: const(char)*; [[The part name]] - @in child: Evas.Object *; [[The object to append]] - } - } size_min_restricted_calc { [[Calculate the minimum required size for a given Edje object. @@ -1718,21 +1610,6 @@ class Edje.Object (Evas.Smart_Clipped, Efl.File, Efl.Container) height to be less than this value]] } } - part_box_remove_all { - [[Removes all elements from the box. - - Removes all the external objects from the box indicated by part. - Elements created from the theme will not be removed. - - See also @.part_box_remove() and @.part_box_remove_at()]] - - return: bool; [[1: Successfully cleared. - 0: An error occurred.]] - params { - @in part: const(char)*; [[The part name]] - @in clear: bool; [[Delete objects on removal]] - } - } part_drag_page { [[Pages x,y steps. diff --git a/src/lib/edje/edje_private.h b/src/lib/edje/edje_private.h index eeafeaf..1e0f420 100644 --- a/src/lib/edje/edje_private.h +++ b/src/lib/edje/edje_private.h @@ -1898,6 +1898,7 @@ struct _Edje_Real_Part_Container { Eina_List *items; // 4 //FIXME: only if table/box Edje_Part_Box_Animation *anim; // 4 //FIXME: Used only if box + Eo *eo_proxy; }; struct _Edje_Real_Part_Swallow @@ -2430,6 +2431,7 @@ Eina_Bool _edje_real_part_box_prepend(Edje *ed, Edje_Real_Part *rp, Evas Eina_Bool _edje_real_part_box_insert_before(Edje *ed, Edje_Real_Part *rp, Evas_Object *child_obj, const Evas_Object *ref); Eina_Bool _edje_real_part_box_insert_after(Edje *ed, Edje_Real_Part *rp, Evas_Object *child_obj, const Evas_Object *ref); Eina_Bool _edje_real_part_box_insert_at(Edje *ed, Edje_Real_Part *rp, Evas_Object *child_obj, unsigned int pos); +Evas_Object *_edje_real_part_box_content_at(Edje *ed, Edje_Real_Part *rp, unsigned int pos); Evas_Object *_edje_real_part_box_remove(Edje *ed, Edje_Real_Part *rp, Evas_Object *child_obj); Evas_Object *_edje_real_part_box_remove_at(Edje *ed, Edje_Real_Part *rp, unsigned int pos); Eina_Bool _edje_real_part_box_remove_all(Edje *ed, Edje_Real_Part *rp, Eina_Bool clear); @@ -2939,6 +2941,18 @@ void _edje_part_ignore_flags_set(Edje *ed, Edje_Real_Part *rp, Evas_Event_Flags Evas_Event_Flags _edje_part_mask_flags_get(Edje *ed, Edje_Real_Part *rp); void _edje_part_mask_flags_set(Edje *ed, Edje_Real_Part *rp, Evas_Event_Flags mask_flags); +/* part containers */ +Eo *_edje_box_internal_proxy_get(Edje_Object *obj, Edje *ed, Edje_Real_Part *rp); +Eina_Bool _edje_part_box_append(Edje *ed, const char *part, Evas_Object *child); +Eina_Bool _edje_part_box_prepend(Edje *ed, const char *part, Evas_Object *child); +Eina_Bool _edje_part_box_insert_before(Edje *ed, const char *part, Evas_Object *child, const Evas_Object *reference); +Eina_Bool _edje_part_box_insert_after(Edje *ed, const char *part, Evas_Object *child, const Evas_Object *reference); +Eina_Bool _edje_part_box_insert_at(Edje *ed, const char *part, Evas_Object *child, unsigned int pos); +Evas_Object *_edje_part_box_content_at(Edje *ed, const char *part, unsigned int pos); +Evas_Object *_edje_part_box_remove(Edje *ed, const char *part, Evas_Object *child); +Evas_Object *_edje_part_box_remove_at(Edje *ed, const char *part, unsigned int pos); +Eina_Bool _edje_part_box_remove_all(Edje *ed, const char *part, Eina_Bool clear); + #ifdef HAVE_LIBREMIX #include #endif diff --git a/src/lib/edje/edje_util.c b/src/lib/edje/edje_util.c index 8f7899f..223c0b1 100644 --- a/src/lib/edje/edje_util.c +++ b/src/lib/edje/edje_util.c @@ -3875,7 +3875,7 @@ _edje_object_efl_container_content_remove(Eo *obj EINA_UNUSED, Edje *ed, Evas_Ob } EOLIAN Efl_Gfx_Base * -_edje_object_efl_container_content_get(Eo *obj EINA_UNUSED, Edje *ed, const char *part) +_edje_object_efl_container_content_get(Eo *obj, Edje *ed, const char *part) { Edje_Real_Part *rp; @@ -3886,10 +3886,20 @@ _edje_object_efl_container_content_get(Eo *obj EINA_UNUSED, Edje *ed, const char rp = _edje_real_part_recursive_get(&ed, part); if (!rp) return NULL; - if ((rp->type != EDJE_RP_TYPE_SWALLOW) || - (!rp->typedata.swallow)) return NULL; - return rp->typedata.swallow->swallowed_object; + switch (rp->type) + { + case EDJE_RP_TYPE_SWALLOW: + if (!rp->typedata.swallow) return NULL; + return rp->typedata.swallow->swallowed_object; + case EDJE_RP_TYPE_CONTAINER: + return _edje_box_internal_proxy_get(obj, ed, rp); + case EDJE_RP_TYPE_TEXT: + WRN("not implemented yet"); + return NULL; + default: + return NULL; + } } /* new in eo */ @@ -4713,8 +4723,8 @@ _edje_box_shutdown(void) _edje_box_layout_registry = NULL; } -EOLIAN Eina_Bool -_edje_object_part_box_append(Eo *obj EINA_UNUSED, Edje *ed, const char *part, Evas_Object *child) +Eina_Bool +_edje_part_box_append(Edje *ed, const char *part, Evas_Object *child) { Eina_Bool ret; Edje_Real_Part *rp; @@ -4742,8 +4752,8 @@ _edje_object_part_box_append(Eo *obj EINA_UNUSED, Edje *ed, const char *part, Ev return ret; } -EOLIAN Eina_Bool -_edje_object_part_box_prepend(Eo *obj EINA_UNUSED, Edje *ed, const char *part, Evas_Object *child) +Eina_Bool +_edje_part_box_prepend(Edje *ed, const char *part, Evas_Object *child) { Eina_Bool ret; Edje_Real_Part *rp; @@ -4770,8 +4780,8 @@ _edje_object_part_box_prepend(Eo *obj EINA_UNUSED, Edje *ed, const char *part, E return ret; } -EOLIAN Eina_Bool -_edje_object_part_box_insert_before(Eo *obj EINA_UNUSED, Edje *ed, const char *part, Evas_Object *child, const Evas_Object *reference) +Eina_Bool +_edje_part_box_insert_before(Edje *ed, const char *part, Evas_Object *child, const Evas_Object *reference) { Eina_Bool ret; Edje_Real_Part *rp; @@ -4798,8 +4808,8 @@ _edje_object_part_box_insert_before(Eo *obj EINA_UNUSED, Edje *ed, const char *p return ret; } -EOLIAN Eina_Bool -_edje_object_part_box_insert_after(Eo *obj EINA_UNUSED, Edje *ed, const char *part, Evas_Object *child, const Evas_Object *reference) +Eina_Bool +_edje_part_box_insert_after(Edje *ed, const char *part, Evas_Object *child, const Evas_Object *reference) { Eina_Bool ret; Edje_Real_Part *rp; @@ -4826,8 +4836,8 @@ _edje_object_part_box_insert_after(Eo *obj EINA_UNUSED, Edje *ed, const char *pa return ret; } -EOLIAN Eina_Bool -_edje_object_part_box_insert_at(Eo *obj EINA_UNUSED, Edje *ed, const char *part, Evas_Object *child, unsigned int pos) +Eina_Bool +_edje_part_box_insert_at(Edje *ed, const char *part, Evas_Object *child, unsigned int pos) { Eina_Bool ret; Edje_Real_Part *rp; @@ -4854,8 +4864,8 @@ _edje_object_part_box_insert_at(Eo *obj EINA_UNUSED, Edje *ed, const char *part, return ret; } -EOLIAN Evas_Object * -_edje_object_part_box_remove(Eo *obj EINA_UNUSED, Edje *ed, const char *part, Evas_Object *child) +Evas_Object * +_edje_part_box_remove(Edje *ed, const char *part, Evas_Object *child) { Edje_Real_Part *rp; Evas_Object *r; @@ -4883,8 +4893,8 @@ _edje_object_part_box_remove(Eo *obj EINA_UNUSED, Edje *ed, const char *part, Ev return r; } -EOLIAN Evas_Object * -_edje_object_part_box_remove_at(Eo *obj EINA_UNUSED, Edje *ed, const char *part, unsigned int pos) +Evas_Object * +_edje_part_box_remove_at(Edje *ed, const char *part, unsigned int pos) { Edje_Real_Part *rp; Evas_Object *r; @@ -4912,8 +4922,24 @@ _edje_object_part_box_remove_at(Eo *obj EINA_UNUSED, Edje *ed, const char *part, return r; } -EOLIAN Eina_Bool -_edje_object_part_box_remove_all(Eo *obj EINA_UNUSED, Edje *ed, const char *part, Eina_Bool clear) +Evas_Object * +_edje_part_box_content_at(Edje *ed, const char *part, unsigned int pos) +{ + Edje_Real_Part *rp; + Evas_Object *r; + + if ((!ed) || (!part)) return NULL; + + rp = _edje_real_part_recursive_get(&ed, part); + if (!rp) return NULL; + if (rp->part->type != EDJE_PART_TYPE_BOX) return NULL; + + r = _edje_real_part_box_content_at(ed, rp, pos); + return r; +} + +Eina_Bool +_edje_part_box_remove_all(Edje *ed, const char *part, Eina_Bool clear) { Eina_Bool ret; Edje_Real_Part *rp; @@ -5190,6 +5216,18 @@ _edje_real_part_box_insert_at(Edje *ed, Edje_Real_Part *rp, Evas_Object *child_o } Evas_Object * +_edje_real_part_box_content_at(Edje *ed EINA_UNUSED, Edje_Real_Part *rp, unsigned int pos) +{ + Evas_Object_Box_Option *opt; + Evas_Object_Box_Data *priv; + + priv = eo_data_scope_get(rp->object, EVAS_BOX_CLASS); + opt = eina_list_nth(priv->children, pos); + if (!opt) return NULL; + return opt->obj; +} + +Evas_Object * _edje_real_part_box_remove(Edje *ed, Edje_Real_Part *rp, Evas_Object *child_obj) { if (evas_object_data_get(child_obj, "\377 edje.box_item")) return NULL; diff --git a/src/lib/edje/efl_canvas_layout_internal_box.eo b/src/lib/edje/efl_canvas_layout_internal_box.eo new file mode 100644 index 0000000..a8443d3 --- /dev/null +++ b/src/lib/edje/efl_canvas_layout_internal_box.eo @@ -0,0 +1,38 @@ +class Efl.Canvas.Layout_Internal.Box (Eo.Base, Efl.Pack_Linear) +{ + [[Represents a Box created as part of a layout. + + Can not be deleted, this is only a representation of an internal object + of an EFL layout. + ]] + legacy_prefix: null; + data: Edje_Box_Data; + methods { + @property real_part @protected { + set {} + values { + ed: void*; + rp: void*; + part: const(char)*; + } + } + } + implements { + Eo.Base.finalize; + Efl.Container.content_iterate; + Efl.Container.content_count; + Efl.Container.content_remove; + Efl.Pack.pack_clear; + Efl.Pack.unpack_all; + Efl.Pack.unpack; + Efl.Pack.pack; + Efl.Pack_Linear.pack_begin; + Efl.Pack_Linear.pack_end; + Efl.Pack_Linear.pack_before; + Efl.Pack_Linear.pack_after; + Efl.Pack_Linear.pack_insert; + Efl.Pack_Linear.content_at.get; + Efl.Pack_Linear.content_at_remove; + Efl.Pack_Linear.content_index.get; + } +} diff --git a/src/lib/evas/canvas/evas_box.eo b/src/lib/evas/canvas/evas_box.eo index 3f3069e..16dcc6c 100644 --- a/src/lib/evas/canvas/evas_box.eo +++ b/src/lib/evas/canvas/evas_box.eo @@ -646,7 +646,11 @@ class Evas.Box (Evas.Smart_Clipped) priv: Evas_Object_Box_Data *; data: void *; } - + } + count { + [[Returns the number of items in the box.]] + legacy: null; + return: int; } } implements { diff --git a/src/lib/evas/canvas/evas_object_box.c b/src/lib/evas/canvas/evas_object_box.c index 55e7ca5..38216a7 100644 --- a/src/lib/evas/canvas/evas_object_box.c +++ b/src/lib/evas/canvas/evas_object_box.c @@ -1900,6 +1900,13 @@ evas_object_box_children_get(const Evas_Object *o) return new_list; } +EOLIAN static int +_evas_box_count(Eo *o, Evas_Object_Box_Data *_pd EINA_UNUSED) +{ + EVAS_OBJECT_BOX_DATA_GET_OR_RETURN_VAL(o, priv, 0); + return eina_list_count(priv->children); +} + EOLIAN static const char* _evas_box_option_property_name_get(const Eo *o EINA_UNUSED, Evas_Object_Box_Data *_pd EINA_UNUSED, int property EINA_UNUSED) { diff --git a/src/tests/edje/edje_test_edje.c b/src/tests/edje/edje_test_edje.c index 3bd890e..1ac5971 100644 --- a/src/tests/edje/edje_test_edje.c +++ b/src/tests/edje/edje_test_edje.c @@ -494,10 +494,76 @@ START_TEST(edje_test_box) } END_TEST +START_TEST(edje_test_box_eoapi) +{ + Evas *evas; + Evas_Object *obj, *sobj, *sobjs[5]; + Eina_Iterator *it; + Eo *box; + int i; + + evas = EDJE_TEST_INIT_EVAS(); + + obj = edje_object_add(evas); + fail_unless(edje_object_file_set(obj, test_layout_get("test_box.edj"), "test_group")); + + for (i = 0; i < 5; i++) + { + sobjs[i] = evas_object_rectangle_add(evas); + fail_if(!sobjs[i]); + } + + /* same test case as legacy api above */ + box = efl_content_get(obj, "box"); + fail_if(!box); + + efl_pack_end(box, sobjs[3]); + efl_pack_begin(box, sobjs[1]); + efl_pack_before(box, sobjs[0], sobjs[1]); + efl_pack_after(box, sobjs[4], sobjs[3]); + efl_pack_insert(box, sobjs[2], 2); + fail_if(efl_content_count(box) != 5); + + it = efl_content_iterate(box); + i = 0; + EINA_ITERATOR_FOREACH(it, sobj) + fail_if(sobj != sobjs[i++]); + fail_if(i != 5); + eina_iterator_free(it); + + /* clear up and test a bit more */ + efl_pack_unpack_all(box); + fail_if(efl_content_count(box) != 0); + + efl_pack(box, sobjs[1]); + efl_pack_insert(box, sobjs[0], 0); + efl_pack_insert(box, sobjs[2], -1); + it = efl_content_iterate(box); + i = 0; + EINA_ITERATOR_FOREACH(it, sobj) + fail_if(sobj != sobjs[i++]); + fail_if(i != 3); + eina_iterator_free(it); + + fail_if(!efl_content_remove(box, sobjs[0])); + fail_if(efl_content_count(box) != 2); + fail_if(!efl_pack_content_at_remove(box, 1)); + fail_if(efl_content_count(box) != 1); + fail_if(efl_pack_content_index_get(box, sobjs[1]) != 0); + + efl_pack_clear(box); + fail_if(efl_content_count(box) != 0); + + eo_del(box); + + EDJE_TEST_FREE_EVAS(); +} +END_TEST + void edje_test_edje(TCase *tc) { tcase_add_test(tc, edje_test_edje_init); - tcase_add_test(tc,edje_test_load_simple_layout); + tcase_add_test(tc, edje_test_load_simple_layout); tcase_add_test(tc, edje_test_edje_load); tcase_add_test(tc, edje_test_simple_layout_geometry); tcase_add_test(tc, edje_test_complex_layout); @@ -511,4 +577,5 @@ void edje_test_edje(TCase *tc) tcase_add_test(tc, edje_test_swallows_eoapi); tcase_add_test(tc, edje_test_access); tcase_add_test(tc, edje_test_box); + tcase_add_test(tc, edje_test_box_eoapi); } -- 2.7.4