Tk Source Code

View Ticket
Login
Ticket UUID: 8229232472e9f94281919ab55b178286d5ad5627
Title: Cascade menu entry indicator wrong colour on Unix
Type: Bug Version: 8.6.8
Submitter: cjmcdonald Created on: 2018-09-21 16:22:25
Subsystem: 12. Unix Menus Assigned To: fvogel
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2018-09-30 20:29:35
Resolution: Fixed Closed By: cjmcdonald
    Closed on: 2018-09-30 20:29:35
Description:

The cascade menu entry type contains a small arrow indicator, to indicate that a sub-menu may be invoked. On Unix the colour of the arrow indicator is always taken from the menu -activebackground colour, even if the entry is not active (i.e. not under the mouse).

This is not too noticable for a default -activebackground colour which is just slightly lighter than the normal -background. But to match some Linux themes we want a different -activebackground, e.g.

    option add *Menu.activeBackground #86abd9
    option add *Menu.activeForeground #ffffff

then the cascade indicator is clearly the wrong colour for an non-active entry, see the "Open Previous" entry in the attached indicator-tk8.6.8.png image.

The attached patch is for the tk8.6.8 version of unix/tkUnixMenu.c.

If fixes the problem so that the cascade indicator is drawn in the normal -background colour (see indicator-patched.png), unless the entry is actually active under the mouse in which case it is drawn with -activebackground (see indicator-active-patched.png).

User Comments: cjmcdonald added on 2018-09-30 20:29:35:
Thanks François, your prompt and thorough attention to Tk tickets is an encouragement to make reports

fvogel added on 2018-09-30 19:00:32:
Merged to core-8-6-branch and trunk.

Thanks again for the report and for the patch!

fvogel added on 2018-09-23 13:52:00:

Attached two snapshots - before and after the patch, made with the following test script on Linux Debian 8:

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"
.m.f add cascade -label "Item 2"
.m.f add cascade -label "Item 3"
. configure -menu .m
.m.f configure -activebackground #86abd9 -activeforeground #ffffff


fvogel added on 2018-09-22 13:13:06:

Analysis of the call sequence is as follows:

  1. In the entire code base there is a single call to TkpDrawMenuEntry (in DisplayMenu). This call has a hardcoded "1" as last parameter (drawingParameters on Windows, and drawArrow on Linux and Mac).
  2. On Windows, TkpDrawMenuEntry calls DrawMenuEntryAccelerator and DrawMenuEntryArrow, the latter is drawing the arrow if (drawingParameters & DRAW_MENU_ENTRY_ARROW) which is always true since DRAW_MENU_ENTRY_ARROW is defined to be 1 and drawingParameters received the hardcoded "1" mentioned above.

  3. On Linux, TkpDrawMenuEntry calls DrawMenuEntryAccelerator which draws the arrow if its last parameter drawArrow is true, which is always the case (the hardcoded "1" mentioned above).

  4. On macOS, TkpDrawMenuEntry is an empty function (native rendering is used).

Given all this, it turns out that the signature of DrawMenuEntryAccelerator does not have to be changed: the arrow is not drawn by this function but in DrawMenuEntryArrow, and the bgBorder would anyway not be used. Adding bgBorder to DrawMenuEntryArrow on Windows neither does seems necessary to me since a native Windows system bitmap is drawn there (DrawWindowsSystemBitmap, with a graphics context gc adapted according to whether the menu entry is disabled or active or a normal entry). I have however changed a bit the comments about the drawArrow parameter, see [6c01b18ee4].


fvogel added on 2018-09-22 07:10:54:

Thanks for the report, and even more thanks for the patch!

I have committed your patch [091bec9313] in a bugfix branch.

The patch changes the signature of DrawMenuEntryAccelerator() on Linux. For the sake of uniformity I was wondering whether this signature change should be propagated to Windows, even if bgBorder/activeBorder are not used in this function on Windows (and the function itself does not exists at all on Mac).

Then I discovered that even before your patch the signature of DrawMenuEntryAccelerator() is not the same on Windows and on Linux, there is an additional parameter drawArrow on Linux, but with a comment in TkpDrawMenuEntry() saying that it applies only to Windows! I'll try to understand this a bit more.


Attachments: