COptionMenu - how to see which submenu entry is selected

Hello!

I have created a menu that has 3 simple entries and a submenu.
My menu is its own VSTGUI::IControlListener and I have overriden the valueChanged() method, in order to check what item is selected and trigger some actions.
It works fine for the simple entries, but not for the submenu entries. Whenever I select an item from the submenu, I get in return the index of the last item selected from the main menu. How can I access the items from the submenu?

Thank you!

You can either add CCommandMenuItems to your menu and set its actions, or you can register an IOptionMenuListener on the menu and use the onOptionMenuSetPopupResult method.

1 Like

I can confirm the same issue here too when migrating from VSTGUI 3.6 to 4.4.
Submenus worked fine in 3.6. In 4.4 clicking on the submenu returns wrong results and do not longer work. The tag assigned to the submenu is never called. Instead the tag of root menu is called with the index value of the submenu.

Thanks

Update:
It’s a bug that affects all versions of VSTGUI4 (4.0 up to 4.11).
If was able to fix it.
The bug occurs since valueChanged() is called instead of lastMenu->valueChanged()

Solution:

bool COptionMenu::popup ()
{
bool popupResult = false;
if (!getFrame ())
return popupResult;

CBaseObjectGuard objGuard (this);

beforePopup ();

inPopup = true;

beginEdit ();

lastResult = -1;
lastMenu = 0;

getFrame ()->onStartLocalEventLoop ();

IPlatformOptionMenu* platformMenu = getFrame ()->getPlatformFrame ()->createPlatformOptionMenu ();
if (platformMenu)
{
PlatformOptionMenuResult platformPopupResult = platformMenu->popup (this);
if (platformPopupResult.menu != 0)
{
IDependency::DeferChanges dc (this);
lastMenu = platformPopupResult.menu;
lastResult = platformPopupResult.index;
lastMenu->setValue ((float)lastResult);
lastMenu->valueChanged();
invalid ();
popupResult = true;
CCommandMenuItem* commandItem = dynamic_cast<CCommandMenuItem*>(lastMenu->getEntry (lastResult));
if (commandItem)
commandItem->execute ();
}
platformMenu->forget ();
}

endEdit ();
inPopup = false;
return popupResult;
}