From 93c5fdf107657e8f0041985743fe2918ef0cd394 Mon Sep 17 00:00:00 2001 From: dgp Date: Fri, 2 Jan 2015 20:17:39 +0000 Subject: The [winfo id] of a Tk window is meant to identify it. The actual value returned, though, has been a hex-formatted int value -- that is 32 bits. On OS X Cocoa, the actual Window or XID is not an int but an unsigned long, and does not fit in 32 bits. (What's really stored even seems to be a (MacDrawable *) -- a pointer -- definitely not something 32-bits can capture). Thus generating [winfo id] loses info, and breaks totally. Has for a long time apparently. There are even explicit comments in place plainly stating that it is broken and what needs doing to fix it. Updated the platform-specific routines Tkp(Scan|Print)WindowId() so that window id's are no longer lossy and broken in Cocoa Tk. --- macosx/tkMacOSXEmbed.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- macosx/tkMacOSXPort.h | 9 +-------- 2 files changed, 47 insertions(+), 10 deletions(-) diff --git a/macosx/tkMacOSXEmbed.c b/macosx/tkMacOSXEmbed.c index 17832c6..ef83276 100644 --- a/macosx/tkMacOSXEmbed.c +++ b/macosx/tkMacOSXEmbed.c @@ -174,6 +174,50 @@ TkpMakeWindow( /* *---------------------------------------------------------------------- * + * TkpScanWindowId -- + * + * Given a string, produce the corresponding Window Id. + * + * Results: + * The return value is normally TCL_OK; in this case *idPtr will be set + * to the Window value equivalent to string. If string is improperly + * formed then TCL_ERROR is returned and an error message will be left in + * the interp's result. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +int +TkpScanWindowId( + Tcl_Interp *interp, + CONST char * string, + Window *idPtr) +{ + int code; + Tcl_Obj obj; + + obj.refCount = 1; + obj.bytes = string; + obj.length = strlen(string); + obj.typePtr = NULL; + + code = Tcl_GetLongFromObj(interp, &obj, (long *)idPtr); + + if (obj.refCount > 1) { + Tcl_Panic("invalid sharing of Tcl_Obj on C stack"); + } + if (obj.typePtr && obj.typePtr->freeIntRepProc) { + obj.typePtr->freeIntRepProc(&obj); + } + return code; +} + +/* + *---------------------------------------------------------------------- + * * TkpUseWindow -- * * This procedure causes a Tk window to use a given X window as its @@ -214,7 +258,7 @@ TkpUseWindow( } /* - * Decode the container pointer, and look for it among the list of + * Decode the container window ID, and look for it among the list of * available containers. * * N.B. For now, we are limiting the containers to be in the same Tk @@ -222,7 +266,7 @@ TkpUseWindow( * containers. */ - if (Tcl_GetInt(interp, string, (int*) &parent) != TCL_OK) { + if (TkpScanWindowId(interp, string, (Window *)&parent) != TCL_OK) { return TCL_ERROR; } diff --git a/macosx/tkMacOSXPort.h b/macosx/tkMacOSXPort.h index 0a60cf6..6b56c83 100644 --- a/macosx/tkMacOSXPort.h +++ b/macosx/tkMacOSXPort.h @@ -162,14 +162,7 @@ */ #define TkpPrintWindowId(buf,w) \ - sprintf((buf), "0x%x", (unsigned int) (w)) - -/* - * TkpScanWindowId is just an alias for Tcl_GetInt on Unix. - */ - -#define TkpScanWindowId(i,s,wp) \ - Tcl_GetInt((i),(s),(int *) (wp)) + sprintf((buf), "0x%lx", (unsigned long) (w)) /* * Turn off Tk double-buffering as Aqua windows are already double-buffered. -- cgit v0.12 From 2f75423051e6eda811bcdfeadd4b5397d12baae2 Mon Sep 17 00:00:00 2001 From: dgp Date: Fri, 2 Jan 2015 20:18:52 +0000 Subject: remove old comment --- macosx/tkMacOSXPort.h | 1 - 1 file changed, 1 deletion(-) diff --git a/macosx/tkMacOSXPort.h b/macosx/tkMacOSXPort.h index 6b56c83..2ccbac3 100644 --- a/macosx/tkMacOSXPort.h +++ b/macosx/tkMacOSXPort.h @@ -158,7 +158,6 @@ /* * This macro stores a representation of the window handle in a string. - * This should perhaps use the real size of an XID. */ #define TkpPrintWindowId(buf,w) \ -- cgit v0.12