diff options
author | pspjuth <peter.spjuth@gmail.com> | 2004-11-07 22:00:12 (GMT) |
---|---|---|
committer | pspjuth <peter.spjuth@gmail.com> | 2004-11-07 22:00:12 (GMT) |
commit | ce2b25e17cc451455a42e252bebe6d79a041b49d (patch) | |
tree | cdce1b05d63cec843960d42689eb08dff535d7ef | |
parent | 547bf5ad9b134b9600676729e20a86e75a6115a7 (diff) | |
download | tk-ce2b25e17cc451455a42e252bebe6d79a041b49d.zip tk-ce2b25e17cc451455a42e252bebe6d79a041b49d.tar.gz tk-ce2b25e17cc451455a42e252bebe6d79a041b49d.tar.bz2 |
Made handling of ^ a bit more consistent in
corner cases. This makes ^ work without any widgets in the same
command. [Bug 962589]
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | generic/tkGrid.c | 87 | ||||
-rw-r--r-- | tests/grid.test | 39 |
3 files changed, 111 insertions, 22 deletions
@@ -1,3 +1,10 @@ +2004-11-07 Peter Spjuth <peter.spjuth@space.se> + + * tests/grid.test: + * generic/tkGrid.c: Made handling of ^ a bit more consistent in + corner cases. This makes ^ work without any widgets in the same + command. [Bug 962589] + 2004-11-07 Donal K. Fellows <donal.k.fellows@man.ac.uk> * library/demos/anilabel.tcl: Added a simple demonstration of how diff --git a/generic/tkGrid.c b/generic/tkGrid.c index cb2f310..e89e65a 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.33 2004/03/16 19:53:28 hobbs Exp $ + * RCS: @(#) $Id: tkGrid.c,v 1.34 2004/11/07 22:00:23 pspjuth Exp $ */ #include "tkInt.h" @@ -2730,13 +2730,14 @@ ConfigureSlaves(interp, tkwin, objc, objv) * make sure that there is at least one * window name. */ { - Gridder *masterPtr; + Gridder *masterPtr = NULL; Gridder *slavePtr; Tk_Window other, slave, parent, ancestor; int i, j, tmp; int length; int numWindows; int width; + int defaultRow = -1; int defaultColumn = 0; /* default column number */ int defaultColumnSpan = 1; /* default number of columns */ char *lastWindow; /* use this window to base current @@ -2765,6 +2766,20 @@ ConfigureSlaves(interp, tkwin, objc, objv) firstChar = string[0]; if (firstChar == '.') { + /* + * Check that windows are valid, and locate the first slave's + * parent window (default for -in). + */ + if (TkGetWindowFromObj(interp, tkwin, objv[i], &slave) != TCL_OK) { + return TCL_ERROR; + } + if (masterPtr == NULL) { + parent = Tk_Parent(slave); + if (parent != NULL) { + masterPtr = GetGrid(parent); + InitMasterData(masterPtr); + } + } numWindows++; continue; } @@ -2809,6 +2824,49 @@ ConfigureSlaves(interp, tkwin, objc, objv) } /* + * Go through all options looking for -in and -row, which are needed to + * be found first to handle the special case where ^ is used on a row + * without windows names, but with an -in option. + * Since all options are checked here, we do not need to handle the + * error case again later. + */ + + for (i = numWindows; i < objc; i += 2) { + if (Tcl_GetIndexFromObj(interp, objv[i], optionStrings, "option", 0, + &index) != TCL_OK) { + return TCL_ERROR; + } + if (index == CONF_IN) { + if (TkGetWindowFromObj(interp, tkwin, objv[i+1], &other) != + TCL_OK) { + return TCL_ERROR; + } + masterPtr = GetGrid(other); + InitMasterData(masterPtr); + } else if (index == CONF_ROW) { + if (Tcl_GetIntFromObj(interp, objv[i+1], &tmp) != TCL_OK + || tmp < 0) { + Tcl_ResetResult(interp); + Tcl_AppendResult(interp, "bad row value \"", + Tcl_GetString(objv[i+1]), + "\": must be a non-negative integer", (char *) NULL); + return TCL_ERROR; + } + defaultRow = tmp; + } + } + + /* If no -row is given, use the first unoccupied row of the master. */ + if (defaultRow < 0) { + if (masterPtr != NULL && masterPtr->masterDataPtr != NULL) { + SetGridSize(masterPtr); + defaultRow = masterPtr->masterDataPtr->rowEnd; + } else { + defaultRow = 0; + } + } + + /* * Iterate over all of the slave windows and short-cuts, parsing * options for each slave. It's a bit wasteful to re-parse the * options for each slave, but things get too messy if we try to @@ -2819,7 +2877,6 @@ ConfigureSlaves(interp, tkwin, objc, objv) * first window. */ - masterPtr = NULL; positionGiven = 0; for (j = 0; j < numWindows; j++) { string = Tcl_GetString(objv[j]); @@ -2873,10 +2930,8 @@ ConfigureSlaves(interp, tkwin, objc, objv) */ for (i = numWindows; i < objc; i += 2) { - if (Tcl_GetIndexFromObj(interp, objv[i], optionStrings, "option", 0, - &index) != TCL_OK) { - return TCL_ERROR; - } + Tcl_GetIndexFromObj(interp, objv[i], optionStrings, "option", 0, + &index); if (index == CONF_COLUMN) { if (Tcl_GetIntFromObj(interp, objv[i+1], &tmp) != TCL_OK || tmp < 0) { @@ -2948,7 +3003,7 @@ ConfigureSlaves(interp, tkwin, objc, objv) if (Tcl_GetIntFromObj(interp, objv[i+1], &tmp) != TCL_OK || tmp < 0) { Tcl_ResetResult(interp); - Tcl_AppendResult(interp, "bad grid value \"", + Tcl_AppendResult(interp, "bad row value \"", Tcl_GetString(objv[i+1]), "\": must be a non-negative integer", (char *)NULL); return TCL_ERROR; @@ -3063,11 +3118,7 @@ ConfigureSlaves(interp, tkwin, objc, objv) } slavePtr->numCols += defaultColumnSpan - 1; if (slavePtr->row == -1) { - if (masterPtr->masterDataPtr == NULL) { - slavePtr->row = 0; - } else { - slavePtr->row = masterPtr->masterDataPtr->rowEnd; - } + slavePtr->row = defaultRow; } defaultColumn += slavePtr->numCols; defaultColumnSpan = 1; @@ -3127,12 +3178,7 @@ ConfigureSlaves(interp, tkwin, objc, objv) */ if (lastWindow == NULL) { - if (masterPtr->masterDataPtr != NULL) { - SetGridSize(masterPtr); - lastRow = masterPtr->masterDataPtr->rowEnd - 2; - } else { - lastRow = 0; - } + lastRow = defaultRow - 1; lastColumn = 0; } else { other = Tk_NameToWindow(interp, lastWindow, tkwin); @@ -3143,7 +3189,8 @@ ConfigureSlaves(interp, tkwin, objc, objv) lastColumn += numSkip; - for (match=0, slavePtr = masterPtr->slavePtr; slavePtr != NULL; + match = 0; + for (slavePtr = masterPtr->slavePtr; slavePtr != NULL; slavePtr = slavePtr->nextPtr) { if (slavePtr->column == lastColumn diff --git a/tests/grid.test b/tests/grid.test index d94b762..fca981c 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.24 2004/02/18 21:25:42 pspjuth Exp $ +# RCS: @(#) $Id: grid.test,v 1.25 2004/11/07 22:00:12 pspjuth Exp $ package require tcltest 2.1 eval tcltest::configure $argv @@ -164,7 +164,7 @@ grid_reset 3.2 test grid-3.3 {configure: basic argument checking} { button .b list [catch {grid .b -row -1} msg] $msg -} {1 {bad grid value "-1": must be a non-negative integer}} +} {1 {bad row value "-1": must be a non-negative integer}} grid_reset 3.3 test grid-3.4 {configure: basic argument checking} { @@ -952,6 +952,41 @@ test grid-11.17 {default widget placement} { } {100 50 100} grid_reset 11.17 +test grid-11.18 {default widget placement} { + foreach l {a b c d e} { + frame .$l -width 50 -height 50 + } + grid .a .b .c .d -sticky news + grid ^ ^ ^ x -in . ;# ^ and no child should work with -in. + grid rowconfigure . {0 1} -uniform a + update + set res "" + lappend res [winfo height .a] + lappend res [winfo height .b] + lappend res [winfo height .c] + lappend res [winfo height .d] +} {100 100 100 50} +grid_reset 11.18 + +test grid-11.19 {default widget placement} { + foreach l {a b c d e} { + frame .$l -width 50 -height 50 + } + grid .a .b -sticky news + grid .c .d -sticky news + grid ^ -in . -row 2 + grid x ^ -in . -row 1 + + grid rowconfigure . {0 1 2} -uniform a + update + set res "" + lappend res [winfo height .a] + lappend res [winfo height .b] + lappend res [winfo height .c] + lappend res [winfo height .d] +} {50 100 100 50} +grid_reset 11.19 + test grid-12.1 {-sticky} { catch {unset data} frame .f -width 200 -height 100 -highlightthickness 0 -bg red |