From: hrp@cray.com (Hal Peterson)
Subject: graph-1.0 under tk3.0
Organization: Cray Research, Inc.
Date: 7 Jan 93 16:29:16 CST

Here are some patches to get graph-1.0 (Hypertext, x-y plots, and bar
charts) to run under tk3.0.  Beware, though, this is a fifteen-minute
hack and some of it looks mighty fishy.  Can somebody suggest a better
way to handle the deletion of the window following the
Tk_EventuallyFree?

						Hal

-----------------------------------------------------------------
*** 1.1	1993/01/06 23:02:54
--- graph.c	1993/01/07 00:33:22
***************
*** 672,678 ****
  static void DestroyGraph _ANSI_ARGS_((ClientData clientData));
  static int GraphWidgetCmd _ANSI_ARGS_((ClientData clientData,
  			       Tcl_Interp * interp, int argc, char **argv));
- extern void TkBindError _ANSI_ARGS_((Tcl_Interp * interp));
  
  extern char *sys_errlist[];
  
--- 672,677 ----
***************
*** 2441,2451 ****
  	    EventuallyRedraw(graphPtr);
  	break;
      case DestroyNotify:
- 	Tcl_DeleteCommand(graphPtr->interp, Tk_PathName(graphPtr->tkwin));
- 	graphPtr->tkwin = NULL;
  	if (graphPtr->flags & REDRAW_PENDING)
  	    Tk_CancelIdleCall(DisplayGraph, (ClientData) graphPtr);
  	Tk_EventuallyFree((ClientData) graphPtr, DestroyGraph);
  	break;
      case ConfigureNotify:
  	graphPtr->flags |= LAYOUT_NEEDED;
--- 2440,2450 ----
  	    EventuallyRedraw(graphPtr);
  	break;
      case DestroyNotify:
  	if (graphPtr->flags & REDRAW_PENDING)
  	    Tk_CancelIdleCall(DisplayGraph, (ClientData) graphPtr);
  	Tk_EventuallyFree((ClientData) graphPtr, DestroyGraph);
+ 	Tcl_DeleteCommand(graphPtr->interp, Tk_PathName(graphPtr->tkwin));
+ 	graphPtr->tkwin = NULL;
  	break;
      case ConfigureNotify:
  	graphPtr->flags |= LAYOUT_NEEDED;
***************
*** 2533,2545 ****
      if (linePtr->name != NULL)
  	ckfree(linePtr->name);
      if (linePtr->stipple != None)
! 	Tk_FreeBitmap(linePtr->stipple);
      if (linePtr->fgColor != NULL)
  	Tk_FreeColor((XColor *) linePtr->fgColor);
      if (linePtr->bgColor != NULL)
  	Tk_FreeColor((XColor *) linePtr->bgColor);
      if (linePtr->gc != None)
! 	Tk_FreeGC(linePtr->gc);
      if (linePtr->x.valueArr != NULL)
  	ckfree((char *)linePtr->x.valueArr);
      if (linePtr->y.valueArr != NULL)
--- 2532,2544 ----
      if (linePtr->name != NULL)
  	ckfree(linePtr->name);
      if (linePtr->stipple != None)
! 	Tk_FreeBitmap(Tk_Display(linePtr->parent->tkwin), linePtr->stipple);
      if (linePtr->fgColor != NULL)
  	Tk_FreeColor((XColor *) linePtr->fgColor);
      if (linePtr->bgColor != NULL)
  	Tk_FreeColor((XColor *) linePtr->bgColor);
      if (linePtr->gc != None)
! 	Tk_FreeGC(Tk_Display(linePtr->parent->tkwin), linePtr->gc);
      if (linePtr->x.valueArr != NULL)
  	ckfree((char *)linePtr->x.valueArr);
      if (linePtr->y.valueArr != NULL)
***************
*** 2615,2621 ****
      }
      newGC = Tk_GetGC(tkwin, valueMask, &gcValues);
      if (linePtr->gc != None)
! 	Tk_FreeGC(linePtr->gc);
      linePtr->gc = newGC;
      return TCL_OK;
  }
--- 2614,2620 ----
      }
      newGC = Tk_GetGC(tkwin, valueMask, &gcValues);
      if (linePtr->gc != None)
! 	Tk_FreeGC(Tk_Display(tkwin), linePtr->gc);
      linePtr->gc = newGC;
      return TCL_OK;
  }
***************
*** 2778,2784 ****
      valueMask = (GCForeground | GCBackground | GCFont);
      newGC = Tk_GetGC(graphPtr->tkwin, valueMask, &gcValues);
      if (tagPtr->gc != None)
! 	Tk_FreeGC(tagPtr->gc);
      tagPtr->gc = newGC;
      return TCL_OK;
  }
--- 2777,2783 ----
      valueMask = (GCForeground | GCBackground | GCFont);
      newGC = Tk_GetGC(graphPtr->tkwin, valueMask, &gcValues);
      if (tagPtr->gc != None)
! 	Tk_FreeGC(Tk_Display(graphPtr->tkwin), tagPtr->gc);
      tagPtr->gc = newGC;
      return TCL_OK;
  }
***************
*** 3317,3323 ****
  	    if (tagPtr->bitmap != None) {
  		int w, h;
  
! 		Tk_SizeOfBitmap(tagPtr->bitmap, &w, &h);
  		DrawRotatedBitmap(graphPtr, tagPtr->bitmap, tagPtr->gc, w, h,
  				  GX(graphPtr, x), GY(graphPtr, y),
  				  tagPtr->rotation, tagPtr->anchor);
--- 3316,3323 ----
  	    if (tagPtr->bitmap != None) {
  		int w, h;
  
! 		Tk_SizeOfBitmap(Tk_Display(graphPtr->tkwin), tagPtr->bitmap,
! 				&w, &h);
  		DrawRotatedBitmap(graphPtr, tagPtr->bitmap, tagPtr->gc, w, h,
  				  GX(graphPtr, x), GY(graphPtr, y),
  				  tagPtr->rotation, tagPtr->anchor);
***************
*** 5260,5266 ****
      if (graphPtr->geometry)  /* Geometry */
  	free(graphPtr->geometry);
      if (graphPtr->gc != None)/* Graphics context of graph */
! 	Tk_FreeGC(graphPtr->gc);
      if (graphPtr->title)     /* Graph title */
  	free(graphPtr->title);
      if (graphPtr->fontPtr)   /* Normal font */
--- 5260,5266 ----
      if (graphPtr->geometry)  /* Geometry */
  	free(graphPtr->geometry);
      if (graphPtr->gc != None)/* Graphics context of graph */
! 	Tk_FreeGC(Tk_Display(graphPtr->tkwin), graphPtr->gc);
      if (graphPtr->title)     /* Graph title */
  	free(graphPtr->title);
      if (graphPtr->fontPtr)   /* Normal font */
***************
*** 5270,5280 ****
      if (graphPtr->numberFg)  /* Axis/number color */
  	Tk_FreeColor(graphPtr->numberFg);
      if (graphPtr->numberGC != None)	/* Graphics context of axis */
! 	Tk_FreeGC(graphPtr->numberGC);
      if (graphPtr->fgColor)   /* Foreground color */
  	Tk_FreeColor(graphPtr->fgColor);
      if (graphPtr->cursor != None)	/* cursor */
! 	Tk_FreeCursor(graphPtr->cursor);
      if (graphPtr->X.label)   /* X axis label */
  	ckfree(graphPtr->X.label);
      if (graphPtr->Y.label)   /* Y axis label */
--- 5270,5280 ----
      if (graphPtr->numberFg)  /* Axis/number color */
  	Tk_FreeColor(graphPtr->numberFg);
      if (graphPtr->numberGC != None)	/* Graphics context of axis */
! 	Tk_FreeGC(Tk_Display(graphPtr->tkwin), graphPtr->numberGC);
      if (graphPtr->fgColor)   /* Foreground color */
  	Tk_FreeColor(graphPtr->fgColor);
      if (graphPtr->cursor != None)	/* cursor */
! 	Tk_FreeCursor(Tk_Display(graphPtr->tkwin), graphPtr->cursor);
      if (graphPtr->X.label)   /* X axis label */
  	ckfree(graphPtr->X.label);
      if (graphPtr->Y.label)   /* Y axis label */
***************
*** 5357,5363 ****
      valueMask = (GCForeground | GCBackground | GCFont | GCLineWidth);
      newGC = Tk_GetGC(graphPtr->tkwin, valueMask, &gcValues);
      if (graphPtr->gc != None)
! 	Tk_FreeGC(graphPtr->gc);
      graphPtr->gc = newGC;
  
      /* Create axis GC */
--- 5357,5363 ----
      valueMask = (GCForeground | GCBackground | GCFont | GCLineWidth);
      newGC = Tk_GetGC(graphPtr->tkwin, valueMask, &gcValues);
      if (graphPtr->gc != None)
! 	Tk_FreeGC(Tk_Display(graphPtr->tkwin), graphPtr->gc);
      graphPtr->gc = newGC;
  
      /* Create axis GC */
***************
*** 5365,5371 ****
      gcValues.foreground = graphPtr->numberFg->pixel;
      newGC = Tk_GetGC(graphPtr->tkwin, valueMask, &gcValues);
      if (graphPtr->numberGC != None)
! 	Tk_FreeGC(graphPtr->numberGC);
      graphPtr->numberGC = newGC;
  
      return TCL_OK;
--- 5365,5371 ----
      gcValues.foreground = graphPtr->numberFg->pixel;
      newGC = Tk_GetGC(graphPtr->tkwin, valueMask, &gcValues);
      if (graphPtr->numberGC != None)
! 	Tk_FreeGC(Tk_Display(graphPtr->tkwin), graphPtr->numberGC);
      graphPtr->numberGC = newGC;
  
      return TCL_OK;
***************
*** 5706,5712 ****
  	break;
      }
      if (result != TCL_OK) {
!         TkBindError(graphPtr->interp);
  	return;
      }
      if (graphPtr->doubleBuffered) {
--- 5706,5712 ----
  	break;
      }
      if (result != TCL_OK) {
!         Tk_BackgroundError(graphPtr->interp);
  	return;
      }
      if (graphPtr->doubleBuffered) {
*** 1.1	1993/01/06 23:02:54
--- htext2.c	1993/01/07 00:36:37
***************
*** 410,416 ****
  extern int TkMeasureChars _ANSI_ARGS_ ((XFontStruct * fontStructPtr,
  		char *source, int maxChars, int startX, int maxX, int flags,
  					int *nextXPtr));
- extern void TkBindError _ANSI_ARGS_ ((Tcl_Interp * interp));
  
  /* end of Forward Declarations */
  
--- 410,415 ----
***************
*** 874,880 ****
  
      /* Free allocated memory for the following: */
      if (textPtr->gc != None) /* Graphics context */
! 	Tk_FreeGC (textPtr->gc);
      if (textPtr->border)     /* 3D Border */
  	Tk_Free3DBorder (textPtr->border);
      if (textPtr->normalFg)   /* Foreground color */
--- 873,879 ----
  
      /* Free allocated memory for the following: */
      if (textPtr->gc != None) /* Graphics context */
! 	Tk_FreeGC (Tk_Display(textPtr->tkwin), textPtr->gc);
      if (textPtr->border)     /* 3D Border */
  	Tk_Free3DBorder (textPtr->border);
      if (textPtr->normalFg)   /* Foreground color */
***************
*** 892,898 ****
      if (textPtr->text != NULL)	/* Text string */
  	ckfree (textPtr->text);
      if (textPtr->cursor != None)	/* Cursor */
! 	Tk_FreeCursor (textPtr->cursor);
      FreeLines (textPtr);
      ckfree ((char *)textPtr);/* */
  }
--- 891,897 ----
      if (textPtr->text != NULL)	/* Text string */
  	ckfree (textPtr->text);
      if (textPtr->cursor != None)	/* Cursor */
! 	Tk_FreeCursor (Tk_Display(textPtr->tkwin), textPtr->cursor);
      FreeLines (textPtr);
      ckfree ((char *)textPtr);/* */
  }
***************
*** 955,961 ****
      valueMask = GCForeground | GCFont;
      newGC = Tk_GetGC (tkwin, valueMask, &gcValues);
      if (textPtr->gc != None)
! 	Tk_FreeGC (textPtr->gc);
      textPtr->gc = newGC;
  
      /* Kill the -file option, if the -text option exists */
--- 954,960 ----
      valueMask = GCForeground | GCFont;
      newGC = Tk_GetGC (tkwin, valueMask, &gcValues);
      if (textPtr->gc != None)
! 	Tk_FreeGC (Tk_Display(textPtr->tkwin), textPtr->gc);
      textPtr->gc = newGC;
  
      /* Kill the -file option, if the -text option exists */
***************
*** 1032,1042 ****
  	break;
  
      case DestroyNotify:
- 	Tcl_DeleteCommand (textPtr->interp, Tk_PathName (textPtr->tkwin));
- 	textPtr->tkwin = NULL;
  	if (textPtr->flags & REDRAW_PENDING)
  	    Tk_CancelIdleCall (DisplayText, (ClientData) textPtr);
  	Tk_EventuallyFree ((ClientData) textPtr, DestroyText);
  	break;
  
      }
--- 1031,1041 ----
  	break;
  
      case DestroyNotify:
  	if (textPtr->flags & REDRAW_PENDING)
  	    Tk_CancelIdleCall (DisplayText, (ClientData) textPtr);
  	Tk_EventuallyFree ((ClientData) textPtr, DestroyText);
+ 	Tcl_DeleteCommand (textPtr->interp, Tk_PathName (textPtr->tkwin));
+ 	textPtr->tkwin = NULL;
  	break;
  
      }
***************
*** 2170,2176 ****
      sprintf (cmdbuf, "%s %d %d %d %d", command, totalUnits, windowUnits,
  	     firstUnit, lastUnit);
      if (Tcl_Eval (interp, cmdbuf, 0, NULL) != TCL_OK) {
! 	TkBindError (interp);
      }
  }
  
--- 2169,2175 ----
      sprintf (cmdbuf, "%s %d %d %d %d", command, totalUnits, windowUnits,
  	     firstUnit, lastUnit);
      if (Tcl_Eval (interp, cmdbuf, 0, NULL) != TCL_OK) {
! 	Tk_BackgroundError (interp);
      }
  }
  
--
Hal Peterson				Internet:  hrp@cray.com
Cray Research, Inc.			Telephone:  +1 612 683 5440

    The working class and the employing class have nothing in common.
						- The IWW Preamble
Newsgroups: comp.lang.tcl