Allow sending signals to GROUP sub-parts.
authorbarbieri <barbieri@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Sat, 2 May 2009 20:05:53 +0000 (20:05 +0000)
committerbarbieri <barbieri@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Sat, 2 May 2009 20:05:53 +0000 (20:05 +0000)
Today signals emitted inside GROUP sub-parts are delivered to parent
group as "part-name:original-source". This is good and allow edje
groups to be reused. But no counter part to send events to inside
sub-groups existed.

This patch allows one to send a signal "signal" to inside a part
"part" that is of type GROUP by prepending signal emission with part name:

    emission: "part:signal"
    source: "source"

this is the same as:

   o = edje_object_part_swallow_get(ed);
   edje_object_signal_emit(o, "signal", "source");

but can be done all in themes, no need to go to application c/c++/python.

Based on patch by Pieter, see mail list.

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

src/lib/edje_program.c

index 2c6e518..2e9b383 100644 (file)
@@ -2,6 +2,7 @@
  * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
  */
 
+#define _GNU_SOURCE
 #include <string.h>
 
 #include "edje_private.h"
@@ -814,8 +815,43 @@ _edje_emit(Edje *ed, const char *sig, const char *src)
    Edje_Message_Signal emsg;
    Eina_List *l;
    Evas_Object *obj;
-   
+   const char *sep;
+
    if (ed->delete_me) return;
+
+   sep = strchr(sig, ':');
+   if (sep)
+     {
+       /* the signal contains a colon, split the signal into "group:signal",
+       * and deliver it to "group"
+       */
+       char *part = strdupa(sig);
+       if (part)
+        {
+           char *newsig = part + (sep - sig);
+           int i;
+           *newsig = '\0';
+           newsig++;
+
+            for (i = 0; i < ed->table_parts_size; i++)
+              {
+                 Edje_Real_Part *rp = ed->table_parts[i];
+                 if ((rp->part->type == EDJE_PART_TYPE_GROUP) &&
+                     (rp->swallowed_object) &&
+                     (rp->part) && (rp->part->name) &&
+                     (strcmp(rp->part->name, part) == 0))
+                   {
+                      Edje *ed2 = _edje_fetch(rp->swallowed_object);
+                      if (ed2) _edje_emit(ed2, newsig, src);
+                      return; /* stop processing.
+                              * XXX maybe let signal be processed anyway?
+                              * XXX in this case, just comment this line
+                              */
+                   }
+              }
+         }
+     }
+
    emsg.sig = sig;
    emsg.src = src;
    _edje_message_send(ed, EDJE_QUEUE_SCRIPT, EDJE_MESSAGE_SIGNAL, 0, &emsg);