diff options
-rw-r--r-- | tests/button.test | 32 | ||||
-rw-r--r-- | win/tkWinButton.c | 140 |
2 files changed, 110 insertions, 62 deletions
diff --git a/tests/button.test b/tests/button.test index d7f9028..794c7b4 100644 --- a/tests/button.test +++ b/tests/button.test @@ -7,7 +7,7 @@ # Copyright (c) 1998-1999 by Scriptics Corporation. # All rights reserved. # -# RCS: @(#) $Id: button.test,v 1.12 2002/07/14 05:48:46 dgp Exp $ +# RCS: @(#) $Id: button.test,v 1.13 2002/09/02 23:32:35 hobbs Exp $ package require tcltest 2.1 namespace import -force tcltest::configure @@ -775,6 +775,36 @@ test button-13.1 {button widget vs hidden commands} { deleteWindows +test button-14.1 {size behaviouor} { + set res {} + foreach class {label button radiobutton checkbutton} { + eval destroy [winfo children .] + + $class .a -text Hej + $class .b -text Hej -width 10 -height 1 + $class .c -text "" -width 10 -height 1 + + for {set t 0} {$t < 2} {incr t} { + set res2 {} + # With -width, width should not be affected by text change + lappend res2 [expr {[winfo reqwidth .b] == [winfo reqwidth .c]}] + # With -height, height should not be affected by text change + lappend res2 [expr {[winfo reqheight .b] == [winfo reqheight .c]}] + # A one line text should be as high as -height 1 + lappend res2 [expr {[winfo reqheight .a] == [winfo reqheight .b]}] + lappend res $res2 + + # Do the second round with another font + .a configure -font "Arial 20" + .b configure -font "Arial 20" + .c configure -font "Arial 20" + } + } + set res +} {{1 1 1} {1 1 1} {1 1 1} {1 1 1} {1 1 1} {1 1 1} {1 1 1} {1 1 1}} + +deleteWindows + option clear # cleanup diff --git a/win/tkWinButton.c b/win/tkWinButton.c index 4ca5054..e004a3c 100644 --- a/win/tkWinButton.c +++ b/win/tkWinButton.c @@ -9,7 +9,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkWinButton.c,v 1.18 2002/08/28 01:08:06 drh Exp $ + * RCS: @(#) $Id: tkWinButton.c,v 1.19 2002/09/02 23:32:35 hobbs Exp $ */ #define OEMRESOURCE @@ -842,66 +842,66 @@ TkpComputeButtonGeometry(butPtr) /* * Set width and height by button type; See User Experience table, p449. + * These are text-based measurements, even if the text is "". + * If there is an image, height will get set again later. */ switch (butPtr->type) { case TYPE_BUTTON: { - if (haveText) { - /* - * First compute the minimum width of the button in - * characters. MWUE says that the button should be - * 50 DLUs. We allow 6 DLUs padding left and right. - * (There is no rule but this is consistent with the - * fact that button text is 8 DLUs high and buttons - * are 14 DLUs high.) - * - * The width is specified in characters. A character - * is, by definition, 4 DLUs wide. 11 char * 4 DLU - * is 44 DLU + 6 DLU padding = 50 DLU. Therefore, - * width = -11 -> MWUE compliant buttons. - */ - if (butPtr->width < 0) { - /* Min width in characters */ - minWidth = -(butPtr->width); - /* Allow for characters */ - width = avgWidth * minWidth; - /* Add for padding */ - width += (int)(0.5 + (6 * hDLU)); - } - - /* - * If shrink-wrapping was requested (width = 0) or - * if the text is wider than the default button width, - * adjust the button width up to suit. - */ - if (butPtr->width == 0 - || (txtWidth + (int)(0.5 + (6 * hDLU)) > width)) { - width = txtWidth + (int)(0.5 + (6 * hDLU)); - } + /* + * First compute the minimum width of the button in + * characters. MWUE says that the button should be + * 50 DLUs. We allow 6 DLUs padding left and right. + * (There is no rule but this is consistent with the + * fact that button text is 8 DLUs high and buttons + * are 14 DLUs high.) + * + * The width is specified in characters. A character + * is, by definition, 4 DLUs wide. 11 char * 4 DLU + * is 44 DLU + 6 DLU padding = 50 DLU. Therefore, + * width = -11 -> MWUE compliant buttons. + */ + if (butPtr->width < 0) { + /* Min width in characters */ + minWidth = -(butPtr->width); + /* Allow for characters */ + width = avgWidth * minWidth; + /* Add for padding */ + width += (int)(0.5 + (6 * hDLU)); + } - /* - * The User Experience says 14 DLUs. Since text is, by - * definition, 8 DLU/line, this allows for multi-line text - * while working perfectly for single-line text. - */ - height = txtHeight + (int)(0.5 + (6 * vDLU)); - - /* - * The above includes 6 DLUs of padding which should include - * defaults of 1 pixel of highlightwidth, 2 pixels of - * borderwidth, 1 pixel of padding and 1 pixel of extra inset - * on each side. Those will be added later so reduce width - * and height now to compensate. - */ - width -= 10; - height -= 10; - - /* - * Extra inset for the focus ring. - */ - butPtr->inset += 1; - } - break; - } + /* + * If shrink-wrapping was requested (width = 0) or + * if the text is wider than the default button width, + * adjust the button width up to suit. + */ + if (butPtr->width == 0 + || (txtWidth + (int)(0.5 + (6 * hDLU)) > width)) { + width = txtWidth + (int)(0.5 + (6 * hDLU)); + } + + /* + * The User Experience says 14 DLUs. Since text is, by + * definition, 8 DLU/line, this allows for multi-line text + * while working perfectly for single-line text. + */ + height = txtHeight + (int)(0.5 + (6 * vDLU)); + + /* + * The above includes 6 DLUs of padding which should include + * defaults of 1 pixel of highlightwidth, 2 pixels of + * borderwidth, 1 pixel of padding and 1 pixel of extra inset + * on each side. Those will be added later so reduce width + * and height now to compensate. + */ + width -= 10; + height -= 10; + + /* + * Extra inset for the focus ring. + */ + butPtr->inset += 1; + break; + } case TYPE_LABEL: { /* @@ -918,8 +918,9 @@ TkpComputeButtonGeometry(butPtr) if (txtHeight) { height = txtHeight; } else { - /* If there's no text, we want the height to be one linespace */ - /* WUZ - and no image? */ + /* + * If there's no text, we want the height to be one linespace. + */ height = fm.linespace; } break; @@ -1044,12 +1045,29 @@ TkpComputeButtonGeometry(butPtr) } /* - * butPtr->height is in lines of text. We need to allow for + * butPtr->height is in lines of text. We need to allow for * that many lines on the face, not in the over-all button * height. */ if (butPtr->height > 0) { height = butPtr->height * fm.linespace; + + /* + * Make the same adjustments as above to get same height for + * e.g. a one line text with -height 0 or 1. [Bug #565485] + */ + + switch (butPtr->type) { + case TYPE_BUTTON: { + height += (int)(0.5 + (6 * vDLU)) - 10; + break; + } + case TYPE_RADIO_BUTTON: + case TYPE_CHECK_BUTTON: { + height += (int)(0.5 + (2.0 * vDLU)) - 4; + break; + } + } } width += 2 * butPtr->padX; @@ -1058,7 +1076,7 @@ TkpComputeButtonGeometry(butPtr) /* Fix up width and height for indicator sizing and spacing */ if (butPtr->type == TYPE_RADIO_BUTTON - || butPtr->type == TYPE_CHECK_BUTTON) { + || butPtr->type == TYPE_CHECK_BUTTON) { if (butPtr->indicatorOn) { butPtr->indicatorDiameter = tsdPtr->boxHeight; |