Help with menus in OSX

I’ve imported an application that works on Windows.
It has a menu bar with several menu items.
All menu items have submenus but one.

On Windows when I click on a menu item with subnemus, these submenus are shown. But if I click on the only one that hasn’t submenus menu handler for this menu item is activated and code there is executed.

On OSX its is exactly the same with menu items with submenus, but nothing happens when I click on the menu item without submenus.
Is it the normal behaviour in OSX? Is it not possible to have menu items without submenus? If it is possible, what should I do?

Thanks for your help.

There is a case open and VERIFIED from 2008 Feedback #3411 .

I still don’t know if it is a bug or a normal behaviour in OSX, because I’m not a regular OSX user.
But have any of you noticed another OSX application with a menu item without submenus? Does it work?

[quote=200517:@Ramon SASTRE]I’ve imported an application that works on Windows.
It has a menu bar with several menu items.
All menu items have submenus but one.

On Windows when I click on a menu item with subnemus, these submenus are shown. But if I click on the only one that hasn’t submenus menu handler for this menu item is activated and code there is executed.

On OSX its is exactly the same with menu items with submenus, but nothing happens when I click on the menu item without submenus.
Is it the normal behaviour in OSX? Is it not possible to have menu items without submenus? If it is possible, what should I do?[/quote]

Ramon, depends what you call submenu.

In OS X, there is the notion of (dropdown) menu which appears when you click a menu item in the menu bar, for instance Edit shows a menu with cut, copy, paste, etc. A submenu is a supplemental menu that appears when you select an option in that menu, for instance File/Open with, which offers several apps.

It is unfortunate Xojo calls menu item for instance “Edit”, which in fact is a menu title. In OS X, you cannot attach execution to that menu title. Only to items in the drop down menu.

In Windows, you can indeed have a menu handler for the menu title.

Thank you Michel,
What you say is very clear and it is exactly what I thoight.
But in this case:

  • it should be clarified in Xojo documentation
  • It has no sense to allow code in this event if it is not computed

In general Menus have created a lot of problems to me when trying to program both for Windows and OSX. The truth is that menu philosophy in both OS is very different! In general I try to avoid menus and use other type of controls: buttons, segmented controls…

[quote=200528:@Ramon SASTRE]Thank you Michel,
What you say is very clear and it is exactly what I thoight.
But in this case:

  • it should be clarified in Xojo documentation
  • It has no sense to allow code in this event if it is not computed

In general Menus have created a lot of problems to me when trying to program both for Windows and OSX. The truth is that menu philosophy in both OS is very different! In general I try to avoid menus and use other type of controls: buttons, segmented controls…[/quote]

You are right, the philosophy is not exactly the same. One menu bar for all windows in OS X, one per window in Windows. And the fact the menu titles menu handlers do not work.

I have found, though, that the menu title click is about the only real difference in everyday use.

For the LR, Paul Lefebvre generally gracefully changes it right away when a Feedback is filed.

That said, I am not going to leave you in pain. You can nevertheless obtain execution upon menu bar title click.

Add a 20 ms multiple timer to the page.
In the Action event, add :

Sub Action() Label1.Text = str(system.mousex)+" "+str(system.Mousey) if system.mousey < screen(0).AvailableTop and system.mousex > 308 and system.mouseX < 362 _ and System.MouseDown then MsgBox "click" end if End Sub

This will pop a MsgBox “Click” when the third menu is clicked.

You may find convenient to use this in the same timer to find the left and right of a menu title on the bar (308-362) :

Label1.Text = str(system.mousex)+" "+str(system.Mousey)

That is how I found the left and right of my third item. Note that it is a powerful method, that enables all sorts of additional tricks, like detecting a click in screen corners or elsewhere on the screen.

Finally, note that this is absolutely not conformant to the highly revered HIG (Human Interface Guidelines), so Mac OS X zealots may regard that as slightly apostatic :wink:

Could be an issue if you plan to distribute the app in the MAS.

OK. I just played again with that. I had forgotten to prevent muliple clicks. Here is the corrected code :

Sub Action() Static MouseDown as Boolean if system.mousey < screen(0).AvailableTop and system.mousex > 308 and system.mouseX < 362 _ and System.MouseDown and not MouseDown then MsgBox "click" MouseDown = True elseIf not System.MouseDown and MouseDown then MouseDown = False end if End Sub

The other issue is that when a menu title is clicked, it becomes selected and stays that way. If not showing a MsgBox, adding an item named by a space character shows a small box underneath during the click, and makes it unselect like all other menus.

There maybe a declare to do the same, though.

Michel,

That is fantastic! I’m not going to use it now, but as you say it is a powerful tool that may be used for other things.
In the current case I prefer to adapt my app.
Thanks a lot.

This is my best solution (work around?) to this situation:

#if TargetMacOS Then Dim m0 as MenuItem = MenuBar.Item(1) // Let's suppose that this is the menu without menu items if m0.Count = 0 Then m0.Append m0.clone #endif
Then I have a repeated menu, but the second one works.

[quote=200815:@Ramon SASTRE]This is my best solution (work around?) to this situation:

#if TargetMacOS Then Dim m0 as MenuItem = MenuBar.Item(1) // Let's suppose that this is the menu without menu items if m0.Count = 0 Then m0.Append m0.clone #endif
Then I have a repeated menu, but the second one works.[/quote]

It works. That will be conformant to the HIG. Through the years, I found them to be very useful to avoid mistakes, even on the Windows side.

Using the menu title as a button, if you think about it, is like having a PopupMenu that works as a button and never shows a dropdown.