Tk Source Code

Artifact [932e8d57]
Login

Artifact 932e8d578476ab28d606523ad3b1b391b062a3a9:

Attachment "tip47.patch2" to ticket [572978ff] added by mdejong 2002-06-24 13:20:04. Also attachment "tip47.patch2" to ticket [571600ff] added by mdejong 2002-06-24 11:17:21.
Index: doc/bind.n
===================================================================
RCS file: /cvsroot/tktoolkit/tk/doc/bind.n,v
retrieving revision 1.5
diff -u -r1.5 bind.n
--- doc/bind.n	23 May 2000 00:31:36 -0000	1.5
+++ doc/bind.n	24 Jun 2002 04:12:00 -0000
@@ -162,18 +162,18 @@
 couple non-standard X event types that were added to better support
 the Macintosh and Windows platforms.  Below is a list of all the valid
 types; where two names appear together, they are synonyms.
-.DS C
+.DS
 .ta 5c 10c
-\fBActivate	Enter	Map
-ButtonPress, Button	Expose	Motion
-.VS
-ButtonRelease	FocusIn	MouseWheel	
-.VE
-Circulate	FocusOut	Property
+\fBActivate	Destroy	Map
+ButtonPress, Button	Enter	MapRequest
+ButtonRelease	Expose	Motion
+Circulate	FocusIn	MouseWheel	
+CirculateRequest	FocusOut	Property
 Colormap	Gravity	Reparent
-Configure	KeyPress, Key	Unmap
-Deactivate	KeyRelease	Visibility
-Destroy	Leave\fR
+Configure	KeyPress, Key	ResizeRequest
+ConfigureRequest	KeyRelease	Unmap
+Create	Leave	Visibility
+Deactivate\fR
 .DE
 .PP
 .VS
@@ -290,6 +290,13 @@
 NotifyInferior	NotifyPointerRoot
 NotifyNonlinear	NotifyVirtual\fR
 .DE
+For \fBConfigureRequest\fR events, the string will be one of:
+.DS
+.ta 6c
+\fBAbove	Opposite
+Below	None
+BottomIf	TopIf\fR
+.DE
 For events other than these, the substituted string is undefined.
 .RE
 .IP \fB%f\fR 5
@@ -297,9 +304,13 @@
 for \fBEnter\fR and \fBLeave\fR events.
 .IP \fB%h\fR 5
 .VS
-The \fIheight\fR field from the event.  Valid for the \fBConfigure\fR and
+The \fIheight\fR field from the event.  Valid for the \fBConfigure\fR,
+\fBConfigureRequest\fR, \fBCreate\fR, \fBResizeRequest\fR, and
 \fBExpose\fR events.
 .VE
+.IP \fB%i\fR 5
+The \fIwindow\fR field from the event, represented as a hexadecimal
+integer.
 .IP \fB%k\fR 5
 The \fIkeycode\fR field from the event.  Valid only for \fBKeyPress\fR
 and \fBKeyRelease\fR events.
@@ -316,7 +327,7 @@
 .IP \fB%p\fR 5
 The \fIplace\fR field from the event, substituted as one of the
 strings \fBPlaceOnTop\fR or \fBPlaceOnBottom\fR.  Valid only
-for \fBCirculate\fR events.
+for \fBCirculate\fR and \fBCirculateRequest\fR events.
 .IP \fB%s\fR 5
 The \fIstate\fR field from the event.  For \fBButtonPress\fR,
 \fBButtonRelease\fR, \fBEnter\fR, \fBKeyPress\fR, \fBKeyRelease\fR,
@@ -330,7 +341,8 @@
 .IP \fB%w\fR 5
 The \fIwidth\fR field from the event.  Valid only for
 .VS
-\fBConfigure\fR and \fBExpose\fR events.
+\fBConfigure\fR, \fBConfigureRequest\fR, \fBCreate\fR,
+\fBResizeRequest\fR, and \fBExpose\fR events.
 .VE
 .IP \fB%x\fR 5
 The \fIx\fR field from the event.  Valid only for events containing
@@ -346,7 +358,7 @@
 Valid only for \fBKeyPress\fR and \fBKeyRelease\fR events.
 .IP \fB%B\fR 5
 The \fIborder_width\fR field from the event.  Valid only for
-\fBConfigure\fR events.
+\fBConfigure\fR, \fBConfigureRequest\fR, and \fBCreate\fR events.
 .VS
 .IP \fB%D\fR 5
 This reports the \fIdelta\fR value of a \fBMouseWheel\fR event.  The
@@ -416,7 +428,7 @@
 If the extra backslash hadn't been added, Tcl would not have been
 able to parse the script correctly.
 
-.SH MULTIPLE MATCHES
+.SH "MULTIPLE MATCHES"
 .PP
 It is possible for several bindings to match a given X event.
 If the bindings are associated with different \fItag\fR's,
@@ -436,7 +448,6 @@
 If the \fBbreak\fR command is invoked within a binding script,
 then that script terminates and no other scripts will be invoked
 for the event.
-.VS
 .PP
 If more than one binding matches a particular event and they
 have the same \fItag\fR, then the most specific binding
@@ -450,7 +461,6 @@
 (c) if the modifiers specified in one pattern are a subset of the
 modifiers in another pattern, then the pattern with more modifiers
 is more specific.
-.VS
 (d) a virtual event whose physical pattern matches the sequence is less
 specific than the same physical pattern that is not associated with a 
 virtual event.
@@ -477,7 +487,6 @@
 will be invoked, but if the user presses button 2 then one of
 either the \fB<<Paste>>\fR or the \fB<<Scroll>>\fR bindings will
 be invoked, but exactly which one gets invoked is undefined.
-.VE
 .PP
 If an X event does not match any of the existing bindings, then the
 event is ignored.
Index: generic/tk.h
===================================================================
RCS file: /cvsroot/tktoolkit/tk/generic/tk.h,v
retrieving revision 1.58
diff -u -r1.58 tk.h
--- generic/tk.h	6 Mar 2002 15:36:17 -0000	1.58
+++ generic/tk.h	24 Jun 2002 04:12:05 -0000
@@ -715,6 +715,12 @@
     (((Tk_FakeWin *) (tkwin))->flags & TK_MAPPED)
 #define Tk_IsTopLevel(tkwin) \
     (((Tk_FakeWin *) (tkwin))->flags & TK_TOP_LEVEL)
+#define Tk_HasWrapper(tkwin) \
+    (((Tk_FakeWin *) (tkwin))->flags & TK_HAS_WRAPPER)
+#define Tk_WinManaged(tkwin) \
+    (((Tk_FakeWin *) (tkwin))->flags & TK_WIN_MANAGED)
+#define Tk_TopWinHierarchy(tkwin) \
+    (((Tk_FakeWin *) (tkwin))->flags & TK_TOP_HIERARCHY)
 #define Tk_ReqWidth(tkwin)		(((Tk_FakeWin *) (tkwin))->reqWidth)
 #define Tk_ReqHeight(tkwin)		(((Tk_FakeWin *) (tkwin))->reqHeight)
 /* Tk_InternalBorderWidth is deprecated */
@@ -792,9 +798,7 @@
  *
  * TK_MAPPED:			1 means window is currently mapped,
  *				0 means unmapped.
- * TK_TOP_LEVEL:		1 means this is a top-level window (it
- *				was or will be created as a child of
- *				a root window).
+ * TK_TOP_LEVEL:		1 means this is a top-level widget.
  * TK_ALREADY_DEAD:		1 means the window is in the process of
  *				being destroyed already.
  * TK_NEED_CONFIG_NOTIFY:	1 means that the window has been reconfigured
@@ -846,6 +850,18 @@
  *				special Unix menubar windows.
  * TK_ANONYMOUS_WINDOW:		1 means that this window has no name, and is
  *				thus not accessible from Tk.
+ * TK_HAS_WRAPPER		1 means that this window has a wrapper window
+ * TK_WIN_MANAGED		1 means that this window is a child of the
+ *				root window, and is managed by the window
+ *				manager.
+ * TK_TOP_HIERARCHY		1 means this window is at the top of a
+ *				physical window hierarchy within this
+ *				process, i.e. the window's parent
+ *				either doesn't exist or is not owned by
+ *				this Tk application.
+ * TK_PROP_PROPCHANGE		1 means that PropertyNotify events in
+ *				this window's children should propagate
+ *				up to this window.
  */
 
 
@@ -864,6 +880,10 @@
 #define TK_WRAPPER		0x1000
 #define TK_REPARENTED		0x2000
 #define TK_ANONYMOUS_WINDOW	0x4000
+#define TK_HAS_WRAPPER		0x8000
+#define TK_WIN_MANAGED		0x10000
+#define TK_TOP_HIERARCHY	0x20000
+#define TK_PROP_PROPCHANGE	0x40000
 
 /*
  *--------------------------------------------------------------
Index: generic/tkBind.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/generic/tkBind.c,v
retrieving revision 1.21
diff -u -r1.21 tkBind.c
--- generic/tkBind.c	25 Jan 2002 21:09:36 -0000	1.21
+++ generic/tkBind.c	24 Jun 2002 04:12:05 -0000
@@ -506,6 +506,11 @@
     {"Activate",	ActivateNotify,		ActivateMask},
     {"Deactivate",	DeactivateNotify,	ActivateMask},
     {"MouseWheel",	MouseWheelEvent,	MouseWheelMask},
+    {"CirculateRequest", CirculateRequest,	SubstructureRedirectMask},
+    {"ConfigureRequest", ConfigureRequest,	SubstructureRedirectMask},
+    {"Create",		CreateNotify,		SubstructureNotifyMask},
+    {"MapRequest",	MapRequest,             SubstructureRedirectMask},
+    {"ResizeRequest",	ResizeRequest,		ResizeRedirectMask},
     {(char *) NULL,	0,			0}
 };
 static Tcl_HashTable eventTable;
@@ -537,6 +542,10 @@
 #define COLORMAP		0x10000
 #define VIRTUAL			0x20000
 #define ACTIVATE		0x40000
+#define	MAPREQ			0x80000
+#define	CONFIGREQ		0x100000
+#define	RESIZEREQ		0x200000
+#define CIRCREQ			0x400000
 
 #define KEY_BUTTON_MOTION_VIRTUAL	(KEY|BUTTON|MOTION|VIRTUAL)
 
@@ -561,12 +570,12 @@
    /* DestroyNotify */		DESTROY,
    /* UnmapNotify */		UNMAP,
    /* MapNotify */		MAP,
-   /* MapRequest */		0,
+   /* MapRequest */		MAPREQ,
    /* ReparentNotify */		REPARENT,
    /* ConfigureNotify */	CONFIG,
-   /* ConfigureRequest */	0,
+   /* ConfigureRequest */	CONFIGREQ,
    /* GravityNotify */		GRAVITY,
-   /* ResizeRequest */		0,
+   /* ResizeRequest */		RESIZEREQ,
    /* CirculateNotify */	CIRC,
    /* CirculateRequest */	0,
    /* PropertyNotify */		PROP,
@@ -636,6 +645,22 @@
     {-1, NULL}
 };
 
+static TkStateMap configureRequestDetail[] = {
+    {None,		"None"},
+    {Above,		"Above"},
+    {Below,		"Below"},
+    {BottomIf,		"BottomIf"},
+    {TopIf,		"TopIf"},
+    {Opposite,		"Opposite"},
+    {-1, NULL}
+};
+
+static TkStateMap propNotify[] = {
+    {PropertyNewValue,	"NewValue"},
+    {PropertyDelete,	"Delete"},
+    {-1, NULL}
+};
+
 /*
  * Prototypes for local procedures defined in this file:
  */
@@ -2032,6 +2057,10 @@
 		}
 		goto nextEvent;
 	    }
+	    if (eventPtr->xany.type == CreateNotify
+		&& eventPtr->xcreatewindow.parent != window) {
+		goto nextSequence;
+	    } else 
 	    if (eventPtr->xany.window != window) {
 		goto nextSequence;
 	    }
@@ -2245,6 +2274,7 @@
     *sourcePtrPtr = bestSourcePtr;
     return bestPtr;
 }
+
 
 /*
  *--------------------------------------------------------------
@@ -2343,6 +2373,14 @@
 		    }
 		    string = TkFindStateString(notifyDetail, number);
 		}
+		else if (flags & CONFIGREQ) {
+		    if (eventPtr->xconfigurerequest.value_mask & CWStackMode) {
+			string = TkFindStateString(configureRequestDetail,
+					eventPtr->xconfigurerequest.detail);
+		    } else {
+			string = "";
+		    }
+		}
 		goto doString;
 	    case 'f':
 		number = eventPtr->xcrossing.focus;
@@ -2353,7 +2391,26 @@
 		} else if (flags & (CONFIG)) {
 		    number = eventPtr->xconfigure.height;
 		}
+		else if (flags & CREATE) {
+		    number = eventPtr->xcreatewindow.height;
+		} else if (flags & CONFIGREQ) {
+		    number =  eventPtr->xconfigurerequest.height;
+		} else if (flags & RESIZEREQ) {
+		    number =  eventPtr->xresizerequest.height;
+		}
 		goto doNumber;
+	    case 'i':
+		if (flags & CREATE) {
+		    TkpPrintWindowId(numStorage, eventPtr->xcreatewindow.window);
+		} else if (flags & CONFIGREQ) {
+		    TkpPrintWindowId(numStorage, eventPtr->xconfigurerequest.window);
+		} else if (flags & MAPREQ) {
+		    TkpPrintWindowId(numStorage, eventPtr->xmaprequest.window);
+		} else {
+		    TkpPrintWindowId(numStorage, eventPtr->xany.window);
+		}
+		string = numStorage;
+		goto doString;
 	    case 'k':
 		number = eventPtr->xkey.keycode;
 		goto doNumber;
@@ -2377,13 +2434,21 @@
 		}
 		goto doNumber;
 	    case 'p':
-		string = TkFindStateString(circPlace, eventPtr->xcirculate.place);
+		if (flags & CIRC) {
+		    string = TkFindStateString(circPlace, eventPtr->xcirculate.place);
+		} else if (flags & CIRCREQ) {
+		    string = TkFindStateString(circPlace, eventPtr->xcirculaterequest.place);
+		}
 		goto doString;
 	    case 's':
 		if (flags & (KEY_BUTTON_MOTION_VIRTUAL)) {
 		    number = eventPtr->xkey.state;
 		} else if (flags & CROSSING) {
 		    number = eventPtr->xcrossing.state;
+		} else if (flags & PROP) {
+		    string = TkFindStateString(propNotify,
+			    eventPtr->xproperty.state);
+		    goto doString;
 		} else if (flags & VISIBILITY) {
 		    string = TkFindStateString(visNotify,
 			    eventPtr->xvisibility.state);
@@ -2408,6 +2473,13 @@
 		} else if (flags & CONFIG) {
 		    number = eventPtr->xconfigure.width;
 		}
+		else if (flags & CREATE) {
+		    number = eventPtr->xcreatewindow.width;
+		} else if (flags & CONFIGREQ) {
+		    number =  eventPtr->xconfigurerequest.width;
+		} else if (flags & RESIZEREQ) {
+		    number =  eventPtr->xresizerequest.width;
+		}
 		goto doNumber;
 	    case 'x':
 		if (flags & (KEY_BUTTON_MOTION_VIRTUAL)) {
@@ -2421,6 +2493,11 @@
 		} else if (flags & REPARENT) {
 		    number = eventPtr->xreparent.x;
 		}
+		else if (flags & CREATE) {
+		    number = eventPtr->xcreatewindow.x;
+		} else if (flags & CONFIGREQ) {
+		    number =  eventPtr->xconfigurerequest.x;
+		}
 		goto doNumber;
 	    case 'y':
 		if (flags & (KEY_BUTTON_MOTION_VIRTUAL)) {
@@ -2435,6 +2512,11 @@
 		    number = eventPtr->xcrossing.y;
 
 		}
+		else if (flags & CREATE) {
+		    number = eventPtr->xcreatewindow.y;
+		} else if (flags & CONFIGREQ) {
+		    number =  eventPtr->xconfigurerequest.y;
+		}
 		goto doNumber;
 	    case 'A':
 		if (flags & KEY) {
@@ -2443,7 +2525,13 @@
 		}
 		goto doString;
 	    case 'B':
-		number = eventPtr->xcreatewindow.border_width;
+		if (flags & CREATE) {
+		    number = eventPtr->xcreatewindow.border_width;
+		} else if (flags & CONFIGREQ) {
+		    number = eventPtr->xconfigurerequest.border_width;
+		} else {
+		    number = eventPtr->xconfigure.border_width;
+		}
 		goto doNumber;
 	    case 'D':
 		/*
@@ -2468,6 +2556,11 @@
 	    case 'N':
 		number = (int) keySym;
 		goto doNumber;
+	    case 'P':
+		if (flags & PROP) {
+		    string = Tk_GetAtomName((Tk_Window) winPtr, eventPtr->xproperty.atom);
+		}
+		goto doString;
 	    case 'R':
 		TkpPrintWindowId(numStorage, eventPtr->xkey.root);
 		string = numStorage;
Index: generic/tkCanvWind.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/generic/tkCanvWind.c,v
retrieving revision 1.5
diff -u -r1.5 tkCanvWind.c
--- generic/tkCanvWind.c	3 Jul 2001 06:03:44 -0000	1.5
+++ generic/tkCanvWind.c	24 Jun 2002 04:12:05 -0000
@@ -353,7 +353,7 @@
 	    /*
 	     * Make sure that the canvas is either the parent of the
 	     * window associated with the item or a descendant of that
-	     * parent.  Also, don't allow a top-level window to be
+	     * parent.  Also, don't allow a top-of-hierarchy window to be
 	     * managed inside a canvas.
 	     */
 
@@ -363,7 +363,7 @@
 		if (ancestor == parent) {
 		    break;
 		}
-		if (((Tk_FakeWin *) (ancestor))->flags & TK_TOP_LEVEL) {
+		if (((Tk_FakeWin *) (ancestor))->flags & TK_TOP_HIERARCHY) {
 		    badWindow:
 		    Tcl_AppendResult(interp, "can't use ",
 			    Tk_PathName(winItemPtr->tkwin),
@@ -372,7 +372,7 @@
 		    return TCL_ERROR;
 		}
 	    }
-	    if (((Tk_FakeWin *) (winItemPtr->tkwin))->flags & TK_TOP_LEVEL) {
+	    if (((Tk_FakeWin *) (winItemPtr->tkwin))->flags & TK_TOP_HIERARCHY) {
 		goto badWindow;
 	    }
 	    if (winItemPtr->tkwin == canvasTkwin) {
Index: generic/tkCmds.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/generic/tkCmds.c,v
retrieving revision 1.23
diff -u -r1.23 tkCmds.c
--- generic/tkCmds.c	20 Mar 2002 22:55:16 -0000	1.23
+++ generic/tkCmds.c	24 Jun 2002 04:12:11 -0000
@@ -270,7 +270,7 @@
 	objPtr[0] = (ClientData) winPtr->pathName;
 	objPtr[1] = (ClientData) winPtr->classUid;
 	for (topLevPtr = winPtr;
-		(topLevPtr != NULL) && !(topLevPtr->flags & TK_TOP_LEVEL);
+		(topLevPtr != NULL) && !(topLevPtr->flags & TK_TOP_HIERARCHY);
 		topLevPtr = topLevPtr->parentPtr) {
 	    /* Empty loop body. */
 	}
@@ -337,7 +337,7 @@
 	    Tcl_ListObjAppendElement(interp, listPtr,
 		    Tcl_NewStringObj(winPtr->classUid, -1));
 	    winPtr2 = winPtr;
-	    while ((winPtr2 != NULL) && !(Tk_IsTopLevel(winPtr2))) {
+	    while ((winPtr2 != NULL) && !(Tk_TopWinHierarchy(winPtr2))) {
 		winPtr2 = winPtr2->parentPtr;
 	    }
 	    if ((winPtr != winPtr2) && (winPtr2 != NULL)) {
@@ -1246,7 +1246,7 @@
 		if ((winPtr == NULL) || !(winPtr->flags & TK_MAPPED)) {
 		    break;
 		}
-		if (winPtr->flags & TK_TOP_LEVEL) {
+		if (winPtr->flags & TK_TOP_HIERARCHY) {
 		    viewable = 1;
 		    break;
 		}
Index: generic/tkEvent.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/generic/tkEvent.c,v
retrieving revision 1.9
diff -u -r1.9 tkEvent.c
--- generic/tkEvent.c	5 Apr 2002 08:41:07 -0000	1.9
+++ generic/tkEvent.c	24 Jun 2002 04:12:11 -0000
@@ -161,6 +161,8 @@
 static void		DelayedMotionProc _ANSI_ARGS_((ClientData clientData));
 static int		WindowEventProc _ANSI_ARGS_((Tcl_Event *evPtr,
 			    int flags));
+static int		TkXErrorHandler _ANSI_ARGS_((ClientData clientData,
+			    XErrorEvent *errEventPtr));
 
 
 /*
@@ -519,6 +521,91 @@
 /*
  *--------------------------------------------------------------
  *
+ * TkXErrorHandler --
+ *
+ *	TkXErrorHandler is an error handler, to be installed
+ *	via Tk_CreateErrorHandler, that will set a flag if an
+ *	X error occurred.
+ *
+ * Results:
+ *	Always returns 0, indicating that the X error was
+ *	handled.
+ *
+ * Side effects:
+ *	None.
+ *
+ *--------------------------------------------------------------
+ */
+
+static int
+TkXErrorHandler (clientData, errEventPtr)
+    ClientData clientData;      /* Pointer to flag we set       */
+    XErrorEvent *errEventPtr;   /* X error info                 */
+{
+    int *error;
+
+    error = (int *) clientData;
+    *error = 1;
+    return 0;
+}
+
+/*
+ *--------------------------------------------------------------
+ *
+ * ParentXId --
+ *
+ *	Returns the parent of the given window, or "None"
+ *	if the window doesn't exist.
+ *
+ * Results:
+ *	Returns an X window ID.
+ *
+ * Side effects:
+ *	None.
+ *
+ *--------------------------------------------------------------
+ */
+
+static Window
+ParentXId(display, w)
+    Display *display;
+    Window w;
+{
+    Tk_ErrorHandler handler;
+    int gotXError;
+    Status status;
+    Window parent;
+    Window root;
+    Window *childList;
+    unsigned int nChildren;
+
+    /* Handle errors ourselves. */
+
+    gotXError = 0;
+    handler = Tk_CreateErrorHandler(display, -1, -1, -1,
+			TkXErrorHandler, (ClientData) (&gotXError));
+
+    /* Get the parent window. */
+
+    status = XQueryTree(display, w, &root, &parent, &childList, &nChildren);
+
+    /* Do some cleanup; gotta return "None" if we got an error. */
+
+    Tk_DeleteErrorHandler(handler);
+    XSync(display, False);
+    if (status != 0 && childList != NULL) {
+	XFree(childList);
+    }
+    if (status == 0) {
+        parent = None;
+    }
+
+    return parent;
+}
+
+/*
+ *--------------------------------------------------------------
+ *
  * Tk_HandleEvent --
  *
  *	Given an event, invoke all the handlers that have
@@ -544,6 +631,7 @@
     unsigned long mask;
     InProgress ip;
     Window handlerWindow;
+    Window parentXId;
     TkDisplay *dispPtr;
     Tcl_Interp *interp = (Tcl_Interp *) NULL;
     ThreadSpecificData *tsdPtr = (ThreadSpecificData *) 
@@ -655,18 +743,38 @@
     }
     winPtr = (TkWindow *) Tk_IdToWindow(eventPtr->xany.display, handlerWindow);
     if (winPtr == NULL) {
-
 	/*
 	 * There isn't a TkWindow structure for this window.
 	 * However, if the event is a PropertyNotify event then call
 	 * the selection manager (it deals beneath-the-table with
-	 * certain properties).
+	 * certain properties). Also, if the window's parent is a
+	 * Tk window that has the TK_PROP_PROPCHANGE flag set, then
+	 * we must propagate the PropertyNotify event up to the parent.
 	 */
 
-	if (eventPtr->type == PropertyNotify) {
-	    TkSelPropProc(eventPtr);
+	if (eventPtr->type != PropertyNotify) {
+	    return;
 	}
-	return;
+
+	TkSelPropProc(eventPtr);
+
+	/* Get handlerWindow's parent. */
+
+	parentXId = ParentXId(eventPtr->xany.display, handlerWindow);
+	if (parentXId == None) {
+	    return;
+	}
+
+	winPtr = (TkWindow *) Tk_IdToWindow(eventPtr->xany.display, parentXId);
+	if (winPtr == NULL) {
+	    return;
+	}
+
+	if (!(winPtr->flags & TK_PROP_PROPCHANGE)) {
+	    return;
+	}
+
+	handlerWindow = parentXId;
     }
 
     /*
@@ -893,7 +1001,14 @@
 	 * these events here than in the lower-level procedures.
 	 */
 
-	if ((ip.winPtr != None) && (mask != SubstructureNotifyMask)) {
+	/*
+	 * ...well, except when we use the tkwm patches, in which case
+	 * we DO handle CreateNotify events, so we gotta pass 'em through.
+	 */
+
+	if ((ip.winPtr != None)
+		&& ((mask != SubstructureNotifyMask)
+				|| (eventPtr->type == CreateNotify))) {
 	    TkBindEventProc(winPtr, eventPtr);
 	}
     }
@@ -1172,7 +1287,7 @@
     
     childPtr = winPtr->childList;
     while (childPtr != NULL) {
-	if (!Tk_IsTopLevel(childPtr)) {
+	if (!Tk_TopWinHierarchy(childPtr)) {
 	    TkQueueEventForAllChildren(childPtr, eventPtr);
 	}
 	childPtr = childPtr->nextPtr;
Index: generic/tkFocus.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/generic/tkFocus.c,v
retrieving revision 1.7
diff -u -r1.7 tkFocus.c
--- generic/tkFocus.c	12 Apr 2002 10:03:24 -0000	1.7
+++ generic/tkFocus.c	24 Jun 2002 04:12:11 -0000
@@ -216,7 +216,7 @@
 	    }
 	    for (topLevelPtr = newPtr; topLevelPtr != NULL;
 		    topLevelPtr = topLevelPtr->parentPtr)  {
-		if (topLevelPtr->flags & TK_TOP_LEVEL) {
+		if (topLevelPtr->flags & TK_TOP_HIERARCHY) {
 		    for (tlFocusPtr = newPtr->mainPtr->tlFocusPtr;
 			    tlFocusPtr != NULL;
 			    tlFocusPtr = tlFocusPtr->nextPtr) {
@@ -588,7 +588,7 @@
 	if (!(topLevelPtr->flags & TK_MAPPED)) {
 	    allMapped = 0;
 	}
-	if (topLevelPtr->flags & TK_TOP_LEVEL) {
+	if (topLevelPtr->flags & TK_TOP_HIERARCHY) {
 	    break;
 	}
     }
Index: generic/tkGrab.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/generic/tkGrab.c,v
retrieving revision 1.7
diff -u -r1.7 tkGrab.c
--- generic/tkGrab.c	17 Jan 2002 05:13:11 -0000	1.7
+++ generic/tkGrab.c	24 Jun 2002 04:12:11 -0000
@@ -742,7 +742,7 @@
 
 	if (eventPtr->xcrossing.send_event != GENERATED_EVENT_MAGIC) {
 	    if ((eventPtr->type == LeaveNotify) &&
-		    (winPtr->flags & TK_TOP_LEVEL)) {
+		    (winPtr->flags & TK_TOP_HIERARCHY)) {
 		dispPtr->serverWinPtr = NULL;
 	    } else {
 		dispPtr->serverWinPtr = winPtr;
@@ -941,7 +941,7 @@
 	eventPtr->xmotion.subwindow = None;
 	for (childPtr = winPtr->childList; childPtr != NULL;
 		childPtr = childPtr->nextPtr) {
-	    if (childPtr->flags & TK_TOP_LEVEL) {
+	    if (childPtr->flags & TK_TOP_HIERARCHY) {
 		continue;
 	    }
 	    x = eventPtr->xmotion.x - childPtr->changes.x;
@@ -1226,7 +1226,7 @@
 	ReleaseButtonGrab(dispPtr);
     }
     if (dispPtr->serverWinPtr == winPtr) {
-	if (winPtr->flags & TK_TOP_LEVEL) {
+	if (winPtr->flags & TK_TOP_HIERARCHY) {
 	    dispPtr->serverWinPtr = NULL;
 	} else {
 	    dispPtr->serverWinPtr = winPtr->parentPtr;
@@ -1451,7 +1451,7 @@
     if (winPtr1 != NULL) {
 	for (winPtr = winPtr1; winPtr != NULL; winPtr = winPtr->parentPtr) {
 	    winPtr->flags |= TK_GRAB_FLAG;
-	    if (winPtr->flags & TK_TOP_LEVEL) {
+	    if (winPtr->flags & TK_TOP_HIERARCHY) {
 		break;
 	    }
 	}
@@ -1471,7 +1471,7 @@
 		ancestorPtr = winPtr;
 		break;
 	    }
-	    if (winPtr->flags & TK_TOP_LEVEL)  {
+	    if (winPtr->flags & TK_TOP_HIERARCHY)  {
 		count2++;
 		break;
 	    }
@@ -1493,7 +1493,7 @@
 	    if (winPtr == ancestorPtr) {
 		count1 = i;
 	    }
-	    if (winPtr->flags & TK_TOP_LEVEL) {
+	    if (winPtr->flags & TK_TOP_HIERARCHY) {
 		if (count1 == -1) {
 		    count1 = i+1;
 		}
@@ -1543,7 +1543,7 @@
 		if (winPtr2 == winPtr) {
 		    return TK_GRAB_ANCESTOR;
 		}
-		if (winPtr2->flags & TK_TOP_LEVEL) {
+		if (winPtr2->flags & TK_TOP_HIERARCHY) {
 		    break;
 		}
 	    }
Index: generic/tkGrid.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/generic/tkGrid.c,v
retrieving revision 1.20
diff -u -r1.20 tkGrid.c
--- generic/tkGrid.c	17 Jan 2002 05:13:11 -0000	1.20
+++ generic/tkGrid.c	24 Jun 2002 04:12:12 -0000
@@ -2642,7 +2642,7 @@
 	    return TCL_ERROR;
 	}
 
-	if (Tk_IsTopLevel(slave)) {
+	if (Tk_TopWinHierarchy(slave)) {
 	    Tcl_AppendResult(interp, "can't manage \"", Tcl_GetString(objv[j]),
 		    "\": it's a top-level window", (char *) NULL);
 	    return TCL_ERROR;
@@ -2806,7 +2806,7 @@
 	    if (ancestor == parent) {
 		break;
 	    }
-	    if (Tk_IsTopLevel(ancestor)) {
+	    if (Tk_TopWinHierarchy(ancestor)) {
 		Tcl_AppendResult(interp, "can't put ", Tcl_GetString(objv[j]),
 			" inside ", Tk_PathName(masterPtr->tkwin),
 			(char *) NULL);
Index: generic/tkImage.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/generic/tkImage.c,v
retrieving revision 1.14
diff -u -r1.14 tkImage.c
--- generic/tkImage.c	3 Feb 2002 22:33:07 -0000	1.14
+++ generic/tkImage.c	24 Jun 2002 04:12:13 -0000
@@ -1048,7 +1048,7 @@
     GC gc;
     int x, y;
 {
-    while (!Tk_IsTopLevel(tkwin)) {
+    while (!Tk_TopWinHierarchy(tkwin)) {
 	x -= Tk_X(tkwin) + Tk_Changes(tkwin)->border_width;
 	y -= Tk_Y(tkwin) + Tk_Changes(tkwin)->border_width;
 	tkwin = Tk_Parent(tkwin);
Index: generic/tkPack.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/generic/tkPack.c,v
retrieving revision 1.15
diff -u -r1.15 tkPack.c
--- generic/tkPack.c	17 Jan 2002 05:13:11 -0000	1.15
+++ generic/tkPack.c	24 Jun 2002 04:12:14 -0000
@@ -1190,7 +1190,7 @@
 	    if (ancestor == parent) {
 		break;
 	    }
-	    if (((Tk_FakeWin *) (ancestor))->flags & TK_TOP_LEVEL) {
+	    if (((Tk_FakeWin *) (ancestor))->flags & TK_TOP_HIERARCHY) {
 		badWindow:
 		Tcl_AppendResult(interp, "can't pack ", Tcl_GetString(objv[0]),
 			" inside ", Tk_PathName(masterPtr->tkwin),
@@ -1198,7 +1198,7 @@
 		return TCL_ERROR;
 	    }
 	}
-	if (((Tk_FakeWin *) (tkwin))->flags & TK_TOP_LEVEL) {
+	if (((Tk_FakeWin *) (tkwin))->flags & TK_TOP_HIERARCHY) {
 	    goto badWindow;
 	}
 	if (tkwin == masterPtr->tkwin) {
@@ -1589,7 +1589,7 @@
 	if (TkGetWindowFromObj(interp, tkwin, objv[j], &slave) != TCL_OK) {
 	    return TCL_ERROR;
 	}
-	if (Tk_IsTopLevel(slave)) {
+	if (Tk_TopWinHierarchy(slave)) {
 	    Tcl_AppendResult(interp, "can't pack \"", Tcl_GetString(objv[j]),
 		    "\": it's a top-level window", (char *) NULL);
 	    return TCL_ERROR;
@@ -1795,7 +1795,7 @@
 	    if (ancestor == parent) {
 		break;
 	    }
-	    if (Tk_IsTopLevel(ancestor)) {
+	    if (Tk_TopWinHierarchy(ancestor)) {
 		Tcl_AppendResult(interp, "can't pack ", Tcl_GetString(objv[j]),
 			" inside ", Tk_PathName(masterPtr->tkwin),
 			(char *) NULL);
Index: generic/tkPlace.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/generic/tkPlace.c,v
retrieving revision 1.11
diff -u -r1.11 tkPlace.c
--- generic/tkPlace.c	17 Jan 2002 05:13:11 -0000	1.11
+++ generic/tkPlace.c	24 Jun 2002 04:12:14 -0000
@@ -593,7 +593,7 @@
     int result = TCL_OK;
     Slave *slavePtr;
     
-    if (Tk_IsTopLevel(tkwin)) {
+    if (Tk_TopWinHierarchy(tkwin)) {
 	Tcl_AppendResult(interp, "can't use placer on top-level window \"",
 		Tk_PathName(tkwin), "\"; use wm command instead",
 		(char *) NULL);
@@ -626,7 +626,7 @@
 	    if (ancestor == Tk_Parent(slavePtr->tkwin)) {
 		break;
 	    }
-	    if (Tk_IsTopLevel(ancestor)) {
+	    if (Tk_TopWinHierarchy(ancestor)) {
 		Tcl_AppendResult(interp, "can't place ",
 			Tk_PathName(slavePtr->tkwin), " relative to ",
 			Tk_PathName(tkwin), (char *) NULL);
Index: generic/tkPointer.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/generic/tkPointer.c,v
retrieving revision 1.5
diff -u -r1.5 tkPointer.c
--- generic/tkPointer.c	23 Nov 2001 02:07:02 -0000	1.5
+++ generic/tkPointer.c	24 Jun 2002 04:12:15 -0000
@@ -562,7 +562,7 @@
 	if (winPtr->atts.cursor != None) {
 	    cursor = winPtr->atts.cursor;
 	    break;
-	} else if (winPtr->flags & TK_TOP_LEVEL) {
+	} else if (winPtr->flags & TK_TOP_HIERARCHY) {
 	    break;
 	}
 	winPtr = winPtr->parentPtr;
Index: generic/tkTextWind.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/generic/tkTextWind.c,v
retrieving revision 1.4
diff -u -r1.4 tkTextWind.c
--- generic/tkTextWind.c	14 Dec 1999 06:52:33 -0000	1.4
+++ generic/tkTextWind.c	24 Jun 2002 04:12:15 -0000
@@ -370,7 +370,7 @@
 		if (ancestor == parent) {
 		    break;
 		}
-		if (Tk_IsTopLevel(ancestor)) {
+		if (Tk_TopWinHierarchy(ancestor)) {
 		    badMaster:
 		    Tcl_AppendResult(textPtr->interp, "can't embed ",
 			    Tk_PathName(ewPtr->body.ew.tkwin), " in ",
@@ -379,7 +379,7 @@
 		    return TCL_ERROR;
 		}
 	    }
-	    if (Tk_IsTopLevel(ewPtr->body.ew.tkwin)
+	    if (Tk_TopWinHierarchy(ewPtr->body.ew.tkwin)
 		    || (ewPtr->body.ew.tkwin == textPtr->tkwin)) {
 		goto badMaster;
 	    }
@@ -790,7 +790,7 @@
 	    if (ancestor == Tk_Parent(ewPtr->body.ew.tkwin)) {
 		break;
 	    }
-	    if (Tk_IsTopLevel(ancestor)) {
+	    if (Tk_TopWinHierarchy(ancestor)) {
 		badMaster:
 		Tcl_AppendResult(textPtr->interp, "can't embed ",
 			Tk_PathName(ewPtr->body.ew.tkwin), " relative to ",
@@ -800,7 +800,7 @@
 		goto gotWindow;
 	    }
 	}
-	if (Tk_IsTopLevel(ewPtr->body.ew.tkwin)
+	if (Tk_TopWinHierarchy(ewPtr->body.ew.tkwin)
 		|| (textPtr->tkwin == ewPtr->body.ew.tkwin)) {
 	    goto badMaster;
 	}
Index: generic/tkWindow.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/generic/tkWindow.c,v
retrieving revision 1.45
diff -u -r1.45 tkWindow.c
--- generic/tkWindow.c	12 Apr 2002 10:20:27 -0000	1.45
+++ generic/tkWindow.c	24 Jun 2002 04:12:17 -0000
@@ -364,12 +364,12 @@
     winPtr->dirtyAtts |= CWBorderPixel;
 
     /*
-     * (Need to set the TK_TOP_LEVEL flag immediately here;  otherwise
+     * (Need to set the TK_TOP_HIERARCHY flag immediately here;  otherwise
      * Tk_DestroyWindow will core dump if it is called before the flag
      * has been set.)
      */
 
-    winPtr->flags |= TK_TOP_LEVEL;
+    winPtr->flags |= TK_TOP_HIERARCHY|TK_TOP_LEVEL|TK_HAS_WRAPPER|TK_WIN_MANAGED;
 
     if (parent != NULL) {
         if (NameWindow(interp, winPtr, (TkWindow *) parent, name) != TCL_OK) {
@@ -1347,7 +1347,7 @@
      * Cleanup the data structures associated with this window.
      */
 
-    if (winPtr->flags & TK_TOP_LEVEL) {
+    if (winPtr->flags & TK_WIN_MANAGED) {
 	TkWmDeadWindow(winPtr);
     } else if (winPtr->flags & TK_WM_COLORMAP_WINDOW) {
 	TkWmRemoveFromColormapWindows(winPtr);
@@ -1356,7 +1356,7 @@
 #if defined(MAC_TCL) || defined(__WIN32__)
 	XDestroyWindow(winPtr->display, winPtr->window);
 #else
-	if ((winPtr->flags & TK_TOP_LEVEL)
+	if ((winPtr->flags & TK_TOP_HIERARCHY)
 		|| !(winPtr->flags & TK_DONT_DESTROY_WINDOW)) {
 	    /*
 	     * The parent has already been destroyed and this isn't
@@ -1538,7 +1538,7 @@
     if (winPtr->window == None) {
 	Tk_MakeWindowExist(tkwin);
     }
-    if (winPtr->flags & TK_TOP_LEVEL) {
+    if (winPtr->flags & TK_WIN_MANAGED) {
 	/*
 	 * Lots of special processing has to be done for top-level
 	 * windows.  Let tkWm.c handle everything itself.
@@ -1595,7 +1595,7 @@
 	return;
     }
 
-    if ((winPtr->parentPtr == NULL) || (winPtr->flags & TK_TOP_LEVEL)) {
+    if ((winPtr->parentPtr == NULL) || (winPtr->flags & TK_TOP_HIERARCHY)) {
 	parent = XRootWindow(winPtr->display, winPtr->screenNum);
     } else {
 	if (winPtr->parentPtr->window == None) {
@@ -1617,7 +1617,7 @@
     winPtr->dirtyAtts = 0;
     winPtr->dirtyChanges = 0;
 
-    if (!(winPtr->flags & TK_TOP_LEVEL)) {
+    if (!(winPtr->flags & TK_TOP_HIERARCHY)) {
 	/*
 	 * If any siblings higher up in the stacking order have already
 	 * been created then move this window to its rightful position
@@ -1632,7 +1632,7 @@
 	for (winPtr2 = winPtr->nextPtr; winPtr2 != NULL;
 		winPtr2 = winPtr2->nextPtr) {
 	    if ((winPtr2->window != None)
-		    && !(winPtr2->flags & (TK_TOP_LEVEL|TK_REPARENTED))) {
+		    && !(winPtr2->flags & (TK_TOP_HIERARCHY|TK_REPARENTED))) {
 		XWindowChanges changes;
 		changes.sibling = winPtr2->window;
 		changes.stack_mode = Below;
@@ -1698,7 +1698,7 @@
     if (!(winPtr->flags & TK_MAPPED) || (winPtr->flags & TK_ALREADY_DEAD)) {
 	return;
     }
-    if (winPtr->flags & TK_TOP_LEVEL) {
+    if (winPtr->flags & TK_WIN_MANAGED) {
 	/*
 	 * Special processing has to be done for top-level windows.  Let
 	 * tkWm.c handle everything itself.
@@ -1709,7 +1709,7 @@
     }
     winPtr->flags &= ~TK_MAPPED;
     XUnmapWindow(winPtr->display, winPtr->window);
-    if (!(winPtr->flags & TK_TOP_LEVEL)) {
+    if (!(winPtr->flags & TK_TOP_HIERARCHY)) {
 	XEvent event;
 
 	event.type = UnmapNotify;
@@ -2018,7 +2018,7 @@
 
     if (winPtr->window != None) {
 	XSetWindowColormap(winPtr->display, winPtr->window, colormap);
-	if (!(winPtr->flags & TK_TOP_LEVEL)) {
+	if (!(winPtr->flags & TK_WIN_MANAGED)) {
 	    TkWmAddToColormapWindows(winPtr);
 	    winPtr->flags |= TK_WM_COLORMAP_WINDOW;
 	}
@@ -2147,7 +2147,7 @@
     register TkWindow *winPtr = (TkWindow *) tkwin;
 
     winPtr->classUid = Tk_GetUid(className);
-    if (winPtr->flags & TK_TOP_LEVEL) {
+    if (winPtr->flags & TK_WIN_MANAGED) {
 	TkWmSetClass(winPtr);
     }
     TkOptionClassChanged(winPtr);
@@ -2383,8 +2383,8 @@
      * otherPtr without changing any of Tk's childLists.
      */
 
-    if (winPtr->flags & TK_TOP_LEVEL) {
-	while ((otherPtr != NULL) && !(otherPtr->flags & TK_TOP_LEVEL)) {
+    if (winPtr->flags & TK_WIN_MANAGED) {
+	while ((otherPtr != NULL) && !(otherPtr->flags & TK_TOP_HIERARCHY)) {
 	    otherPtr = otherPtr->parentPtr;
 	}
 	TkWmRestackToplevel(winPtr, aboveBelow, otherPtr);
@@ -2410,7 +2410,7 @@
 	}
     } else {
 	while (winPtr->parentPtr != otherPtr->parentPtr) {
-	    if ((otherPtr == NULL) || (otherPtr->flags & TK_TOP_LEVEL)) {
+	    if ((otherPtr == NULL) || (otherPtr->flags & TK_TOP_HIERARCHY)) {
 		return TCL_ERROR;
 	    }
 	    otherPtr = otherPtr->parentPtr;
@@ -2462,7 +2462,7 @@
 	for (otherPtr = winPtr->nextPtr; otherPtr != NULL;
 		otherPtr = otherPtr->nextPtr) {
 	    if ((otherPtr->window != None)
-		    && !(otherPtr->flags & (TK_TOP_LEVEL|TK_REPARENTED))){
+		    && !(otherPtr->flags & (TK_TOP_HIERARCHY|TK_REPARENTED))){
 		changes.sibling = otherPtr->window;
 		changes.stack_mode = Below;
 		mask = CWStackMode|CWSibling;
Index: mac/tkMacSubwindows.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/mac/tkMacSubwindows.c,v
retrieving revision 1.6
diff -u -r1.6 tkMacSubwindows.c
--- mac/tkMacSubwindows.c	10 Feb 2000 08:56:24 -0000	1.6
+++ mac/tkMacSubwindows.c	24 Jun 2002 04:12:18 -0000
@@ -724,14 +724,14 @@
 	 * This is not currently enforced, however.
 	 */
 	
-	if (!Tk_IsTopLevel(winPtr)) { 
+	if (!Tk_TopWinHierarchy(winPtr)) { 
 	    TkMacUpdateClipRgn(winPtr->parentPtr);
 	    SectRgn(rgn, 
 		    winPtr->parentPtr->privatePtr->aboveClipRgn, rgn);
 				
 	    win2Ptr = winPtr->nextPtr;
 	    while (win2Ptr != NULL) {
-		if (Tk_IsTopLevel(win2Ptr) || !Tk_IsMapped(win2Ptr)) {
+		if (Tk_TopWinHierarchy(win2Ptr) || !Tk_IsMapped(win2Ptr)) {
 		    win2Ptr = win2Ptr->nextPtr;
 		    continue;
 		}
@@ -776,7 +776,7 @@
 		
 	win2Ptr = winPtr->childList;
 	while (win2Ptr != NULL) {
-	    if (Tk_IsTopLevel(win2Ptr) || !Tk_IsMapped(win2Ptr)) {
+	    if (Tk_TopWinHierarchy(win2Ptr) || !Tk_IsMapped(win2Ptr)) {
 		win2Ptr = win2Ptr->nextPtr;
 		continue;
 	    }
@@ -1000,7 +1000,7 @@
      */
     childPtr = winPtr->childList;
     while (childPtr != NULL) {
-	if (!Tk_IsTopLevel(childPtr) && Tk_IsMapped(childPtr)) {
+	if (!Tk_TopWinHierarchy(childPtr) && Tk_IsMapped(childPtr)) {
 	    TkMacInvalClipRgns(childPtr);
 	}
 	childPtr = childPtr->nextPtr;
@@ -1133,7 +1133,7 @@
 
     childPtr = winPtr->childList;
     while (childPtr != NULL) {
-	if (!Tk_IsTopLevel(childPtr)) {
+	if (!Tk_TopWinHierarchy(childPtr)) {
 	    UpdateOffsets(childPtr, deltaX, deltaY);
 	}
 	childPtr = childPtr->nextPtr;
Index: mac/tkMacWindowMgr.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/mac/tkMacWindowMgr.c,v
retrieving revision 1.9
diff -u -r1.9 tkMacWindowMgr.c
--- mac/tkMacWindowMgr.c	23 Nov 2001 02:06:32 -0000	1.9
+++ mac/tkMacWindowMgr.c	24 Jun 2002 04:12:19 -0000
@@ -426,7 +426,7 @@
      
     for (childPtr = winPtr->childList; childPtr != NULL;
 				       childPtr = childPtr->nextPtr) {
-	if (!Tk_IsMapped(childPtr) || Tk_IsTopLevel(childPtr)) {
+	if (!Tk_IsMapped(childPtr) || Tk_TopWinHierarchy(childPtr)) {
 	    continue;
 	}
 
@@ -1546,7 +1546,7 @@
 TkpSetCapture(
     TkWindow *winPtr)			/* Capture window, or NULL. */
 {
-    while ((winPtr != NULL) && !Tk_IsTopLevel(winPtr)) {
+    while ((winPtr != NULL) && !Tk_TopWinHierarchy(winPtr)) {
 	winPtr = winPtr->parentPtr;
     }
     gGrabWinPtr = (Tk_Window) winPtr;
Index: mac/tkMacWm.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/mac/tkMacWm.c,v
retrieving revision 1.17
diff -u -r1.17 tkMacWm.c
--- mac/tkMacWm.c	24 May 2002 09:50:11 -0000	1.17
+++ mac/tkMacWm.c	24 Jun 2002 04:12:21 -0000
@@ -1870,10 +1870,13 @@
      * information.
      */
 
-    while (!(winPtr->flags & TK_TOP_LEVEL)) {
+    while (!(winPtr->flags & TK_TOP_HIERARCHY)) {
 	winPtr = winPtr->parentPtr;
     }
     wmPtr = winPtr->wmInfoPtr;
+    if (wmPtr == NULL) {
+	return;
+    }
 
     if ((wmPtr->gridWin != NULL) && (wmPtr->gridWin != tkwin)) {
 	return;
@@ -1955,10 +1958,14 @@
      * information.
      */
 
-    while (!(winPtr->flags & TK_TOP_LEVEL)) {
+    while (!(winPtr->flags & TK_TOP_HIERARCHY)) {
 	winPtr = winPtr->parentPtr;
     }
     wmPtr = winPtr->wmInfoPtr;
+    if (wmPtr == NULL) {
+	return;
+    }
+
     if (tkwin != wmPtr->gridWin) {
 	return;
     }
@@ -2511,7 +2518,7 @@
     while (1) {
 	x += winPtr->changes.x + winPtr->changes.border_width;
 	y += winPtr->changes.y + winPtr->changes.border_width;
-	if (winPtr->flags & TK_TOP_LEVEL) {
+	if (winPtr->flags & TK_TOP_HIERARCHY) {
 	    if (!(Tk_IsEmbedded(winPtr))) {
 	    	x += winPtr->wmInfoPtr->xInParent;
 	    	y += winPtr->wmInfoPtr->yInParent;
@@ -2561,6 +2568,9 @@
 		}
 	    }
 	}
+	if (winPtr->flags & TK_TOP_HIERARCHY) {
+	    break; /* Punt */
+	}
 	winPtr = winPtr->parentPtr;
     }
     *xPtr = x;
@@ -2668,7 +2678,7 @@
 	    for (childPtr = winPtr->childList; childPtr != NULL;
 		    childPtr = childPtr->nextPtr) {
 	        if (!Tk_IsMapped(childPtr) ||
-			(childPtr->flags & TK_TOP_LEVEL)) {
+			(childPtr->flags & TK_TOP_HIERARCHY)) {
 		    continue;
 	        }
 	        tmpx = x - childPtr->changes.x;
@@ -2762,7 +2772,7 @@
 	    for (childPtr = winPtr->childList; childPtr != NULL;
 					   childPtr = childPtr->nextPtr) {
 	        if (!Tk_IsMapped(childPtr) ||
-			(childPtr->flags & TK_TOP_LEVEL)) {
+			(childPtr->flags & TK_TOP_HIERARCHY)) {
 		    continue;
 	        }
 	        if (x < childPtr->changes.x || y < childPtr->changes.y) {
@@ -2895,10 +2905,13 @@
      * information for that window.
      */
 
-    while (!(winPtr->flags & TK_TOP_LEVEL)) {
+    while (!(winPtr->flags & TK_TOP_HIERARCHY)) {
 	winPtr = winPtr->parentPtr;
     }
     wmPtr = winPtr->wmInfoPtr;
+    if (wmPtr == NULL) {
+	return; /* Punt */
+    }
 
     /*
      * Make sure that the geometry information is up-to-date, then copy
@@ -3322,10 +3335,14 @@
 
 	    return;
 	}
-	if (topPtr->flags & TK_TOP_LEVEL) {
+	if (topPtr->flags & TK_TOP_HIERARCHY) {
 	    break;
 	}
     }
+    if (topPtr->wmInfoPtr == NULL) {
+	return;
+    }
+
     if (topPtr->wmInfoPtr->flags & WM_COLORMAPS_EXPLICIT) {
 	return;
     }
@@ -3412,7 +3429,7 @@
 
 	    return;
 	}
-	if (topPtr->flags & TK_TOP_LEVEL) {
+	if (topPtr->flags & TK_TOP_HIERARCHY) {
 	    break;
 	}
     }
@@ -3430,6 +3447,10 @@
      * it up.
      */
 
+    if (topPtr->wmInfoPtr == NULL) {
+	return;
+    }
+
     count = topPtr->wmInfoPtr->cmapCount;
     oldPtr = topPtr->wmInfoPtr->cmapList;
     for (i = 0; i < count; i++) {
@@ -4648,7 +4669,7 @@
     TkWindow *winPtr)		/* Window that received a focus-related
 				 * event. */
 {
-    if (!(winPtr->flags & TK_TOP_LEVEL)) {
+    if (!(winPtr->flags & TK_TOP_HIERARCHY)) {
 	return NULL;
     }
     return winPtr;
Index: unix/Makefile.in
===================================================================
RCS file: /cvsroot/tktoolkit/tk/unix/Makefile.in,v
retrieving revision 1.65
diff -u -r1.65 Makefile.in
--- unix/Makefile.in	6 Mar 2002 18:54:16 -0000	1.65
+++ unix/Makefile.in	24 Jun 2002 04:12:22 -0000
@@ -138,6 +138,12 @@
 MEM_DEBUG_FLAGS		=
 #MEM_DEBUG_FLAGS	= -DTCL_MEM_DEBUG
 
+# To disable window-manager enablers, reverse the comment characters
+# on the following two lines.
+
+WM_ENABLER_FLAGS	= -DWM_ENABLERS
+#WM_ENABLER_FLAGS	= 
+
 # If your X server is X11R4 or earlier, then you may wish to reverse
 # the comment characters on the following two lines.  This will enable
 # extra code to speed up XStringToKeysym.  In X11R5 and later releases
@@ -248,7 +254,8 @@
 -I${UNIX_DIR} -I${GENERIC_DIR} \
 -I${BMAP_DIR} -I${TCL_GENERIC_DIR} ${X11_INCLUDES} \
 ${AC_FLAGS} ${PROTO_FLAGS} \
-${SECURITY_FLAGS} ${MEM_DEBUG_FLAGS} ${KEYSYM_FLAGS} ${NO_DEPRECATED_FLAGS}
+${SECURITY_FLAGS} ${MEM_DEBUG_FLAGS} ${KEYSYM_FLAGS} ${NO_DEPRECATED_FLAGS} \
+${WM_ENABLER_FLAGS}
 
 CC_SWITCHES = ${CC_SWITCHES_NO_STUBS} ${TCL_STUB_FLAGS} 
 
@@ -256,7 +263,7 @@
 -I${BMAP_DIR} \
 -I${TCL_GENERIC_DIR} ${X11_INCLUDES} \
 ${AC_FLAGS} ${PROTO_FLAGS} ${SECURITY_FLAGS} ${MEM_DEBUG_FLAGS} \
-${KEYSYM_FLAGS}
+${WM_ENABLER_FLAGS} ${KEYSYM_FLAGS}
 
 WISH_OBJS = tkAppInit.o
 
Index: unix/tkUnixEmbed.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/unix/tkUnixEmbed.c,v
retrieving revision 1.4
diff -u -r1.4 tkUnixEmbed.c
--- unix/tkUnixEmbed.c	27 May 2002 17:33:26 -0000	1.4
+++ unix/tkUnixEmbed.c	24 Jun 2002 04:12:23 -0000
@@ -780,7 +780,7 @@
 
 	    return;
 	}
-	if (winPtr->flags & TK_TOP_LEVEL) {
+	if (winPtr->flags & TK_TOP_HIERARCHY) {
 	    break;
 	}
 	winPtr = winPtr->parentPtr;
Index: unix/tkUnixWm.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/unix/tkUnixWm.c,v
retrieving revision 1.21
diff -u -r1.21 tkUnixWm.c
--- unix/tkUnixWm.c	12 Jun 2002 19:02:49 -0000	1.21
+++ unix/tkUnixWm.c	24 Jun 2002 04:12:28 -0000
@@ -1299,7 +1299,7 @@
 	    if (tkwin2 == NULL) {
 		return TCL_ERROR;
 	    }
-	    while (!Tk_IsTopLevel(tkwin2)) {
+	    while (!Tk_TopWinHierarchy(tkwin2)) {
 		/*
 		 * Ensure that the group leader is actually a Tk toplevel.
 		 */
@@ -2050,7 +2050,7 @@
 	    if (masterPtr == NULL) {
 		return TCL_ERROR;
 	    }
-	    while (!Tk_IsTopLevel(masterPtr)) {
+	    while (!Tk_TopWinHierarchy(masterPtr)) {
 		/*
 		 * Ensure that the master window is actually a Tk toplevel.
 		 */
@@ -2226,7 +2226,7 @@
      * information.
      */
 
-    while (!(winPtr->flags & TK_TOP_LEVEL)) {
+    while (!(winPtr->flags & TK_TOP_HIERARCHY)) {
 	winPtr = winPtr->parentPtr;
 	if (winPtr == NULL) {
 	    /*
@@ -2237,6 +2237,9 @@
 	}
     }
     wmPtr = winPtr->wmInfoPtr;
+    if(wmPtr == NULL) {
+	return;
+    }
 
     if ((wmPtr->gridWin != NULL) && (wmPtr->gridWin != tkwin)) {
 	return;
@@ -2318,7 +2321,7 @@
      * information.
      */
 
-    while (!(winPtr->flags & TK_TOP_LEVEL)) {
+    while (!(winPtr->flags & TK_TOP_HIERARCHY)) {
 	winPtr = winPtr->parentPtr;
 	if (winPtr == NULL) {
 	    /*
@@ -2329,6 +2332,10 @@
 	}
     }
     wmPtr = winPtr->wmInfoPtr;
+    if(wmPtr == NULL) {
+	return;
+    }
+
     if (tkwin != wmPtr->gridWin) {
 	return;
     }
@@ -3936,7 +3943,7 @@
 	nextPtr = NULL;
 	for (childPtr = winPtr->childList; childPtr != NULL;
 		childPtr = childPtr->nextPtr) {
-	    if (!Tk_IsMapped(childPtr) || (childPtr->flags & TK_TOP_LEVEL)) {
+	    if (!Tk_IsMapped(childPtr) || (childPtr->flags & TK_TOP_HIERARCHY)) {
 		continue;
 	    }
 	    if (childPtr->flags & TK_REPARENTED) {
@@ -4086,10 +4093,18 @@
      * information for that window.
      */
 
-    while (!(winPtr->flags & TK_TOP_LEVEL) && (winPtr->parentPtr != NULL)) {
+    while (!(winPtr->flags & TK_TOP_HIERARCHY) && (winPtr->parentPtr != NULL)) {
 	winPtr = winPtr->parentPtr;
     }
     wmPtr = winPtr->wmInfoPtr;
+    if(wmPtr == NULL) {
+	/* Punt. */
+	*xPtr = 0;
+	*yPtr = 0;
+	*widthPtr = 0;
+	*heightPtr = 0;
+    }
+
 
     /*
      * Make sure that the geometry information is up-to-date, then copy
@@ -4676,10 +4691,14 @@
 
 	    return;
 	}
-	if (topPtr->flags & TK_TOP_LEVEL) {
+	if (topPtr->flags & TK_TOP_HIERARCHY) {
 	    break;
 	}
     }
+    if(topPtr->wmInfoPtr == NULL) {
+	return;
+    }
+
     if (topPtr->wmInfoPtr->flags & WM_COLORMAPS_EXPLICIT) {
 	return;
     }
@@ -4776,7 +4795,7 @@
 
 	    return;
 	}
-	if (topPtr->flags & TK_TOP_LEVEL) {
+	if (topPtr->flags & TK_TOP_HIERARCHY) {
 	    break;
 	}
     }
@@ -4788,6 +4807,10 @@
 
 	return;
     }
+    if (topPtr->wmInfoPtr == NULL) {
+	return;
+    }
+
     if (topPtr->wmInfoPtr->wrapperPtr == NULL) {
 	CreateWrapper(topPtr->wmInfoPtr);
     }
@@ -4963,7 +4986,7 @@
     XSetWindowAttributes atts;
     TkWindow *wrapperPtr;
 
-    if (!Tk_IsTopLevel(tkwin)) {
+    if (!Tk_HasWrapper(tkwin)) {
 	return;
     }
     wmPtr = ((TkWindow *) tkwin)->wmInfoPtr;
Index: win/tkWinScrlbr.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/win/tkWinScrlbr.c,v
retrieving revision 1.7
diff -u -r1.7 tkWinScrlbr.c
--- win/tkWinScrlbr.c	22 Nov 2000 01:49:38 -0000	1.7
+++ win/tkWinScrlbr.c	24 Jun 2002 04:12:28 -0000
@@ -242,7 +242,7 @@
 
     for (winPtr = ((TkWindow*)tkwin)->nextPtr; winPtr != NULL;
 	 winPtr = winPtr->nextPtr) {
-	if ((winPtr->window != None) && !(winPtr->flags & TK_TOP_LEVEL)) {
+	if ((winPtr->window != None) && !(winPtr->flags & TK_TOP_HIERARCHY)) {
 	    TkWinSetWindowPos(scrollPtr->hwnd, Tk_GetHWND(winPtr->window),
 		    Below);
 	    break;
Index: win/tkWinWindow.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/win/tkWinWindow.c,v
retrieving revision 1.9
diff -u -r1.9 tkWinWindow.c
--- win/tkWinWindow.c	1 Oct 2001 21:22:35 -0000	1.9
+++ win/tkWinWindow.c	24 Jun 2002 04:12:28 -0000
@@ -371,13 +371,13 @@
      * its mapped children have just become visible.
      */
 
-    if (!(winPtr->flags & TK_TOP_LEVEL)) {
+    if (!(winPtr->flags & TK_TOP_HIERARCHY)) {
 	for (parentPtr = winPtr->parentPtr; ;
 	        parentPtr = parentPtr->parentPtr) {
 	    if ((parentPtr == NULL) || !(parentPtr->flags & TK_MAPPED)) {
 		return;
 	    }
-	    if (parentPtr->flags & TK_TOP_LEVEL) {
+	    if (parentPtr->flags & TK_TOP_HIERARCHY) {
 		break;
 	    }
 	}
@@ -478,7 +478,7 @@
     ShowWindow(Tk_GetHWND(w), SW_HIDE);
     winPtr->flags &= ~TK_MAPPED;
 
-    if (winPtr->flags & TK_TOP_LEVEL) {
+    if (winPtr->flags & TK_WIN_MANAGED) {
 	event.type = UnmapNotify;
 	event.xunmap.serial = display->request;
 	event.xunmap.send_event = False;
Index: win/tkWinWm.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/win/tkWinWm.c,v
retrieving revision 1.39
diff -u -r1.39 tkWinWm.c
--- win/tkWinWm.c	12 Jun 2002 19:02:50 -0000	1.39
+++ win/tkWinWm.c	24 Jun 2002 04:12:30 -0000
@@ -3308,7 +3308,7 @@
 	    if (masterPtr == NULL) {
 		return TCL_ERROR;
 	    }
-	    while (!(masterPtr->flags & TK_TOP_LEVEL)) {
+	    while (!(masterPtr->flags & TK_TOP_HIERARCHY)) {
 	        /*
 	         * Ensure that the master window is actually a Tk toplevel.
 	         */
@@ -3476,10 +3476,13 @@
      * information.
      */
 
-    while (!(winPtr->flags & TK_TOP_LEVEL)) {
+    while (!(winPtr->flags & TK_TOP_HIERARCHY)) {
 	winPtr = winPtr->parentPtr;
     }
     wmPtr = winPtr->wmInfoPtr;
+    if (wmPtr == NULL) {
+	return;
+    }
 
     if ((wmPtr->gridWin != NULL) && (wmPtr->gridWin != tkwin)) {
 	return;
@@ -3560,10 +3563,14 @@
      * information.
      */
 
-    while (!(winPtr->flags & TK_TOP_LEVEL)) {
+    while (!(winPtr->flags & TK_TOP_HIERARCHY)) {
 	winPtr = winPtr->parentPtr;
     }
     wmPtr = winPtr->wmInfoPtr;
+    if (wmPtr == NULL) {
+	return;
+    }
+
     if (tkwin != wmPtr->gridWin) {
 	return;
     }
@@ -4592,10 +4599,14 @@
 
 	    return;
 	}
-	if (topPtr->flags & TK_TOP_LEVEL) {
+	if (topPtr->flags & TK_TOP_HIERARCHY) {
 	    break;
 	}
     }
+    if (topPtr->wmInfoPtr == NULL) {
+	return;
+    }
+
     if (topPtr->wmInfoPtr->flags & WM_COLORMAPS_EXPLICIT) {
 	return;
     }
@@ -4699,6 +4710,10 @@
 	return;
     }
 
+    if (topPtr->wmInfoPtr == NULL) {
+	return;
+    }
+
     /*
      * Find the window and slide the following ones down to cover
      * it up.
@@ -5201,7 +5216,7 @@
 	 * toplevel window.  
 	 */
 
-	if (!Tk_IsTopLevel(childPtr) && Tk_IsMapped(childPtr)) {
+	if (!Tk_TopWinHierarchy(childPtr) && Tk_IsMapped(childPtr)) {
 	    InvalidateSubTree(childPtr, colormap);
 	}
     }
@@ -5679,7 +5694,7 @@
     TkWindow *winPtr;		/* Window that received a focus-related
 				 * event. */
 {
-    if (!(winPtr->flags & TK_TOP_LEVEL)) {
+    if (!(winPtr->flags & TK_TOP_HIERARCHY)) {
 	return NULL;
     }
     return winPtr;
@@ -5709,7 +5724,7 @@
     TkWindow *winPtr)		/* Window that received a focus-related
 				 * event. */
 {
-    if (!(winPtr->flags & TK_TOP_LEVEL)) {
+    if (!(winPtr->flags & TK_TOP_HIERARCHY)) {
 	return NULL;
     }
     return winPtr;