new program action PARAM_SET, complements PARAM_COPY.
authorbarbieri <barbieri@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Wed, 31 Mar 2010 20:48:51 +0000 (20:48 +0000)
committerbarbieri <barbieri@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Wed, 31 Mar 2010 20:48:51 +0000 (20:48 +0000)
Sometimes you want to catch an action like "clicked" from elm/button
or "mouse,clicked,1" from a regular part and want to set a property
like "play" on some object. In this case there is no source property
to copy, so setting the destination makes sense. This was possible
with Embryo, and now it is with regular "program".

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: "button"; type: EXTERNAL;
               source: "elm/button";
               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;
                  rel2.relative: 0.5 1.0;
                  text { font: "Sans"; size: 16; }
               }
            }
            part { name: "entry"; type: EXTERNAL;
               source: "elm/scrolled_entry";
               description { state: "default" 0.0;
                  rel1.relative: 0.5 0.5;
                  params.bool: "editable" 0;
               }
            }
            programs {
               program {
                  signal: "clicked";
                  source: "button";
                  action: PARAM_SET "display" "text" "hello world!";
               }
               program {
                  signal: "clicked";
                  source: "button";
                  action: PARAM_SET "entry" "text" "bla!";
               }
            }
         }
      }
   }

}}}

git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/edje@47635 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/bin/edje_cc_handlers.c
src/lib/Edje.h
src/lib/edje_program.c

index 8318bd4..513a82f 100644 (file)
@@ -6572,7 +6572,7 @@ 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, PARAM_COPY
+        FOCUS_SET, PARAM_COPY, PARAM_SET
         Only one action can be specified per program. Examples:\n
            action: STATE_SET "statename" 0.5;\n
            action: ACTION_STOP;\n
@@ -6583,6 +6583,7 @@ st_collections_group_programs_program_in(void)
            action: FOCUS_SET;\n
            action: FOCUS_OBJECT;\n
            action: PARAM_COPY "src_part" "src_param" "dst_part" "dst_param";\n
+          action: PARAM_SET "part" "param" "value";\n
     @endproperty
 */
 static void
@@ -6605,6 +6606,7 @@ st_collections_group_programs_program_action(void)
                           "FOCUS_SET", EDJE_ACTION_TYPE_FOCUS_SET,
                           "FOCUS_OBJECT", EDJE_ACTION_TYPE_FOCUS_OBJECT,
                           "PARAM_COPY", EDJE_ACTION_TYPE_PARAM_COPY,
+                          "PARAM_SET", EDJE_ACTION_TYPE_PARAM_SET,
                           NULL);
    if (ep->action == EDJE_ACTION_TYPE_STATE_SET)
      {
@@ -6646,6 +6648,17 @@ st_collections_group_programs_program_action(void)
        free(src_part);
        free(dst_part);
      }
+   else if (ep->action == EDJE_ACTION_TYPE_PARAM_SET)
+     {
+       char *part;
+
+       part = parse_str(1);
+       ep->state = parse_str(2);
+       ep->state2 = parse_str(3);
+
+       data_queue_part_lookup(pc, part, &(ep->param.dst));
+       free(part);
+     }
 
    switch (ep->action)
      {
@@ -6667,6 +6680,9 @@ st_collections_group_programs_program_action(void)
       case EDJE_ACTION_TYPE_PARAM_COPY:
         check_arg_count(5);
         break;
+      case EDJE_ACTION_TYPE_PARAM_SET:
+        check_arg_count(4);
+        break;
       default:
        check_arg_count(3);
      }
index 3d1b8b1..90ebff2 100644 (file)
@@ -127,7 +127,8 @@ typedef enum _Edje_Action_Type
    EDJE_ACTION_TYPE_LUA_SCRIPT    = 9,
    EDJE_ACTION_TYPE_FOCUS_OBJECT  = 10,
    EDJE_ACTION_TYPE_PARAM_COPY    = 11,
-   EDJE_ACTION_TYPE_LAST          = 12
+   EDJE_ACTION_TYPE_PARAM_SET     = 12,
+   EDJE_ACTION_TYPE_LAST          = 13
 } Edje_Action_Type;
 
 typedef enum _Edje_Tween_Mode
index 5002fb7..f9122f9 100644 (file)
@@ -33,6 +33,7 @@ void *alloca (size_t);
 
 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);
+static void _edje_param_set(Edje_Real_Part *part, const char *param, const char *value);
 
 int             _edje_anim_count = 0;
 Ecore_Animator *_edje_timer = NULL;
@@ -958,6 +959,20 @@ _edje_program_run(Edje *ed, Edje_Program *pr, Eina_Bool force, const char *ssig,
 //     _edje_emit(ed, "program,stop", pr->name);
        if (_edje_block_break(ed)) goto break_prog;
      }
+   else if (pr->action == EDJE_ACTION_TYPE_PARAM_SET)
+     {
+       Edje_Real_Part *part;
+
+//     _edje_emit(ed, "program,start", pr->name);
+       if (_edje_block_break(ed)) goto break_prog;
+
+       part = ed->table_parts[pr->param.dst % ed->table_parts_size];
+       _edje_param_set(part, pr->state, 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);
@@ -2012,6 +2027,68 @@ _edje_param_copy(Edje_Real_Part *src_part, const char *src_param, Edje_Real_Part
    free(free_ptr);
 }
 
+static void
+_edje_param_set(Edje_Real_Part *part, const char *param, const char *value)
+{
+   Edje_External_Param val;
+   const Edje_External_Param_Info *info;
+
+   if ((!part) || (!param) || (!value))
+     return;
+
+   if (part->part->type == EDJE_PART_TYPE_EXTERNAL)
+     info = _edje_external_param_info_get(part->swallowed_object, param);
+   else
+     info = _edje_native_param_info_get(part, param);
+
+   if (!info)
+     {
+       ERR("cannot copy, invalid destination parameter '%s' of part '%s'",
+           param, part->part->name);
+       return;
+     }
+
+   val.name = "(temp)";
+   val.type = EDJE_EXTERNAL_PARAM_TYPE_STRING;
+   val.s = value;
+
+   if (!_edje_param_convert(&val, info))
+     {
+       ERR("cannot convert parameter type STRING to requested type %s",
+           edje_external_param_type_str(info->type));
+       return;
+     }
+
+   if (!_edje_param_validate(&val, info))
+     {
+       ERR("incorrect parameter value failed validation for type %s",
+           edje_external_param_type_str(info->type));
+       return;
+     }
+
+   if (part->part->type == EDJE_PART_TYPE_EXTERNAL)
+     {
+       val.name = param;
+       if (!_edje_external_param_set(part->swallowed_object, &val))
+         {
+            ERR("failed to set parameter '%s' (%s) of part '%s'",
+                param, edje_external_param_type_str(info->type),
+                part->part->name);
+            return;
+         }
+     }
+   else
+     {
+       if (!_edje_param_native_set(part, param, &val))
+         {
+            ERR("failed to set parameter '%s' (%s) of part '%s'",
+                param, edje_external_param_type_str(info->type),
+                part->part->name);
+            return;
+         }
+     }
+}
+
 /**
  *
  * @}