From 9b595a2097050131cd62cbc24ae8201efbf0a83a Mon Sep 17 00:00:00 2001
From: Ivica Ico Bukvic <ico@vt.edu>
Date: Sat, 25 Feb 2012 18:24:37 -0500
Subject: [PATCH] altered behavior of gop objects so that internal elements are
 not visibly selected. Also reworked the way array and scalar selection is
 dealt with fixing segfault and making a more fool-proof way of selecting
 them.

---
 src/g_array.c    |  3 ++-
 src/g_graph.c    | 12 ++++++++----
 src/g_rtext.c    |  5 +++--
 src/g_scalar.c   | 13 ++++++++-----
 src/g_template.c | 36 ++++++++++++++++++------------------
 src/g_text.c     | 14 ++++++++------
 6 files changed, 47 insertions(+), 36 deletions(-)

diff --git a/src/g_array.c b/src/g_array.c
index b3e5fed10..035aa2795 100644
--- a/src/g_array.c
+++ b/src/g_array.c
@@ -1038,7 +1038,8 @@ static void garray_displace(t_gobj *z, t_glist *glist, int dx, int dy)
 
 static void garray_select(t_gobj *z, t_glist *glist, int state)
 {
-    t_garray *x = (t_garray *)z;
+    t_garray *x = (t_garray *)z;	
+	sys_vgui("pdtk_select_all_gop_widgets .x%lx %lx %d\n", glist_getcanvas(glist), x->x_glist, state);
     /* fill in later */
 }
 
diff --git a/src/g_graph.c b/src/g_graph.c
index e01766db1..776d270d3 100644
--- a/src/g_graph.c
+++ b/src/g_graph.c
@@ -1083,13 +1083,15 @@ static void graph_displace_withtag(t_gobj *z, t_glist *glist, int dx, int dy)
     else
     {
 		//first check for legacy objects that don't offer displacefnwtag and fallback on the old way of doing things
-		t_gobj *g;
+		/*t_gobj *g;
 		for (g = glist->gl_list; g; g = g->g_next) {
-			if (!g->g_pd->c_wb->w_displacefnwtag) {
+			if (g && !g->g_pd->c_wb->w_displacefnwtag) {
+				fprintf(stderr,"     NO fnwtag\n");
 				graph_displace(z, glist, dx, dy);
 				return;
 			}
 		}
+		fprintf(stderr,"fnwtag\n");*/
         x->gl_obj.te_xpix += dx;
         x->gl_obj.te_ypix += dy;
         canvas_fixlinesfor(glist_getcanvas(glist), &x->gl_obj);
@@ -1114,16 +1116,18 @@ static void graph_select(t_gobj *z, t_glist *glist, int state)
 		} else {
 			canvas = glist;
 		}
-        sys_vgui(".x%lx.c itemconfigure %sR -fill %s\n", canvas, 
+		if(glist_istoplevel(glist)) {
+        	sys_vgui(".x%lx.c itemconfigure %sR -fill %s\n", canvas, 
                  rtext_gettag(y), (state? "$select_color" : "$graph_outline"));
 /*
         sys_vgui(".x%lx.c itemconfigure graph%lx -fill %s\n",
                  glist_getcanvas(glist), z, 
                  (state? "$select_color" : "$graph_outline"));
 */
-        sys_vgui(".x%lx.c itemconfigure %s -fill %s\n",
+        	sys_vgui(".x%lx.c itemconfigure %s -fill %s\n",
                  canvas, rtext_gettag(y), 
                  (state? "$select_color" : "black"));
+		}
 		t_gobj *g;
 		if (x->gl_list)
 			for (g = x->gl_list; g; g = g->g_next)
diff --git a/src/g_rtext.c b/src/g_rtext.c
index 82bdce63a..bcfa6588e 100644
--- a/src/g_rtext.c
+++ b/src/g_rtext.c
@@ -404,8 +404,9 @@ void rtext_select(t_rtext *x, int state)
 {
     t_glist *glist = x->x_glist;
     t_canvas *canvas = glist_getcanvas(glist);
-    sys_vgui(".x%lx.c itemconfigure %s -fill %s\n", canvas, 
-        x->x_tag, (state? "$select_color" : "$text_color"));
+	if (glist_istoplevel(glist))
+		sys_vgui(".x%lx.c itemconfigure %s -fill %s\n", canvas, 
+		    x->x_tag, (state? "$select_color" : "$text_color"));
 	if (x->x_text->te_pd->c_wb && x->x_text->te_pd->c_wb->w_displacefnwtag) {
 		if (state)
 			sys_vgui(".x%lx.c addtag selected withtag %s\n",
diff --git a/src/g_scalar.c b/src/g_scalar.c
index b6a7e19cd..b5af20a01 100644
--- a/src/g_scalar.c
+++ b/src/g_scalar.c
@@ -203,14 +203,16 @@ static void scalar_drawselectrect(t_scalar *x, t_glist *glist, int state)
        
         scalar_getrect(&x->sc_gobj, glist, &x1, &y1, &x2, &y2);
         x1--; x2++; y1--; y2++;
-        sys_vgui(".x%lx.c create line %d %d %d %d %d %d %d %d %d %d \
-            -width 0 -fill $select_color -tags {select%lx selected}\n",
-                glist_getcanvas(glist), x1, y1, x1, y2, x2, y2, x2, y1, x1, y1,
-                x);
+		if (glist_istoplevel(glist))
+		    sys_vgui(".x%lx.c create line %d %d %d %d %d %d %d %d %d %d \
+		        -width 0 -fill $select_color -tags {select%lx selected}\n",
+		            glist_getcanvas(glist), x1, y1, x1, y2, x2, y2, x2, y1, x1, y1,
+		            x);
     }
     else
     {
-        sys_vgui(".x%lx.c delete select%lx\n", glist_getcanvas(glist), x);
+		if (glist_istoplevel(glist))
+        	sys_vgui(".x%lx.c delete select%lx\n", glist_getcanvas(glist), x);
     }
 }
 
@@ -228,6 +230,7 @@ static void scalar_select(t_gobj *z, t_glist *owner, int state)
         template_notify(tmpl, (state ? gensym("select") : gensym("deselect")),
             1, &at);
     gpointer_unset(&gp);
+	sys_vgui("pdtk_select_all_gop_widgets .x%lx %lx %d\n", glist_getcanvas(owner), owner, state);
     scalar_drawselectrect(x, owner, state);
 }
 
diff --git a/src/g_template.c b/src/g_template.c
index e7279d92b..c217bac7e 100644
--- a/src/g_template.c
+++ b/src/g_template.c
@@ -1173,16 +1173,16 @@ static void curve_vis(t_gobj *z, t_glist *glist,
                 fill, outline);
             else sys_vgui("-fill %s\\\n", outline);
             if (flags & BEZ) sys_vgui("-smooth 1\\\n");
-            sys_vgui("-tags .x%lx%s.curve%lx\n", glist_getcanvas(glist), 
-				(glist_istoplevel(glist) ? "bogus" : rtext_gettag(glist_findrtext(glist_getcanvas(glist), &glist->gl_obj))),data);
+            sys_vgui("-tags .x%lx.x%lx.curve%lx\n", glist_getcanvas(glist), glist,
+				data);
         }
         else post("warning: curves need at least two points to be graphed");
     }
     else
     {
-        if (n > 1) sys_vgui(".x%lx.c delete .x%lx%s.curve%lx\n",
-            glist_getcanvas(glist), glist_getcanvas(glist), 
-			(glist_istoplevel(glist) ? "bogus" : rtext_gettag(glist_findrtext(glist_getcanvas(glist), &glist->gl_obj))),data);      
+        if (n > 1) sys_vgui(".x%lx.c delete .x%lx.x%lx.curve%lx\n",
+            glist_getcanvas(glist), glist_getcanvas(glist), glist,
+			data);      
     }
 }
 
@@ -1648,8 +1648,8 @@ static void plot_vis(t_gobj *z, t_glist *glist,
     t_word *data, t_template *template, t_float basex, t_float basey,
     int tovis)
 {
-	//fprintf(stderr,"plot_vis %lx %lx %lx %s\n", (t_int)z, (t_int)glist, (t_int)glist_getcanvas(glist), rtext_gettag(glist_findrtext(glist_getcanvas(glist), &glist->gl_obj)));
     t_plot *x = (t_plot *)z;
+	fprintf(stderr,"plot %lx glist %lx glist_getcanvas %lx plot->x_obj %lx plot->x_canvas %lx\n", (t_int)x, (t_int)glist, (t_int)glist_getcanvas(glist), (t_int)&x->x_obj, (t_int)x->x_canvas);
     int elemsize, yonset, wonset, xonset, i;
     t_canvas *elemtemplatecanvas;
     t_template *elemtemplate;
@@ -1720,14 +1720,14 @@ static void plot_vis(t_gobj *z, t_glist *glist,
                 {
 					//we subtract 1 from y to keep it in sync with the rest of the types of templates
                     sys_vgui(
-".x%lx.c create rectangle %d %d %d %d -fill black -width 0  -tags .x%lx%s.plot%lx\n",
+".x%lx.c create rectangle %d %d %d %d -fill black -width 0  -tags .x%lx.x%lx.plot%lx\n",
                         glist_getcanvas(glist),
                         ixpix, (int)glist_ytopixels(glist, 
                             basey + fielddesc_cvttocoord(yfielddesc, minyval)) - 1,
                         inextx, (int)(glist_ytopixels(glist, 
                             basey + fielddesc_cvttocoord(yfielddesc, maxyval))
-                                + linewidth) - 1, glist_getcanvas(glist), 
-						(glist_istoplevel(glist) ? "bogus" : rtext_gettag(glist_findrtext(glist_getcanvas(glist), &glist->gl_obj))), data);
+                                + linewidth) - 1, glist_getcanvas(glist), glist,
+						 data);
                     ndrawn++;
                     minyval = 1e20;
                     maxyval = -1e20;
@@ -1820,8 +1820,8 @@ static void plot_vis(t_gobj *z, t_glist *glist,
                     outline, outline);
                 if (style == PLOTSTYLE_BEZ) sys_vgui("-smooth 1\\\n");
 
-                sys_vgui("-tags .x%lx%s.plot%lx\n", glist_getcanvas(glist), 
-					(glist_istoplevel(glist) ? "bogus" : rtext_gettag(glist_findrtext(glist_getcanvas(glist), &glist->gl_obj))), data);
+                sys_vgui("-tags .x%lx.x%lx.plot%lx\n", glist_getcanvas(glist), glist,
+					 data);
             }
             else if (linewidth > 0)
             {
@@ -1864,7 +1864,7 @@ static void plot_vis(t_gobj *z, t_glist *glist,
                 sys_vgui("-fill %s\\\n", outline);
                 if (style == PLOTSTYLE_BEZ) sys_vgui("-smooth 1\\\n");
 
-                sys_vgui("-tags .x%lx%s.plot%lx\n", glist_getcanvas(glist), (glist_istoplevel(glist) ? "bogus" : rtext_gettag(glist_findrtext(glist_getcanvas(glist), &glist->gl_obj))), data);
+                sys_vgui("-tags .x%lx.x%lx.plot%lx\n", glist_getcanvas(glist), glist, data);
             }
         }
             /* We're done with the outline; now draw all the points.
@@ -1916,8 +1916,8 @@ static void plot_vis(t_gobj *z, t_glist *glist,
             }
         }
             /* and then the trace */
-        sys_vgui(".x%lx.c delete .x%lx%s.plot%lx\n",
-            glist_getcanvas(glist), glist_getcanvas(glist), (glist_istoplevel(glist) ? "bogus" : rtext_gettag(glist_findrtext(glist_getcanvas(glist), &glist->gl_obj))), data);      
+        sys_vgui(".x%lx.c delete .x%lx.x%lx.plot%lx\n",
+            glist_getcanvas(glist), glist_getcanvas(glist), glist, data);      
     }
 }
 
@@ -2144,11 +2144,11 @@ static void drawnumber_vis(t_gobj *z, t_glist *glist,
                 glist_getcanvas(glist), xloc, yloc, colorstring, buf);
         sys_vgui(" -font {{%s} %d %s}", sys_font,
 				 sys_hostfontsize(glist_getfont(glist)), sys_fontweight);
-        sys_vgui(" -tags .x%lx%s.drawnumber%lx\n", 
-			glist_getcanvas(glist), (glist_istoplevel(glist) ? "bogus" : rtext_gettag(glist_findrtext(glist_getcanvas(glist), &glist->gl_obj))), data);
+        sys_vgui(" -tags .x%lx.x%lx.drawnumber%lx\n", 
+			glist_getcanvas(glist), glist, data);
     }
-    else sys_vgui(".x%lx.c delete .x%lx%s.drawnumber%lx\n", glist_getcanvas(glist), 
-		glist_getcanvas(glist), (glist_istoplevel(glist) ? "bogus" : rtext_gettag(glist_findrtext(glist_getcanvas(glist), &glist->gl_obj))), data);
+    else sys_vgui(".x%lx.c delete .x%lx.x%lx.drawnumber%lx\n", glist_getcanvas(glist), 
+		glist_getcanvas(glist), glist, data);
 }
 
 static t_float drawnumber_motion_ycumulative;
diff --git a/src/g_text.c b/src/g_text.c
index 23c54a35d..fc96fa683 100644
--- a/src/g_text.c
+++ b/src/g_text.c
@@ -1227,11 +1227,13 @@ static void text_select(t_gobj *z, t_glist *glist, int state)
     else
         outline = "$box_outline";
     if (glist_isvisible(glist) && gobj_shouldvis(&x->te_g, glist)) {
-        sys_vgui(".x%lx.c itemconfigure %sR -outline %s\n", glist_getcanvas(glist), 
-                 rtext_gettag(y), (state? "$select_color" : outline));
-		if (z->g_pd == gatom_class) {
-    		sys_vgui("catch {.x%lx.c itemconfigure %lx.l -fill %s}\n", glist_getcanvas(glist), 
-				x, (state? "$select_color" : "$text_color"));
+		if (glist_istoplevel(glist)) {
+		    sys_vgui(".x%lx.c itemconfigure %sR -outline %s\n", glist_getcanvas(glist), 
+		             rtext_gettag(y), (state? "$select_color" : outline));
+			if (z->g_pd == gatom_class) {
+				sys_vgui("catch {.x%lx.c itemconfigure %lx.l -fill %s}\n", glist_getcanvas(glist), 
+					x, (state? "$select_color" : "$text_color"));
+			}
 		}
 		if (z->g_pd->c_wb && z->g_pd->c_wb->w_displacefnwtag) {
 			int i, ni, no;
@@ -1243,7 +1245,7 @@ static void text_select(t_gobj *z, t_glist *glist, int state)
 		    	sys_vgui(".x%lx.c addtag selected withtag %sR \n",
 		    	    glist_getcanvas(glist), rtext_gettag(y));
 
-				if (pd_class(&x->te_pd) == text_class)
+				if (pd_class(&x->te_pd) == text_class && glist_istoplevel(glist))
 	        		sys_vgui(".x%lx.c itemconfigure %sR -width 1 -fill $obj_box_fill\n",
 						glist_getcanvas(glist), rtext_gettag(y));
 
-- 
GitLab