changeset 1434:4be04f29fa70

Add functions to search for the text recursively inside coord_t tree. Once we find the first instance, we change the text of it. We need to think about how to manage the multiple segment texts, which is composed of several tspan.
author wycc
date Mon, 11 Apr 2011 12:52:09 +0800
parents 8e8c9ab3818f
children b12c513212af
files nodejs/coord.cc nodejs/coord.m4
diffstat 2 files changed, 48 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/nodejs/coord.cc	Mon Apr 11 00:28:45 2011 +0800
+++ b/nodejs/coord.cc	Mon Apr 11 12:52:09 2011 +0800
@@ -8,6 +8,7 @@
 #include "mb_X_supp.h"
 #include "mb_tools.h"
 #include "njs_mb_supp.h"
+#include <string.h>
 }
 
 #include "mbfly_njs.h"
@@ -15,7 +16,6 @@
 #ifndef ASSERT
 #define ASSERT(x)
 #endif
-
 #define OK 0
 
 /*! \page jsgc How to Manage Life-cycle of Objects for Javascript.
@@ -407,6 +407,50 @@
     x = cc(0)*xx+cc(1)*yy+cc(2);
     return Number::New(x);
 }
+
+static int
+xnjsmb_coord_set_text_recursive(coord_t *coord, Handle<Object> self,
+				const char *txt) {
+    shape_t *sh;
+    coord_t *child;
+    Handle<Object> rt;
+    redraw_man_t *rdman;
+
+    FOR_COORD_SHAPES(coord, sh) {
+	printf("shape type %d\n",sh->obj.obj_type);
+	if (sh->obj.obj_type == MBO_STEXT) {
+	    sh_stext_set_text(sh, txt);
+	    /*
+	     * Mark changed.
+	     */
+	    rt = GET(self, "mbrt")->ToObject();
+	    ASSERT(rt != NULL);
+	    rdman = xnjsmb_rt_rdman(rt);
+
+	    if(sh_get_coord(sh))
+		rdman_shape_changed(rdman, sh);
+	    return 1;
+	}
+    }
+    for((child) = STAILQ_HEAD((coord)->children);
+        (child) != NULL;
+        (child) = STAILQ_NEXT(coord_t, sibling, (child))) {
+	/* Invalidate members of a coord */
+	if ( xnjsmb_coord_set_text_recursive(child, self, txt))
+	    return 1;
+    }
+    return 0;
+    
+}
+
+static void
+xnjsmb_coord_set_text(coord_t *coord, Handle<Object> self,
+			 const char *txt) {
+    printf("text=%s\n",txt);
+    xnjsmb_coord_set_text_recursive(coord,self,txt);
+}
+
+
 #undef m
 
 #include "coord-inc.h"
--- a/nodejs/coord.m4	Mon Apr 11 00:28:45 2011 +0800
+++ b/nodejs/coord.m4	Mon Apr 11 12:52:09 2011 +0800
@@ -7,6 +7,9 @@
 	],
 	[METHOD([add_shape], [xnjsmb_coord_add_shape],
 		(SELF, OBJ([shape], [shape], [shape_t]), ERR), 1, []),
+
+	 METHOD([set_text], [xnjsmb_coord_set_text],
+       			    (SELF, STR([txt])), 1, []),
 	 METHOD([remove], [xnjsmb_coord_remove], (SELF), 0, []),
 	 METHOD([clone_from_subtree], [xnjsmb_coord_clone_from_subtree],
 	 	(SELF, OBJ([src], [coord], [coord_t]), ERR), 1,