From: barbieri Date: Thu, 25 Mar 2010 20:18:24 +0000 (+0000) Subject: allow setting parameters from embryo! X-Git-Tag: 2.0_alpha~163^2~596 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e999ba91aa9398571d7b8487d7f1286e64a7add3;p=framework%2Fuifw%2Fedje.git allow setting parameters from embryo! git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/edje@47459 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- diff --git a/data/include/edje.inc b/data/include/edje.inc index fe2fdf9..49097d9 100644 --- a/data/include/edje.inc +++ b/data/include/edje.inc @@ -151,6 +151,16 @@ native set_min_size (Float:w, Float:h); native set_max_size (Float:w, Float:h); native part_swallow (part_id, GROUP:str[]); +native external_param_get_int(id, param_name[]); +native external_param_set_int(id, param_name[], value); +native Float:external_param_get_float(id, param_name[]); +native external_param_set_float(id, param_name[], Float:value); +native external_param_get_strlen(id, param_name[]); +native external_param_get_str(id, param_name[], value[], value_maxlen); +native external_param_set_str(id, param_name[], value[]); +native external_param_get_bool(id, param_name[]); +native external_param_set_bool(id, param_name[], value); + enum Msg_Type { MSG_NONE = 0, diff --git a/src/lib/edje_embryo.c b/src/lib/edje_embryo.c index a2c84e1..ada4b21 100644 --- a/src/lib/edje_embryo.c +++ b/src/lib/edje_embryo.c @@ -211,6 +211,16 @@ void *alloca (size_t); * * part_swallow(part_id, group_name) * + * external_param_get_int(id, param_name[]) + * external_param_set_int(id, param_name[], value) + * Float:external_param_get_float(id, param_name[]) + * external_param_set_float(id, param_name[], Float:value) + * external_param_get_strlen(id, param_name[]) + * external_param_get_str(id, param_name[], value[], value_maxlen) + * external_param_set_str(id, param_name[], value[]) + * external_param_get_bool(id, param_name[]) + * external_param_set_bool(id, param_name[], value) + * * ADD/DEL CUSTOM OBJECTS UNDER SOLE EMBRYO SCRIPT CONTROL * */ @@ -2287,6 +2297,262 @@ _edje_embryo_fn_part_swallow(Embryo_Program *ep, Embryo_Cell *params) return 0; } +/* external_param_get_int(id, param_name[]) */ +static Embryo_Cell +_edje_embryo_fn_external_param_get_int(Embryo_Program *ep, Embryo_Cell *params) +{ + Edje *ed; + int part_id; + Edje_Real_Part *rp; + Edje_External_Param eep; + char *param_name; + + CHKPARAM(2); + ed = embryo_program_data_get(ep); + + part_id = params[1]; + if (part_id < 0) return 0; + rp = ed->table_parts[part_id % ed->table_parts_size]; + + GETSTR(param_name, params[2]); + if (!param_name) return 0; + eep.name = param_name; + eep.type = EDJE_EXTERNAL_PARAM_TYPE_INT; + eep.i = 0; + _edje_external_param_get(rp->swallowed_object, &eep); + return eep.i; +} + +/* external_param_set_int(id, param_name[], val) */ +static Embryo_Cell +_edje_embryo_fn_external_param_set_int(Embryo_Program *ep, Embryo_Cell *params) +{ + Edje *ed; + int part_id; + Edje_Real_Part *rp; + Edje_External_Param eep; + char *param_name; + + CHKPARAM(3); + ed = embryo_program_data_get(ep); + + part_id = params[1]; + if (part_id < 0) return 0; + rp = ed->table_parts[part_id % ed->table_parts_size]; + + GETSTR(param_name, params[2]); + if (!param_name) return 0; + eep.name = param_name; + eep.type = EDJE_EXTERNAL_PARAM_TYPE_INT; + eep.i = params[3]; + return _edje_external_param_set(rp->swallowed_object, &eep); +} + +/* Float:external_param_get_float(id, param_name[]) */ +static Embryo_Cell +_edje_embryo_fn_external_param_get_float(Embryo_Program *ep, Embryo_Cell *params) +{ + Edje *ed; + int part_id; + Edje_Real_Part *rp; + Edje_External_Param eep; + char *param_name; + float v; + + CHKPARAM(2); + ed = embryo_program_data_get(ep); + + part_id = params[1]; + if (part_id < 0) return 0; + rp = ed->table_parts[part_id % ed->table_parts_size]; + + GETSTR(param_name, params[2]); + if (!param_name) return 0; + eep.name = param_name; + eep.type = EDJE_EXTERNAL_PARAM_TYPE_DOUBLE; + eep.d = 0.0; + _edje_external_param_get(rp->swallowed_object, &eep); + v = eep.d; + return EMBRYO_FLOAT_TO_CELL(v); +} + +/* external_param_set_float(id, param_name[], Float:val) */ +static Embryo_Cell +_edje_embryo_fn_external_param_set_float(Embryo_Program *ep, Embryo_Cell *params) +{ + Edje *ed; + int part_id; + Edje_Real_Part *rp; + Edje_External_Param eep; + char *param_name; + + CHKPARAM(3); + ed = embryo_program_data_get(ep); + + part_id = params[1]; + if (part_id < 0) return 0; + rp = ed->table_parts[part_id % ed->table_parts_size]; + + GETSTR(param_name, params[2]); + if (!param_name) return 0; + eep.name = param_name; + eep.type = EDJE_EXTERNAL_PARAM_TYPE_DOUBLE; + eep.d = EMBRYO_CELL_TO_FLOAT(params[3]); + return _edje_external_param_set(rp->swallowed_object, &eep); +} + +/* external_param_get_strlen(id, param_name[]) */ +static Embryo_Cell +_edje_embryo_fn_external_param_get_strlen(Embryo_Program *ep, Embryo_Cell *params) +{ + Edje *ed; + int part_id; + Edje_Real_Part *rp; + Edje_External_Param eep; + char *param_name; + + CHKPARAM(2); + ed = embryo_program_data_get(ep); + + part_id = params[1]; + if (part_id < 0) return 0; + rp = ed->table_parts[part_id % ed->table_parts_size]; + + GETSTR(param_name, params[2]); + if (!param_name) return 0; + eep.name = param_name; + eep.type = EDJE_EXTERNAL_PARAM_TYPE_STRING; + eep.s = NULL; + _edje_external_param_get(rp->swallowed_object, &eep); + if (!eep.s) return 0; + return strlen(eep.s); +} + +/* external_param_get_str(id, param_name[], val[], val_maxlen) */ +static Embryo_Cell +_edje_embryo_fn_external_param_get_str(Embryo_Program *ep, Embryo_Cell *params) +{ + Edje *ed; + int part_id; + Edje_Real_Part *rp; + Edje_External_Param eep; + char *param_name; + size_t src_len, dst_len; + + CHKPARAM(4); + dst_len = params[4]; + if (dst_len < 1) goto error; + + ed = embryo_program_data_get(ep); + + part_id = params[1]; + if (part_id < 0) goto error; + rp = ed->table_parts[part_id % ed->table_parts_size]; + + GETSTR(param_name, params[2]); + if (!param_name) return 0; + eep.name = param_name; + eep.type = EDJE_EXTERNAL_PARAM_TYPE_STRING; + eep.s = NULL; + _edje_external_param_get(rp->swallowed_object, &eep); + if (!eep.s) goto error; + src_len = strlen(eep.s); + if (src_len < dst_len) + { + SETSTR(eep.s, params[3]); + } + else + { + char *tmp = alloca(dst_len); + memcpy(tmp, eep.s, dst_len - 1); + tmp[dst_len] = '\0'; + SETSTR(tmp, params[3]); + } + return 1; + + error: + SETSTR("", params[3]); + return 0; +} + +/* external_param_set_str(id, param_name[], val[]) */ +static Embryo_Cell +_edje_embryo_fn_external_param_set_str(Embryo_Program *ep, Embryo_Cell *params) +{ + Edje *ed; + int part_id; + Edje_Real_Part *rp; + Edje_External_Param eep; + char *param_name, *val; + + CHKPARAM(3); + ed = embryo_program_data_get(ep); + + part_id = params[1]; + if (part_id < 0) return 0; + rp = ed->table_parts[part_id % ed->table_parts_size]; + + GETSTR(param_name, params[2]); + if (!param_name) return 0; + eep.name = param_name; + eep.type = EDJE_EXTERNAL_PARAM_TYPE_STRING; + GETSTR(val, params[3]); + if (!val) return 0; + eep.s = val; + return _edje_external_param_set(rp->swallowed_object, &eep); +} + +/* external_param_get_bool(id, param_name[]) */ +static Embryo_Cell +_edje_embryo_fn_external_param_get_bool(Embryo_Program *ep, Embryo_Cell *params) +{ + Edje *ed; + int part_id; + Edje_Real_Part *rp; + Edje_External_Param eep; + char *param_name; + + CHKPARAM(2); + ed = embryo_program_data_get(ep); + + part_id = params[1]; + if (part_id < 0) return 0; + rp = ed->table_parts[part_id % ed->table_parts_size]; + + GETSTR(param_name, params[2]); + if (!param_name) return 0; + eep.name = param_name; + eep.type = EDJE_EXTERNAL_PARAM_TYPE_BOOL; + eep.i = 0; + _edje_external_param_get(rp->swallowed_object, &eep); + return eep.i; +} + +/* external_param_set_bool(id, param_name[], val) */ +static Embryo_Cell +_edje_embryo_fn_external_param_set_bool(Embryo_Program *ep, Embryo_Cell *params) +{ + Edje *ed; + int part_id; + Edje_Real_Part *rp; + Edje_External_Param eep; + char *param_name; + + CHKPARAM(3); + ed = embryo_program_data_get(ep); + + part_id = params[1]; + if (part_id < 0) return 0; + rp = ed->table_parts[part_id % ed->table_parts_size]; + + GETSTR(param_name, params[2]); + if (!param_name) return 0; + eep.name = param_name; + eep.type = EDJE_EXTERNAL_PARAM_TYPE_BOOL; + eep.i = params[3]; + return _edje_external_param_set(rp->swallowed_object, &eep); +} + void _edje_embryo_script_init(Edje *ed) { @@ -2366,6 +2632,16 @@ _edje_embryo_script_init(Edje *ed) embryo_program_native_call_add(ep, "part_swallow", _edje_embryo_fn_part_swallow); + embryo_program_native_call_add(ep, "external_param_get_int", _edje_embryo_fn_external_param_get_int); + embryo_program_native_call_add(ep, "external_param_set_int", _edje_embryo_fn_external_param_set_int); + embryo_program_native_call_add(ep, "external_param_get_float", _edje_embryo_fn_external_param_get_float); + embryo_program_native_call_add(ep, "external_param_set_float", _edje_embryo_fn_external_param_set_float); + embryo_program_native_call_add(ep, "external_param_get_strlen", _edje_embryo_fn_external_param_get_strlen); + embryo_program_native_call_add(ep, "external_param_get_str", _edje_embryo_fn_external_param_get_str); + embryo_program_native_call_add(ep, "external_param_set_str", _edje_embryo_fn_external_param_set_str); + embryo_program_native_call_add(ep, "external_param_get_bool", _edje_embryo_fn_external_param_get_bool); + embryo_program_native_call_add(ep, "external_param_set_bool", _edje_embryo_fn_external_param_set_bool); + // embryo_program_vm_push(ed->collection->script); // _edje_embryo_globals_init(ed); }