summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--generic/tkGrid.c44
-rw-r--r--tests/grid.test27
3 files changed, 53 insertions, 24 deletions
diff --git a/ChangeLog b/ChangeLog
index bb0095a..062a4e2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2004-02-18 Peter Spjuth <peter.spjuth@space.se>
+
+ * tests/grid.test:
+ * generic/tkGrid.c: Fixed a bug in grid geometry calculations for
+ a shrinking grid. [Bug 899246]
+
2004-02-17 Jeff Hobbs <jeffh@ActiveState.com>
* generic/tkBind.c (HandleEventGenerate): only modify root[xy]
diff --git a/generic/tkGrid.c b/generic/tkGrid.c
index 62b064f..2c90d2b 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.31 2004/01/13 02:06:00 davygrvy Exp $
+ * RCS: @(#) $Id: tkGrid.c,v 1.32 2004/02/18 21:25:41 pspjuth Exp $
*/
#include "tkInt.h"
@@ -1411,9 +1411,9 @@ AdjustOffsets(size, slots, slotPtr)
{
register int slot; /* Current slot. */
int diff; /* Extra pixels needed to add to the layout. */
- int totalWeight = 0; /* Sum of the weights for all the slots. */
- int weight = 0; /* Sum of the weights so far. */
- int minSize = 0; /* Minimum possible layout size. */
+ int totalWeight; /* Sum of the weights for all the slots. */
+ int weight; /* Sum of the weights so far. */
+ int minSize; /* Minimum possible layout size. */
int newDiff; /* The most pixels that can be added on
* the current pass. */
@@ -1431,11 +1431,12 @@ AdjustOffsets(size, slots, slotPtr)
* If all the weights are zero, there is nothing more to do.
*/
- for (slot=0; slot < slots; slot++) {
+ totalWeight = 0;
+ for (slot = 0; slot < slots; slot++) {
totalWeight += slotPtr[slot].weight;
}
- if (totalWeight == 0 ) {
+ if (totalWeight == 0) {
return slotPtr[slots-1].offset;
}
@@ -1445,7 +1446,8 @@ AdjustOffsets(size, slots, slotPtr)
*/
if (diff > 0) {
- for (weight=slot=0; slot < slots; slot++) {
+ weight = 0;
+ for (slot = 0; slot < slots; slot++) {
weight += slotPtr[slot].weight;
slotPtr[slot].offset += diff * weight / totalWeight;
}
@@ -1455,16 +1457,19 @@ AdjustOffsets(size, slots, slotPtr)
/*
* The layout must shrink below its requested size. Compute the
* minimum possible size by looking at the slot minSizes.
+ * Store each slot's minimum size in temp.
*/
- for (slot=0; slot < slots; slot++) {
+ minSize = 0;
+ for (slot = 0; slot < slots; slot++) {
if (slotPtr[slot].weight > 0) {
- minSize += slotPtr[slot].minSize;
+ slotPtr[slot].temp = slotPtr[slot].minSize;
} else if (slot > 0) {
- minSize += slotPtr[slot].offset - slotPtr[slot-1].offset;
+ slotPtr[slot].temp = slotPtr[slot].offset - slotPtr[slot-1].offset;
} else {
- minSize += slotPtr[slot].offset;
+ slotPtr[slot].temp = slotPtr[slot].offset;
}
+ minSize += slotPtr[slot].temp;
}
/*
@@ -1474,14 +1479,8 @@ AdjustOffsets(size, slots, slotPtr)
if (size <= minSize) {
int offset = 0;
- for (slot=0; slot < slots; slot++) {
- if (slotPtr[slot].weight > 0) {
- offset += slotPtr[slot].minSize;
- } else if (slot > 0) {
- offset += slotPtr[slot].offset - slotPtr[slot-1].offset;
- } else {
- offset += slotPtr[slot].offset;
- }
+ for (slot = 0; slot < slots; slot++) {
+ offset += slotPtr[slot].temp;
slotPtr[slot].offset = offset;
}
return minSize;
@@ -1493,12 +1492,12 @@ AdjustOffsets(size, slots, slotPtr)
*/
while (diff < 0) {
-
/*
* Find the total weight for the shrinkable slots.
*/
- for (totalWeight=slot=0; slot < slots; slot++) {
+ totalWeight = 0;
+ for (slot = 0; slot < slots; slot++) {
int current = (slot == 0) ? slotPtr[slot].offset :
slotPtr[slot].offset - slotPtr[slot-1].offset;
if (current > slotPtr[slot].minSize) {
@@ -1537,7 +1536,8 @@ AdjustOffsets(size, slots, slotPtr)
* Now distribute the space.
*/
- for (weight=slot=0; slot < slots; slot++) {
+ weight = 0;
+ for (slot = 0; slot < slots; slot++) {
weight += slotPtr[slot].temp;
slotPtr[slot].offset += newDiff * weight / totalWeight;
}
diff --git a/tests/grid.test b/tests/grid.test
index 187f061..d94b762 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.23 2004/01/09 22:23:26 pspjuth Exp $
+# RCS: @(#) $Id: grid.test,v 1.24 2004/02/18 21:25:42 pspjuth Exp $
package require tcltest 2.1
eval tcltest::configure $argv
@@ -1375,7 +1375,7 @@ test grid-16.7 {layout weights (shrinking at minsize)} {
lappend a [winfo width .$i]-[winfo height .$i]-[winfo ismapped .$i]
}
set a
-} {100-75-1 1-1-0 200-150-1}
+} {100-75-1 1-1-0 100-75-1}
grid_reset 16.7
test grid-16.8 {layout internal constraints} {
@@ -1602,6 +1602,29 @@ test grid-16.16 {layout span} {
[list 25 39 29 57 0] [list 30 34 22 64 0]]
grid_reset 16.16
+test grid-16.17 {layout weights (shrinking at minsize)} {
+ foreach i {0 1 2 3} {
+ frame .$i -bg gray -width 100 -height 75 -bd 2 -relief ridge
+ grid .$i -row $i -column $i -sticky nswe
+ }
+ grid propagate . 0
+ grid columnconfigure . {0 1} -weight 1 -minsize 0
+ grid rowconfigure . {0 1} -weight 1 -minsize 0
+ set a ""
+ . configure -width 250 -height 200
+ update
+ foreach i {0 1 2 3} {
+ lappend a [winfo width .$i]-[winfo height .$i]-[winfo ismapped .$i]
+ }
+ . configure -width 150 -height 100
+ update
+ foreach i {0 1 2 3} {
+ lappend a [winfo width .$i]-[winfo height .$i]-[winfo ismapped .$i]
+ }
+ set a
+} {25-25-1 25-25-1 100-75-1 100-75-1 25-25-0 25-25-0 100-75-1 100-75-1}
+grid_reset 16.17
+
test grid-17.1 {forget and pending idle handlers} {
# This test is intended to detect a crash caused by a failure to remove
# pending idle handlers when grid forget is invoked.