Difference between revisions of "Cocoa Internals/Menu"
Line 13: | Line 13: | ||
===Application Menu Translation=== | ===Application Menu Translation=== | ||
The titles (caption) of the Application menus are stored as "resourcestring" and could be translated by a translation module. | The titles (caption) of the Application menus are stored as "resourcestring" and could be translated by a translation module. | ||
+ | ===Menus and Menu Items Clicks=== | ||
+ | There's a difference between Menus and MenuItems. "Menus" is simply a "MenuItem" with a submenu (and other subitems). | ||
+ | |||
+ | The difference is how CocoaWS is reporting "clicks" to LCL. | ||
+ | |||
+ | For "Menus" the clicks are reported when a mouse HOVERs over the menuitem. (this is due to the fact of the click is called at '''menuNeedUpdate'''. Calling at '''menuWillOpen''' is too late, as macOS directly forbids changing the submenu items at that time). | ||
==See Also== | ==See Also== |
Revision as of 04:54, 10 October 2021
Menu logic in macOS is different from the one in Windows (and other systems). The entire application only has one menu on top. That's it. There are no "per window" menus attached. (instead a window could use a Toolbar instead)
Basic Logic
- The TMainMenu of the active window is set as the Application menu
- If active window doesn't have TMainMenu the last active window with TMainMenu is still used
- The Window running as modal disables the main menu, UNLESS it has its own main menu.
Implementation
used classes are
- NSMenu
- NSMenuItem
Application Menu
If there's TMainMenu allocated for LCL form, WSCocoa internally allocates the "Application" menu. The "Application" menu is macOS convention, that any app should do it. Since there's no logical concept of "Application" menu in LCL, CocoaWS simply always creates it for you.
Application Menu Translation
The titles (caption) of the Application menus are stored as "resourcestring" and could be translated by a translation module.
Menus and Menu Items Clicks
There's a difference between Menus and MenuItems. "Menus" is simply a "MenuItem" with a submenu (and other subitems).
The difference is how CocoaWS is reporting "clicks" to LCL.
For "Menus" the clicks are reported when a mouse HOVERs over the menuitem. (this is due to the fact of the click is called at menuNeedUpdate. Calling at menuWillOpen is too late, as macOS directly forbids changing the submenu items at that time).