diff options
Diffstat (limited to 'generic/tkPack.c')
-rw-r--r-- | generic/tkPack.c | 165 |
1 files changed, 92 insertions, 73 deletions
diff --git a/generic/tkPack.c b/generic/tkPack.c index 1412a9d..65962bf 100644 --- a/generic/tkPack.c +++ b/generic/tkPack.c @@ -4,8 +4,8 @@ * This file contains code to implement the "packer" geometry manager for * Tk. * - * Copyright (c) 1990-1994 The Regents of the University of California. - * Copyright (c) 1994-1997 Sun Microsystems, Inc. + * Copyright © 1990-1994 The Regents of the University of California. + * Copyright © 1994-1997 Sun Microsystems, Inc. * * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. @@ -13,9 +13,9 @@ #include "tkInt.h" -typedef enum {TOP, BOTTOM, LEFT, RIGHT} Side; +typedef enum {BOTTOM, LEFT, RIGHT, TOP} Side; static const char *const sideNames[] = { - "top", "bottom", "left", "right", NULL + "bottom", "left", "right", "top", NULL }; /* @@ -103,8 +103,8 @@ typedef struct Packer { * The following structure is the official type record for the packer: */ -static void PackReqProc(ClientData clientData, Tk_Window tkwin); -static void PackLostContentProc(ClientData clientData, +static void PackReqProc(void *clientData, Tk_Window tkwin); +static void PackLostContentProc(void *clientData, Tk_Window tkwin); static const Tk_GeomMgr packerType = { @@ -117,14 +117,16 @@ static const Tk_GeomMgr packerType = { * Forward declarations for functions defined later in this file: */ -static void ArrangePacking(ClientData clientData); +static void ArrangePacking(void *clientData); static int ConfigureContent(Tcl_Interp *interp, Tk_Window tkwin, int objc, Tcl_Obj *const objv[]); static Tcl_FreeProc DestroyPacker; static Packer * GetPacker(Tk_Window tkwin); +#ifndef TK_NO_DEPRECATED static int PackAfter(Tcl_Interp *interp, Packer *prevPtr, Packer *containerPtr, int objc,Tcl_Obj *const objv[]); -static void PackStructureProc(ClientData clientData, +#endif /* !TK_NO_DEPRECATED */ +static void PackStructureProc(void *clientData, XEvent *eventPtr); static void Unlink(Packer *packPtr); static int XExpansion(Packer *contentPtr, int cavityWidth); @@ -160,12 +162,12 @@ TkAppendPadAmount( Tcl_Obj *padding[2]; if (halfSpace*2 == allSpace) { - Tcl_DictObjPut(NULL, bufferObj, Tcl_NewStringObj(switchName, -1), - Tcl_NewIntObj(halfSpace)); + Tcl_DictObjPut(NULL, bufferObj, Tcl_NewStringObj(switchName, TCL_INDEX_NONE), + Tcl_NewWideIntObj(halfSpace)); } else { - padding[0] = Tcl_NewIntObj(halfSpace); - padding[1] = Tcl_NewIntObj(allSpace - halfSpace); - Tcl_DictObjPut(NULL, bufferObj, Tcl_NewStringObj(switchName, -1), + padding[0] = Tcl_NewWideIntObj(halfSpace); + padding[1] = Tcl_NewWideIntObj(allSpace - halfSpace); + Tcl_DictObjPut(NULL, bufferObj, Tcl_NewStringObj(switchName, TCL_INDEX_NONE), Tcl_NewListObj(2, padding)); } } @@ -189,7 +191,7 @@ TkAppendPadAmount( int Tk_PackObjCmd( - ClientData clientData, /* Main window associated with interpreter. */ + void *clientData, /* Main window associated with interpreter. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* Argument objects. */ @@ -197,12 +199,17 @@ Tk_PackObjCmd( Tk_Window tkwin = (Tk_Window)clientData; const char *argv2; static const char *const optionStrings[] = { - /* after, append, before and unpack are deprecated */ - "after", "append", "before", "unpack", "configure", - "content", "forget", "info", "propagate", "slaves", NULL }; +#ifndef TK_NO_DEPRECATED + "after", "append", "before", "unpack", +#endif /* !TK_NO_DEPRECATED */ + "configure", "content", "forget", "info", "propagate", "slaves", NULL }; + static const char *const optionStringsNoDep[] = { + "configure", "content", "forget", "info", "propagate", NULL }; enum options { - PACK_AFTER, PACK_APPEND, PACK_BEFORE, PACK_UNPACK, PACK_CONFIGURE, - PACK_CONTENT, PACK_FORGET, PACK_INFO, PACK_PROPAGATE, PACK_SLAVES }; +#ifndef TK_NO_DEPRECATED + PACK_AFTER, PACK_APPEND, PACK_BEFORE, PACK_UNPACK, +#endif /* !TK_NO_DEPRECATED */ + PACK_CONFIGURE, PACK_CONTENT, PACK_FORGET, PACK_INFO, PACK_PROPAGATE, PACK_SLAVES }; int index; if (objc >= 2) { @@ -225,13 +232,14 @@ Tk_PackObjCmd( * deprecated and new options. */ - Tcl_GetIndexFromObj(interp, objv[1], &optionStrings[4], + Tcl_GetIndexFromObj(interp, objv[1], optionStringsNoDep, "option", 0, &index); return TCL_ERROR; } argv2 = Tcl_GetString(objv[2]); switch ((enum options) index) { +#ifndef TK_NO_DEPRECATED case PACK_AFTER: { Packer *prevPtr; Tk_Window tkwin2; @@ -243,7 +251,7 @@ Tk_PackObjCmd( if (prevPtr->containerPtr == NULL) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "window \"%s\" isn't packed", argv2)); - Tcl_SetErrorCode(interp, "TK", "PACK", "NOT_PACKED", NULL); + Tcl_SetErrorCode(interp, "TK", "PACK", "NOT_PACKED", (char *)NULL); return TCL_ERROR; } return PackAfter(interp, prevPtr, prevPtr->containerPtr, objc-3, objv+3); @@ -277,7 +285,7 @@ Tk_PackObjCmd( if (packPtr->containerPtr == NULL) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "window \"%s\" isn't packed", argv2)); - Tcl_SetErrorCode(interp, "TK", "PACK", "NOT_PACKED", NULL); + Tcl_SetErrorCode(interp, "TK", "PACK", "NOT_PACKED", (char *)NULL); return TCL_ERROR; } containerPtr = packPtr->containerPtr; @@ -296,11 +304,12 @@ Tk_PackObjCmd( } return PackAfter(interp, prevPtr, containerPtr, objc-3, objv+3); } +#endif /* !TK_NO_DEPRECATED */ case PACK_CONFIGURE: if (argv2[0] != '.') { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "bad argument \"%s\": must be name of window", argv2)); - Tcl_SetErrorCode(interp, "TK", "VALUE", "WINDOW_PATH", NULL); + Tcl_SetErrorCode(interp, "TK", "VALUE", "WINDOW_PATH", (char *)NULL); return TCL_ERROR; } return ConfigureContent(interp, tkwin, objc-2, objv+2); @@ -342,41 +351,41 @@ Tk_PackObjCmd( if (contentPtr->containerPtr == NULL) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "window \"%s\" isn't packed", argv2)); - Tcl_SetErrorCode(interp, "TK", "PACK", "NOT_PACKED", NULL); + Tcl_SetErrorCode(interp, "TK", "PACK", "NOT_PACKED", (char *)NULL); return TCL_ERROR; } infoObj = Tcl_NewObj(); - Tcl_DictObjPut(NULL, infoObj, Tcl_NewStringObj("-in", -1), - TkNewWindowObj(contentPtr->containerPtr->tkwin)); - Tcl_DictObjPut(NULL, infoObj, Tcl_NewStringObj("-anchor", -1), - Tcl_NewStringObj(Tk_NameOfAnchor(contentPtr->anchor), -1)); - Tcl_DictObjPut(NULL, infoObj, Tcl_NewStringObj("-expand", -1), + Tcl_DictObjPut(NULL, infoObj, Tcl_NewStringObj("-in", TCL_INDEX_NONE), + Tk_NewWindowObj(contentPtr->containerPtr->tkwin)); + Tcl_DictObjPut(NULL, infoObj, Tcl_NewStringObj("-anchor", TCL_INDEX_NONE), + Tcl_NewStringObj(Tk_NameOfAnchor(contentPtr->anchor), TCL_INDEX_NONE)); + Tcl_DictObjPut(NULL, infoObj, Tcl_NewStringObj("-expand", TCL_INDEX_NONE), Tcl_NewBooleanObj(contentPtr->flags & EXPAND)); switch (contentPtr->flags & (FILLX|FILLY)) { case 0: - Tcl_DictObjPut(NULL, infoObj, Tcl_NewStringObj("-fill", -1), - Tcl_NewStringObj("none", -1)); + Tcl_DictObjPut(NULL, infoObj, Tcl_NewStringObj("-fill", TCL_INDEX_NONE), + Tcl_NewStringObj("none", TCL_INDEX_NONE)); break; case FILLX: - Tcl_DictObjPut(NULL, infoObj, Tcl_NewStringObj("-fill", -1), - Tcl_NewStringObj("x", -1)); + Tcl_DictObjPut(NULL, infoObj, Tcl_NewStringObj("-fill", TCL_INDEX_NONE), + Tcl_NewStringObj("x", TCL_INDEX_NONE)); break; case FILLY: - Tcl_DictObjPut(NULL, infoObj, Tcl_NewStringObj("-fill", -1), - Tcl_NewStringObj("y", -1)); + Tcl_DictObjPut(NULL, infoObj, Tcl_NewStringObj("-fill", TCL_INDEX_NONE), + Tcl_NewStringObj("y", TCL_INDEX_NONE)); break; case FILLX|FILLY: - Tcl_DictObjPut(NULL, infoObj, Tcl_NewStringObj("-fill", -1), - Tcl_NewStringObj("both", -1)); + Tcl_DictObjPut(NULL, infoObj, Tcl_NewStringObj("-fill", TCL_INDEX_NONE), + Tcl_NewStringObj("both", TCL_INDEX_NONE)); break; } TkAppendPadAmount(infoObj, "-ipadx", contentPtr->iPadX/2, contentPtr->iPadX); TkAppendPadAmount(infoObj, "-ipady", contentPtr->iPadY/2, contentPtr->iPadY); TkAppendPadAmount(infoObj, "-padx", contentPtr->padLeft,contentPtr->padX); TkAppendPadAmount(infoObj, "-pady", contentPtr->padTop, contentPtr->padY); - Tcl_DictObjPut(NULL, infoObj, Tcl_NewStringObj("-side", -1), - Tcl_NewStringObj(sideNames[contentPtr->side], -1)); + Tcl_DictObjPut(NULL, infoObj, Tcl_NewStringObj("-side", TCL_INDEX_NONE), + Tcl_NewStringObj(sideNames[contentPtr->side], TCL_INDEX_NONE)); Tcl_SetObjResult(interp, infoObj); break; } @@ -453,11 +462,12 @@ Tk_PackObjCmd( for (contentPtr = containerPtr->contentPtr; contentPtr != NULL; contentPtr = contentPtr->nextPtr) { Tcl_ListObjAppendElement(NULL, resultObj, - TkNewWindowObj(contentPtr->tkwin)); + Tk_NewWindowObj(contentPtr->tkwin)); } Tcl_SetObjResult(interp, resultObj); break; } +#ifndef TK_NO_DEPRECATED case PACK_UNPACK: { Tk_Window tkwin2; Packer *packPtr; @@ -481,6 +491,7 @@ Tk_PackObjCmd( } break; } +#endif /* !TK_NO_DEPRECATED */ } return TCL_OK; @@ -506,7 +517,7 @@ Tk_PackObjCmd( static void PackReqProc( - ClientData clientData, /* Packer's information about window that got + void *clientData, /* Packer's information about window that got * new preferred geometry. */ TCL_UNUSED(Tk_Window)) /* Other Tk-related information about the * window. */ @@ -573,7 +584,7 @@ PackLostContentProc( static void ArrangePacking( - ClientData clientData) /* Structure describing container whose content + void *clientData) /* Structure describing container whose content * are to be re-layed out. */ { Packer *containerPtr = (Packer *)clientData; @@ -815,12 +826,10 @@ ArrangePacking( x = frameX + borderLeft; y = frameY + borderTop; break; - case TK_ANCHOR_CENTER: + default: x = frameX + (borderLeft + frameWidth - width - borderRight)/2; y = frameY + (borderTop + frameHeight - height - borderBtm)/2; break; - default: - Tcl_Panic("bad frame factor in ArrangePacking"); } width -= contentPtr->doubleBw; height -= contentPtr->doubleBw; @@ -1086,6 +1095,7 @@ GetPacker( *------------------------------------------------------------------------ */ +#ifndef TK_NO_DEPRECATED static int PackAfter( Tcl_Interp *interp, /* Interpreter for error reporting. */ @@ -1101,7 +1111,8 @@ PackAfter( Packer *packPtr; Tk_Window tkwin, ancestor, parent; Tcl_Obj **options; - int index, optionCount, c; + int c; + Tcl_Size index, optionCount; /* * Iterate over all of the window specifiers, each consisting of two @@ -1114,7 +1125,7 @@ PackAfter( Tcl_SetObjResult(interp, Tcl_ObjPrintf( "wrong # args: window \"%s\" should be followed by options", Tcl_GetString(objv[0]))); - Tcl_SetErrorCode(interp, "TCL", "WRONGARGS", NULL); + Tcl_SetErrorCode(interp, "TCL", "WRONGARGS", (char *)NULL); return TCL_ERROR; } @@ -1137,9 +1148,9 @@ PackAfter( if (((Tk_FakeWin *) (ancestor))->flags & TK_TOP_HIERARCHY) { badWindow: Tcl_SetObjResult(interp, Tcl_ObjPrintf( - "can't pack %s inside %s", Tcl_GetString(objv[0]), + "can't pack \"%s\" inside \"%s\"", Tcl_GetString(objv[0]), Tk_PathName(containerPtr->tkwin))); - Tcl_SetErrorCode(interp, "TK", "GEOMETRY", "HIERARCHY", NULL); + Tcl_SetErrorCode(interp, "TK", "GEOMETRY", "HIERARCHY", (char *)NULL); return TCL_ERROR; } } @@ -1168,7 +1179,7 @@ PackAfter( packPtr->flags |= OLD_STYLE; for (index = 0 ; index < optionCount; index++) { Tcl_Obj *curOptPtr = options[index]; - int length; + Tcl_Size length; const char *curOpt = Tcl_GetStringFromObj(curOptPtr, &length); c = curOpt[0]; @@ -1202,7 +1213,7 @@ PackAfter( "wrong # args: \"%s\" option must be" " followed by screen distance", curOpt)); Tcl_SetErrorCode(interp, "TK", "OLDPACK", "BAD_PARAMETER", - NULL); + (char *)NULL); return TCL_ERROR; } if (TkParsePadAmount(interp, tkwin, options[index+1], @@ -1230,9 +1241,9 @@ PackAfter( if (optionCount <= (index+1)) { Tcl_SetObjResult(interp, Tcl_NewStringObj( "wrong # args: \"frame\"" - " option must be followed by anchor point", -1)); + " option must be followed by anchor point", TCL_INDEX_NONE)); Tcl_SetErrorCode(interp, "TK", "OLDPACK", "BAD_PARAMETER", - NULL); + (char *)NULL); return TCL_ERROR; } if (Tk_GetAnchorFromObj(interp, options[index+1], @@ -1246,7 +1257,7 @@ PackAfter( " right, expand, fill, fillx, filly, padx, pady, or" " frame", curOpt)); Tcl_SetErrorCode(interp, "TK", "OLDPACK", "BAD_PARAMETER", - NULL); + (char *)NULL); return TCL_ERROR; } } @@ -1306,6 +1317,7 @@ PackAfter( } return TCL_OK; } +#endif /* !TK_NO_DEPRECATED */ /* *---------------------------------------------------------------------- @@ -1359,11 +1371,15 @@ Unlink( /* * If we have emptied this container from content it means we are no longer * handling it and should mark it as free. + * + * Send the event "NoManagedChild" to the container to inform it about there + * being no managed children inside it. */ if ((containerPtr->contentPtr == NULL) && (containerPtr->flags & ALLOCED_CONTAINER)) { TkFreeGeometryContainer(containerPtr->tkwin, "pack"); containerPtr->flags &= ~ALLOCED_CONTAINER; + Tk_SendVirtualEvent(containerPtr->tkwin, "NoManagedChild", NULL); } } @@ -1388,8 +1404,11 @@ Unlink( static void DestroyPacker( - char *memPtr) /* Info about packed window that is now - * dead. */ +#if TCL_MAJOR_VERSION > 8 + void *memPtr) /* Info about packed window that is now dead. */ +#else + char *memPtr) +#endif { Packer *packPtr = (Packer *)memPtr; @@ -1419,7 +1438,7 @@ DestroyPacker( static void PackStructureProc( - ClientData clientData, /* Our information about window referred to by + void *clientData, /* Our information about window referred to by * eventPtr. */ XEvent *eventPtr) /* Describes what just happened. */ { @@ -1432,7 +1451,7 @@ PackStructureProc( Tcl_DoWhenIdle(ArrangePacking, packPtr); } if ((packPtr->containerPtr != NULL) - && (packPtr->doubleBw != 2*Tk_Changes(packPtr->tkwin)->border_width)) { + && (packPtr->doubleBw != 2*Tk_Changes(packPtr->tkwin)->border_width)) { if (!(packPtr->containerPtr->flags & REQUESTED_REPACK)) { packPtr->doubleBw = 2*Tk_Changes(packPtr->tkwin)->border_width; packPtr->containerPtr->flags |= REQUESTED_REPACK; @@ -1457,8 +1476,8 @@ PackStructureProc( if (packPtr->tkwin != NULL) { TkDisplay *dispPtr = ((TkWindow *) packPtr->tkwin)->dispPtr; - Tcl_DeleteHashEntry(Tcl_FindHashEntry(&dispPtr->packerHashTable, - (void *)packPtr->tkwin)); + Tcl_DeleteHashEntry(Tcl_FindHashEntry(&dispPtr->packerHashTable, + packPtr->tkwin)); } if (packPtr->flags & REQUESTED_REPACK) { @@ -1567,7 +1586,7 @@ ConfigureContent( Tcl_SetObjResult(interp, Tcl_ObjPrintf( "can't pack \"%s\": it's a top-level window", Tcl_GetString(objv[j]))); - Tcl_SetErrorCode(interp, "TK", "GEOMETRY", "TOPLEVEL", NULL); + Tcl_SetErrorCode(interp, "TK", "GEOMETRY", "TOPLEVEL", (char *)NULL); return TCL_ERROR; } contentPtr = GetPacker(content); @@ -1593,7 +1612,7 @@ ConfigureContent( Tcl_SetObjResult(interp, Tcl_ObjPrintf( "extra option \"%s\" (option with no value?)", Tcl_GetString(objv[i]))); - Tcl_SetErrorCode(interp, "TK", "PACK", "BAD_PARAMETER", NULL); + Tcl_SetErrorCode(interp, "TK", "PACK", "BAD_PARAMETER", (char *)NULL); return TCL_ERROR; } if (Tcl_GetIndexFromObj(interp, objv[i], optionStrings, @@ -1615,7 +1634,7 @@ ConfigureContent( "window \"%s\" isn't packed", Tcl_GetString(objv[i+1]))); Tcl_SetErrorCode(interp, "TK", "PACK", "NOT_PACKED", - NULL); + (char *)NULL); return TCL_ERROR; } containerPtr = prevPtr->containerPtr; @@ -1673,7 +1692,7 @@ ConfigureContent( Tcl_SetObjResult(interp, Tcl_ObjPrintf( "bad fill style \"%s\": must be " "none, x, y, or both", string)); - Tcl_SetErrorCode(interp, "TK", "VALUE", "FILL", NULL); + Tcl_SetErrorCode(interp, "TK", "VALUE", "FILL", (char *)NULL); return TCL_ERROR; } break; @@ -1699,7 +1718,7 @@ ConfigureContent( Tcl_SetObjResult(interp, Tcl_ObjPrintf( "bad ipadx value \"%s\": must be positive screen" " distance", Tcl_GetString(objv[i+1]))); - Tcl_SetErrorCode(interp, "TK", "VALUE", "INT_PAD", NULL); + Tcl_SetErrorCode(interp, "TK", "VALUE", "INT_PAD", (char *)NULL); return TCL_ERROR; } contentPtr->iPadX = tmp * 2; @@ -1710,7 +1729,7 @@ ConfigureContent( Tcl_SetObjResult(interp, Tcl_ObjPrintf( "bad ipady value \"%s\": must be positive screen" " distance", Tcl_GetString(objv[i+1]))); - Tcl_SetErrorCode(interp, "TK", "VALUE", "INT_PAD", NULL); + Tcl_SetErrorCode(interp, "TK", "VALUE", "INT_PAD", (char *)NULL); return TCL_ERROR; } contentPtr->iPadY = tmp * 2; @@ -1788,16 +1807,16 @@ ConfigureContent( } if (Tk_TopWinHierarchy(ancestor)) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( - "can't pack %s inside %s", Tcl_GetString(objv[j]), + "can't pack \"%s\" inside \"%s\"", Tcl_GetString(objv[j]), Tk_PathName(containerPtr->tkwin))); - Tcl_SetErrorCode(interp, "TK", "GEOMETRY", "HIERARCHY", NULL); + Tcl_SetErrorCode(interp, "TK", "GEOMETRY", "HIERARCHY", (char *)NULL); return TCL_ERROR; } } if (content == containerPtr->tkwin) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( - "can't pack %s inside itself", Tcl_GetString(objv[j]))); - Tcl_SetErrorCode(interp, "TK", "GEOMETRY", "SELF", NULL); + "can't pack \"%s\" inside itself", Tcl_GetString(objv[j]))); + Tcl_SetErrorCode(interp, "TK", "GEOMETRY", "SELF", (char *)NULL); return TCL_ERROR; } @@ -1809,9 +1828,9 @@ ConfigureContent( container = (TkWindow *)TkGetContainer(container)) { if (container == (TkWindow *)content) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( - "can't put %s inside %s, would cause management loop", - Tcl_GetString(objv[j]), Tk_PathName(containerPtr->tkwin))); - Tcl_SetErrorCode(interp, "TK", "GEOMETRY", "LOOP", NULL); + "can't put \"%s\" inside \"%s\": would cause management loop", + Tcl_GetString(objv[j]), Tk_PathName(containerPtr->tkwin))); + Tcl_SetErrorCode(interp, "TK", "GEOMETRY", "LOOP", (char *)NULL); return TCL_ERROR; } } |