(i) scrollbar.test scrollbar-3.42

From: ania.pawelczyk
Date: Jul 04, 2008 @ 02:54am UTC

Problem:
test scrollbar-3.42 fails under windows.
Idea:
test scrollbar-3.42
  1. line 288 place configure .t.s -width [expr [winfo reqwidth .t.s] – 4]
    place configure .t.s -width [expr {([winfo reqwidth .t.s] – 4) / 2}]

    Explenation
    test:
    #line 281
    toplevel .t -width 250 -height 100
    wm geom .t +0+0
    scrollbar .t.s -orient horizontal -borderwidth 2
    place .t.s -width 201
    update
    if {[testConstraint testmetrics]} {
    place configure .t.s -width [expr 2+1]
    } else {
    puts [winfo reqwidth .t.s]
    place configure .t.s -width [expr {([winfo reqwidth .t.s] – 4)/2}]
    }
    update
    test scrollbar-3.42 {ScrollbarWidgetCmd procedure, "fraction" option} {
    .t.s fraction 100 0
    } {0}

Although, according to man page the result of a test should be 1,
pathName fraction x y
Returns a real number between 0 and 1 indicating where the point given by x and y lies in the trough area of the scrollbar. The value 0 corresponds to the top or left of the trough, the value 1 corresponds to the bottom or right, 0.5 corresponds to the middle, and so on. X and y must be pixel coordinates relative to the scrollbar widget. If x and y refer to a point outside the trough, the closest point in the trough is used. )

nevertheless, according to tkScrollbar.c that differs:
/
tkScrollbar.c/
// line 329
} else if ((c 'f') && (strncmp(argv[1], "fraction", length) 0)) {
int x, y, pos, length;
[...]
if (scrollPtr->vertical) {
pos = y – (scrollPtr->arrowLength + scrollPtr->inset);
length = Tk_Height(scrollPtr->tkwin)
– 1 – 2
(scrollPtr->arrowLength + scrollPtr->inset);
} else {
pos = x – (scrollPtr->arrowLength + scrollPtr->inset);
length = Tk_Width(scrollPtr->tkwin)
– 1- 2;
}
if (length == 0) {
fraction = 0.0;
} else {
fraction = ((double) pos / (double) length);
}
if (fraction < 0) {
fraction = 0;
} else if (fraction > 1.0) {
fraction = 1.0;
}

The goal of the test case is following situation:
pos >= 0; length <= 0
(as place configure .t.s -width [expr [winfo reqwidth .t.s] – 4] aims at creating the widget which length is smaller than requested by window’s geometry manager).

However, It’s not considered that the [expr [winfo reqwidth .t.s] – 4] (where 4 is for scrollbar .t.s borderwidth 2) value is greater than
1+ 2
(scrollPtr>arrowLength + scrollPtr->inset);
(in contrary to Unix)

/* tkUnixScrlbr.c /
// line 339
if (scrollPtr->vertical) {
Tk_GeometryRequest(scrollPtr->tkwin,
scrollPtr->width + 2
scrollPtr->inset,
2);
} else {
Tk_GeometryRequest(scrollPtr->tkwin,
2
(scrollPtr->arrowLength + scrollPtr->borderWidth+ scrollPtr->inset),
scrollPtr->width + 2scrollPtr->inset);
}
Tk_SetInternalBorder(scrollPtr->tkwin, scrollPtr->inset);

/ tkWinScrlbr.c /
// line 464
if (scrollPtr->vertical) {
Tk_GeometryRequest(scrollPtr->tkwin,
scrollPtr->width,
2
scrollPtr->arrowLength + minThumbSize);
} else {
Tk_GeometryRequest(scrollPtr->tkwin,
2*scrollPtr->arrowLength + minThumbSize,
scrollPtr->width);
}
Tk_SetInternalBorder(scrollPtr->tkwin, 0);
minThumbSize = hThumb; hThumb = GetSystemMetrics(SM_CXHTHUMB);
GetSystemMetrics – This function retrieves the dimensions of Windows display elements and system configuration settings.
SM_CXHTHUMB – For retrieving the width of the thumb box in a horizontal scroll bar, in pixels.

In a result even if we set
place configure .t.s -width [expr [winfo reqwidth .t.s] – 4]
tkScrollbar.c’s variable length may still be > 0 under Windows

I suggest p.e. dividing
place configure .t.s -width [expr {([winfo reqwidth .t.s] – 4) / 2}]

 
Reply
-->