edje: Implement part_geometry_get with Efl.Part

This refactors even more the edje part eo internals. But now
common part APIs can easily be implemented in edje_part.c

The API now looks like:
  efl_gfx_geometry_get(efl_part(edje, "part"), &x, &y, &w, &h)
This commit is contained in:
Jean-Philippe Andre 2017-05-26 11:33:58 +09:00
parent 42403cd3df
commit da2a7e6587
14 changed files with 116 additions and 109 deletions

View File

@ -90,6 +90,7 @@ lib/edje/edje_smart.c \
lib/edje/edje_text.c \
lib/edje/edje_textblock_styles.c \
lib/edje/edje_util.c \
lib/edje/edje_legacy.c \
lib/edje/edje_var.c \
lib/edje/edje_signal.c \
lib/edje/edje_part.c \

View File

@ -149,6 +149,32 @@ EAPI Edje_Load_Error edje_object_load_error_get(const Evas_Object *obj);
*/
EAPI const char *edje_load_error_str (Edje_Load_Error error);
/**
* @brief Retrieves the geometry of a given Edje part, in a given Edje object's
* group definition, relative to the object's area.
*
* This function gets the geometry of an Edje part within its group. The x and
* y coordinates are relative to the top left corner of the whole obj object's
* area.
*
* @note Use @c null pointers on the geometry components you're not interested
* in: they'll be ignored by the function.
*
* @note On failure, this function will make all non-$null geometry pointers'
* pointed variables be set to zero.
*
* @param[in] part The Edje part's name
* @param[out] x A pointer to a variable where to store the part's x coordinate
* @param[out] y A pointer to a variable where to store the part's y coordinate
* @param[out] w A pointer to a variable where to store the part's width
* @param[out] h A pointer to a variable where to store the part's height
*
* @return @c true on success, @c false otherwise
*
* @ingroup Edje_Object
*/
EAPI Eina_Bool edje_object_part_geometry_get(const Edje_Object *obj, const char * part, int *x, int *y, int *w, int *h);
/**
* @brief Gets a handle to the Evas object implementing a given Edje part, in
* an Edje object.

View File

@ -0,0 +1,41 @@
/* Legacy API implementations based on internal EO calls */
#include "edje_private.h"
EAPI Eina_Bool
edje_object_part_geometry_get(const Edje_Object *obj, const char *part, int *x, int *y, int *w, int *h)
{
Edje_Real_Part *rp;
Edje *ed;
// Similar to geometry_get(efl_part(obj, part), x, y, w, h) but the bool
// return value matters here.
ed = _edje_fetch(obj);
if ((!ed) || (!part))
{
if (x) *x = 0;
if (y) *y = 0;
if (w) *w = 0;
if (h) *h = 0;
return EINA_FALSE;
}
/* Need to recalc before providing the object. */
_edje_recalc_do(ed);
rp = _edje_real_part_recursive_get(&ed, part);
if (!rp)
{
if (x) *x = 0;
if (y) *y = 0;
if (w) *w = 0;
if (h) *h = 0;
return EINA_FALSE;
}
if (x) *x = rp->x;
if (y) *y = rp->y;
if (w) *w = rp->w;
if (h) *h = rp->h;
return EINA_TRUE;
}

View File

@ -837,32 +837,6 @@ class Edje.Object (Efl.Canvas.Group.Clipped, Efl.File, Efl.Container, Efl.Part,
val_ret: double; [[Part state value]]
}
}
@property part_geometry {
get {
[[Retrieves the geometry of a given Edje part, in a given Edje
object's group definition, relative to the object's area.
This function gets the geometry of an Edje part within its
group. The x and y coordinates are relative to the top left
corner of the whole obj object's area.
Note: Use $null pointers on the geometry components you're not
interested in: they'll be ignored by the function.
Note: On failure, this function will make all non-$null geometry
pointers' pointed variables be set to zero.]]
return: bool; [[$true on success, $false otherwise]]
}
keys {
part: string; [[The Edje part's name]]
}
values {
x: int; [[A pointer to a variable where to store the part's x coordinate]]
y: int; [[A pointer to a variable where to store the part's y coordinate]]
w: int; [[A pointer to a variable where to store the part's width]]
h: int; [[A pointer to a variable where to store the part's height]]
}
}
@property part_drag_value {
set {
[[Sets the dragable object location.

View File

@ -1,5 +1,6 @@
#include "edje_private.h"
#include "edje_part_helper.h"
#define MY_CLASS EFL_CANVAS_LAYOUT_INTERNAL_CLASS
PROXY_INIT(box)
PROXY_INIT(table)
@ -13,11 +14,43 @@ _edje_internal_proxy_shutdown(void)
_swallow_shutdown();
}
/* Internal EO API */
void
_edje_real_part_set(Eo *obj, void *ed, void *rp, const char *part)
{
PROXY_DATA_GET(obj, pd);
pd->ed = ed;
pd->rp = rp;
pd->part = part;
pd->temp = 1;
efl_parent_set(obj, pd->ed->obj);
}
EOAPI EFL_VOID_FUNC_BODYV(_efl_canvas_layout_internal_real_part_set, EFL_FUNC_CALL(ed, rp, part), void *ed, void *rp, const char *part)
EOLIAN static Efl_Object *
_efl_canvas_layout_internal_efl_object_finalize(Eo *obj, Efl_Canvas_Layout_Internal_Data *pd)
{
EINA_SAFETY_ON_FALSE_RETURN_VAL(pd->rp && pd->ed && pd->part, NULL);
return efl_finalize(efl_super(obj, MY_CLASS));
}
#define EFL_CANVAS_LAYOUT_INTERNAL_EXTRA_OPS \
EFL_OBJECT_OP_FUNC(_efl_canvas_layout_internal_real_part_set, NULL)
EOLIAN void
_efl_canvas_layout_internal_efl_gfx_geometry_get(Eo *obj EINA_UNUSED, Efl_Canvas_Layout_Internal_Data *pd, int *x, int *y, int *w, int *h)
{
Edje_Real_Part *rp = pd->rp;
_edje_recalc_do(pd->ed);
if (!rp)
{
if (x) *x = 0;
if (y) *y = 0;
if (w) *w = 0;
if (h) *h = 0;
}
if (x) *x = rp->x;
if (y) *y = rp->y;
if (w) *w = rp->w;
if (h) *h = rp->h;
RETURN_VOID;
}
#include "efl_canvas_layout_internal.eo.c"

View File

@ -214,9 +214,4 @@ _efl_canvas_layout_internal_box_efl_orientation_orientation_get(Eo *obj, void *_
RETURN_VAL(EFL_ORIENT_NONE);
}
/* Internal EO API */
#define EFL_CANVAS_LAYOUT_INTERNAL_BOX_EXTRA_OPS \
EFL_OBJECT_OP_FUNC(_efl_canvas_layout_internal_real_part_set, _efl_canvas_layout_internal_box_efl_canvas_layout_internal_real_part_set)
#include "efl_canvas_layout_internal_box.eo.c"

View File

@ -1,8 +1,6 @@
#include "edje_private.h"
#include "efl_canvas_layout_internal.eo.h"
EOAPI void _efl_canvas_layout_internal_real_part_set(Eo *obj, void *ed, void *rp, const char *part);
typedef struct _Efl_Canvas_Layout_Internal_Data Efl_Canvas_Layout_Internal_Data;
struct _Efl_Canvas_Layout_Internal_Data
@ -27,6 +25,8 @@ struct _Part_Item_Iterator
#define RETURN_VOID do { PROXY_UNREF(obj, pd); return; } while(0)
#define PROXY_CALL(a) ({ PROXY_REF(obj, pd); a; })
void _edje_real_part_set(Eo *obj, void *ed, void *rp, const char *part);
/* ugly macros to avoid code duplication */
#define PROXY_RESET(type) \
@ -48,7 +48,7 @@ _ ## type ## _shutdown(void); \
static Eo * _ ## type ## _proxy = NULL; \
\
static void \
type ## _del_cb(Eo *proxy) \
_ ## type ## _del_cb(Eo *proxy) \
{ \
if (_ ## type ## _proxy) \
{ \
@ -85,8 +85,10 @@ _edje_ ## type ## _internal_proxy_get(Edje_Object *obj EINA_UNUSED, Edje *ed, Ed
ERR("Found invalid handle for efl_part. Reset."); \
_ ## type ## _proxy = NULL; \
} \
return efl_add(MY_CLASS, ed->obj, \
_efl_canvas_layout_internal_real_part_set(efl_added, ed, rp, rp->part->name)); \
proxy = efl_add(MY_CLASS, ed->obj, \
_edje_real_part_set(efl_added, ed, rp, rp->part->name)); \
efl_del_intercept_set(proxy, _ ## type ## _del_cb); \
return proxy; \
} \
\
if (EINA_UNLIKELY(pd->temp)) \
@ -99,28 +101,9 @@ _edje_ ## type ## _internal_proxy_get(Edje_Object *obj EINA_UNUSED, Edje *ed, Ed
} \
proxy = _ ## type ## _proxy; \
_ ## type ## _proxy = NULL; \
_efl_canvas_layout_internal_real_part_set(proxy, ed, rp, rp->part->name); \
_edje_real_part_set(proxy, ed, rp, rp->part->name); \
efl_del_intercept_set(proxy, _ ## type ## _del_cb); \
return proxy; \
} \
\
EOLIAN static void \
_efl_canvas_layout_internal_ ## type ## _efl_canvas_layout_internal_real_part_set(Eo *obj, void *_pd EINA_UNUSED, void *ed, void *rp, const char *part) \
{ \
PROXY_DATA_GET(obj, pd); \
pd->ed = ed; \
pd->rp = rp; \
pd->part = part; \
pd->temp = 1; \
efl_del_intercept_set(obj, type ## _del_cb); \
efl_parent_set(obj, pd->ed->obj); \
} \
\
EOLIAN static Efl_Object * \
_efl_canvas_layout_internal_ ## type ## _efl_object_finalize(Eo *obj, void *_pd EINA_UNUSED) \
{ \
PROXY_DATA_GET(obj, pd); \
EINA_SAFETY_ON_FALSE_RETURN_VAL(pd->rp && pd->ed && pd->part, NULL); \
return efl_finalize(efl_super(obj, MY_CLASS)); \
}
#ifdef DEBUG

View File

@ -31,9 +31,4 @@ _efl_canvas_layout_internal_swallow_efl_container_content_unset(Eo *obj, void *_
RETURN_VAL(content);
}
/* Internal EO APIs */
#define EFL_CANVAS_LAYOUT_INTERNAL_SWALLOW_EXTRA_OPS \
EFL_OBJECT_OP_FUNC(_efl_canvas_layout_internal_real_part_set, _efl_canvas_layout_internal_swallow_efl_canvas_layout_internal_real_part_set),
#include "efl_canvas_layout_internal_swallow.eo.c"

View File

@ -352,9 +352,4 @@ edje_object_part_table_clear(Edje_Object *obj, const char *part, Eina_Bool clear
return efl_pack_unpack_all(table);
}
/* Internal EO APIs */
#define EFL_CANVAS_LAYOUT_INTERNAL_TABLE_EXTRA_OPS \
EFL_OBJECT_OP_FUNC(_efl_canvas_layout_internal_real_part_set, _efl_canvas_layout_internal_table_efl_canvas_layout_internal_real_part_set),
#include "efl_canvas_layout_internal_table.eo.c"

View File

@ -1822,40 +1822,6 @@ edje_object_part_object_get(const Eo *obj, const char *part)
return rp->object;
}
EOLIAN Eina_Bool
_edje_object_part_geometry_get(Eo *obj EINA_UNUSED, Edje *ed, const char *part, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
{
Edje_Real_Part *rp;
if ((!ed) || (!part))
{
if (x) *x = 0;
if (y) *y = 0;
if (w) *w = 0;
if (h) *h = 0;
return EINA_FALSE;
}
/* Need to recalc before providing the object. */
_edje_recalc_do(ed);
rp = _edje_real_part_recursive_get(&ed, part);
if (!rp)
{
if (x) *x = 0;
if (y) *y = 0;
if (w) *w = 0;
if (h) *h = 0;
return EINA_FALSE;
}
if (x) *x = rp->x;
if (y) *y = rp->y;
if (w) *w = rp->w;
if (h) *h = rp->h;
return EINA_TRUE;
}
EOLIAN void
_edje_object_item_provider_set(Eo *obj EINA_UNUSED, Edje *ed, Edje_Item_Provider_Cb func, void *data)
{

View File

@ -2,7 +2,8 @@ class Efl.Canvas.Layout_Internal (Efl.Object, Efl.Gfx)
{
[[Common class for part proxy objects for $Efl.Canvas.Layout.]]
implements {
//Efl.Gfx.Size.geometry { get; }
Efl.Object.finalize;
Efl.Gfx.geometry { get; }
//Efl.Gfx.Size.size { get; }
}
}

View File

@ -8,7 +8,6 @@ class Efl.Canvas.Layout_Internal.Box (Efl.Canvas.Layout_Internal, Efl.Pack.Linea
]]
data: null;
implements {
Efl.Object.finalize;
Efl.Container.content_iterate;
Efl.Container.content_count;
Efl.Container.content_remove;

View File

@ -7,7 +7,6 @@ class Efl.Canvas.Layout_Internal.Swallow (Efl.Canvas.Layout_Internal, Efl.Contai
]]
data: null;
implements {
Efl.Object.finalize;
Efl.Container.content { get; set; }
Efl.Container.content_unset;
}

View File

@ -7,7 +7,6 @@ class Efl.Canvas.Layout_Internal.Table (Efl.Canvas.Layout_Internal, Efl.Pack.Gri
]]
data: null;
implements {
Efl.Object.finalize;
Efl.Container.content_iterate;
Efl.Container.content_count;
Efl.Container.content_remove;