Menu Item custom callback not called if MenuBarModel::setMacMainMenu


#1

I suspect a bug when using a custom callback with an item of a SubMenu, on Mac. The item is well displayed but when clicked, the callback is not called. However, it ONLY happens when the MenuBarModel::setMacMainMenu is used with the menu as a parameter. When it is NOT applied, the menu item works fine. Is it a bug? On Windows and Linux, everything is fine.

My menu item is created like this:

...
PopupMenu::Item item;
item.text = "my text";
item.itemID = 1234;		// Why not?
ReferenceCountedObjectPtr<MyItemCallback> myItemCallback(new MyItemCallback());
item.customCallback = myItemCallback;

mySubMenu.addItem(item);
...

With MyItemCallback being a child of the PopupMenu::CustomCallback:

class MyItemCallback : public PopupMenu::CustomCallback
{
public:
	bool menuItemTriggered() override
	{
		// Item clicked! Do something.
	}
}

Thanks.


#2

Please check the develop trunk. There used to be a bug which has been fixed a month ago.
Not sure if this really your issue as it was the main menu but just in case.


#3

Yes this should be fixed in JUCE 5.1.2.


#4

Thanks for your answer. However, I tested on the latest version of JUCE on both master and develop, and it does not work: the callback is not called. if setMacMainMenu is used.


#5

Thanks for reporting. This is fixed on develop with commit e0b0920.

It turns out that by fixing this bug we discovered a memory-leak (as PopupMenu::CustomCallback has a leak detector) for any native macOS menu item that JUCE creates. It took ages to figure out what the problem was but it’s finally fixed - also on develop -
with commit 6ae99f4.


#6

Glad I could help :). This is working now, thanks a lot.