Tk Source Code

View Ticket
Login
Ticket UUID: efbedd5ff5864ea56310fb68b72667095c0e5dec
Title: Aqua: bugs for compound non-Ttk button-like widgets
Type: Bug Version: core-8-6-branch
Submitter: chrstphrchvz Created on: 2020-03-30 05:46:53
Subsystem: 03. [*button] and [label] Assigned To: kevin_walzer
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2020-04-03 12:24:37
Resolution: Accepted Closed By: kevin_walzer
    Closed on: 2020-04-03 12:24:37
Description:

Bug 1:

On X11 and Windows, setting non-zero -width and -height controls the preferred dimensions of the widget. But on Aqua as of [ef130fefac] (between Tk 8.6.3 and 8.6.4), -width and -height are currently ignored for compound non-Ttk button-like widgets (label, button, checkbutton, and radiobutton): the widgets always use minimum automatic dimensions based on the size of the image (or bitmap) and text (if any).

The radio.tcl widget demo specifically expects to be able to create a compound label (.radio.right.l), get its maximum automatic width and height that result when setting -compound to left and top, and then combine them so that the width and height do not change when -compound changes. On Aqua, at least the height changes:

More recent changes (or possibly bugs) in geometry/redrawing behavior can cause stale drawing artifacts when -compound changes:

A simplified example (the label will not be 100x100, and clicking it will change its dimensions):

pack [label .l -background green -foreground white -bitmap questhead \
    -compound top -text Text -width 100 -height 100]
bind .l <1> {.l configure -compound left}
if {[tk windowingsystem] eq "aqua"} {
    bind .l <2> {.l configure -compound top}
} else {
    bind .l <3> {.l configure -compound top}
}


I believe this issue was introduced when these lines were removed from TkpComputeButtonGeometry() (near line 350 of TkMacOSXButton.c):

	if (butPtr->width > 0) {
	    width = butPtr->width;
	}
	if (butPtr->height > 0) {
	    height = butPtr->height;
	}

Either duplicating equivalent statements (plus handling for butPtr->type == TYPE_BUTTON) from the image-only into the image-and-text case, or making the image-and-text case part of a larger has-image case (which is what the attached patch does), appears to fix the issue.

Bug 2:

On X11 and Windows, when a non-Ttk button-like widget has both image (or bitmap) and text, setting -compound to none behaves as if there is only an image, and no text is shown. On Aqua (also as of [ef130fefac]) the widget may initially display correctly, but changing -compound away from and then back to none will not display correctly: the image will not be perfectly centered, and any text not obscured by the image is visible.

pack [label .l -background darkBlue -foreground white -bitmap questhead -compound none -text Text -width 100 -height 100]
bind .l <1> {.l configure -compound left}
if {[tk windowingsystem] eq "aqua"} {
    bind .l <2> {.l configure -compound none}
} else {
    bind .l <3> {.l configure -compound none}
}


The faulty appearance is because in DrawButtonImageAndText(), the condition for the case of drawing text and image was changed from

if (butPtr->compound != COMPOUND_NONE && haveImage && haveText) {
to
if (haveImage && haveText) {
but unlike in TkpComputeButtonGeometry(), there is nothing in DrawButtonImageAndText() that checks for butPtr->compound != COMPOUND_NONE before setting haveText = 1.

The widget looks correct initially because butPtr->textWidth and butPtr->textHeight are 0 when the widget is created, which DrawButtonImageAndText() interprets as there not being text. textWidth and textHeight only become non-zero when -compound is changed away from none, but are not zeroed when -compound is changed back to none, which DrawButtonImageAndText() then interprets as there being text. Apparently, textWidth and textHeight are supposed to be ignored when -compound is none.

The attached patch restores the butPtr->compound != COMPOUND_NONE check, but maybe there is a better approach.

I am uncertain whether other similar issues remain unaddressed or regressions are introduced. These The first issue seems simple enough to have an automated test for, but I am not familiar with Tk's test suite.

User Comments: kevin_walzer added on 2020-04-03 12:24:37:
Patch committed to trunk and core-8-6--branch. Thank you for the patch, Christopher.

kevin_walzer added on 2020-03-31 13:10:19:
The macbuttonfix branch includes Christopher's patch. It corrects the behavior he has diagnosed. Please test the branch and if there are no objections, I will commit in a day or so.

chrstphrchvz added on 2020-03-30 18:46:47:

I did notice that some intervening commits from about a year ago did slightly affect the appearance of these issues, but understanding that some of those changes were reversions and also trying to find when it began to diverge from the X11 code (tkUnixButton.c) I went looking further back.

I also notice that the patch I posted for [06d8246baf] eliminates the stale drawing artifacts the first issue exhibits.

I don't know of any way to test appearances, however.

Sorry, I meant just for the first issue. The second issue indeed is probably beyond what Tk can verify programmatically.


marc_culler (claiming to be Marc Culler) added on 2020-03-30 13:07:35:
Kevin, the commit to which Christopher refers was from 2015.  I think these were
errors that I made while trying to reorganize confusing code that I didn't fully
understand. The patch looks good to me.  Many thanks, Christoper!

It might be possible to add some regression tests that check sizes of compound
buttons.  I don't know of any way to test appearances, however.

kevin_walzer added on 2020-03-30 12:18:59:
Christopher, thank you for your thorough documentation of this bug, and your detective work in clarifying how it was introduced and for proposing a patch. 

We were doing a lot of work on the button code in the last year or so - Marc, do you recall what led to these changes? Based on Christopher's work, it seems safe to implement his patch, but I am also not certain of the potential side effects. If you don't recall any specific issues, I will be glad to test the patch in a branch, and then merge if no objections arise.

Attachments: