diff nodejs/coord.cc @ 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 d82a828e8e26
children ef3908d9a3d2
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"