Cannot identify the Menubar button clicked under Mac OS

Richard Gaskin ambassador at fourthworld.com
Tue Feb 25 11:57:53 EST 2020


Henry Lowe wrote:

 > The Livecode Lesson 'Update a menu with a list of open windows'
 > recommends placing a mousedown handler in the script of the Menubar
 > group to determine which menu was clicked on:
 >
 > 
http://lessons.livecode.com/m/2592/l/126566-update-a-menu-with-a-list-of-open-windows
 >
 > The suggested code is:
 >
 > on mouseDown
 > 	if the short name of the target is "Window" then
 >
 > However under Mac OS, using LC 9.6.0 (dp2), 'the short name of the
 > target' actually returns the name of the Menubar group not the menu
 > that was clicked.  This appears to be a longstanding bug, first
 > reported in 2007:
 >
 > https://quality.livecode.com/show_bug.cgi?id=5142
 >
 > Anyone know of a workaround for this?

No workaround needed: use the group's mouseDown message to update your 
menus, for the reasons Curry described.

Mac menus are already an exception in a great many respects. On Windows 
and Linux they are buttons, but on Mac the buttons are merely 
placeholders for properties used to recreate them dynamically as a 
native macOS menubar.  They also change stack size. Only one menubar is 
visible at a time, giving rise to the Mac-specific defaultMenubar. 
There are probably other differences. As the only OS with a global menu 
bar, it is by its nature an exception; we can expect exceptional methods 
to work with it.

But update handling isn't one of the exceptions here, if we consider the 
nuances of the interaction:

If we attempt to update a single menu on mouseDown, what happens when 
the user clicks down on any menu other than the Windows menu, then 
slides over to the Windows menu?  In normal LC messaging behavior, no 
mouseDown message would be sent to the Windows menu button.  To attempt 
to update a single menu would require you to track mouseDown messages 
across all menu buttons in the group, and track mouseEnter messages to 
then explicitly send an update message to the one the mouse is over. 
This would be tedious for us to script, and a heckuva lotta work for the 
engine team to coerce those messages from the mouse position within the 
macOS menu bar.

When it comes up updating menu contents, because of sliding-while-down, 
that's an action you'd want to do for all menus whenever any of them is 
clicked on, on all platforms.  So just put the update routines in the 
group and you're good.

The messaging mechanics are described in the tutorial you linked to:

     Cross-platform note: When a menu button is being displayed in
     the Mac OS menu bar, it does not receive mouseDown messages,
     but its group does. For this reason, this example handler
     should be placed in the script of the menu bar group, rather
     than in the menu button. The first line of the handler makes
     sure it's only executed if the user clicked the Window menu.
     This ensures that the example will work on all platforms.

It's been this way since MetaCard was first ported to MacOS, and while 
it does add to the long list of ways menus behave differently with 
macOS' native global menubar, it handles the use case well, better than 
attempting to handle this in the button itself.

I've added a note in the bug report suggesting we add something in the 
Dictionary entry for menubar to note the messaging exception and that 
content updates are best handled with-the-grain on that.

-- 
  Richard Gaskin
  Fourth World Systems
  Software Design and Development for the Desktop, Mobile, and the Web
  ____________________________________________________________________
  Ambassador at FourthWorld.com                http://www.FourthWorld.com








More information about the use-livecode mailing list