From 413e598de2e293d8046eaadcb0e4e30a9b9f49cc Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 12 Feb 2001 18:06:47 +0000 Subject: Asymmetric padding in "pack" and "grid" geometry managers --- ChangeLog | 7 ++ doc/grid.n | 6 +- doc/pack.n | 8 +- generic/tkGrid.c | 51 ++++++------ generic/tkPack.c | 242 ++++++++++++++++++++++++++++++++++++++++--------------- tests/grid.test | 70 +++++++++++----- tests/pack.test | 91 +++++++++++++++++---- 7 files changed, 350 insertions(+), 125 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7616751..a1b97b8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2001-02-12 D. Richard Hipp + + TIP #21: Asymmetric padding in the pack and grid geometry managers. + With this changes, you can now say "-padx {10 20}" to put 10 pixels + of padding on the left and 20 on the right. Similar rules apply + for vertical padding. See the revised documentation for details. + 2001-01-02 Andreas Kupries * Everything below belongs together and implements TIP #8 diff --git a/doc/grid.n b/doc/grid.n index 1bd9121..809ce50 100644 --- a/doc/grid.n +++ b/doc/grid.n @@ -4,7 +4,7 @@ '\" See the file "license.terms" for information on usage and redistribution '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. '\" -'\" RCS: @(#) $Id: grid.n,v 1.2 1998/09/14 18:22:56 stanton Exp $ +'\" RCS: @(#) $Id: grid.n,v 1.3 2001/02/12 18:06:47 drh Exp $ '\" .so man.macros .TH grid n 4.1 Tk "Tk Built-In Commands" @@ -113,12 +113,16 @@ The \fIamount\fR defaults to 0. \fB\-padx \fIamount\fR The \fIamount\fR specifies how much horizontal external padding to leave on each side of the slave(s), in screen units. +\fIAmount\fR may be a list +of two values to specify padding for left and right separately. The \fIamount\fR defaults to 0. This space is added outside the slave(s) border. .TP \fB\-pady \fIamount\fR The \fIamount\fR specifies how much vertical external padding to leave on the top and bottom of the slave(s), in screen units. +\fIAmount\fR may be a list +of two values to specify padding for top and bottom separately. The \fIamount\fR defaults to 0. This space is added outside the slave(s) border. .TP diff --git a/doc/pack.n b/doc/pack.n index 411e8f7..ddda916 100644 --- a/doc/pack.n +++ b/doc/pack.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: pack.n,v 1.2 1998/09/14 18:22:58 stanton Exp $ +'\" RCS: @(#) $Id: pack.n,v 1.3 2001/02/12 18:06:47 drh Exp $ '\" .so man.macros .TH pack n 4.0 Tk "Tk Built-In Commands" @@ -101,12 +101,14 @@ leave on each side of the slave(s). .TP \fB\-padx \fIamount\fR \fIAmount\fR specifies how much horizontal external padding to -leave on each side of the slave(s). +leave on each side of the slave(s). \fIAmount\fR may be a list +of two values to specify padding for left and right separately. \fIAmount\fR defaults to 0. .TP \fB\-pady \fIamount\fR \fIAmount\fR specifies how much vertical external padding to -leave on each side of the slave(s). +leave on each side of the slave(s). \fIAmount\fR may be a list +of two values to specify padding for top and bottom separtely. \fIAmount\fR defaults to 0. .TP \fB\-side \fIside\fR diff --git a/generic/tkGrid.c b/generic/tkGrid.c index 8564381..0d176f5 100644 --- a/generic/tkGrid.c +++ b/generic/tkGrid.c @@ -8,7 +8,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkGrid.c,v 1.10 2000/08/02 20:52:34 ericm Exp $ + * RCS: @(#) $Id: tkGrid.c,v 1.11 2001/02/12 18:06:47 drh Exp $ */ #include "tkInt.h" @@ -161,10 +161,13 @@ typedef struct Gridder { int numCols, numRows; /* Number of columns or rows this slave spans. * Should be at least 1. */ int padX, padY; /* Total additional pixels to leave around the - * window (half of this space is left on each - * side). This is space *outside* the window: + * window. Some is of this space is on each + * side. This is space *outside* the window: * we'll allocate extra space in frame but * won't enlarge window). */ + int padLeft, padTop; /* The part of padX or padY to use on the + * left or top of the widget, respectively. + * By default, this is half of padX or padY. */ int iPadX, iPadY; /* Total extra pixels to allocate inside the * window (half this amount will appear on * each side). */ @@ -266,6 +269,14 @@ static void StickyToString _ANSI_ARGS_((int flags, char *result)); static int StringToSticky _ANSI_ARGS_((char *string)); static void Unlink _ANSI_ARGS_((Gridder *gridPtr)); +/* + * Prototypes for procedures contained in other files but not exported + * using tkIntDecls.h + */ + +void TkPrintPadAmount _ANSI_ARGS_((Tcl_Interp*, char*, int, int)); +int TkParsePadAmount _ANSI_ARGS_((Tcl_Interp*, Tk_Window, char*, int*, int*)); + static Tk_GeomMgr gridMgrType = { "grid", /* name */ GridReqProc, /* requestProc */ @@ -545,6 +556,7 @@ GridForgetRemoveCommand(tkwin, interp, argc, argv) slavePtr->numCols = 1; slavePtr->numRows = 1; slavePtr->padX = slavePtr->padY = 0; + slavePtr->padLeft = slavePtr->padTop = 0; slavePtr->iPadX = slavePtr->iPadY = 0; slavePtr->doubleBw = 2*Tk_Changes(tkwin)->border_width; if (slavePtr->flags & REQUESTED_RELAYOUT) { @@ -615,10 +627,10 @@ GridInfoCommand(tkwin, interp, argc, argv) slavePtr->column, slavePtr->row, slavePtr->numCols, slavePtr->numRows); Tcl_AppendResult(interp, buffer, (char *) NULL); - sprintf(buffer, " -ipadx %d -ipady %d -padx %d -pady %d", - slavePtr->iPadX/2, slavePtr->iPadY/2, slavePtr->padX/2, - slavePtr->padY/2); - Tcl_AppendResult(interp, buffer, (char *) NULL); + TkPrintPadAmount(interp, "ipadx", slavePtr->iPadX/2, slavePtr->iPadX); + TkPrintPadAmount(interp, "ipady", slavePtr->iPadY/2, slavePtr->iPadY); + TkPrintPadAmount(interp, "padx", slavePtr->padLeft, slavePtr->padX); + TkPrintPadAmount(interp, "pady", slavePtr->padTop, slavePtr->padY); StickyToString(slavePtr->sticky,buffer); Tcl_AppendResult(interp, " -sticky ", buffer, (char *) NULL); return TCL_OK; @@ -1425,9 +1437,9 @@ AdjustForSticky(slavePtr, xPtr, yPtr, widthPtr, heightPtr) int diffy=0; /* Cavity hight - slave height. */ int sticky = slavePtr->sticky; - *xPtr += slavePtr->padX/2; + *xPtr += slavePtr->padLeft; *widthPtr -= slavePtr->padX; - *yPtr += slavePtr->padY/2; + *yPtr += slavePtr->padTop; *heightPtr -= slavePtr->padY; if (*widthPtr > (Tk_ReqWidth(slavePtr->tkwin) + slavePtr->iPadX)) { @@ -2029,6 +2041,7 @@ GetGrid(tkwin) gridPtr->numRows = 1; gridPtr->padX = gridPtr->padY = 0; + gridPtr->padLeft = gridPtr->padTop = 0; gridPtr->iPadX = gridPtr->iPadY = 0; gridPtr->doubleBw = 2*Tk_Changes(tkwin)->border_width; gridPtr->abortPtr = NULL; @@ -2599,26 +2612,16 @@ ConfigureSlaves(interp, tkwin, argc, argv) slavePtr->iPadY = tmp*2; } else if ((c == 'p') && (strncmp(argv[i], "-padx", length) == 0)) { - if ((Tk_GetPixels(interp, slave, argv[i+1], &tmp) != TCL_OK) - || (tmp< 0)) { - Tcl_ResetResult(interp); - Tcl_AppendResult(interp, "bad padx value \"", argv[i+1], - "\": must be positive screen distance", - (char *) NULL); + if (TkParsePadAmount(interp, tkwin, argv[i+1], + &slavePtr->padLeft, &slavePtr->padX) != TCL_OK) { return TCL_ERROR; } - slavePtr->padX = tmp*2; } else if ((c == 'p') && (strncmp(argv[i], "-pady", length) == 0)) { - if ((Tk_GetPixels(interp, slave, argv[i+1], &tmp) != TCL_OK) - || (tmp< 0)) { - Tcl_ResetResult(interp); - Tcl_AppendResult(interp, "bad pady value \"", argv[i+1], - "\": must be positive screen distance", - (char *) NULL); + if (TkParsePadAmount(interp, tkwin, argv[i+1], + &slavePtr->padTop, &slavePtr->padY) != TCL_OK) { return TCL_ERROR; } - slavePtr->padY = tmp*2; } else if ((c == 'r') && (strncmp(argv[i], "-row", length) == 0)) { if (Tcl_GetInt(interp, argv[i+1], &tmp) != TCL_OK || tmp<0) { Tcl_ResetResult(interp); @@ -2905,4 +2908,4 @@ StringToSticky(string) } } return sticky; -} +} diff --git a/generic/tkPack.c b/generic/tkPack.c index a178261..a6df7a9 100644 --- a/generic/tkPack.c +++ b/generic/tkPack.c @@ -10,7 +10,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkPack.c,v 1.6 2000/04/10 22:43:12 ericm Exp $ + * RCS: @(#) $Id: tkPack.c,v 1.7 2001/02/12 18:06:47 drh Exp $ */ #include "tkPort.h" @@ -24,7 +24,7 @@ typedef enum {TOP, BOTTOM, LEFT, RIGHT} Side; * structure of the following type: */ -typedef struct /* Green Bay */ Packer { +typedef struct Packer { Tk_Window tkwin; /* Tk token for window. NULL means that * the window has been deleted, but the * packet hasn't had a chance to clean up @@ -45,12 +45,15 @@ typedef struct /* Green Bay */ Packer { * than window needs, this indicates how * where to position window in frame. */ int padX, padY; /* Total additional pixels to leave around the - * window (half of this space is left on each - * side). This is space *outside* the window: + * window. Some is of this space is on each + * side. This is space *outside* the window: * we'll allocate extra space in frame but * won't enlarge window). */ + int padLeft, padTop; /* The part of padX or padY to use on the + * left or top of the widget, respectively. + * By default, this is half of padX or padY. */ int iPadX, iPadY; /* Total extra pixels to allocate inside the - * window (half this amount will appear on + * window (half of this amount will appear on * each side). */ int doubleBw; /* Twice the window's last known border * width. If this changes, the window @@ -136,6 +139,43 @@ static int YExpansion _ANSI_ARGS_((Packer *slavePtr, /* *-------------------------------------------------------------- * + * TkPrintPadAmount -- + * + * This procedure generates a text value that describes one + * of the -padx, -pady, -ipadx, or -ipady configuration options. + * The text value generated is appended to the interpreter + * result. + * + * Results: + * None. + * + * Side effects: + * None. + * + *-------------------------------------------------------------- + */ +void +TkPrintPadAmount(interp, switchName, halfSpace, allSpace) + Tcl_Interp *interp; /* The interpreter into which the result + * is written. */ + char *switchName; /* One of "padx", "pady", "ipadx" or "ipady" */ + int halfSpace; /* The left or top padding amount */ + int allSpace; /* The total amount of padding */ +{ + char buffer[60 + 2*TCL_INTEGER_SPACE]; + if (halfSpace*2 == allSpace) { + sprintf(buffer, " -%.10s %d", switchName, halfSpace); + } else { + sprintf(buffer, " -%.10s {%d %d}", switchName, halfSpace, + allSpace - halfSpace); + } + Tcl_AppendResult(interp, buffer, (char *)NULL); +} + + +/* + *-------------------------------------------------------------- + * * Tk_PackCmd -- * * This procedure is invoked to process the "pack" Tcl command. @@ -268,7 +308,6 @@ Tk_PackCmd(clientData, interp, argc, argv) } else if ((c == 'i') && (strncmp(argv[1], "info", length) == 0)) { register Packer *slavePtr; Tk_Window slave; - char buffer[64 + TCL_INTEGER_SPACE * 4]; static char *sideNames[] = {"top", "bottom", "left", "right"}; if (argc != 3) { @@ -307,10 +346,11 @@ Tk_PackCmd(clientData, interp, argc, argv) Tcl_AppendResult(interp, "both", (char *) NULL); break; } - sprintf(buffer, " -ipadx %d -ipady %d -padx %d -pady %d", - slavePtr->iPadX/2, slavePtr->iPadY/2, slavePtr->padX/2, - slavePtr->padY/2); - Tcl_AppendResult(interp, buffer, " -side ", sideNames[slavePtr->side], + TkPrintPadAmount(interp, "ipadx", slavePtr->iPadX/2, slavePtr->iPadX); + TkPrintPadAmount(interp, "ipady", slavePtr->iPadY/2, slavePtr->iPadY); + TkPrintPadAmount(interp, "padx", slavePtr->padLeft, slavePtr->padX); + TkPrintPadAmount(interp, "pady", slavePtr->padTop, slavePtr->padY); + Tcl_AppendResult(interp, " -side ", sideNames[slavePtr->side], (char *) NULL); } else if ((c == 'p') && (strncmp(argv[1], "propagate", length) == 0)) { Tk_Window master; @@ -518,6 +558,8 @@ ArrangePacking(clientData) int abort; /* May get set to non-zero to abort this * repacking operation. */ int borderX, borderY; + int borderTop, borderBtm; + int borderLeft, borderRight; int maxWidth, maxHeight, tmp; masterPtr->flags &= ~REQUESTED_REPACK; @@ -678,9 +720,15 @@ ArrangePacking(clientData) if (slavePtr->flags & OLD_STYLE) { borderX = borderY = 0; + borderTop = borderBtm = 0; + borderLeft = borderRight = 0; } else { borderX = slavePtr->padX; borderY = slavePtr->padY; + borderLeft = slavePtr->padLeft; + borderRight = borderX - borderLeft; + borderTop = slavePtr->padTop; + borderBtm = borderY - borderTop; } width = Tk_ReqWidth(slavePtr->tkwin) + slavePtr->doubleBw + slavePtr->iPadX; @@ -694,44 +742,42 @@ ArrangePacking(clientData) || (height > (frameHeight - borderY))) { height = frameHeight - borderY; } - borderX /= 2; - borderY /= 2; switch (slavePtr->anchor) { case TK_ANCHOR_N: - x = frameX + (frameWidth - width)/2; - y = frameY + borderY; + x = frameX + (borderLeft + frameWidth - width - borderRight)/2; + y = frameY + borderTop; break; case TK_ANCHOR_NE: - x = frameX + frameWidth - width - borderX; - y = frameY + borderY; + x = frameX + frameWidth - width - borderRight; + y = frameY + borderTop; break; case TK_ANCHOR_E: - x = frameX + frameWidth - width - borderX; - y = frameY + (frameHeight - height)/2; + x = frameX + frameWidth - width - borderRight; + y = frameY + (borderTop + frameHeight - height - borderBtm)/2; break; case TK_ANCHOR_SE: - x = frameX + frameWidth - width - borderX; - y = frameY + frameHeight - height - borderY; + x = frameX + frameWidth - width - borderRight; + y = frameY + frameHeight - height - borderBtm; break; case TK_ANCHOR_S: - x = frameX + (frameWidth - width)/2; - y = frameY + frameHeight - height - borderY; + x = frameX + (borderLeft + frameWidth - width - borderRight)/2; + y = frameY + frameHeight - height - borderBtm; break; case TK_ANCHOR_SW: - x = frameX + borderX; - y = frameY + frameHeight - height - borderY; + x = frameX + borderLeft; + y = frameY + frameHeight - height - borderBtm; break; case TK_ANCHOR_W: - x = frameX + borderX; - y = frameY + (frameHeight - height)/2; + x = frameX + borderLeft; + y = frameY + (borderTop + frameHeight - height - borderBtm)/2; break; case TK_ANCHOR_NW: - x = frameX + borderX; - y = frameY + borderY; + x = frameX + borderLeft; + y = frameY + borderTop; break; case TK_ANCHOR_CENTER: - x = frameX + (frameWidth - width)/2; - y = frameY + (frameHeight - height)/2; + x = frameX + (borderLeft + frameWidth - width - borderRight)/2; + y = frameY + (borderTop + frameHeight - height - borderBtm)/2; break; default: panic("bad frame factor in ArrangePacking"); @@ -969,6 +1015,7 @@ GetPacker(tkwin) packPtr->side = TOP; packPtr->anchor = TK_ANCHOR_CENTER; packPtr->padX = packPtr->padY = 0; + packPtr->padLeft = packPtr->padTop = 0; packPtr->iPadX = packPtr->iPadY = 0; packPtr->doubleBw = 2*Tk_Changes(tkwin)->border_width; packPtr->abortPtr = NULL; @@ -982,6 +1029,85 @@ GetPacker(tkwin) /* *-------------------------------------------------------------- * + * TkParsePadAmount -- + * + * This procedure parses a padding specification and returns + * the appropriate padding values. A padding specification can + * be either a single pixel width, or a list of two pixel widths. + * If a single pixel width, the amount specified is used for + * padding on both sides. If two amounts are specified, then + * they specify the left/right or top/bottom padding. + * + * Results: + * A standard Tcl return value. + * + * Side effects: + * An error message is written to the interpreter is something + * is not right. + * + *-------------------------------------------------------------- + */ + +int +TkParsePadAmount(interp, tkwin, padSpec, halfPtr, allPtr) + Tcl_Interp *interp; /* Interpreter for error reporting. */ + Tk_Window tkwin; /* A window. Needed by Tk_GetPixels() */ + char *padSpec; /* The argument to "-padx", "-pady", "-ipadx", + * or "-ipady". The thing to be parsed. */ + int *halfPtr; /* Write the left/top part of padding here */ + int *allPtr; /* Write the total padding here */ +{ + char *secondPart; /* The second pixel amount of the list */ + char *separator = 0; /* Separator between 1st and 2nd pixel widths */ + int sepChar; /* Character used as the separator */ + int firstInt, secondInt; /* The two components of the padding */ + + for (secondPart=padSpec; + (*secondPart != '\0') && !isspace(UCHAR(*secondPart)); + secondPart++) + { /* Do nothing */ } + if (*secondPart != '\0') { + separator = secondPart; + sepChar = *secondPart; + *secondPart = '\0'; + secondPart++; + while ( isspace(UCHAR(*secondPart)) ) { + secondPart++; + } + if (*secondPart == '\0'){ + secondPart = 0; + *separator = sepChar; + } + } else { + secondPart = 0; + } + if ((Tk_GetPixels(interp, tkwin, padSpec, &firstInt) != TCL_OK) || + (firstInt < 0)) { + Tcl_ResetResult(interp); + Tcl_AppendResult(interp, "bad pad value \"", padSpec, + "\": must be positive screen distance", (char *) NULL); + return TCL_ERROR; + } + if (secondPart) { + if ((Tk_GetPixels(interp, tkwin, secondPart, &secondInt) != TCL_OK) || + (secondInt < 0)) { + Tcl_ResetResult(interp); + Tcl_AppendResult(interp, "bad 2nd pad value \"", secondPart, + "\": must be positive screen distance", (char *) NULL); + return TCL_ERROR; + } + *separator = sepChar; + } else { + secondInt = firstInt; + } + if (halfPtr != 0) *halfPtr = firstInt; + *allPtr = firstInt + secondInt; + return TCL_OK; +} + +/* + *-------------------------------------------------------------- + * * PackAfter -- * * This procedure does most of the real work of adding @@ -1013,7 +1139,7 @@ PackAfter(interp, prevPtr, masterPtr, argc, argv) Tk_Window tkwin, ancestor, parent; size_t length; char **options; - int index, tmp, optionCount, c; + int index, optionCount, c; /* * Iterate over all of the window specifiers, each consisting of @@ -1072,6 +1198,7 @@ PackAfter(interp, prevPtr, masterPtr, argc, argv) packPtr->side = TOP; packPtr->anchor = TK_ANCHOR_CENTER; packPtr->padX = packPtr->padY = 0; + packPtr->padLeft = packPtr->padTop = 0; packPtr->iPadX = packPtr->iPadY = 0; packPtr->flags &= ~(FILLX|FILLY|EXPAND); packPtr->flags |= OLD_STYLE; @@ -1111,27 +1238,24 @@ PackAfter(interp, prevPtr, masterPtr, argc, argv) (char *) NULL); goto error; } - if ((Tk_GetPixels(interp, tkwin, options[index+1], &tmp) - != TCL_OK) || (tmp < 0)) { - badPad: - Tcl_AppendResult(interp, "bad pad value \"", - options[index+1], - "\": must be positive screen distance", - (char *) NULL); + if (TkParsePadAmount(interp, tkwin, options[index+1], + &packPtr->padLeft, &packPtr->padX) != TCL_OK) { goto error; } - packPtr->padX = tmp; + packPtr->padX /= 2; + packPtr->padLeft /= 2; packPtr->iPadX = 0; index++; } else if ((c == 'p') && (strcmp(curOpt, "pady")) == 0) { if (optionCount < (index+2)) { goto missingPad; } - if ((Tk_GetPixels(interp, tkwin, options[index+1], &tmp) - != TCL_OK) || (tmp < 0)) { - goto badPad; + if (TkParsePadAmount(interp, tkwin, options[index+1], + &packPtr->padTop, &packPtr->padY) != TCL_OK) { + goto error; } - packPtr->padY = tmp; + packPtr->padY /= 2; + packPtr->padTop /= 2; packPtr->iPadY = 0; index++; } else if ((c == 'f') && (length > 1) @@ -1462,6 +1586,7 @@ ConfigureSlaves(interp, tkwin, argc, argv) slavePtr->side = TOP; slavePtr->anchor = TK_ANCHOR_CENTER; slavePtr->padX = slavePtr->padY = 0; + slavePtr->padLeft = slavePtr->padTop = 0; slavePtr->iPadX = slavePtr->iPadY = 0; slavePtr->flags &= ~(FILLX|FILLY|EXPAND); } @@ -1561,34 +1686,25 @@ ConfigureSlaves(interp, tkwin, argc, argv) positionGiven = 1; } } else if ((c == 'i') && (strcmp(argv[i], "-ipadx") == 0)) { - if ((Tk_GetPixels(interp, slave, argv[i+1], &tmp) != TCL_OK) - || (tmp < 0)) { - badPad: - Tcl_ResetResult(interp); - Tcl_AppendResult(interp, "bad pad value \"", argv[i+1], - "\": must be positive screen distance", - (char *) NULL); + if (TkParsePadAmount(interp, slave, argv[i+1], + 0, &slavePtr->iPadX) != TCL_OK) { return TCL_ERROR; } - slavePtr->iPadX = tmp*2; } else if ((c == 'i') && (strcmp(argv[i], "-ipady") == 0)) { - if ((Tk_GetPixels(interp, slave, argv[i+1], &tmp) != TCL_OK) - || (tmp< 0)) { - goto badPad; + if (TkParsePadAmount(interp, slave, argv[i+1], + 0, &slavePtr->iPadY) != TCL_OK) { + return TCL_ERROR; } - slavePtr->iPadY = tmp*2; } else if ((c == 'p') && (strcmp(argv[i], "-padx") == 0)) { - if ((Tk_GetPixels(interp, slave, argv[i+1], &tmp) != TCL_OK) - || (tmp< 0)) { - goto badPad; + if (TkParsePadAmount(interp, slave, argv[i+1], + &slavePtr->padLeft, &slavePtr->padX) != TCL_OK) { + return TCL_ERROR; } - slavePtr->padX = tmp*2; } else if ((c == 'p') && (strcmp(argv[i], "-pady") == 0)) { - if ((Tk_GetPixels(interp, slave, argv[i+1], &tmp) != TCL_OK) - || (tmp< 0)) { - goto badPad; + if (TkParsePadAmount(interp, slave, argv[i+1], + &slavePtr->padTop, &slavePtr->padY) != TCL_OK) { + return TCL_ERROR; } - slavePtr->padY = tmp*2; } else if ((c == 's') && (strncmp(argv[i], "-side", length) == 0)) { c = argv[i+1][0]; if ((c == 't') && (strcmp(argv[i+1], "top") == 0)) { diff --git a/tests/grid.test b/tests/grid.test index 31e49df..75ead6e 100644 --- a/tests/grid.test +++ b/tests/grid.test @@ -5,7 +5,7 @@ # Copyright (c) 1998-1999 by Scriptics Corporation. # All rights reserved. # -# RCS: @(#) $Id: grid.test,v 1.8 2000/04/17 17:44:27 ericm Exp $ +# RCS: @(#) $Id: grid.test,v 1.9 2001/02/12 18:06:47 drh Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { source [file join [pwd] [file dirname [info script]] defs.tcl] @@ -198,6 +198,15 @@ test grid-4.3 {forget} { } {-in . -column 0 -row 0 -columnspan 1 -rowspan 1 -ipadx 0 -ipady 0 -padx 0 -pady 0 -sticky {}} grid_reset 4.3 +test grid-4.3.1 {forget} { + button .c + grid .c -row 2 -column 2 -rowspan 2 -columnspan 2 -padx {3 5} -pady {4 7} -sticky ns + grid forget .c + grid .c -row 0 -column 0 + grid info .c +} {-in . -column 0 -row 0 -columnspan 1 -rowspan 1 -ipadx 0 -ipady 0 -padx 0 -pady 0 -sticky {}} +grid_reset 4.3.1 + test grid-4.4 {forget, calling Tk_UnmaintainGeometry} { frame .f -bd 2 -relief raised place .f -x 10 -y 20 -width 200 -height 100 @@ -915,9 +924,15 @@ grid_reset 13.7 test grid-13.8 {-padx} { frame .f -width 20 -height 20 -highlightthickness 0 -bg red list [catch "grid .f -padx x" msg] $msg -} {1 {bad padx value "x": must be positive screen distance}} +} {1 {bad pad value "x": must be positive screen distance}} grid_reset 13.8 +test grid-13.8.1 {-padx} { + frame .f -width 20 -height 20 -highlightthickness 0 -bg red + list [catch "grid .f -padx {10 x}" msg] $msg +} {1 {bad 2nd pad value "x": must be positive screen distance}} +grid_reset 13.8.1 + test grid-13.9 {-padx} { frame .f -width 200 -height 100 -highlightthickness 0 -bg red grid .f @@ -925,16 +940,33 @@ test grid-13.9 {-padx} { set a "[winfo width .f] [winfo width .]" grid .f -padx 1 update - list $a "[winfo width .f] [winfo width .]" -} {{200 200} {200 202}} + list $a "[winfo width .f] [winfo width .] [winfo x .f]" +} {{200 200} {200 202 1}} grid_reset 13.9 +test grid-13.9.1 {-padx} { + frame .f -width 200 -height 100 -highlightthickness 0 -bg red + grid .f + update + set a "[winfo width .f] [winfo width .]" + grid .f -padx {10 5} + update + list $a "[winfo width .f] [winfo width .] [winfo x .f]" +} {{200 200} {200 215 10}} +grid_reset 13.9.1 + test grid-13.10 {-pady} { frame .f -width 20 -height 20 -highlightthickness 0 -bg red list [catch "grid .f -pady x" msg] $msg -} {1 {bad pady value "x": must be positive screen distance}} +} {1 {bad pad value "x": must be positive screen distance}} grid_reset 13.10 +test grid-13.10.1 {-pady} { + frame .f -width 20 -height 20 -highlightthickness 0 -bg red + list [catch "grid .f -pady {10 x}" msg] $msg +} {1 {bad 2nd pad value "x": must be positive screen distance}} +grid_reset 13.10.1 + test grid-13.11 {-pady} { frame .f -width 200 -height 100 -highlightthickness 0 -bg red grid .f @@ -942,10 +974,21 @@ test grid-13.11 {-pady} { set a "[winfo height .f] [winfo height .]" grid .f -pady 1 update - list $a "[winfo height .f] [winfo height .]" -} {{100 100} {100 102}} + list $a "[winfo height .f] [winfo height .] [winfo y .f]" +} {{100 100} {100 102 1}} grid_reset 13.11 +test grid-13.11.1 {-pady} { + frame .f -width 200 -height 100 -highlightthickness 0 -bg red + grid .f + update + set a "[winfo height .f] [winfo height .]" + grid .f -pady {4 16} + update + list $a "[winfo height .f] [winfo height .] [winfo y .f]" +} {{100 100} {100 120 4}} +grid_reset 13.11.1 + test grid-13.12 {-ipad x and y} { frame .f -width 20 -height 20 -highlightthickness 0 -bg red grid columnconfigure . 0 -minsize 150 @@ -1244,16 +1287,3 @@ test grid-17.1 {forget and pending idle handlers} { # cleanup ::tcltest::cleanupTests return - - - - - - - - - - - - - diff --git a/tests/pack.test b/tests/pack.test index abfd0d4..a36cb58 100644 --- a/tests/pack.test +++ b/tests/pack.test @@ -6,7 +6,7 @@ # Copyright (c) 1998-1999 by Scriptics Corporation. # All rights reserved. # -# RCS: @(#) $Id: pack.test,v 1.5 1999/04/21 21:53:29 rjohnson Exp $ +# RCS: @(#) $Id: pack.test,v 1.6 2001/02/12 18:06:48 drh Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { source [file join [pwd] [file dirname [info script]] defs.tcl] @@ -75,6 +75,12 @@ test pack-1.4 {-side option} { test pack-2.1 {x padding and filling} { pack1 -side right -padx 20 } {20x40+260+80 240x200+0+0} +test pack-2.1.1 {x padding and filling} { + pack1 -side right -padx {10 30} +} {20x40+250+80 240x200+0+0} +test pack-2.1.2 {x padding and filling} { + pack1 -side right -padx {35 5} +} {20x40+275+80 240x200+0+0} test pack-2.2 {x padding and filling} { pack1 -side right -ipadx 20 } {60x40+240+80 240x200+0+0} @@ -84,30 +90,51 @@ test pack-2.3 {x padding and filling} { test pack-2.4 {x padding and filling} { pack1 -side right -padx 20 -fill x } {20x40+260+80 240x200+0+0} +test pack-2.4.1 {x padding and filling} { + pack1 -side right -padx {9 31} -fill x +} {20x40+249+80 240x200+0+0} test pack-2.5 {x padding and filling} { pack1 -side right -ipadx 20 -fill x } {60x40+240+80 240x200+0+0} test pack-2.6 {x padding and filling} { pack1 -side right -ipadx 5 -padx 10 -fill x } {30x40+260+80 250x200+0+0} +test pack-2.6.1 {x padding and filling} { + pack1 -side right -ipadx 5 -padx {5 15} -fill x +} {30x40+255+80 250x200+0+0} test pack-2.7 {x padding and filling} { pack1 -side top -padx 20 } {20x40+140+0 300x160+0+40} +test pack-2.7.1 {x padding and filling} { + pack1 -side top -padx {0 40} +} {20x40+120+0 300x160+0+40} +test pack-2.7.2 {x padding and filling} { + pack1 -side top -padx {31 9} +} {20x40+151+0 300x160+0+40} test pack-2.8 {x padding and filling} { pack1 -side top -ipadx 20 } {60x40+120+0 300x160+0+40} test pack-2.9 {x padding and filling} { pack1 -side top -ipadx 5 -padx 10 } {30x40+135+0 300x160+0+40} +test pack-2.9.1 {x padding and filling} { + pack1 -side top -ipadx 5 -padx {5 15} +} {30x40+130+0 300x160+0+40} test pack-2.10 {x padding and filling} { pack1 -side top -padx 20 -fill x } {260x40+20+0 300x160+0+40} +test pack-2.10.1 {x padding and filling} { + pack1 -side top -padx {25 15} -fill x +} {260x40+25+0 300x160+0+40} test pack-2.11 {x padding and filling} { pack1 -side top -ipadx 20 -fill x } {300x40+0+0 300x160+0+40} test pack-2.12 {x padding and filling} { pack1 -side top -ipadx 5 -padx 10 -fill x } {280x40+10+0 300x160+0+40} +test pack-2.12 {x padding and filling} { + pack1 -side top -ipadx 5 -padx {5 15} -fill x +} {280x40+5+0 300x160+0+40} set pad [winfo pixels .pack 1c] test pack-2.13 {x padding and filling} { pack forget .pack.a .pack.b .pack.c .pack.d @@ -125,39 +152,66 @@ test pack-2.14 {x padding and filling} { test pack-3.1 {y padding and filling} { pack1 -side right -pady 20 } {20x40+280+80 280x200+0+0} +test pack-3.1.1 {y padding and filling} { + pack1 -side right -pady {5 35} +} {20x40+280+65 280x200+0+0} +test pack-3.1.2 {y padding and filling} { + pack1 -side right -pady {40 0} +} {20x40+280+100 280x200+0+0} test pack-3.2 {y padding and filling} { pack1 -side right -ipady 20 } {20x80+280+60 280x200+0+0} test pack-3.3 {y padding and filling} { pack1 -side right -ipady 5 -pady 10 } {20x50+280+75 280x200+0+0} +test pack-3.3.1 {y padding and filling} { + pack1 -side right -ipady 5 -pady {5 15} +} {20x50+280+70 280x200+0+0} test pack-3.4 {y padding and filling} { pack1 -side right -pady 20 -fill y } {20x160+280+20 280x200+0+0} +test pack-3.4.1 {y padding and filling} { + pack1 -side right -pady {35 5} -fill y +} {20x160+280+35 280x200+0+0} test pack-3.5 {y padding and filling} { pack1 -side right -ipady 20 -fill y } {20x200+280+0 280x200+0+0} test pack-3.6 {y padding and filling} { pack1 -side right -ipady 5 -pady 10 -fill y } {20x180+280+10 280x200+0+0} +test pack-3.6.1 {y padding and filling} { + pack1 -side right -ipady 5 -pady {0 20} -fill y +} {20x180+280+0 280x200+0+0} test pack-3.7 {y padding and filling} { pack1 -side top -pady 20 } {20x40+140+20 300x120+0+80} +test pack-3.7.1 {y padding and filling} { + pack1 -side top -pady {40 0} +} {20x40+140+40 300x120+0+80} test pack-3.8 {y padding and filling} { pack1 -side top -ipady 20 } {20x80+140+0 300x120+0+80} test pack-3.9 {y padding and filling} { pack1 -side top -ipady 5 -pady 10 } {20x50+140+10 300x130+0+70} +test pack-3.9.1 {y padding and filling} { + pack1 -side top -ipady 5 -pady {3 17} +} {20x50+140+3 300x130+0+70} test pack-3.10 {y padding and filling} { pack1 -side top -pady 20 -fill y } {20x40+140+20 300x120+0+80} +test pack-3.10.1 {y padding and filling} { + pack1 -side top -pady {39 1} -fill y +} {20x40+140+39 300x120+0+80} test pack-3.11 {y padding and filling} { pack1 -side top -ipady 20 -fill y } {20x80+140+0 300x120+0+80} test pack-3.12 {y padding and filling} { pack1 -side top -ipady 5 -pady 10 -fill y } {20x50+140+10 300x130+0+70} +test pack-3.12.1 {y padding and filling} { + pack1 -side top -ipady 5 -pady {1 19} -fill y +} {20x50+140+1 300x130+0+70} set pad [winfo pixels .pack 1c] test pack-3.13 {y padding and filling} { pack forget .pack.a .pack.b .pack.c .pack.d @@ -595,9 +649,15 @@ test pack-11.11 {info option} { test pack-11.12 {info option} { pack4 -padx 2 } 2 +test pack-11.12.1 {info option} { + pack4 -padx {2 9} +} {2 9} test pack-11.13 {info option} { pack4 -pady 3 } 3 +test pack-11.13.1 {info option} { + pack4 -pady {3 11} +} {3 11} test pack-11.14 {info option} { pack4 -side top } top @@ -670,18 +730,34 @@ test pack-12.15 {command options and errors} { pack forget .pack.a .pack.b .pack.c .pack.d list [catch {pack .pack.a -padx abc} msg] $msg } {1 {bad pad value "abc": must be positive screen distance}} +test pack-12.15.1 {command options and errors} { + pack forget .pack.a .pack.b .pack.c .pack.d + list [catch {pack .pack.a -padx {5 abc}} msg] $msg +} {1 {bad 2nd pad value "abc": must be positive screen distance}} test pack-12.16 {command options and errors} { pack forget .pack.a .pack.b .pack.c .pack.d list [catch {pack .pack.a -padx -1} msg] $msg } {1 {bad pad value "-1": must be positive screen distance}} +test pack-12.16.1 {command options and errors} { + pack forget .pack.a .pack.b .pack.c .pack.d + list [catch {pack .pack.a -padx {5 -1}} msg] $msg +} {1 {bad 2nd pad value "-1": must be positive screen distance}} test pack-12.17 {command options and errors} { pack forget .pack.a .pack.b .pack.c .pack.d list [catch {pack .pack.a -pady abc} msg] $msg } {1 {bad pad value "abc": must be positive screen distance}} +test pack-12.17.1 {command options and errors} { + pack forget .pack.a .pack.b .pack.c .pack.d + list [catch {pack .pack.a -pady {0 abc}} msg] $msg +} {1 {bad 2nd pad value "abc": must be positive screen distance}} test pack-12.18 {command options and errors} { pack forget .pack.a .pack.b .pack.c .pack.d list [catch {pack .pack.a -pady -1} msg] $msg } {1 {bad pad value "-1": must be positive screen distance}} +test pack-12.18.1 {command options and errors} { + pack forget .pack.a .pack.b .pack.c .pack.d + list [catch {pack .pack.a -pady {0 -1}} msg] $msg +} {1 {bad 2nd pad value "-1": must be positive screen distance}} test pack-12.19 {command options and errors} { pack forget .pack.a .pack.b .pack.c .pack.d list [catch {pack .pack.a -ipadx abc} msg] $msg @@ -984,16 +1060,3 @@ foreach i {pack1 pack2 pack3 pack4} { # cleanup ::tcltest::cleanupTests return - - - - - - - - - - - - - -- cgit v0.12