From 4ef5859cd543baab59caafbd6ab1fc08424fb725 Mon Sep 17 00:00:00 2001 From: barbieri Date: Sat, 27 Mar 2010 01:26:10 +0000 Subject: [PATCH] new program action PARAM_COPY, awesome crazy stuff! :-) Edje got a new program action called PARAM_COPY in the form: action: PARAM_COPY "src_part" "src_param" "dst_part" "dst_param"; This will copy the parameter "src_param" from part "src_part" to parameter "dst_param" of part "dst_part". So far so good, why the "crazy" in the first line? Because this also: * do type conversion! * set properties of native parts, not just EXTERNAL! The type conversion allows one to get an integer and display that in a text property, or get an string and convert into a float. The set of native parts is quite simple, basically a map of Edje.h edje_object_part_*_set(). With that one can set the string to be used by a TEXT, or set drag page/step/size/value! (page/step increments are not supported at the moment, if it is worth, they may be supported in future). Sample EDC: {{{ // test.edc, compile with edje_cc and run with edje_player externals { external: "elm"; } collections { group { name: "main"; parts { part { name: "bg"; type: RECT; description { state: "default" 0.0; color: 255 255 255 255; } } part { name: "entry"; type: EXTERNAL; source: "elm/scrolled_entry"; description { state: "default" 0.0; rel2.relative: 1.0 0.5; } } part { name: "display"; type: TEXT; description { state: "default" 0.0; color: 0 128 0 255; rel1.relative: 0.0 0.5; text { font: "Sans"; size: 16; } } } programs { program { signal: "changed"; source: "entry"; action: PARAM_COPY "entry" "text" "display" "text"; } } } } } }}} git-svn-id: http://svn.enlightenment.org/svn/e/trunk/edje@47500 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- src/bin/edje_cc_handlers.c | 31 ++- src/lib/Edje.h | 3 +- src/lib/edje_data.c | 3 + src/lib/edje_entry.c | 7 + src/lib/edje_private.h | 11 + src/lib/edje_program.c | 564 +++++++++++++++++++++++++++++++++++++++++++++ src/lib/edje_util.c | 6 +- 7 files changed, 618 insertions(+), 7 deletions(-) diff --git a/src/bin/edje_cc_handlers.c b/src/bin/edje_cc_handlers.c index d1128f4..ca808a1 100644 --- a/src/bin/edje_cc_handlers.c +++ b/src/bin/edje_cc_handlers.c @@ -6530,11 +6530,17 @@ st_collections_group_programs_program_in(void) @effect Action to be performed by the program. Valid actions are: STATE_SET, ACTION_STOP, SIGNAL_EMIT, DRAG_VAL_SET, DRAG_VAL_STEP, DRAG_VAL_PAGE, - FOCUS_SET. + FOCUS_SET, PARAM_COPY Only one action can be specified per program. Examples:\n action: STATE_SET "statename" 0.5;\n - action: ACTION_STOP "programname";\n - action: SIGNAL_EMIT "signalname" "emitter"; + action: ACTION_STOP;\n + action: SIGNAL_EMIT "signalname" "emitter";\n + action: DRAG_VAL_SET 0.5 0.0;\n + action: DRAG_VAL_STEP 1.0 0.0;\n + action: DRAG_VAL_PAGE 0.0 0.0;\n + action: FOCUS_SET;\n + action: FOCUS_OBJECT;\n + action: PARAM_COPY "src_part" "src_param" "dst_part" "dst_param";\n @endproperty */ static void @@ -6556,6 +6562,7 @@ st_collections_group_programs_program_action(void) "LUA_SCRIPT", EDJE_ACTION_TYPE_LUA_SCRIPT, "FOCUS_SET", EDJE_ACTION_TYPE_FOCUS_SET, "FOCUS_OBJECT", EDJE_ACTION_TYPE_FOCUS_OBJECT, + "PARAM_COPY", EDJE_ACTION_TYPE_PARAM_COPY, NULL); if (ep->action == EDJE_ACTION_TYPE_STATE_SET) { @@ -6582,6 +6589,21 @@ st_collections_group_programs_program_action(void) ep->value = parse_float(1); ep->value2 = parse_float(2); } + else if (ep->action == EDJE_ACTION_TYPE_PARAM_COPY) + { + char *src_part, *dst_part; + + src_part = parse_str(1); + ep->state = parse_str(2); + dst_part = parse_str(3); + ep->state2 = parse_str(4); + + data_queue_part_lookup(pc, src_part, &(ep->param.src)); + data_queue_part_lookup(pc, dst_part, &(ep->param.dst)); + + free(src_part); + free(dst_part); + } switch (ep->action) { @@ -6600,6 +6622,9 @@ st_collections_group_programs_program_action(void) case EDJE_ACTION_TYPE_FOCUS_SET: check_arg_count(1); break; + case EDJE_ACTION_TYPE_PARAM_COPY: + check_arg_count(5); + break; default: check_arg_count(3); } diff --git a/src/lib/Edje.h b/src/lib/Edje.h index c7c5207..cf58ee6 100644 --- a/src/lib/Edje.h +++ b/src/lib/Edje.h @@ -126,7 +126,8 @@ typedef enum _Edje_Action_Type EDJE_ACTION_TYPE_FOCUS_SET = 8, EDJE_ACTION_TYPE_LUA_SCRIPT = 9, EDJE_ACTION_TYPE_FOCUS_OBJECT = 10, - EDJE_ACTION_TYPE_LAST = 11 + EDJE_ACTION_TYPE_PARAM_COPY = 11, + EDJE_ACTION_TYPE_LAST = 12 } Edje_Action_Type; typedef enum _Edje_Tween_Mode diff --git a/src/lib/edje_data.c b/src/lib/edje_data.c index 3245b86..e62f16e 100644 --- a/src/lib/edje_data.c +++ b/src/lib/edje_data.c @@ -231,6 +231,9 @@ _edje_edd_init(void) EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_program, Edje_Program, "api.name", api.name, EET_T_STRING); EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_program, Edje_Program, "api.description", api.description, EET_T_STRING); + EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_program, Edje_Program, "param.src", param.src, EET_T_INT); + EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_program, Edje_Program, "param.dst", param.dst, EET_T_INT); + EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, Edje_Part_Image_Id); _edje_edd_edje_part_image_id = eet_data_descriptor_file_new(&eddc); diff --git a/src/lib/edje_entry.c b/src/lib/edje_entry.c index 6f400cd..b6a5df6 100644 --- a/src/lib/edje_entry.c +++ b/src/lib/edje_entry.c @@ -2117,6 +2117,13 @@ _edje_entry_select_allow_set(Edje_Real_Part *rp, Eina_Bool allow) en->select_allow = allow; } +Eina_Bool +_edje_entry_select_allow_get(const Edje_Real_Part *rp) +{ + const Entry *en = rp->entry_data; + return en->select_allow; +} + void _edje_entry_select_abort(Edje_Real_Part *rp) { diff --git a/src/lib/edje_private.h b/src/lib/edje_private.h index 4bdea78..ec092d1 100644 --- a/src/lib/edje_private.h +++ b/src/lib/edje_private.h @@ -448,6 +448,12 @@ struct _Edje_Program /* a conditional program to be run */ const char *name; const char *description; } api; + + /* used for PARAM_COPY (param names in state and state2 above!) */ + struct { + int src; /* part where parameter is being retrieved */ + int dst; /* part where parameter is being stored */ + } param; }; struct _Edje_Program_Target /* the target of an action */ @@ -1308,6 +1314,10 @@ Eina_Bool _edje_real_part_table_pack(Edje_Real_Part *rp, Evas_Object *ch Eina_Bool _edje_real_part_table_unpack(Edje_Real_Part *rp, Evas_Object *child_obj); void _edje_real_part_table_clear(Edje_Real_Part *rp, Eina_Bool clear); +Eina_Bool _edje_object_part_text_raw_set(Evas_Object *obj, Edje_Real_Part *rp, const char *part, const char *text); +char *_edje_text_escape(const char *text); +char *_edje_text_unescape(const char *text); + void _edje_embryo_script_init (Edje *ed); void _edje_embryo_script_shutdown (Edje *ed); void _edje_embryo_script_reset (Edje *ed); @@ -1507,6 +1517,7 @@ const Eina_List *_edje_entry_anchor_geometry_get(Edje_Real_Part *rp, const char const Eina_List *_edje_entry_anchors_list(Edje_Real_Part *rp); void _edje_entry_cursor_geometry_get(Edje_Real_Part *rp, Evas_Coord *cx, Evas_Coord *cy, Evas_Coord *cw, Evas_Coord *ch); void _edje_entry_select_allow_set(Edje_Real_Part *rp, Eina_Bool allow); +Eina_Bool _edje_entry_select_allow_get(const Edje_Real_Part *rp); void _edje_entry_select_abort(Edje_Real_Part *rp); Eina_Bool _edje_entry_cursor_next(Edje_Real_Part *rp, Edje_Cursor cur); diff --git a/src/lib/edje_program.c b/src/lib/edje_program.c index 16652e2..67fdcaa 100644 --- a/src/lib/edje_program.c +++ b/src/lib/edje_program.c @@ -32,6 +32,7 @@ void *alloca (size_t); #include "edje_private.h" static void _edje_emit_cb(Edje *ed, const char *sig, const char *src); +static void _edje_param_copy(Edje_Real_Part *src_part, const char *src_param, Edje_Real_Part *dst_part, const char *dst_param); int _edje_anim_count = 0; Ecore_Animator *_edje_timer = NULL; @@ -942,6 +943,21 @@ _edje_program_run(Edje *ed, Edje_Program *pr, Eina_Bool force, const char *ssig, } } } + else if (pr->action == EDJE_ACTION_TYPE_PARAM_COPY) + { + Edje_Real_Part *src_part, *dst_part; + +// _edje_emit(ed, "program,start", pr->name); + if (_edje_block_break(ed)) goto break_prog; + + src_part = ed->table_parts[pr->param.src % ed->table_parts_size]; + dst_part = ed->table_parts[pr->param.dst % ed->table_parts_size]; + _edje_param_copy(src_part, pr->state, dst_part, pr->state2); + + if (_edje_block_break(ed)) goto break_prog; +// _edje_emit(ed, "program,stop", pr->name); + if (_edje_block_break(ed)) goto break_prog; + } else { // _edje_emit(ed, "program,start", pr->name); @@ -1313,6 +1329,554 @@ _edje_emit_cb(Edje *ed, const char *sig, const char *src) _edje_unref(ed); } +static const Edje_External_Param_Info * +_edje_external_param_info_get(const Evas_Object *obj, const char *name) +{ + const Edje_External_Type *type; + const Edje_External_Param_Info *info; + + type = evas_object_data_get(obj, "Edje_External_Type"); + if (!type) return NULL; + for (info = type->parameters_info; info->name != NULL; info++) + if (!strcmp(info->name, name)) return info; + + return NULL; +} + +static Edje_External_Param * +_edje_param_external_get(const Evas_Object *obj, const char *name, Edje_External_Param *param) +{ + const Edje_External_Param_Info *info; + + info = _edje_external_param_info_get(obj, name); + if (!info) return NULL; + + memset(param, 0, sizeof(*param)); + param->name = info->name; + param->type = info->type; + if (!_edje_external_param_get(obj, param)) return NULL; + return param; +} + +static Edje_External_Param_Type +_edje_param_external_type_get(const Evas_Object *obj, const char *name) +{ + const Edje_External_Param_Info *info; + + info = _edje_external_param_info_get(obj, name); + if (!info) return EDJE_EXTERNAL_PARAM_TYPE_MAX; + + return info->type; +} + +/* simulate external properties for native objects */ +static Edje_External_Param * +_edje_param_native_get(Edje_Real_Part *rp, const char *name, Edje_External_Param *param, void **free_ptr) +{ + *free_ptr = NULL; + if ((rp->part->type == EDJE_PART_TYPE_TEXT) || + (rp->part->type == EDJE_PART_TYPE_TEXTBLOCK)) + { + if (!strcmp(name, "text")) + { + param->name = name; + param->type = EDJE_EXTERNAL_PARAM_TYPE_STRING; + + _edje_recalc_do(rp->edje); + if (rp->part->entry_mode > EDJE_ENTRY_EDIT_MODE_NONE) + param->s = _edje_entry_text_get(rp); + else if (rp->part->type == EDJE_PART_TYPE_TEXT) + param->s = rp->text.text; + else + param->s = evas_object_textblock_text_markup_get(rp->object); + return param; + } + if (rp->part->type == EDJE_PART_TYPE_TEXTBLOCK) + { + if (!strcmp(name, "text_unescaped")) + { + param->name = name; + param->type = EDJE_EXTERNAL_PARAM_TYPE_STRING; + + _edje_recalc_do(rp->edje); + if (rp->part->entry_mode > EDJE_ENTRY_EDIT_MODE_NONE) + { + const char *tmp = _edje_entry_text_get(rp); + char *unescaped = _edje_text_unescape(tmp); + *free_ptr = unescaped; + param->s = unescaped; + } + else if (rp->part->type == EDJE_PART_TYPE_TEXT) + param->s = rp->text.text; + else + { + const char *tmp; + char *unescaped; + + tmp = evas_object_textblock_text_markup_get(rp->object); + unescaped = _edje_text_unescape(tmp); + *free_ptr = unescaped; + param->s = unescaped; + } + + return param; + } + + if ((rp->entry_data) && + (rp->part->entry_mode > EDJE_ENTRY_EDIT_MODE_NONE) && + (!strcmp(name, "select_allow"))) + { + param->name = name; + param->type = EDJE_EXTERNAL_PARAM_TYPE_BOOL; + param->i = _edje_entry_select_allow_get(rp); + return param; + } + } + } + + if ((rp->drag) && (rp->drag->down.count == 0)) + { + if (!strncmp(name, "drag_", sizeof("drag_") - 1)) + { + const char *sub_name = name + sizeof("drag_") - 1; + if (!strcmp(sub_name, "value_x")) + { + double d; + + _edje_recalc_do(rp->edje); + d = TO_DOUBLE(rp->drag->val.x); + if (rp->part->dragable.x < 0) d = 1.0 - d; + param->name = name; + param->type = EDJE_EXTERNAL_PARAM_TYPE_DOUBLE; + param->d = d; + return param; + } + if (!strcmp(sub_name, "value_y")) + { + double d; + + _edje_recalc_do(rp->edje); + d = TO_DOUBLE(rp->drag->val.y); + if (rp->part->dragable.y < 0) d = 1.0 - d; + param->name = name; + param->type = EDJE_EXTERNAL_PARAM_TYPE_DOUBLE; + param->d = d; + return param; + } + + if (!strcmp(sub_name, "size_w")) + { + _edje_recalc_do(rp->edje); + param->name = name; + param->type = EDJE_EXTERNAL_PARAM_TYPE_DOUBLE; + param->d = TO_DOUBLE(rp->drag->size.x); + return param; + } + if (!strcmp(sub_name, "size_h")) + { + _edje_recalc_do(rp->edje); + param->name = name; + param->type = EDJE_EXTERNAL_PARAM_TYPE_DOUBLE; + param->d = TO_DOUBLE(rp->drag->size.y); + return param; + } + + if (!strcmp(sub_name, "step_x")) + { + _edje_recalc_do(rp->edje); + param->name = name; + param->type = EDJE_EXTERNAL_PARAM_TYPE_DOUBLE; + param->d = TO_DOUBLE(rp->drag->step.x); + return param; + } + if (!strcmp(sub_name, "step_y")) + { + _edje_recalc_do(rp->edje); + param->name = name; + param->type = EDJE_EXTERNAL_PARAM_TYPE_DOUBLE; + param->d = TO_DOUBLE(rp->drag->step.y); + return param; + } + + if (!strcmp(sub_name, "page_x")) + { + _edje_recalc_do(rp->edje); + param->name = name; + param->type = EDJE_EXTERNAL_PARAM_TYPE_DOUBLE; + param->d = TO_DOUBLE(rp->drag->page.x); + return param; + } + if (!strcmp(sub_name, "page_y")) + { + _edje_recalc_do(rp->edje); + param->name = name; + param->type = EDJE_EXTERNAL_PARAM_TYPE_DOUBLE; + param->d = TO_DOUBLE(rp->drag->page.y); + return param; + } + + return NULL; + } + } + + return NULL; +} + +static Eina_Bool +_edje_param_native_set(Edje_Real_Part *rp, const char *name, const Edje_External_Param *param) +{ + if ((rp->part->type == EDJE_PART_TYPE_TEXT) || + (rp->part->type == EDJE_PART_TYPE_TEXTBLOCK)) + { + if (!strcmp(name, "text")) + { + if (param->type != EDJE_EXTERNAL_PARAM_TYPE_STRING) + return EINA_FALSE; + + _edje_object_part_text_raw_set + (rp->edje->obj, rp, rp->part->name, param->s); + return EINA_TRUE; + } + if (rp->part->type == EDJE_PART_TYPE_TEXTBLOCK) + { + if (!strcmp(name, "text_unescaped")) + { + if (param->type != EDJE_EXTERNAL_PARAM_TYPE_STRING) + return EINA_FALSE; + + if (rp->part->type == EDJE_PART_TYPE_TEXT) + _edje_object_part_text_raw_set + (rp->edje->obj, rp, rp->part->name, param->s); + else + { + char *escaped = _edje_text_escape(param->s); + _edje_object_part_text_raw_set + (rp->edje->obj, rp, rp->part->name, escaped); + free(escaped); + } + + return EINA_TRUE; + } + + if ((rp->entry_data) && + (rp->part->entry_mode > EDJE_ENTRY_EDIT_MODE_NONE) && + (!strcmp(name, "select_allow"))) + { + if (param->type != EDJE_EXTERNAL_PARAM_TYPE_BOOL) + return EINA_FALSE; + _edje_entry_select_allow_set(rp, param->i); + return EINA_TRUE; + } + } + } + + if ((rp->drag) && (rp->drag->down.count == 0)) + { + if (!strncmp(name, "drag_", sizeof("drag_") - 1)) + { + const char *sub_name = name + sizeof("drag_") - 1; + if (!strcmp(sub_name, "value_x")) + { + double d; + if (param->type != EDJE_EXTERNAL_PARAM_TYPE_DOUBLE) + return EINA_FALSE; + d = param->d; + if (rp->part->dragable.confine_id != -1) + d = CLAMP(d, 0.0, 1.0); + if (rp->part->dragable.x < 0) d = 1.0 - d; + if (rp->drag->val.x == FROM_DOUBLE(d)) return EINA_TRUE; + rp->drag->val.x = FROM_DOUBLE(d); +#ifdef EDJE_CALC_CACHE + rp->invalidate = 1; +#endif + _edje_dragable_pos_set + (rp->edje, rp, rp->drag->val.x, rp->drag->val.y); + _edje_emit(rp->edje, "drag,set", rp->part->name); + return EINA_TRUE; + } + if (!strcmp(sub_name, "value_y")) + { + double d; + if (param->type != EDJE_EXTERNAL_PARAM_TYPE_DOUBLE) + return EINA_FALSE; + d = param->d; + if (rp->part->dragable.confine_id != -1) + d = CLAMP(d, 0.0, 1.0); + if (rp->part->dragable.y < 0) d = 1.0 - d; + if (rp->drag->val.y == FROM_DOUBLE(d)) return EINA_TRUE; + rp->drag->val.y = FROM_DOUBLE(d); +#ifdef EDJE_CALC_CACHE + rp->invalidate = 1; +#endif + _edje_dragable_pos_set + (rp->edje, rp, rp->drag->val.x, rp->drag->val.y); + _edje_emit(rp->edje, "drag,set", rp->part->name); + return EINA_TRUE; + } + + if (!strcmp(sub_name, "size_w")) + { + if (param->type != EDJE_EXTERNAL_PARAM_TYPE_DOUBLE) + return EINA_FALSE; + rp->drag->size.x = FROM_DOUBLE(CLAMP(param->d, 0.0, 1.0)); + rp->edje->dirty = 1; +#ifdef EDJE_CALC_CACHE + rp->invalidate = 1; +#endif + _edje_recalc(rp->edje); + return EINA_TRUE; + } + if (!strcmp(sub_name, "size_h")) + { + if (param->type != EDJE_EXTERNAL_PARAM_TYPE_DOUBLE) + return EINA_FALSE; + rp->drag->size.y = FROM_DOUBLE(CLAMP(param->d, 0.0, 1.0)); + rp->edje->dirty = 1; +#ifdef EDJE_CALC_CACHE + rp->invalidate = 1; +#endif + _edje_recalc(rp->edje); + return EINA_TRUE; + } + + if (!strcmp(sub_name, "step_x")) + { + if (param->type != EDJE_EXTERNAL_PARAM_TYPE_DOUBLE) + return EINA_FALSE; + rp->drag->step.x = FROM_DOUBLE(CLAMP(param->d, 0.0, 1.0)); +#ifdef EDJE_CALC_CACHE + rp->invalidate = 1; +#endif + return EINA_TRUE; + } + if (!strcmp(sub_name, "step_y")) + { + if (param->type != EDJE_EXTERNAL_PARAM_TYPE_DOUBLE) + return EINA_FALSE; + rp->drag->step.y = FROM_DOUBLE(CLAMP(param->d, 0.0, 1.0)); +#ifdef EDJE_CALC_CACHE + rp->invalidate = 1; +#endif + return EINA_TRUE; + } + + if (!strcmp(sub_name, "page_x")) + { + if (param->type != EDJE_EXTERNAL_PARAM_TYPE_DOUBLE) + return EINA_FALSE; + rp->drag->page.x = FROM_DOUBLE(CLAMP(param->d, 0.0, 1.0)); +#ifdef EDJE_CALC_CACHE + rp->invalidate = 1; +#endif + return EINA_TRUE; + } + if (!strcmp(sub_name, "page_y")) + { + if (param->type != EDJE_EXTERNAL_PARAM_TYPE_DOUBLE) + return EINA_FALSE; + rp->drag->page.y = FROM_DOUBLE(CLAMP(param->d, 0.0, 1.0)); +#ifdef EDJE_CALC_CACHE + rp->invalidate = 1; +#endif + return EINA_TRUE; + } + + return EINA_FALSE; + } + } + + return EINA_FALSE; +} + +static Edje_External_Param_Type +_edje_param_native_type_get(const Edje_Real_Part *rp, const char *name) +{ + if ((rp->part->type == EDJE_PART_TYPE_TEXT) || + (rp->part->type == EDJE_PART_TYPE_TEXTBLOCK)) + { + if (!strcmp(name, "text")) return EDJE_EXTERNAL_PARAM_TYPE_STRING; + if (rp->part->type == EDJE_PART_TYPE_TEXTBLOCK) + { + if (!strcmp(name, "text_unescaped")) + return EDJE_EXTERNAL_PARAM_TYPE_STRING; + if (!strcmp(name, "select_allow")) + return EDJE_EXTERNAL_PARAM_TYPE_BOOL; + } + } + + if ((rp->drag) && (rp->drag->down.count == 0)) + { + if (!strncmp(name, "drag_", sizeof("drag_") - 1)) + { + name += sizeof("drag_") - 1; + if ((!strcmp(name, "value_x")) || + (!strcmp(name, "value_y")) || + (!strcmp(name, "size_w")) || + (!strcmp(name, "size_h")) || + (!strcmp(name, "step_x")) || + (!strcmp(name, "step_y")) || + (!strcmp(name, "page_x")) || + (!strcmp(name, "page_y"))) + return EDJE_EXTERNAL_PARAM_TYPE_DOUBLE; + else + return EDJE_EXTERNAL_PARAM_TYPE_MAX; + } + } + + return EDJE_EXTERNAL_PARAM_TYPE_MAX; +} + +static Edje_External_Param * +_edje_param_convert(Edje_External_Param *param, Edje_External_Param_Type type) +{ + if (param->type == type) return param; + + switch (type) + { + case EDJE_EXTERNAL_PARAM_TYPE_BOOL: + case EDJE_EXTERNAL_PARAM_TYPE_INT: + { + int i; + switch (param->type) + { + case EDJE_EXTERNAL_PARAM_TYPE_DOUBLE: + i = (int)param->d; + break; + case EDJE_EXTERNAL_PARAM_TYPE_STRING: + i = (param->s) ? atoi(param->s) : 0; + break; + case EDJE_EXTERNAL_PARAM_TYPE_BOOL: + i = param->i; + default: + return NULL; + } + param->type = type; + param->i = i; + return param; + } + + case EDJE_EXTERNAL_PARAM_TYPE_DOUBLE: + { + double d; + switch (param->type) + { + case EDJE_EXTERNAL_PARAM_TYPE_INT: + d = (double)param->i; + break; + case EDJE_EXTERNAL_PARAM_TYPE_STRING: + d = (param->s) ? atof(param->s) : 0.0; + break; + case EDJE_EXTERNAL_PARAM_TYPE_BOOL: + d = (double)param->i; + default: + return NULL; + } + param->type = type; + param->d = d; + return param; + } + + case EDJE_EXTERNAL_PARAM_TYPE_STRING: + { + static char s[64]; + switch (param->type) + { + case EDJE_EXTERNAL_PARAM_TYPE_BOOL: + case EDJE_EXTERNAL_PARAM_TYPE_INT: + if (!snprintf(s, sizeof(s), "%i", param->i)) return NULL; + break; + case EDJE_EXTERNAL_PARAM_TYPE_DOUBLE: + if (!snprintf(s, sizeof(s), "%f", param->d)) return NULL; + break; + default: + return NULL; + } + param->type = type; + param->s = s; + return param; + } + + default: return NULL; + } +} + +static void +_edje_param_copy(Edje_Real_Part *src_part, const char *src_param, Edje_Real_Part *dst_part, const char *dst_param) +{ + Edje_External_Param val; + Edje_External_Param_Type dst_type; + void *free_ptr = NULL; + + if ((!src_part) || (!src_param) || (!dst_part) || (!dst_param)) + return; + + if (dst_part->part->type == EDJE_PART_TYPE_EXTERNAL) + dst_type = _edje_param_external_type_get + (dst_part->swallowed_object, dst_param); + else + dst_type = _edje_param_native_type_get(dst_part, dst_param); + + if (dst_type == EDJE_EXTERNAL_PARAM_TYPE_MAX) + { + ERR("cannot copy, invalid destination parameter '%s' of part '%s'", + dst_param, dst_part->part->name); + return; + } + + if (src_part->part->type == EDJE_PART_TYPE_EXTERNAL) + { + if (!_edje_param_external_get + (src_part->swallowed_object, src_param, &val)) + { + ERR("cannot get parameter '%s' of part '%s'", + src_param, src_part->part->name); + return; + } + } + else + { + if (!_edje_param_native_get(src_part, src_param, &val, &free_ptr)) + { + ERR("cannot get parameter '%s' of part '%s'", + src_param, src_part->part->name); + return; + } + } + + if (!_edje_param_convert(&val, dst_type)) + { + ERR("cannot convert parameter type %s to requested type %s", + edje_external_param_type_str(val.type), + edje_external_param_type_str(dst_type)); + goto end; + } + + if (dst_part->part->type == EDJE_PART_TYPE_EXTERNAL) + { + val.name = dst_param; + if (!_edje_external_param_set(dst_part->swallowed_object, &val)) + { + ERR("failed to set parameter '%s' (%s) of part '%s'", + dst_param, edje_external_param_type_str(dst_type), + dst_part->part->name); + goto end; + } + } + else + { + if (!_edje_param_native_set(dst_part, dst_param, &val)) + { + ERR("failed to set parameter '%s' (%s) of part '%s'", + dst_param, edje_external_param_type_str(dst_type), + dst_part->part->name); + goto end; + } + } + + end: + free(free_ptr); +} + /** * * @} diff --git a/src/lib/edje_util.c b/src/lib/edje_util.c index 4d732e8..d958777 100644 --- a/src/lib/edje_util.c +++ b/src/lib/edje_util.c @@ -1224,7 +1224,7 @@ edje_object_text_change_cb_set(Evas_Object *obj, void (*func) (void *data, Evas_ } } -static Eina_Bool +Eina_Bool _edje_object_part_text_raw_set(Evas_Object *obj, Edje_Real_Part *rp, const char *part, const char *text) { if ((!rp->text.text) && (!text)) @@ -1307,7 +1307,7 @@ edje_object_part_text_get(const Evas_Object *obj, const char *part) return NULL; } -static char * +char * _edje_text_escape(const char *text) { Eina_Strbuf *txt; @@ -1341,7 +1341,7 @@ _edje_text_escape(const char *text) return ret; } -static char * +char * _edje_text_unescape(const char *text) { Eina_Strbuf *txt; -- 2.7.4