From 96c560f77aba5d5884e31b20395d1afb98e097ed Mon Sep 17 00:00:00 2001
From: Ivica Ico Bukvic <ico@vt.edu>
Date: Fri, 2 Dec 2011 17:46:17 -0500
Subject: [PATCH] Fixed consistency errors

---
 src/g_canvas.c | 21 +++++++++++++++++++--
 src/g_editor.c | 10 ++++++----
 src/g_graph.c  |  2 +-
 3 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/src/g_canvas.c b/src/g_canvas.c
index 1b7fa0c77..2589f47cb 100644
--- a/src/g_canvas.c
+++ b/src/g_canvas.c
@@ -1808,10 +1808,27 @@ void canvasgop__clickhook(t_scalehandle *sh, t_floatarg f, t_floatarg xxx, t_flo
 
 				// check if the text is not hidden
 				// if so make minimum width and height based retrieved from getrect
-				if (!x->gl_hidetext) {
-					gobj_getrect((t_gobj*)x, (x->gl_owner ? x->gl_owner : x), &x1, &y1, &x2, &y2);
+				if (!x->gl_hidetext && x->gl_owner) {
+					gobj_getrect((t_gobj*)x, x->gl_owner, &x1, &y1, &x2, &y2);
 					if (x2-x1 > x->gl_pixwidth) x->gl_pixwidth = x2-x1;
 					if (y2-y1 > x->gl_pixheight) x->gl_pixheight = y2-y1;
+				} else {
+					// WARNING: ugly hack trying to replicate rtext_senditup if we have no parent
+					// later consider instead of hardwiring values pulling these more intelligently from
+					// a common place THIS SHOULD BE LATER MERGED WITH GRPAH_GETRECT
+					int fw = sys_fontwidth(x->gl_font);
+					int fh = sys_fontheight(x->gl_font);
+					int tcols = strlen(x->gl_name->s_name) - 3;
+					int th = fh + fh * (tcols/60) + 4;
+					if (tcols > 60) tcols = 60;
+					int tw = fw * tcols + 4;
+					if (tw + x1 > x2)
+						x2 = tw + x1;
+					if (th + y1 > y2)
+						y2 = th + y1;
+					if (x2-x1 > x->gl_pixwidth) x->gl_pixwidth = x2-x1;
+					if (y2-y1 > x->gl_pixheight) x->gl_pixheight = y2-y1;
+					//fprintf(stderr,"graph_getrect->text_getrect %d=%d %d=%d\n", fw, x2, fh, y2);
 				}
 
 				canvas_dirty(x, 1);
diff --git a/src/g_editor.c b/src/g_editor.c
index 94c4c2ffb..6820bcaff 100644
--- a/src/g_editor.c
+++ b/src/g_editor.c
@@ -1563,11 +1563,13 @@ void canvas_map(t_canvas *x, t_floatarg f);
 
 void canvas_vis(t_canvas *x, t_floatarg f)
 {
-	//fprintf(stderr,"canvas_vis %f\n", f);
+	//fprintf(stderr,"canvas_vis .x%lx %f\n", (t_int)x, f);
     char buf[30];
     int flag = (f != 0);
-    if (x != glist_getcanvas(x))
+    if (x != glist_getcanvas(x) && glist_isvisible(glist_getcanvas(x))) {
         bug("canvas_vis");
+		fprintf(stderr,"canvas_vis .x%lx .x%lx %f\n", (t_int)x, (t_int)glist_getcanvas(x), f);
+	}
     if (flag)
     {
         /* post("havewindow %d, isgraph %d, isvisible %d  editor %d",
@@ -1859,9 +1861,9 @@ static void canvas_donecanvasdialog(t_glist *x,
 
 	// make sure gop is never smaller than its text
 	// if one wants smaller gop window, make sure to disable text
-	if (x->gl_isgraph && !x->gl_hidetext) {
+	if (x->gl_isgraph && !x->gl_hidetext && x->gl_owner) {
 		//fprintf(stderr, "check size\n");
-		gobj_getrect((t_gobj*)x, (x->gl_owner ? x->gl_owner : x), &rx1, &ry1, &rx2, &ry2);
+		gobj_getrect((t_gobj*)x, x->gl_owner, &rx1, &ry1, &rx2, &ry2);
 		//fprintf(stderr,"%d %d %d %d\n", rx1, rx2, ry1, ry2);
 		if (rx2-rx1 > x->gl_pixwidth) {
 			x->gl_pixwidth = rx2-rx1;
diff --git a/src/g_graph.c b/src/g_graph.c
index 23fccfd76..9329bf6fc 100644
--- a/src/g_graph.c
+++ b/src/g_graph.c
@@ -953,10 +953,10 @@ static void graph_graphrect(t_gobj *z, t_glist *glist,
 static void graph_getrect(t_gobj *z, t_glist *glist,
     int *xp1, int *yp1, int *xp2, int *yp2)
 {
-	//fprintf(stderr,"graph_getrect\n");
     int x1 = 0x7fffffff, y1 = 0x7fffffff, x2 = -0x7fffffff, y2 = -0x7fffffff;
     int tx1 = 0x7fffffff, ty1 = 0x7fffffff, tx2 = -0x7fffffff, ty2 = -0x7fffffff;
     t_glist *x = (t_glist *)z;
+	//fprintf(stderr,"graph_getrect %d\n", x->gl_isgraph);
     if (x->gl_isgraph)
     {
         int hadwindow;
-- 
GitLab