# HG changeset patch # User wycc # Date 1302497529 -28800 # Node ID 4be04f29fa708af7d7a8df7672e9369712ca656e # Parent 8e8c9ab3818f1e981bbcad70c409b2bd64ae2788 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. diff -r 8e8c9ab3818f -r 4be04f29fa70 nodejs/coord.cc --- 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 } #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 self, + const char *txt) { + shape_t *sh; + coord_t *child; + Handle 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 self, + const char *txt) { + printf("text=%s\n",txt); + xnjsmb_coord_set_text_recursive(coord,self,txt); +} + + #undef m #include "coord-inc.h" diff -r 8e8c9ab3818f -r 4be04f29fa70 nodejs/coord.m4 --- 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,