Tk Source Code

View Ticket
Login
Ticket UUID: 9658bc800ca8193dba1035ca245179a5cb564052
Title: Right border calculated wrong in Tk menu if borderwidth != activeborderwidth
Type: Bug Version: 8.6.8
Submitter: anonymous Created on: 2018-09-18 11:20:00
Subsystem: 10. Generic Menus Assigned To: fvogel
Priority: 5 Medium Severity: Cosmetic
Status: Closed Last Modified: 2018-10-06 09:26:21
Resolution: Fixed Closed By: fvogel
    Closed on: 2018-10-06 09:26:21
Description:
On Unix I observe that the right border of menus is too wide or too narrow if activeborderwidth differs from borderwidth. With the appended patch I get the correct spacing.

Note that I have tested this patch only with simple menus without accelerators or indicators. Also, in ticket 43b596451ec6b59359145ff32e689a2eec70bb85, there is mentioned that the problem is not observable on Windows. So the bug may be in tkUnixMenu.c.

--- generic/tkMenuDraw.c
+++ generic/tkMenuDraw.c
@@ -673,7 +673,7 @@
 	} else {
 	    if (mePtr->entryFlags & ENTRY_LAST_COLUMN) {
 		width = Tk_Width(menuPtr->tkwin) - mePtr->x
-			- activeBorderWidth;
+			- borderWidth;
 	    } else {
 		width = mePtr->width + borderWidth;
 	    }
User Comments: fvogel added on 2018-10-06 09:26:21:
Merged to core-8-6-branch and trunk.

fvogel added on 2018-09-29 09:57:04:

Same issue as for the tearoff entry now fixed for the separator entry on Linux. It was already OK on Win, and on macOS this is handled by the OS. See [f8495992ed].


fvogel added on 2018-09-29 09:38:16:

Test script that allowed to generate the tearoff entry snapshots:

package require Tk
menu .m
menu .m.f -tearoff 1 -background red
.m add cascade -label File -menu .m.f
.m.f add command -label "Item 1"
.m.f add command -label "Item 2" -columnbreak 1
. configure -menu .m
.m.f configure -activeborderwidth 40 -borderwidth 25  ; # look at the result


fvogel added on 2018-09-29 09:34:29:

Also fixed the drawing of the tearoff entry, which was visibly wrong with large -activeborderwidth, see snapshots "Tearoff entry drawing incorrect.png" and its fixed version "Tearoff entry drawing correct.png"

This is [dff5745bca].


fvogel added on 2018-09-29 08:11:00:

Again more fixes in [9dcde6779c]. As incredible as it seems, calculation of the geometry of the menu widget was wrong for more than 20 years, on all platforms, and this was hidden behind questionable adjustments of the menu entries widths at display time.

The problem however was only obvious when -activeborderwidth and -borderwidth were quite different, and when there was at least one columnbreak menu entry. To get an idea of what was wrong, see attachment "Wrong menu geometry.png" taken on Windows and generated by the test script below.


fvogel added on 2018-09-28 22:19:31:

It turns out there were more issues than the original patch proposed to fix. I have committed [1d847471e4] to fix them.

See also the two attachments to the present ticket, "Win-tornoff - Before 1d847471e4.png" and "Win-tornoff - At patch 1d847471e4.png". These snapshots were created on Windows using the following test script:

package require Tk
menu .m
menu .m.f -tearoff 1 -background red
.m add cascade -label File -menu .m.f
.m.f add command -label "Item 0"
.m.f add command -label "Item 1" -accelerator "Ctrl-a" -bitmap hourglass -compound left
.m.f add command -accelerator "Ctrl-a" -bitmap hourglass
.m.f add cascade -label "Item 3"
.m.f add cascade -label "Item 4" -columnbreak 1
.m.f add cascade -label "Item 5"
.m.f add cascade -label "Item 6"
.m.f add cascade -label "Item 7"
.m.f add command -label "This is another item, item 9" -accelerator "Ctrl-a" -bitmap hourglass -compound left
. configure -menu .m
.m.f invoke 0
.m.f configure -activeborderwidth 20 -borderwidth 8  ; # look at the result


fvogel added on 2018-09-26 06:29:51:

Thanks.

Patch committed in branch bug-9658bc800c for easy testing.


anonymous added on 2018-09-23 19:10:39:
I have added the screenshots for your sample script. Those should clearly show the issue, at least on Unix platforms.

fvogel added on 2018-09-23 14:20:17:

Does the following script show the issue and if so what is it exactly (show snapshots please)?

package require Tk
menu .m
menu .m.f
.m add cascade -label File -menu .m.f
.m.f add command -label "Item 0"
.m.f add command -label "Item 1" -accelerator "Ctrl-a" -bitmap hourglass -compound left
.m.f add command -accelerator "Ctrl-a" -bitmap hourglass
.m.f add cascade -label "Item 3"
. configure -menu .m
.m.f configure -activeborderwidth 20 -borderwidth 8  ; # look at the result

.m.f configure -activeborderwidth 8 -borderwidth 20  ; # look at the result


fvogel added on 2018-09-23 14:09:05:
Thanks for the report and for the patch.

For the sake of clarity regarding what we're chasing here, could you please post a demo script triggering the problem, and two snapshots the first one clearly showing the issue, and the second one demonstrating how it gets resolved by your patch? Thanks!

Attachments: