Tk Source Code

Artifact [bcce26e18e]
Login

Artifact bcce26e18e77c2dd788c5a9a65942dd0e6f4f593:

Attachment "textpatch.diff" to ticket [741179ffff] added by vincentdarley 2003-05-22 06:31:28.
? textpatch.diff
? tkMenu.c.diff
? vtkMenu.c
Index: tkText.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/generic/tkText.c,v
retrieving revision 1.37
diff -u -r1.37 tkText.c
--- tkText.c	21 May 2003 09:21:57 -0000	1.37
+++ tkText.c	21 May 2003 23:20:27 -0000
@@ -1336,32 +1336,36 @@
 	    textPtr->prevHeight = Tk_Height(textPtr->tkwin);
 	}
     } else if (eventPtr->type == DestroyNotify) {
-	if (textPtr->tkwin != NULL) {
-	    /*
-	     * NOTE: we must zero out selBorder, selBorderWidthPtr and
-	     * selFgColorPtr: they are duplicates of information in the
-	     * "sel" tag, which will be freed up when we delete all tags.
-	     * Hence we don't want the automatic config options freeing
-	     * process to delete them as well.
-	     */
+	/*
+	 * NOTE: we must zero out selBorder, selBorderWidthPtr and
+	 * selFgColorPtr: they are duplicates of information in the
+	 * "sel" tag, which will be freed up when we delete all tags.
+	 * Hence we don't want the automatic config options freeing
+	 * process to delete them as well.
+	 */
 
-	    textPtr->selBorder = NULL;
-	    textPtr->selBorderWidthPtr = NULL;
-	    textPtr->selBorderWidth = 0;
-	    textPtr->selFgColorPtr = NULL;
-	    if (textPtr->setGrid) {
-		Tk_UnsetGrid(textPtr->tkwin);
-	    }
+	textPtr->selBorder = NULL;
+	textPtr->selBorderWidthPtr = NULL;
+	textPtr->selBorderWidth = 0;
+	textPtr->selFgColorPtr = NULL;
+	if (textPtr->setGrid) {
+	    Tk_UnsetGrid(textPtr->tkwin);
+	    textPtr->setGrid = 0;
+	}
+	if (!(textPtr->flags & OPTIONS_FREED)) {
 	    Tk_FreeConfigOptions((char *) textPtr, textPtr->optionTable,
 				 textPtr->tkwin);
-	    /* 
-	     * We don't delete the associated Tcl command yet, because
-	     * that will cause textPtr->tkWin to be nulled out, and that
-	     * is needed inside DestroyText to clean up certain tags
-	     * which might have been created (e.g. in the text widget
-	     * styles demo).
-	     */
+	    textPtr->flags |= OPTIONS_FREED;
 	}
+	textPtr->flags |= DESTROYED;
+	
+	/* 
+	 * We don't delete the associated Tcl command yet, because
+	 * that will cause textPtr->tkWin to be nulled out, and that
+	 * is needed inside DestroyText to clean up certain tags
+	 * which might have been created (e.g. in the text widget
+	 * styles demo).
+	 */
 	Tcl_EventuallyFree((ClientData) textPtr, DestroyText);
     } else if ((eventPtr->type == FocusIn) || (eventPtr->type == FocusOut)) {
 	if (eventPtr->xfocus.detail != NotifyInferior) {
@@ -1418,16 +1422,17 @@
 
     /*
      * This procedure could be invoked either because the window was
-     * destroyed and the command was then deleted (in which case tkwin
-     * is NULL) or because the command was deleted, and then this procedure
-     * destroys the widget.
+     * destroyed and the command was then deleted (in which this flag is
+     * already set) or because the command was deleted, and then this
+     * procedure destroys the widget.
      */
 
-    if (tkwin != NULL) {
+    if (!(textPtr->flags & DESTROYED)) {
 	if (textPtr->setGrid) {
 	    Tk_UnsetGrid(textPtr->tkwin);
+	    textPtr->setGrid = 0;
 	}
-	textPtr->tkwin = NULL;
+	textPtr->flags |= DESTROYED;
 	Tk_DestroyWindow(tkwin);
     }
 }
Index: tkText.h
===================================================================
RCS file: /cvsroot/tktoolkit/tk/generic/tkText.h,v
retrieving revision 1.14
diff -u -r1.14 tkText.h
--- tkText.h	19 May 2003 13:04:23 -0000	1.14
+++ tkText.h	21 May 2003 23:21:21 -0000
@@ -513,7 +513,6 @@
 				 * it here. */
     int state;			/* Either STATE_NORMAL or STATE_DISABLED. A
 				 * text widget is read-only when disabled. */
-
     /*
      * Default information for displaying (may be overridden by tags
      * applied to ranges of characters).
@@ -707,6 +706,10 @@
  *				for the duration of button presses.
  * UPDATE_SCROLLBARS:		Non-zero means scrollbar(s) should be updated
  *				during next redisplay operation.
+ * NEED_REPICK                  This appears unused and should probably
+ *                              be ignored
+ * OPTIONS_FREED                The widget's options have been freed
+ * DESTROYED                    The widget is going away                            				
  */
 
 #define GOT_SELECTION		1
@@ -715,6 +718,8 @@
 #define BUTTON_DOWN		8
 #define UPDATE_SCROLLBARS	0x10
 #define NEED_REPICK		0x20
+#define OPTIONS_FREED		0x40
+#define DESTROYED		0x80
 
 /*
  * Records of the following type define segment types in terms of
Index: tkTextDisp.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/generic/tkTextDisp.c,v
retrieving revision 1.15
diff -u -r1.15 tkTextDisp.c
--- tkTextDisp.c	19 May 2003 13:04:23 -0000	1.15
+++ tkTextDisp.c	21 May 2003 23:24:49 -0000
@@ -2188,7 +2188,7 @@
 				 * compiler warnings. */
     Tcl_Interp *interp;
 
-    if (textPtr->tkwin == NULL) {
+    if ((textPtr->tkwin == NULL) || (textPtr->flags & DESTROYED)) {
 
 	/*
 	 * The widget has been deleted.  Don't do anything.
@@ -2205,7 +2205,7 @@
                 TCL_GLOBAL_ONLY);
     }
 
-    if (textPtr->tkwin == NULL) {
+    if ((textPtr->tkwin == NULL) || (textPtr->flags & DESTROYED)) {
 
 	/*
 	 * The widget has been deleted.  Don't do anything.
@@ -2226,7 +2226,7 @@
                 TCL_GLOBAL_ONLY);
     }
 
-    if (textPtr->tkwin == NULL) {
+    if ((textPtr->tkwin == NULL) || (textPtr->flags & DESTROYED)) {
 
 	/*
 	 * The widget has been deleted.  Don't do anything.
@@ -2244,12 +2244,14 @@
      */
 
     while (dInfoPtr->flags & REPICK_NEEDED) {
+	int flags = textPtr->flags;
+	
 	Tcl_Preserve((ClientData) textPtr);
 	dInfoPtr->flags &= ~REPICK_NEEDED;
 	TkTextPickCurrent(textPtr, &textPtr->pickEvent);
 	tkwin = textPtr->tkwin;
 	Tcl_Release((ClientData) textPtr);
-	if (tkwin == NULL) {
+	if ((textPtr->tkwin == NULL) || (textPtr->flags & DESTROYED)) {
 	    goto end;
 	}
     }
@@ -2494,7 +2496,7 @@
 		    TCL_GLOBAL_ONLY|TCL_APPEND_VALUE|TCL_LIST_ELEMENT);
 	}
 
-        if (textPtr->tkwin == NULL) {
+        if ((textPtr->tkwin == NULL) || (textPtr->flags & DESTROYED)) {
 
 	    /*
              * The widget has been deleted.  Don't do anything.
@@ -2524,7 +2526,7 @@
 	    GetYView(textPtr->interp, textPtr, 1);
 	}
 
-        if (textPtr->tkwin == NULL) {
+        if ((textPtr->tkwin == NULL) || (textPtr->flags & DESTROYED)) {
 
 	    /*
              * The widget has been deleted.  Don't do anything.
Index: tkTextTag.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/generic/tkTextTag.c,v
retrieving revision 1.9
diff -u -r1.9 tkTextTag.c
--- tkTextTag.c	19 May 2003 13:04:24 -0000	1.9
+++ tkTextTag.c	21 May 2003 23:24:53 -0000
@@ -1187,7 +1187,7 @@
 	TkTextPickCurrent(textPtr, eventPtr);
     }
     if ((textPtr->numCurTags > 0) && (textPtr->bindingTable != NULL)
-	    && (textPtr->tkwin != NULL)) {
+	    && (textPtr->tkwin != NULL) && !(textPtr->flags & DESTROYED)) {
 	Tk_BindEvent(textPtr->bindingTable, eventPtr, textPtr->tkwin,
 		textPtr->numCurTags, (ClientData *) textPtr->curTagArrayPtr);
     }
@@ -1359,7 +1359,8 @@
     oldArrayPtr = textPtr->curTagArrayPtr;
     textPtr->curTagArrayPtr = newArrayPtr;
     if (numOldTags != 0) {
-	if ((textPtr->bindingTable != NULL) && (textPtr->tkwin != NULL)) {
+	if ((textPtr->bindingTable != NULL) && (textPtr->tkwin != NULL)
+	  && !(textPtr->flags & DESTROYED)) {
 	    event = textPtr->pickEvent;
 	    event.type = LeaveNotify;
 
@@ -1387,7 +1388,8 @@
 	    textPtr->pickEvent.xcrossing.y, &index);
     TkTextSetMark(textPtr, "current", &index);
     if (numNewTags != 0) {
-	if ((textPtr->bindingTable != NULL) && (textPtr->tkwin != NULL)) {
+	if ((textPtr->bindingTable != NULL) && (textPtr->tkwin != NULL)
+	  && !(textPtr->flags & DESTROYED)) {
 	    event = textPtr->pickEvent;
 	    event.type = EnterNotify;
 	    event.xcrossing.detail = NotifyAncestor;