Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

185 lines
7.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef JUCE_MENUBARMODEL_H_INCLUDED
  18. #define JUCE_MENUBARMODEL_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. A class for controlling MenuBar components.
  22. This class is used to tell a MenuBar what menus to show, and to respond
  23. to a menu being selected.
  24. @see MenuBarModel::Listener, MenuBarComponent, PopupMenu
  25. */
  26. class JUCE_API MenuBarModel : private AsyncUpdater,
  27. private ApplicationCommandManagerListener
  28. {
  29. public:
  30. //==============================================================================
  31. MenuBarModel() noexcept;
  32. /** Destructor. */
  33. virtual ~MenuBarModel();
  34. //==============================================================================
  35. /** Call this when some of your menu items have changed.
  36. This method will cause a callback to any MenuBarListener objects that
  37. are registered with this model.
  38. If this model is displaying items from an ApplicationCommandManager, you
  39. can use the setApplicationCommandManagerToWatch() method to cause
  40. change messages to be sent automatically when the ApplicationCommandManager
  41. is changed.
  42. @see addListener, removeListener, MenuBarListener
  43. */
  44. void menuItemsChanged();
  45. /** Tells the menu bar to listen to the specified command manager, and to update
  46. itself when the commands change.
  47. This will also allow it to flash a menu name when a command from that menu
  48. is invoked using a keystroke.
  49. */
  50. void setApplicationCommandManagerToWatch (ApplicationCommandManager* manager) noexcept;
  51. //==============================================================================
  52. /** A class to receive callbacks when a MenuBarModel changes.
  53. @see MenuBarModel::addListener, MenuBarModel::removeListener, MenuBarModel::menuItemsChanged
  54. */
  55. class JUCE_API Listener
  56. {
  57. public:
  58. /** Destructor. */
  59. virtual ~Listener() {}
  60. //==============================================================================
  61. /** This callback is made when items are changed in the menu bar model.
  62. */
  63. virtual void menuBarItemsChanged (MenuBarModel* menuBarModel) = 0;
  64. /** This callback is made when an application command is invoked that
  65. is represented by one of the items in the menu bar model.
  66. */
  67. virtual void menuCommandInvoked (MenuBarModel* menuBarModel,
  68. const ApplicationCommandTarget::InvocationInfo& info) = 0;
  69. };
  70. /** Registers a listener for callbacks when the menu items in this model change.
  71. The listener object will get callbacks when this object's menuItemsChanged()
  72. method is called.
  73. @see removeListener
  74. */
  75. void addListener (Listener* listenerToAdd) noexcept;
  76. /** Removes a listener.
  77. @see addListener
  78. */
  79. void removeListener (Listener* listenerToRemove) noexcept;
  80. //==============================================================================
  81. /** This method must return a list of the names of the menus. */
  82. virtual StringArray getMenuBarNames() = 0;
  83. /** This should return the popup menu to display for a given top-level menu.
  84. @param topLevelMenuIndex the index of the top-level menu to show
  85. @param menuName the name of the top-level menu item to show
  86. */
  87. virtual PopupMenu getMenuForIndex (int topLevelMenuIndex,
  88. const String& menuName) = 0;
  89. /** This is called when a menu item has been clicked on.
  90. @param menuItemID the item ID of the PopupMenu item that was selected
  91. @param topLevelMenuIndex the index of the top-level menu from which the item was
  92. chosen (just in case you've used duplicate ID numbers
  93. on more than one of the popup menus)
  94. */
  95. virtual void menuItemSelected (int menuItemID,
  96. int topLevelMenuIndex) = 0;
  97. //==============================================================================
  98. #if JUCE_MAC || DOXYGEN
  99. /** MAC ONLY - Sets the model that is currently being shown as the main
  100. menu bar at the top of the screen on the Mac.
  101. You can pass 0 to stop the current model being displayed. Be careful
  102. not to delete a model while it is being used.
  103. An optional extra menu can be specified, containing items to add to the top of
  104. the apple menu. (Confusingly, the 'apple' menu isn't the one with a picture of
  105. an apple, it's the one next to it, with your application's name at the top
  106. and the services menu etc on it). When one of these items is selected, the
  107. menu bar model will be used to invoke it, and in the menuItemSelected() callback
  108. the topLevelMenuIndex parameter will be -1. If you pass in an extraAppleMenuItems
  109. object then newMenuBarModel must be non-null.
  110. If the recentItemsMenuName parameter is non-empty, then any sub-menus with this
  111. name will be replaced by OSX's special recent-files menu.
  112. */
  113. static void setMacMainMenu (MenuBarModel* newMenuBarModel,
  114. const PopupMenu* extraAppleMenuItems = nullptr,
  115. const String& recentItemsMenuName = String::empty);
  116. /** MAC ONLY - Returns the menu model that is currently being shown as
  117. the main menu bar.
  118. */
  119. static MenuBarModel* getMacMainMenu();
  120. /** MAC ONLY - Returns the menu that was last passed as the extraAppleMenuItems
  121. argument to setMacMainMenu(), or nullptr if none was specified.
  122. */
  123. static const PopupMenu* getMacExtraAppleItemsMenu();
  124. #endif
  125. //==============================================================================
  126. /** @internal */
  127. void applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info) override;
  128. /** @internal */
  129. void applicationCommandListChanged() override;
  130. /** @internal */
  131. void handleAsyncUpdate() override;
  132. private:
  133. ApplicationCommandManager* manager;
  134. ListenerList <Listener> listeners;
  135. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MenuBarModel)
  136. };
  137. /** This typedef is just for compatibility with old code - newer code should use the MenuBarModel::Listener class directly. */
  138. typedef MenuBarModel::Listener MenuBarModelListener;
  139. #endif // JUCE_MENUBARMODEL_H_INCLUDED