DesktopPopUpMenu - hierarchical sub-menus?

I would like to use the DesktopPopUpMenu with an already created hierarchical desktopMenuItem.

However if I try to add the menu like:

Var m As DesktopMenuItem =
For i As Integer = 0 To m.count - 1
  Me.AddRow m.MenuAt(i)

It only takes the first element in the hierarchy and doesn’t add the submenus that are already embedded in m.

Is there a way to achieve whilst keeping the look and feel of the standard control?


In ConstructContextualMenu, I do that :

Var popMenu As DeskTopMenuItem
popMenu = MenuAction.Clone
base = popMenu.PopUp

and I have the same menu as a popup with sub-menus…

I had tried that before, expecting it to work, but it appears ContextualMenus don’t work on the Mac. Extract from the manual: “ContextualMenus do not work with PopupMenu on macOS due to a limitation of the underlying macOS control that is used.”

So currently I am using a desktopMenuItem.popup in the MouseUp event - and having to backfill the result into the text of a blank first row so that it looks as if it has been selected. Not as pretty.

I don’t understand.
With the code that I posted before, I have that :

Sorry it is in French.

I don’t understand why we have a difference.

  1. On my Mac (Ventura 13.2, Xojo 2022r4) - ConstructContextualMenu does not fire when clicking the control.

  2. In your code, base is the root menuItem for the popup control, but you have assigned to it the result of your popMenu (base = popMenu.popUp). I’m not sure that would work as you indicate.

ConstructContextualMenu fires on a right click.

Ah, I think we are discussing different things. I am trying to use the DesktopPopupMenu - not right click on canvas/window/container etc.

Oups, sorry!
I have some DesktopPopupMenu but without submenus.

There’s probably a feedback somewhere for doing this, as the underlying macOS control will happily allow it, it’s just Xojo’s framework that sits atop won’t.

What you can do is to build a hierarchical menu of menu items, Then you grab [NSMenuitem submenu] from the base item, then use [NSPopupButton setMenu:] to set that menu onto the PopupMenu.

When I used it, I dynamically built the menu at open and used addHandler to capture the action event of each item. However I was using the PopupMenu in a “PullDown” form [NSPopupButton setPullsDown:], whereby selecting an item from the menu didn’t change the displayed label of the PopupMenu.

The declares for doing this is part of my App Kit, but are NOT compatible with DesktopControls. I’m sure the MVPs can provide you with a version or plugin that works with DesktopControls.

Thanks Sam - I’ll use MBS’s stuff to get this working.

Whoa wait. The AddRow method of DesktopPopupMenu will also take a DesktopMenuItem. Why can’t you use that?