From 66b10ca873b53d7f03f2f84d27a54adc02a3fc35 Mon Sep 17 00:00:00 2001 From: dkf Date: Wed, 30 Jun 2004 22:17:56 +0000 Subject: TIP#153 implementation from Neil McKay, with thanks! --- ChangeLog | 9 +++++++++ doc/winfo.n | 6 ++++-- generic/tkCmds.c | 41 +++++++++++++++++++++-------------------- 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index c84fdfc..0b12b14 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2004-06-30 Donal K. Fellows + + TIP#153 IMPLEMENTATION + + * generic/tkCmds.c (GetTopHierarchy): Modified from GetToplevel so + * doc/winfo.n: that [winfo toplevel] does not + assume that it is really working with toplevels. Occasionally this + is important. Thanks to Neil McKay for this patch! + 2004-06-29 Jeff Hobbs * generic/tkCmds.c (Tk_WinfoObjCmd): refetch interp result obj for diff --git a/doc/winfo.n b/doc/winfo.n index 324d6e3..ce79778 100644 --- a/doc/winfo.n +++ b/doc/winfo.n @@ -5,7 +5,7 @@ '\" See the file "license.terms" for information on usage and redistribution '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. '\" -'\" RCS: @(#) $Id: winfo.n,v 1.5 2004/06/18 22:31:18 dkf Exp $ +'\" RCS: @(#) $Id: winfo.n,v 1.6 2004/06/30 22:17:59 dkf Exp $ '\" .so man.macros .TH winfo n 4.3 Tk "Tk Built-In Commands" @@ -261,7 +261,9 @@ is the name of the vendor for the server, and \fIvendorRelease\fR is an integer release number provided by the server. .TP \fBwinfo toplevel \fIwindow\fR -Returns the path name of the top-level window containing \fIwindow\fR. +Returns the path name of the top-of-hierarchy window containing \fIwindow\fR. +In standard Tk this will always be a \fBtoplevel\fR widget, but extensions may +create other kinds of top-of-hierarchy widgets. .TP \fBwinfo viewable \fIwindow\fR Returns 1 if \fIwindow\fR and all of its ancestors up through the diff --git a/generic/tkCmds.c b/generic/tkCmds.c index f664b8c..dfd9af1 100644 --- a/generic/tkCmds.c +++ b/generic/tkCmds.c @@ -11,7 +11,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkCmds.c,v 1.33 2004/06/29 23:21:43 hobbs Exp $ + * RCS: @(#) $Id: tkCmds.c,v 1.34 2004/06/30 22:18:01 dkf Exp $ */ #include "tkPort.h" @@ -30,7 +30,7 @@ * Forward declarations for procedures defined later in this file: */ -static TkWindow * GetToplevel _ANSI_ARGS_((Tk_Window tkwin)); +static TkWindow * GetTopHierarchy _ANSI_ARGS_((Tk_Window tkwin)); static char * WaitVariableProc _ANSI_ARGS_((ClientData clientData, Tcl_Interp *interp, CONST char *name1, CONST char *name2, int flags)); @@ -1283,7 +1283,7 @@ Tk_WinfoObjCmd(clientData, interp, objc, objv) useY = 1; pointerxy: - winPtr = GetToplevel(tkwin); + winPtr = GetTopHierarchy(tkwin); if (winPtr == NULL) { x = -1; y = -1; @@ -1361,7 +1361,7 @@ Tk_WinfoObjCmd(clientData, interp, objc, objv) break; } case WIN_TOPLEVEL: { - winPtr = GetToplevel(tkwin); + winPtr = GetTopHierarchy(tkwin); if (winPtr != NULL) { Tcl_SetStringObj(resultPtr, winPtr->pathName, -1); } @@ -2019,14 +2019,15 @@ TkDeadAppCmd(clientData, interp, argc, argv) /* *---------------------------------------------------------------------- * - * GetToplevel -- + * GetTopHierarchy -- * - * Retrieves the toplevel window which is the nearest ancestor of - * of the specified window. + * Retrieves the top-of-hierarchy window which is the nearest + * ancestor of the specified window. * * Results: - * Returns the toplevel window or NULL if the window has no - * ancestor which is a toplevel. + * Returns the top-of-hierarchy window, or NULL if the window + * has no ancestor which is at the top of a physical window + * hierarchy. * * Side effects: * None. @@ -2035,17 +2036,17 @@ TkDeadAppCmd(clientData, interp, argc, argv) */ static TkWindow * -GetToplevel(tkwin) - Tk_Window tkwin; /* Window for which the toplevel should be - * deterined. */ +GetTopHierarchy(tkwin) + Tk_Window tkwin; /* Window for which the top-of-hierarchy + * ancestor should be deterined. */ { - TkWindow *winPtr = (TkWindow *) tkwin; + TkWindow *winPtr = (TkWindow *) tkwin; - while (!(winPtr->flags & TK_TOP_LEVEL)) { - winPtr = winPtr->parentPtr; - if (winPtr == NULL) { - return NULL; - } - } - return winPtr; + while (!(winPtr->flags & TK_TOP_HIERARCHY)) { + winPtr = winPtr->parentPtr; + if (winPtr == NULL) { + return NULL; /* This should never happen! */ + } + } + return winPtr; } -- cgit v0.12